blob: 4ab1ffa9df11716facdbdd09ebb75f9a93aac886 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Johannes Berge5497d72011-07-05 16:35:40 +0200406/* policy for GTK rekey offload attributes */
407static const struct nla_policy
408nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
409 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
410 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
411 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
412};
413
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300414static const struct nla_policy
415nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300417 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300419};
420
Johannes Berg97990a02013-04-19 01:02:55 +0200421static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
422 struct netlink_callback *cb,
423 struct cfg80211_registered_device **rdev,
424 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100425{
Johannes Berg67748892010-10-04 21:14:06 +0200426 int err;
427
Johannes Berg67748892010-10-04 21:14:06 +0200428 rtnl_lock();
429
Johannes Berg97990a02013-04-19 01:02:55 +0200430 if (!cb->args[0]) {
431 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
432 nl80211_fam.attrbuf, nl80211_fam.maxattr,
433 nl80211_policy);
434 if (err)
435 goto out_unlock;
436
437 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
438 nl80211_fam.attrbuf);
439 if (IS_ERR(*wdev)) {
440 err = PTR_ERR(*wdev);
441 goto out_unlock;
442 }
443 *rdev = wiphy_to_dev((*wdev)->wiphy);
444 cb->args[0] = (*rdev)->wiphy_idx;
445 cb->args[1] = (*wdev)->identifier;
446 } else {
447 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
448 struct wireless_dev *tmp;
449
450 if (!wiphy) {
451 err = -ENODEV;
452 goto out_unlock;
453 }
454 *rdev = wiphy_to_dev(wiphy);
455 *wdev = NULL;
456
Johannes Berg97990a02013-04-19 01:02:55 +0200457 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
458 if (tmp->identifier == cb->args[1]) {
459 *wdev = tmp;
460 break;
461 }
462 }
Johannes Berg97990a02013-04-19 01:02:55 +0200463
464 if (!*wdev) {
465 err = -ENODEV;
466 goto out_unlock;
467 }
Johannes Berg67748892010-10-04 21:14:06 +0200468 }
469
Johannes Berg67748892010-10-04 21:14:06 +0200470 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200471 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200472 rtnl_unlock();
473 return err;
474}
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200477{
Johannes Berg67748892010-10-04 21:14:06 +0200478 rtnl_unlock();
479}
480
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100481/* IE validation */
482static bool is_valid_ie_attr(const struct nlattr *attr)
483{
484 const u8 *pos;
485 int len;
486
487 if (!attr)
488 return true;
489
490 pos = nla_data(attr);
491 len = nla_len(attr);
492
493 while (len) {
494 u8 elemlen;
495
496 if (len < 2)
497 return false;
498 len -= 2;
499
500 elemlen = pos[1];
501 if (elemlen > len)
502 return false;
503
504 len -= elemlen;
505 pos += 2 + elemlen;
506 }
507
508 return true;
509}
510
Johannes Berg55682962007-09-20 13:09:35 -0400511/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000512static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400513 int flags, u8 cmd)
514{
515 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000516 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400517}
518
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400519static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100520 struct ieee80211_channel *chan,
521 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400522{
David S. Miller9360ffd2012-03-29 04:41:26 -0400523 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
524 chan->center_freq))
525 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400526
David S. Miller9360ffd2012-03-29 04:41:26 -0400527 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
528 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
529 goto nla_put_failure;
530 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
531 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
532 goto nla_put_failure;
533 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
534 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
535 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100536 if (chan->flags & IEEE80211_CHAN_RADAR) {
537 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
538 goto nla_put_failure;
539 if (large) {
540 u32 time;
541
542 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
543
544 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
545 chan->dfs_state))
546 goto nla_put_failure;
547 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
548 time))
549 goto nla_put_failure;
550 }
551 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100553 if (large) {
554 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
565 goto nla_put_failure;
566 }
567
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
569 DBM_TO_MBM(chan->max_power)))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
572 return 0;
573
574 nla_put_failure:
575 return -ENOBUFS;
576}
577
Johannes Berg55682962007-09-20 13:09:35 -0400578/* netlink command implementations */
579
Johannes Bergb9454e82009-07-08 13:29:08 +0200580struct key_parse {
581 struct key_params p;
582 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200583 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200584 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100585 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200586};
587
588static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
589{
590 struct nlattr *tb[NL80211_KEY_MAX + 1];
591 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
592 nl80211_key_policy);
593 if (err)
594 return err;
595
596 k->def = !!tb[NL80211_KEY_DEFAULT];
597 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
598
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100599 if (k->def) {
600 k->def_uni = true;
601 k->def_multi = true;
602 }
603 if (k->defmgmt)
604 k->def_multi = true;
605
Johannes Bergb9454e82009-07-08 13:29:08 +0200606 if (tb[NL80211_KEY_IDX])
607 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
608
609 if (tb[NL80211_KEY_DATA]) {
610 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
611 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
612 }
613
614 if (tb[NL80211_KEY_SEQ]) {
615 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
616 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
617 }
618
619 if (tb[NL80211_KEY_CIPHER])
620 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
621
Johannes Berge31b8212010-10-05 19:39:30 +0200622 if (tb[NL80211_KEY_TYPE]) {
623 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
624 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
625 return -EINVAL;
626 }
627
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100628 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
629 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100630 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
631 tb[NL80211_KEY_DEFAULT_TYPES],
632 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100633 if (err)
634 return err;
635
636 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
637 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
638 }
639
Johannes Bergb9454e82009-07-08 13:29:08 +0200640 return 0;
641}
642
643static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
644{
645 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
646 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
647 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
648 }
649
650 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
651 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
652 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
653 }
654
655 if (info->attrs[NL80211_ATTR_KEY_IDX])
656 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
657
658 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
659 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
660
661 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
662 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
663
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 if (k->def) {
665 k->def_uni = true;
666 k->def_multi = true;
667 }
668 if (k->defmgmt)
669 k->def_multi = true;
670
Johannes Berge31b8212010-10-05 19:39:30 +0200671 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
672 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
673 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
674 return -EINVAL;
675 }
676
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
678 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
679 int err = nla_parse_nested(
680 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
681 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
682 nl80211_key_default_policy);
683 if (err)
684 return err;
685
686 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
687 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
688 }
689
Johannes Bergb9454e82009-07-08 13:29:08 +0200690 return 0;
691}
692
693static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
694{
695 int err;
696
697 memset(k, 0, sizeof(*k));
698 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200699 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200700
701 if (info->attrs[NL80211_ATTR_KEY])
702 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
703 else
704 err = nl80211_parse_key_old(info, k);
705
706 if (err)
707 return err;
708
709 if (k->def && k->defmgmt)
710 return -EINVAL;
711
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (k->defmgmt) {
713 if (k->def_uni || !k->def_multi)
714 return -EINVAL;
715 }
716
Johannes Bergb9454e82009-07-08 13:29:08 +0200717 if (k->idx != -1) {
718 if (k->defmgmt) {
719 if (k->idx < 4 || k->idx > 5)
720 return -EINVAL;
721 } else if (k->def) {
722 if (k->idx < 0 || k->idx > 3)
723 return -EINVAL;
724 } else {
725 if (k->idx < 0 || k->idx > 5)
726 return -EINVAL;
727 }
728 }
729
730 return 0;
731}
732
Johannes Bergfffd0932009-07-08 14:22:54 +0200733static struct cfg80211_cached_keys *
734nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530735 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200736{
737 struct key_parse parse;
738 struct nlattr *key;
739 struct cfg80211_cached_keys *result;
740 int rem, err, def = 0;
741
742 result = kzalloc(sizeof(*result), GFP_KERNEL);
743 if (!result)
744 return ERR_PTR(-ENOMEM);
745
746 result->def = -1;
747 result->defmgmt = -1;
748
749 nla_for_each_nested(key, keys, rem) {
750 memset(&parse, 0, sizeof(parse));
751 parse.idx = -1;
752
753 err = nl80211_parse_key_new(key, &parse);
754 if (err)
755 goto error;
756 err = -EINVAL;
757 if (!parse.p.key)
758 goto error;
759 if (parse.idx < 0 || parse.idx > 4)
760 goto error;
761 if (parse.def) {
762 if (def)
763 goto error;
764 def = 1;
765 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100766 if (!parse.def_uni || !parse.def_multi)
767 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200768 } else if (parse.defmgmt)
769 goto error;
770 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200771 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (err)
773 goto error;
774 result->params[parse.idx].cipher = parse.p.cipher;
775 result->params[parse.idx].key_len = parse.p.key_len;
776 result->params[parse.idx].key = result->data[parse.idx];
777 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530778
779 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
780 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
781 if (no_ht)
782 *no_ht = true;
783 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200784 }
785
786 return result;
787 error:
788 kfree(result);
789 return ERR_PTR(err);
790}
791
792static int nl80211_key_allowed(struct wireless_dev *wdev)
793{
794 ASSERT_WDEV_LOCK(wdev);
795
Johannes Bergfffd0932009-07-08 14:22:54 +0200796 switch (wdev->iftype) {
797 case NL80211_IFTYPE_AP:
798 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200799 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700800 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200801 break;
802 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200803 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200804 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200805 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806 return -ENOLINK;
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 return 0;
813}
814
Johannes Berg7527a782011-05-13 10:58:57 +0200815static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
816{
817 struct nlattr *nl_modes = nla_nest_start(msg, attr);
818 int i;
819
820 if (!nl_modes)
821 goto nla_put_failure;
822
823 i = 0;
824 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400825 if ((ifmodes & 1) && nla_put_flag(msg, i))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 ifmodes >>= 1;
828 i++;
829 }
830
831 nla_nest_end(msg, nl_modes);
832 return 0;
833
834nla_put_failure:
835 return -ENOBUFS;
836}
837
838static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100839 struct sk_buff *msg,
840 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200841{
842 struct nlattr *nl_combis;
843 int i, j;
844
845 nl_combis = nla_nest_start(msg,
846 NL80211_ATTR_INTERFACE_COMBINATIONS);
847 if (!nl_combis)
848 goto nla_put_failure;
849
850 for (i = 0; i < wiphy->n_iface_combinations; i++) {
851 const struct ieee80211_iface_combination *c;
852 struct nlattr *nl_combi, *nl_limits;
853
854 c = &wiphy->iface_combinations[i];
855
856 nl_combi = nla_nest_start(msg, i + 1);
857 if (!nl_combi)
858 goto nla_put_failure;
859
860 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
861 if (!nl_limits)
862 goto nla_put_failure;
863
864 for (j = 0; j < c->n_limits; j++) {
865 struct nlattr *nl_limit;
866
867 nl_limit = nla_nest_start(msg, j + 1);
868 if (!nl_limit)
869 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
871 c->limits[j].max))
872 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200873 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
874 c->limits[j].types))
875 goto nla_put_failure;
876 nla_nest_end(msg, nl_limit);
877 }
878
879 nla_nest_end(msg, nl_limits);
880
David S. Miller9360ffd2012-03-29 04:41:26 -0400881 if (c->beacon_int_infra_match &&
882 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
883 goto nla_put_failure;
884 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
885 c->num_different_channels) ||
886 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
887 c->max_interfaces))
888 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100889 if (large &&
890 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
891 c->radar_detect_widths))
892 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200893
894 nla_nest_end(msg, nl_combi);
895 }
896
897 nla_nest_end(msg, nl_combis);
898
899 return 0;
900nla_put_failure:
901 return -ENOBUFS;
902}
903
Johannes Berg3713b4e2013-02-14 16:19:38 +0100904#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100905static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
906 struct sk_buff *msg)
907{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200908 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100909 struct nlattr *nl_tcp;
910
911 if (!tcp)
912 return 0;
913
914 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
915 if (!nl_tcp)
916 return -ENOBUFS;
917
918 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
919 tcp->data_payload_max))
920 return -ENOBUFS;
921
922 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
923 tcp->data_payload_max))
924 return -ENOBUFS;
925
926 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
927 return -ENOBUFS;
928
929 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
930 sizeof(*tcp->tok), tcp->tok))
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
934 tcp->data_interval_max))
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
938 tcp->wake_payload_max))
939 return -ENOBUFS;
940
941 nla_nest_end(msg, nl_tcp);
942 return 0;
943}
944
Johannes Berg3713b4e2013-02-14 16:19:38 +0100945static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100946 struct cfg80211_registered_device *dev,
947 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948{
949 struct nlattr *nl_wowlan;
950
Johannes Berg964dc9e2013-06-03 17:25:34 +0200951 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100952 return 0;
953
954 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
955 if (!nl_wowlan)
956 return -ENOBUFS;
957
Johannes Berg964dc9e2013-06-03 17:25:34 +0200958 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200960 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200962 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200964 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
974 return -ENOBUFS;
975
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 if (dev->wiphy.wowlan->n_patterns) {
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 struct nl80211_wowlan_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 .max_patterns = dev->wiphy.wowlan->n_patterns,
979 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
980 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
981 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 };
983
984 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
985 sizeof(pat), &pat))
986 return -ENOBUFS;
987 }
988
Johannes Bergb56cf722013-02-20 01:02:38 +0100989 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
990 return -ENOBUFS;
991
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992 nla_nest_end(msg, nl_wowlan);
993
994 return 0;
995}
996#endif
997
998static int nl80211_send_band_rateinfo(struct sk_buff *msg,
999 struct ieee80211_supported_band *sband)
1000{
1001 struct nlattr *nl_rates, *nl_rate;
1002 struct ieee80211_rate *rate;
1003 int i;
1004
1005 /* add HT info */
1006 if (sband->ht_cap.ht_supported &&
1007 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1008 sizeof(sband->ht_cap.mcs),
1009 &sband->ht_cap.mcs) ||
1010 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1011 sband->ht_cap.cap) ||
1012 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1013 sband->ht_cap.ampdu_factor) ||
1014 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1015 sband->ht_cap.ampdu_density)))
1016 return -ENOBUFS;
1017
1018 /* add VHT info */
1019 if (sband->vht_cap.vht_supported &&
1020 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1021 sizeof(sband->vht_cap.vht_mcs),
1022 &sband->vht_cap.vht_mcs) ||
1023 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1024 sband->vht_cap.cap)))
1025 return -ENOBUFS;
1026
1027 /* add bitrates */
1028 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1029 if (!nl_rates)
1030 return -ENOBUFS;
1031
1032 for (i = 0; i < sband->n_bitrates; i++) {
1033 nl_rate = nla_nest_start(msg, i);
1034 if (!nl_rate)
1035 return -ENOBUFS;
1036
1037 rate = &sband->bitrates[i];
1038 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1039 rate->bitrate))
1040 return -ENOBUFS;
1041 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1042 nla_put_flag(msg,
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_rate);
1047 }
1048
1049 nla_nest_end(msg, nl_rates);
1050
1051 return 0;
1052}
1053
1054static int
1055nl80211_send_mgmt_stypes(struct sk_buff *msg,
1056 const struct ieee80211_txrx_stypes *mgmt_stypes)
1057{
1058 u16 stypes;
1059 struct nlattr *nl_ftypes, *nl_ifs;
1060 enum nl80211_iftype ift;
1061 int i;
1062
1063 if (!mgmt_stypes)
1064 return 0;
1065
1066 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1067 if (!nl_ifs)
1068 return -ENOBUFS;
1069
1070 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1071 nl_ftypes = nla_nest_start(msg, ift);
1072 if (!nl_ftypes)
1073 return -ENOBUFS;
1074 i = 0;
1075 stypes = mgmt_stypes[ift].tx;
1076 while (stypes) {
1077 if ((stypes & 1) &&
1078 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1079 (i << 4) | IEEE80211_FTYPE_MGMT))
1080 return -ENOBUFS;
1081 stypes >>= 1;
1082 i++;
1083 }
1084 nla_nest_end(msg, nl_ftypes);
1085 }
1086
1087 nla_nest_end(msg, nl_ifs);
1088
1089 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1090 if (!nl_ifs)
1091 return -ENOBUFS;
1092
1093 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1094 nl_ftypes = nla_nest_start(msg, ift);
1095 if (!nl_ftypes)
1096 return -ENOBUFS;
1097 i = 0;
1098 stypes = mgmt_stypes[ift].rx;
1099 while (stypes) {
1100 if ((stypes & 1) &&
1101 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1102 (i << 4) | IEEE80211_FTYPE_MGMT))
1103 return -ENOBUFS;
1104 stypes >>= 1;
1105 i++;
1106 }
1107 nla_nest_end(msg, nl_ftypes);
1108 }
1109 nla_nest_end(msg, nl_ifs);
1110
1111 return 0;
1112}
1113
1114static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1115 struct sk_buff *msg, u32 portid, u32 seq,
1116 int flags, bool split, long *split_start,
1117 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001118{
1119 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001120 struct nlattr *nl_bands, *nl_band;
1121 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001122 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001123 enum ieee80211_band band;
1124 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001125 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001126 const struct ieee80211_txrx_stypes *mgmt_stypes =
1127 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001129 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001130
Eric W. Biederman15e47302012-09-07 20:12:54 +00001131 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001132 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133 return -ENOBUFS;
1134
1135 /* allow always using the variables */
1136 if (!split) {
1137 split_start = &start;
1138 band_start = &start_band;
1139 chan_start = &start_chan;
1140 }
Johannes Berg55682962007-09-20 13:09:35 -04001141
David S. Miller9360ffd2012-03-29 04:41:26 -04001142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1144 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001145 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001148
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 switch (*split_start) {
1150 case 0:
1151 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1152 dev->wiphy.retry_short) ||
1153 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1154 dev->wiphy.retry_long) ||
1155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1156 dev->wiphy.frag_threshold) ||
1157 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1158 dev->wiphy.rts_threshold) ||
1159 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1160 dev->wiphy.coverage_class) ||
1161 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1162 dev->wiphy.max_scan_ssids) ||
1163 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1164 dev->wiphy.max_sched_scan_ssids) ||
1165 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1166 dev->wiphy.max_scan_ie_len) ||
1167 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1168 dev->wiphy.max_sched_scan_ie_len) ||
1169 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1170 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001171 goto nla_put_failure;
1172
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1174 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1175 goto nla_put_failure;
1176 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1178 goto nla_put_failure;
1179 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1180 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1181 goto nla_put_failure;
1182 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1183 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1184 goto nla_put_failure;
1185 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1186 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1187 goto nla_put_failure;
1188 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1189 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001190 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001191 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1192 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1193 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001194
Johannes Berg3713b4e2013-02-14 16:19:38 +01001195 (*split_start)++;
1196 if (split)
1197 break;
1198 case 1:
1199 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1200 sizeof(u32) * dev->wiphy.n_cipher_suites,
1201 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001202 goto nla_put_failure;
1203
Johannes Berg3713b4e2013-02-14 16:19:38 +01001204 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1205 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001206 goto nla_put_failure;
1207
Johannes Berg3713b4e2013-02-14 16:19:38 +01001208 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1209 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1210 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001211
Johannes Berg3713b4e2013-02-14 16:19:38 +01001212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1213 dev->wiphy.available_antennas_tx) ||
1214 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1215 dev->wiphy.available_antennas_rx))
1216 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001217
Johannes Berg3713b4e2013-02-14 16:19:38 +01001218 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1219 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1220 dev->wiphy.probe_resp_offload))
1221 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001222
Johannes Berg3713b4e2013-02-14 16:19:38 +01001223 if ((dev->wiphy.available_antennas_tx ||
1224 dev->wiphy.available_antennas_rx) &&
1225 dev->ops->get_antenna) {
1226 u32 tx_ant = 0, rx_ant = 0;
1227 int res;
1228 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1229 if (!res) {
1230 if (nla_put_u32(msg,
1231 NL80211_ATTR_WIPHY_ANTENNA_TX,
1232 tx_ant) ||
1233 nla_put_u32(msg,
1234 NL80211_ATTR_WIPHY_ANTENNA_RX,
1235 rx_ant))
1236 goto nla_put_failure;
1237 }
Johannes Bergee688b002008-01-24 19:38:39 +01001238 }
1239
Johannes Berg3713b4e2013-02-14 16:19:38 +01001240 (*split_start)++;
1241 if (split)
1242 break;
1243 case 2:
1244 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1245 dev->wiphy.interface_modes))
1246 goto nla_put_failure;
1247 (*split_start)++;
1248 if (split)
1249 break;
1250 case 3:
1251 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1252 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001253 goto nla_put_failure;
1254
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1256 struct ieee80211_supported_band *sband;
1257
1258 sband = dev->wiphy.bands[band];
1259
1260 if (!sband)
1261 continue;
1262
1263 nl_band = nla_nest_start(msg, band);
1264 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001265 goto nla_put_failure;
1266
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 switch (*chan_start) {
1268 case 0:
1269 if (nl80211_send_band_rateinfo(msg, sband))
1270 goto nla_put_failure;
1271 (*chan_start)++;
1272 if (split)
1273 break;
1274 default:
1275 /* add frequencies */
1276 nl_freqs = nla_nest_start(
1277 msg, NL80211_BAND_ATTR_FREQS);
1278 if (!nl_freqs)
1279 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001280
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 for (i = *chan_start - 1;
1282 i < sband->n_channels;
1283 i++) {
1284 nl_freq = nla_nest_start(msg, i);
1285 if (!nl_freq)
1286 goto nla_put_failure;
1287
1288 chan = &sband->channels[i];
1289
Johannes Bergcdc89b92013-02-18 23:54:36 +01001290 if (nl80211_msg_put_channel(msg, chan,
1291 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 goto nla_put_failure;
1293
1294 nla_nest_end(msg, nl_freq);
1295 if (split)
1296 break;
1297 }
1298 if (i < sband->n_channels)
1299 *chan_start = i + 2;
1300 else
1301 *chan_start = 0;
1302 nla_nest_end(msg, nl_freqs);
1303 }
1304
1305 nla_nest_end(msg, nl_band);
1306
1307 if (split) {
1308 /* start again here */
1309 if (*chan_start)
1310 band--;
1311 break;
1312 }
Johannes Bergee688b002008-01-24 19:38:39 +01001313 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001315
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 if (band < IEEE80211_NUM_BANDS)
1317 *band_start = band + 1;
1318 else
1319 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001320
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 /* if bands & channels are done, continue outside */
1322 if (*band_start == 0 && *chan_start == 0)
1323 (*split_start)++;
1324 if (split)
1325 break;
1326 case 4:
1327 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1328 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001329 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330
1331 i = 0;
1332#define CMD(op, n) \
1333 do { \
1334 if (dev->ops->op) { \
1335 i++; \
1336 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1337 goto nla_put_failure; \
1338 } \
1339 } while (0)
1340
1341 CMD(add_virtual_intf, NEW_INTERFACE);
1342 CMD(change_virtual_intf, SET_INTERFACE);
1343 CMD(add_key, NEW_KEY);
1344 CMD(start_ap, START_AP);
1345 CMD(add_station, NEW_STATION);
1346 CMD(add_mpath, NEW_MPATH);
1347 CMD(update_mesh_config, SET_MESH_CONFIG);
1348 CMD(change_bss, SET_BSS);
1349 CMD(auth, AUTHENTICATE);
1350 CMD(assoc, ASSOCIATE);
1351 CMD(deauth, DEAUTHENTICATE);
1352 CMD(disassoc, DISASSOCIATE);
1353 CMD(join_ibss, JOIN_IBSS);
1354 CMD(join_mesh, JOIN_MESH);
1355 CMD(set_pmksa, SET_PMKSA);
1356 CMD(del_pmksa, DEL_PMKSA);
1357 CMD(flush_pmksa, FLUSH_PMKSA);
1358 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1359 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1360 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1361 CMD(mgmt_tx, FRAME);
1362 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1363 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1364 i++;
1365 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1366 goto nla_put_failure;
1367 }
1368 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1369 dev->ops->join_mesh) {
1370 i++;
1371 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1372 goto nla_put_failure;
1373 }
1374 CMD(set_wds_peer, SET_WDS_PEER);
1375 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1376 CMD(tdls_mgmt, TDLS_MGMT);
1377 CMD(tdls_oper, TDLS_OPER);
1378 }
1379 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1380 CMD(sched_scan_start, START_SCHED_SCAN);
1381 CMD(probe_client, PROBE_CLIENT);
1382 CMD(set_noack_map, SET_NOACK_MAP);
1383 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1384 i++;
1385 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1386 goto nla_put_failure;
1387 }
1388 CMD(start_p2p_device, START_P2P_DEVICE);
1389 CMD(set_mcast_rate, SET_MCAST_RATE);
Arend van Spriel5de17982013-04-18 15:49:00 +02001390 if (split) {
1391 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1392 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1393 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001394
Kalle Valo4745fc02011-11-17 19:06:10 +02001395#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001396 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001397#endif
1398
Johannes Berg8fdc6212009-03-14 09:34:01 +01001399#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001400
Johannes Berg3713b4e2013-02-14 16:19:38 +01001401 if (dev->ops->connect || dev->ops->auth) {
1402 i++;
1403 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001404 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001405 }
1406
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 if (dev->ops->disconnect || dev->ops->deauth) {
1408 i++;
1409 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1410 goto nla_put_failure;
1411 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001412
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 nla_nest_end(msg, nl_cmds);
1414 (*split_start)++;
1415 if (split)
1416 break;
1417 case 5:
1418 if (dev->ops->remain_on_channel &&
1419 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1420 nla_put_u32(msg,
1421 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1422 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001423 goto nla_put_failure;
1424
Johannes Berg3713b4e2013-02-14 16:19:38 +01001425 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1426 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1427 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001428
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1430 goto nla_put_failure;
1431 (*split_start)++;
1432 if (split)
1433 break;
1434 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001435#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001436 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 goto nla_put_failure;
1438 (*split_start)++;
1439 if (split)
1440 break;
1441#else
1442 (*split_start)++;
1443#endif
1444 case 7:
1445 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1446 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001447 goto nla_put_failure;
1448
Johannes Bergcdc89b92013-02-18 23:54:36 +01001449 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001451
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 (*split_start)++;
1453 if (split)
1454 break;
1455 case 8:
1456 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1457 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1458 dev->wiphy.ap_sme_capa))
1459 goto nla_put_failure;
1460
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001461 features = dev->wiphy.features;
1462 /*
1463 * We can only add the per-channel limit information if the
1464 * dump is split, otherwise it makes it too big. Therefore
1465 * only advertise it in that case.
1466 */
1467 if (split)
1468 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1469 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 goto nla_put_failure;
1471
1472 if (dev->wiphy.ht_capa_mod_mask &&
1473 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1474 sizeof(*dev->wiphy.ht_capa_mod_mask),
1475 dev->wiphy.ht_capa_mod_mask))
1476 goto nla_put_failure;
1477
1478 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1479 dev->wiphy.max_acl_mac_addrs &&
1480 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1481 dev->wiphy.max_acl_mac_addrs))
1482 goto nla_put_failure;
1483
1484 /*
1485 * Any information below this point is only available to
1486 * applications that can deal with it being split. This
1487 * helps ensure that newly added capabilities don't break
1488 * older tools by overrunning their buffers.
1489 *
1490 * We still increment split_start so that in the split
1491 * case we'll continue with more data in the next round,
1492 * but break unconditionally so unsplit data stops here.
1493 */
1494 (*split_start)++;
1495 break;
1496 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001497 if (dev->wiphy.extended_capabilities &&
1498 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1499 dev->wiphy.extended_capabilities_len,
1500 dev->wiphy.extended_capabilities) ||
1501 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1502 dev->wiphy.extended_capabilities_len,
1503 dev->wiphy.extended_capabilities_mask)))
1504 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505
Johannes Bergee2aca32013-02-21 17:36:01 +01001506 if (dev->wiphy.vht_capa_mod_mask &&
1507 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1508 sizeof(*dev->wiphy.vht_capa_mod_mask),
1509 dev->wiphy.vht_capa_mod_mask))
1510 goto nla_put_failure;
1511
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 /* done */
1513 *split_start = 0;
1514 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001515 }
Johannes Berg55682962007-09-20 13:09:35 -04001516 return genlmsg_end(msg, hdr);
1517
1518 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001519 genlmsg_cancel(msg, hdr);
1520 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001521}
1522
1523static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1524{
Johannes Berg645e77d2013-03-01 14:03:49 +01001525 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001526 int start = cb->args[0];
1527 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 s64 filter_wiphy = -1;
1529 bool split = false;
1530 struct nlattr **tb = nl80211_fam.attrbuf;
1531 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001532
Johannes Berg5fe231e2013-05-08 21:45:15 +02001533 rtnl_lock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1535 tb, nl80211_fam.maxattr, nl80211_policy);
1536 if (res == 0) {
1537 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1538 if (tb[NL80211_ATTR_WIPHY])
1539 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1540 if (tb[NL80211_ATTR_WDEV])
1541 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1542 if (tb[NL80211_ATTR_IFINDEX]) {
1543 struct net_device *netdev;
1544 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1545
1546 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg940d0ac2013-06-11 16:51:03 +02001547 if (!netdev) {
1548 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 return -ENODEV;
Johannes Berg940d0ac2013-06-11 16:51:03 +02001550 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 if (netdev->ieee80211_ptr) {
1552 dev = wiphy_to_dev(
1553 netdev->ieee80211_ptr->wiphy);
1554 filter_wiphy = dev->wiphy_idx;
1555 }
1556 dev_put(netdev);
1557 }
1558 }
1559
Johannes Berg79c97e92009-07-07 03:56:12 +02001560 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001561 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1562 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001563 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001564 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1566 continue;
1567 /* attempt to fit multiple wiphy data chunks into the skb */
1568 do {
1569 ret = nl80211_send_wiphy(dev, skb,
1570 NETLINK_CB(cb->skb).portid,
1571 cb->nlh->nlmsg_seq,
1572 NLM_F_MULTI,
1573 split, &cb->args[1],
1574 &cb->args[2],
1575 &cb->args[3]);
1576 if (ret < 0) {
1577 /*
1578 * If sending the wiphy data didn't fit (ENOBUFS
1579 * or EMSGSIZE returned), this SKB is still
1580 * empty (so it's not too big because another
1581 * wiphy dataset is already in the skb) and
1582 * we've not tried to adjust the dump allocation
1583 * yet ... then adjust the alloc size to be
1584 * bigger, and return 1 but with the empty skb.
1585 * This results in an empty message being RX'ed
1586 * in userspace, but that is ignored.
1587 *
1588 * We can then retry with the larger buffer.
1589 */
1590 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1591 !skb->len &&
1592 cb->min_dump_alloc < 4096) {
1593 cb->min_dump_alloc = 4096;
Johannes Berg940d0ac2013-06-11 16:51:03 +02001594 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 return 1;
1596 }
1597 idx--;
1598 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001599 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 } while (cb->args[1] > 0);
1601 break;
Johannes Berg55682962007-09-20 13:09:35 -04001602 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001603 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001604
1605 cb->args[0] = idx;
1606
1607 return skb->len;
1608}
1609
1610static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1611{
1612 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001613 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001614
Johannes Berg645e77d2013-03-01 14:03:49 +01001615 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001616 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001617 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001618
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1620 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001621 nlmsg_free(msg);
1622 return -ENOBUFS;
1623 }
Johannes Berg55682962007-09-20 13:09:35 -04001624
Johannes Berg134e6372009-07-10 09:51:34 +00001625 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001626}
1627
Jouni Malinen31888482008-10-30 16:59:24 +02001628static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1629 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1630 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1631 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1632 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1633 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1634};
1635
1636static int parse_txq_params(struct nlattr *tb[],
1637 struct ieee80211_txq_params *txq_params)
1638{
Johannes Berga3304b02012-03-28 11:04:24 +02001639 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001640 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1641 !tb[NL80211_TXQ_ATTR_AIFS])
1642 return -EINVAL;
1643
Johannes Berga3304b02012-03-28 11:04:24 +02001644 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001645 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1646 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1647 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1648 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1649
Johannes Berga3304b02012-03-28 11:04:24 +02001650 if (txq_params->ac >= NL80211_NUM_ACS)
1651 return -EINVAL;
1652
Jouni Malinen31888482008-10-30 16:59:24 +02001653 return 0;
1654}
1655
Johannes Bergf444de02010-05-05 15:25:02 +02001656static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1657{
1658 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001659 * You can only set the channel explicitly for WDS interfaces,
1660 * all others have their channel managed via their respective
1661 * "establish a connection" command (connect, join, ...)
1662 *
1663 * For AP/GO and mesh mode, the channel can be set with the
1664 * channel userspace API, but is only stored and passed to the
1665 * low-level driver when the AP starts or the mesh is joined.
1666 * This is for backward compatibility, userspace can also give
1667 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001668 *
1669 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001670 * whatever else is going on, so they have their own special
1671 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001672 */
1673 return !wdev ||
1674 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001675 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001676 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1677 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001678}
1679
Johannes Berg683b6d32012-11-08 21:25:48 +01001680static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1681 struct genl_info *info,
1682 struct cfg80211_chan_def *chandef)
1683{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301684 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001685
1686 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1687 return -EINVAL;
1688
1689 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1690
1691 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001692 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1693 chandef->center_freq1 = control_freq;
1694 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001695
1696 /* Primary channel not allowed */
1697 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1698 return -EINVAL;
1699
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001700 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1701 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001702
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001703 chantype = nla_get_u32(
1704 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1705
1706 switch (chantype) {
1707 case NL80211_CHAN_NO_HT:
1708 case NL80211_CHAN_HT20:
1709 case NL80211_CHAN_HT40PLUS:
1710 case NL80211_CHAN_HT40MINUS:
1711 cfg80211_chandef_create(chandef, chandef->chan,
1712 chantype);
1713 break;
1714 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001715 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001716 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001717 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1718 chandef->width =
1719 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1720 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1721 chandef->center_freq1 =
1722 nla_get_u32(
1723 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1724 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1725 chandef->center_freq2 =
1726 nla_get_u32(
1727 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1728 }
1729
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001730 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001731 return -EINVAL;
1732
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001733 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1734 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001735 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001736
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001737 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1738 chandef->width == NL80211_CHAN_WIDTH_10) &&
1739 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1740 return -EINVAL;
1741
Johannes Berg683b6d32012-11-08 21:25:48 +01001742 return 0;
1743}
1744
Johannes Bergf444de02010-05-05 15:25:02 +02001745static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1746 struct wireless_dev *wdev,
1747 struct genl_info *info)
1748{
Johannes Berg683b6d32012-11-08 21:25:48 +01001749 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001750 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001751 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1752
1753 if (wdev)
1754 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001755
Johannes Bergf444de02010-05-05 15:25:02 +02001756 if (!nl80211_can_set_dev_channel(wdev))
1757 return -EOPNOTSUPP;
1758
Johannes Berg683b6d32012-11-08 21:25:48 +01001759 result = nl80211_parse_chandef(rdev, info, &chandef);
1760 if (result)
1761 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001762
Johannes Berge8c9bd52012-06-06 08:18:22 +02001763 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001764 case NL80211_IFTYPE_AP:
1765 case NL80211_IFTYPE_P2P_GO:
1766 if (wdev->beacon_interval) {
1767 result = -EBUSY;
1768 break;
1769 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001771 result = -EINVAL;
1772 break;
1773 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001774 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001775 result = 0;
1776 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001777 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001778 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001779 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001780 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001781 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001782 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001783 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001784 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001785 }
Johannes Bergf444de02010-05-05 15:25:02 +02001786
1787 return result;
1788}
1789
1790static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1791{
Johannes Berg4c476992010-10-04 21:36:35 +02001792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1793 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001794
Johannes Berg4c476992010-10-04 21:36:35 +02001795 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001796}
1797
Bill Jordane8347eb2010-10-01 13:54:28 -04001798static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1799{
Johannes Berg43b19952010-10-07 13:10:30 +02001800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1801 struct net_device *dev = info->user_ptr[1];
1802 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001803 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001804
1805 if (!info->attrs[NL80211_ATTR_MAC])
1806 return -EINVAL;
1807
Johannes Berg43b19952010-10-07 13:10:30 +02001808 if (netif_running(dev))
1809 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001810
Johannes Berg43b19952010-10-07 13:10:30 +02001811 if (!rdev->ops->set_wds_peer)
1812 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001813
Johannes Berg43b19952010-10-07 13:10:30 +02001814 if (wdev->iftype != NL80211_IFTYPE_WDS)
1815 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001816
1817 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001818 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001819}
1820
1821
Johannes Berg55682962007-09-20 13:09:35 -04001822static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1823{
1824 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001825 struct net_device *netdev = NULL;
1826 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001827 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001828 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001829 u32 changed;
1830 u8 retry_short = 0, retry_long = 0;
1831 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001832 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001833
Johannes Berg5fe231e2013-05-08 21:45:15 +02001834 ASSERT_RTNL();
1835
Johannes Bergf444de02010-05-05 15:25:02 +02001836 /*
1837 * Try to find the wiphy and netdev. Normally this
1838 * function shouldn't need the netdev, but this is
1839 * done for backward compatibility -- previously
1840 * setting the channel was done per wiphy, but now
1841 * it is per netdev. Previous userland like hostapd
1842 * also passed a netdev to set_wiphy, so that it is
1843 * possible to let that go to the right netdev!
1844 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001845
Johannes Bergf444de02010-05-05 15:25:02 +02001846 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1847 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1848
1849 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001850 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001851 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001852 else
Johannes Bergf444de02010-05-05 15:25:02 +02001853 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001854 }
1855
Johannes Bergf444de02010-05-05 15:25:02 +02001856 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001857 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1858 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001859 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001860 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001861 wdev = NULL;
1862 netdev = NULL;
1863 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001864 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001865 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001866
1867 /*
1868 * end workaround code, by now the rdev is available
1869 * and locked, and wdev may or may not be NULL.
1870 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001871
1872 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001873 result = cfg80211_dev_rename(
1874 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001875
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001876 if (result)
1877 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001878
Jouni Malinen31888482008-10-30 16:59:24 +02001879 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1880 struct ieee80211_txq_params txq_params;
1881 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1882
1883 if (!rdev->ops->set_txq_params) {
1884 result = -EOPNOTSUPP;
1885 goto bad_res;
1886 }
1887
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001888 if (!netdev) {
1889 result = -EINVAL;
1890 goto bad_res;
1891 }
1892
Johannes Berg133a3ff2011-11-03 14:50:13 +01001893 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1894 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1895 result = -EINVAL;
1896 goto bad_res;
1897 }
1898
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001899 if (!netif_running(netdev)) {
1900 result = -ENETDOWN;
1901 goto bad_res;
1902 }
1903
Jouni Malinen31888482008-10-30 16:59:24 +02001904 nla_for_each_nested(nl_txq_params,
1905 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1906 rem_txq_params) {
1907 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1908 nla_data(nl_txq_params),
1909 nla_len(nl_txq_params),
1910 txq_params_policy);
1911 result = parse_txq_params(tb, &txq_params);
1912 if (result)
1913 goto bad_res;
1914
Hila Gonene35e4d22012-06-27 17:19:42 +03001915 result = rdev_set_txq_params(rdev, netdev,
1916 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001917 if (result)
1918 goto bad_res;
1919 }
1920 }
1921
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001922 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001923 result = __nl80211_set_channel(rdev,
1924 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1925 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001926 if (result)
1927 goto bad_res;
1928 }
1929
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001930 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001931 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001932 enum nl80211_tx_power_setting type;
1933 int idx, mbm = 0;
1934
Johannes Bergc8442112012-10-24 10:17:18 +02001935 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1936 txp_wdev = NULL;
1937
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001938 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001939 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001940 goto bad_res;
1941 }
1942
1943 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1944 type = nla_get_u32(info->attrs[idx]);
1945
1946 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1947 (type != NL80211_TX_POWER_AUTOMATIC)) {
1948 result = -EINVAL;
1949 goto bad_res;
1950 }
1951
1952 if (type != NL80211_TX_POWER_AUTOMATIC) {
1953 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1954 mbm = nla_get_u32(info->attrs[idx]);
1955 }
1956
Johannes Bergc8442112012-10-24 10:17:18 +02001957 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001958 if (result)
1959 goto bad_res;
1960 }
1961
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001962 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1963 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1964 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001965 if ((!rdev->wiphy.available_antennas_tx &&
1966 !rdev->wiphy.available_antennas_rx) ||
1967 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001968 result = -EOPNOTSUPP;
1969 goto bad_res;
1970 }
1971
1972 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1973 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1974
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001975 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001976 * available antenna masks, except for the "all" mask */
1977 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1978 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001979 result = -EINVAL;
1980 goto bad_res;
1981 }
1982
Bruno Randolf7f531e02010-12-16 11:30:22 +09001983 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1984 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001985
Hila Gonene35e4d22012-06-27 17:19:42 +03001986 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001987 if (result)
1988 goto bad_res;
1989 }
1990
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001991 changed = 0;
1992
1993 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1994 retry_short = nla_get_u8(
1995 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1996 if (retry_short == 0) {
1997 result = -EINVAL;
1998 goto bad_res;
1999 }
2000 changed |= WIPHY_PARAM_RETRY_SHORT;
2001 }
2002
2003 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2004 retry_long = nla_get_u8(
2005 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2006 if (retry_long == 0) {
2007 result = -EINVAL;
2008 goto bad_res;
2009 }
2010 changed |= WIPHY_PARAM_RETRY_LONG;
2011 }
2012
2013 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2014 frag_threshold = nla_get_u32(
2015 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2016 if (frag_threshold < 256) {
2017 result = -EINVAL;
2018 goto bad_res;
2019 }
2020 if (frag_threshold != (u32) -1) {
2021 /*
2022 * Fragments (apart from the last one) are required to
2023 * have even length. Make the fragmentation code
2024 * simpler by stripping LSB should someone try to use
2025 * odd threshold value.
2026 */
2027 frag_threshold &= ~0x1;
2028 }
2029 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2030 }
2031
2032 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2033 rts_threshold = nla_get_u32(
2034 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2035 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2036 }
2037
Lukáš Turek81077e82009-12-21 22:50:47 +01002038 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2039 coverage_class = nla_get_u8(
2040 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2041 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2042 }
2043
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002044 if (changed) {
2045 u8 old_retry_short, old_retry_long;
2046 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002047 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002048
2049 if (!rdev->ops->set_wiphy_params) {
2050 result = -EOPNOTSUPP;
2051 goto bad_res;
2052 }
2053
2054 old_retry_short = rdev->wiphy.retry_short;
2055 old_retry_long = rdev->wiphy.retry_long;
2056 old_frag_threshold = rdev->wiphy.frag_threshold;
2057 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002058 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002059
2060 if (changed & WIPHY_PARAM_RETRY_SHORT)
2061 rdev->wiphy.retry_short = retry_short;
2062 if (changed & WIPHY_PARAM_RETRY_LONG)
2063 rdev->wiphy.retry_long = retry_long;
2064 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2065 rdev->wiphy.frag_threshold = frag_threshold;
2066 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2067 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002068 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2069 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070
Hila Gonene35e4d22012-06-27 17:19:42 +03002071 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002072 if (result) {
2073 rdev->wiphy.retry_short = old_retry_short;
2074 rdev->wiphy.retry_long = old_retry_long;
2075 rdev->wiphy.frag_threshold = old_frag_threshold;
2076 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002077 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002078 }
2079 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002080
Johannes Berg306d6112008-12-08 12:39:04 +01002081 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002082 if (netdev)
2083 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002084 return result;
2085}
2086
Johannes Berg71bbc992012-06-15 15:30:18 +02002087static inline u64 wdev_id(struct wireless_dev *wdev)
2088{
2089 return (u64)wdev->identifier |
2090 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2091}
Johannes Berg55682962007-09-20 13:09:35 -04002092
Johannes Berg683b6d32012-11-08 21:25:48 +01002093static int nl80211_send_chandef(struct sk_buff *msg,
2094 struct cfg80211_chan_def *chandef)
2095{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002096 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002097
Johannes Berg683b6d32012-11-08 21:25:48 +01002098 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2099 chandef->chan->center_freq))
2100 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002101 switch (chandef->width) {
2102 case NL80211_CHAN_WIDTH_20_NOHT:
2103 case NL80211_CHAN_WIDTH_20:
2104 case NL80211_CHAN_WIDTH_40:
2105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2106 cfg80211_get_chandef_type(chandef)))
2107 return -ENOBUFS;
2108 break;
2109 default:
2110 break;
2111 }
2112 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2113 return -ENOBUFS;
2114 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2115 return -ENOBUFS;
2116 if (chandef->center_freq2 &&
2117 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002118 return -ENOBUFS;
2119 return 0;
2120}
2121
Eric W. Biederman15e47302012-09-07 20:12:54 +00002122static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002123 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002124 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002125{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002126 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002127 void *hdr;
2128
Eric W. Biederman15e47302012-09-07 20:12:54 +00002129 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002130 if (!hdr)
2131 return -1;
2132
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002133 if (dev &&
2134 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002135 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002136 goto nla_put_failure;
2137
2138 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2139 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002140 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002141 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002142 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2143 rdev->devlist_generation ^
2144 (cfg80211_rdev_list_generation << 2)))
2145 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002146
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002147 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002148 int ret;
2149 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002150
Johannes Berg683b6d32012-11-08 21:25:48 +01002151 ret = rdev_get_channel(rdev, wdev, &chandef);
2152 if (ret == 0) {
2153 if (nl80211_send_chandef(msg, &chandef))
2154 goto nla_put_failure;
2155 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002156 }
2157
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002158 if (wdev->ssid_len) {
2159 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2160 goto nla_put_failure;
2161 }
2162
Johannes Berg55682962007-09-20 13:09:35 -04002163 return genlmsg_end(msg, hdr);
2164
2165 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002166 genlmsg_cancel(msg, hdr);
2167 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002168}
2169
2170static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2171{
2172 int wp_idx = 0;
2173 int if_idx = 0;
2174 int wp_start = cb->args[0];
2175 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002176 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002177 struct wireless_dev *wdev;
2178
Johannes Berg5fe231e2013-05-08 21:45:15 +02002179 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002180 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2181 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002182 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002183 if (wp_idx < wp_start) {
2184 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002185 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002186 }
Johannes Berg55682962007-09-20 13:09:35 -04002187 if_idx = 0;
2188
Johannes Berg89a54e42012-06-15 14:33:17 +02002189 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002190 if (if_idx < if_start) {
2191 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002192 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002194 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002195 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002196 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002197 goto out;
2198 }
2199 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002200 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002201
2202 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002203 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002204 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002205 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002206
2207 cb->args[0] = wp_idx;
2208 cb->args[1] = if_idx;
2209
2210 return skb->len;
2211}
2212
2213static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2214{
2215 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002216 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002217 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002218
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002219 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002220 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002221 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002222
Eric W. Biederman15e47302012-09-07 20:12:54 +00002223 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002224 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002225 nlmsg_free(msg);
2226 return -ENOBUFS;
2227 }
Johannes Berg55682962007-09-20 13:09:35 -04002228
Johannes Berg134e6372009-07-10 09:51:34 +00002229 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002230}
2231
Michael Wu66f7ac52008-01-31 19:48:22 +01002232static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2233 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2234 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2235 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2236 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2237 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002238 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002239};
2240
2241static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2242{
2243 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2244 int flag;
2245
2246 *mntrflags = 0;
2247
2248 if (!nla)
2249 return -EINVAL;
2250
2251 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2252 nla, mntr_flags_policy))
2253 return -EINVAL;
2254
2255 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2256 if (flags[flag])
2257 *mntrflags |= (1<<flag);
2258
2259 return 0;
2260}
2261
Johannes Berg9bc383d2009-11-19 11:55:19 +01002262static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002263 struct net_device *netdev, u8 use_4addr,
2264 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002265{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002266 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002267 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002268 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002269 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002270 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002271
2272 switch (iftype) {
2273 case NL80211_IFTYPE_AP_VLAN:
2274 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2275 return 0;
2276 break;
2277 case NL80211_IFTYPE_STATION:
2278 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2279 return 0;
2280 break;
2281 default:
2282 break;
2283 }
2284
2285 return -EOPNOTSUPP;
2286}
2287
Johannes Berg55682962007-09-20 13:09:35 -04002288static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2289{
Johannes Berg4c476992010-10-04 21:36:35 +02002290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002291 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002292 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002293 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002294 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002295 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002296 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002297
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002298 memset(&params, 0, sizeof(params));
2299
Johannes Berg04a773a2009-04-19 21:24:32 +02002300 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002301
Johannes Berg723b0382008-09-16 20:22:09 +02002302 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002303 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002304 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002305 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002306 if (ntype > NL80211_IFTYPE_MAX)
2307 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002308 }
2309
Johannes Berg92ffe052008-09-16 20:39:36 +02002310 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002311 struct wireless_dev *wdev = dev->ieee80211_ptr;
2312
Johannes Berg4c476992010-10-04 21:36:35 +02002313 if (ntype != NL80211_IFTYPE_MESH_POINT)
2314 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002315 if (netif_running(dev))
2316 return -EBUSY;
2317
2318 wdev_lock(wdev);
2319 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2320 IEEE80211_MAX_MESH_ID_LEN);
2321 wdev->mesh_id_up_len =
2322 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2323 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2324 wdev->mesh_id_up_len);
2325 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002326 }
2327
Felix Fietkau8b787642009-11-10 18:53:10 +01002328 if (info->attrs[NL80211_ATTR_4ADDR]) {
2329 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2330 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002331 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002332 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002333 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002334 } else {
2335 params.use_4addr = -1;
2336 }
2337
Johannes Berg92ffe052008-09-16 20:39:36 +02002338 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002339 if (ntype != NL80211_IFTYPE_MONITOR)
2340 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002341 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2342 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002343 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002344 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002345
2346 flags = &_flags;
2347 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002348 }
Johannes Berg3b858752009-03-12 09:55:09 +01002349
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002350 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2351 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2352 return -EOPNOTSUPP;
2353
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002354 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002355 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002356 else
2357 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002358
Johannes Berg9bc383d2009-11-19 11:55:19 +01002359 if (!err && params.use_4addr != -1)
2360 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2361
Johannes Berg55682962007-09-20 13:09:35 -04002362 return err;
2363}
2364
2365static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2366{
Johannes Berg4c476992010-10-04 21:36:35 +02002367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002368 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002369 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002370 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002371 int err;
2372 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002373 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002374
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002375 memset(&params, 0, sizeof(params));
2376
Johannes Berg55682962007-09-20 13:09:35 -04002377 if (!info->attrs[NL80211_ATTR_IFNAME])
2378 return -EINVAL;
2379
2380 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2381 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2382 if (type > NL80211_IFTYPE_MAX)
2383 return -EINVAL;
2384 }
2385
Johannes Berg79c97e92009-07-07 03:56:12 +02002386 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002387 !(rdev->wiphy.interface_modes & (1 << type)))
2388 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002389
Arend van Spriel1c18f142013-01-08 10:17:27 +01002390 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2391 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2392 ETH_ALEN);
2393 if (!is_valid_ether_addr(params.macaddr))
2394 return -EADDRNOTAVAIL;
2395 }
2396
Johannes Berg9bc383d2009-11-19 11:55:19 +01002397 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002398 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002399 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002400 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002401 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002402 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002403
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002404 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2405 if (!msg)
2406 return -ENOMEM;
2407
Michael Wu66f7ac52008-01-31 19:48:22 +01002408 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2409 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2410 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002411
2412 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2413 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2414 return -EOPNOTSUPP;
2415
Hila Gonene35e4d22012-06-27 17:19:42 +03002416 wdev = rdev_add_virtual_intf(rdev,
2417 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2418 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002419 if (IS_ERR(wdev)) {
2420 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002421 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002422 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002423
Johannes Berg98104fde2012-06-16 00:19:54 +02002424 switch (type) {
2425 case NL80211_IFTYPE_MESH_POINT:
2426 if (!info->attrs[NL80211_ATTR_MESH_ID])
2427 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002428 wdev_lock(wdev);
2429 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2430 IEEE80211_MAX_MESH_ID_LEN);
2431 wdev->mesh_id_up_len =
2432 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2433 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2434 wdev->mesh_id_up_len);
2435 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002436 break;
2437 case NL80211_IFTYPE_P2P_DEVICE:
2438 /*
2439 * P2P Device doesn't have a netdev, so doesn't go
2440 * through the netdev notifier and must be added here
2441 */
2442 mutex_init(&wdev->mtx);
2443 INIT_LIST_HEAD(&wdev->event_list);
2444 spin_lock_init(&wdev->event_lock);
2445 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2446 spin_lock_init(&wdev->mgmt_registrations_lock);
2447
Johannes Berg98104fde2012-06-16 00:19:54 +02002448 wdev->identifier = ++rdev->wdev_id;
2449 list_add_rcu(&wdev->list, &rdev->wdev_list);
2450 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002451 break;
2452 default:
2453 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002454 }
2455
Eric W. Biederman15e47302012-09-07 20:12:54 +00002456 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002457 rdev, wdev) < 0) {
2458 nlmsg_free(msg);
2459 return -ENOBUFS;
2460 }
2461
2462 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002463}
2464
2465static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2466{
Johannes Berg4c476992010-10-04 21:36:35 +02002467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002468 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002469
Johannes Berg4c476992010-10-04 21:36:35 +02002470 if (!rdev->ops->del_virtual_intf)
2471 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002472
Johannes Berg84efbb82012-06-16 00:00:26 +02002473 /*
2474 * If we remove a wireless device without a netdev then clear
2475 * user_ptr[1] so that nl80211_post_doit won't dereference it
2476 * to check if it needs to do dev_put(). Otherwise it crashes
2477 * since the wdev has been freed, unlike with a netdev where
2478 * we need the dev_put() for the netdev to really be freed.
2479 */
2480 if (!wdev->netdev)
2481 info->user_ptr[1] = NULL;
2482
Hila Gonene35e4d22012-06-27 17:19:42 +03002483 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002484}
2485
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002486static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2487{
2488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2489 struct net_device *dev = info->user_ptr[1];
2490 u16 noack_map;
2491
2492 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2493 return -EINVAL;
2494
2495 if (!rdev->ops->set_noack_map)
2496 return -EOPNOTSUPP;
2497
2498 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2499
Hila Gonene35e4d22012-06-27 17:19:42 +03002500 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002501}
2502
Johannes Berg41ade002007-12-19 02:03:29 +01002503struct get_key_cookie {
2504 struct sk_buff *msg;
2505 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002506 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002507};
2508
2509static void get_key_callback(void *c, struct key_params *params)
2510{
Johannes Bergb9454e82009-07-08 13:29:08 +02002511 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002512 struct get_key_cookie *cookie = c;
2513
David S. Miller9360ffd2012-03-29 04:41:26 -04002514 if ((params->key &&
2515 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2516 params->key_len, params->key)) ||
2517 (params->seq &&
2518 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2519 params->seq_len, params->seq)) ||
2520 (params->cipher &&
2521 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2522 params->cipher)))
2523 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002524
Johannes Bergb9454e82009-07-08 13:29:08 +02002525 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2526 if (!key)
2527 goto nla_put_failure;
2528
David S. Miller9360ffd2012-03-29 04:41:26 -04002529 if ((params->key &&
2530 nla_put(cookie->msg, NL80211_KEY_DATA,
2531 params->key_len, params->key)) ||
2532 (params->seq &&
2533 nla_put(cookie->msg, NL80211_KEY_SEQ,
2534 params->seq_len, params->seq)) ||
2535 (params->cipher &&
2536 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2537 params->cipher)))
2538 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002539
David S. Miller9360ffd2012-03-29 04:41:26 -04002540 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2541 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002542
2543 nla_nest_end(cookie->msg, key);
2544
Johannes Berg41ade002007-12-19 02:03:29 +01002545 return;
2546 nla_put_failure:
2547 cookie->error = 1;
2548}
2549
2550static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2551{
Johannes Berg4c476992010-10-04 21:36:35 +02002552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002553 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002554 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002555 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002556 const u8 *mac_addr = NULL;
2557 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002558 struct get_key_cookie cookie = {
2559 .error = 0,
2560 };
2561 void *hdr;
2562 struct sk_buff *msg;
2563
2564 if (info->attrs[NL80211_ATTR_KEY_IDX])
2565 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2566
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002567 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002568 return -EINVAL;
2569
2570 if (info->attrs[NL80211_ATTR_MAC])
2571 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2572
Johannes Berge31b8212010-10-05 19:39:30 +02002573 pairwise = !!mac_addr;
2574 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2575 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2576 if (kt >= NUM_NL80211_KEYTYPES)
2577 return -EINVAL;
2578 if (kt != NL80211_KEYTYPE_GROUP &&
2579 kt != NL80211_KEYTYPE_PAIRWISE)
2580 return -EINVAL;
2581 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2582 }
2583
Johannes Berg4c476992010-10-04 21:36:35 +02002584 if (!rdev->ops->get_key)
2585 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002586
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002588 if (!msg)
2589 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002590
Eric W. Biederman15e47302012-09-07 20:12:54 +00002591 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002592 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002593 if (IS_ERR(hdr))
2594 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002595
2596 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002597 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002598
David S. Miller9360ffd2012-03-29 04:41:26 -04002599 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2600 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2601 goto nla_put_failure;
2602 if (mac_addr &&
2603 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2604 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002605
Johannes Berge31b8212010-10-05 19:39:30 +02002606 if (pairwise && mac_addr &&
2607 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2608 return -ENOENT;
2609
Hila Gonene35e4d22012-06-27 17:19:42 +03002610 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2611 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002612
2613 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002614 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002615
2616 if (cookie.error)
2617 goto nla_put_failure;
2618
2619 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002620 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002621
2622 nla_put_failure:
2623 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002624 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002625 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002626 return err;
2627}
2628
2629static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2630{
Johannes Berg4c476992010-10-04 21:36:35 +02002631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002632 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002633 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002634 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002635
Johannes Bergb9454e82009-07-08 13:29:08 +02002636 err = nl80211_parse_key(info, &key);
2637 if (err)
2638 return err;
2639
2640 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002641 return -EINVAL;
2642
Johannes Bergb9454e82009-07-08 13:29:08 +02002643 /* only support setting default key */
2644 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002645 return -EINVAL;
2646
Johannes Bergfffd0932009-07-08 14:22:54 +02002647 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002648
2649 if (key.def) {
2650 if (!rdev->ops->set_default_key) {
2651 err = -EOPNOTSUPP;
2652 goto out;
2653 }
2654
2655 err = nl80211_key_allowed(dev->ieee80211_ptr);
2656 if (err)
2657 goto out;
2658
Hila Gonene35e4d22012-06-27 17:19:42 +03002659 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002660 key.def_uni, key.def_multi);
2661
2662 if (err)
2663 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002664
Johannes Berg3d23e342009-09-29 23:27:28 +02002665#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002666 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002667#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002668 } else {
2669 if (key.def_uni || !key.def_multi) {
2670 err = -EINVAL;
2671 goto out;
2672 }
2673
2674 if (!rdev->ops->set_default_mgmt_key) {
2675 err = -EOPNOTSUPP;
2676 goto out;
2677 }
2678
2679 err = nl80211_key_allowed(dev->ieee80211_ptr);
2680 if (err)
2681 goto out;
2682
Hila Gonene35e4d22012-06-27 17:19:42 +03002683 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002684 if (err)
2685 goto out;
2686
2687#ifdef CONFIG_CFG80211_WEXT
2688 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2689#endif
2690 }
2691
2692 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002693 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002694
Johannes Berg41ade002007-12-19 02:03:29 +01002695 return err;
2696}
2697
2698static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2699{
Johannes Berg4c476992010-10-04 21:36:35 +02002700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002701 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002702 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002703 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002704 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002705
Johannes Bergb9454e82009-07-08 13:29:08 +02002706 err = nl80211_parse_key(info, &key);
2707 if (err)
2708 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002709
Johannes Bergb9454e82009-07-08 13:29:08 +02002710 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002711 return -EINVAL;
2712
Johannes Berg41ade002007-12-19 02:03:29 +01002713 if (info->attrs[NL80211_ATTR_MAC])
2714 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2715
Johannes Berge31b8212010-10-05 19:39:30 +02002716 if (key.type == -1) {
2717 if (mac_addr)
2718 key.type = NL80211_KEYTYPE_PAIRWISE;
2719 else
2720 key.type = NL80211_KEYTYPE_GROUP;
2721 }
2722
2723 /* for now */
2724 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2725 key.type != NL80211_KEYTYPE_GROUP)
2726 return -EINVAL;
2727
Johannes Berg4c476992010-10-04 21:36:35 +02002728 if (!rdev->ops->add_key)
2729 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002730
Johannes Berge31b8212010-10-05 19:39:30 +02002731 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2732 key.type == NL80211_KEYTYPE_PAIRWISE,
2733 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002734 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002735
2736 wdev_lock(dev->ieee80211_ptr);
2737 err = nl80211_key_allowed(dev->ieee80211_ptr);
2738 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002739 err = rdev_add_key(rdev, dev, key.idx,
2740 key.type == NL80211_KEYTYPE_PAIRWISE,
2741 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002742 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002743
Johannes Berg41ade002007-12-19 02:03:29 +01002744 return err;
2745}
2746
2747static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2748{
Johannes Berg4c476992010-10-04 21:36:35 +02002749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002750 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002751 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002752 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002753 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002754
Johannes Bergb9454e82009-07-08 13:29:08 +02002755 err = nl80211_parse_key(info, &key);
2756 if (err)
2757 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002758
2759 if (info->attrs[NL80211_ATTR_MAC])
2760 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2761
Johannes Berge31b8212010-10-05 19:39:30 +02002762 if (key.type == -1) {
2763 if (mac_addr)
2764 key.type = NL80211_KEYTYPE_PAIRWISE;
2765 else
2766 key.type = NL80211_KEYTYPE_GROUP;
2767 }
2768
2769 /* for now */
2770 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2771 key.type != NL80211_KEYTYPE_GROUP)
2772 return -EINVAL;
2773
Johannes Berg4c476992010-10-04 21:36:35 +02002774 if (!rdev->ops->del_key)
2775 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002776
Johannes Bergfffd0932009-07-08 14:22:54 +02002777 wdev_lock(dev->ieee80211_ptr);
2778 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002779
2780 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2781 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2782 err = -ENOENT;
2783
Johannes Bergfffd0932009-07-08 14:22:54 +02002784 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002785 err = rdev_del_key(rdev, dev, key.idx,
2786 key.type == NL80211_KEYTYPE_PAIRWISE,
2787 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002788
Johannes Berg3d23e342009-09-29 23:27:28 +02002789#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002790 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002791 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002792 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002793 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002794 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2795 }
2796#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002797 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002798
Johannes Berg41ade002007-12-19 02:03:29 +01002799 return err;
2800}
2801
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302802/* This function returns an error or the number of nested attributes */
2803static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2804{
2805 struct nlattr *attr;
2806 int n_entries = 0, tmp;
2807
2808 nla_for_each_nested(attr, nl_attr, tmp) {
2809 if (nla_len(attr) != ETH_ALEN)
2810 return -EINVAL;
2811
2812 n_entries++;
2813 }
2814
2815 return n_entries;
2816}
2817
2818/*
2819 * This function parses ACL information and allocates memory for ACL data.
2820 * On successful return, the calling function is responsible to free the
2821 * ACL buffer returned by this function.
2822 */
2823static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2824 struct genl_info *info)
2825{
2826 enum nl80211_acl_policy acl_policy;
2827 struct nlattr *attr;
2828 struct cfg80211_acl_data *acl;
2829 int i = 0, n_entries, tmp;
2830
2831 if (!wiphy->max_acl_mac_addrs)
2832 return ERR_PTR(-EOPNOTSUPP);
2833
2834 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2835 return ERR_PTR(-EINVAL);
2836
2837 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2838 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2839 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2840 return ERR_PTR(-EINVAL);
2841
2842 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2843 return ERR_PTR(-EINVAL);
2844
2845 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2846 if (n_entries < 0)
2847 return ERR_PTR(n_entries);
2848
2849 if (n_entries > wiphy->max_acl_mac_addrs)
2850 return ERR_PTR(-ENOTSUPP);
2851
2852 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2853 GFP_KERNEL);
2854 if (!acl)
2855 return ERR_PTR(-ENOMEM);
2856
2857 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2858 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2859 i++;
2860 }
2861
2862 acl->n_acl_entries = n_entries;
2863 acl->acl_policy = acl_policy;
2864
2865 return acl;
2866}
2867
2868static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2869{
2870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2871 struct net_device *dev = info->user_ptr[1];
2872 struct cfg80211_acl_data *acl;
2873 int err;
2874
2875 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2876 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2877 return -EOPNOTSUPP;
2878
2879 if (!dev->ieee80211_ptr->beacon_interval)
2880 return -EINVAL;
2881
2882 acl = parse_acl_data(&rdev->wiphy, info);
2883 if (IS_ERR(acl))
2884 return PTR_ERR(acl);
2885
2886 err = rdev_set_mac_acl(rdev, dev, acl);
2887
2888 kfree(acl);
2889
2890 return err;
2891}
2892
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002893static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002894 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002895{
Johannes Berg88600202012-02-13 15:17:18 +01002896 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002897
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002898 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2899 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2900 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2901 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002902 return -EINVAL;
2903
Johannes Berg88600202012-02-13 15:17:18 +01002904 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002905
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002906 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2907 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2908 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002909 if (!bcn->head_len)
2910 return -EINVAL;
2911 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002912 }
2913
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002914 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2915 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2916 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002917 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002918 }
2919
Johannes Berg4c476992010-10-04 21:36:35 +02002920 if (!haveinfo)
2921 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002922
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002923 if (attrs[NL80211_ATTR_IE]) {
2924 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2925 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002926 }
2927
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002928 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002929 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002930 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002931 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002932 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002933 }
2934
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002935 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002936 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002937 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002938 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002939 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002940 }
2941
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002942 if (attrs[NL80211_ATTR_PROBE_RESP]) {
2943 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
2944 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002945 }
2946
Johannes Berg88600202012-02-13 15:17:18 +01002947 return 0;
2948}
2949
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002950static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2951 struct cfg80211_ap_settings *params)
2952{
2953 struct wireless_dev *wdev;
2954 bool ret = false;
2955
Johannes Berg89a54e42012-06-15 14:33:17 +02002956 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002957 if (wdev->iftype != NL80211_IFTYPE_AP &&
2958 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2959 continue;
2960
Johannes Berg683b6d32012-11-08 21:25:48 +01002961 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002962 continue;
2963
Johannes Berg683b6d32012-11-08 21:25:48 +01002964 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002965 ret = true;
2966 break;
2967 }
2968
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002969 return ret;
2970}
2971
Jouni Malinene39e5b52012-09-30 19:29:39 +03002972static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2973 enum nl80211_auth_type auth_type,
2974 enum nl80211_commands cmd)
2975{
2976 if (auth_type > NL80211_AUTHTYPE_MAX)
2977 return false;
2978
2979 switch (cmd) {
2980 case NL80211_CMD_AUTHENTICATE:
2981 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2982 auth_type == NL80211_AUTHTYPE_SAE)
2983 return false;
2984 return true;
2985 case NL80211_CMD_CONNECT:
2986 case NL80211_CMD_START_AP:
2987 /* SAE not supported yet */
2988 if (auth_type == NL80211_AUTHTYPE_SAE)
2989 return false;
2990 return true;
2991 default:
2992 return false;
2993 }
2994}
2995
Johannes Berg88600202012-02-13 15:17:18 +01002996static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2997{
2998 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2999 struct net_device *dev = info->user_ptr[1];
3000 struct wireless_dev *wdev = dev->ieee80211_ptr;
3001 struct cfg80211_ap_settings params;
3002 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003003 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003004
3005 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3006 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3007 return -EOPNOTSUPP;
3008
3009 if (!rdev->ops->start_ap)
3010 return -EOPNOTSUPP;
3011
3012 if (wdev->beacon_interval)
3013 return -EALREADY;
3014
3015 memset(&params, 0, sizeof(params));
3016
3017 /* these are required for START_AP */
3018 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3019 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3020 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3021 return -EINVAL;
3022
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003023 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003024 if (err)
3025 return err;
3026
3027 params.beacon_interval =
3028 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3029 params.dtim_period =
3030 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3031
3032 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3033 if (err)
3034 return err;
3035
3036 /*
3037 * In theory, some of these attributes should be required here
3038 * but since they were not used when the command was originally
3039 * added, keep them optional for old user space programs to let
3040 * them continue to work with drivers that do not need the
3041 * additional information -- drivers must check!
3042 */
3043 if (info->attrs[NL80211_ATTR_SSID]) {
3044 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3045 params.ssid_len =
3046 nla_len(info->attrs[NL80211_ATTR_SSID]);
3047 if (params.ssid_len == 0 ||
3048 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3049 return -EINVAL;
3050 }
3051
3052 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3053 params.hidden_ssid = nla_get_u32(
3054 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3055 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3056 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3057 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3058 return -EINVAL;
3059 }
3060
3061 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3062
3063 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3064 params.auth_type = nla_get_u32(
3065 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003066 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3067 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003068 return -EINVAL;
3069 } else
3070 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3071
3072 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3073 NL80211_MAX_NR_CIPHER_SUITES);
3074 if (err)
3075 return err;
3076
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303077 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3078 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3079 return -EOPNOTSUPP;
3080 params.inactivity_timeout = nla_get_u16(
3081 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3082 }
3083
Johannes Berg53cabad2012-11-14 15:17:28 +01003084 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3085 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3086 return -EINVAL;
3087 params.p2p_ctwindow =
3088 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3089 if (params.p2p_ctwindow > 127)
3090 return -EINVAL;
3091 if (params.p2p_ctwindow != 0 &&
3092 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3093 return -EINVAL;
3094 }
3095
3096 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3097 u8 tmp;
3098
3099 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3100 return -EINVAL;
3101 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3102 if (tmp > 1)
3103 return -EINVAL;
3104 params.p2p_opp_ps = tmp;
3105 if (params.p2p_opp_ps != 0 &&
3106 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3107 return -EINVAL;
3108 }
3109
Johannes Bergaa430da2012-05-16 23:50:18 +02003110 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003111 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3112 if (err)
3113 return err;
3114 } else if (wdev->preset_chandef.chan) {
3115 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003116 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003117 return -EINVAL;
3118
Johannes Berg683b6d32012-11-08 21:25:48 +01003119 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003120 return -EINVAL;
3121
Simon Wunderlich04f39042013-02-08 18:16:19 +01003122 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3123 if (err < 0)
3124 return err;
3125 if (err) {
3126 radar_detect_width = BIT(params.chandef.width);
3127 params.radar_required = true;
3128 }
3129
Simon Wunderlich04f39042013-02-08 18:16:19 +01003130 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3131 params.chandef.chan,
3132 CHAN_MODE_SHARED,
3133 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003134 if (err)
3135 return err;
3136
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303137 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3138 params.acl = parse_acl_data(&rdev->wiphy, info);
3139 if (IS_ERR(params.acl))
3140 return PTR_ERR(params.acl);
3141 }
3142
Hila Gonene35e4d22012-06-27 17:19:42 +03003143 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003144 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003145 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003146 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003147 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003148 wdev->ssid_len = params.ssid_len;
3149 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003150 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303151
3152 kfree(params.acl);
3153
Johannes Berg56d18932011-05-09 18:41:15 +02003154 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003155}
3156
Johannes Berg88600202012-02-13 15:17:18 +01003157static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3158{
3159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3160 struct net_device *dev = info->user_ptr[1];
3161 struct wireless_dev *wdev = dev->ieee80211_ptr;
3162 struct cfg80211_beacon_data params;
3163 int err;
3164
3165 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3166 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3167 return -EOPNOTSUPP;
3168
3169 if (!rdev->ops->change_beacon)
3170 return -EOPNOTSUPP;
3171
3172 if (!wdev->beacon_interval)
3173 return -EINVAL;
3174
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003175 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003176 if (err)
3177 return err;
3178
Hila Gonene35e4d22012-06-27 17:19:42 +03003179 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003180}
3181
3182static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003183{
Johannes Berg4c476992010-10-04 21:36:35 +02003184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3185 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003186
Michal Kazior60771782012-06-29 12:46:56 +02003187 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003188}
3189
Johannes Berg5727ef12007-12-19 02:03:34 +01003190static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3191 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3192 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3193 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003194 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003195 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003196 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003197};
3198
Johannes Bergeccb8e82009-05-11 21:57:56 +03003199static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003200 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003201 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003202{
3203 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003204 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003205 int flag;
3206
Johannes Bergeccb8e82009-05-11 21:57:56 +03003207 /*
3208 * Try parsing the new attribute first so userspace
3209 * can specify both for older kernels.
3210 */
3211 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3212 if (nla) {
3213 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003214
Johannes Bergeccb8e82009-05-11 21:57:56 +03003215 sta_flags = nla_data(nla);
3216 params->sta_flags_mask = sta_flags->mask;
3217 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003218 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003219 if ((params->sta_flags_mask |
3220 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3221 return -EINVAL;
3222 return 0;
3223 }
3224
3225 /* if present, parse the old attribute */
3226
3227 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003228 if (!nla)
3229 return 0;
3230
3231 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3232 nla, sta_flags_policy))
3233 return -EINVAL;
3234
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003235 /*
3236 * Only allow certain flags for interface types so that
3237 * other attributes are silently ignored. Remember that
3238 * this is backward compatibility code with old userspace
3239 * and shouldn't be hit in other cases anyway.
3240 */
3241 switch (iftype) {
3242 case NL80211_IFTYPE_AP:
3243 case NL80211_IFTYPE_AP_VLAN:
3244 case NL80211_IFTYPE_P2P_GO:
3245 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3246 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3247 BIT(NL80211_STA_FLAG_WME) |
3248 BIT(NL80211_STA_FLAG_MFP);
3249 break;
3250 case NL80211_IFTYPE_P2P_CLIENT:
3251 case NL80211_IFTYPE_STATION:
3252 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3253 BIT(NL80211_STA_FLAG_TDLS_PEER);
3254 break;
3255 case NL80211_IFTYPE_MESH_POINT:
3256 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3257 BIT(NL80211_STA_FLAG_MFP) |
3258 BIT(NL80211_STA_FLAG_AUTHORIZED);
3259 default:
3260 return -EINVAL;
3261 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003262
Johannes Berg3383b5a2012-05-10 20:14:43 +02003263 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3264 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003265 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003266
Johannes Berg3383b5a2012-05-10 20:14:43 +02003267 /* no longer support new API additions in old API */
3268 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3269 return -EINVAL;
3270 }
3271 }
3272
Johannes Berg5727ef12007-12-19 02:03:34 +01003273 return 0;
3274}
3275
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003276static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3277 int attr)
3278{
3279 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003280 u32 bitrate;
3281 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003282
3283 rate = nla_nest_start(msg, attr);
3284 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003285 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003286
3287 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3288 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003289 /* report 16-bit bitrate only if we can */
3290 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003291 if (bitrate > 0 &&
3292 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3293 return false;
3294 if (bitrate_compat > 0 &&
3295 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3296 return false;
3297
3298 if (info->flags & RATE_INFO_FLAGS_MCS) {
3299 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3300 return false;
3301 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3302 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3303 return false;
3304 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3305 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3306 return false;
3307 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3308 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3309 return false;
3310 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3311 return false;
3312 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3313 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3314 return false;
3315 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3316 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3317 return false;
3318 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3319 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3320 return false;
3321 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3322 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3323 return false;
3324 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3325 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3326 return false;
3327 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003328
3329 nla_nest_end(msg, rate);
3330 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003331}
3332
Felix Fietkau119363c2013-04-22 16:29:30 +02003333static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3334 int id)
3335{
3336 void *attr;
3337 int i = 0;
3338
3339 if (!mask)
3340 return true;
3341
3342 attr = nla_nest_start(msg, id);
3343 if (!attr)
3344 return false;
3345
3346 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3347 if (!(mask & BIT(i)))
3348 continue;
3349
3350 if (nla_put_u8(msg, i, signal[i]))
3351 return false;
3352 }
3353
3354 nla_nest_end(msg, attr);
3355
3356 return true;
3357}
3358
Eric W. Biederman15e47302012-09-07 20:12:54 +00003359static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003360 int flags,
3361 struct cfg80211_registered_device *rdev,
3362 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003363 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003364{
3365 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003366 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003367
Eric W. Biederman15e47302012-09-07 20:12:54 +00003368 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003369 if (!hdr)
3370 return -1;
3371
David S. Miller9360ffd2012-03-29 04:41:26 -04003372 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3373 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3374 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3375 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003376
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003377 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3378 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003379 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003380 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3381 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3382 sinfo->connected_time))
3383 goto nla_put_failure;
3384 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3385 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3386 sinfo->inactive_time))
3387 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003388 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3389 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003390 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003391 (u32)sinfo->rx_bytes))
3392 goto nla_put_failure;
3393 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003394 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003395 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3396 (u32)sinfo->tx_bytes))
3397 goto nla_put_failure;
3398 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3399 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003400 sinfo->rx_bytes))
3401 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003402 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3403 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003404 sinfo->tx_bytes))
3405 goto nla_put_failure;
3406 if ((sinfo->filled & STATION_INFO_LLID) &&
3407 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3408 goto nla_put_failure;
3409 if ((sinfo->filled & STATION_INFO_PLID) &&
3410 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3411 goto nla_put_failure;
3412 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3413 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3414 sinfo->plink_state))
3415 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003416 switch (rdev->wiphy.signal_type) {
3417 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003418 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3419 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3420 sinfo->signal))
3421 goto nla_put_failure;
3422 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3423 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3424 sinfo->signal_avg))
3425 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003426 break;
3427 default:
3428 break;
3429 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003430 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3431 if (!nl80211_put_signal(msg, sinfo->chains,
3432 sinfo->chain_signal,
3433 NL80211_STA_INFO_CHAIN_SIGNAL))
3434 goto nla_put_failure;
3435 }
3436 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3437 if (!nl80211_put_signal(msg, sinfo->chains,
3438 sinfo->chain_signal_avg,
3439 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3440 goto nla_put_failure;
3441 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003442 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003443 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3444 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003445 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003446 }
3447 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3448 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3449 NL80211_STA_INFO_RX_BITRATE))
3450 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003451 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003452 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3453 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3454 sinfo->rx_packets))
3455 goto nla_put_failure;
3456 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3458 sinfo->tx_packets))
3459 goto nla_put_failure;
3460 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3461 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3462 sinfo->tx_retries))
3463 goto nla_put_failure;
3464 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3465 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3466 sinfo->tx_failed))
3467 goto nla_put_failure;
3468 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3469 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3470 sinfo->beacon_loss_count))
3471 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003472 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3473 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3474 sinfo->local_pm))
3475 goto nla_put_failure;
3476 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3477 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3478 sinfo->peer_pm))
3479 goto nla_put_failure;
3480 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3481 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3482 sinfo->nonpeer_pm))
3483 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003484 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3485 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3486 if (!bss_param)
3487 goto nla_put_failure;
3488
David S. Miller9360ffd2012-03-29 04:41:26 -04003489 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3490 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3491 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3492 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3493 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3494 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3495 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3496 sinfo->bss_param.dtim_period) ||
3497 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3498 sinfo->bss_param.beacon_interval))
3499 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003500
3501 nla_nest_end(msg, bss_param);
3502 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003503 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3504 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3505 sizeof(struct nl80211_sta_flag_update),
3506 &sinfo->sta_flags))
3507 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003508 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3509 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3510 sinfo->t_offset))
3511 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003512 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003513
David S. Miller9360ffd2012-03-29 04:41:26 -04003514 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3515 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3516 sinfo->assoc_req_ies))
3517 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003518
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003519 return genlmsg_end(msg, hdr);
3520
3521 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003522 genlmsg_cancel(msg, hdr);
3523 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003524}
3525
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003527 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003528{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529 struct station_info sinfo;
3530 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003531 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003532 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003533 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003534 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003535
Johannes Berg97990a02013-04-19 01:02:55 +02003536 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003537 if (err)
3538 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539
Johannes Berg97990a02013-04-19 01:02:55 +02003540 if (!wdev->netdev) {
3541 err = -EINVAL;
3542 goto out_err;
3543 }
3544
Johannes Bergbba95fe2008-07-29 13:22:51 +02003545 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003546 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003547 goto out_err;
3548 }
3549
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003551 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003552 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003553 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003554 if (err == -ENOENT)
3555 break;
3556 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003557 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003558
3559 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003560 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003561 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003562 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003563 &sinfo) < 0)
3564 goto out;
3565
3566 sta_idx++;
3567 }
3568
3569
3570 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003571 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003572 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003573 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003574 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003575
3576 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003577}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003578
Johannes Berg5727ef12007-12-19 02:03:34 +01003579static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3580{
Johannes Berg4c476992010-10-04 21:36:35 +02003581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3582 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003583 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584 struct sk_buff *msg;
3585 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003586 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003587
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003588 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
3590 if (!info->attrs[NL80211_ATTR_MAC])
3591 return -EINVAL;
3592
3593 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3594
Johannes Berg4c476992010-10-04 21:36:35 +02003595 if (!rdev->ops->get_station)
3596 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Hila Gonene35e4d22012-06-27 17:19:42 +03003598 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003599 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003600 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003601
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003605
Eric W. Biederman15e47302012-09-07 20:12:54 +00003606 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003607 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003608 nlmsg_free(msg);
3609 return -ENOBUFS;
3610 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003611
Johannes Berg4c476992010-10-04 21:36:35 +02003612 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003613}
3614
Johannes Berg77ee7c82013-02-15 00:48:33 +01003615int cfg80211_check_station_change(struct wiphy *wiphy,
3616 struct station_parameters *params,
3617 enum cfg80211_station_type statype)
3618{
3619 if (params->listen_interval != -1)
3620 return -EINVAL;
3621 if (params->aid)
3622 return -EINVAL;
3623
3624 /* When you run into this, adjust the code below for the new flag */
3625 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3626
3627 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003628 case CFG80211_STA_MESH_PEER_KERNEL:
3629 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003630 /*
3631 * No ignoring the TDLS flag here -- the userspace mesh
3632 * code doesn't have the bug of including TDLS in the
3633 * mask everywhere.
3634 */
3635 if (params->sta_flags_mask &
3636 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3637 BIT(NL80211_STA_FLAG_MFP) |
3638 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3639 return -EINVAL;
3640 break;
3641 case CFG80211_STA_TDLS_PEER_SETUP:
3642 case CFG80211_STA_TDLS_PEER_ACTIVE:
3643 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3644 return -EINVAL;
3645 /* ignore since it can't change */
3646 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3647 break;
3648 default:
3649 /* disallow mesh-specific things */
3650 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3651 return -EINVAL;
3652 if (params->local_pm)
3653 return -EINVAL;
3654 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3655 return -EINVAL;
3656 }
3657
3658 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3659 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3660 /* TDLS can't be set, ... */
3661 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3662 return -EINVAL;
3663 /*
3664 * ... but don't bother the driver with it. This works around
3665 * a hostapd/wpa_supplicant issue -- it always includes the
3666 * TLDS_PEER flag in the mask even for AP mode.
3667 */
3668 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3669 }
3670
3671 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3672 /* reject other things that can't change */
3673 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3674 return -EINVAL;
3675 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3676 return -EINVAL;
3677 if (params->supported_rates)
3678 return -EINVAL;
3679 if (params->ext_capab || params->ht_capa || params->vht_capa)
3680 return -EINVAL;
3681 }
3682
3683 if (statype != CFG80211_STA_AP_CLIENT) {
3684 if (params->vlan)
3685 return -EINVAL;
3686 }
3687
3688 switch (statype) {
3689 case CFG80211_STA_AP_MLME_CLIENT:
3690 /* Use this only for authorizing/unauthorizing a station */
3691 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3692 return -EOPNOTSUPP;
3693 break;
3694 case CFG80211_STA_AP_CLIENT:
3695 /* accept only the listed bits */
3696 if (params->sta_flags_mask &
3697 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3698 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3699 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3700 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3701 BIT(NL80211_STA_FLAG_WME) |
3702 BIT(NL80211_STA_FLAG_MFP)))
3703 return -EINVAL;
3704
3705 /* but authenticated/associated only if driver handles it */
3706 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3707 params->sta_flags_mask &
3708 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3709 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3710 return -EINVAL;
3711 break;
3712 case CFG80211_STA_IBSS:
3713 case CFG80211_STA_AP_STA:
3714 /* reject any changes other than AUTHORIZED */
3715 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3716 return -EINVAL;
3717 break;
3718 case CFG80211_STA_TDLS_PEER_SETUP:
3719 /* reject any changes other than AUTHORIZED or WME */
3720 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3721 BIT(NL80211_STA_FLAG_WME)))
3722 return -EINVAL;
3723 /* force (at least) rates when authorizing */
3724 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3725 !params->supported_rates)
3726 return -EINVAL;
3727 break;
3728 case CFG80211_STA_TDLS_PEER_ACTIVE:
3729 /* reject any changes */
3730 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003731 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003732 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3733 return -EINVAL;
3734 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003735 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003736 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3737 return -EINVAL;
3738 break;
3739 }
3740
3741 return 0;
3742}
3743EXPORT_SYMBOL(cfg80211_check_station_change);
3744
Johannes Berg5727ef12007-12-19 02:03:34 +01003745/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003746 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003747 */
Johannes Berg80b99892011-11-18 16:23:01 +01003748static struct net_device *get_vlan(struct genl_info *info,
3749 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003750{
Johannes Berg463d0182009-07-14 00:33:35 +02003751 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003752 struct net_device *v;
3753 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003754
Johannes Berg80b99892011-11-18 16:23:01 +01003755 if (!vlanattr)
3756 return NULL;
3757
3758 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3759 if (!v)
3760 return ERR_PTR(-ENODEV);
3761
3762 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3763 ret = -EINVAL;
3764 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003765 }
Johannes Berg80b99892011-11-18 16:23:01 +01003766
Johannes Berg77ee7c82013-02-15 00:48:33 +01003767 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3768 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3769 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3770 ret = -EINVAL;
3771 goto error;
3772 }
3773
Johannes Berg80b99892011-11-18 16:23:01 +01003774 if (!netif_running(v)) {
3775 ret = -ENETDOWN;
3776 goto error;
3777 }
3778
3779 return v;
3780 error:
3781 dev_put(v);
3782 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003783}
3784
Jouni Malinendf881292013-02-14 21:10:54 +02003785static struct nla_policy
3786nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3787 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3788 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3789};
3790
Johannes Bergff276692013-02-15 00:09:01 +01003791static int nl80211_parse_sta_wme(struct genl_info *info,
3792 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003793{
Jouni Malinendf881292013-02-14 21:10:54 +02003794 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3795 struct nlattr *nla;
3796 int err;
3797
Jouni Malinendf881292013-02-14 21:10:54 +02003798 /* parse WME attributes if present */
3799 if (!info->attrs[NL80211_ATTR_STA_WME])
3800 return 0;
3801
3802 nla = info->attrs[NL80211_ATTR_STA_WME];
3803 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3804 nl80211_sta_wme_policy);
3805 if (err)
3806 return err;
3807
3808 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3809 params->uapsd_queues = nla_get_u8(
3810 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3811 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3812 return -EINVAL;
3813
3814 if (tb[NL80211_STA_WME_MAX_SP])
3815 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3816
3817 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3818 return -EINVAL;
3819
3820 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3821
3822 return 0;
3823}
3824
Johannes Bergff276692013-02-15 00:09:01 +01003825static int nl80211_set_station_tdls(struct genl_info *info,
3826 struct station_parameters *params)
3827{
3828 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003829 if (info->attrs[NL80211_ATTR_PEER_AID])
3830 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003831 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3832 params->ht_capa =
3833 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3834 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3835 params->vht_capa =
3836 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3837
3838 return nl80211_parse_sta_wme(info, params);
3839}
3840
Johannes Berg5727ef12007-12-19 02:03:34 +01003841static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3842{
Johannes Berg4c476992010-10-04 21:36:35 +02003843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003844 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003845 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003846 u8 *mac_addr;
3847 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003848
3849 memset(&params, 0, sizeof(params));
3850
3851 params.listen_interval = -1;
3852
Johannes Berg77ee7c82013-02-15 00:48:33 +01003853 if (!rdev->ops->change_station)
3854 return -EOPNOTSUPP;
3855
Johannes Berg5727ef12007-12-19 02:03:34 +01003856 if (info->attrs[NL80211_ATTR_STA_AID])
3857 return -EINVAL;
3858
3859 if (!info->attrs[NL80211_ATTR_MAC])
3860 return -EINVAL;
3861
3862 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3863
3864 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3865 params.supported_rates =
3866 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3867 params.supported_rates_len =
3868 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3869 }
3870
Jouni Malinen9d62a982013-02-14 21:10:13 +02003871 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3872 params.capability =
3873 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3874 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3875 }
3876
3877 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3878 params.ext_capab =
3879 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3880 params.ext_capab_len =
3881 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3882 }
3883
Jouni Malinendf881292013-02-14 21:10:54 +02003884 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003885 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003886
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003887 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003888 return -EINVAL;
3889
Johannes Bergf8bacc22013-02-14 23:27:01 +01003890 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003891 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003892 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3893 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3894 return -EINVAL;
3895 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003896
Johannes Bergf8bacc22013-02-14 23:27:01 +01003897 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003898 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003899 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3900 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3901 return -EINVAL;
3902 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3903 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003904
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003905 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3906 enum nl80211_mesh_power_mode pm = nla_get_u32(
3907 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3908
3909 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3910 pm > NL80211_MESH_POWER_MAX)
3911 return -EINVAL;
3912
3913 params.local_pm = pm;
3914 }
3915
Johannes Berg77ee7c82013-02-15 00:48:33 +01003916 /* Include parameters for TDLS peer (will check later) */
3917 err = nl80211_set_station_tdls(info, &params);
3918 if (err)
3919 return err;
3920
3921 params.vlan = get_vlan(info, rdev);
3922 if (IS_ERR(params.vlan))
3923 return PTR_ERR(params.vlan);
3924
Johannes Berga97f4422009-06-18 17:23:43 +02003925 switch (dev->ieee80211_ptr->iftype) {
3926 case NL80211_IFTYPE_AP:
3927 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003928 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003929 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003930 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003931 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003932 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003933 break;
3934 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003935 err = -EOPNOTSUPP;
3936 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003937 }
3938
Johannes Berg77ee7c82013-02-15 00:48:33 +01003939 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003940 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003941
Johannes Berg77ee7c82013-02-15 00:48:33 +01003942 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003943 if (params.vlan)
3944 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003945
Johannes Berg5727ef12007-12-19 02:03:34 +01003946 return err;
3947}
3948
3949static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3950{
Johannes Berg4c476992010-10-04 21:36:35 +02003951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003952 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003953 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003954 struct station_parameters params;
3955 u8 *mac_addr = NULL;
3956
3957 memset(&params, 0, sizeof(params));
3958
Johannes Berg984c3112013-02-14 23:43:25 +01003959 if (!rdev->ops->add_station)
3960 return -EOPNOTSUPP;
3961
Johannes Berg5727ef12007-12-19 02:03:34 +01003962 if (!info->attrs[NL80211_ATTR_MAC])
3963 return -EINVAL;
3964
Johannes Berg5727ef12007-12-19 02:03:34 +01003965 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3966 return -EINVAL;
3967
3968 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3969 return -EINVAL;
3970
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003971 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3972 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003973 return -EINVAL;
3974
Johannes Berg5727ef12007-12-19 02:03:34 +01003975 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3976 params.supported_rates =
3977 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3978 params.supported_rates_len =
3979 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3980 params.listen_interval =
3981 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003982
Jouni Malinen3d124ea2013-05-27 18:24:02 +03003983 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003984 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03003985 else
3986 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003987 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3988 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003989
Jouni Malinen9d62a982013-02-14 21:10:13 +02003990 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3991 params.capability =
3992 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3993 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3994 }
3995
3996 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3997 params.ext_capab =
3998 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3999 params.ext_capab_len =
4000 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4001 }
4002
Jouni Malinen36aedc902008-08-25 11:58:58 +03004003 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4004 params.ht_capa =
4005 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004006
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004007 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4008 params.vht_capa =
4009 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4010
Johannes Bergf8bacc22013-02-14 23:27:01 +01004011 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004012 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004013 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4014 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4015 return -EINVAL;
4016 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004017
Johannes Bergff276692013-02-15 00:09:01 +01004018 err = nl80211_parse_sta_wme(info, &params);
4019 if (err)
4020 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004021
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004022 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004023 return -EINVAL;
4024
Johannes Berg77ee7c82013-02-15 00:48:33 +01004025 /* When you run into this, adjust the code below for the new flag */
4026 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4027
Johannes Bergbdd90d52011-12-14 12:20:27 +01004028 switch (dev->ieee80211_ptr->iftype) {
4029 case NL80211_IFTYPE_AP:
4030 case NL80211_IFTYPE_AP_VLAN:
4031 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004032 /* ignore WME attributes if iface/sta is not capable */
4033 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4034 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4035 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004036
Johannes Bergbdd90d52011-12-14 12:20:27 +01004037 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004038 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4039 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004040 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004041 /* but don't bother the driver with it */
4042 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004043
Johannes Bergd582cff2012-10-26 17:53:44 +02004044 /* allow authenticated/associated only if driver handles it */
4045 if (!(rdev->wiphy.features &
4046 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4047 params.sta_flags_mask &
4048 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4049 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4050 return -EINVAL;
4051
Johannes Bergbdd90d52011-12-14 12:20:27 +01004052 /* must be last in here for error handling */
4053 params.vlan = get_vlan(info, rdev);
4054 if (IS_ERR(params.vlan))
4055 return PTR_ERR(params.vlan);
4056 break;
4057 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004058 /* ignore uAPSD data */
4059 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4060
Johannes Bergd582cff2012-10-26 17:53:44 +02004061 /* associated is disallowed */
4062 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4063 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004064 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004065 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4066 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004067 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004068 break;
4069 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004070 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004071 /* ignore uAPSD data */
4072 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4073
Johannes Berg77ee7c82013-02-15 00:48:33 +01004074 /* these are disallowed */
4075 if (params.sta_flags_mask &
4076 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4077 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004078 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004079 /* Only TDLS peers can be added */
4080 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4081 return -EINVAL;
4082 /* Can only add if TDLS ... */
4083 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4084 return -EOPNOTSUPP;
4085 /* ... with external setup is supported */
4086 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4087 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004088 /*
4089 * Older wpa_supplicant versions always mark the TDLS peer
4090 * as authorized, but it shouldn't yet be.
4091 */
4092 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004093 break;
4094 default:
4095 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004096 }
4097
Johannes Bergbdd90d52011-12-14 12:20:27 +01004098 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004099
Hila Gonene35e4d22012-06-27 17:19:42 +03004100 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004101
Johannes Berg5727ef12007-12-19 02:03:34 +01004102 if (params.vlan)
4103 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004104 return err;
4105}
4106
4107static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4108{
Johannes Berg4c476992010-10-04 21:36:35 +02004109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4110 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004111 u8 *mac_addr = NULL;
4112
4113 if (info->attrs[NL80211_ATTR_MAC])
4114 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4115
Johannes Berge80cf852009-05-11 14:43:13 +02004116 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004117 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004118 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004119 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4120 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004121
Johannes Berg4c476992010-10-04 21:36:35 +02004122 if (!rdev->ops->del_station)
4123 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004124
Hila Gonene35e4d22012-06-27 17:19:42 +03004125 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004126}
4127
Eric W. Biederman15e47302012-09-07 20:12:54 +00004128static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004129 int flags, struct net_device *dev,
4130 u8 *dst, u8 *next_hop,
4131 struct mpath_info *pinfo)
4132{
4133 void *hdr;
4134 struct nlattr *pinfoattr;
4135
Eric W. Biederman15e47302012-09-07 20:12:54 +00004136 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004137 if (!hdr)
4138 return -1;
4139
David S. Miller9360ffd2012-03-29 04:41:26 -04004140 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4141 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4142 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4143 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4144 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004145
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004146 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4147 if (!pinfoattr)
4148 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004149 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4150 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4151 pinfo->frame_qlen))
4152 goto nla_put_failure;
4153 if (((pinfo->filled & MPATH_INFO_SN) &&
4154 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4155 ((pinfo->filled & MPATH_INFO_METRIC) &&
4156 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4157 pinfo->metric)) ||
4158 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4159 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4160 pinfo->exptime)) ||
4161 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4162 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4163 pinfo->flags)) ||
4164 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4165 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4166 pinfo->discovery_timeout)) ||
4167 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4168 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4169 pinfo->discovery_retries)))
4170 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004171
4172 nla_nest_end(msg, pinfoattr);
4173
4174 return genlmsg_end(msg, hdr);
4175
4176 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004177 genlmsg_cancel(msg, hdr);
4178 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004179}
4180
4181static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004182 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004183{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004184 struct mpath_info pinfo;
4185 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004186 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004187 u8 dst[ETH_ALEN];
4188 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004189 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004190 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004191
Johannes Berg97990a02013-04-19 01:02:55 +02004192 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004193 if (err)
4194 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004195
4196 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004197 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004198 goto out_err;
4199 }
4200
Johannes Berg97990a02013-04-19 01:02:55 +02004201 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004202 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004203 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004204 }
4205
Johannes Bergbba95fe2008-07-29 13:22:51 +02004206 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004207 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4208 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004209 if (err == -ENOENT)
4210 break;
4211 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004212 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004213
Eric W. Biederman15e47302012-09-07 20:12:54 +00004214 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004215 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004216 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004217 &pinfo) < 0)
4218 goto out;
4219
4220 path_idx++;
4221 }
4222
4223
4224 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004225 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004226 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004227 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004228 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004229 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004230}
4231
4232static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4233{
Johannes Berg4c476992010-10-04 21:36:35 +02004234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004235 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004236 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004237 struct mpath_info pinfo;
4238 struct sk_buff *msg;
4239 u8 *dst = NULL;
4240 u8 next_hop[ETH_ALEN];
4241
4242 memset(&pinfo, 0, sizeof(pinfo));
4243
4244 if (!info->attrs[NL80211_ATTR_MAC])
4245 return -EINVAL;
4246
4247 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4248
Johannes Berg4c476992010-10-04 21:36:35 +02004249 if (!rdev->ops->get_mpath)
4250 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004251
Johannes Berg4c476992010-10-04 21:36:35 +02004252 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4253 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004254
Hila Gonene35e4d22012-06-27 17:19:42 +03004255 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004256 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004257 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004259 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004261 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262
Eric W. Biederman15e47302012-09-07 20:12:54 +00004263 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004264 dev, dst, next_hop, &pinfo) < 0) {
4265 nlmsg_free(msg);
4266 return -ENOBUFS;
4267 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004268
Johannes Berg4c476992010-10-04 21:36:35 +02004269 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004270}
4271
4272static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4273{
Johannes Berg4c476992010-10-04 21:36:35 +02004274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4275 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004276 u8 *dst = NULL;
4277 u8 *next_hop = NULL;
4278
4279 if (!info->attrs[NL80211_ATTR_MAC])
4280 return -EINVAL;
4281
4282 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4283 return -EINVAL;
4284
4285 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4286 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4287
Johannes Berg4c476992010-10-04 21:36:35 +02004288 if (!rdev->ops->change_mpath)
4289 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004290
Johannes Berg4c476992010-10-04 21:36:35 +02004291 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4292 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004293
Hila Gonene35e4d22012-06-27 17:19:42 +03004294 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004295}
Johannes Berg4c476992010-10-04 21:36:35 +02004296
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004297static int nl80211_new_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];
4300 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004301 u8 *dst = NULL;
4302 u8 *next_hop = NULL;
4303
4304 if (!info->attrs[NL80211_ATTR_MAC])
4305 return -EINVAL;
4306
4307 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4308 return -EINVAL;
4309
4310 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4311 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4312
Johannes Berg4c476992010-10-04 21:36:35 +02004313 if (!rdev->ops->add_mpath)
4314 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004315
Johannes Berg4c476992010-10-04 21:36:35 +02004316 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4317 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004318
Hila Gonene35e4d22012-06-27 17:19:42 +03004319 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004320}
4321
4322static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4323{
Johannes Berg4c476992010-10-04 21:36:35 +02004324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4325 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004326 u8 *dst = NULL;
4327
4328 if (info->attrs[NL80211_ATTR_MAC])
4329 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4330
Johannes Berg4c476992010-10-04 21:36:35 +02004331 if (!rdev->ops->del_mpath)
4332 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004333
Hila Gonene35e4d22012-06-27 17:19:42 +03004334 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004335}
4336
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004337static int nl80211_set_bss(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];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004341 struct bss_parameters params;
4342
4343 memset(&params, 0, sizeof(params));
4344 /* default to not changing parameters */
4345 params.use_cts_prot = -1;
4346 params.use_short_preamble = -1;
4347 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004348 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004349 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004350 params.p2p_ctwindow = -1;
4351 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004352
4353 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4354 params.use_cts_prot =
4355 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4356 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4357 params.use_short_preamble =
4358 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4359 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4360 params.use_short_slot_time =
4361 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004362 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4363 params.basic_rates =
4364 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4365 params.basic_rates_len =
4366 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4367 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004368 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4369 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004370 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4371 params.ht_opmode =
4372 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004373
Johannes Berg53cabad2012-11-14 15:17:28 +01004374 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4375 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4376 return -EINVAL;
4377 params.p2p_ctwindow =
4378 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4379 if (params.p2p_ctwindow < 0)
4380 return -EINVAL;
4381 if (params.p2p_ctwindow != 0 &&
4382 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4383 return -EINVAL;
4384 }
4385
4386 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4387 u8 tmp;
4388
4389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4390 return -EINVAL;
4391 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4392 if (tmp > 1)
4393 return -EINVAL;
4394 params.p2p_opp_ps = tmp;
4395 if (params.p2p_opp_ps &&
4396 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4397 return -EINVAL;
4398 }
4399
Johannes Berg4c476992010-10-04 21:36:35 +02004400 if (!rdev->ops->change_bss)
4401 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004402
Johannes Berg074ac8d2010-09-16 14:58:22 +02004403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004404 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4405 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004406
Hila Gonene35e4d22012-06-27 17:19:42 +03004407 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004408}
4409
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004410static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004411 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4412 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4413 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4414 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4415 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4416 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4417};
4418
4419static int parse_reg_rule(struct nlattr *tb[],
4420 struct ieee80211_reg_rule *reg_rule)
4421{
4422 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4423 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4424
4425 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4426 return -EINVAL;
4427 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4428 return -EINVAL;
4429 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4430 return -EINVAL;
4431 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4432 return -EINVAL;
4433 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4434 return -EINVAL;
4435
4436 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4437
4438 freq_range->start_freq_khz =
4439 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4440 freq_range->end_freq_khz =
4441 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4442 freq_range->max_bandwidth_khz =
4443 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4444
4445 power_rule->max_eirp =
4446 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4447
4448 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4449 power_rule->max_antenna_gain =
4450 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4451
4452 return 0;
4453}
4454
4455static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4456{
4457 int r;
4458 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004459 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004460
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004461 /*
4462 * You should only get this when cfg80211 hasn't yet initialized
4463 * completely when built-in to the kernel right between the time
4464 * window between nl80211_init() and regulatory_init(), if that is
4465 * even possible.
4466 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004467 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004468 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004469
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004470 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4471 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004472
4473 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4474
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004475 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4476 user_reg_hint_type =
4477 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4478 else
4479 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4480
4481 switch (user_reg_hint_type) {
4482 case NL80211_USER_REG_HINT_USER:
4483 case NL80211_USER_REG_HINT_CELL_BASE:
4484 break;
4485 default:
4486 return -EINVAL;
4487 }
4488
4489 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004490
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004491 return r;
4492}
4493
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004494static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004495 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004496{
Johannes Berg4c476992010-10-04 21:36:35 +02004497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004498 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004499 struct wireless_dev *wdev = dev->ieee80211_ptr;
4500 struct mesh_config cur_params;
4501 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004502 void *hdr;
4503 struct nlattr *pinfoattr;
4504 struct sk_buff *msg;
4505
Johannes Berg29cbe682010-12-03 09:20:44 +01004506 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4507 return -EOPNOTSUPP;
4508
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004509 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004510 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004511
Johannes Berg29cbe682010-12-03 09:20:44 +01004512 wdev_lock(wdev);
4513 /* If not connected, get default parameters */
4514 if (!wdev->mesh_id_len)
4515 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4516 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004517 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004518 wdev_unlock(wdev);
4519
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004520 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004521 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004522
4523 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004524 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004525 if (!msg)
4526 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004527 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004528 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004529 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004530 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004531 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004532 if (!pinfoattr)
4533 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004534 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4535 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4536 cur_params.dot11MeshRetryTimeout) ||
4537 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4538 cur_params.dot11MeshConfirmTimeout) ||
4539 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4540 cur_params.dot11MeshHoldingTimeout) ||
4541 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4542 cur_params.dot11MeshMaxPeerLinks) ||
4543 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4544 cur_params.dot11MeshMaxRetries) ||
4545 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4546 cur_params.dot11MeshTTL) ||
4547 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4548 cur_params.element_ttl) ||
4549 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4550 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004551 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4552 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004553 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4554 cur_params.dot11MeshHWMPmaxPREQretries) ||
4555 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4556 cur_params.path_refresh_time) ||
4557 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4558 cur_params.min_discovery_timeout) ||
4559 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4560 cur_params.dot11MeshHWMPactivePathTimeout) ||
4561 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4562 cur_params.dot11MeshHWMPpreqMinInterval) ||
4563 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4564 cur_params.dot11MeshHWMPperrMinInterval) ||
4565 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4566 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4567 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4568 cur_params.dot11MeshHWMPRootMode) ||
4569 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4570 cur_params.dot11MeshHWMPRannInterval) ||
4571 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4572 cur_params.dot11MeshGateAnnouncementProtocol) ||
4573 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4574 cur_params.dot11MeshForwarding) ||
4575 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004576 cur_params.rssi_threshold) ||
4577 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004578 cur_params.ht_opmode) ||
4579 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4580 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4581 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004582 cur_params.dot11MeshHWMProotInterval) ||
4583 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004584 cur_params.dot11MeshHWMPconfirmationInterval) ||
4585 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4586 cur_params.power_mode) ||
4587 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004588 cur_params.dot11MeshAwakeWindowDuration) ||
4589 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4590 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004591 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004592 nla_nest_end(msg, pinfoattr);
4593 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004594 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004595
Johannes Berg3b858752009-03-12 09:55:09 +01004596 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004597 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004598 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004599 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004600 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601}
4602
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004603static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004604 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4605 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4606 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4607 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4608 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4609 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004610 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004611 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004612 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004613 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4614 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4615 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4616 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4617 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004618 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004619 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004620 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004621 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004622 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004623 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004624 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4625 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004626 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4627 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004628 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004629 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4630 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004631 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004632};
4633
Javier Cardonac80d5452010-12-16 17:37:49 -08004634static const struct nla_policy
4635 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004636 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004637 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4638 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004639 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004640 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004641 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004642 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004643 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004644 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004645};
4646
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004647static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004648 struct mesh_config *cfg,
4649 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004650{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004651 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004652 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004653
Marco Porschea54fba2013-01-07 16:04:48 +01004654#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4655do { \
4656 if (tb[attr]) { \
4657 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4658 return -EINVAL; \
4659 cfg->param = fn(tb[attr]); \
4660 mask |= (1 << (attr - 1)); \
4661 } \
4662} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004663
4664
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004665 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004666 return -EINVAL;
4667 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004668 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004669 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004670 return -EINVAL;
4671
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004672 /* This makes sure that there aren't more than 32 mesh config
4673 * parameters (otherwise our bitfield scheme would not work.) */
4674 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4675
4676 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004677 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004678 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4679 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004680 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004681 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4682 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004683 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004684 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4685 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004686 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004687 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4688 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004690 mask, NL80211_MESHCONF_MAX_RETRIES,
4691 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004693 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004694 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004695 mask, NL80211_MESHCONF_ELEMENT_TTL,
4696 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004698 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4699 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4701 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004702 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4703 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004705 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4706 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4709 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004711 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4712 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4714 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004715 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4716 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004717 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004718 1, 65535, mask,
4719 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004720 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004722 1, 65535, mask,
4723 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004724 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004725 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004726 dot11MeshHWMPnetDiameterTraversalTime,
4727 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004728 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4729 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4731 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4732 nla_get_u8);
4733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4734 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004735 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004737 dot11MeshGateAnnouncementProtocol, 0, 1,
4738 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004739 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004741 mask, NL80211_MESHCONF_FORWARDING,
4742 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004744 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4745 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004747 mask, NL80211_MESHCONF_HT_OPMODE,
4748 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004749 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004750 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004751 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4752 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004753 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004754 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4755 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004756 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004757 dot11MeshHWMPconfirmationInterval,
4758 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004759 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4760 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004761 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4762 NL80211_MESH_POWER_ACTIVE,
4763 NL80211_MESH_POWER_MAX,
4764 mask, NL80211_MESHCONF_POWER_MODE,
4765 nla_get_u32);
4766 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4767 0, 65535, mask,
4768 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004769 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4770 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4771 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004772 if (mask_out)
4773 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004774
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004775 return 0;
4776
4777#undef FILL_IN_MESH_PARAM_IF_SET
4778}
4779
Javier Cardonac80d5452010-12-16 17:37:49 -08004780static int nl80211_parse_mesh_setup(struct genl_info *info,
4781 struct mesh_setup *setup)
4782{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004784 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4785
4786 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4787 return -EINVAL;
4788 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4789 info->attrs[NL80211_ATTR_MESH_SETUP],
4790 nl80211_mesh_setup_params_policy))
4791 return -EINVAL;
4792
Javier Cardonad299a1f2012-03-31 11:31:33 -07004793 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4794 setup->sync_method =
4795 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4796 IEEE80211_SYNC_METHOD_VENDOR :
4797 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4798
Javier Cardonac80d5452010-12-16 17:37:49 -08004799 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4800 setup->path_sel_proto =
4801 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4802 IEEE80211_PATH_PROTOCOL_VENDOR :
4803 IEEE80211_PATH_PROTOCOL_HWMP;
4804
4805 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4806 setup->path_metric =
4807 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4808 IEEE80211_PATH_METRIC_VENDOR :
4809 IEEE80211_PATH_METRIC_AIRTIME;
4810
Javier Cardona581a8b02011-04-07 15:08:27 -07004811
4812 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004813 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004814 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004815 if (!is_valid_ie_attr(ieattr))
4816 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004817 setup->ie = nla_data(ieattr);
4818 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004819 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004820 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4821 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4822 return -EINVAL;
4823 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004824 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4825 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004826 if (setup->is_secure)
4827 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004828
Colleen Twitty6e16d902013-05-08 11:45:59 -07004829 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4830 if (!setup->user_mpm)
4831 return -EINVAL;
4832 setup->auth_id =
4833 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4834 }
4835
Javier Cardonac80d5452010-12-16 17:37:49 -08004836 return 0;
4837}
4838
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004839static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004840 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004841{
4842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4843 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004844 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004845 struct mesh_config cfg;
4846 u32 mask;
4847 int err;
4848
Johannes Berg29cbe682010-12-03 09:20:44 +01004849 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4850 return -EOPNOTSUPP;
4851
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004852 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004853 return -EOPNOTSUPP;
4854
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004855 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004856 if (err)
4857 return err;
4858
Johannes Berg29cbe682010-12-03 09:20:44 +01004859 wdev_lock(wdev);
4860 if (!wdev->mesh_id_len)
4861 err = -ENOLINK;
4862
4863 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004864 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004865
4866 wdev_unlock(wdev);
4867
4868 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004869}
4870
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004871static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4872{
Johannes Berg458f4f92012-12-06 15:47:38 +01004873 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004874 struct sk_buff *msg;
4875 void *hdr = NULL;
4876 struct nlattr *nl_reg_rules;
4877 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004878
4879 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004880 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004881
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004882 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004883 if (!msg)
4884 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004885
Eric W. Biederman15e47302012-09-07 20:12:54 +00004886 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004887 NL80211_CMD_GET_REG);
4888 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004889 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004890
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004891 if (reg_last_request_cell_base() &&
4892 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4893 NL80211_USER_REG_HINT_CELL_BASE))
4894 goto nla_put_failure;
4895
Johannes Berg458f4f92012-12-06 15:47:38 +01004896 rcu_read_lock();
4897 regdom = rcu_dereference(cfg80211_regdomain);
4898
4899 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4900 (regdom->dfs_region &&
4901 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4902 goto nla_put_failure_rcu;
4903
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004904 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4905 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004906 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004907
Johannes Berg458f4f92012-12-06 15:47:38 +01004908 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004909 struct nlattr *nl_reg_rule;
4910 const struct ieee80211_reg_rule *reg_rule;
4911 const struct ieee80211_freq_range *freq_range;
4912 const struct ieee80211_power_rule *power_rule;
4913
Johannes Berg458f4f92012-12-06 15:47:38 +01004914 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004915 freq_range = &reg_rule->freq_range;
4916 power_rule = &reg_rule->power_rule;
4917
4918 nl_reg_rule = nla_nest_start(msg, i);
4919 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004920 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004921
David S. Miller9360ffd2012-03-29 04:41:26 -04004922 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4923 reg_rule->flags) ||
4924 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4925 freq_range->start_freq_khz) ||
4926 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4927 freq_range->end_freq_khz) ||
4928 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4929 freq_range->max_bandwidth_khz) ||
4930 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4931 power_rule->max_antenna_gain) ||
4932 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4933 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004934 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004935
4936 nla_nest_end(msg, nl_reg_rule);
4937 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004938 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939
4940 nla_nest_end(msg, nl_reg_rules);
4941
4942 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004943 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004944
Johannes Berg458f4f92012-12-06 15:47:38 +01004945nla_put_failure_rcu:
4946 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004947nla_put_failure:
4948 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004949put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004950 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004951 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004952}
4953
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4955{
4956 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4957 struct nlattr *nl_reg_rule;
4958 char *alpha2 = NULL;
4959 int rem_reg_rules = 0, r = 0;
4960 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004961 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004962 struct ieee80211_regdomain *rd = NULL;
4963
4964 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4965 return -EINVAL;
4966
4967 if (!info->attrs[NL80211_ATTR_REG_RULES])
4968 return -EINVAL;
4969
4970 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4971
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004972 if (info->attrs[NL80211_ATTR_DFS_REGION])
4973 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4974
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004975 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004976 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004977 num_rules++;
4978 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004979 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004980 }
4981
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004983 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004984
4985 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004986 if (!rd)
4987 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004988
4989 rd->n_reg_rules = num_rules;
4990 rd->alpha2[0] = alpha2[0];
4991 rd->alpha2[1] = alpha2[1];
4992
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004993 /*
4994 * Disable DFS master mode if the DFS region was
4995 * not supported or known on this kernel.
4996 */
4997 if (reg_supported_dfs_region(dfs_region))
4998 rd->dfs_region = dfs_region;
4999
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005000 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005001 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005002 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005003 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5004 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005005 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5006 if (r)
5007 goto bad_reg;
5008
5009 rule_idx++;
5010
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005011 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5012 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005013 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005014 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005015 }
5016
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005017 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005018 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005019 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005020
Johannes Bergd2372b32008-10-24 20:32:20 +02005021 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005022 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005023 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005024}
5025
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005026static int validate_scan_freqs(struct nlattr *freqs)
5027{
5028 struct nlattr *attr1, *attr2;
5029 int n_channels = 0, tmp1, tmp2;
5030
5031 nla_for_each_nested(attr1, freqs, tmp1) {
5032 n_channels++;
5033 /*
5034 * Some hardware has a limited channel list for
5035 * scanning, and it is pretty much nonsensical
5036 * to scan for a channel twice, so disallow that
5037 * and don't require drivers to check that the
5038 * channel list they get isn't longer than what
5039 * they can scan, as long as they can scan all
5040 * the channels they registered at once.
5041 */
5042 nla_for_each_nested(attr2, freqs, tmp2)
5043 if (attr1 != attr2 &&
5044 nla_get_u32(attr1) == nla_get_u32(attr2))
5045 return 0;
5046 }
5047
5048 return n_channels;
5049}
5050
Johannes Berg2a519312009-02-10 21:25:55 +01005051static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5052{
Johannes Berg4c476992010-10-04 21:36:35 +02005053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005054 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005055 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005056 struct nlattr *attr;
5057 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005058 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005059 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005060
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005061 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5062 return -EINVAL;
5063
Johannes Berg79c97e92009-07-07 03:56:12 +02005064 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005065
Johannes Berg4c476992010-10-04 21:36:35 +02005066 if (!rdev->ops->scan)
5067 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005068
Johannes Bergf9f47522013-03-19 15:04:07 +01005069 if (rdev->scan_req) {
5070 err = -EBUSY;
5071 goto unlock;
5072 }
Johannes Berg2a519312009-02-10 21:25:55 +01005073
5074 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005075 n_channels = validate_scan_freqs(
5076 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005077 if (!n_channels) {
5078 err = -EINVAL;
5079 goto unlock;
5080 }
Johannes Berg2a519312009-02-10 21:25:55 +01005081 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005082 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005083 n_channels = 0;
5084
Johannes Berg2a519312009-02-10 21:25:55 +01005085 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5086 if (wiphy->bands[band])
5087 n_channels += wiphy->bands[band]->n_channels;
5088 }
5089
5090 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5091 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5092 n_ssids++;
5093
Johannes Bergf9f47522013-03-19 15:04:07 +01005094 if (n_ssids > wiphy->max_scan_ssids) {
5095 err = -EINVAL;
5096 goto unlock;
5097 }
Johannes Berg2a519312009-02-10 21:25:55 +01005098
Jouni Malinen70692ad2009-02-16 19:39:13 +02005099 if (info->attrs[NL80211_ATTR_IE])
5100 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5101 else
5102 ie_len = 0;
5103
Johannes Bergf9f47522013-03-19 15:04:07 +01005104 if (ie_len > wiphy->max_scan_ie_len) {
5105 err = -EINVAL;
5106 goto unlock;
5107 }
Johannes Berg18a83652009-03-31 12:12:05 +02005108
Johannes Berg2a519312009-02-10 21:25:55 +01005109 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005110 + sizeof(*request->ssids) * n_ssids
5111 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005112 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005113 if (!request) {
5114 err = -ENOMEM;
5115 goto unlock;
5116 }
Johannes Berg2a519312009-02-10 21:25:55 +01005117
Johannes Berg2a519312009-02-10 21:25:55 +01005118 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005119 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005120 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005121 if (ie_len) {
5122 if (request->ssids)
5123 request->ie = (void *)(request->ssids + n_ssids);
5124 else
5125 request->ie = (void *)(request->channels + n_channels);
5126 }
Johannes Berg2a519312009-02-10 21:25:55 +01005127
Johannes Berg584991d2009-11-02 13:32:03 +01005128 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005129 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5130 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005131 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005132 struct ieee80211_channel *chan;
5133
5134 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5135
5136 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005137 err = -EINVAL;
5138 goto out_free;
5139 }
Johannes Berg584991d2009-11-02 13:32:03 +01005140
5141 /* ignore disabled channels */
5142 if (chan->flags & IEEE80211_CHAN_DISABLED)
5143 continue;
5144
5145 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005146 i++;
5147 }
5148 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005149 enum ieee80211_band band;
5150
Johannes Berg2a519312009-02-10 21:25:55 +01005151 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005152 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5153 int j;
5154 if (!wiphy->bands[band])
5155 continue;
5156 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005157 struct ieee80211_channel *chan;
5158
5159 chan = &wiphy->bands[band]->channels[j];
5160
5161 if (chan->flags & IEEE80211_CHAN_DISABLED)
5162 continue;
5163
5164 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005165 i++;
5166 }
5167 }
5168 }
5169
Johannes Berg584991d2009-11-02 13:32:03 +01005170 if (!i) {
5171 err = -EINVAL;
5172 goto out_free;
5173 }
5174
5175 request->n_channels = i;
5176
Johannes Berg2a519312009-02-10 21:25:55 +01005177 i = 0;
5178 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5179 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005180 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005181 err = -EINVAL;
5182 goto out_free;
5183 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005184 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005185 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005186 i++;
5187 }
5188 }
5189
Jouni Malinen70692ad2009-02-16 19:39:13 +02005190 if (info->attrs[NL80211_ATTR_IE]) {
5191 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005192 memcpy((void *)request->ie,
5193 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005194 request->ie_len);
5195 }
5196
Johannes Berg34850ab2011-07-18 18:08:35 +02005197 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005198 if (wiphy->bands[i])
5199 request->rates[i] =
5200 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005201
5202 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5203 nla_for_each_nested(attr,
5204 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5205 tmp) {
5206 enum ieee80211_band band = nla_type(attr);
5207
Dan Carpenter84404622011-07-29 11:52:18 +03005208 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005209 err = -EINVAL;
5210 goto out_free;
5211 }
5212 err = ieee80211_get_ratemask(wiphy->bands[band],
5213 nla_data(attr),
5214 nla_len(attr),
5215 &request->rates[band]);
5216 if (err)
5217 goto out_free;
5218 }
5219 }
5220
Sam Leffler46856bb2012-10-11 21:03:32 -07005221 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005222 request->flags = nla_get_u32(
5223 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005224 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5225 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5226 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5227 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005228 err = -EOPNOTSUPP;
5229 goto out_free;
5230 }
5231 }
Sam Lefflered4737712012-10-11 21:03:31 -07005232
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305233 request->no_cck =
5234 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5235
Johannes Bergfd014282012-06-18 19:17:03 +02005236 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005237 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005238 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005239
Johannes Berg79c97e92009-07-07 03:56:12 +02005240 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005241 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005242
Johannes Berg463d0182009-07-14 00:33:35 +02005243 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005244 nl80211_send_scan_start(rdev, wdev);
5245 if (wdev->netdev)
5246 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005247 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005248 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005249 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005250 kfree(request);
5251 }
Johannes Berg3b858752009-03-12 09:55:09 +01005252
Johannes Bergf9f47522013-03-19 15:04:07 +01005253 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005254 return err;
5255}
5256
Luciano Coelho807f8a82011-05-11 17:09:35 +03005257static int nl80211_start_sched_scan(struct sk_buff *skb,
5258 struct genl_info *info)
5259{
5260 struct cfg80211_sched_scan_request *request;
5261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5262 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005263 struct nlattr *attr;
5264 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005265 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005266 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005267 enum ieee80211_band band;
5268 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005269 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005270
5271 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5272 !rdev->ops->sched_scan_start)
5273 return -EOPNOTSUPP;
5274
5275 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5276 return -EINVAL;
5277
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005278 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5279 return -EINVAL;
5280
5281 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5282 if (interval == 0)
5283 return -EINVAL;
5284
Luciano Coelho807f8a82011-05-11 17:09:35 +03005285 wiphy = &rdev->wiphy;
5286
5287 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5288 n_channels = validate_scan_freqs(
5289 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5290 if (!n_channels)
5291 return -EINVAL;
5292 } else {
5293 n_channels = 0;
5294
5295 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5296 if (wiphy->bands[band])
5297 n_channels += wiphy->bands[band]->n_channels;
5298 }
5299
5300 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5301 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5302 tmp)
5303 n_ssids++;
5304
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005305 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005306 return -EINVAL;
5307
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005308 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5309 nla_for_each_nested(attr,
5310 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5311 tmp)
5312 n_match_sets++;
5313
5314 if (n_match_sets > wiphy->max_match_sets)
5315 return -EINVAL;
5316
Luciano Coelho807f8a82011-05-11 17:09:35 +03005317 if (info->attrs[NL80211_ATTR_IE])
5318 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5319 else
5320 ie_len = 0;
5321
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005322 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005323 return -EINVAL;
5324
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005325 if (rdev->sched_scan_req) {
5326 err = -EINPROGRESS;
5327 goto out;
5328 }
5329
Luciano Coelho807f8a82011-05-11 17:09:35 +03005330 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005331 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005332 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005333 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005334 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005335 if (!request) {
5336 err = -ENOMEM;
5337 goto out;
5338 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005339
5340 if (n_ssids)
5341 request->ssids = (void *)&request->channels[n_channels];
5342 request->n_ssids = n_ssids;
5343 if (ie_len) {
5344 if (request->ssids)
5345 request->ie = (void *)(request->ssids + n_ssids);
5346 else
5347 request->ie = (void *)(request->channels + n_channels);
5348 }
5349
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005350 if (n_match_sets) {
5351 if (request->ie)
5352 request->match_sets = (void *)(request->ie + ie_len);
5353 else if (request->ssids)
5354 request->match_sets =
5355 (void *)(request->ssids + n_ssids);
5356 else
5357 request->match_sets =
5358 (void *)(request->channels + n_channels);
5359 }
5360 request->n_match_sets = n_match_sets;
5361
Luciano Coelho807f8a82011-05-11 17:09:35 +03005362 i = 0;
5363 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5364 /* user specified, bail out if channel not found */
5365 nla_for_each_nested(attr,
5366 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5367 tmp) {
5368 struct ieee80211_channel *chan;
5369
5370 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5371
5372 if (!chan) {
5373 err = -EINVAL;
5374 goto out_free;
5375 }
5376
5377 /* ignore disabled channels */
5378 if (chan->flags & IEEE80211_CHAN_DISABLED)
5379 continue;
5380
5381 request->channels[i] = chan;
5382 i++;
5383 }
5384 } else {
5385 /* all channels */
5386 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5387 int j;
5388 if (!wiphy->bands[band])
5389 continue;
5390 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5391 struct ieee80211_channel *chan;
5392
5393 chan = &wiphy->bands[band]->channels[j];
5394
5395 if (chan->flags & IEEE80211_CHAN_DISABLED)
5396 continue;
5397
5398 request->channels[i] = chan;
5399 i++;
5400 }
5401 }
5402 }
5403
5404 if (!i) {
5405 err = -EINVAL;
5406 goto out_free;
5407 }
5408
5409 request->n_channels = i;
5410
5411 i = 0;
5412 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5413 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5414 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005415 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005416 err = -EINVAL;
5417 goto out_free;
5418 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005419 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005420 memcpy(request->ssids[i].ssid, nla_data(attr),
5421 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005422 i++;
5423 }
5424 }
5425
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005426 i = 0;
5427 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5428 nla_for_each_nested(attr,
5429 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5430 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005431 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005432
5433 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5434 nla_data(attr), nla_len(attr),
5435 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005436 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005437 if (ssid) {
5438 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5439 err = -EINVAL;
5440 goto out_free;
5441 }
5442 memcpy(request->match_sets[i].ssid.ssid,
5443 nla_data(ssid), nla_len(ssid));
5444 request->match_sets[i].ssid.ssid_len =
5445 nla_len(ssid);
5446 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005447 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5448 if (rssi)
5449 request->rssi_thold = nla_get_u32(rssi);
5450 else
5451 request->rssi_thold =
5452 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005453 i++;
5454 }
5455 }
5456
Luciano Coelho807f8a82011-05-11 17:09:35 +03005457 if (info->attrs[NL80211_ATTR_IE]) {
5458 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5459 memcpy((void *)request->ie,
5460 nla_data(info->attrs[NL80211_ATTR_IE]),
5461 request->ie_len);
5462 }
5463
Sam Leffler46856bb2012-10-11 21:03:32 -07005464 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005465 request->flags = nla_get_u32(
5466 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005467 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5468 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5469 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5470 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005471 err = -EOPNOTSUPP;
5472 goto out_free;
5473 }
5474 }
Sam Lefflered4737712012-10-11 21:03:31 -07005475
Luciano Coelho807f8a82011-05-11 17:09:35 +03005476 request->dev = dev;
5477 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005478 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005479 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005480
Hila Gonene35e4d22012-06-27 17:19:42 +03005481 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005482 if (!err) {
5483 rdev->sched_scan_req = request;
5484 nl80211_send_sched_scan(rdev, dev,
5485 NL80211_CMD_START_SCHED_SCAN);
5486 goto out;
5487 }
5488
5489out_free:
5490 kfree(request);
5491out:
5492 return err;
5493}
5494
5495static int nl80211_stop_sched_scan(struct sk_buff *skb,
5496 struct genl_info *info)
5497{
5498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5499
5500 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5501 !rdev->ops->sched_scan_stop)
5502 return -EOPNOTSUPP;
5503
Johannes Berg5fe231e2013-05-08 21:45:15 +02005504 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005505}
5506
Simon Wunderlich04f39042013-02-08 18:16:19 +01005507static int nl80211_start_radar_detection(struct sk_buff *skb,
5508 struct genl_info *info)
5509{
5510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5511 struct net_device *dev = info->user_ptr[1];
5512 struct wireless_dev *wdev = dev->ieee80211_ptr;
5513 struct cfg80211_chan_def chandef;
5514 int err;
5515
5516 err = nl80211_parse_chandef(rdev, info, &chandef);
5517 if (err)
5518 return err;
5519
5520 if (wdev->cac_started)
5521 return -EBUSY;
5522
5523 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5524 if (err < 0)
5525 return err;
5526
5527 if (err == 0)
5528 return -EINVAL;
5529
5530 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5531 return -EINVAL;
5532
5533 if (!rdev->ops->start_radar_detection)
5534 return -EOPNOTSUPP;
5535
Simon Wunderlich04f39042013-02-08 18:16:19 +01005536 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5537 chandef.chan, CHAN_MODE_SHARED,
5538 BIT(chandef.width));
5539 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005540 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005541
5542 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5543 if (!err) {
5544 wdev->channel = chandef.chan;
5545 wdev->cac_started = true;
5546 wdev->cac_start_time = jiffies;
5547 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005548 return err;
5549}
5550
Johannes Berg9720bb32011-06-21 09:45:33 +02005551static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5552 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005553 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005554 struct wireless_dev *wdev,
5555 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005556{
Johannes Berg48ab9052009-07-10 18:42:31 +02005557 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005558 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005559 void *hdr;
5560 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005561 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005562
5563 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005564
Eric W. Biederman15e47302012-09-07 20:12:54 +00005565 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005566 NL80211_CMD_NEW_SCAN_RESULTS);
5567 if (!hdr)
5568 return -1;
5569
Johannes Berg9720bb32011-06-21 09:45:33 +02005570 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5571
Johannes Berg97990a02013-04-19 01:02:55 +02005572 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5573 goto nla_put_failure;
5574 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005575 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5576 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005577 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5578 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005579
5580 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5581 if (!bss)
5582 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005583 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005584 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005585 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005586
5587 rcu_read_lock();
5588 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005589 if (ies) {
5590 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5591 goto fail_unlock_rcu;
5592 tsf = true;
5593 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5594 ies->len, ies->data))
5595 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005596 }
5597 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005598 if (ies) {
5599 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5600 goto fail_unlock_rcu;
5601 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5602 ies->len, ies->data))
5603 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005604 }
5605 rcu_read_unlock();
5606
David S. Miller9360ffd2012-03-29 04:41:26 -04005607 if (res->beacon_interval &&
5608 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5609 goto nla_put_failure;
5610 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5611 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5612 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5613 jiffies_to_msecs(jiffies - intbss->ts)))
5614 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005615
Johannes Berg77965c92009-02-18 18:45:06 +01005616 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005617 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005618 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5619 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005620 break;
5621 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005622 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5623 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005624 break;
5625 default:
5626 break;
5627 }
5628
Johannes Berg48ab9052009-07-10 18:42:31 +02005629 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005630 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005631 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005632 if (intbss == wdev->current_bss &&
5633 nla_put_u32(msg, NL80211_BSS_STATUS,
5634 NL80211_BSS_STATUS_ASSOCIATED))
5635 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005636 break;
5637 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005638 if (intbss == wdev->current_bss &&
5639 nla_put_u32(msg, NL80211_BSS_STATUS,
5640 NL80211_BSS_STATUS_IBSS_JOINED))
5641 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005642 break;
5643 default:
5644 break;
5645 }
5646
Johannes Berg2a519312009-02-10 21:25:55 +01005647 nla_nest_end(msg, bss);
5648
5649 return genlmsg_end(msg, hdr);
5650
Johannes Berg8cef2c92013-02-05 16:54:31 +01005651 fail_unlock_rcu:
5652 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005653 nla_put_failure:
5654 genlmsg_cancel(msg, hdr);
5655 return -EMSGSIZE;
5656}
5657
Johannes Berg97990a02013-04-19 01:02:55 +02005658static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005659{
Johannes Berg48ab9052009-07-10 18:42:31 +02005660 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005661 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005662 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005663 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005664 int err;
5665
Johannes Berg97990a02013-04-19 01:02:55 +02005666 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005667 if (err)
5668 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005669
Johannes Berg48ab9052009-07-10 18:42:31 +02005670 wdev_lock(wdev);
5671 spin_lock_bh(&rdev->bss_lock);
5672 cfg80211_bss_expire(rdev);
5673
Johannes Berg9720bb32011-06-21 09:45:33 +02005674 cb->seq = rdev->bss_generation;
5675
Johannes Berg48ab9052009-07-10 18:42:31 +02005676 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005677 if (++idx <= start)
5678 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005679 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005680 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005681 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005682 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005683 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005684 }
5685 }
5686
Johannes Berg48ab9052009-07-10 18:42:31 +02005687 spin_unlock_bh(&rdev->bss_lock);
5688 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005689
Johannes Berg97990a02013-04-19 01:02:55 +02005690 cb->args[2] = idx;
5691 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005692
Johannes Berg67748892010-10-04 21:14:06 +02005693 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005694}
5695
Eric W. Biederman15e47302012-09-07 20:12:54 +00005696static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005697 int flags, struct net_device *dev,
5698 struct survey_info *survey)
5699{
5700 void *hdr;
5701 struct nlattr *infoattr;
5702
Eric W. Biederman15e47302012-09-07 20:12:54 +00005703 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005704 NL80211_CMD_NEW_SURVEY_RESULTS);
5705 if (!hdr)
5706 return -ENOMEM;
5707
David S. Miller9360ffd2012-03-29 04:41:26 -04005708 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5709 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005710
5711 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5712 if (!infoattr)
5713 goto nla_put_failure;
5714
David S. Miller9360ffd2012-03-29 04:41:26 -04005715 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5716 survey->channel->center_freq))
5717 goto nla_put_failure;
5718
5719 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5720 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5721 goto nla_put_failure;
5722 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5723 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5724 goto nla_put_failure;
5725 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5726 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5727 survey->channel_time))
5728 goto nla_put_failure;
5729 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5730 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5731 survey->channel_time_busy))
5732 goto nla_put_failure;
5733 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5734 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5735 survey->channel_time_ext_busy))
5736 goto nla_put_failure;
5737 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5738 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5739 survey->channel_time_rx))
5740 goto nla_put_failure;
5741 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5742 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5743 survey->channel_time_tx))
5744 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005745
5746 nla_nest_end(msg, infoattr);
5747
5748 return genlmsg_end(msg, hdr);
5749
5750 nla_put_failure:
5751 genlmsg_cancel(msg, hdr);
5752 return -EMSGSIZE;
5753}
5754
5755static int nl80211_dump_survey(struct sk_buff *skb,
5756 struct netlink_callback *cb)
5757{
5758 struct survey_info survey;
5759 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005760 struct wireless_dev *wdev;
5761 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005762 int res;
5763
Johannes Berg97990a02013-04-19 01:02:55 +02005764 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005765 if (res)
5766 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005767
Johannes Berg97990a02013-04-19 01:02:55 +02005768 if (!wdev->netdev) {
5769 res = -EINVAL;
5770 goto out_err;
5771 }
5772
Holger Schurig61fa7132009-11-11 12:25:40 +01005773 if (!dev->ops->dump_survey) {
5774 res = -EOPNOTSUPP;
5775 goto out_err;
5776 }
5777
5778 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005779 struct ieee80211_channel *chan;
5780
Johannes Berg97990a02013-04-19 01:02:55 +02005781 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005782 if (res == -ENOENT)
5783 break;
5784 if (res)
5785 goto out_err;
5786
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005787 /* Survey without a channel doesn't make sense */
5788 if (!survey.channel) {
5789 res = -EINVAL;
5790 goto out;
5791 }
5792
5793 chan = ieee80211_get_channel(&dev->wiphy,
5794 survey.channel->center_freq);
5795 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5796 survey_idx++;
5797 continue;
5798 }
5799
Holger Schurig61fa7132009-11-11 12:25:40 +01005800 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005801 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005802 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005803 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005804 goto out;
5805 survey_idx++;
5806 }
5807
5808 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005809 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005810 res = skb->len;
5811 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005812 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005813 return res;
5814}
5815
Samuel Ortizb23aa672009-07-01 21:26:54 +02005816static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5817{
5818 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5819 NL80211_WPA_VERSION_2));
5820}
5821
Jouni Malinen636a5d32009-03-19 13:39:22 +02005822static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5823{
Johannes Berg4c476992010-10-04 21:36:35 +02005824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5825 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005826 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005827 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5828 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005829 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005830 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005831 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005832
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005833 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5834 return -EINVAL;
5835
5836 if (!info->attrs[NL80211_ATTR_MAC])
5837 return -EINVAL;
5838
Jouni Malinen17780922009-03-27 20:52:47 +02005839 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5840 return -EINVAL;
5841
Johannes Berg19957bb2009-07-02 17:20:43 +02005842 if (!info->attrs[NL80211_ATTR_SSID])
5843 return -EINVAL;
5844
5845 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5846 return -EINVAL;
5847
Johannes Bergfffd0932009-07-08 14:22:54 +02005848 err = nl80211_parse_key(info, &key);
5849 if (err)
5850 return err;
5851
5852 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005853 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5854 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005855 if (!key.p.key || !key.p.key_len)
5856 return -EINVAL;
5857 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5858 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5859 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5860 key.p.key_len != WLAN_KEY_LEN_WEP104))
5861 return -EINVAL;
5862 if (key.idx > 4)
5863 return -EINVAL;
5864 } else {
5865 key.p.key_len = 0;
5866 key.p.key = NULL;
5867 }
5868
Johannes Bergafea0b72010-08-10 09:46:42 +02005869 if (key.idx >= 0) {
5870 int i;
5871 bool ok = false;
5872 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5873 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5874 ok = true;
5875 break;
5876 }
5877 }
Johannes Berg4c476992010-10-04 21:36:35 +02005878 if (!ok)
5879 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005880 }
5881
Johannes Berg4c476992010-10-04 21:36:35 +02005882 if (!rdev->ops->auth)
5883 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005884
Johannes Berg074ac8d2010-09-16 14:58:22 +02005885 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005886 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5887 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005888
Johannes Berg19957bb2009-07-02 17:20:43 +02005889 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005890 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005891 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005892 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5893 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005894
Johannes Berg19957bb2009-07-02 17:20:43 +02005895 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5896 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5897
5898 if (info->attrs[NL80211_ATTR_IE]) {
5899 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5900 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5901 }
5902
5903 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005904 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005905 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005906
Jouni Malinene39e5b52012-09-30 19:29:39 +03005907 if (auth_type == NL80211_AUTHTYPE_SAE &&
5908 !info->attrs[NL80211_ATTR_SAE_DATA])
5909 return -EINVAL;
5910
5911 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5912 if (auth_type != NL80211_AUTHTYPE_SAE)
5913 return -EINVAL;
5914 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5915 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5916 /* need to include at least Auth Transaction and Status Code */
5917 if (sae_data_len < 4)
5918 return -EINVAL;
5919 }
5920
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005921 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5922
Johannes Berg95de8172012-01-20 13:55:25 +01005923 /*
5924 * Since we no longer track auth state, ignore
5925 * requests to only change local state.
5926 */
5927 if (local_state_change)
5928 return 0;
5929
Johannes Berg91bf9b22013-05-15 17:44:01 +02005930 wdev_lock(dev->ieee80211_ptr);
5931 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5932 ssid, ssid_len, ie, ie_len,
5933 key.p.key, key.p.key_len, key.idx,
5934 sae_data, sae_data_len);
5935 wdev_unlock(dev->ieee80211_ptr);
5936 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005937}
5938
Johannes Bergc0692b82010-08-27 14:26:53 +03005939static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5940 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005941 struct cfg80211_crypto_settings *settings,
5942 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005943{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005944 memset(settings, 0, sizeof(*settings));
5945
Samuel Ortizb23aa672009-07-01 21:26:54 +02005946 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5947
Johannes Bergc0692b82010-08-27 14:26:53 +03005948 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5949 u16 proto;
5950 proto = nla_get_u16(
5951 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5952 settings->control_port_ethertype = cpu_to_be16(proto);
5953 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5954 proto != ETH_P_PAE)
5955 return -EINVAL;
5956 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5957 settings->control_port_no_encrypt = true;
5958 } else
5959 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5960
Samuel Ortizb23aa672009-07-01 21:26:54 +02005961 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5962 void *data;
5963 int len, i;
5964
5965 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5966 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5967 settings->n_ciphers_pairwise = len / sizeof(u32);
5968
5969 if (len % sizeof(u32))
5970 return -EINVAL;
5971
Johannes Berg3dc27d22009-07-02 21:36:37 +02005972 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005973 return -EINVAL;
5974
5975 memcpy(settings->ciphers_pairwise, data, len);
5976
5977 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005978 if (!cfg80211_supported_cipher_suite(
5979 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005980 settings->ciphers_pairwise[i]))
5981 return -EINVAL;
5982 }
5983
5984 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5985 settings->cipher_group =
5986 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005987 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5988 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005989 return -EINVAL;
5990 }
5991
5992 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5993 settings->wpa_versions =
5994 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5995 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5996 return -EINVAL;
5997 }
5998
5999 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6000 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006001 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006002
6003 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6004 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6005 settings->n_akm_suites = len / sizeof(u32);
6006
6007 if (len % sizeof(u32))
6008 return -EINVAL;
6009
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006010 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6011 return -EINVAL;
6012
Samuel Ortizb23aa672009-07-01 21:26:54 +02006013 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006014 }
6015
6016 return 0;
6017}
6018
Jouni Malinen636a5d32009-03-19 13:39:22 +02006019static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6020{
Johannes Berg4c476992010-10-04 21:36:35 +02006021 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6022 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006023 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006024 struct cfg80211_assoc_request req = {};
6025 const u8 *bssid, *ssid;
6026 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006027
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006028 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6029 return -EINVAL;
6030
6031 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006032 !info->attrs[NL80211_ATTR_SSID] ||
6033 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006034 return -EINVAL;
6035
Johannes Berg4c476992010-10-04 21:36:35 +02006036 if (!rdev->ops->assoc)
6037 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006038
Johannes Berg074ac8d2010-09-16 14:58:22 +02006039 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006040 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6041 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006042
Johannes Berg19957bb2009-07-02 17:20:43 +02006043 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006044
Johannes Berg19957bb2009-07-02 17:20:43 +02006045 chan = ieee80211_get_channel(&rdev->wiphy,
6046 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006047 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6048 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006049
Johannes Berg19957bb2009-07-02 17:20:43 +02006050 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6051 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006052
6053 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006054 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6055 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006056 }
6057
Jouni Malinendc6382c2009-05-06 22:09:37 +03006058 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006059 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006060 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006061 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006062 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006063 else if (mfp != NL80211_MFP_NO)
6064 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006065 }
6066
Johannes Berg3e5d7642009-07-07 14:37:26 +02006067 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006068 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006069
Ben Greear7e7c8922011-11-18 11:31:59 -08006070 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006071 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006072
6073 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006074 memcpy(&req.ht_capa_mask,
6075 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6076 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006077
6078 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006079 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006080 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006081 memcpy(&req.ht_capa,
6082 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6083 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006084 }
6085
Johannes Bergee2aca32013-02-21 17:36:01 +01006086 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006087 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006088
6089 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006090 memcpy(&req.vht_capa_mask,
6091 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6092 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006093
6094 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006095 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006096 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006097 memcpy(&req.vht_capa,
6098 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6099 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006100 }
6101
Johannes Bergf62fab72013-02-21 20:09:09 +01006102 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006103 if (!err) {
6104 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006105 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6106 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006107 wdev_unlock(dev->ieee80211_ptr);
6108 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006109
Jouni Malinen636a5d32009-03-19 13:39:22 +02006110 return err;
6111}
6112
6113static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6114{
Johannes Berg4c476992010-10-04 21:36:35 +02006115 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6116 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006117 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006118 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006119 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006120 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006121
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006122 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6123 return -EINVAL;
6124
6125 if (!info->attrs[NL80211_ATTR_MAC])
6126 return -EINVAL;
6127
6128 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6129 return -EINVAL;
6130
Johannes Berg4c476992010-10-04 21:36:35 +02006131 if (!rdev->ops->deauth)
6132 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006133
Johannes Berg074ac8d2010-09-16 14:58:22 +02006134 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006135 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6136 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006137
Johannes Berg19957bb2009-07-02 17:20:43 +02006138 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006139
Johannes Berg19957bb2009-07-02 17:20:43 +02006140 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6141 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006142 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006143 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006144 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006145
6146 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006147 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6148 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006149 }
6150
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006151 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6152
Johannes Berg91bf9b22013-05-15 17:44:01 +02006153 wdev_lock(dev->ieee80211_ptr);
6154 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6155 local_state_change);
6156 wdev_unlock(dev->ieee80211_ptr);
6157 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006158}
6159
6160static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6161{
Johannes Berg4c476992010-10-04 21:36:35 +02006162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6163 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006164 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006165 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006166 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006167 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006168
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006169 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6170 return -EINVAL;
6171
6172 if (!info->attrs[NL80211_ATTR_MAC])
6173 return -EINVAL;
6174
6175 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6176 return -EINVAL;
6177
Johannes Berg4c476992010-10-04 21:36:35 +02006178 if (!rdev->ops->disassoc)
6179 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006180
Johannes Berg074ac8d2010-09-16 14:58:22 +02006181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6183 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006184
Johannes Berg19957bb2009-07-02 17:20:43 +02006185 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006186
Johannes Berg19957bb2009-07-02 17:20:43 +02006187 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6188 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006189 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006190 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006191 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006192
6193 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006194 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6195 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006196 }
6197
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006198 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6199
Johannes Berg91bf9b22013-05-15 17:44:01 +02006200 wdev_lock(dev->ieee80211_ptr);
6201 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6202 local_state_change);
6203 wdev_unlock(dev->ieee80211_ptr);
6204 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006205}
6206
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006207static bool
6208nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6209 int mcast_rate[IEEE80211_NUM_BANDS],
6210 int rateval)
6211{
6212 struct wiphy *wiphy = &rdev->wiphy;
6213 bool found = false;
6214 int band, i;
6215
6216 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6217 struct ieee80211_supported_band *sband;
6218
6219 sband = wiphy->bands[band];
6220 if (!sband)
6221 continue;
6222
6223 for (i = 0; i < sband->n_bitrates; i++) {
6224 if (sband->bitrates[i].bitrate == rateval) {
6225 mcast_rate[band] = i + 1;
6226 found = true;
6227 break;
6228 }
6229 }
6230 }
6231
6232 return found;
6233}
6234
Johannes Berg04a773a2009-04-19 21:24:32 +02006235static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6236{
Johannes Berg4c476992010-10-04 21:36:35 +02006237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6238 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006239 struct cfg80211_ibss_params ibss;
6240 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006241 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006242 int err;
6243
Johannes Berg8e30bc52009-04-22 17:45:38 +02006244 memset(&ibss, 0, sizeof(ibss));
6245
Johannes Berg04a773a2009-04-19 21:24:32 +02006246 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6247 return -EINVAL;
6248
Johannes Berg683b6d32012-11-08 21:25:48 +01006249 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006250 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6251 return -EINVAL;
6252
Johannes Berg8e30bc52009-04-22 17:45:38 +02006253 ibss.beacon_interval = 100;
6254
6255 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6256 ibss.beacon_interval =
6257 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6258 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6259 return -EINVAL;
6260 }
6261
Johannes Berg4c476992010-10-04 21:36:35 +02006262 if (!rdev->ops->join_ibss)
6263 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006264
Johannes Berg4c476992010-10-04 21:36:35 +02006265 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6266 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006267
Johannes Berg79c97e92009-07-07 03:56:12 +02006268 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006269
Johannes Berg39193492011-09-16 13:45:25 +02006270 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006271 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006272
6273 if (!is_valid_ether_addr(ibss.bssid))
6274 return -EINVAL;
6275 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006276 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6277 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6278
6279 if (info->attrs[NL80211_ATTR_IE]) {
6280 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6281 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6282 }
6283
Johannes Berg683b6d32012-11-08 21:25:48 +01006284 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6285 if (err)
6286 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006287
Johannes Berg683b6d32012-11-08 21:25:48 +01006288 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006289 return -EINVAL;
6290
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006291 switch (ibss.chandef.width) {
6292 case NL80211_CHAN_WIDTH_20_NOHT:
6293 break;
6294 case NL80211_CHAN_WIDTH_20:
6295 case NL80211_CHAN_WIDTH_40:
6296 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6297 break;
6298 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006299 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006300 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006301
Johannes Berg04a773a2009-04-19 21:24:32 +02006302 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006303 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006304
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006305 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6306 u8 *rates =
6307 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6308 int n_rates =
6309 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6310 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006311 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006312
Johannes Berg34850ab2011-07-18 18:08:35 +02006313 err = ieee80211_get_ratemask(sband, rates, n_rates,
6314 &ibss.basic_rates);
6315 if (err)
6316 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006317 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006318
6319 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6320 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6321 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6322 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006323
Johannes Berg4c476992010-10-04 21:36:35 +02006324 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306325 bool no_ht = false;
6326
Johannes Berg4c476992010-10-04 21:36:35 +02006327 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306328 info->attrs[NL80211_ATTR_KEYS],
6329 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006330 if (IS_ERR(connkeys))
6331 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306332
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006333 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6334 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306335 kfree(connkeys);
6336 return -EINVAL;
6337 }
Johannes Berg4c476992010-10-04 21:36:35 +02006338 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006339
Antonio Quartulli267335d2012-01-31 20:25:47 +01006340 ibss.control_port =
6341 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6342
Johannes Berg4c476992010-10-04 21:36:35 +02006343 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006344 if (err)
6345 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006346 return err;
6347}
6348
6349static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6350{
Johannes Berg4c476992010-10-04 21:36:35 +02006351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6352 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006353
Johannes Berg4c476992010-10-04 21:36:35 +02006354 if (!rdev->ops->leave_ibss)
6355 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006356
Johannes Berg4c476992010-10-04 21:36:35 +02006357 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6358 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006359
Johannes Berg4c476992010-10-04 21:36:35 +02006360 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006361}
6362
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006363static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6364{
6365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6366 struct net_device *dev = info->user_ptr[1];
6367 int mcast_rate[IEEE80211_NUM_BANDS];
6368 u32 nla_rate;
6369 int err;
6370
6371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6373 return -EOPNOTSUPP;
6374
6375 if (!rdev->ops->set_mcast_rate)
6376 return -EOPNOTSUPP;
6377
6378 memset(mcast_rate, 0, sizeof(mcast_rate));
6379
6380 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6381 return -EINVAL;
6382
6383 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6384 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6385 return -EINVAL;
6386
6387 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6388
6389 return err;
6390}
6391
6392
Johannes Bergaff89a92009-07-01 21:26:51 +02006393#ifdef CONFIG_NL80211_TESTMODE
6394static struct genl_multicast_group nl80211_testmode_mcgrp = {
6395 .name = "testmode",
6396};
6397
6398static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6399{
Johannes Berg4c476992010-10-04 21:36:35 +02006400 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006401 int err;
6402
6403 if (!info->attrs[NL80211_ATTR_TESTDATA])
6404 return -EINVAL;
6405
Johannes Bergaff89a92009-07-01 21:26:51 +02006406 err = -EOPNOTSUPP;
6407 if (rdev->ops->testmode_cmd) {
6408 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006409 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006410 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6411 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6412 rdev->testmode_info = NULL;
6413 }
6414
Johannes Bergaff89a92009-07-01 21:26:51 +02006415 return err;
6416}
6417
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006418static int nl80211_testmode_dump(struct sk_buff *skb,
6419 struct netlink_callback *cb)
6420{
Johannes Berg00918d32011-12-13 17:22:05 +01006421 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006422 int err;
6423 long phy_idx;
6424 void *data = NULL;
6425 int data_len = 0;
6426
Johannes Berg5fe231e2013-05-08 21:45:15 +02006427 rtnl_lock();
6428
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006429 if (cb->args[0]) {
6430 /*
6431 * 0 is a valid index, but not valid for args[0],
6432 * so we need to offset by 1.
6433 */
6434 phy_idx = cb->args[0] - 1;
6435 } else {
6436 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6437 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6438 nl80211_policy);
6439 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006440 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006441
Johannes Berg2bd7e352012-06-15 14:23:16 +02006442 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6443 nl80211_fam.attrbuf);
6444 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006445 err = PTR_ERR(rdev);
6446 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006447 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006448 phy_idx = rdev->wiphy_idx;
6449 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006450
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006451 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6452 cb->args[1] =
6453 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6454 }
6455
6456 if (cb->args[1]) {
6457 data = nla_data((void *)cb->args[1]);
6458 data_len = nla_len((void *)cb->args[1]);
6459 }
6460
Johannes Berg00918d32011-12-13 17:22:05 +01006461 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6462 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006463 err = -ENOENT;
6464 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006465 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006466
Johannes Berg00918d32011-12-13 17:22:05 +01006467 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006468 err = -EOPNOTSUPP;
6469 goto out_err;
6470 }
6471
6472 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006473 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006474 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6475 NL80211_CMD_TESTMODE);
6476 struct nlattr *tmdata;
6477
David S. Miller9360ffd2012-03-29 04:41:26 -04006478 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006479 genlmsg_cancel(skb, hdr);
6480 break;
6481 }
6482
6483 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6484 if (!tmdata) {
6485 genlmsg_cancel(skb, hdr);
6486 break;
6487 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006488 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006489 nla_nest_end(skb, tmdata);
6490
6491 if (err == -ENOBUFS || err == -ENOENT) {
6492 genlmsg_cancel(skb, hdr);
6493 break;
6494 } else if (err) {
6495 genlmsg_cancel(skb, hdr);
6496 goto out_err;
6497 }
6498
6499 genlmsg_end(skb, hdr);
6500 }
6501
6502 err = skb->len;
6503 /* see above */
6504 cb->args[0] = phy_idx + 1;
6505 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006506 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006507 return err;
6508}
6509
Johannes Bergaff89a92009-07-01 21:26:51 +02006510static struct sk_buff *
6511__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006512 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006513{
6514 struct sk_buff *skb;
6515 void *hdr;
6516 struct nlattr *data;
6517
6518 skb = nlmsg_new(approxlen + 100, gfp);
6519 if (!skb)
6520 return NULL;
6521
Eric W. Biederman15e47302012-09-07 20:12:54 +00006522 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006523 if (!hdr) {
6524 kfree_skb(skb);
6525 return NULL;
6526 }
6527
David S. Miller9360ffd2012-03-29 04:41:26 -04006528 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6529 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006530 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6531
6532 ((void **)skb->cb)[0] = rdev;
6533 ((void **)skb->cb)[1] = hdr;
6534 ((void **)skb->cb)[2] = data;
6535
6536 return skb;
6537
6538 nla_put_failure:
6539 kfree_skb(skb);
6540 return NULL;
6541}
6542
6543struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6544 int approxlen)
6545{
6546 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6547
6548 if (WARN_ON(!rdev->testmode_info))
6549 return NULL;
6550
6551 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006552 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006553 rdev->testmode_info->snd_seq,
6554 GFP_KERNEL);
6555}
6556EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6557
6558int cfg80211_testmode_reply(struct sk_buff *skb)
6559{
6560 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6561 void *hdr = ((void **)skb->cb)[1];
6562 struct nlattr *data = ((void **)skb->cb)[2];
6563
6564 if (WARN_ON(!rdev->testmode_info)) {
6565 kfree_skb(skb);
6566 return -EINVAL;
6567 }
6568
6569 nla_nest_end(skb, data);
6570 genlmsg_end(skb, hdr);
6571 return genlmsg_reply(skb, rdev->testmode_info);
6572}
6573EXPORT_SYMBOL(cfg80211_testmode_reply);
6574
6575struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6576 int approxlen, gfp_t gfp)
6577{
6578 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6579
6580 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6581}
6582EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6583
6584void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6585{
6586 void *hdr = ((void **)skb->cb)[1];
6587 struct nlattr *data = ((void **)skb->cb)[2];
6588
6589 nla_nest_end(skb, data);
6590 genlmsg_end(skb, hdr);
6591 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6592}
6593EXPORT_SYMBOL(cfg80211_testmode_event);
6594#endif
6595
Samuel Ortizb23aa672009-07-01 21:26:54 +02006596static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6597{
Johannes Berg4c476992010-10-04 21:36:35 +02006598 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6599 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006600 struct cfg80211_connect_params connect;
6601 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006602 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006603 int err;
6604
6605 memset(&connect, 0, sizeof(connect));
6606
6607 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6608 return -EINVAL;
6609
6610 if (!info->attrs[NL80211_ATTR_SSID] ||
6611 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6612 return -EINVAL;
6613
6614 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6615 connect.auth_type =
6616 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006617 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6618 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006619 return -EINVAL;
6620 } else
6621 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6622
6623 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6624
Johannes Bergc0692b82010-08-27 14:26:53 +03006625 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006626 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006627 if (err)
6628 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006629
Johannes Berg074ac8d2010-09-16 14:58:22 +02006630 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006631 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6632 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006633
Johannes Berg79c97e92009-07-07 03:56:12 +02006634 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006635
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306636 connect.bg_scan_period = -1;
6637 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6638 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6639 connect.bg_scan_period =
6640 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6641 }
6642
Samuel Ortizb23aa672009-07-01 21:26:54 +02006643 if (info->attrs[NL80211_ATTR_MAC])
6644 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6645 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6646 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6647
6648 if (info->attrs[NL80211_ATTR_IE]) {
6649 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6650 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6651 }
6652
Jouni Malinencee00a92013-01-15 17:15:57 +02006653 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6654 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6655 if (connect.mfp != NL80211_MFP_REQUIRED &&
6656 connect.mfp != NL80211_MFP_NO)
6657 return -EINVAL;
6658 } else {
6659 connect.mfp = NL80211_MFP_NO;
6660 }
6661
Samuel Ortizb23aa672009-07-01 21:26:54 +02006662 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6663 connect.channel =
6664 ieee80211_get_channel(wiphy,
6665 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6666 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006667 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6668 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006669 }
6670
Johannes Bergfffd0932009-07-08 14:22:54 +02006671 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6672 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306673 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006674 if (IS_ERR(connkeys))
6675 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006676 }
6677
Ben Greear7e7c8922011-11-18 11:31:59 -08006678 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6679 connect.flags |= ASSOC_REQ_DISABLE_HT;
6680
6681 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6682 memcpy(&connect.ht_capa_mask,
6683 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6684 sizeof(connect.ht_capa_mask));
6685
6686 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006687 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6688 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006689 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006690 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006691 memcpy(&connect.ht_capa,
6692 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6693 sizeof(connect.ht_capa));
6694 }
6695
Johannes Bergee2aca32013-02-21 17:36:01 +01006696 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6697 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6698
6699 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6700 memcpy(&connect.vht_capa_mask,
6701 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6702 sizeof(connect.vht_capa_mask));
6703
6704 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6705 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6706 kfree(connkeys);
6707 return -EINVAL;
6708 }
6709 memcpy(&connect.vht_capa,
6710 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6711 sizeof(connect.vht_capa));
6712 }
6713
Johannes Berg83739b02013-05-15 17:44:01 +02006714 wdev_lock(dev->ieee80211_ptr);
6715 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6716 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006717 if (err)
6718 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006719 return err;
6720}
6721
6722static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6723{
Johannes Berg4c476992010-10-04 21:36:35 +02006724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6725 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006726 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006727 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006728
6729 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6730 reason = WLAN_REASON_DEAUTH_LEAVING;
6731 else
6732 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6733
6734 if (reason == 0)
6735 return -EINVAL;
6736
Johannes Berg074ac8d2010-09-16 14:58:22 +02006737 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006738 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6739 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006740
Johannes Berg83739b02013-05-15 17:44:01 +02006741 wdev_lock(dev->ieee80211_ptr);
6742 ret = cfg80211_disconnect(rdev, dev, reason, true);
6743 wdev_unlock(dev->ieee80211_ptr);
6744 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006745}
6746
Johannes Berg463d0182009-07-14 00:33:35 +02006747static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6748{
Johannes Berg4c476992010-10-04 21:36:35 +02006749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006750 struct net *net;
6751 int err;
6752 u32 pid;
6753
6754 if (!info->attrs[NL80211_ATTR_PID])
6755 return -EINVAL;
6756
6757 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6758
Johannes Berg463d0182009-07-14 00:33:35 +02006759 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006760 if (IS_ERR(net))
6761 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006762
6763 err = 0;
6764
6765 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006766 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6767 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006768
Johannes Berg463d0182009-07-14 00:33:35 +02006769 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006770 return err;
6771}
6772
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006773static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6774{
Johannes Berg4c476992010-10-04 21:36:35 +02006775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006776 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6777 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006778 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006779 struct cfg80211_pmksa pmksa;
6780
6781 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6782
6783 if (!info->attrs[NL80211_ATTR_MAC])
6784 return -EINVAL;
6785
6786 if (!info->attrs[NL80211_ATTR_PMKID])
6787 return -EINVAL;
6788
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006789 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6790 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6791
Johannes Berg074ac8d2010-09-16 14:58:22 +02006792 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006793 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6794 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006795
6796 switch (info->genlhdr->cmd) {
6797 case NL80211_CMD_SET_PMKSA:
6798 rdev_ops = rdev->ops->set_pmksa;
6799 break;
6800 case NL80211_CMD_DEL_PMKSA:
6801 rdev_ops = rdev->ops->del_pmksa;
6802 break;
6803 default:
6804 WARN_ON(1);
6805 break;
6806 }
6807
Johannes Berg4c476992010-10-04 21:36:35 +02006808 if (!rdev_ops)
6809 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006810
Johannes Berg4c476992010-10-04 21:36:35 +02006811 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006812}
6813
6814static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6815{
Johannes Berg4c476992010-10-04 21:36:35 +02006816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6817 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006818
Johannes Berg074ac8d2010-09-16 14:58:22 +02006819 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006820 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6821 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006822
Johannes Berg4c476992010-10-04 21:36:35 +02006823 if (!rdev->ops->flush_pmksa)
6824 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006825
Hila Gonene35e4d22012-06-27 17:19:42 +03006826 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006827}
6828
Arik Nemtsov109086c2011-09-28 14:12:50 +03006829static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6830{
6831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6832 struct net_device *dev = info->user_ptr[1];
6833 u8 action_code, dialog_token;
6834 u16 status_code;
6835 u8 *peer;
6836
6837 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6838 !rdev->ops->tdls_mgmt)
6839 return -EOPNOTSUPP;
6840
6841 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6842 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6843 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6844 !info->attrs[NL80211_ATTR_IE] ||
6845 !info->attrs[NL80211_ATTR_MAC])
6846 return -EINVAL;
6847
6848 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6849 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6850 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6851 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6852
Hila Gonene35e4d22012-06-27 17:19:42 +03006853 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6854 dialog_token, status_code,
6855 nla_data(info->attrs[NL80211_ATTR_IE]),
6856 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006857}
6858
6859static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6860{
6861 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6862 struct net_device *dev = info->user_ptr[1];
6863 enum nl80211_tdls_operation operation;
6864 u8 *peer;
6865
6866 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6867 !rdev->ops->tdls_oper)
6868 return -EOPNOTSUPP;
6869
6870 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6871 !info->attrs[NL80211_ATTR_MAC])
6872 return -EINVAL;
6873
6874 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6875 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6876
Hila Gonene35e4d22012-06-27 17:19:42 +03006877 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006878}
6879
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006880static int nl80211_remain_on_channel(struct sk_buff *skb,
6881 struct genl_info *info)
6882{
Johannes Berg4c476992010-10-04 21:36:35 +02006883 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006884 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006885 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006886 struct sk_buff *msg;
6887 void *hdr;
6888 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006889 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006890 int err;
6891
6892 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6893 !info->attrs[NL80211_ATTR_DURATION])
6894 return -EINVAL;
6895
6896 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6897
Johannes Berg7c4ef712011-11-18 15:33:48 +01006898 if (!rdev->ops->remain_on_channel ||
6899 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006900 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006901
Johannes Bergebf348f2012-06-01 12:50:54 +02006902 /*
6903 * We should be on that channel for at least a minimum amount of
6904 * time (10ms) but no longer than the driver supports.
6905 */
6906 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6907 duration > rdev->wiphy.max_remain_on_channel_duration)
6908 return -EINVAL;
6909
Johannes Berg683b6d32012-11-08 21:25:48 +01006910 err = nl80211_parse_chandef(rdev, info, &chandef);
6911 if (err)
6912 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006913
6914 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006915 if (!msg)
6916 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006917
Eric W. Biederman15e47302012-09-07 20:12:54 +00006918 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006919 NL80211_CMD_REMAIN_ON_CHANNEL);
6920
6921 if (IS_ERR(hdr)) {
6922 err = PTR_ERR(hdr);
6923 goto free_msg;
6924 }
6925
Johannes Berg683b6d32012-11-08 21:25:48 +01006926 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6927 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006928
6929 if (err)
6930 goto free_msg;
6931
David S. Miller9360ffd2012-03-29 04:41:26 -04006932 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6933 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006934
6935 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006936
6937 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006938
6939 nla_put_failure:
6940 err = -ENOBUFS;
6941 free_msg:
6942 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006943 return err;
6944}
6945
6946static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6947 struct genl_info *info)
6948{
Johannes Berg4c476992010-10-04 21:36:35 +02006949 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006950 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006951 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006952
6953 if (!info->attrs[NL80211_ATTR_COOKIE])
6954 return -EINVAL;
6955
Johannes Berg4c476992010-10-04 21:36:35 +02006956 if (!rdev->ops->cancel_remain_on_channel)
6957 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006958
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006959 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6960
Hila Gonene35e4d22012-06-27 17:19:42 +03006961 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006962}
6963
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006964static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6965 u8 *rates, u8 rates_len)
6966{
6967 u8 i;
6968 u32 mask = 0;
6969
6970 for (i = 0; i < rates_len; i++) {
6971 int rate = (rates[i] & 0x7f) * 5;
6972 int ridx;
6973 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6974 struct ieee80211_rate *srate =
6975 &sband->bitrates[ridx];
6976 if (rate == srate->bitrate) {
6977 mask |= 1 << ridx;
6978 break;
6979 }
6980 }
6981 if (ridx == sband->n_bitrates)
6982 return 0; /* rate not found */
6983 }
6984
6985 return mask;
6986}
6987
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006988static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6989 u8 *rates, u8 rates_len,
6990 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6991{
6992 u8 i;
6993
6994 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6995
6996 for (i = 0; i < rates_len; i++) {
6997 int ridx, rbit;
6998
6999 ridx = rates[i] / 8;
7000 rbit = BIT(rates[i] % 8);
7001
7002 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007003 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007004 return false;
7005
7006 /* check availability */
7007 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7008 mcs[ridx] |= rbit;
7009 else
7010 return false;
7011 }
7012
7013 return true;
7014}
7015
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007016static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007017 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7018 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007019 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7020 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007021};
7022
7023static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7024 struct genl_info *info)
7025{
7026 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007028 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007029 int rem, i;
7030 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007031 struct nlattr *tx_rates;
7032 struct ieee80211_supported_band *sband;
7033
7034 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7035 return -EINVAL;
7036
Johannes Berg4c476992010-10-04 21:36:35 +02007037 if (!rdev->ops->set_bitrate_mask)
7038 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007039
7040 memset(&mask, 0, sizeof(mask));
7041 /* Default to all rates enabled */
7042 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7043 sband = rdev->wiphy.bands[i];
7044 mask.control[i].legacy =
7045 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007046 if (sband)
7047 memcpy(mask.control[i].mcs,
7048 sband->ht_cap.mcs.rx_mask,
7049 sizeof(mask.control[i].mcs));
7050 else
7051 memset(mask.control[i].mcs, 0,
7052 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007053 }
7054
7055 /*
7056 * The nested attribute uses enum nl80211_band as the index. This maps
7057 * directly to the enum ieee80211_band values used in cfg80211.
7058 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007059 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007060 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7061 {
7062 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007063 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7064 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007065 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007066 if (sband == NULL)
7067 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007068 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7069 nla_len(tx_rates), nl80211_txattr_policy);
7070 if (tb[NL80211_TXRATE_LEGACY]) {
7071 mask.control[band].legacy = rateset_to_mask(
7072 sband,
7073 nla_data(tb[NL80211_TXRATE_LEGACY]),
7074 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307075 if ((mask.control[band].legacy == 0) &&
7076 nla_len(tb[NL80211_TXRATE_LEGACY]))
7077 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007078 }
7079 if (tb[NL80211_TXRATE_MCS]) {
7080 if (!ht_rateset_to_mask(
7081 sband,
7082 nla_data(tb[NL80211_TXRATE_MCS]),
7083 nla_len(tb[NL80211_TXRATE_MCS]),
7084 mask.control[band].mcs))
7085 return -EINVAL;
7086 }
7087
7088 if (mask.control[band].legacy == 0) {
7089 /* don't allow empty legacy rates if HT
7090 * is not even supported. */
7091 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7092 return -EINVAL;
7093
7094 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7095 if (mask.control[band].mcs[i])
7096 break;
7097
7098 /* legacy and mcs rates may not be both empty */
7099 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007100 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007101 }
7102 }
7103
Hila Gonene35e4d22012-06-27 17:19:42 +03007104 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007105}
7106
Johannes Berg2e161f72010-08-12 15:38:38 +02007107static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007108{
Johannes Berg4c476992010-10-04 21:36:35 +02007109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007110 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007111 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007112
7113 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7114 return -EINVAL;
7115
Johannes Berg2e161f72010-08-12 15:38:38 +02007116 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7117 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007118
Johannes Berg71bbc992012-06-15 15:30:18 +02007119 switch (wdev->iftype) {
7120 case NL80211_IFTYPE_STATION:
7121 case NL80211_IFTYPE_ADHOC:
7122 case NL80211_IFTYPE_P2P_CLIENT:
7123 case NL80211_IFTYPE_AP:
7124 case NL80211_IFTYPE_AP_VLAN:
7125 case NL80211_IFTYPE_MESH_POINT:
7126 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007127 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007128 break;
7129 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007130 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007131 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007132
7133 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007134 if (!rdev->ops->mgmt_tx)
7135 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007136
Eric W. Biederman15e47302012-09-07 20:12:54 +00007137 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007138 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7139 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007140}
7141
Johannes Berg2e161f72010-08-12 15:38:38 +02007142static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007143{
Johannes Berg4c476992010-10-04 21:36:35 +02007144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007145 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007146 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007147 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007148 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007149 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007150 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007151 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007152 bool offchan, no_cck, dont_wait_for_ack;
7153
7154 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007155
Johannes Berg683b6d32012-11-08 21:25:48 +01007156 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007157 return -EINVAL;
7158
Johannes Berg4c476992010-10-04 21:36:35 +02007159 if (!rdev->ops->mgmt_tx)
7160 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007161
Johannes Berg71bbc992012-06-15 15:30:18 +02007162 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007163 case NL80211_IFTYPE_P2P_DEVICE:
7164 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7165 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007166 case NL80211_IFTYPE_STATION:
7167 case NL80211_IFTYPE_ADHOC:
7168 case NL80211_IFTYPE_P2P_CLIENT:
7169 case NL80211_IFTYPE_AP:
7170 case NL80211_IFTYPE_AP_VLAN:
7171 case NL80211_IFTYPE_MESH_POINT:
7172 case NL80211_IFTYPE_P2P_GO:
7173 break;
7174 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007175 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007176 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007177
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007178 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007179 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007180 return -EINVAL;
7181 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007182
7183 /*
7184 * We should wait on the channel for at least a minimum amount
7185 * of time (10ms) but no longer than the driver supports.
7186 */
7187 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7188 wait > rdev->wiphy.max_remain_on_channel_duration)
7189 return -EINVAL;
7190
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007191 }
7192
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007193 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7194
Johannes Berg7c4ef712011-11-18 15:33:48 +01007195 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7196 return -EINVAL;
7197
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307198 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7199
Antonio Quartulliea141b752013-06-11 14:20:03 +02007200 /* get the channel if any has been specified, otherwise pass NULL to
7201 * the driver. The latter will use the current one
7202 */
7203 chandef.chan = NULL;
7204 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7205 err = nl80211_parse_chandef(rdev, info, &chandef);
7206 if (err)
7207 return err;
7208 }
7209
7210 if (!chandef.chan && offchan)
7211 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007212
Johannes Berge247bd902011-11-04 11:18:21 +01007213 if (!dont_wait_for_ack) {
7214 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7215 if (!msg)
7216 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007217
Eric W. Biederman15e47302012-09-07 20:12:54 +00007218 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007219 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007220
Johannes Berge247bd902011-11-04 11:18:21 +01007221 if (IS_ERR(hdr)) {
7222 err = PTR_ERR(hdr);
7223 goto free_msg;
7224 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007225 }
Johannes Berge247bd902011-11-04 11:18:21 +01007226
Johannes Berg683b6d32012-11-08 21:25:48 +01007227 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007228 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7229 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007230 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007231 if (err)
7232 goto free_msg;
7233
Johannes Berge247bd902011-11-04 11:18:21 +01007234 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007235 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7236 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007237
Johannes Berge247bd902011-11-04 11:18:21 +01007238 genlmsg_end(msg, hdr);
7239 return genlmsg_reply(msg, info);
7240 }
7241
7242 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007243
7244 nla_put_failure:
7245 err = -ENOBUFS;
7246 free_msg:
7247 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007248 return err;
7249}
7250
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007251static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7252{
7253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007254 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007255 u64 cookie;
7256
7257 if (!info->attrs[NL80211_ATTR_COOKIE])
7258 return -EINVAL;
7259
7260 if (!rdev->ops->mgmt_tx_cancel_wait)
7261 return -EOPNOTSUPP;
7262
Johannes Berg71bbc992012-06-15 15:30:18 +02007263 switch (wdev->iftype) {
7264 case NL80211_IFTYPE_STATION:
7265 case NL80211_IFTYPE_ADHOC:
7266 case NL80211_IFTYPE_P2P_CLIENT:
7267 case NL80211_IFTYPE_AP:
7268 case NL80211_IFTYPE_AP_VLAN:
7269 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007270 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007271 break;
7272 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007273 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007274 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007275
7276 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7277
Hila Gonene35e4d22012-06-27 17:19:42 +03007278 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007279}
7280
Kalle Valoffb9eb32010-02-17 17:58:10 +02007281static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7282{
Johannes Berg4c476992010-10-04 21:36:35 +02007283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007284 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007285 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007286 u8 ps_state;
7287 bool state;
7288 int err;
7289
Johannes Berg4c476992010-10-04 21:36:35 +02007290 if (!info->attrs[NL80211_ATTR_PS_STATE])
7291 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007292
7293 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7294
Johannes Berg4c476992010-10-04 21:36:35 +02007295 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7296 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007297
7298 wdev = dev->ieee80211_ptr;
7299
Johannes Berg4c476992010-10-04 21:36:35 +02007300 if (!rdev->ops->set_power_mgmt)
7301 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007302
7303 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7304
7305 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007306 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007307
Hila Gonene35e4d22012-06-27 17:19:42 +03007308 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007309 if (!err)
7310 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007311 return err;
7312}
7313
7314static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7315{
Johannes Berg4c476992010-10-04 21:36:35 +02007316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007317 enum nl80211_ps_state ps_state;
7318 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007319 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007320 struct sk_buff *msg;
7321 void *hdr;
7322 int err;
7323
Kalle Valoffb9eb32010-02-17 17:58:10 +02007324 wdev = dev->ieee80211_ptr;
7325
Johannes Berg4c476992010-10-04 21:36:35 +02007326 if (!rdev->ops->set_power_mgmt)
7327 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007328
7329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007330 if (!msg)
7331 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007332
Eric W. Biederman15e47302012-09-07 20:12:54 +00007333 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007334 NL80211_CMD_GET_POWER_SAVE);
7335 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007336 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007337 goto free_msg;
7338 }
7339
7340 if (wdev->ps)
7341 ps_state = NL80211_PS_ENABLED;
7342 else
7343 ps_state = NL80211_PS_DISABLED;
7344
David S. Miller9360ffd2012-03-29 04:41:26 -04007345 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7346 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007347
7348 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007349 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007350
Johannes Berg4c476992010-10-04 21:36:35 +02007351 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007352 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007353 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007354 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007355 return err;
7356}
7357
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007358static struct nla_policy
7359nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7360 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7361 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7362 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007363 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7364 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7365 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007366};
7367
Thomas Pedersen84f10702012-07-12 16:17:33 -07007368static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007369 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007370{
7371 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7372 struct wireless_dev *wdev;
7373 struct net_device *dev = info->user_ptr[1];
7374
Johannes Bergd9d8b012012-11-26 12:51:52 +01007375 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007376 return -EINVAL;
7377
7378 wdev = dev->ieee80211_ptr;
7379
7380 if (!rdev->ops->set_cqm_txe_config)
7381 return -EOPNOTSUPP;
7382
7383 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7384 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7385 return -EOPNOTSUPP;
7386
Hila Gonene35e4d22012-06-27 17:19:42 +03007387 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007388}
7389
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007390static int nl80211_set_cqm_rssi(struct genl_info *info,
7391 s32 threshold, u32 hysteresis)
7392{
Johannes Berg4c476992010-10-04 21:36:35 +02007393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007394 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007395 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007396
7397 if (threshold > 0)
7398 return -EINVAL;
7399
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007400 wdev = dev->ieee80211_ptr;
7401
Johannes Berg4c476992010-10-04 21:36:35 +02007402 if (!rdev->ops->set_cqm_rssi_config)
7403 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007404
Johannes Berg074ac8d2010-09-16 14:58:22 +02007405 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007406 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7407 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007408
Hila Gonene35e4d22012-06-27 17:19:42 +03007409 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007410}
7411
7412static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7413{
7414 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7415 struct nlattr *cqm;
7416 int err;
7417
7418 cqm = info->attrs[NL80211_ATTR_CQM];
7419 if (!cqm) {
7420 err = -EINVAL;
7421 goto out;
7422 }
7423
7424 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7425 nl80211_attr_cqm_policy);
7426 if (err)
7427 goto out;
7428
7429 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7430 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7431 s32 threshold;
7432 u32 hysteresis;
7433 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7434 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7435 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007436 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7437 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7438 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7439 u32 rate, pkts, intvl;
7440 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7441 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7442 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7443 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007444 } else
7445 err = -EINVAL;
7446
7447out:
7448 return err;
7449}
7450
Johannes Berg29cbe682010-12-03 09:20:44 +01007451static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7452{
7453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7454 struct net_device *dev = info->user_ptr[1];
7455 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007456 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007457 int err;
7458
7459 /* start with default */
7460 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007461 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007462
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007463 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007464 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007465 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007466 if (err)
7467 return err;
7468 }
7469
7470 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7471 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7472 return -EINVAL;
7473
Javier Cardonac80d5452010-12-16 17:37:49 -08007474 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7475 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7476
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007477 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7478 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7479 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7480 return -EINVAL;
7481
Marco Porsch9bdbf042013-01-07 16:04:51 +01007482 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7483 setup.beacon_interval =
7484 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7485 if (setup.beacon_interval < 10 ||
7486 setup.beacon_interval > 10000)
7487 return -EINVAL;
7488 }
7489
7490 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7491 setup.dtim_period =
7492 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7493 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7494 return -EINVAL;
7495 }
7496
Javier Cardonac80d5452010-12-16 17:37:49 -08007497 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7498 /* parse additional setup parameters if given */
7499 err = nl80211_parse_mesh_setup(info, &setup);
7500 if (err)
7501 return err;
7502 }
7503
Thomas Pedersend37bb182013-03-04 13:06:13 -08007504 if (setup.user_mpm)
7505 cfg.auto_open_plinks = false;
7506
Johannes Bergcc1d2802012-05-16 23:50:20 +02007507 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007508 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7509 if (err)
7510 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007511 } else {
7512 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007513 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007514 }
7515
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007516 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7517 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7518 int n_rates =
7519 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7520 struct ieee80211_supported_band *sband;
7521
7522 if (!setup.chandef.chan)
7523 return -EINVAL;
7524
7525 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7526
7527 err = ieee80211_get_ratemask(sband, rates, n_rates,
7528 &setup.basic_rates);
7529 if (err)
7530 return err;
7531 }
7532
Javier Cardonac80d5452010-12-16 17:37:49 -08007533 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007534}
7535
7536static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7537{
7538 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7539 struct net_device *dev = info->user_ptr[1];
7540
7541 return cfg80211_leave_mesh(rdev, dev);
7542}
7543
Johannes Bergdfb89c52012-06-27 09:23:48 +02007544#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007545static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7546 struct cfg80211_registered_device *rdev)
7547{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007548 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007549 struct nlattr *nl_pats, *nl_pat;
7550 int i, pat_len;
7551
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007552 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007553 return 0;
7554
7555 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7556 if (!nl_pats)
7557 return -ENOBUFS;
7558
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007559 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007560 nl_pat = nla_nest_start(msg, i + 1);
7561 if (!nl_pat)
7562 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007563 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007564 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7565 DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007566 wowlan->patterns[i].mask) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007567 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007568 pat_len, wowlan->patterns[i].pattern) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007569 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007570 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007571 return -ENOBUFS;
7572 nla_nest_end(msg, nl_pat);
7573 }
7574 nla_nest_end(msg, nl_pats);
7575
7576 return 0;
7577}
7578
Johannes Berg2a0e0472013-01-23 22:57:40 +01007579static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7580 struct cfg80211_wowlan_tcp *tcp)
7581{
7582 struct nlattr *nl_tcp;
7583
7584 if (!tcp)
7585 return 0;
7586
7587 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7588 if (!nl_tcp)
7589 return -ENOBUFS;
7590
7591 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7592 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7593 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7594 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7595 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7596 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7597 tcp->payload_len, tcp->payload) ||
7598 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7599 tcp->data_interval) ||
7600 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7601 tcp->wake_len, tcp->wake_data) ||
7602 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7603 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7604 return -ENOBUFS;
7605
7606 if (tcp->payload_seq.len &&
7607 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7608 sizeof(tcp->payload_seq), &tcp->payload_seq))
7609 return -ENOBUFS;
7610
7611 if (tcp->payload_tok.len &&
7612 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7613 sizeof(tcp->payload_tok) + tcp->tokens_size,
7614 &tcp->payload_tok))
7615 return -ENOBUFS;
7616
Johannes Berge248ad32013-05-16 10:24:28 +02007617 nla_nest_end(msg, nl_tcp);
7618
Johannes Berg2a0e0472013-01-23 22:57:40 +01007619 return 0;
7620}
7621
Johannes Bergff1b6e62011-05-04 15:37:28 +02007622static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7623{
7624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7625 struct sk_buff *msg;
7626 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007627 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007628
Johannes Berg964dc9e2013-06-03 17:25:34 +02007629 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007630 return -EOPNOTSUPP;
7631
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007632 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007633 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007634 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7635 rdev->wiphy.wowlan_config->tcp->payload_len +
7636 rdev->wiphy.wowlan_config->tcp->wake_len +
7637 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007638 }
7639
7640 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007641 if (!msg)
7642 return -ENOMEM;
7643
Eric W. Biederman15e47302012-09-07 20:12:54 +00007644 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007645 NL80211_CMD_GET_WOWLAN);
7646 if (!hdr)
7647 goto nla_put_failure;
7648
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007649 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007650 struct nlattr *nl_wowlan;
7651
7652 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7653 if (!nl_wowlan)
7654 goto nla_put_failure;
7655
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007656 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007657 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007658 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007659 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007660 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007661 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007662 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007663 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007664 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007665 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007666 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007667 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007668 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007669 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7670 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007671
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007672 if (nl80211_send_wowlan_patterns(msg, rdev))
7673 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007674
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007675 if (nl80211_send_wowlan_tcp(msg,
7676 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007677 goto nla_put_failure;
7678
Johannes Bergff1b6e62011-05-04 15:37:28 +02007679 nla_nest_end(msg, nl_wowlan);
7680 }
7681
7682 genlmsg_end(msg, hdr);
7683 return genlmsg_reply(msg, info);
7684
7685nla_put_failure:
7686 nlmsg_free(msg);
7687 return -ENOBUFS;
7688}
7689
Johannes Berg2a0e0472013-01-23 22:57:40 +01007690static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7691 struct nlattr *attr,
7692 struct cfg80211_wowlan *trig)
7693{
7694 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7695 struct cfg80211_wowlan_tcp *cfg;
7696 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7697 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7698 u32 size;
7699 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7700 int err, port;
7701
Johannes Berg964dc9e2013-06-03 17:25:34 +02007702 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007703 return -EINVAL;
7704
7705 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7706 nla_data(attr), nla_len(attr),
7707 nl80211_wowlan_tcp_policy);
7708 if (err)
7709 return err;
7710
7711 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7712 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7713 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7714 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7715 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7716 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7717 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7718 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7719 return -EINVAL;
7720
7721 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007722 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007723 return -EINVAL;
7724
7725 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007726 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007727 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007728 return -EINVAL;
7729
7730 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007731 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007732 return -EINVAL;
7733
7734 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7735 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7736 return -EINVAL;
7737
7738 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7739 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7740
7741 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7742 tokens_size = tokln - sizeof(*tok);
7743
7744 if (!tok->len || tokens_size % tok->len)
7745 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007746 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007747 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007748 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007749 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007750 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007751 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007752 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007753 return -EINVAL;
7754 if (tok->offset + tok->len > data_size)
7755 return -EINVAL;
7756 }
7757
7758 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7759 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007760 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007761 return -EINVAL;
7762 if (seq->len == 0 || seq->len > 4)
7763 return -EINVAL;
7764 if (seq->len + seq->offset > data_size)
7765 return -EINVAL;
7766 }
7767
7768 size = sizeof(*cfg);
7769 size += data_size;
7770 size += wake_size + wake_mask_size;
7771 size += tokens_size;
7772
7773 cfg = kzalloc(size, GFP_KERNEL);
7774 if (!cfg)
7775 return -ENOMEM;
7776 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7777 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7778 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7779 ETH_ALEN);
7780 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7781 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7782 else
7783 port = 0;
7784#ifdef CONFIG_INET
7785 /* allocate a socket and port for it and use it */
7786 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7787 IPPROTO_TCP, &cfg->sock, 1);
7788 if (err) {
7789 kfree(cfg);
7790 return err;
7791 }
7792 if (inet_csk_get_port(cfg->sock->sk, port)) {
7793 sock_release(cfg->sock);
7794 kfree(cfg);
7795 return -EADDRINUSE;
7796 }
7797 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7798#else
7799 if (!port) {
7800 kfree(cfg);
7801 return -EINVAL;
7802 }
7803 cfg->src_port = port;
7804#endif
7805
7806 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7807 cfg->payload_len = data_size;
7808 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7809 memcpy((void *)cfg->payload,
7810 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7811 data_size);
7812 if (seq)
7813 cfg->payload_seq = *seq;
7814 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7815 cfg->wake_len = wake_size;
7816 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7817 memcpy((void *)cfg->wake_data,
7818 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7819 wake_size);
7820 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7821 data_size + wake_size;
7822 memcpy((void *)cfg->wake_mask,
7823 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7824 wake_mask_size);
7825 if (tok) {
7826 cfg->tokens_size = tokens_size;
7827 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7828 }
7829
7830 trig->tcp = cfg;
7831
7832 return 0;
7833}
7834
Johannes Bergff1b6e62011-05-04 15:37:28 +02007835static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7836{
7837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7838 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007839 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007840 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007841 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007842 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007843 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007844
Johannes Berg964dc9e2013-06-03 17:25:34 +02007845 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007846 return -EOPNOTSUPP;
7847
Johannes Bergae33bd82012-07-12 16:25:02 +02007848 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7849 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007850 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007851 goto set_wakeup;
7852 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007853
7854 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7855 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7856 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7857 nl80211_wowlan_policy);
7858 if (err)
7859 return err;
7860
7861 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7862 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7863 return -EINVAL;
7864 new_triggers.any = true;
7865 }
7866
7867 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7868 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7869 return -EINVAL;
7870 new_triggers.disconnect = true;
7871 }
7872
7873 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7874 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7875 return -EINVAL;
7876 new_triggers.magic_pkt = true;
7877 }
7878
Johannes Berg77dbbb12011-07-13 10:48:55 +02007879 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7880 return -EINVAL;
7881
7882 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7883 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7884 return -EINVAL;
7885 new_triggers.gtk_rekey_failure = true;
7886 }
7887
7888 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7889 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7890 return -EINVAL;
7891 new_triggers.eap_identity_req = true;
7892 }
7893
7894 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7895 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7896 return -EINVAL;
7897 new_triggers.four_way_handshake = true;
7898 }
7899
7900 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7901 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7902 return -EINVAL;
7903 new_triggers.rfkill_release = true;
7904 }
7905
Johannes Bergff1b6e62011-05-04 15:37:28 +02007906 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7907 struct nlattr *pat;
7908 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007909 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007910 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7911
7912 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7913 rem)
7914 n_patterns++;
7915 if (n_patterns > wowlan->n_patterns)
7916 return -EINVAL;
7917
7918 new_triggers.patterns = kcalloc(n_patterns,
7919 sizeof(new_triggers.patterns[0]),
7920 GFP_KERNEL);
7921 if (!new_triggers.patterns)
7922 return -ENOMEM;
7923
7924 new_triggers.n_patterns = n_patterns;
7925 i = 0;
7926
7927 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7928 rem) {
7929 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7930 nla_data(pat), nla_len(pat), NULL);
7931 err = -EINVAL;
7932 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7933 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7934 goto error;
7935 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7936 mask_len = DIV_ROUND_UP(pat_len, 8);
7937 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7938 mask_len)
7939 goto error;
7940 if (pat_len > wowlan->pattern_max_len ||
7941 pat_len < wowlan->pattern_min_len)
7942 goto error;
7943
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007944 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7945 pkt_offset = 0;
7946 else
7947 pkt_offset = nla_get_u32(
7948 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7949 if (pkt_offset > wowlan->max_pkt_offset)
7950 goto error;
7951 new_triggers.patterns[i].pkt_offset = pkt_offset;
7952
Johannes Bergff1b6e62011-05-04 15:37:28 +02007953 new_triggers.patterns[i].mask =
7954 kmalloc(mask_len + pat_len, GFP_KERNEL);
7955 if (!new_triggers.patterns[i].mask) {
7956 err = -ENOMEM;
7957 goto error;
7958 }
7959 new_triggers.patterns[i].pattern =
7960 new_triggers.patterns[i].mask + mask_len;
7961 memcpy(new_triggers.patterns[i].mask,
7962 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7963 mask_len);
7964 new_triggers.patterns[i].pattern_len = pat_len;
7965 memcpy(new_triggers.patterns[i].pattern,
7966 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7967 pat_len);
7968 i++;
7969 }
7970 }
7971
Johannes Berg2a0e0472013-01-23 22:57:40 +01007972 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7973 err = nl80211_parse_wowlan_tcp(
7974 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7975 &new_triggers);
7976 if (err)
7977 goto error;
7978 }
7979
Johannes Bergae33bd82012-07-12 16:25:02 +02007980 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7981 if (!ntrig) {
7982 err = -ENOMEM;
7983 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007984 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007985 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007986 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007987
Johannes Bergae33bd82012-07-12 16:25:02 +02007988 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007989 if (rdev->ops->set_wakeup &&
7990 prev_enabled != !!rdev->wiphy.wowlan_config)
7991 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02007992
Johannes Bergff1b6e62011-05-04 15:37:28 +02007993 return 0;
7994 error:
7995 for (i = 0; i < new_triggers.n_patterns; i++)
7996 kfree(new_triggers.patterns[i].mask);
7997 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007998 if (new_triggers.tcp && new_triggers.tcp->sock)
7999 sock_release(new_triggers.tcp->sock);
8000 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008001 return err;
8002}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008003#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008004
Johannes Berge5497d72011-07-05 16:35:40 +02008005static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8006{
8007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8008 struct net_device *dev = info->user_ptr[1];
8009 struct wireless_dev *wdev = dev->ieee80211_ptr;
8010 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8011 struct cfg80211_gtk_rekey_data rekey_data;
8012 int err;
8013
8014 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8015 return -EINVAL;
8016
8017 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8018 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8019 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8020 nl80211_rekey_policy);
8021 if (err)
8022 return err;
8023
8024 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8025 return -ERANGE;
8026 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8027 return -ERANGE;
8028 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8029 return -ERANGE;
8030
8031 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8032 NL80211_KEK_LEN);
8033 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8034 NL80211_KCK_LEN);
8035 memcpy(rekey_data.replay_ctr,
8036 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8037 NL80211_REPLAY_CTR_LEN);
8038
8039 wdev_lock(wdev);
8040 if (!wdev->current_bss) {
8041 err = -ENOTCONN;
8042 goto out;
8043 }
8044
8045 if (!rdev->ops->set_rekey_data) {
8046 err = -EOPNOTSUPP;
8047 goto out;
8048 }
8049
Hila Gonene35e4d22012-06-27 17:19:42 +03008050 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008051 out:
8052 wdev_unlock(wdev);
8053 return err;
8054}
8055
Johannes Berg28946da2011-11-04 11:18:12 +01008056static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8057 struct genl_info *info)
8058{
8059 struct net_device *dev = info->user_ptr[1];
8060 struct wireless_dev *wdev = dev->ieee80211_ptr;
8061
8062 if (wdev->iftype != NL80211_IFTYPE_AP &&
8063 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8064 return -EINVAL;
8065
Eric W. Biederman15e47302012-09-07 20:12:54 +00008066 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008067 return -EBUSY;
8068
Eric W. Biederman15e47302012-09-07 20:12:54 +00008069 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008070 return 0;
8071}
8072
Johannes Berg7f6cf312011-11-04 11:18:15 +01008073static int nl80211_probe_client(struct sk_buff *skb,
8074 struct genl_info *info)
8075{
8076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8077 struct net_device *dev = info->user_ptr[1];
8078 struct wireless_dev *wdev = dev->ieee80211_ptr;
8079 struct sk_buff *msg;
8080 void *hdr;
8081 const u8 *addr;
8082 u64 cookie;
8083 int err;
8084
8085 if (wdev->iftype != NL80211_IFTYPE_AP &&
8086 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8087 return -EOPNOTSUPP;
8088
8089 if (!info->attrs[NL80211_ATTR_MAC])
8090 return -EINVAL;
8091
8092 if (!rdev->ops->probe_client)
8093 return -EOPNOTSUPP;
8094
8095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8096 if (!msg)
8097 return -ENOMEM;
8098
Eric W. Biederman15e47302012-09-07 20:12:54 +00008099 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008100 NL80211_CMD_PROBE_CLIENT);
8101
8102 if (IS_ERR(hdr)) {
8103 err = PTR_ERR(hdr);
8104 goto free_msg;
8105 }
8106
8107 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8108
Hila Gonene35e4d22012-06-27 17:19:42 +03008109 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008110 if (err)
8111 goto free_msg;
8112
David S. Miller9360ffd2012-03-29 04:41:26 -04008113 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8114 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008115
8116 genlmsg_end(msg, hdr);
8117
8118 return genlmsg_reply(msg, info);
8119
8120 nla_put_failure:
8121 err = -ENOBUFS;
8122 free_msg:
8123 nlmsg_free(msg);
8124 return err;
8125}
8126
Johannes Berg5e7602302011-11-04 11:18:17 +01008127static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8128{
8129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008130 struct cfg80211_beacon_registration *reg, *nreg;
8131 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008132
8133 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8134 return -EOPNOTSUPP;
8135
Ben Greear37c73b52012-10-26 14:49:25 -07008136 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8137 if (!nreg)
8138 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008139
Ben Greear37c73b52012-10-26 14:49:25 -07008140 /* First, check if already registered. */
8141 spin_lock_bh(&rdev->beacon_registrations_lock);
8142 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8143 if (reg->nlportid == info->snd_portid) {
8144 rv = -EALREADY;
8145 goto out_err;
8146 }
8147 }
8148 /* Add it to the list */
8149 nreg->nlportid = info->snd_portid;
8150 list_add(&nreg->list, &rdev->beacon_registrations);
8151
8152 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008153
8154 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008155out_err:
8156 spin_unlock_bh(&rdev->beacon_registrations_lock);
8157 kfree(nreg);
8158 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008159}
8160
Johannes Berg98104fde2012-06-16 00:19:54 +02008161static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8162{
8163 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8164 struct wireless_dev *wdev = info->user_ptr[1];
8165 int err;
8166
8167 if (!rdev->ops->start_p2p_device)
8168 return -EOPNOTSUPP;
8169
8170 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8171 return -EOPNOTSUPP;
8172
8173 if (wdev->p2p_started)
8174 return 0;
8175
Johannes Berg98104fde2012-06-16 00:19:54 +02008176 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008177 if (err)
8178 return err;
8179
Johannes Bergeeb126e2012-10-23 15:16:50 +02008180 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008181 if (err)
8182 return err;
8183
8184 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008185 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008186
8187 return 0;
8188}
8189
8190static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8191{
8192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8193 struct wireless_dev *wdev = info->user_ptr[1];
8194
8195 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8196 return -EOPNOTSUPP;
8197
8198 if (!rdev->ops->stop_p2p_device)
8199 return -EOPNOTSUPP;
8200
Johannes Bergf9f47522013-03-19 15:04:07 +01008201 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008202
8203 return 0;
8204}
8205
Johannes Berg3713b4e2013-02-14 16:19:38 +01008206static int nl80211_get_protocol_features(struct sk_buff *skb,
8207 struct genl_info *info)
8208{
8209 void *hdr;
8210 struct sk_buff *msg;
8211
8212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8213 if (!msg)
8214 return -ENOMEM;
8215
8216 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8217 NL80211_CMD_GET_PROTOCOL_FEATURES);
8218 if (!hdr)
8219 goto nla_put_failure;
8220
8221 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8222 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8223 goto nla_put_failure;
8224
8225 genlmsg_end(msg, hdr);
8226 return genlmsg_reply(msg, info);
8227
8228 nla_put_failure:
8229 kfree_skb(msg);
8230 return -ENOBUFS;
8231}
8232
Jouni Malinen355199e2013-02-27 17:14:27 +02008233static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8234{
8235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8236 struct cfg80211_update_ft_ies_params ft_params;
8237 struct net_device *dev = info->user_ptr[1];
8238
8239 if (!rdev->ops->update_ft_ies)
8240 return -EOPNOTSUPP;
8241
8242 if (!info->attrs[NL80211_ATTR_MDID] ||
8243 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8244 return -EINVAL;
8245
8246 memset(&ft_params, 0, sizeof(ft_params));
8247 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8248 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8249 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8250
8251 return rdev_update_ft_ies(rdev, dev, &ft_params);
8252}
8253
Arend van Spriel5de17982013-04-18 15:49:00 +02008254static int nl80211_crit_protocol_start(struct sk_buff *skb,
8255 struct genl_info *info)
8256{
8257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8258 struct wireless_dev *wdev = info->user_ptr[1];
8259 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8260 u16 duration;
8261 int ret;
8262
8263 if (!rdev->ops->crit_proto_start)
8264 return -EOPNOTSUPP;
8265
8266 if (WARN_ON(!rdev->ops->crit_proto_stop))
8267 return -EINVAL;
8268
8269 if (rdev->crit_proto_nlportid)
8270 return -EBUSY;
8271
8272 /* determine protocol if provided */
8273 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8274 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8275
8276 if (proto >= NUM_NL80211_CRIT_PROTO)
8277 return -EINVAL;
8278
8279 /* timeout must be provided */
8280 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8281 return -EINVAL;
8282
8283 duration =
8284 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8285
8286 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8287 return -ERANGE;
8288
8289 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8290 if (!ret)
8291 rdev->crit_proto_nlportid = info->snd_portid;
8292
8293 return ret;
8294}
8295
8296static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8297 struct genl_info *info)
8298{
8299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8300 struct wireless_dev *wdev = info->user_ptr[1];
8301
8302 if (!rdev->ops->crit_proto_stop)
8303 return -EOPNOTSUPP;
8304
8305 if (rdev->crit_proto_nlportid) {
8306 rdev->crit_proto_nlportid = 0;
8307 rdev_crit_proto_stop(rdev, wdev);
8308 }
8309 return 0;
8310}
8311
Johannes Berg4c476992010-10-04 21:36:35 +02008312#define NL80211_FLAG_NEED_WIPHY 0x01
8313#define NL80211_FLAG_NEED_NETDEV 0x02
8314#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008315#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8316#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8317 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008318#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008319/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008320#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8321 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008322
8323static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8324 struct genl_info *info)
8325{
8326 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008327 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008328 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008329 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8330
8331 if (rtnl)
8332 rtnl_lock();
8333
8334 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008335 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008336 if (IS_ERR(rdev)) {
8337 if (rtnl)
8338 rtnl_unlock();
8339 return PTR_ERR(rdev);
8340 }
8341 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008342 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8343 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008344 ASSERT_RTNL();
8345
Johannes Berg89a54e42012-06-15 14:33:17 +02008346 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8347 info->attrs);
8348 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008349 if (rtnl)
8350 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008351 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008352 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008353
Johannes Berg89a54e42012-06-15 14:33:17 +02008354 dev = wdev->netdev;
8355 rdev = wiphy_to_dev(wdev->wiphy);
8356
Johannes Berg1bf614e2012-06-15 15:23:36 +02008357 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8358 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008359 if (rtnl)
8360 rtnl_unlock();
8361 return -EINVAL;
8362 }
8363
8364 info->user_ptr[1] = dev;
8365 } else {
8366 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008367 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008368
Johannes Berg1bf614e2012-06-15 15:23:36 +02008369 if (dev) {
8370 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8371 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008372 if (rtnl)
8373 rtnl_unlock();
8374 return -ENETDOWN;
8375 }
8376
8377 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008378 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8379 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008380 if (rtnl)
8381 rtnl_unlock();
8382 return -ENETDOWN;
8383 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008384 }
8385
Johannes Berg4c476992010-10-04 21:36:35 +02008386 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008387 }
8388
8389 return 0;
8390}
8391
8392static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8393 struct genl_info *info)
8394{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008395 if (info->user_ptr[1]) {
8396 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8397 struct wireless_dev *wdev = info->user_ptr[1];
8398
8399 if (wdev->netdev)
8400 dev_put(wdev->netdev);
8401 } else {
8402 dev_put(info->user_ptr[1]);
8403 }
8404 }
Johannes Berg4c476992010-10-04 21:36:35 +02008405 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8406 rtnl_unlock();
8407}
8408
Johannes Berg55682962007-09-20 13:09:35 -04008409static struct genl_ops nl80211_ops[] = {
8410 {
8411 .cmd = NL80211_CMD_GET_WIPHY,
8412 .doit = nl80211_get_wiphy,
8413 .dumpit = nl80211_dump_wiphy,
8414 .policy = nl80211_policy,
8415 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008416 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8417 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008418 },
8419 {
8420 .cmd = NL80211_CMD_SET_WIPHY,
8421 .doit = nl80211_set_wiphy,
8422 .policy = nl80211_policy,
8423 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008424 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008425 },
8426 {
8427 .cmd = NL80211_CMD_GET_INTERFACE,
8428 .doit = nl80211_get_interface,
8429 .dumpit = nl80211_dump_interface,
8430 .policy = nl80211_policy,
8431 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008432 .internal_flags = NL80211_FLAG_NEED_WDEV |
8433 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008434 },
8435 {
8436 .cmd = NL80211_CMD_SET_INTERFACE,
8437 .doit = nl80211_set_interface,
8438 .policy = nl80211_policy,
8439 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008440 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8441 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008442 },
8443 {
8444 .cmd = NL80211_CMD_NEW_INTERFACE,
8445 .doit = nl80211_new_interface,
8446 .policy = nl80211_policy,
8447 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008448 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8449 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008450 },
8451 {
8452 .cmd = NL80211_CMD_DEL_INTERFACE,
8453 .doit = nl80211_del_interface,
8454 .policy = nl80211_policy,
8455 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008456 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008457 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008458 },
Johannes Berg41ade002007-12-19 02:03:29 +01008459 {
8460 .cmd = NL80211_CMD_GET_KEY,
8461 .doit = nl80211_get_key,
8462 .policy = nl80211_policy,
8463 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008465 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008466 },
8467 {
8468 .cmd = NL80211_CMD_SET_KEY,
8469 .doit = nl80211_set_key,
8470 .policy = nl80211_policy,
8471 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008473 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008474 },
8475 {
8476 .cmd = NL80211_CMD_NEW_KEY,
8477 .doit = nl80211_new_key,
8478 .policy = nl80211_policy,
8479 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008481 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008482 },
8483 {
8484 .cmd = NL80211_CMD_DEL_KEY,
8485 .doit = nl80211_del_key,
8486 .policy = nl80211_policy,
8487 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008488 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008489 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008490 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008491 {
8492 .cmd = NL80211_CMD_SET_BEACON,
8493 .policy = nl80211_policy,
8494 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008495 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008497 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008498 },
8499 {
Johannes Berg88600202012-02-13 15:17:18 +01008500 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008501 .policy = nl80211_policy,
8502 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008503 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008505 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008506 },
8507 {
Johannes Berg88600202012-02-13 15:17:18 +01008508 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008509 .policy = nl80211_policy,
8510 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008511 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008513 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008514 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008515 {
8516 .cmd = NL80211_CMD_GET_STATION,
8517 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008518 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008519 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008520 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8521 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008522 },
8523 {
8524 .cmd = NL80211_CMD_SET_STATION,
8525 .doit = nl80211_set_station,
8526 .policy = nl80211_policy,
8527 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008529 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008530 },
8531 {
8532 .cmd = NL80211_CMD_NEW_STATION,
8533 .doit = nl80211_new_station,
8534 .policy = nl80211_policy,
8535 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008537 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008538 },
8539 {
8540 .cmd = NL80211_CMD_DEL_STATION,
8541 .doit = nl80211_del_station,
8542 .policy = nl80211_policy,
8543 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008544 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008545 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008546 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008547 {
8548 .cmd = NL80211_CMD_GET_MPATH,
8549 .doit = nl80211_get_mpath,
8550 .dumpit = nl80211_dump_mpath,
8551 .policy = nl80211_policy,
8552 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008554 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008555 },
8556 {
8557 .cmd = NL80211_CMD_SET_MPATH,
8558 .doit = nl80211_set_mpath,
8559 .policy = nl80211_policy,
8560 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008562 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008563 },
8564 {
8565 .cmd = NL80211_CMD_NEW_MPATH,
8566 .doit = nl80211_new_mpath,
8567 .policy = nl80211_policy,
8568 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008569 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008570 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008571 },
8572 {
8573 .cmd = NL80211_CMD_DEL_MPATH,
8574 .doit = nl80211_del_mpath,
8575 .policy = nl80211_policy,
8576 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008578 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008579 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008580 {
8581 .cmd = NL80211_CMD_SET_BSS,
8582 .doit = nl80211_set_bss,
8583 .policy = nl80211_policy,
8584 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008585 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008586 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008587 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008588 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008589 .cmd = NL80211_CMD_GET_REG,
8590 .doit = nl80211_get_reg,
8591 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008592 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008593 /* can be retrieved by unprivileged users */
8594 },
8595 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008596 .cmd = NL80211_CMD_SET_REG,
8597 .doit = nl80211_set_reg,
8598 .policy = nl80211_policy,
8599 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008600 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008601 },
8602 {
8603 .cmd = NL80211_CMD_REQ_SET_REG,
8604 .doit = nl80211_req_set_reg,
8605 .policy = nl80211_policy,
8606 .flags = GENL_ADMIN_PERM,
8607 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008608 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008609 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8610 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008611 .policy = nl80211_policy,
8612 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008614 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008615 },
8616 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008617 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8618 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008619 .policy = nl80211_policy,
8620 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008622 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008623 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008624 {
Johannes Berg2a519312009-02-10 21:25:55 +01008625 .cmd = NL80211_CMD_TRIGGER_SCAN,
8626 .doit = nl80211_trigger_scan,
8627 .policy = nl80211_policy,
8628 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008629 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008630 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008631 },
8632 {
8633 .cmd = NL80211_CMD_GET_SCAN,
8634 .policy = nl80211_policy,
8635 .dumpit = nl80211_dump_scan,
8636 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008637 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008638 .cmd = NL80211_CMD_START_SCHED_SCAN,
8639 .doit = nl80211_start_sched_scan,
8640 .policy = nl80211_policy,
8641 .flags = GENL_ADMIN_PERM,
8642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8643 NL80211_FLAG_NEED_RTNL,
8644 },
8645 {
8646 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8647 .doit = nl80211_stop_sched_scan,
8648 .policy = nl80211_policy,
8649 .flags = GENL_ADMIN_PERM,
8650 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8651 NL80211_FLAG_NEED_RTNL,
8652 },
8653 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008654 .cmd = NL80211_CMD_AUTHENTICATE,
8655 .doit = nl80211_authenticate,
8656 .policy = nl80211_policy,
8657 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008658 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008659 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008660 },
8661 {
8662 .cmd = NL80211_CMD_ASSOCIATE,
8663 .doit = nl80211_associate,
8664 .policy = nl80211_policy,
8665 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008666 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008667 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008668 },
8669 {
8670 .cmd = NL80211_CMD_DEAUTHENTICATE,
8671 .doit = nl80211_deauthenticate,
8672 .policy = nl80211_policy,
8673 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008674 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008675 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008676 },
8677 {
8678 .cmd = NL80211_CMD_DISASSOCIATE,
8679 .doit = nl80211_disassociate,
8680 .policy = nl80211_policy,
8681 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008682 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008683 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008684 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008685 {
8686 .cmd = NL80211_CMD_JOIN_IBSS,
8687 .doit = nl80211_join_ibss,
8688 .policy = nl80211_policy,
8689 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008690 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008691 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008692 },
8693 {
8694 .cmd = NL80211_CMD_LEAVE_IBSS,
8695 .doit = nl80211_leave_ibss,
8696 .policy = nl80211_policy,
8697 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008699 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008700 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008701#ifdef CONFIG_NL80211_TESTMODE
8702 {
8703 .cmd = NL80211_CMD_TESTMODE,
8704 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008705 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008706 .policy = nl80211_policy,
8707 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008708 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8709 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008710 },
8711#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008712 {
8713 .cmd = NL80211_CMD_CONNECT,
8714 .doit = nl80211_connect,
8715 .policy = nl80211_policy,
8716 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008717 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008718 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008719 },
8720 {
8721 .cmd = NL80211_CMD_DISCONNECT,
8722 .doit = nl80211_disconnect,
8723 .policy = nl80211_policy,
8724 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008725 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008726 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008727 },
Johannes Berg463d0182009-07-14 00:33:35 +02008728 {
8729 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8730 .doit = nl80211_wiphy_netns,
8731 .policy = nl80211_policy,
8732 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008733 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8734 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008735 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008736 {
8737 .cmd = NL80211_CMD_GET_SURVEY,
8738 .policy = nl80211_policy,
8739 .dumpit = nl80211_dump_survey,
8740 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008741 {
8742 .cmd = NL80211_CMD_SET_PMKSA,
8743 .doit = nl80211_setdel_pmksa,
8744 .policy = nl80211_policy,
8745 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008747 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008748 },
8749 {
8750 .cmd = NL80211_CMD_DEL_PMKSA,
8751 .doit = nl80211_setdel_pmksa,
8752 .policy = nl80211_policy,
8753 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008755 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008756 },
8757 {
8758 .cmd = NL80211_CMD_FLUSH_PMKSA,
8759 .doit = nl80211_flush_pmksa,
8760 .policy = nl80211_policy,
8761 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008762 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008763 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008764 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008765 {
8766 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8767 .doit = nl80211_remain_on_channel,
8768 .policy = nl80211_policy,
8769 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008770 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008771 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008772 },
8773 {
8774 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8775 .doit = nl80211_cancel_remain_on_channel,
8776 .policy = nl80211_policy,
8777 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008778 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008779 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008780 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008781 {
8782 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8783 .doit = nl80211_set_tx_bitrate_mask,
8784 .policy = nl80211_policy,
8785 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008786 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8787 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008788 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008789 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008790 .cmd = NL80211_CMD_REGISTER_FRAME,
8791 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008792 .policy = nl80211_policy,
8793 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008794 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008795 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008796 },
8797 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008798 .cmd = NL80211_CMD_FRAME,
8799 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008800 .policy = nl80211_policy,
8801 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008802 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008803 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008804 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008805 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008806 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8807 .doit = nl80211_tx_mgmt_cancel_wait,
8808 .policy = nl80211_policy,
8809 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008810 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008811 NL80211_FLAG_NEED_RTNL,
8812 },
8813 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008814 .cmd = NL80211_CMD_SET_POWER_SAVE,
8815 .doit = nl80211_set_power_save,
8816 .policy = nl80211_policy,
8817 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008818 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8819 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008820 },
8821 {
8822 .cmd = NL80211_CMD_GET_POWER_SAVE,
8823 .doit = nl80211_get_power_save,
8824 .policy = nl80211_policy,
8825 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008826 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8827 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008828 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008829 {
8830 .cmd = NL80211_CMD_SET_CQM,
8831 .doit = nl80211_set_cqm,
8832 .policy = nl80211_policy,
8833 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008834 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8835 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008836 },
Johannes Bergf444de02010-05-05 15:25:02 +02008837 {
8838 .cmd = NL80211_CMD_SET_CHANNEL,
8839 .doit = nl80211_set_channel,
8840 .policy = nl80211_policy,
8841 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008842 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8843 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008844 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008845 {
8846 .cmd = NL80211_CMD_SET_WDS_PEER,
8847 .doit = nl80211_set_wds_peer,
8848 .policy = nl80211_policy,
8849 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008850 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8851 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008852 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008853 {
8854 .cmd = NL80211_CMD_JOIN_MESH,
8855 .doit = nl80211_join_mesh,
8856 .policy = nl80211_policy,
8857 .flags = GENL_ADMIN_PERM,
8858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8859 NL80211_FLAG_NEED_RTNL,
8860 },
8861 {
8862 .cmd = NL80211_CMD_LEAVE_MESH,
8863 .doit = nl80211_leave_mesh,
8864 .policy = nl80211_policy,
8865 .flags = GENL_ADMIN_PERM,
8866 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8867 NL80211_FLAG_NEED_RTNL,
8868 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008869#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008870 {
8871 .cmd = NL80211_CMD_GET_WOWLAN,
8872 .doit = nl80211_get_wowlan,
8873 .policy = nl80211_policy,
8874 /* can be retrieved by unprivileged users */
8875 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8876 NL80211_FLAG_NEED_RTNL,
8877 },
8878 {
8879 .cmd = NL80211_CMD_SET_WOWLAN,
8880 .doit = nl80211_set_wowlan,
8881 .policy = nl80211_policy,
8882 .flags = GENL_ADMIN_PERM,
8883 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8884 NL80211_FLAG_NEED_RTNL,
8885 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008886#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008887 {
8888 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8889 .doit = nl80211_set_rekey_data,
8890 .policy = nl80211_policy,
8891 .flags = GENL_ADMIN_PERM,
8892 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8893 NL80211_FLAG_NEED_RTNL,
8894 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008895 {
8896 .cmd = NL80211_CMD_TDLS_MGMT,
8897 .doit = nl80211_tdls_mgmt,
8898 .policy = nl80211_policy,
8899 .flags = GENL_ADMIN_PERM,
8900 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8901 NL80211_FLAG_NEED_RTNL,
8902 },
8903 {
8904 .cmd = NL80211_CMD_TDLS_OPER,
8905 .doit = nl80211_tdls_oper,
8906 .policy = nl80211_policy,
8907 .flags = GENL_ADMIN_PERM,
8908 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8909 NL80211_FLAG_NEED_RTNL,
8910 },
Johannes Berg28946da2011-11-04 11:18:12 +01008911 {
8912 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8913 .doit = nl80211_register_unexpected_frame,
8914 .policy = nl80211_policy,
8915 .flags = GENL_ADMIN_PERM,
8916 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8917 NL80211_FLAG_NEED_RTNL,
8918 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008919 {
8920 .cmd = NL80211_CMD_PROBE_CLIENT,
8921 .doit = nl80211_probe_client,
8922 .policy = nl80211_policy,
8923 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008925 NL80211_FLAG_NEED_RTNL,
8926 },
Johannes Berg5e7602302011-11-04 11:18:17 +01008927 {
8928 .cmd = NL80211_CMD_REGISTER_BEACONS,
8929 .doit = nl80211_register_beacons,
8930 .policy = nl80211_policy,
8931 .flags = GENL_ADMIN_PERM,
8932 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8933 NL80211_FLAG_NEED_RTNL,
8934 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008935 {
8936 .cmd = NL80211_CMD_SET_NOACK_MAP,
8937 .doit = nl80211_set_noack_map,
8938 .policy = nl80211_policy,
8939 .flags = GENL_ADMIN_PERM,
8940 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8941 NL80211_FLAG_NEED_RTNL,
8942 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008943 {
8944 .cmd = NL80211_CMD_START_P2P_DEVICE,
8945 .doit = nl80211_start_p2p_device,
8946 .policy = nl80211_policy,
8947 .flags = GENL_ADMIN_PERM,
8948 .internal_flags = NL80211_FLAG_NEED_WDEV |
8949 NL80211_FLAG_NEED_RTNL,
8950 },
8951 {
8952 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8953 .doit = nl80211_stop_p2p_device,
8954 .policy = nl80211_policy,
8955 .flags = GENL_ADMIN_PERM,
8956 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8957 NL80211_FLAG_NEED_RTNL,
8958 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008959 {
8960 .cmd = NL80211_CMD_SET_MCAST_RATE,
8961 .doit = nl80211_set_mcast_rate,
8962 .policy = nl80211_policy,
8963 .flags = GENL_ADMIN_PERM,
8964 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8965 NL80211_FLAG_NEED_RTNL,
8966 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308967 {
8968 .cmd = NL80211_CMD_SET_MAC_ACL,
8969 .doit = nl80211_set_mac_acl,
8970 .policy = nl80211_policy,
8971 .flags = GENL_ADMIN_PERM,
8972 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8973 NL80211_FLAG_NEED_RTNL,
8974 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008975 {
8976 .cmd = NL80211_CMD_RADAR_DETECT,
8977 .doit = nl80211_start_radar_detection,
8978 .policy = nl80211_policy,
8979 .flags = GENL_ADMIN_PERM,
8980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8981 NL80211_FLAG_NEED_RTNL,
8982 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008983 {
8984 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8985 .doit = nl80211_get_protocol_features,
8986 .policy = nl80211_policy,
8987 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008988 {
8989 .cmd = NL80211_CMD_UPDATE_FT_IES,
8990 .doit = nl80211_update_ft_ies,
8991 .policy = nl80211_policy,
8992 .flags = GENL_ADMIN_PERM,
8993 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8994 NL80211_FLAG_NEED_RTNL,
8995 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008996 {
8997 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8998 .doit = nl80211_crit_protocol_start,
8999 .policy = nl80211_policy,
9000 .flags = GENL_ADMIN_PERM,
9001 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9002 NL80211_FLAG_NEED_RTNL,
9003 },
9004 {
9005 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9006 .doit = nl80211_crit_protocol_stop,
9007 .policy = nl80211_policy,
9008 .flags = GENL_ADMIN_PERM,
9009 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9010 NL80211_FLAG_NEED_RTNL,
9011 }
Johannes Berg55682962007-09-20 13:09:35 -04009012};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009013
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009014static struct genl_multicast_group nl80211_mlme_mcgrp = {
9015 .name = "mlme",
9016};
Johannes Berg55682962007-09-20 13:09:35 -04009017
9018/* multicast groups */
9019static struct genl_multicast_group nl80211_config_mcgrp = {
9020 .name = "config",
9021};
Johannes Berg2a519312009-02-10 21:25:55 +01009022static struct genl_multicast_group nl80211_scan_mcgrp = {
9023 .name = "scan",
9024};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009025static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9026 .name = "regulatory",
9027};
Johannes Berg55682962007-09-20 13:09:35 -04009028
9029/* notification functions */
9030
9031void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9032{
9033 struct sk_buff *msg;
9034
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009036 if (!msg)
9037 return;
9038
Johannes Berg3713b4e2013-02-14 16:19:38 +01009039 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
9040 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009041 nlmsg_free(msg);
9042 return;
9043 }
9044
Johannes Berg463d0182009-07-14 00:33:35 +02009045 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9046 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009047}
9048
Johannes Berg362a4152009-05-24 16:43:15 +02009049static int nl80211_add_scan_req(struct sk_buff *msg,
9050 struct cfg80211_registered_device *rdev)
9051{
9052 struct cfg80211_scan_request *req = rdev->scan_req;
9053 struct nlattr *nest;
9054 int i;
9055
9056 if (WARN_ON(!req))
9057 return 0;
9058
9059 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9060 if (!nest)
9061 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009062 for (i = 0; i < req->n_ssids; i++) {
9063 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9064 goto nla_put_failure;
9065 }
Johannes Berg362a4152009-05-24 16:43:15 +02009066 nla_nest_end(msg, nest);
9067
9068 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9069 if (!nest)
9070 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009071 for (i = 0; i < req->n_channels; i++) {
9072 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9073 goto nla_put_failure;
9074 }
Johannes Berg362a4152009-05-24 16:43:15 +02009075 nla_nest_end(msg, nest);
9076
David S. Miller9360ffd2012-03-29 04:41:26 -04009077 if (req->ie &&
9078 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9079 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009080
Sam Lefflered4737712012-10-11 21:03:31 -07009081 if (req->flags)
9082 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9083
Johannes Berg362a4152009-05-24 16:43:15 +02009084 return 0;
9085 nla_put_failure:
9086 return -ENOBUFS;
9087}
9088
Johannes Berga538e2d2009-06-16 19:56:42 +02009089static int nl80211_send_scan_msg(struct sk_buff *msg,
9090 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009091 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009092 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009093 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009094{
9095 void *hdr;
9096
Eric W. Biederman15e47302012-09-07 20:12:54 +00009097 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009098 if (!hdr)
9099 return -1;
9100
David S. Miller9360ffd2012-03-29 04:41:26 -04009101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009102 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9103 wdev->netdev->ifindex)) ||
9104 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009105 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009106
Johannes Berg362a4152009-05-24 16:43:15 +02009107 /* ignore errors and send incomplete event anyway */
9108 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009109
9110 return genlmsg_end(msg, hdr);
9111
9112 nla_put_failure:
9113 genlmsg_cancel(msg, hdr);
9114 return -EMSGSIZE;
9115}
9116
Luciano Coelho807f8a82011-05-11 17:09:35 +03009117static int
9118nl80211_send_sched_scan_msg(struct sk_buff *msg,
9119 struct cfg80211_registered_device *rdev,
9120 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009121 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009122{
9123 void *hdr;
9124
Eric W. Biederman15e47302012-09-07 20:12:54 +00009125 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009126 if (!hdr)
9127 return -1;
9128
David S. Miller9360ffd2012-03-29 04:41:26 -04009129 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9130 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9131 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009132
9133 return genlmsg_end(msg, hdr);
9134
9135 nla_put_failure:
9136 genlmsg_cancel(msg, hdr);
9137 return -EMSGSIZE;
9138}
9139
Johannes Berga538e2d2009-06-16 19:56:42 +02009140void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009141 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009142{
9143 struct sk_buff *msg;
9144
Thomas Graf58050fc2012-06-28 03:57:45 +00009145 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009146 if (!msg)
9147 return;
9148
Johannes Bergfd014282012-06-18 19:17:03 +02009149 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009150 NL80211_CMD_TRIGGER_SCAN) < 0) {
9151 nlmsg_free(msg);
9152 return;
9153 }
9154
Johannes Berg463d0182009-07-14 00:33:35 +02009155 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9156 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009157}
9158
Johannes Berg2a519312009-02-10 21:25:55 +01009159void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009160 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009161{
9162 struct sk_buff *msg;
9163
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009165 if (!msg)
9166 return;
9167
Johannes Bergfd014282012-06-18 19:17:03 +02009168 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009169 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009170 nlmsg_free(msg);
9171 return;
9172 }
9173
Johannes Berg463d0182009-07-14 00:33:35 +02009174 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9175 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009176}
9177
9178void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009179 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009180{
9181 struct sk_buff *msg;
9182
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009183 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009184 if (!msg)
9185 return;
9186
Johannes Bergfd014282012-06-18 19:17:03 +02009187 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009188 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009189 nlmsg_free(msg);
9190 return;
9191 }
9192
Johannes Berg463d0182009-07-14 00:33:35 +02009193 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9194 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009195}
9196
Luciano Coelho807f8a82011-05-11 17:09:35 +03009197void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9198 struct net_device *netdev)
9199{
9200 struct sk_buff *msg;
9201
9202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9203 if (!msg)
9204 return;
9205
9206 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9207 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9208 nlmsg_free(msg);
9209 return;
9210 }
9211
9212 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9213 nl80211_scan_mcgrp.id, GFP_KERNEL);
9214}
9215
9216void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9217 struct net_device *netdev, u32 cmd)
9218{
9219 struct sk_buff *msg;
9220
Thomas Graf58050fc2012-06-28 03:57:45 +00009221 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009222 if (!msg)
9223 return;
9224
9225 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9226 nlmsg_free(msg);
9227 return;
9228 }
9229
9230 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9231 nl80211_scan_mcgrp.id, GFP_KERNEL);
9232}
9233
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009234/*
9235 * This can happen on global regulatory changes or device specific settings
9236 * based on custom world regulatory domains.
9237 */
9238void nl80211_send_reg_change_event(struct regulatory_request *request)
9239{
9240 struct sk_buff *msg;
9241 void *hdr;
9242
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009244 if (!msg)
9245 return;
9246
9247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9248 if (!hdr) {
9249 nlmsg_free(msg);
9250 return;
9251 }
9252
9253 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009254 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9255 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009256
David S. Miller9360ffd2012-03-29 04:41:26 -04009257 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9258 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9259 NL80211_REGDOM_TYPE_WORLD))
9260 goto nla_put_failure;
9261 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9262 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9263 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9264 goto nla_put_failure;
9265 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9266 request->intersect) {
9267 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9268 NL80211_REGDOM_TYPE_INTERSECTION))
9269 goto nla_put_failure;
9270 } else {
9271 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9272 NL80211_REGDOM_TYPE_COUNTRY) ||
9273 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9274 request->alpha2))
9275 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009276 }
9277
Johannes Bergf4173762012-12-03 18:23:37 +01009278 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009279 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9280 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009281
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009282 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009283
Johannes Bergbc43b282009-07-25 10:54:13 +02009284 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009285 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009286 GFP_ATOMIC);
9287 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009288
9289 return;
9290
9291nla_put_failure:
9292 genlmsg_cancel(msg, hdr);
9293 nlmsg_free(msg);
9294}
9295
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009296static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9297 struct net_device *netdev,
9298 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009299 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009300{
9301 struct sk_buff *msg;
9302 void *hdr;
9303
Johannes Berge6d6e342009-07-01 21:26:47 +02009304 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009305 if (!msg)
9306 return;
9307
9308 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9309 if (!hdr) {
9310 nlmsg_free(msg);
9311 return;
9312 }
9313
David S. Miller9360ffd2012-03-29 04:41:26 -04009314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9316 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9317 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009318
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009319 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009320
Johannes Berg463d0182009-07-14 00:33:35 +02009321 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9322 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009323 return;
9324
9325 nla_put_failure:
9326 genlmsg_cancel(msg, hdr);
9327 nlmsg_free(msg);
9328}
9329
9330void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009331 struct net_device *netdev, const u8 *buf,
9332 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009333{
9334 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009335 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009336}
9337
9338void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9339 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009340 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009341{
Johannes Berge6d6e342009-07-01 21:26:47 +02009342 nl80211_send_mlme_event(rdev, netdev, buf, len,
9343 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009344}
9345
Jouni Malinen53b46b82009-03-27 20:53:56 +02009346void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009347 struct net_device *netdev, const u8 *buf,
9348 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009349{
9350 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009351 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009352}
9353
Jouni Malinen53b46b82009-03-27 20:53:56 +02009354void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9355 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009356 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009357{
9358 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009359 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009360}
9361
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009362void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9363 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009364{
Johannes Berg947add32013-02-22 22:05:20 +01009365 struct wireless_dev *wdev = dev->ieee80211_ptr;
9366 struct wiphy *wiphy = wdev->wiphy;
9367 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009368 const struct ieee80211_mgmt *mgmt = (void *)buf;
9369 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009370
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009371 if (WARN_ON(len < 2))
9372 return;
9373
9374 if (ieee80211_is_deauth(mgmt->frame_control))
9375 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9376 else
9377 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9378
9379 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9380 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009381}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009382EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009383
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009384static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9385 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009386 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009387{
9388 struct sk_buff *msg;
9389 void *hdr;
9390
Johannes Berge6d6e342009-07-01 21:26:47 +02009391 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009392 if (!msg)
9393 return;
9394
9395 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9396 if (!hdr) {
9397 nlmsg_free(msg);
9398 return;
9399 }
9400
David S. Miller9360ffd2012-03-29 04:41:26 -04009401 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9402 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9403 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9404 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9405 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009406
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009407 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009408
Johannes Berg463d0182009-07-14 00:33:35 +02009409 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9410 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009411 return;
9412
9413 nla_put_failure:
9414 genlmsg_cancel(msg, hdr);
9415 nlmsg_free(msg);
9416}
9417
9418void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009419 struct net_device *netdev, const u8 *addr,
9420 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009421{
9422 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009423 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009424}
9425
9426void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009427 struct net_device *netdev, const u8 *addr,
9428 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009429{
Johannes Berge6d6e342009-07-01 21:26:47 +02009430 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9431 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009432}
9433
Samuel Ortizb23aa672009-07-01 21:26:54 +02009434void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9435 struct net_device *netdev, const u8 *bssid,
9436 const u8 *req_ie, size_t req_ie_len,
9437 const u8 *resp_ie, size_t resp_ie_len,
9438 u16 status, gfp_t gfp)
9439{
9440 struct sk_buff *msg;
9441 void *hdr;
9442
Thomas Graf58050fc2012-06-28 03:57:45 +00009443 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009444 if (!msg)
9445 return;
9446
9447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9448 if (!hdr) {
9449 nlmsg_free(msg);
9450 return;
9451 }
9452
David S. Miller9360ffd2012-03-29 04:41:26 -04009453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9454 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9455 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9456 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9457 (req_ie &&
9458 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9459 (resp_ie &&
9460 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9461 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009462
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009463 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009464
Johannes Berg463d0182009-07-14 00:33:35 +02009465 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9466 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009467 return;
9468
9469 nla_put_failure:
9470 genlmsg_cancel(msg, hdr);
9471 nlmsg_free(msg);
9472
9473}
9474
9475void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9476 struct net_device *netdev, const u8 *bssid,
9477 const u8 *req_ie, size_t req_ie_len,
9478 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9479{
9480 struct sk_buff *msg;
9481 void *hdr;
9482
Thomas Graf58050fc2012-06-28 03:57:45 +00009483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009484 if (!msg)
9485 return;
9486
9487 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9488 if (!hdr) {
9489 nlmsg_free(msg);
9490 return;
9491 }
9492
David S. Miller9360ffd2012-03-29 04:41:26 -04009493 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9494 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9495 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9496 (req_ie &&
9497 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9498 (resp_ie &&
9499 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9500 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009501
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009502 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009503
Johannes Berg463d0182009-07-14 00:33:35 +02009504 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9505 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009506 return;
9507
9508 nla_put_failure:
9509 genlmsg_cancel(msg, hdr);
9510 nlmsg_free(msg);
9511
9512}
9513
9514void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9515 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009516 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009517{
9518 struct sk_buff *msg;
9519 void *hdr;
9520
Thomas Graf58050fc2012-06-28 03:57:45 +00009521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009522 if (!msg)
9523 return;
9524
9525 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9526 if (!hdr) {
9527 nlmsg_free(msg);
9528 return;
9529 }
9530
David S. Miller9360ffd2012-03-29 04:41:26 -04009531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9532 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9533 (from_ap && reason &&
9534 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9535 (from_ap &&
9536 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9537 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9538 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009539
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009540 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009541
Johannes Berg463d0182009-07-14 00:33:35 +02009542 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9543 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009544 return;
9545
9546 nla_put_failure:
9547 genlmsg_cancel(msg, hdr);
9548 nlmsg_free(msg);
9549
9550}
9551
Johannes Berg04a773a2009-04-19 21:24:32 +02009552void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9553 struct net_device *netdev, const u8 *bssid,
9554 gfp_t gfp)
9555{
9556 struct sk_buff *msg;
9557 void *hdr;
9558
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009560 if (!msg)
9561 return;
9562
9563 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9564 if (!hdr) {
9565 nlmsg_free(msg);
9566 return;
9567 }
9568
David S. Miller9360ffd2012-03-29 04:41:26 -04009569 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9570 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9571 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9572 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009573
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009574 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009575
Johannes Berg463d0182009-07-14 00:33:35 +02009576 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9577 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009578 return;
9579
9580 nla_put_failure:
9581 genlmsg_cancel(msg, hdr);
9582 nlmsg_free(msg);
9583}
9584
Johannes Berg947add32013-02-22 22:05:20 +01009585void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9586 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009587{
Johannes Berg947add32013-02-22 22:05:20 +01009588 struct wireless_dev *wdev = dev->ieee80211_ptr;
9589 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009590 struct sk_buff *msg;
9591 void *hdr;
9592
Johannes Berg947add32013-02-22 22:05:20 +01009593 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9594 return;
9595
9596 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9597
Javier Cardonac93b5e72011-04-07 15:08:34 -07009598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9599 if (!msg)
9600 return;
9601
9602 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9603 if (!hdr) {
9604 nlmsg_free(msg);
9605 return;
9606 }
9607
David S. Miller9360ffd2012-03-29 04:41:26 -04009608 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009609 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9610 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009611 (ie_len && ie &&
9612 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9613 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009614
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009615 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009616
9617 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9618 nl80211_mlme_mcgrp.id, gfp);
9619 return;
9620
9621 nla_put_failure:
9622 genlmsg_cancel(msg, hdr);
9623 nlmsg_free(msg);
9624}
Johannes Berg947add32013-02-22 22:05:20 +01009625EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009626
Jouni Malinena3b8b052009-03-27 21:59:49 +02009627void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9628 struct net_device *netdev, const u8 *addr,
9629 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009630 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009631{
9632 struct sk_buff *msg;
9633 void *hdr;
9634
Johannes Berge6d6e342009-07-01 21:26:47 +02009635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009636 if (!msg)
9637 return;
9638
9639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9640 if (!hdr) {
9641 nlmsg_free(msg);
9642 return;
9643 }
9644
David S. Miller9360ffd2012-03-29 04:41:26 -04009645 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9646 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9647 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9648 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9649 (key_id != -1 &&
9650 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9651 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9652 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009653
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009654 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009655
Johannes Berg463d0182009-07-14 00:33:35 +02009656 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9657 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009658 return;
9659
9660 nla_put_failure:
9661 genlmsg_cancel(msg, hdr);
9662 nlmsg_free(msg);
9663}
9664
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009665void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9666 struct ieee80211_channel *channel_before,
9667 struct ieee80211_channel *channel_after)
9668{
9669 struct sk_buff *msg;
9670 void *hdr;
9671 struct nlattr *nl_freq;
9672
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009674 if (!msg)
9675 return;
9676
9677 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9678 if (!hdr) {
9679 nlmsg_free(msg);
9680 return;
9681 }
9682
9683 /*
9684 * Since we are applying the beacon hint to a wiphy we know its
9685 * wiphy_idx is valid
9686 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009687 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9688 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009689
9690 /* Before */
9691 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9692 if (!nl_freq)
9693 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009694 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009695 goto nla_put_failure;
9696 nla_nest_end(msg, nl_freq);
9697
9698 /* After */
9699 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9700 if (!nl_freq)
9701 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009702 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009703 goto nla_put_failure;
9704 nla_nest_end(msg, nl_freq);
9705
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009706 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009707
Johannes Berg463d0182009-07-14 00:33:35 +02009708 rcu_read_lock();
9709 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9710 GFP_ATOMIC);
9711 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009712
9713 return;
9714
9715nla_put_failure:
9716 genlmsg_cancel(msg, hdr);
9717 nlmsg_free(msg);
9718}
9719
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009720static void nl80211_send_remain_on_chan_event(
9721 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009722 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009723 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009724 unsigned int duration, gfp_t gfp)
9725{
9726 struct sk_buff *msg;
9727 void *hdr;
9728
9729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9730 if (!msg)
9731 return;
9732
9733 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9734 if (!hdr) {
9735 nlmsg_free(msg);
9736 return;
9737 }
9738
David S. Miller9360ffd2012-03-29 04:41:26 -04009739 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009740 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9741 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009742 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009743 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009744 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9745 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009746 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9747 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009748
David S. Miller9360ffd2012-03-29 04:41:26 -04009749 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9750 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9751 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009752
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009753 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009754
9755 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9756 nl80211_mlme_mcgrp.id, gfp);
9757 return;
9758
9759 nla_put_failure:
9760 genlmsg_cancel(msg, hdr);
9761 nlmsg_free(msg);
9762}
9763
Johannes Berg947add32013-02-22 22:05:20 +01009764void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9765 struct ieee80211_channel *chan,
9766 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009767{
Johannes Berg947add32013-02-22 22:05:20 +01009768 struct wiphy *wiphy = wdev->wiphy;
9769 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9770
9771 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009772 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009773 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009774 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009775}
Johannes Berg947add32013-02-22 22:05:20 +01009776EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009777
Johannes Berg947add32013-02-22 22:05:20 +01009778void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9779 struct ieee80211_channel *chan,
9780 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009781{
Johannes Berg947add32013-02-22 22:05:20 +01009782 struct wiphy *wiphy = wdev->wiphy;
9783 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9784
9785 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009786 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009787 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009788}
Johannes Berg947add32013-02-22 22:05:20 +01009789EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009790
Johannes Berg947add32013-02-22 22:05:20 +01009791void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9792 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009793{
Johannes Berg947add32013-02-22 22:05:20 +01009794 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9795 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009796 struct sk_buff *msg;
9797
Johannes Berg947add32013-02-22 22:05:20 +01009798 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9799
Thomas Graf58050fc2012-06-28 03:57:45 +00009800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009801 if (!msg)
9802 return;
9803
John W. Linville66266b32012-03-15 13:25:41 -04009804 if (nl80211_send_station(msg, 0, 0, 0,
9805 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009806 nlmsg_free(msg);
9807 return;
9808 }
9809
9810 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9811 nl80211_mlme_mcgrp.id, gfp);
9812}
Johannes Berg947add32013-02-22 22:05:20 +01009813EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009814
Johannes Berg947add32013-02-22 22:05:20 +01009815void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009816{
Johannes Berg947add32013-02-22 22:05:20 +01009817 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9818 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009819 struct sk_buff *msg;
9820 void *hdr;
9821
Johannes Berg947add32013-02-22 22:05:20 +01009822 trace_cfg80211_del_sta(dev, mac_addr);
9823
Thomas Graf58050fc2012-06-28 03:57:45 +00009824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009825 if (!msg)
9826 return;
9827
9828 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9829 if (!hdr) {
9830 nlmsg_free(msg);
9831 return;
9832 }
9833
David S. Miller9360ffd2012-03-29 04:41:26 -04009834 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9835 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9836 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009837
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009838 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009839
9840 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9841 nl80211_mlme_mcgrp.id, gfp);
9842 return;
9843
9844 nla_put_failure:
9845 genlmsg_cancel(msg, hdr);
9846 nlmsg_free(msg);
9847}
Johannes Berg947add32013-02-22 22:05:20 +01009848EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009849
Johannes Berg947add32013-02-22 22:05:20 +01009850void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9851 enum nl80211_connect_failed_reason reason,
9852 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309853{
Johannes Berg947add32013-02-22 22:05:20 +01009854 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9855 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309856 struct sk_buff *msg;
9857 void *hdr;
9858
9859 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9860 if (!msg)
9861 return;
9862
9863 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9864 if (!hdr) {
9865 nlmsg_free(msg);
9866 return;
9867 }
9868
9869 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9870 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9871 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9872 goto nla_put_failure;
9873
9874 genlmsg_end(msg, hdr);
9875
9876 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9877 nl80211_mlme_mcgrp.id, gfp);
9878 return;
9879
9880 nla_put_failure:
9881 genlmsg_cancel(msg, hdr);
9882 nlmsg_free(msg);
9883}
Johannes Berg947add32013-02-22 22:05:20 +01009884EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309885
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009886static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9887 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009888{
9889 struct wireless_dev *wdev = dev->ieee80211_ptr;
9890 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9891 struct sk_buff *msg;
9892 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009893 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009894
Eric W. Biederman15e47302012-09-07 20:12:54 +00009895 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009896 return false;
9897
9898 msg = nlmsg_new(100, gfp);
9899 if (!msg)
9900 return true;
9901
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009902 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009903 if (!hdr) {
9904 nlmsg_free(msg);
9905 return true;
9906 }
9907
David S. Miller9360ffd2012-03-29 04:41:26 -04009908 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9909 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9910 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9911 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009912
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009913 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009914 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009915 return true;
9916
9917 nla_put_failure:
9918 genlmsg_cancel(msg, hdr);
9919 nlmsg_free(msg);
9920 return true;
9921}
9922
Johannes Berg947add32013-02-22 22:05:20 +01009923bool cfg80211_rx_spurious_frame(struct net_device *dev,
9924 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009925{
Johannes Berg947add32013-02-22 22:05:20 +01009926 struct wireless_dev *wdev = dev->ieee80211_ptr;
9927 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009928
Johannes Berg947add32013-02-22 22:05:20 +01009929 trace_cfg80211_rx_spurious_frame(dev, addr);
9930
9931 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9932 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9933 trace_cfg80211_return_bool(false);
9934 return false;
9935 }
9936 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9937 addr, gfp);
9938 trace_cfg80211_return_bool(ret);
9939 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009940}
Johannes Berg947add32013-02-22 22:05:20 +01009941EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9942
9943bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9944 const u8 *addr, gfp_t gfp)
9945{
9946 struct wireless_dev *wdev = dev->ieee80211_ptr;
9947 bool ret;
9948
9949 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9950
9951 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9952 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9953 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9954 trace_cfg80211_return_bool(false);
9955 return false;
9956 }
9957 ret = __nl80211_unexpected_frame(dev,
9958 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9959 addr, gfp);
9960 trace_cfg80211_return_bool(ret);
9961 return ret;
9962}
9963EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009964
Johannes Berg2e161f72010-08-12 15:38:38 +02009965int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009966 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009967 int freq, int sig_dbm,
9968 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009969{
Johannes Berg71bbc992012-06-15 15:30:18 +02009970 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009971 struct sk_buff *msg;
9972 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009973
9974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9975 if (!msg)
9976 return -ENOMEM;
9977
Johannes Berg2e161f72010-08-12 15:38:38 +02009978 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009979 if (!hdr) {
9980 nlmsg_free(msg);
9981 return -ENOMEM;
9982 }
9983
David S. Miller9360ffd2012-03-29 04:41:26 -04009984 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009985 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9986 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009987 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009988 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9989 (sig_dbm &&
9990 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9991 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9992 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009993
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009994 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009995
Eric W. Biederman15e47302012-09-07 20:12:54 +00009996 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009997
9998 nla_put_failure:
9999 genlmsg_cancel(msg, hdr);
10000 nlmsg_free(msg);
10001 return -ENOBUFS;
10002}
10003
Johannes Berg947add32013-02-22 22:05:20 +010010004void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10005 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010006{
Johannes Berg947add32013-02-22 22:05:20 +010010007 struct wiphy *wiphy = wdev->wiphy;
10008 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010009 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010010 struct sk_buff *msg;
10011 void *hdr;
10012
Johannes Berg947add32013-02-22 22:05:20 +010010013 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10014
Jouni Malinen026331c2010-02-15 12:53:10 +020010015 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10016 if (!msg)
10017 return;
10018
Johannes Berg2e161f72010-08-12 15:38:38 +020010019 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010020 if (!hdr) {
10021 nlmsg_free(msg);
10022 return;
10023 }
10024
David S. Miller9360ffd2012-03-29 04:41:26 -040010025 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010026 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10027 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010028 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010029 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10030 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10031 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10032 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010033
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010034 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010035
10036 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10037 return;
10038
10039 nla_put_failure:
10040 genlmsg_cancel(msg, hdr);
10041 nlmsg_free(msg);
10042}
Johannes Berg947add32013-02-22 22:05:20 +010010043EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010044
Johannes Berg947add32013-02-22 22:05:20 +010010045void cfg80211_cqm_rssi_notify(struct net_device *dev,
10046 enum nl80211_cqm_rssi_threshold_event rssi_event,
10047 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010048{
Johannes Berg947add32013-02-22 22:05:20 +010010049 struct wireless_dev *wdev = dev->ieee80211_ptr;
10050 struct wiphy *wiphy = wdev->wiphy;
10051 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010052 struct sk_buff *msg;
10053 struct nlattr *pinfoattr;
10054 void *hdr;
10055
Johannes Berg947add32013-02-22 22:05:20 +010010056 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10057
Thomas Graf58050fc2012-06-28 03:57:45 +000010058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010059 if (!msg)
10060 return;
10061
10062 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10063 if (!hdr) {
10064 nlmsg_free(msg);
10065 return;
10066 }
10067
David S. Miller9360ffd2012-03-29 04:41:26 -040010068 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010069 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010070 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010071
10072 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10073 if (!pinfoattr)
10074 goto nla_put_failure;
10075
David S. Miller9360ffd2012-03-29 04:41:26 -040010076 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10077 rssi_event))
10078 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010079
10080 nla_nest_end(msg, pinfoattr);
10081
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010082 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010083
10084 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10085 nl80211_mlme_mcgrp.id, gfp);
10086 return;
10087
10088 nla_put_failure:
10089 genlmsg_cancel(msg, hdr);
10090 nlmsg_free(msg);
10091}
Johannes Berg947add32013-02-22 22:05:20 +010010092EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010093
Johannes Berg947add32013-02-22 22:05:20 +010010094static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10095 struct net_device *netdev, const u8 *bssid,
10096 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010097{
10098 struct sk_buff *msg;
10099 struct nlattr *rekey_attr;
10100 void *hdr;
10101
Thomas Graf58050fc2012-06-28 03:57:45 +000010102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010103 if (!msg)
10104 return;
10105
10106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10107 if (!hdr) {
10108 nlmsg_free(msg);
10109 return;
10110 }
10111
David S. Miller9360ffd2012-03-29 04:41:26 -040010112 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10113 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10114 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10115 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010116
10117 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10118 if (!rekey_attr)
10119 goto nla_put_failure;
10120
David S. Miller9360ffd2012-03-29 04:41:26 -040010121 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10122 NL80211_REPLAY_CTR_LEN, replay_ctr))
10123 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010124
10125 nla_nest_end(msg, rekey_attr);
10126
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010127 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010128
10129 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10130 nl80211_mlme_mcgrp.id, gfp);
10131 return;
10132
10133 nla_put_failure:
10134 genlmsg_cancel(msg, hdr);
10135 nlmsg_free(msg);
10136}
10137
Johannes Berg947add32013-02-22 22:05:20 +010010138void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10139 const u8 *replay_ctr, gfp_t gfp)
10140{
10141 struct wireless_dev *wdev = dev->ieee80211_ptr;
10142 struct wiphy *wiphy = wdev->wiphy;
10143 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10144
10145 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10146 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10147}
10148EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10149
10150static void
10151nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10152 struct net_device *netdev, int index,
10153 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010154{
10155 struct sk_buff *msg;
10156 struct nlattr *attr;
10157 void *hdr;
10158
Thomas Graf58050fc2012-06-28 03:57:45 +000010159 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010160 if (!msg)
10161 return;
10162
10163 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10164 if (!hdr) {
10165 nlmsg_free(msg);
10166 return;
10167 }
10168
David S. Miller9360ffd2012-03-29 04:41:26 -040010169 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10170 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10171 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010172
10173 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10174 if (!attr)
10175 goto nla_put_failure;
10176
David S. Miller9360ffd2012-03-29 04:41:26 -040010177 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10178 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10179 (preauth &&
10180 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10181 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010182
10183 nla_nest_end(msg, attr);
10184
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010185 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010186
10187 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10188 nl80211_mlme_mcgrp.id, gfp);
10189 return;
10190
10191 nla_put_failure:
10192 genlmsg_cancel(msg, hdr);
10193 nlmsg_free(msg);
10194}
10195
Johannes Berg947add32013-02-22 22:05:20 +010010196void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10197 const u8 *bssid, bool preauth, gfp_t gfp)
10198{
10199 struct wireless_dev *wdev = dev->ieee80211_ptr;
10200 struct wiphy *wiphy = wdev->wiphy;
10201 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10202
10203 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10204 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10205}
10206EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10207
10208static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10209 struct net_device *netdev,
10210 struct cfg80211_chan_def *chandef,
10211 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010212{
10213 struct sk_buff *msg;
10214 void *hdr;
10215
Thomas Graf58050fc2012-06-28 03:57:45 +000010216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010217 if (!msg)
10218 return;
10219
10220 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10221 if (!hdr) {
10222 nlmsg_free(msg);
10223 return;
10224 }
10225
Johannes Berg683b6d32012-11-08 21:25:48 +010010226 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10227 goto nla_put_failure;
10228
10229 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010230 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010231
10232 genlmsg_end(msg, hdr);
10233
10234 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10235 nl80211_mlme_mcgrp.id, gfp);
10236 return;
10237
10238 nla_put_failure:
10239 genlmsg_cancel(msg, hdr);
10240 nlmsg_free(msg);
10241}
10242
Johannes Berg947add32013-02-22 22:05:20 +010010243void cfg80211_ch_switch_notify(struct net_device *dev,
10244 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010245{
Johannes Berg947add32013-02-22 22:05:20 +010010246 struct wireless_dev *wdev = dev->ieee80211_ptr;
10247 struct wiphy *wiphy = wdev->wiphy;
10248 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10249
10250 trace_cfg80211_ch_switch_notify(dev, chandef);
10251
10252 wdev_lock(wdev);
10253
10254 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10255 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10256 goto out;
10257
10258 wdev->channel = chandef->chan;
10259 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10260out:
10261 wdev_unlock(wdev);
10262 return;
10263}
10264EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10265
10266void cfg80211_cqm_txe_notify(struct net_device *dev,
10267 const u8 *peer, u32 num_packets,
10268 u32 rate, u32 intvl, gfp_t gfp)
10269{
10270 struct wireless_dev *wdev = dev->ieee80211_ptr;
10271 struct wiphy *wiphy = wdev->wiphy;
10272 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010273 struct sk_buff *msg;
10274 struct nlattr *pinfoattr;
10275 void *hdr;
10276
10277 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10278 if (!msg)
10279 return;
10280
10281 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10282 if (!hdr) {
10283 nlmsg_free(msg);
10284 return;
10285 }
10286
10287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010288 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010289 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10290 goto nla_put_failure;
10291
10292 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10293 if (!pinfoattr)
10294 goto nla_put_failure;
10295
10296 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10297 goto nla_put_failure;
10298
10299 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10300 goto nla_put_failure;
10301
10302 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10303 goto nla_put_failure;
10304
10305 nla_nest_end(msg, pinfoattr);
10306
10307 genlmsg_end(msg, hdr);
10308
10309 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10310 nl80211_mlme_mcgrp.id, gfp);
10311 return;
10312
10313 nla_put_failure:
10314 genlmsg_cancel(msg, hdr);
10315 nlmsg_free(msg);
10316}
Johannes Berg947add32013-02-22 22:05:20 +010010317EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010318
10319void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010320nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10321 struct cfg80211_chan_def *chandef,
10322 enum nl80211_radar_event event,
10323 struct net_device *netdev, gfp_t gfp)
10324{
10325 struct sk_buff *msg;
10326 void *hdr;
10327
10328 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10329 if (!msg)
10330 return;
10331
10332 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10333 if (!hdr) {
10334 nlmsg_free(msg);
10335 return;
10336 }
10337
10338 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10339 goto nla_put_failure;
10340
10341 /* NOP and radar events don't need a netdev parameter */
10342 if (netdev) {
10343 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10344
10345 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10346 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10347 goto nla_put_failure;
10348 }
10349
10350 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10351 goto nla_put_failure;
10352
10353 if (nl80211_send_chandef(msg, chandef))
10354 goto nla_put_failure;
10355
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010356 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010357
10358 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10359 nl80211_mlme_mcgrp.id, gfp);
10360 return;
10361
10362 nla_put_failure:
10363 genlmsg_cancel(msg, hdr);
10364 nlmsg_free(msg);
10365}
10366
Johannes Berg947add32013-02-22 22:05:20 +010010367void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10368 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010369{
Johannes Berg947add32013-02-22 22:05:20 +010010370 struct wireless_dev *wdev = dev->ieee80211_ptr;
10371 struct wiphy *wiphy = wdev->wiphy;
10372 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010373 struct sk_buff *msg;
10374 struct nlattr *pinfoattr;
10375 void *hdr;
10376
Johannes Berg947add32013-02-22 22:05:20 +010010377 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10378
Thomas Graf58050fc2012-06-28 03:57:45 +000010379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010380 if (!msg)
10381 return;
10382
10383 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10384 if (!hdr) {
10385 nlmsg_free(msg);
10386 return;
10387 }
10388
David S. Miller9360ffd2012-03-29 04:41:26 -040010389 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010390 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010391 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10392 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010393
10394 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10395 if (!pinfoattr)
10396 goto nla_put_failure;
10397
David S. Miller9360ffd2012-03-29 04:41:26 -040010398 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10399 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010400
10401 nla_nest_end(msg, pinfoattr);
10402
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010403 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010404
10405 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10406 nl80211_mlme_mcgrp.id, gfp);
10407 return;
10408
10409 nla_put_failure:
10410 genlmsg_cancel(msg, hdr);
10411 nlmsg_free(msg);
10412}
Johannes Berg947add32013-02-22 22:05:20 +010010413EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010414
Johannes Berg7f6cf312011-11-04 11:18:15 +010010415void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10416 u64 cookie, bool acked, gfp_t gfp)
10417{
10418 struct wireless_dev *wdev = dev->ieee80211_ptr;
10419 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10420 struct sk_buff *msg;
10421 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010422
Beni Lev4ee3e062012-08-27 12:49:39 +030010423 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10424
Thomas Graf58050fc2012-06-28 03:57:45 +000010425 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010426
Johannes Berg7f6cf312011-11-04 11:18:15 +010010427 if (!msg)
10428 return;
10429
10430 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10431 if (!hdr) {
10432 nlmsg_free(msg);
10433 return;
10434 }
10435
David S. Miller9360ffd2012-03-29 04:41:26 -040010436 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10437 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10438 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10439 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10440 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10441 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010442
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010443 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010444
10445 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10446 nl80211_mlme_mcgrp.id, gfp);
10447 return;
10448
10449 nla_put_failure:
10450 genlmsg_cancel(msg, hdr);
10451 nlmsg_free(msg);
10452}
10453EXPORT_SYMBOL(cfg80211_probe_status);
10454
Johannes Berg5e7602302011-11-04 11:18:17 +010010455void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10456 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010457 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010458{
10459 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10460 struct sk_buff *msg;
10461 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010462 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010463
Beni Lev4ee3e062012-08-27 12:49:39 +030010464 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10465
Ben Greear37c73b52012-10-26 14:49:25 -070010466 spin_lock_bh(&rdev->beacon_registrations_lock);
10467 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10468 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10469 if (!msg) {
10470 spin_unlock_bh(&rdev->beacon_registrations_lock);
10471 return;
10472 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010473
Ben Greear37c73b52012-10-26 14:49:25 -070010474 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10475 if (!hdr)
10476 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010477
Ben Greear37c73b52012-10-26 14:49:25 -070010478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10479 (freq &&
10480 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10481 (sig_dbm &&
10482 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10483 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10484 goto nla_put_failure;
10485
10486 genlmsg_end(msg, hdr);
10487
10488 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010489 }
Ben Greear37c73b52012-10-26 14:49:25 -070010490 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010491 return;
10492
10493 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010494 spin_unlock_bh(&rdev->beacon_registrations_lock);
10495 if (hdr)
10496 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010497 nlmsg_free(msg);
10498}
10499EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10500
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010501#ifdef CONFIG_PM
10502void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10503 struct cfg80211_wowlan_wakeup *wakeup,
10504 gfp_t gfp)
10505{
10506 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10507 struct sk_buff *msg;
10508 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010509 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010510
10511 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10512
10513 if (wakeup)
10514 size += wakeup->packet_present_len;
10515
10516 msg = nlmsg_new(size, gfp);
10517 if (!msg)
10518 return;
10519
10520 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10521 if (!hdr)
10522 goto free_msg;
10523
10524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10525 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10526 goto free_msg;
10527
10528 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10529 wdev->netdev->ifindex))
10530 goto free_msg;
10531
10532 if (wakeup) {
10533 struct nlattr *reasons;
10534
10535 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10536
10537 if (wakeup->disconnect &&
10538 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10539 goto free_msg;
10540 if (wakeup->magic_pkt &&
10541 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10542 goto free_msg;
10543 if (wakeup->gtk_rekey_failure &&
10544 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10545 goto free_msg;
10546 if (wakeup->eap_identity_req &&
10547 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10548 goto free_msg;
10549 if (wakeup->four_way_handshake &&
10550 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10551 goto free_msg;
10552 if (wakeup->rfkill_release &&
10553 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10554 goto free_msg;
10555
10556 if (wakeup->pattern_idx >= 0 &&
10557 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10558 wakeup->pattern_idx))
10559 goto free_msg;
10560
Johannes Berg2a0e0472013-01-23 22:57:40 +010010561 if (wakeup->tcp_match)
10562 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10563
10564 if (wakeup->tcp_connlost)
10565 nla_put_flag(msg,
10566 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10567
10568 if (wakeup->tcp_nomoretokens)
10569 nla_put_flag(msg,
10570 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10571
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010572 if (wakeup->packet) {
10573 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10574 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10575
10576 if (!wakeup->packet_80211) {
10577 pkt_attr =
10578 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10579 len_attr =
10580 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10581 }
10582
10583 if (wakeup->packet_len &&
10584 nla_put_u32(msg, len_attr, wakeup->packet_len))
10585 goto free_msg;
10586
10587 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10588 wakeup->packet))
10589 goto free_msg;
10590 }
10591
10592 nla_nest_end(msg, reasons);
10593 }
10594
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010595 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010596
10597 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10598 nl80211_mlme_mcgrp.id, gfp);
10599 return;
10600
10601 free_msg:
10602 nlmsg_free(msg);
10603}
10604EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10605#endif
10606
Jouni Malinen3475b092012-11-16 22:49:57 +020010607void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10608 enum nl80211_tdls_operation oper,
10609 u16 reason_code, gfp_t gfp)
10610{
10611 struct wireless_dev *wdev = dev->ieee80211_ptr;
10612 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10613 struct sk_buff *msg;
10614 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010615
10616 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10617 reason_code);
10618
10619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10620 if (!msg)
10621 return;
10622
10623 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10624 if (!hdr) {
10625 nlmsg_free(msg);
10626 return;
10627 }
10628
10629 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10630 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10631 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10632 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10633 (reason_code > 0 &&
10634 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10635 goto nla_put_failure;
10636
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010637 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010638
10639 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10640 nl80211_mlme_mcgrp.id, gfp);
10641 return;
10642
10643 nla_put_failure:
10644 genlmsg_cancel(msg, hdr);
10645 nlmsg_free(msg);
10646}
10647EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10648
Jouni Malinen026331c2010-02-15 12:53:10 +020010649static int nl80211_netlink_notify(struct notifier_block * nb,
10650 unsigned long state,
10651 void *_notify)
10652{
10653 struct netlink_notify *notify = _notify;
10654 struct cfg80211_registered_device *rdev;
10655 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010656 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010657
10658 if (state != NETLINK_URELEASE)
10659 return NOTIFY_DONE;
10660
10661 rcu_read_lock();
10662
Johannes Berg5e7602302011-11-04 11:18:17 +010010663 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010664 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010665 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010666
10667 spin_lock_bh(&rdev->beacon_registrations_lock);
10668 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10669 list) {
10670 if (reg->nlportid == notify->portid) {
10671 list_del(&reg->list);
10672 kfree(reg);
10673 break;
10674 }
10675 }
10676 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010677 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010678
10679 rcu_read_unlock();
10680
10681 return NOTIFY_DONE;
10682}
10683
10684static struct notifier_block nl80211_netlink_notifier = {
10685 .notifier_call = nl80211_netlink_notify,
10686};
10687
Jouni Malinen355199e2013-02-27 17:14:27 +020010688void cfg80211_ft_event(struct net_device *netdev,
10689 struct cfg80211_ft_event_params *ft_event)
10690{
10691 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10692 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10693 struct sk_buff *msg;
10694 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010695
10696 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10697
10698 if (!ft_event->target_ap)
10699 return;
10700
10701 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10702 if (!msg)
10703 return;
10704
10705 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10706 if (!hdr) {
10707 nlmsg_free(msg);
10708 return;
10709 }
10710
10711 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10712 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10713 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10714 if (ft_event->ies)
10715 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10716 if (ft_event->ric_ies)
10717 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10718 ft_event->ric_ies);
10719
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010720 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010721
10722 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10723 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10724}
10725EXPORT_SYMBOL(cfg80211_ft_event);
10726
Arend van Spriel5de17982013-04-18 15:49:00 +020010727void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10728{
10729 struct cfg80211_registered_device *rdev;
10730 struct sk_buff *msg;
10731 void *hdr;
10732 u32 nlportid;
10733
10734 rdev = wiphy_to_dev(wdev->wiphy);
10735 if (!rdev->crit_proto_nlportid)
10736 return;
10737
10738 nlportid = rdev->crit_proto_nlportid;
10739 rdev->crit_proto_nlportid = 0;
10740
10741 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10742 if (!msg)
10743 return;
10744
10745 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10746 if (!hdr)
10747 goto nla_put_failure;
10748
10749 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10750 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10751 goto nla_put_failure;
10752
10753 genlmsg_end(msg, hdr);
10754
10755 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10756 return;
10757
10758 nla_put_failure:
10759 if (hdr)
10760 genlmsg_cancel(msg, hdr);
10761 nlmsg_free(msg);
10762
10763}
10764EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10765
Johannes Berg55682962007-09-20 13:09:35 -040010766/* initialisation/exit functions */
10767
10768int nl80211_init(void)
10769{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010770 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010771
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010772 err = genl_register_family_with_ops(&nl80211_fam,
10773 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010774 if (err)
10775 return err;
10776
Johannes Berg55682962007-09-20 13:09:35 -040010777 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10778 if (err)
10779 goto err_out;
10780
Johannes Berg2a519312009-02-10 21:25:55 +010010781 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10782 if (err)
10783 goto err_out;
10784
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010785 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10786 if (err)
10787 goto err_out;
10788
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010789 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10790 if (err)
10791 goto err_out;
10792
Johannes Bergaff89a92009-07-01 21:26:51 +020010793#ifdef CONFIG_NL80211_TESTMODE
10794 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10795 if (err)
10796 goto err_out;
10797#endif
10798
Jouni Malinen026331c2010-02-15 12:53:10 +020010799 err = netlink_register_notifier(&nl80211_netlink_notifier);
10800 if (err)
10801 goto err_out;
10802
Johannes Berg55682962007-09-20 13:09:35 -040010803 return 0;
10804 err_out:
10805 genl_unregister_family(&nl80211_fam);
10806 return err;
10807}
10808
10809void nl80211_exit(void)
10810{
Jouni Malinen026331c2010-02-15 12:53:10 +020010811 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010812 genl_unregister_family(&nl80211_fam);
10813}