blob: ea74b9dd9d82cf3541ad7aee4a9de34facad7dec [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-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:
803 if (!wdev->current_bss)
804 return -ENOLINK;
805 break;
806 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200808 if (wdev->sme_state != CFG80211_SME_CONNECTED)
809 return -ENOLINK;
810 break;
811 default:
812 return -EINVAL;
813 }
814
815 return 0;
816}
817
Johannes Berg7527a782011-05-13 10:58:57 +0200818static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
819{
820 struct nlattr *nl_modes = nla_nest_start(msg, attr);
821 int i;
822
823 if (!nl_modes)
824 goto nla_put_failure;
825
826 i = 0;
827 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400828 if ((ifmodes & 1) && nla_put_flag(msg, i))
829 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200830 ifmodes >>= 1;
831 i++;
832 }
833
834 nla_nest_end(msg, nl_modes);
835 return 0;
836
837nla_put_failure:
838 return -ENOBUFS;
839}
840
841static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100842 struct sk_buff *msg,
843 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200844{
845 struct nlattr *nl_combis;
846 int i, j;
847
848 nl_combis = nla_nest_start(msg,
849 NL80211_ATTR_INTERFACE_COMBINATIONS);
850 if (!nl_combis)
851 goto nla_put_failure;
852
853 for (i = 0; i < wiphy->n_iface_combinations; i++) {
854 const struct ieee80211_iface_combination *c;
855 struct nlattr *nl_combi, *nl_limits;
856
857 c = &wiphy->iface_combinations[i];
858
859 nl_combi = nla_nest_start(msg, i + 1);
860 if (!nl_combi)
861 goto nla_put_failure;
862
863 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
864 if (!nl_limits)
865 goto nla_put_failure;
866
867 for (j = 0; j < c->n_limits; j++) {
868 struct nlattr *nl_limit;
869
870 nl_limit = nla_nest_start(msg, j + 1);
871 if (!nl_limit)
872 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400873 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
874 c->limits[j].max))
875 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200876 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
877 c->limits[j].types))
878 goto nla_put_failure;
879 nla_nest_end(msg, nl_limit);
880 }
881
882 nla_nest_end(msg, nl_limits);
883
David S. Miller9360ffd2012-03-29 04:41:26 -0400884 if (c->beacon_int_infra_match &&
885 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
886 goto nla_put_failure;
887 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
888 c->num_different_channels) ||
889 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
890 c->max_interfaces))
891 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100892 if (large &&
893 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
894 c->radar_detect_widths))
895 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200896
897 nla_nest_end(msg, nl_combi);
898 }
899
900 nla_nest_end(msg, nl_combis);
901
902 return 0;
903nla_put_failure:
904 return -ENOBUFS;
905}
906
Johannes Berg3713b4e2013-02-14 16:19:38 +0100907#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100908static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
909 struct sk_buff *msg)
910{
911 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
912 struct nlattr *nl_tcp;
913
914 if (!tcp)
915 return 0;
916
917 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
918 if (!nl_tcp)
919 return -ENOBUFS;
920
921 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
922 tcp->data_payload_max))
923 return -ENOBUFS;
924
925 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
926 tcp->data_payload_max))
927 return -ENOBUFS;
928
929 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
930 return -ENOBUFS;
931
932 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
933 sizeof(*tcp->tok), tcp->tok))
934 return -ENOBUFS;
935
936 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
937 tcp->data_interval_max))
938 return -ENOBUFS;
939
940 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
941 tcp->wake_payload_max))
942 return -ENOBUFS;
943
944 nla_nest_end(msg, nl_tcp);
945 return 0;
946}
947
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100949 struct cfg80211_registered_device *dev,
950 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100951{
952 struct nlattr *nl_wowlan;
953
954 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
955 return 0;
956
957 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
958 if (!nl_wowlan)
959 return -ENOBUFS;
960
961 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
962 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
963 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
964 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
965 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
966 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
967 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
968 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
969 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
970 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
971 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
972 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
973 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
974 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
975 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
977 return -ENOBUFS;
978
979 if (dev->wiphy.wowlan.n_patterns) {
980 struct nl80211_wowlan_pattern_support pat = {
981 .max_patterns = dev->wiphy.wowlan.n_patterns,
982 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
983 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
984 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
985 };
986
987 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
988 sizeof(pat), &pat))
989 return -ENOBUFS;
990 }
991
Johannes Bergb56cf722013-02-20 01:02:38 +0100992 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
993 return -ENOBUFS;
994
Johannes Berg3713b4e2013-02-14 16:19:38 +0100995 nla_nest_end(msg, nl_wowlan);
996
997 return 0;
998}
999#endif
1000
1001static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1002 struct ieee80211_supported_band *sband)
1003{
1004 struct nlattr *nl_rates, *nl_rate;
1005 struct ieee80211_rate *rate;
1006 int i;
1007
1008 /* add HT info */
1009 if (sband->ht_cap.ht_supported &&
1010 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1011 sizeof(sband->ht_cap.mcs),
1012 &sband->ht_cap.mcs) ||
1013 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1014 sband->ht_cap.cap) ||
1015 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1016 sband->ht_cap.ampdu_factor) ||
1017 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1018 sband->ht_cap.ampdu_density)))
1019 return -ENOBUFS;
1020
1021 /* add VHT info */
1022 if (sband->vht_cap.vht_supported &&
1023 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1024 sizeof(sband->vht_cap.vht_mcs),
1025 &sband->vht_cap.vht_mcs) ||
1026 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1027 sband->vht_cap.cap)))
1028 return -ENOBUFS;
1029
1030 /* add bitrates */
1031 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1032 if (!nl_rates)
1033 return -ENOBUFS;
1034
1035 for (i = 0; i < sband->n_bitrates; i++) {
1036 nl_rate = nla_nest_start(msg, i);
1037 if (!nl_rate)
1038 return -ENOBUFS;
1039
1040 rate = &sband->bitrates[i];
1041 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1042 rate->bitrate))
1043 return -ENOBUFS;
1044 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1045 nla_put_flag(msg,
1046 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1047 return -ENOBUFS;
1048
1049 nla_nest_end(msg, nl_rate);
1050 }
1051
1052 nla_nest_end(msg, nl_rates);
1053
1054 return 0;
1055}
1056
1057static int
1058nl80211_send_mgmt_stypes(struct sk_buff *msg,
1059 const struct ieee80211_txrx_stypes *mgmt_stypes)
1060{
1061 u16 stypes;
1062 struct nlattr *nl_ftypes, *nl_ifs;
1063 enum nl80211_iftype ift;
1064 int i;
1065
1066 if (!mgmt_stypes)
1067 return 0;
1068
1069 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1070 if (!nl_ifs)
1071 return -ENOBUFS;
1072
1073 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1074 nl_ftypes = nla_nest_start(msg, ift);
1075 if (!nl_ftypes)
1076 return -ENOBUFS;
1077 i = 0;
1078 stypes = mgmt_stypes[ift].tx;
1079 while (stypes) {
1080 if ((stypes & 1) &&
1081 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1082 (i << 4) | IEEE80211_FTYPE_MGMT))
1083 return -ENOBUFS;
1084 stypes >>= 1;
1085 i++;
1086 }
1087 nla_nest_end(msg, nl_ftypes);
1088 }
1089
1090 nla_nest_end(msg, nl_ifs);
1091
1092 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1093 if (!nl_ifs)
1094 return -ENOBUFS;
1095
1096 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1097 nl_ftypes = nla_nest_start(msg, ift);
1098 if (!nl_ftypes)
1099 return -ENOBUFS;
1100 i = 0;
1101 stypes = mgmt_stypes[ift].rx;
1102 while (stypes) {
1103 if ((stypes & 1) &&
1104 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1105 (i << 4) | IEEE80211_FTYPE_MGMT))
1106 return -ENOBUFS;
1107 stypes >>= 1;
1108 i++;
1109 }
1110 nla_nest_end(msg, nl_ftypes);
1111 }
1112 nla_nest_end(msg, nl_ifs);
1113
1114 return 0;
1115}
1116
1117static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1118 struct sk_buff *msg, u32 portid, u32 seq,
1119 int flags, bool split, long *split_start,
1120 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001121{
1122 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001123 struct nlattr *nl_bands, *nl_band;
1124 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001125 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001126 enum ieee80211_band band;
1127 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001128 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001129 const struct ieee80211_txrx_stypes *mgmt_stypes =
1130 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001131 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001132 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001133
Eric W. Biederman15e47302012-09-07 20:12:54 +00001134 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001135 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001136 return -ENOBUFS;
1137
1138 /* allow always using the variables */
1139 if (!split) {
1140 split_start = &start;
1141 band_start = &start_band;
1142 chan_start = &start_chan;
1143 }
Johannes Berg55682962007-09-20 13:09:35 -04001144
David S. Miller9360ffd2012-03-29 04:41:26 -04001145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1147 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001148 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001150 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001151
Johannes Berg3713b4e2013-02-14 16:19:38 +01001152 switch (*split_start) {
1153 case 0:
1154 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1155 dev->wiphy.retry_short) ||
1156 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1157 dev->wiphy.retry_long) ||
1158 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1159 dev->wiphy.frag_threshold) ||
1160 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1161 dev->wiphy.rts_threshold) ||
1162 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1163 dev->wiphy.coverage_class) ||
1164 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1165 dev->wiphy.max_scan_ssids) ||
1166 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1167 dev->wiphy.max_sched_scan_ssids) ||
1168 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1169 dev->wiphy.max_scan_ie_len) ||
1170 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1171 dev->wiphy.max_sched_scan_ie_len) ||
1172 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1173 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001174 goto nla_put_failure;
1175
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1178 goto nla_put_failure;
1179 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1180 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1181 goto nla_put_failure;
1182 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1183 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1184 goto nla_put_failure;
1185 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1186 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1187 goto nla_put_failure;
1188 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1189 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1190 goto nla_put_failure;
1191 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1192 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001193 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;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001530 struct nlattr **tb;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001532
Johannes Berg3a5a4232013-06-19 10:09:57 +02001533 /* will be zeroed in nlmsg_parse() */
1534 tb = kmalloc(sizeof(*tb) * (NL80211_ATTR_MAX + 1), GFP_KERNEL);
1535 if (!tb)
1536 return -ENOMEM;
1537
Johannes Berg5fe231e2013-05-08 21:45:15 +02001538 rtnl_lock();
David S. Millerd98cae64e2013-06-19 16:49:39 -07001539
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Berg3a5a4232013-06-19 10:09:57 +02001541 tb, NL80211_ATTR_MAX, nl80211_policy);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 if (res == 0) {
1543 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1544 if (tb[NL80211_ATTR_WIPHY])
1545 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1546 if (tb[NL80211_ATTR_WDEV])
1547 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1548 if (tb[NL80211_ATTR_IFINDEX]) {
1549 struct net_device *netdev;
1550 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1551
1552 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1553 if (!netdev) {
David S. Millerd98cae64e2013-06-19 16:49:39 -07001554 rtnl_unlock();
Johannes Berg3a5a4232013-06-19 10:09:57 +02001555 kfree(tb);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 return -ENODEV;
1557 }
1558 if (netdev->ieee80211_ptr) {
1559 dev = wiphy_to_dev(
1560 netdev->ieee80211_ptr->wiphy);
1561 filter_wiphy = dev->wiphy_idx;
1562 }
1563 dev_put(netdev);
1564 }
1565 }
Johannes Berg3a5a4232013-06-19 10:09:57 +02001566 kfree(tb);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001567
Johannes Berg79c97e92009-07-07 03:56:12 +02001568 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001569 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1570 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001571 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001572 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1574 continue;
1575 /* attempt to fit multiple wiphy data chunks into the skb */
1576 do {
1577 ret = nl80211_send_wiphy(dev, skb,
1578 NETLINK_CB(cb->skb).portid,
1579 cb->nlh->nlmsg_seq,
1580 NLM_F_MULTI,
1581 split, &cb->args[1],
1582 &cb->args[2],
1583 &cb->args[3]);
1584 if (ret < 0) {
1585 /*
1586 * If sending the wiphy data didn't fit (ENOBUFS
1587 * or EMSGSIZE returned), this SKB is still
1588 * empty (so it's not too big because another
1589 * wiphy dataset is already in the skb) and
1590 * we've not tried to adjust the dump allocation
1591 * yet ... then adjust the alloc size to be
1592 * bigger, and return 1 but with the empty skb.
1593 * This results in an empty message being RX'ed
1594 * in userspace, but that is ignored.
1595 *
1596 * We can then retry with the larger buffer.
1597 */
1598 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1599 !skb->len &&
1600 cb->min_dump_alloc < 4096) {
1601 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001602 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 return 1;
1604 }
1605 idx--;
1606 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001607 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 } while (cb->args[1] > 0);
1609 break;
Johannes Berg55682962007-09-20 13:09:35 -04001610 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001611 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001612
1613 cb->args[0] = idx;
1614
1615 return skb->len;
1616}
1617
1618static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1619{
1620 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001621 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001622
Johannes Berg645e77d2013-03-01 14:03:49 +01001623 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001624 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001625 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001626
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1628 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001629 nlmsg_free(msg);
1630 return -ENOBUFS;
1631 }
Johannes Berg55682962007-09-20 13:09:35 -04001632
Johannes Berg134e6372009-07-10 09:51:34 +00001633 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001634}
1635
Jouni Malinen31888482008-10-30 16:59:24 +02001636static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1637 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1638 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1639 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1640 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1641 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1642};
1643
1644static int parse_txq_params(struct nlattr *tb[],
1645 struct ieee80211_txq_params *txq_params)
1646{
Johannes Berga3304b02012-03-28 11:04:24 +02001647 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001648 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1649 !tb[NL80211_TXQ_ATTR_AIFS])
1650 return -EINVAL;
1651
Johannes Berga3304b02012-03-28 11:04:24 +02001652 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001653 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1654 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1655 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1656 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1657
Johannes Berga3304b02012-03-28 11:04:24 +02001658 if (txq_params->ac >= NL80211_NUM_ACS)
1659 return -EINVAL;
1660
Jouni Malinen31888482008-10-30 16:59:24 +02001661 return 0;
1662}
1663
Johannes Bergf444de02010-05-05 15:25:02 +02001664static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1665{
1666 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001667 * You can only set the channel explicitly for WDS interfaces,
1668 * all others have their channel managed via their respective
1669 * "establish a connection" command (connect, join, ...)
1670 *
1671 * For AP/GO and mesh mode, the channel can be set with the
1672 * channel userspace API, but is only stored and passed to the
1673 * low-level driver when the AP starts or the mesh is joined.
1674 * This is for backward compatibility, userspace can also give
1675 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001676 *
1677 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001678 * whatever else is going on, so they have their own special
1679 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001680 */
1681 return !wdev ||
1682 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001683 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001684 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1685 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001686}
1687
Johannes Berg683b6d32012-11-08 21:25:48 +01001688static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1689 struct genl_info *info,
1690 struct cfg80211_chan_def *chandef)
1691{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301692 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001693
1694 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1695 return -EINVAL;
1696
1697 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1698
1699 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001700 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1701 chandef->center_freq1 = control_freq;
1702 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001703
1704 /* Primary channel not allowed */
1705 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1706 return -EINVAL;
1707
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001708 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1709 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001710
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001711 chantype = nla_get_u32(
1712 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1713
1714 switch (chantype) {
1715 case NL80211_CHAN_NO_HT:
1716 case NL80211_CHAN_HT20:
1717 case NL80211_CHAN_HT40PLUS:
1718 case NL80211_CHAN_HT40MINUS:
1719 cfg80211_chandef_create(chandef, chandef->chan,
1720 chantype);
1721 break;
1722 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001723 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001724 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001725 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1726 chandef->width =
1727 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1728 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1729 chandef->center_freq1 =
1730 nla_get_u32(
1731 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1732 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1733 chandef->center_freq2 =
1734 nla_get_u32(
1735 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1736 }
1737
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001738 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001739 return -EINVAL;
1740
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001741 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1742 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001743 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001744
Johannes Berg683b6d32012-11-08 21:25:48 +01001745 return 0;
1746}
1747
Johannes Bergf444de02010-05-05 15:25:02 +02001748static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1749 struct wireless_dev *wdev,
1750 struct genl_info *info)
1751{
Johannes Berg683b6d32012-11-08 21:25:48 +01001752 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001753 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001754 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1755
1756 if (wdev)
1757 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001758
Johannes Bergf444de02010-05-05 15:25:02 +02001759 if (!nl80211_can_set_dev_channel(wdev))
1760 return -EOPNOTSUPP;
1761
Johannes Berg683b6d32012-11-08 21:25:48 +01001762 result = nl80211_parse_chandef(rdev, info, &chandef);
1763 if (result)
1764 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001765
Johannes Berge8c9bd52012-06-06 08:18:22 +02001766 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001767 case NL80211_IFTYPE_AP:
1768 case NL80211_IFTYPE_P2P_GO:
1769 if (wdev->beacon_interval) {
1770 result = -EBUSY;
1771 break;
1772 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001773 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001774 result = -EINVAL;
1775 break;
1776 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001777 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001778 result = 0;
1779 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001780 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001781 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001782 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001783 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001784 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001785 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001786 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001787 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001788 }
Johannes Bergf444de02010-05-05 15:25:02 +02001789
1790 return result;
1791}
1792
1793static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1794{
Johannes Berg4c476992010-10-04 21:36:35 +02001795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1796 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001797
Johannes Berg4c476992010-10-04 21:36:35 +02001798 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001799}
1800
Bill Jordane8347eb2010-10-01 13:54:28 -04001801static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1802{
Johannes Berg43b19952010-10-07 13:10:30 +02001803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1804 struct net_device *dev = info->user_ptr[1];
1805 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001806 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001807
1808 if (!info->attrs[NL80211_ATTR_MAC])
1809 return -EINVAL;
1810
Johannes Berg43b19952010-10-07 13:10:30 +02001811 if (netif_running(dev))
1812 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001813
Johannes Berg43b19952010-10-07 13:10:30 +02001814 if (!rdev->ops->set_wds_peer)
1815 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001816
Johannes Berg43b19952010-10-07 13:10:30 +02001817 if (wdev->iftype != NL80211_IFTYPE_WDS)
1818 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001819
1820 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001821 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001822}
1823
1824
Johannes Berg55682962007-09-20 13:09:35 -04001825static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1826{
1827 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001828 struct net_device *netdev = NULL;
1829 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001830 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001831 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001832 u32 changed;
1833 u8 retry_short = 0, retry_long = 0;
1834 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001835 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001836
Johannes Berg5fe231e2013-05-08 21:45:15 +02001837 ASSERT_RTNL();
1838
Johannes Bergf444de02010-05-05 15:25:02 +02001839 /*
1840 * Try to find the wiphy and netdev. Normally this
1841 * function shouldn't need the netdev, but this is
1842 * done for backward compatibility -- previously
1843 * setting the channel was done per wiphy, but now
1844 * it is per netdev. Previous userland like hostapd
1845 * also passed a netdev to set_wiphy, so that it is
1846 * possible to let that go to the right netdev!
1847 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001848
Johannes Bergf444de02010-05-05 15:25:02 +02001849 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1850 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1851
1852 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001853 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001854 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001855 else
Johannes Bergf444de02010-05-05 15:25:02 +02001856 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001857 }
1858
Johannes Bergf444de02010-05-05 15:25:02 +02001859 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001860 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1861 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001862 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001863 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001864 wdev = NULL;
1865 netdev = NULL;
1866 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001867 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001868 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001869
1870 /*
1871 * end workaround code, by now the rdev is available
1872 * and locked, and wdev may or may not be NULL.
1873 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001874
1875 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001876 result = cfg80211_dev_rename(
1877 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001878
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001879 if (result)
1880 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001881
Jouni Malinen31888482008-10-30 16:59:24 +02001882 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1883 struct ieee80211_txq_params txq_params;
1884 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1885
1886 if (!rdev->ops->set_txq_params) {
1887 result = -EOPNOTSUPP;
1888 goto bad_res;
1889 }
1890
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001891 if (!netdev) {
1892 result = -EINVAL;
1893 goto bad_res;
1894 }
1895
Johannes Berg133a3ff2011-11-03 14:50:13 +01001896 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1897 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1898 result = -EINVAL;
1899 goto bad_res;
1900 }
1901
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001902 if (!netif_running(netdev)) {
1903 result = -ENETDOWN;
1904 goto bad_res;
1905 }
1906
Jouni Malinen31888482008-10-30 16:59:24 +02001907 nla_for_each_nested(nl_txq_params,
1908 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1909 rem_txq_params) {
1910 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1911 nla_data(nl_txq_params),
1912 nla_len(nl_txq_params),
1913 txq_params_policy);
1914 result = parse_txq_params(tb, &txq_params);
1915 if (result)
1916 goto bad_res;
1917
Hila Gonene35e4d22012-06-27 17:19:42 +03001918 result = rdev_set_txq_params(rdev, netdev,
1919 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001920 if (result)
1921 goto bad_res;
1922 }
1923 }
1924
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001925 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001926 result = __nl80211_set_channel(rdev,
1927 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1928 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001929 if (result)
1930 goto bad_res;
1931 }
1932
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001933 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001934 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001935 enum nl80211_tx_power_setting type;
1936 int idx, mbm = 0;
1937
Johannes Bergc8442112012-10-24 10:17:18 +02001938 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1939 txp_wdev = NULL;
1940
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001941 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001942 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001943 goto bad_res;
1944 }
1945
1946 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1947 type = nla_get_u32(info->attrs[idx]);
1948
1949 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1950 (type != NL80211_TX_POWER_AUTOMATIC)) {
1951 result = -EINVAL;
1952 goto bad_res;
1953 }
1954
1955 if (type != NL80211_TX_POWER_AUTOMATIC) {
1956 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1957 mbm = nla_get_u32(info->attrs[idx]);
1958 }
1959
Johannes Bergc8442112012-10-24 10:17:18 +02001960 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001961 if (result)
1962 goto bad_res;
1963 }
1964
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001965 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1966 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1967 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001968 if ((!rdev->wiphy.available_antennas_tx &&
1969 !rdev->wiphy.available_antennas_rx) ||
1970 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001971 result = -EOPNOTSUPP;
1972 goto bad_res;
1973 }
1974
1975 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1976 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1977
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001978 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001979 * available antenna masks, except for the "all" mask */
1980 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1981 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001982 result = -EINVAL;
1983 goto bad_res;
1984 }
1985
Bruno Randolf7f531e02010-12-16 11:30:22 +09001986 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1987 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001988
Hila Gonene35e4d22012-06-27 17:19:42 +03001989 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001990 if (result)
1991 goto bad_res;
1992 }
1993
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001994 changed = 0;
1995
1996 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1997 retry_short = nla_get_u8(
1998 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1999 if (retry_short == 0) {
2000 result = -EINVAL;
2001 goto bad_res;
2002 }
2003 changed |= WIPHY_PARAM_RETRY_SHORT;
2004 }
2005
2006 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2007 retry_long = nla_get_u8(
2008 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2009 if (retry_long == 0) {
2010 result = -EINVAL;
2011 goto bad_res;
2012 }
2013 changed |= WIPHY_PARAM_RETRY_LONG;
2014 }
2015
2016 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2017 frag_threshold = nla_get_u32(
2018 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2019 if (frag_threshold < 256) {
2020 result = -EINVAL;
2021 goto bad_res;
2022 }
2023 if (frag_threshold != (u32) -1) {
2024 /*
2025 * Fragments (apart from the last one) are required to
2026 * have even length. Make the fragmentation code
2027 * simpler by stripping LSB should someone try to use
2028 * odd threshold value.
2029 */
2030 frag_threshold &= ~0x1;
2031 }
2032 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2033 }
2034
2035 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2036 rts_threshold = nla_get_u32(
2037 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2038 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2039 }
2040
Lukáš Turek81077e82009-12-21 22:50:47 +01002041 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2042 coverage_class = nla_get_u8(
2043 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2044 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2045 }
2046
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002047 if (changed) {
2048 u8 old_retry_short, old_retry_long;
2049 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002050 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002051
2052 if (!rdev->ops->set_wiphy_params) {
2053 result = -EOPNOTSUPP;
2054 goto bad_res;
2055 }
2056
2057 old_retry_short = rdev->wiphy.retry_short;
2058 old_retry_long = rdev->wiphy.retry_long;
2059 old_frag_threshold = rdev->wiphy.frag_threshold;
2060 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002061 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002062
2063 if (changed & WIPHY_PARAM_RETRY_SHORT)
2064 rdev->wiphy.retry_short = retry_short;
2065 if (changed & WIPHY_PARAM_RETRY_LONG)
2066 rdev->wiphy.retry_long = retry_long;
2067 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2068 rdev->wiphy.frag_threshold = frag_threshold;
2069 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2070 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002071 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2072 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002073
Hila Gonene35e4d22012-06-27 17:19:42 +03002074 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002075 if (result) {
2076 rdev->wiphy.retry_short = old_retry_short;
2077 rdev->wiphy.retry_long = old_retry_long;
2078 rdev->wiphy.frag_threshold = old_frag_threshold;
2079 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002080 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002081 }
2082 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002083
Johannes Berg306d6112008-12-08 12:39:04 +01002084 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002085 if (netdev)
2086 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002087 return result;
2088}
2089
Johannes Berg71bbc992012-06-15 15:30:18 +02002090static inline u64 wdev_id(struct wireless_dev *wdev)
2091{
2092 return (u64)wdev->identifier |
2093 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2094}
Johannes Berg55682962007-09-20 13:09:35 -04002095
Johannes Berg683b6d32012-11-08 21:25:48 +01002096static int nl80211_send_chandef(struct sk_buff *msg,
2097 struct cfg80211_chan_def *chandef)
2098{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002099 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002100
Johannes Berg683b6d32012-11-08 21:25:48 +01002101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2102 chandef->chan->center_freq))
2103 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002104 switch (chandef->width) {
2105 case NL80211_CHAN_WIDTH_20_NOHT:
2106 case NL80211_CHAN_WIDTH_20:
2107 case NL80211_CHAN_WIDTH_40:
2108 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2109 cfg80211_get_chandef_type(chandef)))
2110 return -ENOBUFS;
2111 break;
2112 default:
2113 break;
2114 }
2115 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2116 return -ENOBUFS;
2117 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2118 return -ENOBUFS;
2119 if (chandef->center_freq2 &&
2120 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002121 return -ENOBUFS;
2122 return 0;
2123}
2124
Eric W. Biederman15e47302012-09-07 20:12:54 +00002125static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002126 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002127 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002128{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002129 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002130 void *hdr;
2131
Eric W. Biederman15e47302012-09-07 20:12:54 +00002132 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002133 if (!hdr)
2134 return -1;
2135
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002136 if (dev &&
2137 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002138 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002139 goto nla_put_failure;
2140
2141 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2142 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002143 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002144 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002145 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2146 rdev->devlist_generation ^
2147 (cfg80211_rdev_list_generation << 2)))
2148 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002149
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002150 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002151 int ret;
2152 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002153
Johannes Berg683b6d32012-11-08 21:25:48 +01002154 ret = rdev_get_channel(rdev, wdev, &chandef);
2155 if (ret == 0) {
2156 if (nl80211_send_chandef(msg, &chandef))
2157 goto nla_put_failure;
2158 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002159 }
2160
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002161 if (wdev->ssid_len) {
2162 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2163 goto nla_put_failure;
2164 }
2165
Johannes Berg55682962007-09-20 13:09:35 -04002166 return genlmsg_end(msg, hdr);
2167
2168 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002169 genlmsg_cancel(msg, hdr);
2170 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002171}
2172
2173static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2174{
2175 int wp_idx = 0;
2176 int if_idx = 0;
2177 int wp_start = cb->args[0];
2178 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002179 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002180 struct wireless_dev *wdev;
2181
Johannes Berg5fe231e2013-05-08 21:45:15 +02002182 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002183 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2184 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002185 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002186 if (wp_idx < wp_start) {
2187 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002188 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002189 }
Johannes Berg55682962007-09-20 13:09:35 -04002190 if_idx = 0;
2191
Johannes Berg89a54e42012-06-15 14:33:17 +02002192 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193 if (if_idx < if_start) {
2194 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002195 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002196 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002197 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002198 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002199 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002200 goto out;
2201 }
2202 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002203 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002204
2205 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002206 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002207 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002208 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002209
2210 cb->args[0] = wp_idx;
2211 cb->args[1] = if_idx;
2212
2213 return skb->len;
2214}
2215
2216static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2217{
2218 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002219 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002220 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002221
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002222 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002223 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002224 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002225
Eric W. Biederman15e47302012-09-07 20:12:54 +00002226 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002227 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002228 nlmsg_free(msg);
2229 return -ENOBUFS;
2230 }
Johannes Berg55682962007-09-20 13:09:35 -04002231
Johannes Berg134e6372009-07-10 09:51:34 +00002232 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002233}
2234
Michael Wu66f7ac52008-01-31 19:48:22 +01002235static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2236 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2237 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2238 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2239 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2240 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002241 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002242};
2243
2244static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2245{
2246 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2247 int flag;
2248
2249 *mntrflags = 0;
2250
2251 if (!nla)
2252 return -EINVAL;
2253
2254 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2255 nla, mntr_flags_policy))
2256 return -EINVAL;
2257
2258 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2259 if (flags[flag])
2260 *mntrflags |= (1<<flag);
2261
2262 return 0;
2263}
2264
Johannes Berg9bc383d2009-11-19 11:55:19 +01002265static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002266 struct net_device *netdev, u8 use_4addr,
2267 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002268{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002269 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002270 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002271 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002272 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002273 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002274
2275 switch (iftype) {
2276 case NL80211_IFTYPE_AP_VLAN:
2277 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2278 return 0;
2279 break;
2280 case NL80211_IFTYPE_STATION:
2281 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2282 return 0;
2283 break;
2284 default:
2285 break;
2286 }
2287
2288 return -EOPNOTSUPP;
2289}
2290
Johannes Berg55682962007-09-20 13:09:35 -04002291static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2292{
Johannes Berg4c476992010-10-04 21:36:35 +02002293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002294 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002295 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002296 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002297 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002298 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002299 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002300
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002301 memset(&params, 0, sizeof(params));
2302
Johannes Berg04a773a2009-04-19 21:24:32 +02002303 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002304
Johannes Berg723b0382008-09-16 20:22:09 +02002305 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002306 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002307 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002308 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002309 if (ntype > NL80211_IFTYPE_MAX)
2310 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002311 }
2312
Johannes Berg92ffe052008-09-16 20:39:36 +02002313 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002314 struct wireless_dev *wdev = dev->ieee80211_ptr;
2315
Johannes Berg4c476992010-10-04 21:36:35 +02002316 if (ntype != NL80211_IFTYPE_MESH_POINT)
2317 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002318 if (netif_running(dev))
2319 return -EBUSY;
2320
2321 wdev_lock(wdev);
2322 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2323 IEEE80211_MAX_MESH_ID_LEN);
2324 wdev->mesh_id_up_len =
2325 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2326 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2327 wdev->mesh_id_up_len);
2328 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002329 }
2330
Felix Fietkau8b787642009-11-10 18:53:10 +01002331 if (info->attrs[NL80211_ATTR_4ADDR]) {
2332 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2333 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002334 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002335 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002336 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002337 } else {
2338 params.use_4addr = -1;
2339 }
2340
Johannes Berg92ffe052008-09-16 20:39:36 +02002341 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002342 if (ntype != NL80211_IFTYPE_MONITOR)
2343 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002344 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2345 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002346 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002347 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002348
2349 flags = &_flags;
2350 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002351 }
Johannes Berg3b858752009-03-12 09:55:09 +01002352
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002353 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2354 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2355 return -EOPNOTSUPP;
2356
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002357 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002358 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002359 else
2360 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002361
Johannes Berg9bc383d2009-11-19 11:55:19 +01002362 if (!err && params.use_4addr != -1)
2363 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2364
Johannes Berg55682962007-09-20 13:09:35 -04002365 return err;
2366}
2367
2368static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2369{
Johannes Berg4c476992010-10-04 21:36:35 +02002370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002371 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002372 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002373 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002374 int err;
2375 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002376 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002377
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002378 memset(&params, 0, sizeof(params));
2379
Johannes Berg55682962007-09-20 13:09:35 -04002380 if (!info->attrs[NL80211_ATTR_IFNAME])
2381 return -EINVAL;
2382
2383 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2384 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2385 if (type > NL80211_IFTYPE_MAX)
2386 return -EINVAL;
2387 }
2388
Johannes Berg79c97e92009-07-07 03:56:12 +02002389 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002390 !(rdev->wiphy.interface_modes & (1 << type)))
2391 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002392
Arend van Spriel1c18f142013-01-08 10:17:27 +01002393 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2394 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2395 ETH_ALEN);
2396 if (!is_valid_ether_addr(params.macaddr))
2397 return -EADDRNOTAVAIL;
2398 }
2399
Johannes Berg9bc383d2009-11-19 11:55:19 +01002400 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002401 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002402 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002403 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002404 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002405 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002406
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2408 if (!msg)
2409 return -ENOMEM;
2410
Michael Wu66f7ac52008-01-31 19:48:22 +01002411 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2412 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2413 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002414
2415 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2416 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2417 return -EOPNOTSUPP;
2418
Hila Gonene35e4d22012-06-27 17:19:42 +03002419 wdev = rdev_add_virtual_intf(rdev,
2420 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2421 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002422 if (IS_ERR(wdev)) {
2423 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002424 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002425 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002426
Johannes Berg98104fde2012-06-16 00:19:54 +02002427 switch (type) {
2428 case NL80211_IFTYPE_MESH_POINT:
2429 if (!info->attrs[NL80211_ATTR_MESH_ID])
2430 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002431 wdev_lock(wdev);
2432 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2433 IEEE80211_MAX_MESH_ID_LEN);
2434 wdev->mesh_id_up_len =
2435 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2436 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2437 wdev->mesh_id_up_len);
2438 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002439 break;
2440 case NL80211_IFTYPE_P2P_DEVICE:
2441 /*
2442 * P2P Device doesn't have a netdev, so doesn't go
2443 * through the netdev notifier and must be added here
2444 */
2445 mutex_init(&wdev->mtx);
2446 INIT_LIST_HEAD(&wdev->event_list);
2447 spin_lock_init(&wdev->event_lock);
2448 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2449 spin_lock_init(&wdev->mgmt_registrations_lock);
2450
Johannes Berg98104fde2012-06-16 00:19:54 +02002451 wdev->identifier = ++rdev->wdev_id;
2452 list_add_rcu(&wdev->list, &rdev->wdev_list);
2453 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002454 break;
2455 default:
2456 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002457 }
2458
Eric W. Biederman15e47302012-09-07 20:12:54 +00002459 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002460 rdev, wdev) < 0) {
2461 nlmsg_free(msg);
2462 return -ENOBUFS;
2463 }
2464
2465 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002466}
2467
2468static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2469{
Johannes Berg4c476992010-10-04 21:36:35 +02002470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002471 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002472
Johannes Berg4c476992010-10-04 21:36:35 +02002473 if (!rdev->ops->del_virtual_intf)
2474 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002475
Johannes Berg84efbb82012-06-16 00:00:26 +02002476 /*
2477 * If we remove a wireless device without a netdev then clear
2478 * user_ptr[1] so that nl80211_post_doit won't dereference it
2479 * to check if it needs to do dev_put(). Otherwise it crashes
2480 * since the wdev has been freed, unlike with a netdev where
2481 * we need the dev_put() for the netdev to really be freed.
2482 */
2483 if (!wdev->netdev)
2484 info->user_ptr[1] = NULL;
2485
Hila Gonene35e4d22012-06-27 17:19:42 +03002486 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002487}
2488
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002489static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2490{
2491 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2492 struct net_device *dev = info->user_ptr[1];
2493 u16 noack_map;
2494
2495 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2496 return -EINVAL;
2497
2498 if (!rdev->ops->set_noack_map)
2499 return -EOPNOTSUPP;
2500
2501 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2502
Hila Gonene35e4d22012-06-27 17:19:42 +03002503 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002504}
2505
Johannes Berg41ade002007-12-19 02:03:29 +01002506struct get_key_cookie {
2507 struct sk_buff *msg;
2508 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002509 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002510};
2511
2512static void get_key_callback(void *c, struct key_params *params)
2513{
Johannes Bergb9454e82009-07-08 13:29:08 +02002514 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002515 struct get_key_cookie *cookie = c;
2516
David S. Miller9360ffd2012-03-29 04:41:26 -04002517 if ((params->key &&
2518 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2519 params->key_len, params->key)) ||
2520 (params->seq &&
2521 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2522 params->seq_len, params->seq)) ||
2523 (params->cipher &&
2524 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2525 params->cipher)))
2526 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002527
Johannes Bergb9454e82009-07-08 13:29:08 +02002528 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2529 if (!key)
2530 goto nla_put_failure;
2531
David S. Miller9360ffd2012-03-29 04:41:26 -04002532 if ((params->key &&
2533 nla_put(cookie->msg, NL80211_KEY_DATA,
2534 params->key_len, params->key)) ||
2535 (params->seq &&
2536 nla_put(cookie->msg, NL80211_KEY_SEQ,
2537 params->seq_len, params->seq)) ||
2538 (params->cipher &&
2539 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2540 params->cipher)))
2541 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002542
David S. Miller9360ffd2012-03-29 04:41:26 -04002543 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2544 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002545
2546 nla_nest_end(cookie->msg, key);
2547
Johannes Berg41ade002007-12-19 02:03:29 +01002548 return;
2549 nla_put_failure:
2550 cookie->error = 1;
2551}
2552
2553static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2554{
Johannes Berg4c476992010-10-04 21:36:35 +02002555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002556 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002557 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002558 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002559 const u8 *mac_addr = NULL;
2560 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002561 struct get_key_cookie cookie = {
2562 .error = 0,
2563 };
2564 void *hdr;
2565 struct sk_buff *msg;
2566
2567 if (info->attrs[NL80211_ATTR_KEY_IDX])
2568 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2569
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002570 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002571 return -EINVAL;
2572
2573 if (info->attrs[NL80211_ATTR_MAC])
2574 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2575
Johannes Berge31b8212010-10-05 19:39:30 +02002576 pairwise = !!mac_addr;
2577 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2578 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2579 if (kt >= NUM_NL80211_KEYTYPES)
2580 return -EINVAL;
2581 if (kt != NL80211_KEYTYPE_GROUP &&
2582 kt != NL80211_KEYTYPE_PAIRWISE)
2583 return -EINVAL;
2584 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2585 }
2586
Johannes Berg4c476992010-10-04 21:36:35 +02002587 if (!rdev->ops->get_key)
2588 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002589
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002590 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002591 if (!msg)
2592 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002593
Eric W. Biederman15e47302012-09-07 20:12:54 +00002594 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002595 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002596 if (IS_ERR(hdr))
2597 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002598
2599 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002600 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002601
David S. Miller9360ffd2012-03-29 04:41:26 -04002602 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2603 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2604 goto nla_put_failure;
2605 if (mac_addr &&
2606 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2607 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002608
Johannes Berge31b8212010-10-05 19:39:30 +02002609 if (pairwise && mac_addr &&
2610 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2611 return -ENOENT;
2612
Hila Gonene35e4d22012-06-27 17:19:42 +03002613 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2614 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002615
2616 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002617 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002618
2619 if (cookie.error)
2620 goto nla_put_failure;
2621
2622 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002623 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002624
2625 nla_put_failure:
2626 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002627 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002628 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002629 return err;
2630}
2631
2632static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2633{
Johannes Berg4c476992010-10-04 21:36:35 +02002634 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002635 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002636 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002637 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002638
Johannes Bergb9454e82009-07-08 13:29:08 +02002639 err = nl80211_parse_key(info, &key);
2640 if (err)
2641 return err;
2642
2643 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002644 return -EINVAL;
2645
Johannes Bergb9454e82009-07-08 13:29:08 +02002646 /* only support setting default key */
2647 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002648 return -EINVAL;
2649
Johannes Bergfffd0932009-07-08 14:22:54 +02002650 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002651
2652 if (key.def) {
2653 if (!rdev->ops->set_default_key) {
2654 err = -EOPNOTSUPP;
2655 goto out;
2656 }
2657
2658 err = nl80211_key_allowed(dev->ieee80211_ptr);
2659 if (err)
2660 goto out;
2661
Hila Gonene35e4d22012-06-27 17:19:42 +03002662 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002663 key.def_uni, key.def_multi);
2664
2665 if (err)
2666 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002667
Johannes Berg3d23e342009-09-29 23:27:28 +02002668#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002669 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002670#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002671 } else {
2672 if (key.def_uni || !key.def_multi) {
2673 err = -EINVAL;
2674 goto out;
2675 }
2676
2677 if (!rdev->ops->set_default_mgmt_key) {
2678 err = -EOPNOTSUPP;
2679 goto out;
2680 }
2681
2682 err = nl80211_key_allowed(dev->ieee80211_ptr);
2683 if (err)
2684 goto out;
2685
Hila Gonene35e4d22012-06-27 17:19:42 +03002686 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002687 if (err)
2688 goto out;
2689
2690#ifdef CONFIG_CFG80211_WEXT
2691 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2692#endif
2693 }
2694
2695 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002696 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002697
Johannes Berg41ade002007-12-19 02:03:29 +01002698 return err;
2699}
2700
2701static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2702{
Johannes Berg4c476992010-10-04 21:36:35 +02002703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002704 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002705 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002706 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002707 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002708
Johannes Bergb9454e82009-07-08 13:29:08 +02002709 err = nl80211_parse_key(info, &key);
2710 if (err)
2711 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002712
Johannes Bergb9454e82009-07-08 13:29:08 +02002713 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002714 return -EINVAL;
2715
Johannes Berg41ade002007-12-19 02:03:29 +01002716 if (info->attrs[NL80211_ATTR_MAC])
2717 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2718
Johannes Berge31b8212010-10-05 19:39:30 +02002719 if (key.type == -1) {
2720 if (mac_addr)
2721 key.type = NL80211_KEYTYPE_PAIRWISE;
2722 else
2723 key.type = NL80211_KEYTYPE_GROUP;
2724 }
2725
2726 /* for now */
2727 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2728 key.type != NL80211_KEYTYPE_GROUP)
2729 return -EINVAL;
2730
Johannes Berg4c476992010-10-04 21:36:35 +02002731 if (!rdev->ops->add_key)
2732 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002733
Johannes Berge31b8212010-10-05 19:39:30 +02002734 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2735 key.type == NL80211_KEYTYPE_PAIRWISE,
2736 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002737 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002738
2739 wdev_lock(dev->ieee80211_ptr);
2740 err = nl80211_key_allowed(dev->ieee80211_ptr);
2741 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002742 err = rdev_add_key(rdev, dev, key.idx,
2743 key.type == NL80211_KEYTYPE_PAIRWISE,
2744 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002745 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002746
Johannes Berg41ade002007-12-19 02:03:29 +01002747 return err;
2748}
2749
2750static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2751{
Johannes Berg4c476992010-10-04 21:36:35 +02002752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002753 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002754 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002755 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002756 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002757
Johannes Bergb9454e82009-07-08 13:29:08 +02002758 err = nl80211_parse_key(info, &key);
2759 if (err)
2760 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002761
2762 if (info->attrs[NL80211_ATTR_MAC])
2763 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2764
Johannes Berge31b8212010-10-05 19:39:30 +02002765 if (key.type == -1) {
2766 if (mac_addr)
2767 key.type = NL80211_KEYTYPE_PAIRWISE;
2768 else
2769 key.type = NL80211_KEYTYPE_GROUP;
2770 }
2771
2772 /* for now */
2773 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2774 key.type != NL80211_KEYTYPE_GROUP)
2775 return -EINVAL;
2776
Johannes Berg4c476992010-10-04 21:36:35 +02002777 if (!rdev->ops->del_key)
2778 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002779
Johannes Bergfffd0932009-07-08 14:22:54 +02002780 wdev_lock(dev->ieee80211_ptr);
2781 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002782
2783 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2784 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2785 err = -ENOENT;
2786
Johannes Bergfffd0932009-07-08 14:22:54 +02002787 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002788 err = rdev_del_key(rdev, dev, key.idx,
2789 key.type == NL80211_KEYTYPE_PAIRWISE,
2790 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002791
Johannes Berg3d23e342009-09-29 23:27:28 +02002792#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002793 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002794 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002795 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002796 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002797 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2798 }
2799#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002800 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002801
Johannes Berg41ade002007-12-19 02:03:29 +01002802 return err;
2803}
2804
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302805/* This function returns an error or the number of nested attributes */
2806static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2807{
2808 struct nlattr *attr;
2809 int n_entries = 0, tmp;
2810
2811 nla_for_each_nested(attr, nl_attr, tmp) {
2812 if (nla_len(attr) != ETH_ALEN)
2813 return -EINVAL;
2814
2815 n_entries++;
2816 }
2817
2818 return n_entries;
2819}
2820
2821/*
2822 * This function parses ACL information and allocates memory for ACL data.
2823 * On successful return, the calling function is responsible to free the
2824 * ACL buffer returned by this function.
2825 */
2826static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2827 struct genl_info *info)
2828{
2829 enum nl80211_acl_policy acl_policy;
2830 struct nlattr *attr;
2831 struct cfg80211_acl_data *acl;
2832 int i = 0, n_entries, tmp;
2833
2834 if (!wiphy->max_acl_mac_addrs)
2835 return ERR_PTR(-EOPNOTSUPP);
2836
2837 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2838 return ERR_PTR(-EINVAL);
2839
2840 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2841 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2842 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2843 return ERR_PTR(-EINVAL);
2844
2845 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2846 return ERR_PTR(-EINVAL);
2847
2848 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2849 if (n_entries < 0)
2850 return ERR_PTR(n_entries);
2851
2852 if (n_entries > wiphy->max_acl_mac_addrs)
2853 return ERR_PTR(-ENOTSUPP);
2854
2855 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2856 GFP_KERNEL);
2857 if (!acl)
2858 return ERR_PTR(-ENOMEM);
2859
2860 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2861 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2862 i++;
2863 }
2864
2865 acl->n_acl_entries = n_entries;
2866 acl->acl_policy = acl_policy;
2867
2868 return acl;
2869}
2870
2871static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2872{
2873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2874 struct net_device *dev = info->user_ptr[1];
2875 struct cfg80211_acl_data *acl;
2876 int err;
2877
2878 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2879 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2880 return -EOPNOTSUPP;
2881
2882 if (!dev->ieee80211_ptr->beacon_interval)
2883 return -EINVAL;
2884
2885 acl = parse_acl_data(&rdev->wiphy, info);
2886 if (IS_ERR(acl))
2887 return PTR_ERR(acl);
2888
2889 err = rdev_set_mac_acl(rdev, dev, acl);
2890
2891 kfree(acl);
2892
2893 return err;
2894}
2895
Johannes Berg88600202012-02-13 15:17:18 +01002896static int nl80211_parse_beacon(struct genl_info *info,
2897 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002898{
Johannes Berg88600202012-02-13 15:17:18 +01002899 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002900
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002901 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2902 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2903 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2904 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002905 return -EINVAL;
2906
Johannes Berg88600202012-02-13 15:17:18 +01002907 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002908
Johannes Berged1b6cc2007-12-19 02:03:32 +01002909 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002910 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2911 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2912 if (!bcn->head_len)
2913 return -EINVAL;
2914 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002915 }
2916
2917 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002918 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2919 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002920 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002921 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002922 }
2923
Johannes Berg4c476992010-10-04 21:36:35 +02002924 if (!haveinfo)
2925 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002926
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002927 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002928 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2929 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002930 }
2931
2932 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002933 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002934 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002935 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002936 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2937 }
2938
2939 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002940 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002941 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002942 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002943 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2944 }
2945
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002946 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002947 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002948 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002949 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002950 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2951 }
2952
Johannes Berg88600202012-02-13 15:17:18 +01002953 return 0;
2954}
2955
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002956static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2957 struct cfg80211_ap_settings *params)
2958{
2959 struct wireless_dev *wdev;
2960 bool ret = false;
2961
Johannes Berg89a54e42012-06-15 14:33:17 +02002962 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002963 if (wdev->iftype != NL80211_IFTYPE_AP &&
2964 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2965 continue;
2966
Johannes Berg683b6d32012-11-08 21:25:48 +01002967 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002968 continue;
2969
Johannes Berg683b6d32012-11-08 21:25:48 +01002970 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002971 ret = true;
2972 break;
2973 }
2974
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002975 return ret;
2976}
2977
Jouni Malinene39e5b52012-09-30 19:29:39 +03002978static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2979 enum nl80211_auth_type auth_type,
2980 enum nl80211_commands cmd)
2981{
2982 if (auth_type > NL80211_AUTHTYPE_MAX)
2983 return false;
2984
2985 switch (cmd) {
2986 case NL80211_CMD_AUTHENTICATE:
2987 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2988 auth_type == NL80211_AUTHTYPE_SAE)
2989 return false;
2990 return true;
2991 case NL80211_CMD_CONNECT:
2992 case NL80211_CMD_START_AP:
2993 /* SAE not supported yet */
2994 if (auth_type == NL80211_AUTHTYPE_SAE)
2995 return false;
2996 return true;
2997 default:
2998 return false;
2999 }
3000}
3001
Johannes Berg88600202012-02-13 15:17:18 +01003002static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3003{
3004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3005 struct net_device *dev = info->user_ptr[1];
3006 struct wireless_dev *wdev = dev->ieee80211_ptr;
3007 struct cfg80211_ap_settings params;
3008 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003009 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003010
3011 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3012 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3013 return -EOPNOTSUPP;
3014
3015 if (!rdev->ops->start_ap)
3016 return -EOPNOTSUPP;
3017
3018 if (wdev->beacon_interval)
3019 return -EALREADY;
3020
3021 memset(&params, 0, sizeof(params));
3022
3023 /* these are required for START_AP */
3024 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3025 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3026 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3027 return -EINVAL;
3028
3029 err = nl80211_parse_beacon(info, &params.beacon);
3030 if (err)
3031 return err;
3032
3033 params.beacon_interval =
3034 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3035 params.dtim_period =
3036 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3037
3038 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3039 if (err)
3040 return err;
3041
3042 /*
3043 * In theory, some of these attributes should be required here
3044 * but since they were not used when the command was originally
3045 * added, keep them optional for old user space programs to let
3046 * them continue to work with drivers that do not need the
3047 * additional information -- drivers must check!
3048 */
3049 if (info->attrs[NL80211_ATTR_SSID]) {
3050 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3051 params.ssid_len =
3052 nla_len(info->attrs[NL80211_ATTR_SSID]);
3053 if (params.ssid_len == 0 ||
3054 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3055 return -EINVAL;
3056 }
3057
3058 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3059 params.hidden_ssid = nla_get_u32(
3060 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3061 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3062 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3063 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3064 return -EINVAL;
3065 }
3066
3067 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3068
3069 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3070 params.auth_type = nla_get_u32(
3071 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003072 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3073 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003074 return -EINVAL;
3075 } else
3076 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3077
3078 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3079 NL80211_MAX_NR_CIPHER_SUITES);
3080 if (err)
3081 return err;
3082
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303083 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3084 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3085 return -EOPNOTSUPP;
3086 params.inactivity_timeout = nla_get_u16(
3087 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3088 }
3089
Johannes Berg53cabad2012-11-14 15:17:28 +01003090 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3091 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3092 return -EINVAL;
3093 params.p2p_ctwindow =
3094 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3095 if (params.p2p_ctwindow > 127)
3096 return -EINVAL;
3097 if (params.p2p_ctwindow != 0 &&
3098 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3099 return -EINVAL;
3100 }
3101
3102 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3103 u8 tmp;
3104
3105 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3106 return -EINVAL;
3107 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3108 if (tmp > 1)
3109 return -EINVAL;
3110 params.p2p_opp_ps = tmp;
3111 if (params.p2p_opp_ps != 0 &&
3112 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3113 return -EINVAL;
3114 }
3115
Johannes Bergaa430da2012-05-16 23:50:18 +02003116 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003117 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3118 if (err)
3119 return err;
3120 } else if (wdev->preset_chandef.chan) {
3121 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003122 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003123 return -EINVAL;
3124
Johannes Berg683b6d32012-11-08 21:25:48 +01003125 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003126 return -EINVAL;
3127
Simon Wunderlich04f39042013-02-08 18:16:19 +01003128 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3129 if (err < 0)
3130 return err;
3131 if (err) {
3132 radar_detect_width = BIT(params.chandef.width);
3133 params.radar_required = true;
3134 }
3135
Simon Wunderlich04f39042013-02-08 18:16:19 +01003136 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3137 params.chandef.chan,
3138 CHAN_MODE_SHARED,
3139 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003140 if (err)
3141 return err;
3142
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303143 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3144 params.acl = parse_acl_data(&rdev->wiphy, info);
3145 if (IS_ERR(params.acl))
3146 return PTR_ERR(params.acl);
3147 }
3148
Hila Gonene35e4d22012-06-27 17:19:42 +03003149 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003150 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003151 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003152 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003153 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003154 wdev->ssid_len = params.ssid_len;
3155 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003156 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303157
3158 kfree(params.acl);
3159
Johannes Berg56d18932011-05-09 18:41:15 +02003160 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003161}
3162
Johannes Berg88600202012-02-13 15:17:18 +01003163static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3164{
3165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3166 struct net_device *dev = info->user_ptr[1];
3167 struct wireless_dev *wdev = dev->ieee80211_ptr;
3168 struct cfg80211_beacon_data params;
3169 int err;
3170
3171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3172 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3173 return -EOPNOTSUPP;
3174
3175 if (!rdev->ops->change_beacon)
3176 return -EOPNOTSUPP;
3177
3178 if (!wdev->beacon_interval)
3179 return -EINVAL;
3180
3181 err = nl80211_parse_beacon(info, &params);
3182 if (err)
3183 return err;
3184
Hila Gonene35e4d22012-06-27 17:19:42 +03003185 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003186}
3187
3188static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003189{
Johannes Berg4c476992010-10-04 21:36:35 +02003190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3191 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003192
Michal Kazior60771782012-06-29 12:46:56 +02003193 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003194}
3195
Johannes Berg5727ef12007-12-19 02:03:34 +01003196static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3197 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3198 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3199 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003200 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003201 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003202 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003203};
3204
Johannes Bergeccb8e82009-05-11 21:57:56 +03003205static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003206 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003207 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003208{
3209 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003210 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003211 int flag;
3212
Johannes Bergeccb8e82009-05-11 21:57:56 +03003213 /*
3214 * Try parsing the new attribute first so userspace
3215 * can specify both for older kernels.
3216 */
3217 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3218 if (nla) {
3219 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003220
Johannes Bergeccb8e82009-05-11 21:57:56 +03003221 sta_flags = nla_data(nla);
3222 params->sta_flags_mask = sta_flags->mask;
3223 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003224 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003225 if ((params->sta_flags_mask |
3226 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3227 return -EINVAL;
3228 return 0;
3229 }
3230
3231 /* if present, parse the old attribute */
3232
3233 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003234 if (!nla)
3235 return 0;
3236
3237 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3238 nla, sta_flags_policy))
3239 return -EINVAL;
3240
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003241 /*
3242 * Only allow certain flags for interface types so that
3243 * other attributes are silently ignored. Remember that
3244 * this is backward compatibility code with old userspace
3245 * and shouldn't be hit in other cases anyway.
3246 */
3247 switch (iftype) {
3248 case NL80211_IFTYPE_AP:
3249 case NL80211_IFTYPE_AP_VLAN:
3250 case NL80211_IFTYPE_P2P_GO:
3251 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3252 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3253 BIT(NL80211_STA_FLAG_WME) |
3254 BIT(NL80211_STA_FLAG_MFP);
3255 break;
3256 case NL80211_IFTYPE_P2P_CLIENT:
3257 case NL80211_IFTYPE_STATION:
3258 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3259 BIT(NL80211_STA_FLAG_TDLS_PEER);
3260 break;
3261 case NL80211_IFTYPE_MESH_POINT:
3262 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3263 BIT(NL80211_STA_FLAG_MFP) |
3264 BIT(NL80211_STA_FLAG_AUTHORIZED);
3265 default:
3266 return -EINVAL;
3267 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003268
Johannes Berg3383b5a2012-05-10 20:14:43 +02003269 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3270 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003271 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003272
Johannes Berg3383b5a2012-05-10 20:14:43 +02003273 /* no longer support new API additions in old API */
3274 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3275 return -EINVAL;
3276 }
3277 }
3278
Johannes Berg5727ef12007-12-19 02:03:34 +01003279 return 0;
3280}
3281
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003282static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3283 int attr)
3284{
3285 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003286 u32 bitrate;
3287 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003288
3289 rate = nla_nest_start(msg, attr);
3290 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003291 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003292
3293 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3294 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003295 /* report 16-bit bitrate only if we can */
3296 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003297 if (bitrate > 0 &&
3298 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3299 return false;
3300 if (bitrate_compat > 0 &&
3301 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3302 return false;
3303
3304 if (info->flags & RATE_INFO_FLAGS_MCS) {
3305 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3306 return false;
3307 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3308 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3309 return false;
3310 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3311 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3312 return false;
3313 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3314 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3315 return false;
3316 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3317 return false;
3318 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3319 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3320 return false;
3321 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3322 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3323 return false;
3324 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3325 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3326 return false;
3327 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3328 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3329 return false;
3330 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3331 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3332 return false;
3333 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003334
3335 nla_nest_end(msg, rate);
3336 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003337}
3338
Felix Fietkau119363c2013-04-22 16:29:30 +02003339static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3340 int id)
3341{
3342 void *attr;
3343 int i = 0;
3344
3345 if (!mask)
3346 return true;
3347
3348 attr = nla_nest_start(msg, id);
3349 if (!attr)
3350 return false;
3351
3352 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3353 if (!(mask & BIT(i)))
3354 continue;
3355
3356 if (nla_put_u8(msg, i, signal[i]))
3357 return false;
3358 }
3359
3360 nla_nest_end(msg, attr);
3361
3362 return true;
3363}
3364
Eric W. Biederman15e47302012-09-07 20:12:54 +00003365static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003366 int flags,
3367 struct cfg80211_registered_device *rdev,
3368 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003369 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003370{
3371 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003372 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003373
Eric W. Biederman15e47302012-09-07 20:12:54 +00003374 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003375 if (!hdr)
3376 return -1;
3377
David S. Miller9360ffd2012-03-29 04:41:26 -04003378 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3379 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3380 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3381 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003382
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003383 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3384 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003385 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003386 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3387 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3388 sinfo->connected_time))
3389 goto nla_put_failure;
3390 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3391 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3392 sinfo->inactive_time))
3393 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003394 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3395 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003396 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003397 (u32)sinfo->rx_bytes))
3398 goto nla_put_failure;
3399 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003400 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003401 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3402 (u32)sinfo->tx_bytes))
3403 goto nla_put_failure;
3404 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3405 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003406 sinfo->rx_bytes))
3407 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003408 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3409 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 sinfo->tx_bytes))
3411 goto nla_put_failure;
3412 if ((sinfo->filled & STATION_INFO_LLID) &&
3413 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3414 goto nla_put_failure;
3415 if ((sinfo->filled & STATION_INFO_PLID) &&
3416 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3417 goto nla_put_failure;
3418 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3419 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3420 sinfo->plink_state))
3421 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003422 switch (rdev->wiphy.signal_type) {
3423 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003424 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3425 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3426 sinfo->signal))
3427 goto nla_put_failure;
3428 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3429 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3430 sinfo->signal_avg))
3431 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003432 break;
3433 default:
3434 break;
3435 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003436 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3437 if (!nl80211_put_signal(msg, sinfo->chains,
3438 sinfo->chain_signal,
3439 NL80211_STA_INFO_CHAIN_SIGNAL))
3440 goto nla_put_failure;
3441 }
3442 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3443 if (!nl80211_put_signal(msg, sinfo->chains,
3444 sinfo->chain_signal_avg,
3445 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3446 goto nla_put_failure;
3447 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003448 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003449 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3450 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003451 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003452 }
3453 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3454 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3455 NL80211_STA_INFO_RX_BITRATE))
3456 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003457 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003458 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3459 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3460 sinfo->rx_packets))
3461 goto nla_put_failure;
3462 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3463 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3464 sinfo->tx_packets))
3465 goto nla_put_failure;
3466 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3467 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3468 sinfo->tx_retries))
3469 goto nla_put_failure;
3470 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3471 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3472 sinfo->tx_failed))
3473 goto nla_put_failure;
3474 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3475 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3476 sinfo->beacon_loss_count))
3477 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003478 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3479 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3480 sinfo->local_pm))
3481 goto nla_put_failure;
3482 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3483 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3484 sinfo->peer_pm))
3485 goto nla_put_failure;
3486 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3487 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3488 sinfo->nonpeer_pm))
3489 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003490 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3491 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3492 if (!bss_param)
3493 goto nla_put_failure;
3494
David S. Miller9360ffd2012-03-29 04:41:26 -04003495 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3496 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3497 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3498 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3499 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3500 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3501 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3502 sinfo->bss_param.dtim_period) ||
3503 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3504 sinfo->bss_param.beacon_interval))
3505 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003506
3507 nla_nest_end(msg, bss_param);
3508 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003509 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3510 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3511 sizeof(struct nl80211_sta_flag_update),
3512 &sinfo->sta_flags))
3513 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003514 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3515 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3516 sinfo->t_offset))
3517 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003518 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003519
David S. Miller9360ffd2012-03-29 04:41:26 -04003520 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3521 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3522 sinfo->assoc_req_ies))
3523 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003524
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003525 return genlmsg_end(msg, hdr);
3526
3527 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003528 genlmsg_cancel(msg, hdr);
3529 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003530}
3531
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003532static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003533 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003534{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003535 struct station_info sinfo;
3536 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003537 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003538 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003539 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003540 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003541
Johannes Berg97990a02013-04-19 01:02:55 +02003542 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003543 if (err)
3544 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003545
Johannes Berg97990a02013-04-19 01:02:55 +02003546 if (!wdev->netdev) {
3547 err = -EINVAL;
3548 goto out_err;
3549 }
3550
Johannes Bergbba95fe2008-07-29 13:22:51 +02003551 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003552 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 goto out_err;
3554 }
3555
Johannes Bergbba95fe2008-07-29 13:22:51 +02003556 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003557 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003558 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003559 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003560 if (err == -ENOENT)
3561 break;
3562 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003563 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003564
3565 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003566 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003568 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003569 &sinfo) < 0)
3570 goto out;
3571
3572 sta_idx++;
3573 }
3574
3575
3576 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003577 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003578 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003579 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003580 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003581
3582 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003583}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584
Johannes Berg5727ef12007-12-19 02:03:34 +01003585static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3586{
Johannes Berg4c476992010-10-04 21:36:35 +02003587 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3588 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003589 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003590 struct sk_buff *msg;
3591 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003592 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003593
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003594 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595
3596 if (!info->attrs[NL80211_ATTR_MAC])
3597 return -EINVAL;
3598
3599 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3600
Johannes Berg4c476992010-10-04 21:36:35 +02003601 if (!rdev->ops->get_station)
3602 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Hila Gonene35e4d22012-06-27 17:19:42 +03003604 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003605 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003606 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003607
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003608 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003609 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003610 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003611
Eric W. Biederman15e47302012-09-07 20:12:54 +00003612 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003613 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003614 nlmsg_free(msg);
3615 return -ENOBUFS;
3616 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003617
Johannes Berg4c476992010-10-04 21:36:35 +02003618 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003619}
3620
Johannes Berg77ee7c82013-02-15 00:48:33 +01003621int cfg80211_check_station_change(struct wiphy *wiphy,
3622 struct station_parameters *params,
3623 enum cfg80211_station_type statype)
3624{
3625 if (params->listen_interval != -1)
3626 return -EINVAL;
3627 if (params->aid)
3628 return -EINVAL;
3629
3630 /* When you run into this, adjust the code below for the new flag */
3631 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3632
3633 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003634 case CFG80211_STA_MESH_PEER_KERNEL:
3635 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003636 /*
3637 * No ignoring the TDLS flag here -- the userspace mesh
3638 * code doesn't have the bug of including TDLS in the
3639 * mask everywhere.
3640 */
3641 if (params->sta_flags_mask &
3642 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3643 BIT(NL80211_STA_FLAG_MFP) |
3644 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3645 return -EINVAL;
3646 break;
3647 case CFG80211_STA_TDLS_PEER_SETUP:
3648 case CFG80211_STA_TDLS_PEER_ACTIVE:
3649 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3650 return -EINVAL;
3651 /* ignore since it can't change */
3652 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3653 break;
3654 default:
3655 /* disallow mesh-specific things */
3656 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3657 return -EINVAL;
3658 if (params->local_pm)
3659 return -EINVAL;
3660 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3661 return -EINVAL;
3662 }
3663
3664 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3665 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3666 /* TDLS can't be set, ... */
3667 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3668 return -EINVAL;
3669 /*
3670 * ... but don't bother the driver with it. This works around
3671 * a hostapd/wpa_supplicant issue -- it always includes the
3672 * TLDS_PEER flag in the mask even for AP mode.
3673 */
3674 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3675 }
3676
3677 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3678 /* reject other things that can't change */
3679 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3680 return -EINVAL;
3681 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3682 return -EINVAL;
3683 if (params->supported_rates)
3684 return -EINVAL;
3685 if (params->ext_capab || params->ht_capa || params->vht_capa)
3686 return -EINVAL;
3687 }
3688
3689 if (statype != CFG80211_STA_AP_CLIENT) {
3690 if (params->vlan)
3691 return -EINVAL;
3692 }
3693
3694 switch (statype) {
3695 case CFG80211_STA_AP_MLME_CLIENT:
3696 /* Use this only for authorizing/unauthorizing a station */
3697 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3698 return -EOPNOTSUPP;
3699 break;
3700 case CFG80211_STA_AP_CLIENT:
3701 /* accept only the listed bits */
3702 if (params->sta_flags_mask &
3703 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3704 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3705 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3706 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3707 BIT(NL80211_STA_FLAG_WME) |
3708 BIT(NL80211_STA_FLAG_MFP)))
3709 return -EINVAL;
3710
3711 /* but authenticated/associated only if driver handles it */
3712 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3713 params->sta_flags_mask &
3714 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3715 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3716 return -EINVAL;
3717 break;
3718 case CFG80211_STA_IBSS:
3719 case CFG80211_STA_AP_STA:
3720 /* reject any changes other than AUTHORIZED */
3721 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3722 return -EINVAL;
3723 break;
3724 case CFG80211_STA_TDLS_PEER_SETUP:
3725 /* reject any changes other than AUTHORIZED or WME */
3726 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3727 BIT(NL80211_STA_FLAG_WME)))
3728 return -EINVAL;
3729 /* force (at least) rates when authorizing */
3730 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3731 !params->supported_rates)
3732 return -EINVAL;
3733 break;
3734 case CFG80211_STA_TDLS_PEER_ACTIVE:
3735 /* reject any changes */
3736 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003737 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003738 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3739 return -EINVAL;
3740 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003741 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003742 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3743 return -EINVAL;
3744 break;
3745 }
3746
3747 return 0;
3748}
3749EXPORT_SYMBOL(cfg80211_check_station_change);
3750
Johannes Berg5727ef12007-12-19 02:03:34 +01003751/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003752 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003753 */
Johannes Berg80b99892011-11-18 16:23:01 +01003754static struct net_device *get_vlan(struct genl_info *info,
3755 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003756{
Johannes Berg463d0182009-07-14 00:33:35 +02003757 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003758 struct net_device *v;
3759 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003760
Johannes Berg80b99892011-11-18 16:23:01 +01003761 if (!vlanattr)
3762 return NULL;
3763
3764 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3765 if (!v)
3766 return ERR_PTR(-ENODEV);
3767
3768 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3769 ret = -EINVAL;
3770 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003771 }
Johannes Berg80b99892011-11-18 16:23:01 +01003772
Johannes Berg77ee7c82013-02-15 00:48:33 +01003773 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3774 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3775 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3776 ret = -EINVAL;
3777 goto error;
3778 }
3779
Johannes Berg80b99892011-11-18 16:23:01 +01003780 if (!netif_running(v)) {
3781 ret = -ENETDOWN;
3782 goto error;
3783 }
3784
3785 return v;
3786 error:
3787 dev_put(v);
3788 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003789}
3790
Jouni Malinendf881292013-02-14 21:10:54 +02003791static struct nla_policy
3792nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3793 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3794 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3795};
3796
Johannes Bergff276692013-02-15 00:09:01 +01003797static int nl80211_parse_sta_wme(struct genl_info *info,
3798 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003799{
Jouni Malinendf881292013-02-14 21:10:54 +02003800 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3801 struct nlattr *nla;
3802 int err;
3803
Jouni Malinendf881292013-02-14 21:10:54 +02003804 /* parse WME attributes if present */
3805 if (!info->attrs[NL80211_ATTR_STA_WME])
3806 return 0;
3807
3808 nla = info->attrs[NL80211_ATTR_STA_WME];
3809 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3810 nl80211_sta_wme_policy);
3811 if (err)
3812 return err;
3813
3814 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3815 params->uapsd_queues = nla_get_u8(
3816 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3817 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3818 return -EINVAL;
3819
3820 if (tb[NL80211_STA_WME_MAX_SP])
3821 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3822
3823 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3824 return -EINVAL;
3825
3826 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3827
3828 return 0;
3829}
3830
Johannes Bergff276692013-02-15 00:09:01 +01003831static int nl80211_set_station_tdls(struct genl_info *info,
3832 struct station_parameters *params)
3833{
3834 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003835 if (info->attrs[NL80211_ATTR_PEER_AID])
3836 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003837 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3838 params->ht_capa =
3839 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3840 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3841 params->vht_capa =
3842 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3843
3844 return nl80211_parse_sta_wme(info, params);
3845}
3846
Johannes Berg5727ef12007-12-19 02:03:34 +01003847static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3848{
Johannes Berg4c476992010-10-04 21:36:35 +02003849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003850 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003851 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003852 u8 *mac_addr;
3853 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003854
3855 memset(&params, 0, sizeof(params));
3856
3857 params.listen_interval = -1;
3858
Johannes Berg77ee7c82013-02-15 00:48:33 +01003859 if (!rdev->ops->change_station)
3860 return -EOPNOTSUPP;
3861
Johannes Berg5727ef12007-12-19 02:03:34 +01003862 if (info->attrs[NL80211_ATTR_STA_AID])
3863 return -EINVAL;
3864
3865 if (!info->attrs[NL80211_ATTR_MAC])
3866 return -EINVAL;
3867
3868 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3869
3870 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3871 params.supported_rates =
3872 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3873 params.supported_rates_len =
3874 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3875 }
3876
Jouni Malinen9d62a982013-02-14 21:10:13 +02003877 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3878 params.capability =
3879 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3880 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3881 }
3882
3883 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3884 params.ext_capab =
3885 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3886 params.ext_capab_len =
3887 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3888 }
3889
Jouni Malinendf881292013-02-14 21:10:54 +02003890 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003891 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003892
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003893 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003894 return -EINVAL;
3895
Johannes Bergf8bacc22013-02-14 23:27:01 +01003896 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003897 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003898 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3899 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3900 return -EINVAL;
3901 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003902
Johannes Bergf8bacc22013-02-14 23:27:01 +01003903 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003904 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003905 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3906 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3907 return -EINVAL;
3908 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3909 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003910
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003911 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3912 enum nl80211_mesh_power_mode pm = nla_get_u32(
3913 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3914
3915 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3916 pm > NL80211_MESH_POWER_MAX)
3917 return -EINVAL;
3918
3919 params.local_pm = pm;
3920 }
3921
Johannes Berg77ee7c82013-02-15 00:48:33 +01003922 /* Include parameters for TDLS peer (will check later) */
3923 err = nl80211_set_station_tdls(info, &params);
3924 if (err)
3925 return err;
3926
3927 params.vlan = get_vlan(info, rdev);
3928 if (IS_ERR(params.vlan))
3929 return PTR_ERR(params.vlan);
3930
Johannes Berga97f4422009-06-18 17:23:43 +02003931 switch (dev->ieee80211_ptr->iftype) {
3932 case NL80211_IFTYPE_AP:
3933 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003934 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003935 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003936 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003937 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003938 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003939 break;
3940 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003941 err = -EOPNOTSUPP;
3942 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003943 }
3944
Johannes Berg77ee7c82013-02-15 00:48:33 +01003945 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003946 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003947
Johannes Berg77ee7c82013-02-15 00:48:33 +01003948 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003949 if (params.vlan)
3950 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003951
Johannes Berg5727ef12007-12-19 02:03:34 +01003952 return err;
3953}
3954
3955static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3956{
Johannes Berg4c476992010-10-04 21:36:35 +02003957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003958 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003959 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003960 struct station_parameters params;
3961 u8 *mac_addr = NULL;
3962
3963 memset(&params, 0, sizeof(params));
3964
Johannes Berg984c3112013-02-14 23:43:25 +01003965 if (!rdev->ops->add_station)
3966 return -EOPNOTSUPP;
3967
Johannes Berg5727ef12007-12-19 02:03:34 +01003968 if (!info->attrs[NL80211_ATTR_MAC])
3969 return -EINVAL;
3970
Johannes Berg5727ef12007-12-19 02:03:34 +01003971 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3972 return -EINVAL;
3973
3974 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3975 return -EINVAL;
3976
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003977 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3978 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003979 return -EINVAL;
3980
Johannes Berg5727ef12007-12-19 02:03:34 +01003981 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3982 params.supported_rates =
3983 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3984 params.supported_rates_len =
3985 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3986 params.listen_interval =
3987 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003988
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003989 if (info->attrs[NL80211_ATTR_STA_AID])
3990 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3991 else
3992 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003993 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3994 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003995
Jouni Malinen9d62a982013-02-14 21:10:13 +02003996 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3997 params.capability =
3998 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3999 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4000 }
4001
4002 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4003 params.ext_capab =
4004 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4005 params.ext_capab_len =
4006 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4007 }
4008
Jouni Malinen36aedc92008-08-25 11:58:58 +03004009 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4010 params.ht_capa =
4011 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004012
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4014 params.vht_capa =
4015 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4016
Johannes Bergf8bacc22013-02-14 23:27:01 +01004017 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004018 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004019 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4020 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4021 return -EINVAL;
4022 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004023
Johannes Bergff276692013-02-15 00:09:01 +01004024 err = nl80211_parse_sta_wme(info, &params);
4025 if (err)
4026 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004027
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004028 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004029 return -EINVAL;
4030
Johannes Berg77ee7c82013-02-15 00:48:33 +01004031 /* When you run into this, adjust the code below for the new flag */
4032 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4033
Johannes Bergbdd90d52011-12-14 12:20:27 +01004034 switch (dev->ieee80211_ptr->iftype) {
4035 case NL80211_IFTYPE_AP:
4036 case NL80211_IFTYPE_AP_VLAN:
4037 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004038 /* ignore WME attributes if iface/sta is not capable */
4039 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4040 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4041 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004042
Johannes Bergbdd90d52011-12-14 12:20:27 +01004043 /* TDLS peers cannot be added */
4044 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004045 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004046 /* but don't bother the driver with it */
4047 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004048
Johannes Bergd582cff2012-10-26 17:53:44 +02004049 /* allow authenticated/associated only if driver handles it */
4050 if (!(rdev->wiphy.features &
4051 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4052 params.sta_flags_mask &
4053 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4054 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4055 return -EINVAL;
4056
Johannes Bergbdd90d52011-12-14 12:20:27 +01004057 /* must be last in here for error handling */
4058 params.vlan = get_vlan(info, rdev);
4059 if (IS_ERR(params.vlan))
4060 return PTR_ERR(params.vlan);
4061 break;
4062 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004063 /* ignore uAPSD data */
4064 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4065
Johannes Bergd582cff2012-10-26 17:53:44 +02004066 /* associated is disallowed */
4067 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4068 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004069 /* TDLS peers cannot be added */
4070 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004071 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004072 break;
4073 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004074 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004075 /* ignore uAPSD data */
4076 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4077
Johannes Berg77ee7c82013-02-15 00:48:33 +01004078 /* these are disallowed */
4079 if (params.sta_flags_mask &
4080 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4081 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004082 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004083 /* Only TDLS peers can be added */
4084 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4085 return -EINVAL;
4086 /* Can only add if TDLS ... */
4087 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4088 return -EOPNOTSUPP;
4089 /* ... with external setup is supported */
4090 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4091 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004092 /*
4093 * Older wpa_supplicant versions always mark the TDLS peer
4094 * as authorized, but it shouldn't yet be.
4095 */
4096 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004097 break;
4098 default:
4099 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004100 }
4101
Johannes Bergbdd90d52011-12-14 12:20:27 +01004102 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004103
Hila Gonene35e4d22012-06-27 17:19:42 +03004104 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004105
Johannes Berg5727ef12007-12-19 02:03:34 +01004106 if (params.vlan)
4107 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004108 return err;
4109}
4110
4111static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4112{
Johannes Berg4c476992010-10-04 21:36:35 +02004113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4114 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004115 u8 *mac_addr = NULL;
4116
4117 if (info->attrs[NL80211_ATTR_MAC])
4118 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4119
Johannes Berge80cf852009-05-11 14:43:13 +02004120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004121 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004122 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004123 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4124 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004125
Johannes Berg4c476992010-10-04 21:36:35 +02004126 if (!rdev->ops->del_station)
4127 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004128
Hila Gonene35e4d22012-06-27 17:19:42 +03004129 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004130}
4131
Eric W. Biederman15e47302012-09-07 20:12:54 +00004132static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004133 int flags, struct net_device *dev,
4134 u8 *dst, u8 *next_hop,
4135 struct mpath_info *pinfo)
4136{
4137 void *hdr;
4138 struct nlattr *pinfoattr;
4139
Eric W. Biederman15e47302012-09-07 20:12:54 +00004140 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004141 if (!hdr)
4142 return -1;
4143
David S. Miller9360ffd2012-03-29 04:41:26 -04004144 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4145 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4146 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4147 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4148 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004149
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004150 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4151 if (!pinfoattr)
4152 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004153 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4154 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4155 pinfo->frame_qlen))
4156 goto nla_put_failure;
4157 if (((pinfo->filled & MPATH_INFO_SN) &&
4158 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4159 ((pinfo->filled & MPATH_INFO_METRIC) &&
4160 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4161 pinfo->metric)) ||
4162 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4163 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4164 pinfo->exptime)) ||
4165 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4166 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4167 pinfo->flags)) ||
4168 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4169 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4170 pinfo->discovery_timeout)) ||
4171 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4172 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4173 pinfo->discovery_retries)))
4174 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004175
4176 nla_nest_end(msg, pinfoattr);
4177
4178 return genlmsg_end(msg, hdr);
4179
4180 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004181 genlmsg_cancel(msg, hdr);
4182 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004183}
4184
4185static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004186 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004187{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004188 struct mpath_info pinfo;
4189 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004190 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004191 u8 dst[ETH_ALEN];
4192 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004193 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004194 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004195
Johannes Berg97990a02013-04-19 01:02:55 +02004196 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004197 if (err)
4198 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004199
4200 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004201 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004202 goto out_err;
4203 }
4204
Johannes Berg97990a02013-04-19 01:02:55 +02004205 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004206 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004207 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004208 }
4209
Johannes Bergbba95fe2008-07-29 13:22:51 +02004210 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004211 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4212 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004213 if (err == -ENOENT)
4214 break;
4215 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004216 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004217
Eric W. Biederman15e47302012-09-07 20:12:54 +00004218 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004219 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004220 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004221 &pinfo) < 0)
4222 goto out;
4223
4224 path_idx++;
4225 }
4226
4227
4228 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004229 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004230 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004231 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004232 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004233 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004234}
4235
4236static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4237{
Johannes Berg4c476992010-10-04 21:36:35 +02004238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004239 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004240 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004241 struct mpath_info pinfo;
4242 struct sk_buff *msg;
4243 u8 *dst = NULL;
4244 u8 next_hop[ETH_ALEN];
4245
4246 memset(&pinfo, 0, sizeof(pinfo));
4247
4248 if (!info->attrs[NL80211_ATTR_MAC])
4249 return -EINVAL;
4250
4251 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4252
Johannes Berg4c476992010-10-04 21:36:35 +02004253 if (!rdev->ops->get_mpath)
4254 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004255
Johannes Berg4c476992010-10-04 21:36:35 +02004256 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4257 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004258
Hila Gonene35e4d22012-06-27 17:19:42 +03004259 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004261 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004264 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004265 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004266
Eric W. Biederman15e47302012-09-07 20:12:54 +00004267 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004268 dev, dst, next_hop, &pinfo) < 0) {
4269 nlmsg_free(msg);
4270 return -ENOBUFS;
4271 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004272
Johannes Berg4c476992010-10-04 21:36:35 +02004273 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004274}
4275
4276static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4277{
Johannes Berg4c476992010-10-04 21:36:35 +02004278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4279 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004280 u8 *dst = NULL;
4281 u8 *next_hop = NULL;
4282
4283 if (!info->attrs[NL80211_ATTR_MAC])
4284 return -EINVAL;
4285
4286 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4287 return -EINVAL;
4288
4289 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4290 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4291
Johannes Berg4c476992010-10-04 21:36:35 +02004292 if (!rdev->ops->change_mpath)
4293 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004294
Johannes Berg4c476992010-10-04 21:36:35 +02004295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4296 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004297
Hila Gonene35e4d22012-06-27 17:19:42 +03004298 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004299}
Johannes Berg4c476992010-10-04 21:36:35 +02004300
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004301static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4302{
Johannes Berg4c476992010-10-04 21:36:35 +02004303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4304 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004305 u8 *dst = NULL;
4306 u8 *next_hop = NULL;
4307
4308 if (!info->attrs[NL80211_ATTR_MAC])
4309 return -EINVAL;
4310
4311 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4312 return -EINVAL;
4313
4314 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4315 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4316
Johannes Berg4c476992010-10-04 21:36:35 +02004317 if (!rdev->ops->add_mpath)
4318 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004319
Johannes Berg4c476992010-10-04 21:36:35 +02004320 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4321 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004322
Hila Gonene35e4d22012-06-27 17:19:42 +03004323 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004324}
4325
4326static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4327{
Johannes Berg4c476992010-10-04 21:36:35 +02004328 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4329 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004330 u8 *dst = NULL;
4331
4332 if (info->attrs[NL80211_ATTR_MAC])
4333 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4334
Johannes Berg4c476992010-10-04 21:36:35 +02004335 if (!rdev->ops->del_mpath)
4336 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004337
Hila Gonene35e4d22012-06-27 17:19:42 +03004338 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004339}
4340
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004341static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4342{
Johannes Berg4c476992010-10-04 21:36:35 +02004343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4344 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004345 struct bss_parameters params;
4346
4347 memset(&params, 0, sizeof(params));
4348 /* default to not changing parameters */
4349 params.use_cts_prot = -1;
4350 params.use_short_preamble = -1;
4351 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004352 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004353 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004354 params.p2p_ctwindow = -1;
4355 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004356
4357 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4358 params.use_cts_prot =
4359 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4360 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4361 params.use_short_preamble =
4362 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4363 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4364 params.use_short_slot_time =
4365 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004366 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4367 params.basic_rates =
4368 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4369 params.basic_rates_len =
4370 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4371 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004372 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4373 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004374 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4375 params.ht_opmode =
4376 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004377
Johannes Berg53cabad2012-11-14 15:17:28 +01004378 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4380 return -EINVAL;
4381 params.p2p_ctwindow =
4382 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4383 if (params.p2p_ctwindow < 0)
4384 return -EINVAL;
4385 if (params.p2p_ctwindow != 0 &&
4386 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4387 return -EINVAL;
4388 }
4389
4390 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4391 u8 tmp;
4392
4393 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4394 return -EINVAL;
4395 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4396 if (tmp > 1)
4397 return -EINVAL;
4398 params.p2p_opp_ps = tmp;
4399 if (params.p2p_opp_ps &&
4400 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4401 return -EINVAL;
4402 }
4403
Johannes Berg4c476992010-10-04 21:36:35 +02004404 if (!rdev->ops->change_bss)
4405 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004406
Johannes Berg074ac8d2010-09-16 14:58:22 +02004407 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004408 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4409 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004410
Hila Gonene35e4d22012-06-27 17:19:42 +03004411 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004412}
4413
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004414static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004415 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4416 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4417 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4418 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4419 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4420 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4421};
4422
4423static int parse_reg_rule(struct nlattr *tb[],
4424 struct ieee80211_reg_rule *reg_rule)
4425{
4426 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4427 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4428
4429 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4430 return -EINVAL;
4431 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4432 return -EINVAL;
4433 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4434 return -EINVAL;
4435 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4436 return -EINVAL;
4437 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4438 return -EINVAL;
4439
4440 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4441
4442 freq_range->start_freq_khz =
4443 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4444 freq_range->end_freq_khz =
4445 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4446 freq_range->max_bandwidth_khz =
4447 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4448
4449 power_rule->max_eirp =
4450 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4451
4452 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4453 power_rule->max_antenna_gain =
4454 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4455
4456 return 0;
4457}
4458
4459static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4460{
4461 int r;
4462 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004463 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004464
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004465 /*
4466 * You should only get this when cfg80211 hasn't yet initialized
4467 * completely when built-in to the kernel right between the time
4468 * window between nl80211_init() and regulatory_init(), if that is
4469 * even possible.
4470 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004471 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004472 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004473
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004474 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4475 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004476
4477 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4478
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004479 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4480 user_reg_hint_type =
4481 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4482 else
4483 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4484
4485 switch (user_reg_hint_type) {
4486 case NL80211_USER_REG_HINT_USER:
4487 case NL80211_USER_REG_HINT_CELL_BASE:
4488 break;
4489 default:
4490 return -EINVAL;
4491 }
4492
4493 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004494
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004495 return r;
4496}
4497
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004498static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004499 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004500{
Johannes Berg4c476992010-10-04 21:36:35 +02004501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004502 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004503 struct wireless_dev *wdev = dev->ieee80211_ptr;
4504 struct mesh_config cur_params;
4505 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004506 void *hdr;
4507 struct nlattr *pinfoattr;
4508 struct sk_buff *msg;
4509
Johannes Berg29cbe682010-12-03 09:20:44 +01004510 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4511 return -EOPNOTSUPP;
4512
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004513 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004514 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004515
Johannes Berg29cbe682010-12-03 09:20:44 +01004516 wdev_lock(wdev);
4517 /* If not connected, get default parameters */
4518 if (!wdev->mesh_id_len)
4519 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4520 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004521 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004522 wdev_unlock(wdev);
4523
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004524 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004525 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004526
4527 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004529 if (!msg)
4530 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004531 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004532 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004533 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004534 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004535 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004536 if (!pinfoattr)
4537 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004538 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4539 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4540 cur_params.dot11MeshRetryTimeout) ||
4541 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4542 cur_params.dot11MeshConfirmTimeout) ||
4543 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4544 cur_params.dot11MeshHoldingTimeout) ||
4545 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4546 cur_params.dot11MeshMaxPeerLinks) ||
4547 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4548 cur_params.dot11MeshMaxRetries) ||
4549 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4550 cur_params.dot11MeshTTL) ||
4551 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4552 cur_params.element_ttl) ||
4553 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4554 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004555 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4556 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004557 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4558 cur_params.dot11MeshHWMPmaxPREQretries) ||
4559 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4560 cur_params.path_refresh_time) ||
4561 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4562 cur_params.min_discovery_timeout) ||
4563 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4564 cur_params.dot11MeshHWMPactivePathTimeout) ||
4565 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4566 cur_params.dot11MeshHWMPpreqMinInterval) ||
4567 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4568 cur_params.dot11MeshHWMPperrMinInterval) ||
4569 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4570 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4571 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4572 cur_params.dot11MeshHWMPRootMode) ||
4573 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4574 cur_params.dot11MeshHWMPRannInterval) ||
4575 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4576 cur_params.dot11MeshGateAnnouncementProtocol) ||
4577 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4578 cur_params.dot11MeshForwarding) ||
4579 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004580 cur_params.rssi_threshold) ||
4581 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004582 cur_params.ht_opmode) ||
4583 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4584 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4585 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004586 cur_params.dot11MeshHWMProotInterval) ||
4587 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004588 cur_params.dot11MeshHWMPconfirmationInterval) ||
4589 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4590 cur_params.power_mode) ||
4591 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4592 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004593 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 nla_nest_end(msg, pinfoattr);
4595 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004596 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004597
Johannes Berg3b858752009-03-12 09:55:09 +01004598 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004599 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004600 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004601 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004602 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004603}
4604
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004605static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004606 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4607 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4608 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4609 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4610 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4611 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004612 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004613 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004614 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004615 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4616 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4617 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4618 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4619 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004620 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004621 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004622 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004623 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004624 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004625 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004626 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4627 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004628 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4629 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004630 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004631 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4632 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004633};
4634
Javier Cardonac80d5452010-12-16 17:37:49 -08004635static const struct nla_policy
4636 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004637 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004638 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4639 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004640 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004641 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004642 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004643 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004644 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004645 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004646};
4647
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004648static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004649 struct mesh_config *cfg,
4650 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004651{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004652 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004653 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004654
Marco Porschea54fba2013-01-07 16:04:48 +01004655#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4656do { \
4657 if (tb[attr]) { \
4658 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4659 return -EINVAL; \
4660 cfg->param = fn(tb[attr]); \
4661 mask |= (1 << (attr - 1)); \
4662 } \
4663} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004664
4665
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004666 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004667 return -EINVAL;
4668 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004669 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004670 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004671 return -EINVAL;
4672
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004673 /* This makes sure that there aren't more than 32 mesh config
4674 * parameters (otherwise our bitfield scheme would not work.) */
4675 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4676
4677 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004679 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4680 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4683 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4686 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004688 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4689 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004691 mask, NL80211_MESHCONF_MAX_RETRIES,
4692 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004693 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004694 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004696 mask, NL80211_MESHCONF_ELEMENT_TTL,
4697 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004698 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004699 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4700 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4702 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004703 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4704 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004706 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4707 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004709 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4710 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004712 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4713 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4715 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004716 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4717 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004719 1, 65535, mask,
4720 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004721 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004722 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004723 1, 65535, mask,
4724 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004725 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004726 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004727 dot11MeshHWMPnetDiameterTraversalTime,
4728 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004729 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4730 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4732 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4733 nla_get_u8);
4734 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4735 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004736 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004737 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004738 dot11MeshGateAnnouncementProtocol, 0, 1,
4739 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004740 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004742 mask, NL80211_MESHCONF_FORWARDING,
4743 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004744 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004745 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4746 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004747 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004748 mask, NL80211_MESHCONF_HT_OPMODE,
4749 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004750 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004751 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004752 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4753 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004755 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4756 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004757 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004758 dot11MeshHWMPconfirmationInterval,
4759 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004760 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4761 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004762 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4763 NL80211_MESH_POWER_ACTIVE,
4764 NL80211_MESH_POWER_MAX,
4765 mask, NL80211_MESHCONF_POWER_MODE,
4766 nla_get_u32);
4767 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4768 0, 65535, mask,
4769 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004770 if (mask_out)
4771 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004772
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004773 return 0;
4774
4775#undef FILL_IN_MESH_PARAM_IF_SET
4776}
4777
Javier Cardonac80d5452010-12-16 17:37:49 -08004778static int nl80211_parse_mesh_setup(struct genl_info *info,
4779 struct mesh_setup *setup)
4780{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004782 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4783
4784 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4785 return -EINVAL;
4786 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4787 info->attrs[NL80211_ATTR_MESH_SETUP],
4788 nl80211_mesh_setup_params_policy))
4789 return -EINVAL;
4790
Javier Cardonad299a1f2012-03-31 11:31:33 -07004791 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4792 setup->sync_method =
4793 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4794 IEEE80211_SYNC_METHOD_VENDOR :
4795 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4796
Javier Cardonac80d5452010-12-16 17:37:49 -08004797 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4798 setup->path_sel_proto =
4799 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4800 IEEE80211_PATH_PROTOCOL_VENDOR :
4801 IEEE80211_PATH_PROTOCOL_HWMP;
4802
4803 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4804 setup->path_metric =
4805 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4806 IEEE80211_PATH_METRIC_VENDOR :
4807 IEEE80211_PATH_METRIC_AIRTIME;
4808
Javier Cardona581a8b02011-04-07 15:08:27 -07004809
4810 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004811 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004812 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004813 if (!is_valid_ie_attr(ieattr))
4814 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004815 setup->ie = nla_data(ieattr);
4816 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004817 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004818 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4819 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4820 return -EINVAL;
4821 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004822 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4823 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004824 if (setup->is_secure)
4825 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004826
Colleen Twitty6e16d902013-05-08 11:45:59 -07004827 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4828 if (!setup->user_mpm)
4829 return -EINVAL;
4830 setup->auth_id =
4831 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4832 }
4833
Javier Cardonac80d5452010-12-16 17:37:49 -08004834 return 0;
4835}
4836
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004837static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004838 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004839{
4840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4841 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004842 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004843 struct mesh_config cfg;
4844 u32 mask;
4845 int err;
4846
Johannes Berg29cbe682010-12-03 09:20:44 +01004847 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4848 return -EOPNOTSUPP;
4849
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004850 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004851 return -EOPNOTSUPP;
4852
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004853 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004854 if (err)
4855 return err;
4856
Johannes Berg29cbe682010-12-03 09:20:44 +01004857 wdev_lock(wdev);
4858 if (!wdev->mesh_id_len)
4859 err = -ENOLINK;
4860
4861 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004862 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004863
4864 wdev_unlock(wdev);
4865
4866 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004867}
4868
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004869static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4870{
Johannes Berg458f4f92012-12-06 15:47:38 +01004871 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004872 struct sk_buff *msg;
4873 void *hdr = NULL;
4874 struct nlattr *nl_reg_rules;
4875 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004876
4877 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004878 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004879
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004880 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004881 if (!msg)
4882 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004883
Eric W. Biederman15e47302012-09-07 20:12:54 +00004884 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004885 NL80211_CMD_GET_REG);
4886 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004887 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004888
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004889 if (reg_last_request_cell_base() &&
4890 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4891 NL80211_USER_REG_HINT_CELL_BASE))
4892 goto nla_put_failure;
4893
Johannes Berg458f4f92012-12-06 15:47:38 +01004894 rcu_read_lock();
4895 regdom = rcu_dereference(cfg80211_regdomain);
4896
4897 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4898 (regdom->dfs_region &&
4899 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4900 goto nla_put_failure_rcu;
4901
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004902 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4903 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004904 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004905
Johannes Berg458f4f92012-12-06 15:47:38 +01004906 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004907 struct nlattr *nl_reg_rule;
4908 const struct ieee80211_reg_rule *reg_rule;
4909 const struct ieee80211_freq_range *freq_range;
4910 const struct ieee80211_power_rule *power_rule;
4911
Johannes Berg458f4f92012-12-06 15:47:38 +01004912 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004913 freq_range = &reg_rule->freq_range;
4914 power_rule = &reg_rule->power_rule;
4915
4916 nl_reg_rule = nla_nest_start(msg, i);
4917 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004918 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004919
David S. Miller9360ffd2012-03-29 04:41:26 -04004920 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4921 reg_rule->flags) ||
4922 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4923 freq_range->start_freq_khz) ||
4924 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4925 freq_range->end_freq_khz) ||
4926 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4927 freq_range->max_bandwidth_khz) ||
4928 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4929 power_rule->max_antenna_gain) ||
4930 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4931 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004932 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004933
4934 nla_nest_end(msg, nl_reg_rule);
4935 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004936 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004937
4938 nla_nest_end(msg, nl_reg_rules);
4939
4940 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004941 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004942
Johannes Berg458f4f92012-12-06 15:47:38 +01004943nla_put_failure_rcu:
4944 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004945nla_put_failure:
4946 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004947put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004948 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004949 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004950}
4951
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004952static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4953{
4954 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4955 struct nlattr *nl_reg_rule;
4956 char *alpha2 = NULL;
4957 int rem_reg_rules = 0, r = 0;
4958 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004959 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004960 struct ieee80211_regdomain *rd = NULL;
4961
4962 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4963 return -EINVAL;
4964
4965 if (!info->attrs[NL80211_ATTR_REG_RULES])
4966 return -EINVAL;
4967
4968 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4969
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004970 if (info->attrs[NL80211_ATTR_DFS_REGION])
4971 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4972
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004973 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004974 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004975 num_rules++;
4976 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004977 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004978 }
4979
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004980 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004981 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982
4983 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004984 if (!rd)
4985 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004986
4987 rd->n_reg_rules = num_rules;
4988 rd->alpha2[0] = alpha2[0];
4989 rd->alpha2[1] = alpha2[1];
4990
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004991 /*
4992 * Disable DFS master mode if the DFS region was
4993 * not supported or known on this kernel.
4994 */
4995 if (reg_supported_dfs_region(dfs_region))
4996 rd->dfs_region = dfs_region;
4997
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004998 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004999 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005000 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005001 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5002 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005003 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5004 if (r)
5005 goto bad_reg;
5006
5007 rule_idx++;
5008
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005009 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5010 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005011 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005012 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005013 }
5014
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005015 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005016 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005017 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005018
Johannes Bergd2372b32008-10-24 20:32:20 +02005019 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005020 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005021 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005022}
5023
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005024static int validate_scan_freqs(struct nlattr *freqs)
5025{
5026 struct nlattr *attr1, *attr2;
5027 int n_channels = 0, tmp1, tmp2;
5028
5029 nla_for_each_nested(attr1, freqs, tmp1) {
5030 n_channels++;
5031 /*
5032 * Some hardware has a limited channel list for
5033 * scanning, and it is pretty much nonsensical
5034 * to scan for a channel twice, so disallow that
5035 * and don't require drivers to check that the
5036 * channel list they get isn't longer than what
5037 * they can scan, as long as they can scan all
5038 * the channels they registered at once.
5039 */
5040 nla_for_each_nested(attr2, freqs, tmp2)
5041 if (attr1 != attr2 &&
5042 nla_get_u32(attr1) == nla_get_u32(attr2))
5043 return 0;
5044 }
5045
5046 return n_channels;
5047}
5048
Johannes Berg2a519312009-02-10 21:25:55 +01005049static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5050{
Johannes Berg4c476992010-10-04 21:36:35 +02005051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005052 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005053 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005054 struct nlattr *attr;
5055 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005056 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005057 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005058
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005059 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5060 return -EINVAL;
5061
Johannes Berg79c97e92009-07-07 03:56:12 +02005062 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005063
Johannes Berg4c476992010-10-04 21:36:35 +02005064 if (!rdev->ops->scan)
5065 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005066
Johannes Bergf9f47522013-03-19 15:04:07 +01005067 if (rdev->scan_req) {
5068 err = -EBUSY;
5069 goto unlock;
5070 }
Johannes Berg2a519312009-02-10 21:25:55 +01005071
5072 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005073 n_channels = validate_scan_freqs(
5074 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005075 if (!n_channels) {
5076 err = -EINVAL;
5077 goto unlock;
5078 }
Johannes Berg2a519312009-02-10 21:25:55 +01005079 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005080 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005081 n_channels = 0;
5082
Johannes Berg2a519312009-02-10 21:25:55 +01005083 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5084 if (wiphy->bands[band])
5085 n_channels += wiphy->bands[band]->n_channels;
5086 }
5087
5088 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5089 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5090 n_ssids++;
5091
Johannes Bergf9f47522013-03-19 15:04:07 +01005092 if (n_ssids > wiphy->max_scan_ssids) {
5093 err = -EINVAL;
5094 goto unlock;
5095 }
Johannes Berg2a519312009-02-10 21:25:55 +01005096
Jouni Malinen70692ad2009-02-16 19:39:13 +02005097 if (info->attrs[NL80211_ATTR_IE])
5098 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5099 else
5100 ie_len = 0;
5101
Johannes Bergf9f47522013-03-19 15:04:07 +01005102 if (ie_len > wiphy->max_scan_ie_len) {
5103 err = -EINVAL;
5104 goto unlock;
5105 }
Johannes Berg18a83652009-03-31 12:12:05 +02005106
Johannes Berg2a519312009-02-10 21:25:55 +01005107 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005108 + sizeof(*request->ssids) * n_ssids
5109 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005110 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005111 if (!request) {
5112 err = -ENOMEM;
5113 goto unlock;
5114 }
Johannes Berg2a519312009-02-10 21:25:55 +01005115
Johannes Berg2a519312009-02-10 21:25:55 +01005116 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005117 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005118 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005119 if (ie_len) {
5120 if (request->ssids)
5121 request->ie = (void *)(request->ssids + n_ssids);
5122 else
5123 request->ie = (void *)(request->channels + n_channels);
5124 }
Johannes Berg2a519312009-02-10 21:25:55 +01005125
Johannes Berg584991d2009-11-02 13:32:03 +01005126 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005127 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5128 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005129 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005130 struct ieee80211_channel *chan;
5131
5132 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5133
5134 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005135 err = -EINVAL;
5136 goto out_free;
5137 }
Johannes Berg584991d2009-11-02 13:32:03 +01005138
5139 /* ignore disabled channels */
5140 if (chan->flags & IEEE80211_CHAN_DISABLED)
5141 continue;
5142
5143 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005144 i++;
5145 }
5146 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005147 enum ieee80211_band band;
5148
Johannes Berg2a519312009-02-10 21:25:55 +01005149 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005150 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5151 int j;
5152 if (!wiphy->bands[band])
5153 continue;
5154 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005155 struct ieee80211_channel *chan;
5156
5157 chan = &wiphy->bands[band]->channels[j];
5158
5159 if (chan->flags & IEEE80211_CHAN_DISABLED)
5160 continue;
5161
5162 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005163 i++;
5164 }
5165 }
5166 }
5167
Johannes Berg584991d2009-11-02 13:32:03 +01005168 if (!i) {
5169 err = -EINVAL;
5170 goto out_free;
5171 }
5172
5173 request->n_channels = i;
5174
Johannes Berg2a519312009-02-10 21:25:55 +01005175 i = 0;
5176 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5177 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005178 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005179 err = -EINVAL;
5180 goto out_free;
5181 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005182 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005183 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005184 i++;
5185 }
5186 }
5187
Jouni Malinen70692ad2009-02-16 19:39:13 +02005188 if (info->attrs[NL80211_ATTR_IE]) {
5189 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005190 memcpy((void *)request->ie,
5191 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005192 request->ie_len);
5193 }
5194
Johannes Berg34850ab2011-07-18 18:08:35 +02005195 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005196 if (wiphy->bands[i])
5197 request->rates[i] =
5198 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005199
5200 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5201 nla_for_each_nested(attr,
5202 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5203 tmp) {
5204 enum ieee80211_band band = nla_type(attr);
5205
Dan Carpenter84404622011-07-29 11:52:18 +03005206 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005207 err = -EINVAL;
5208 goto out_free;
5209 }
5210 err = ieee80211_get_ratemask(wiphy->bands[band],
5211 nla_data(attr),
5212 nla_len(attr),
5213 &request->rates[band]);
5214 if (err)
5215 goto out_free;
5216 }
5217 }
5218
Sam Leffler46856bb2012-10-11 21:03:32 -07005219 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005220 request->flags = nla_get_u32(
5221 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005222 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5223 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5224 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5225 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005226 err = -EOPNOTSUPP;
5227 goto out_free;
5228 }
5229 }
Sam Lefflered4737712012-10-11 21:03:31 -07005230
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305231 request->no_cck =
5232 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5233
Johannes Bergfd014282012-06-18 19:17:03 +02005234 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005235 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005236 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005237
Johannes Berg79c97e92009-07-07 03:56:12 +02005238 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005239 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005240
Johannes Berg463d0182009-07-14 00:33:35 +02005241 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005242 nl80211_send_scan_start(rdev, wdev);
5243 if (wdev->netdev)
5244 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005245 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005246 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005247 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005248 kfree(request);
5249 }
Johannes Berg3b858752009-03-12 09:55:09 +01005250
Johannes Bergf9f47522013-03-19 15:04:07 +01005251 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005252 return err;
5253}
5254
Luciano Coelho807f8a82011-05-11 17:09:35 +03005255static int nl80211_start_sched_scan(struct sk_buff *skb,
5256 struct genl_info *info)
5257{
5258 struct cfg80211_sched_scan_request *request;
5259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5260 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005261 struct nlattr *attr;
5262 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005263 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005264 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005265 enum ieee80211_band band;
5266 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005267 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005268
5269 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5270 !rdev->ops->sched_scan_start)
5271 return -EOPNOTSUPP;
5272
5273 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5274 return -EINVAL;
5275
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005276 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5277 return -EINVAL;
5278
5279 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5280 if (interval == 0)
5281 return -EINVAL;
5282
Luciano Coelho807f8a82011-05-11 17:09:35 +03005283 wiphy = &rdev->wiphy;
5284
5285 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5286 n_channels = validate_scan_freqs(
5287 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5288 if (!n_channels)
5289 return -EINVAL;
5290 } else {
5291 n_channels = 0;
5292
5293 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5294 if (wiphy->bands[band])
5295 n_channels += wiphy->bands[band]->n_channels;
5296 }
5297
5298 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5299 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5300 tmp)
5301 n_ssids++;
5302
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005303 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005304 return -EINVAL;
5305
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005306 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5307 nla_for_each_nested(attr,
5308 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5309 tmp)
5310 n_match_sets++;
5311
5312 if (n_match_sets > wiphy->max_match_sets)
5313 return -EINVAL;
5314
Luciano Coelho807f8a82011-05-11 17:09:35 +03005315 if (info->attrs[NL80211_ATTR_IE])
5316 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5317 else
5318 ie_len = 0;
5319
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005320 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005321 return -EINVAL;
5322
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005323 if (rdev->sched_scan_req) {
5324 err = -EINPROGRESS;
5325 goto out;
5326 }
5327
Luciano Coelho807f8a82011-05-11 17:09:35 +03005328 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005329 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005330 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005331 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005332 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005333 if (!request) {
5334 err = -ENOMEM;
5335 goto out;
5336 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005337
5338 if (n_ssids)
5339 request->ssids = (void *)&request->channels[n_channels];
5340 request->n_ssids = n_ssids;
5341 if (ie_len) {
5342 if (request->ssids)
5343 request->ie = (void *)(request->ssids + n_ssids);
5344 else
5345 request->ie = (void *)(request->channels + n_channels);
5346 }
5347
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005348 if (n_match_sets) {
5349 if (request->ie)
5350 request->match_sets = (void *)(request->ie + ie_len);
5351 else if (request->ssids)
5352 request->match_sets =
5353 (void *)(request->ssids + n_ssids);
5354 else
5355 request->match_sets =
5356 (void *)(request->channels + n_channels);
5357 }
5358 request->n_match_sets = n_match_sets;
5359
Luciano Coelho807f8a82011-05-11 17:09:35 +03005360 i = 0;
5361 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5362 /* user specified, bail out if channel not found */
5363 nla_for_each_nested(attr,
5364 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5365 tmp) {
5366 struct ieee80211_channel *chan;
5367
5368 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5369
5370 if (!chan) {
5371 err = -EINVAL;
5372 goto out_free;
5373 }
5374
5375 /* ignore disabled channels */
5376 if (chan->flags & IEEE80211_CHAN_DISABLED)
5377 continue;
5378
5379 request->channels[i] = chan;
5380 i++;
5381 }
5382 } else {
5383 /* all channels */
5384 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5385 int j;
5386 if (!wiphy->bands[band])
5387 continue;
5388 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5389 struct ieee80211_channel *chan;
5390
5391 chan = &wiphy->bands[band]->channels[j];
5392
5393 if (chan->flags & IEEE80211_CHAN_DISABLED)
5394 continue;
5395
5396 request->channels[i] = chan;
5397 i++;
5398 }
5399 }
5400 }
5401
5402 if (!i) {
5403 err = -EINVAL;
5404 goto out_free;
5405 }
5406
5407 request->n_channels = i;
5408
5409 i = 0;
5410 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5411 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5412 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005413 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005414 err = -EINVAL;
5415 goto out_free;
5416 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005417 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005418 memcpy(request->ssids[i].ssid, nla_data(attr),
5419 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005420 i++;
5421 }
5422 }
5423
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005424 i = 0;
5425 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5426 nla_for_each_nested(attr,
5427 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5428 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005429 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005430
5431 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5432 nla_data(attr), nla_len(attr),
5433 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005434 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005435 if (ssid) {
5436 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5437 err = -EINVAL;
5438 goto out_free;
5439 }
5440 memcpy(request->match_sets[i].ssid.ssid,
5441 nla_data(ssid), nla_len(ssid));
5442 request->match_sets[i].ssid.ssid_len =
5443 nla_len(ssid);
5444 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005445 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5446 if (rssi)
5447 request->rssi_thold = nla_get_u32(rssi);
5448 else
5449 request->rssi_thold =
5450 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005451 i++;
5452 }
5453 }
5454
Luciano Coelho807f8a82011-05-11 17:09:35 +03005455 if (info->attrs[NL80211_ATTR_IE]) {
5456 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5457 memcpy((void *)request->ie,
5458 nla_data(info->attrs[NL80211_ATTR_IE]),
5459 request->ie_len);
5460 }
5461
Sam Leffler46856bb2012-10-11 21:03:32 -07005462 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005463 request->flags = nla_get_u32(
5464 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005465 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5466 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5467 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5468 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005469 err = -EOPNOTSUPP;
5470 goto out_free;
5471 }
5472 }
Sam Lefflered4737712012-10-11 21:03:31 -07005473
Luciano Coelho807f8a82011-05-11 17:09:35 +03005474 request->dev = dev;
5475 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005476 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005477 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005478
Hila Gonene35e4d22012-06-27 17:19:42 +03005479 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005480 if (!err) {
5481 rdev->sched_scan_req = request;
5482 nl80211_send_sched_scan(rdev, dev,
5483 NL80211_CMD_START_SCHED_SCAN);
5484 goto out;
5485 }
5486
5487out_free:
5488 kfree(request);
5489out:
5490 return err;
5491}
5492
5493static int nl80211_stop_sched_scan(struct sk_buff *skb,
5494 struct genl_info *info)
5495{
5496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5497
5498 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5499 !rdev->ops->sched_scan_stop)
5500 return -EOPNOTSUPP;
5501
Johannes Berg5fe231e2013-05-08 21:45:15 +02005502 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005503}
5504
Simon Wunderlich04f39042013-02-08 18:16:19 +01005505static int nl80211_start_radar_detection(struct sk_buff *skb,
5506 struct genl_info *info)
5507{
5508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5509 struct net_device *dev = info->user_ptr[1];
5510 struct wireless_dev *wdev = dev->ieee80211_ptr;
5511 struct cfg80211_chan_def chandef;
5512 int err;
5513
5514 err = nl80211_parse_chandef(rdev, info, &chandef);
5515 if (err)
5516 return err;
5517
5518 if (wdev->cac_started)
5519 return -EBUSY;
5520
5521 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5522 if (err < 0)
5523 return err;
5524
5525 if (err == 0)
5526 return -EINVAL;
5527
5528 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5529 return -EINVAL;
5530
5531 if (!rdev->ops->start_radar_detection)
5532 return -EOPNOTSUPP;
5533
Simon Wunderlich04f39042013-02-08 18:16:19 +01005534 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5535 chandef.chan, CHAN_MODE_SHARED,
5536 BIT(chandef.width));
5537 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005538 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005539
5540 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5541 if (!err) {
5542 wdev->channel = chandef.chan;
5543 wdev->cac_started = true;
5544 wdev->cac_start_time = jiffies;
5545 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005546 return err;
5547}
5548
Johannes Berg9720bb32011-06-21 09:45:33 +02005549static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5550 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005551 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005552 struct wireless_dev *wdev,
5553 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005554{
Johannes Berg48ab9052009-07-10 18:42:31 +02005555 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005556 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005557 void *hdr;
5558 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005559 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005560
5561 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005562
Eric W. Biederman15e47302012-09-07 20:12:54 +00005563 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005564 NL80211_CMD_NEW_SCAN_RESULTS);
5565 if (!hdr)
5566 return -1;
5567
Johannes Berg9720bb32011-06-21 09:45:33 +02005568 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5569
Johannes Berg97990a02013-04-19 01:02:55 +02005570 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5571 goto nla_put_failure;
5572 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005573 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5574 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005575 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5576 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005577
5578 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5579 if (!bss)
5580 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005581 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005582 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005583 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005584
5585 rcu_read_lock();
5586 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005587 if (ies) {
5588 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5589 goto fail_unlock_rcu;
5590 tsf = true;
5591 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5592 ies->len, ies->data))
5593 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005594 }
5595 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005596 if (ies) {
5597 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5598 goto fail_unlock_rcu;
5599 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5600 ies->len, ies->data))
5601 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005602 }
5603 rcu_read_unlock();
5604
David S. Miller9360ffd2012-03-29 04:41:26 -04005605 if (res->beacon_interval &&
5606 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5607 goto nla_put_failure;
5608 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5609 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5610 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5611 jiffies_to_msecs(jiffies - intbss->ts)))
5612 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005613
Johannes Berg77965c92009-02-18 18:45:06 +01005614 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005615 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005616 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5617 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005618 break;
5619 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005620 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5621 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005622 break;
5623 default:
5624 break;
5625 }
5626
Johannes Berg48ab9052009-07-10 18:42:31 +02005627 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005628 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005629 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005630 if (intbss == wdev->current_bss &&
5631 nla_put_u32(msg, NL80211_BSS_STATUS,
5632 NL80211_BSS_STATUS_ASSOCIATED))
5633 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005634 break;
5635 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005636 if (intbss == wdev->current_bss &&
5637 nla_put_u32(msg, NL80211_BSS_STATUS,
5638 NL80211_BSS_STATUS_IBSS_JOINED))
5639 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005640 break;
5641 default:
5642 break;
5643 }
5644
Johannes Berg2a519312009-02-10 21:25:55 +01005645 nla_nest_end(msg, bss);
5646
5647 return genlmsg_end(msg, hdr);
5648
Johannes Berg8cef2c92013-02-05 16:54:31 +01005649 fail_unlock_rcu:
5650 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005651 nla_put_failure:
5652 genlmsg_cancel(msg, hdr);
5653 return -EMSGSIZE;
5654}
5655
Johannes Berg97990a02013-04-19 01:02:55 +02005656static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005657{
Johannes Berg48ab9052009-07-10 18:42:31 +02005658 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005659 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005660 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005661 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005662 int err;
5663
Johannes Berg97990a02013-04-19 01:02:55 +02005664 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005665 if (err)
5666 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005667
Johannes Berg48ab9052009-07-10 18:42:31 +02005668 wdev_lock(wdev);
5669 spin_lock_bh(&rdev->bss_lock);
5670 cfg80211_bss_expire(rdev);
5671
Johannes Berg9720bb32011-06-21 09:45:33 +02005672 cb->seq = rdev->bss_generation;
5673
Johannes Berg48ab9052009-07-10 18:42:31 +02005674 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005675 if (++idx <= start)
5676 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005677 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005678 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005679 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005680 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005681 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005682 }
5683 }
5684
Johannes Berg48ab9052009-07-10 18:42:31 +02005685 spin_unlock_bh(&rdev->bss_lock);
5686 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005687
Johannes Berg97990a02013-04-19 01:02:55 +02005688 cb->args[2] = idx;
5689 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005690
Johannes Berg67748892010-10-04 21:14:06 +02005691 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005692}
5693
Eric W. Biederman15e47302012-09-07 20:12:54 +00005694static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005695 int flags, struct net_device *dev,
5696 struct survey_info *survey)
5697{
5698 void *hdr;
5699 struct nlattr *infoattr;
5700
Eric W. Biederman15e47302012-09-07 20:12:54 +00005701 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005702 NL80211_CMD_NEW_SURVEY_RESULTS);
5703 if (!hdr)
5704 return -ENOMEM;
5705
David S. Miller9360ffd2012-03-29 04:41:26 -04005706 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5707 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005708
5709 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5710 if (!infoattr)
5711 goto nla_put_failure;
5712
David S. Miller9360ffd2012-03-29 04:41:26 -04005713 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5714 survey->channel->center_freq))
5715 goto nla_put_failure;
5716
5717 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5718 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5719 goto nla_put_failure;
5720 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5721 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5722 goto nla_put_failure;
5723 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5724 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5725 survey->channel_time))
5726 goto nla_put_failure;
5727 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5728 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5729 survey->channel_time_busy))
5730 goto nla_put_failure;
5731 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5732 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5733 survey->channel_time_ext_busy))
5734 goto nla_put_failure;
5735 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5736 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5737 survey->channel_time_rx))
5738 goto nla_put_failure;
5739 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5740 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5741 survey->channel_time_tx))
5742 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005743
5744 nla_nest_end(msg, infoattr);
5745
5746 return genlmsg_end(msg, hdr);
5747
5748 nla_put_failure:
5749 genlmsg_cancel(msg, hdr);
5750 return -EMSGSIZE;
5751}
5752
5753static int nl80211_dump_survey(struct sk_buff *skb,
5754 struct netlink_callback *cb)
5755{
5756 struct survey_info survey;
5757 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005758 struct wireless_dev *wdev;
5759 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005760 int res;
5761
Johannes Berg97990a02013-04-19 01:02:55 +02005762 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005763 if (res)
5764 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005765
Johannes Berg97990a02013-04-19 01:02:55 +02005766 if (!wdev->netdev) {
5767 res = -EINVAL;
5768 goto out_err;
5769 }
5770
Holger Schurig61fa7132009-11-11 12:25:40 +01005771 if (!dev->ops->dump_survey) {
5772 res = -EOPNOTSUPP;
5773 goto out_err;
5774 }
5775
5776 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005777 struct ieee80211_channel *chan;
5778
Johannes Berg97990a02013-04-19 01:02:55 +02005779 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005780 if (res == -ENOENT)
5781 break;
5782 if (res)
5783 goto out_err;
5784
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005785 /* Survey without a channel doesn't make sense */
5786 if (!survey.channel) {
5787 res = -EINVAL;
5788 goto out;
5789 }
5790
5791 chan = ieee80211_get_channel(&dev->wiphy,
5792 survey.channel->center_freq);
5793 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5794 survey_idx++;
5795 continue;
5796 }
5797
Holger Schurig61fa7132009-11-11 12:25:40 +01005798 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005799 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005800 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005801 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005802 goto out;
5803 survey_idx++;
5804 }
5805
5806 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005807 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005808 res = skb->len;
5809 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005810 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005811 return res;
5812}
5813
Samuel Ortizb23aa672009-07-01 21:26:54 +02005814static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5815{
5816 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5817 NL80211_WPA_VERSION_2));
5818}
5819
Jouni Malinen636a5d32009-03-19 13:39:22 +02005820static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5821{
Johannes Berg4c476992010-10-04 21:36:35 +02005822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5823 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005824 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005825 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5826 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005827 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005828 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005829 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005830
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005831 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5832 return -EINVAL;
5833
5834 if (!info->attrs[NL80211_ATTR_MAC])
5835 return -EINVAL;
5836
Jouni Malinen17780922009-03-27 20:52:47 +02005837 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5838 return -EINVAL;
5839
Johannes Berg19957bb2009-07-02 17:20:43 +02005840 if (!info->attrs[NL80211_ATTR_SSID])
5841 return -EINVAL;
5842
5843 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5844 return -EINVAL;
5845
Johannes Bergfffd0932009-07-08 14:22:54 +02005846 err = nl80211_parse_key(info, &key);
5847 if (err)
5848 return err;
5849
5850 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005851 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5852 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005853 if (!key.p.key || !key.p.key_len)
5854 return -EINVAL;
5855 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5856 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5857 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5858 key.p.key_len != WLAN_KEY_LEN_WEP104))
5859 return -EINVAL;
5860 if (key.idx > 4)
5861 return -EINVAL;
5862 } else {
5863 key.p.key_len = 0;
5864 key.p.key = NULL;
5865 }
5866
Johannes Bergafea0b72010-08-10 09:46:42 +02005867 if (key.idx >= 0) {
5868 int i;
5869 bool ok = false;
5870 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5871 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5872 ok = true;
5873 break;
5874 }
5875 }
Johannes Berg4c476992010-10-04 21:36:35 +02005876 if (!ok)
5877 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005878 }
5879
Johannes Berg4c476992010-10-04 21:36:35 +02005880 if (!rdev->ops->auth)
5881 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005882
Johannes Berg074ac8d2010-09-16 14:58:22 +02005883 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005884 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5885 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005886
Johannes Berg19957bb2009-07-02 17:20:43 +02005887 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005888 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005889 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005890 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5891 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005892
Johannes Berg19957bb2009-07-02 17:20:43 +02005893 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5894 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5895
5896 if (info->attrs[NL80211_ATTR_IE]) {
5897 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5898 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5899 }
5900
5901 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005902 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005903 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005904
Jouni Malinene39e5b52012-09-30 19:29:39 +03005905 if (auth_type == NL80211_AUTHTYPE_SAE &&
5906 !info->attrs[NL80211_ATTR_SAE_DATA])
5907 return -EINVAL;
5908
5909 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5910 if (auth_type != NL80211_AUTHTYPE_SAE)
5911 return -EINVAL;
5912 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5913 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5914 /* need to include at least Auth Transaction and Status Code */
5915 if (sae_data_len < 4)
5916 return -EINVAL;
5917 }
5918
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005919 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5920
Johannes Berg95de8172012-01-20 13:55:25 +01005921 /*
5922 * Since we no longer track auth state, ignore
5923 * requests to only change local state.
5924 */
5925 if (local_state_change)
5926 return 0;
5927
Johannes Berg91bf9b22013-05-15 17:44:01 +02005928 wdev_lock(dev->ieee80211_ptr);
5929 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5930 ssid, ssid_len, ie, ie_len,
5931 key.p.key, key.p.key_len, key.idx,
5932 sae_data, sae_data_len);
5933 wdev_unlock(dev->ieee80211_ptr);
5934 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005935}
5936
Johannes Bergc0692b82010-08-27 14:26:53 +03005937static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5938 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005939 struct cfg80211_crypto_settings *settings,
5940 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005941{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005942 memset(settings, 0, sizeof(*settings));
5943
Samuel Ortizb23aa672009-07-01 21:26:54 +02005944 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5945
Johannes Bergc0692b82010-08-27 14:26:53 +03005946 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5947 u16 proto;
5948 proto = nla_get_u16(
5949 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5950 settings->control_port_ethertype = cpu_to_be16(proto);
5951 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5952 proto != ETH_P_PAE)
5953 return -EINVAL;
5954 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5955 settings->control_port_no_encrypt = true;
5956 } else
5957 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5958
Samuel Ortizb23aa672009-07-01 21:26:54 +02005959 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5960 void *data;
5961 int len, i;
5962
5963 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5964 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5965 settings->n_ciphers_pairwise = len / sizeof(u32);
5966
5967 if (len % sizeof(u32))
5968 return -EINVAL;
5969
Johannes Berg3dc27d22009-07-02 21:36:37 +02005970 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005971 return -EINVAL;
5972
5973 memcpy(settings->ciphers_pairwise, data, len);
5974
5975 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005976 if (!cfg80211_supported_cipher_suite(
5977 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005978 settings->ciphers_pairwise[i]))
5979 return -EINVAL;
5980 }
5981
5982 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5983 settings->cipher_group =
5984 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005985 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5986 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005987 return -EINVAL;
5988 }
5989
5990 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5991 settings->wpa_versions =
5992 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5993 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5994 return -EINVAL;
5995 }
5996
5997 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5998 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005999 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006000
6001 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6002 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6003 settings->n_akm_suites = len / sizeof(u32);
6004
6005 if (len % sizeof(u32))
6006 return -EINVAL;
6007
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006008 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6009 return -EINVAL;
6010
Samuel Ortizb23aa672009-07-01 21:26:54 +02006011 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006012 }
6013
6014 return 0;
6015}
6016
Jouni Malinen636a5d32009-03-19 13:39:22 +02006017static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6018{
Johannes Berg4c476992010-10-04 21:36:35 +02006019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6020 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006021 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006022 struct cfg80211_assoc_request req = {};
6023 const u8 *bssid, *ssid;
6024 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006025
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006026 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6027 return -EINVAL;
6028
6029 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006030 !info->attrs[NL80211_ATTR_SSID] ||
6031 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006032 return -EINVAL;
6033
Johannes Berg4c476992010-10-04 21:36:35 +02006034 if (!rdev->ops->assoc)
6035 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006036
Johannes Berg074ac8d2010-09-16 14:58:22 +02006037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6039 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006040
Johannes Berg19957bb2009-07-02 17:20:43 +02006041 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006042
Johannes Berg19957bb2009-07-02 17:20:43 +02006043 chan = ieee80211_get_channel(&rdev->wiphy,
6044 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006045 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6046 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006047
Johannes Berg19957bb2009-07-02 17:20:43 +02006048 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6049 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006050
6051 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006052 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6053 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006054 }
6055
Jouni Malinendc6382c2009-05-06 22:09:37 +03006056 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006057 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006058 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006059 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006060 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006061 else if (mfp != NL80211_MFP_NO)
6062 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006063 }
6064
Johannes Berg3e5d7642009-07-07 14:37:26 +02006065 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006066 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006067
Ben Greear7e7c8922011-11-18 11:31:59 -08006068 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006069 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006070
6071 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006072 memcpy(&req.ht_capa_mask,
6073 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6074 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006075
6076 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006077 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006078 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006079 memcpy(&req.ht_capa,
6080 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6081 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006082 }
6083
Johannes Bergee2aca32013-02-21 17:36:01 +01006084 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006085 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006086
6087 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006088 memcpy(&req.vht_capa_mask,
6089 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6090 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006091
6092 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006093 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006094 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006095 memcpy(&req.vht_capa,
6096 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6097 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006098 }
6099
Johannes Bergf62fab72013-02-21 20:09:09 +01006100 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006101 if (!err) {
6102 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006103 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6104 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006105 wdev_unlock(dev->ieee80211_ptr);
6106 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006107
Jouni Malinen636a5d32009-03-19 13:39:22 +02006108 return err;
6109}
6110
6111static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6112{
Johannes Berg4c476992010-10-04 21:36:35 +02006113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6114 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006115 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006116 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006117 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006118 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006119
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006120 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6121 return -EINVAL;
6122
6123 if (!info->attrs[NL80211_ATTR_MAC])
6124 return -EINVAL;
6125
6126 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6127 return -EINVAL;
6128
Johannes Berg4c476992010-10-04 21:36:35 +02006129 if (!rdev->ops->deauth)
6130 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006131
Johannes Berg074ac8d2010-09-16 14:58:22 +02006132 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006133 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6134 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006135
Johannes Berg19957bb2009-07-02 17:20:43 +02006136 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006137
Johannes Berg19957bb2009-07-02 17:20:43 +02006138 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6139 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006140 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006141 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006142 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006143
6144 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006145 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6146 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006147 }
6148
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006149 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6150
Johannes Berg91bf9b22013-05-15 17:44:01 +02006151 wdev_lock(dev->ieee80211_ptr);
6152 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6153 local_state_change);
6154 wdev_unlock(dev->ieee80211_ptr);
6155 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006156}
6157
6158static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6159{
Johannes Berg4c476992010-10-04 21:36:35 +02006160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6161 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006162 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006163 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006164 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006165 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006166
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006167 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6168 return -EINVAL;
6169
6170 if (!info->attrs[NL80211_ATTR_MAC])
6171 return -EINVAL;
6172
6173 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6174 return -EINVAL;
6175
Johannes Berg4c476992010-10-04 21:36:35 +02006176 if (!rdev->ops->disassoc)
6177 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006178
Johannes Berg074ac8d2010-09-16 14:58:22 +02006179 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006180 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6181 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006182
Johannes Berg19957bb2009-07-02 17:20:43 +02006183 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006184
Johannes Berg19957bb2009-07-02 17:20:43 +02006185 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6186 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006187 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006188 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006189 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006190
6191 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006192 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6193 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006194 }
6195
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006196 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6197
Johannes Berg91bf9b22013-05-15 17:44:01 +02006198 wdev_lock(dev->ieee80211_ptr);
6199 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6200 local_state_change);
6201 wdev_unlock(dev->ieee80211_ptr);
6202 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006203}
6204
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006205static bool
6206nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6207 int mcast_rate[IEEE80211_NUM_BANDS],
6208 int rateval)
6209{
6210 struct wiphy *wiphy = &rdev->wiphy;
6211 bool found = false;
6212 int band, i;
6213
6214 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6215 struct ieee80211_supported_band *sband;
6216
6217 sband = wiphy->bands[band];
6218 if (!sband)
6219 continue;
6220
6221 for (i = 0; i < sband->n_bitrates; i++) {
6222 if (sband->bitrates[i].bitrate == rateval) {
6223 mcast_rate[band] = i + 1;
6224 found = true;
6225 break;
6226 }
6227 }
6228 }
6229
6230 return found;
6231}
6232
Johannes Berg04a773a2009-04-19 21:24:32 +02006233static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6234{
Johannes Berg4c476992010-10-04 21:36:35 +02006235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6236 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006237 struct cfg80211_ibss_params ibss;
6238 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006239 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006240 int err;
6241
Johannes Berg8e30bc52009-04-22 17:45:38 +02006242 memset(&ibss, 0, sizeof(ibss));
6243
Johannes Berg04a773a2009-04-19 21:24:32 +02006244 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6245 return -EINVAL;
6246
Johannes Berg683b6d32012-11-08 21:25:48 +01006247 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006248 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6249 return -EINVAL;
6250
Johannes Berg8e30bc52009-04-22 17:45:38 +02006251 ibss.beacon_interval = 100;
6252
6253 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6254 ibss.beacon_interval =
6255 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6256 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6257 return -EINVAL;
6258 }
6259
Johannes Berg4c476992010-10-04 21:36:35 +02006260 if (!rdev->ops->join_ibss)
6261 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006262
Johannes Berg4c476992010-10-04 21:36:35 +02006263 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6264 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006265
Johannes Berg79c97e92009-07-07 03:56:12 +02006266 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006267
Johannes Berg39193492011-09-16 13:45:25 +02006268 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006269 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006270
6271 if (!is_valid_ether_addr(ibss.bssid))
6272 return -EINVAL;
6273 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006274 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6275 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6276
6277 if (info->attrs[NL80211_ATTR_IE]) {
6278 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6279 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6280 }
6281
Johannes Berg683b6d32012-11-08 21:25:48 +01006282 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6283 if (err)
6284 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01006285
Johannes Berg683b6d32012-11-08 21:25:48 +01006286 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01006287 return -EINVAL;
6288
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006289 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6290 return -EINVAL;
6291 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6292 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006293 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006294
Johannes Berg04a773a2009-04-19 21:24:32 +02006295 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006296 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006297
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006298 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6299 u8 *rates =
6300 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6301 int n_rates =
6302 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6303 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006304 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006305
Johannes Berg34850ab2011-07-18 18:08:35 +02006306 err = ieee80211_get_ratemask(sband, rates, n_rates,
6307 &ibss.basic_rates);
6308 if (err)
6309 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006310 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006311
6312 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6313 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6314 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6315 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006316
Johannes Berg4c476992010-10-04 21:36:35 +02006317 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306318 bool no_ht = false;
6319
Johannes Berg4c476992010-10-04 21:36:35 +02006320 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306321 info->attrs[NL80211_ATTR_KEYS],
6322 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006323 if (IS_ERR(connkeys))
6324 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306325
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006326 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6327 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306328 kfree(connkeys);
6329 return -EINVAL;
6330 }
Johannes Berg4c476992010-10-04 21:36:35 +02006331 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006332
Antonio Quartulli267335d2012-01-31 20:25:47 +01006333 ibss.control_port =
6334 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6335
Johannes Berg4c476992010-10-04 21:36:35 +02006336 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006337 if (err)
6338 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006339 return err;
6340}
6341
6342static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6343{
Johannes Berg4c476992010-10-04 21:36:35 +02006344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6345 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006346
Johannes Berg4c476992010-10-04 21:36:35 +02006347 if (!rdev->ops->leave_ibss)
6348 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006349
Johannes Berg4c476992010-10-04 21:36:35 +02006350 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6351 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006352
Johannes Berg4c476992010-10-04 21:36:35 +02006353 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006354}
6355
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006356static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6357{
6358 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6359 struct net_device *dev = info->user_ptr[1];
6360 int mcast_rate[IEEE80211_NUM_BANDS];
6361 u32 nla_rate;
6362 int err;
6363
6364 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6365 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6366 return -EOPNOTSUPP;
6367
6368 if (!rdev->ops->set_mcast_rate)
6369 return -EOPNOTSUPP;
6370
6371 memset(mcast_rate, 0, sizeof(mcast_rate));
6372
6373 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6374 return -EINVAL;
6375
6376 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6377 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6378 return -EINVAL;
6379
6380 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6381
6382 return err;
6383}
6384
6385
Johannes Bergaff89a92009-07-01 21:26:51 +02006386#ifdef CONFIG_NL80211_TESTMODE
6387static struct genl_multicast_group nl80211_testmode_mcgrp = {
6388 .name = "testmode",
6389};
6390
6391static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6392{
Johannes Berg4c476992010-10-04 21:36:35 +02006393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006394 int err;
6395
6396 if (!info->attrs[NL80211_ATTR_TESTDATA])
6397 return -EINVAL;
6398
Johannes Bergaff89a92009-07-01 21:26:51 +02006399 err = -EOPNOTSUPP;
6400 if (rdev->ops->testmode_cmd) {
6401 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006402 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006403 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6404 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6405 rdev->testmode_info = NULL;
6406 }
6407
Johannes Bergaff89a92009-07-01 21:26:51 +02006408 return err;
6409}
6410
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006411static int nl80211_testmode_dump(struct sk_buff *skb,
6412 struct netlink_callback *cb)
6413{
Johannes Berg00918d32011-12-13 17:22:05 +01006414 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006415 int err;
6416 long phy_idx;
6417 void *data = NULL;
6418 int data_len = 0;
6419
Johannes Berg5fe231e2013-05-08 21:45:15 +02006420 rtnl_lock();
6421
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006422 if (cb->args[0]) {
6423 /*
6424 * 0 is a valid index, but not valid for args[0],
6425 * so we need to offset by 1.
6426 */
6427 phy_idx = cb->args[0] - 1;
6428 } else {
6429 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6430 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6431 nl80211_policy);
6432 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006433 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006434
Johannes Berg2bd7e352012-06-15 14:23:16 +02006435 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6436 nl80211_fam.attrbuf);
6437 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006438 err = PTR_ERR(rdev);
6439 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006440 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006441 phy_idx = rdev->wiphy_idx;
6442 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006443
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006444 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6445 cb->args[1] =
6446 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6447 }
6448
6449 if (cb->args[1]) {
6450 data = nla_data((void *)cb->args[1]);
6451 data_len = nla_len((void *)cb->args[1]);
6452 }
6453
Johannes Berg00918d32011-12-13 17:22:05 +01006454 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6455 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006456 err = -ENOENT;
6457 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006458 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006459
Johannes Berg00918d32011-12-13 17:22:05 +01006460 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006461 err = -EOPNOTSUPP;
6462 goto out_err;
6463 }
6464
6465 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006466 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006467 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6468 NL80211_CMD_TESTMODE);
6469 struct nlattr *tmdata;
6470
David S. Miller9360ffd2012-03-29 04:41:26 -04006471 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006472 genlmsg_cancel(skb, hdr);
6473 break;
6474 }
6475
6476 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6477 if (!tmdata) {
6478 genlmsg_cancel(skb, hdr);
6479 break;
6480 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006481 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006482 nla_nest_end(skb, tmdata);
6483
6484 if (err == -ENOBUFS || err == -ENOENT) {
6485 genlmsg_cancel(skb, hdr);
6486 break;
6487 } else if (err) {
6488 genlmsg_cancel(skb, hdr);
6489 goto out_err;
6490 }
6491
6492 genlmsg_end(skb, hdr);
6493 }
6494
6495 err = skb->len;
6496 /* see above */
6497 cb->args[0] = phy_idx + 1;
6498 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006499 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006500 return err;
6501}
6502
Johannes Bergaff89a92009-07-01 21:26:51 +02006503static struct sk_buff *
6504__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006505 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006506{
6507 struct sk_buff *skb;
6508 void *hdr;
6509 struct nlattr *data;
6510
6511 skb = nlmsg_new(approxlen + 100, gfp);
6512 if (!skb)
6513 return NULL;
6514
Eric W. Biederman15e47302012-09-07 20:12:54 +00006515 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006516 if (!hdr) {
6517 kfree_skb(skb);
6518 return NULL;
6519 }
6520
David S. Miller9360ffd2012-03-29 04:41:26 -04006521 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6522 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006523 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6524
6525 ((void **)skb->cb)[0] = rdev;
6526 ((void **)skb->cb)[1] = hdr;
6527 ((void **)skb->cb)[2] = data;
6528
6529 return skb;
6530
6531 nla_put_failure:
6532 kfree_skb(skb);
6533 return NULL;
6534}
6535
6536struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6537 int approxlen)
6538{
6539 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6540
6541 if (WARN_ON(!rdev->testmode_info))
6542 return NULL;
6543
6544 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006545 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006546 rdev->testmode_info->snd_seq,
6547 GFP_KERNEL);
6548}
6549EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6550
6551int cfg80211_testmode_reply(struct sk_buff *skb)
6552{
6553 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6554 void *hdr = ((void **)skb->cb)[1];
6555 struct nlattr *data = ((void **)skb->cb)[2];
6556
6557 if (WARN_ON(!rdev->testmode_info)) {
6558 kfree_skb(skb);
6559 return -EINVAL;
6560 }
6561
6562 nla_nest_end(skb, data);
6563 genlmsg_end(skb, hdr);
6564 return genlmsg_reply(skb, rdev->testmode_info);
6565}
6566EXPORT_SYMBOL(cfg80211_testmode_reply);
6567
6568struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6569 int approxlen, gfp_t gfp)
6570{
6571 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6572
6573 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6574}
6575EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6576
6577void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6578{
6579 void *hdr = ((void **)skb->cb)[1];
6580 struct nlattr *data = ((void **)skb->cb)[2];
6581
6582 nla_nest_end(skb, data);
6583 genlmsg_end(skb, hdr);
6584 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6585}
6586EXPORT_SYMBOL(cfg80211_testmode_event);
6587#endif
6588
Samuel Ortizb23aa672009-07-01 21:26:54 +02006589static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6590{
Johannes Berg4c476992010-10-04 21:36:35 +02006591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6592 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006593 struct cfg80211_connect_params connect;
6594 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006595 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006596 int err;
6597
6598 memset(&connect, 0, sizeof(connect));
6599
6600 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6601 return -EINVAL;
6602
6603 if (!info->attrs[NL80211_ATTR_SSID] ||
6604 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6605 return -EINVAL;
6606
6607 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6608 connect.auth_type =
6609 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006610 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6611 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006612 return -EINVAL;
6613 } else
6614 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6615
6616 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6617
Johannes Bergc0692b82010-08-27 14:26:53 +03006618 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006619 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006620 if (err)
6621 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006622
Johannes Berg074ac8d2010-09-16 14:58:22 +02006623 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006624 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6625 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006626
Johannes Berg79c97e92009-07-07 03:56:12 +02006627 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006628
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306629 connect.bg_scan_period = -1;
6630 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6631 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6632 connect.bg_scan_period =
6633 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6634 }
6635
Samuel Ortizb23aa672009-07-01 21:26:54 +02006636 if (info->attrs[NL80211_ATTR_MAC])
6637 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6638 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6639 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6640
6641 if (info->attrs[NL80211_ATTR_IE]) {
6642 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6643 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6644 }
6645
Jouni Malinencee00a92013-01-15 17:15:57 +02006646 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6647 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6648 if (connect.mfp != NL80211_MFP_REQUIRED &&
6649 connect.mfp != NL80211_MFP_NO)
6650 return -EINVAL;
6651 } else {
6652 connect.mfp = NL80211_MFP_NO;
6653 }
6654
Samuel Ortizb23aa672009-07-01 21:26:54 +02006655 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6656 connect.channel =
6657 ieee80211_get_channel(wiphy,
6658 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6659 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006660 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6661 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006662 }
6663
Johannes Bergfffd0932009-07-08 14:22:54 +02006664 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6665 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306666 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006667 if (IS_ERR(connkeys))
6668 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006669 }
6670
Ben Greear7e7c8922011-11-18 11:31:59 -08006671 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6672 connect.flags |= ASSOC_REQ_DISABLE_HT;
6673
6674 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6675 memcpy(&connect.ht_capa_mask,
6676 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6677 sizeof(connect.ht_capa_mask));
6678
6679 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006680 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6681 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006682 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006683 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006684 memcpy(&connect.ht_capa,
6685 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6686 sizeof(connect.ht_capa));
6687 }
6688
Johannes Bergee2aca32013-02-21 17:36:01 +01006689 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6690 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6691
6692 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6693 memcpy(&connect.vht_capa_mask,
6694 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6695 sizeof(connect.vht_capa_mask));
6696
6697 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6698 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6699 kfree(connkeys);
6700 return -EINVAL;
6701 }
6702 memcpy(&connect.vht_capa,
6703 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6704 sizeof(connect.vht_capa));
6705 }
6706
Johannes Berg83739b02013-05-15 17:44:01 +02006707 wdev_lock(dev->ieee80211_ptr);
6708 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6709 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006710 if (err)
6711 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006712 return err;
6713}
6714
6715static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6716{
Johannes Berg4c476992010-10-04 21:36:35 +02006717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6718 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006719 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006720 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006721
6722 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6723 reason = WLAN_REASON_DEAUTH_LEAVING;
6724 else
6725 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6726
6727 if (reason == 0)
6728 return -EINVAL;
6729
Johannes Berg074ac8d2010-09-16 14:58:22 +02006730 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006731 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6732 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006733
Johannes Berg83739b02013-05-15 17:44:01 +02006734 wdev_lock(dev->ieee80211_ptr);
6735 ret = cfg80211_disconnect(rdev, dev, reason, true);
6736 wdev_unlock(dev->ieee80211_ptr);
6737 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006738}
6739
Johannes Berg463d0182009-07-14 00:33:35 +02006740static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6741{
Johannes Berg4c476992010-10-04 21:36:35 +02006742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006743 struct net *net;
6744 int err;
6745 u32 pid;
6746
6747 if (!info->attrs[NL80211_ATTR_PID])
6748 return -EINVAL;
6749
6750 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6751
Johannes Berg463d0182009-07-14 00:33:35 +02006752 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006753 if (IS_ERR(net))
6754 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006755
6756 err = 0;
6757
6758 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006759 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6760 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006761
Johannes Berg463d0182009-07-14 00:33:35 +02006762 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006763 return err;
6764}
6765
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006766static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6767{
Johannes Berg4c476992010-10-04 21:36:35 +02006768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006769 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6770 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006771 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006772 struct cfg80211_pmksa pmksa;
6773
6774 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6775
6776 if (!info->attrs[NL80211_ATTR_MAC])
6777 return -EINVAL;
6778
6779 if (!info->attrs[NL80211_ATTR_PMKID])
6780 return -EINVAL;
6781
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006782 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6783 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6784
Johannes Berg074ac8d2010-09-16 14:58:22 +02006785 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006786 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6787 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006788
6789 switch (info->genlhdr->cmd) {
6790 case NL80211_CMD_SET_PMKSA:
6791 rdev_ops = rdev->ops->set_pmksa;
6792 break;
6793 case NL80211_CMD_DEL_PMKSA:
6794 rdev_ops = rdev->ops->del_pmksa;
6795 break;
6796 default:
6797 WARN_ON(1);
6798 break;
6799 }
6800
Johannes Berg4c476992010-10-04 21:36:35 +02006801 if (!rdev_ops)
6802 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006803
Johannes Berg4c476992010-10-04 21:36:35 +02006804 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006805}
6806
6807static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6808{
Johannes Berg4c476992010-10-04 21:36:35 +02006809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6810 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006811
Johannes Berg074ac8d2010-09-16 14:58:22 +02006812 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006813 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6814 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006815
Johannes Berg4c476992010-10-04 21:36:35 +02006816 if (!rdev->ops->flush_pmksa)
6817 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006818
Hila Gonene35e4d22012-06-27 17:19:42 +03006819 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006820}
6821
Arik Nemtsov109086c2011-09-28 14:12:50 +03006822static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6823{
6824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6825 struct net_device *dev = info->user_ptr[1];
6826 u8 action_code, dialog_token;
6827 u16 status_code;
6828 u8 *peer;
6829
6830 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6831 !rdev->ops->tdls_mgmt)
6832 return -EOPNOTSUPP;
6833
6834 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6835 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6836 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6837 !info->attrs[NL80211_ATTR_IE] ||
6838 !info->attrs[NL80211_ATTR_MAC])
6839 return -EINVAL;
6840
6841 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6842 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6843 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6844 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6845
Hila Gonene35e4d22012-06-27 17:19:42 +03006846 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6847 dialog_token, status_code,
6848 nla_data(info->attrs[NL80211_ATTR_IE]),
6849 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006850}
6851
6852static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6853{
6854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6855 struct net_device *dev = info->user_ptr[1];
6856 enum nl80211_tdls_operation operation;
6857 u8 *peer;
6858
6859 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6860 !rdev->ops->tdls_oper)
6861 return -EOPNOTSUPP;
6862
6863 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6864 !info->attrs[NL80211_ATTR_MAC])
6865 return -EINVAL;
6866
6867 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6868 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6869
Hila Gonene35e4d22012-06-27 17:19:42 +03006870 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006871}
6872
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006873static int nl80211_remain_on_channel(struct sk_buff *skb,
6874 struct genl_info *info)
6875{
Johannes Berg4c476992010-10-04 21:36:35 +02006876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006877 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006878 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006879 struct sk_buff *msg;
6880 void *hdr;
6881 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006882 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006883 int err;
6884
6885 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6886 !info->attrs[NL80211_ATTR_DURATION])
6887 return -EINVAL;
6888
6889 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6890
Johannes Berg7c4ef712011-11-18 15:33:48 +01006891 if (!rdev->ops->remain_on_channel ||
6892 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006893 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006894
Johannes Bergebf348f2012-06-01 12:50:54 +02006895 /*
6896 * We should be on that channel for at least a minimum amount of
6897 * time (10ms) but no longer than the driver supports.
6898 */
6899 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6900 duration > rdev->wiphy.max_remain_on_channel_duration)
6901 return -EINVAL;
6902
Johannes Berg683b6d32012-11-08 21:25:48 +01006903 err = nl80211_parse_chandef(rdev, info, &chandef);
6904 if (err)
6905 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006906
6907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006908 if (!msg)
6909 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006910
Eric W. Biederman15e47302012-09-07 20:12:54 +00006911 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006912 NL80211_CMD_REMAIN_ON_CHANNEL);
6913
6914 if (IS_ERR(hdr)) {
6915 err = PTR_ERR(hdr);
6916 goto free_msg;
6917 }
6918
Johannes Berg683b6d32012-11-08 21:25:48 +01006919 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6920 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006921
6922 if (err)
6923 goto free_msg;
6924
David S. Miller9360ffd2012-03-29 04:41:26 -04006925 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6926 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006927
6928 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006929
6930 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006931
6932 nla_put_failure:
6933 err = -ENOBUFS;
6934 free_msg:
6935 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006936 return err;
6937}
6938
6939static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6940 struct genl_info *info)
6941{
Johannes Berg4c476992010-10-04 21:36:35 +02006942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006943 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006944 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006945
6946 if (!info->attrs[NL80211_ATTR_COOKIE])
6947 return -EINVAL;
6948
Johannes Berg4c476992010-10-04 21:36:35 +02006949 if (!rdev->ops->cancel_remain_on_channel)
6950 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006951
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006952 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6953
Hila Gonene35e4d22012-06-27 17:19:42 +03006954 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006955}
6956
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006957static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6958 u8 *rates, u8 rates_len)
6959{
6960 u8 i;
6961 u32 mask = 0;
6962
6963 for (i = 0; i < rates_len; i++) {
6964 int rate = (rates[i] & 0x7f) * 5;
6965 int ridx;
6966 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6967 struct ieee80211_rate *srate =
6968 &sband->bitrates[ridx];
6969 if (rate == srate->bitrate) {
6970 mask |= 1 << ridx;
6971 break;
6972 }
6973 }
6974 if (ridx == sband->n_bitrates)
6975 return 0; /* rate not found */
6976 }
6977
6978 return mask;
6979}
6980
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006981static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6982 u8 *rates, u8 rates_len,
6983 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6984{
6985 u8 i;
6986
6987 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6988
6989 for (i = 0; i < rates_len; i++) {
6990 int ridx, rbit;
6991
6992 ridx = rates[i] / 8;
6993 rbit = BIT(rates[i] % 8);
6994
6995 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006996 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006997 return false;
6998
6999 /* check availability */
7000 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7001 mcs[ridx] |= rbit;
7002 else
7003 return false;
7004 }
7005
7006 return true;
7007}
7008
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007009static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007010 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7011 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007012 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7013 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007014};
7015
7016static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7017 struct genl_info *info)
7018{
7019 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007021 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007022 int rem, i;
7023 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007024 struct nlattr *tx_rates;
7025 struct ieee80211_supported_band *sband;
7026
7027 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7028 return -EINVAL;
7029
Johannes Berg4c476992010-10-04 21:36:35 +02007030 if (!rdev->ops->set_bitrate_mask)
7031 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007032
7033 memset(&mask, 0, sizeof(mask));
7034 /* Default to all rates enabled */
7035 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7036 sband = rdev->wiphy.bands[i];
7037 mask.control[i].legacy =
7038 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007039 if (sband)
7040 memcpy(mask.control[i].mcs,
7041 sband->ht_cap.mcs.rx_mask,
7042 sizeof(mask.control[i].mcs));
7043 else
7044 memset(mask.control[i].mcs, 0,
7045 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007046 }
7047
7048 /*
7049 * The nested attribute uses enum nl80211_band as the index. This maps
7050 * directly to the enum ieee80211_band values used in cfg80211.
7051 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007052 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007053 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7054 {
7055 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007056 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7057 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007058 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007059 if (sband == NULL)
7060 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007061 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7062 nla_len(tx_rates), nl80211_txattr_policy);
7063 if (tb[NL80211_TXRATE_LEGACY]) {
7064 mask.control[band].legacy = rateset_to_mask(
7065 sband,
7066 nla_data(tb[NL80211_TXRATE_LEGACY]),
7067 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307068 if ((mask.control[band].legacy == 0) &&
7069 nla_len(tb[NL80211_TXRATE_LEGACY]))
7070 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007071 }
7072 if (tb[NL80211_TXRATE_MCS]) {
7073 if (!ht_rateset_to_mask(
7074 sband,
7075 nla_data(tb[NL80211_TXRATE_MCS]),
7076 nla_len(tb[NL80211_TXRATE_MCS]),
7077 mask.control[band].mcs))
7078 return -EINVAL;
7079 }
7080
7081 if (mask.control[band].legacy == 0) {
7082 /* don't allow empty legacy rates if HT
7083 * is not even supported. */
7084 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7085 return -EINVAL;
7086
7087 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7088 if (mask.control[band].mcs[i])
7089 break;
7090
7091 /* legacy and mcs rates may not be both empty */
7092 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007093 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007094 }
7095 }
7096
Hila Gonene35e4d22012-06-27 17:19:42 +03007097 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007098}
7099
Johannes Berg2e161f72010-08-12 15:38:38 +02007100static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007101{
Johannes Berg4c476992010-10-04 21:36:35 +02007102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007103 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007104 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007105
7106 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7107 return -EINVAL;
7108
Johannes Berg2e161f72010-08-12 15:38:38 +02007109 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7110 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007111
Johannes Berg71bbc992012-06-15 15:30:18 +02007112 switch (wdev->iftype) {
7113 case NL80211_IFTYPE_STATION:
7114 case NL80211_IFTYPE_ADHOC:
7115 case NL80211_IFTYPE_P2P_CLIENT:
7116 case NL80211_IFTYPE_AP:
7117 case NL80211_IFTYPE_AP_VLAN:
7118 case NL80211_IFTYPE_MESH_POINT:
7119 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007120 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007121 break;
7122 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007123 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007124 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007125
7126 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007127 if (!rdev->ops->mgmt_tx)
7128 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007129
Eric W. Biederman15e47302012-09-07 20:12:54 +00007130 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007131 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7132 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007133}
7134
Johannes Berg2e161f72010-08-12 15:38:38 +02007135static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007136{
Johannes Berg4c476992010-10-04 21:36:35 +02007137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007138 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007139 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007140 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007141 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007142 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007143 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007144 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007145 bool offchan, no_cck, dont_wait_for_ack;
7146
7147 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007148
Johannes Berg683b6d32012-11-08 21:25:48 +01007149 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007150 return -EINVAL;
7151
Johannes Berg4c476992010-10-04 21:36:35 +02007152 if (!rdev->ops->mgmt_tx)
7153 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007154
Johannes Berg71bbc992012-06-15 15:30:18 +02007155 switch (wdev->iftype) {
7156 case NL80211_IFTYPE_STATION:
7157 case NL80211_IFTYPE_ADHOC:
7158 case NL80211_IFTYPE_P2P_CLIENT:
7159 case NL80211_IFTYPE_AP:
7160 case NL80211_IFTYPE_AP_VLAN:
7161 case NL80211_IFTYPE_MESH_POINT:
7162 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007163 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007164 break;
7165 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007166 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007167 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007168
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007169 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007170 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007171 return -EINVAL;
7172 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007173
7174 /*
7175 * We should wait on the channel for at least a minimum amount
7176 * of time (10ms) but no longer than the driver supports.
7177 */
7178 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7179 wait > rdev->wiphy.max_remain_on_channel_duration)
7180 return -EINVAL;
7181
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007182 }
7183
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007184 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7185
Johannes Berg7c4ef712011-11-18 15:33:48 +01007186 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7187 return -EINVAL;
7188
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307189 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7190
Johannes Berg683b6d32012-11-08 21:25:48 +01007191 err = nl80211_parse_chandef(rdev, info, &chandef);
7192 if (err)
7193 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007194
Johannes Berge247bd902011-11-04 11:18:21 +01007195 if (!dont_wait_for_ack) {
7196 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7197 if (!msg)
7198 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007199
Eric W. Biederman15e47302012-09-07 20:12:54 +00007200 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007201 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007202
Johannes Berge247bd902011-11-04 11:18:21 +01007203 if (IS_ERR(hdr)) {
7204 err = PTR_ERR(hdr);
7205 goto free_msg;
7206 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007207 }
Johannes Berge247bd902011-11-04 11:18:21 +01007208
Johannes Berg683b6d32012-11-08 21:25:48 +01007209 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007210 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7211 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007212 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007213 if (err)
7214 goto free_msg;
7215
Johannes Berge247bd902011-11-04 11:18:21 +01007216 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007217 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7218 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007219
Johannes Berge247bd902011-11-04 11:18:21 +01007220 genlmsg_end(msg, hdr);
7221 return genlmsg_reply(msg, info);
7222 }
7223
7224 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007225
7226 nla_put_failure:
7227 err = -ENOBUFS;
7228 free_msg:
7229 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007230 return err;
7231}
7232
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007233static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7234{
7235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007236 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007237 u64 cookie;
7238
7239 if (!info->attrs[NL80211_ATTR_COOKIE])
7240 return -EINVAL;
7241
7242 if (!rdev->ops->mgmt_tx_cancel_wait)
7243 return -EOPNOTSUPP;
7244
Johannes Berg71bbc992012-06-15 15:30:18 +02007245 switch (wdev->iftype) {
7246 case NL80211_IFTYPE_STATION:
7247 case NL80211_IFTYPE_ADHOC:
7248 case NL80211_IFTYPE_P2P_CLIENT:
7249 case NL80211_IFTYPE_AP:
7250 case NL80211_IFTYPE_AP_VLAN:
7251 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007252 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007253 break;
7254 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007255 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007256 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007257
7258 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7259
Hila Gonene35e4d22012-06-27 17:19:42 +03007260 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007261}
7262
Kalle Valoffb9eb32010-02-17 17:58:10 +02007263static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7264{
Johannes Berg4c476992010-10-04 21:36:35 +02007265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007266 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007267 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268 u8 ps_state;
7269 bool state;
7270 int err;
7271
Johannes Berg4c476992010-10-04 21:36:35 +02007272 if (!info->attrs[NL80211_ATTR_PS_STATE])
7273 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007274
7275 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7276
Johannes Berg4c476992010-10-04 21:36:35 +02007277 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7278 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007279
7280 wdev = dev->ieee80211_ptr;
7281
Johannes Berg4c476992010-10-04 21:36:35 +02007282 if (!rdev->ops->set_power_mgmt)
7283 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007284
7285 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7286
7287 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007288 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007289
Hila Gonene35e4d22012-06-27 17:19:42 +03007290 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007291 if (!err)
7292 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007293 return err;
7294}
7295
7296static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7297{
Johannes Berg4c476992010-10-04 21:36:35 +02007298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007299 enum nl80211_ps_state ps_state;
7300 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007301 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007302 struct sk_buff *msg;
7303 void *hdr;
7304 int err;
7305
Kalle Valoffb9eb32010-02-17 17:58:10 +02007306 wdev = dev->ieee80211_ptr;
7307
Johannes Berg4c476992010-10-04 21:36:35 +02007308 if (!rdev->ops->set_power_mgmt)
7309 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007310
7311 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007312 if (!msg)
7313 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007314
Eric W. Biederman15e47302012-09-07 20:12:54 +00007315 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007316 NL80211_CMD_GET_POWER_SAVE);
7317 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007318 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007319 goto free_msg;
7320 }
7321
7322 if (wdev->ps)
7323 ps_state = NL80211_PS_ENABLED;
7324 else
7325 ps_state = NL80211_PS_DISABLED;
7326
David S. Miller9360ffd2012-03-29 04:41:26 -04007327 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7328 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007329
7330 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007331 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007332
Johannes Berg4c476992010-10-04 21:36:35 +02007333 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007334 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007335 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007336 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007337 return err;
7338}
7339
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007340static struct nla_policy
7341nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7342 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7343 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7344 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007345 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7346 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7347 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007348};
7349
Thomas Pedersen84f10702012-07-12 16:17:33 -07007350static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007351 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007352{
7353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7354 struct wireless_dev *wdev;
7355 struct net_device *dev = info->user_ptr[1];
7356
Johannes Bergd9d8b012012-11-26 12:51:52 +01007357 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007358 return -EINVAL;
7359
7360 wdev = dev->ieee80211_ptr;
7361
7362 if (!rdev->ops->set_cqm_txe_config)
7363 return -EOPNOTSUPP;
7364
7365 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7366 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7367 return -EOPNOTSUPP;
7368
Hila Gonene35e4d22012-06-27 17:19:42 +03007369 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007370}
7371
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007372static int nl80211_set_cqm_rssi(struct genl_info *info,
7373 s32 threshold, u32 hysteresis)
7374{
Johannes Berg4c476992010-10-04 21:36:35 +02007375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007376 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007377 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007378
7379 if (threshold > 0)
7380 return -EINVAL;
7381
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007382 wdev = dev->ieee80211_ptr;
7383
Johannes Berg4c476992010-10-04 21:36:35 +02007384 if (!rdev->ops->set_cqm_rssi_config)
7385 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007386
Johannes Berg074ac8d2010-09-16 14:58:22 +02007387 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007388 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7389 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007390
Hila Gonene35e4d22012-06-27 17:19:42 +03007391 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007392}
7393
7394static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7395{
7396 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7397 struct nlattr *cqm;
7398 int err;
7399
7400 cqm = info->attrs[NL80211_ATTR_CQM];
7401 if (!cqm) {
7402 err = -EINVAL;
7403 goto out;
7404 }
7405
7406 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7407 nl80211_attr_cqm_policy);
7408 if (err)
7409 goto out;
7410
7411 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7412 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7413 s32 threshold;
7414 u32 hysteresis;
7415 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7416 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7417 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007418 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7419 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7420 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7421 u32 rate, pkts, intvl;
7422 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7423 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7424 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7425 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007426 } else
7427 err = -EINVAL;
7428
7429out:
7430 return err;
7431}
7432
Johannes Berg29cbe682010-12-03 09:20:44 +01007433static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7434{
7435 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7436 struct net_device *dev = info->user_ptr[1];
7437 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007438 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007439 int err;
7440
7441 /* start with default */
7442 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007443 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007444
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007445 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007446 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007447 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007448 if (err)
7449 return err;
7450 }
7451
7452 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7453 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7454 return -EINVAL;
7455
Javier Cardonac80d5452010-12-16 17:37:49 -08007456 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7457 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7458
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007459 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7460 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7461 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7462 return -EINVAL;
7463
Marco Porsch9bdbf042013-01-07 16:04:51 +01007464 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7465 setup.beacon_interval =
7466 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7467 if (setup.beacon_interval < 10 ||
7468 setup.beacon_interval > 10000)
7469 return -EINVAL;
7470 }
7471
7472 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7473 setup.dtim_period =
7474 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7475 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7476 return -EINVAL;
7477 }
7478
Javier Cardonac80d5452010-12-16 17:37:49 -08007479 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7480 /* parse additional setup parameters if given */
7481 err = nl80211_parse_mesh_setup(info, &setup);
7482 if (err)
7483 return err;
7484 }
7485
Thomas Pedersend37bb182013-03-04 13:06:13 -08007486 if (setup.user_mpm)
7487 cfg.auto_open_plinks = false;
7488
Johannes Bergcc1d2802012-05-16 23:50:20 +02007489 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007490 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7491 if (err)
7492 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007493 } else {
7494 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007495 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007496 }
7497
Javier Cardonac80d5452010-12-16 17:37:49 -08007498 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007499}
7500
7501static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7502{
7503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7504 struct net_device *dev = info->user_ptr[1];
7505
7506 return cfg80211_leave_mesh(rdev, dev);
7507}
7508
Johannes Bergdfb89c52012-06-27 09:23:48 +02007509#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007510static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7511 struct cfg80211_registered_device *rdev)
7512{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007513 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007514 struct nlattr *nl_pats, *nl_pat;
7515 int i, pat_len;
7516
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007517 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007518 return 0;
7519
7520 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7521 if (!nl_pats)
7522 return -ENOBUFS;
7523
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007524 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007525 nl_pat = nla_nest_start(msg, i + 1);
7526 if (!nl_pat)
7527 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007528 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007529 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7530 DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007531 wowlan->patterns[i].mask) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007532 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007533 pat_len, wowlan->patterns[i].pattern) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007534 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007535 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007536 return -ENOBUFS;
7537 nla_nest_end(msg, nl_pat);
7538 }
7539 nla_nest_end(msg, nl_pats);
7540
7541 return 0;
7542}
7543
Johannes Berg2a0e0472013-01-23 22:57:40 +01007544static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7545 struct cfg80211_wowlan_tcp *tcp)
7546{
7547 struct nlattr *nl_tcp;
7548
7549 if (!tcp)
7550 return 0;
7551
7552 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7553 if (!nl_tcp)
7554 return -ENOBUFS;
7555
7556 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7557 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7558 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7559 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7560 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7561 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7562 tcp->payload_len, tcp->payload) ||
7563 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7564 tcp->data_interval) ||
7565 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7566 tcp->wake_len, tcp->wake_data) ||
7567 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7568 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7569 return -ENOBUFS;
7570
7571 if (tcp->payload_seq.len &&
7572 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7573 sizeof(tcp->payload_seq), &tcp->payload_seq))
7574 return -ENOBUFS;
7575
7576 if (tcp->payload_tok.len &&
7577 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7578 sizeof(tcp->payload_tok) + tcp->tokens_size,
7579 &tcp->payload_tok))
7580 return -ENOBUFS;
7581
Johannes Berge248ad32013-05-16 10:24:28 +02007582 nla_nest_end(msg, nl_tcp);
7583
Johannes Berg2a0e0472013-01-23 22:57:40 +01007584 return 0;
7585}
7586
Johannes Bergff1b6e62011-05-04 15:37:28 +02007587static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7588{
7589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7590 struct sk_buff *msg;
7591 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007592 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007593
Johannes Berg2a0e0472013-01-23 22:57:40 +01007594 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7595 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007596 return -EOPNOTSUPP;
7597
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007598 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007599 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007600 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7601 rdev->wiphy.wowlan_config->tcp->payload_len +
7602 rdev->wiphy.wowlan_config->tcp->wake_len +
7603 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007604 }
7605
7606 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007607 if (!msg)
7608 return -ENOMEM;
7609
Eric W. Biederman15e47302012-09-07 20:12:54 +00007610 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007611 NL80211_CMD_GET_WOWLAN);
7612 if (!hdr)
7613 goto nla_put_failure;
7614
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007615 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007616 struct nlattr *nl_wowlan;
7617
7618 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7619 if (!nl_wowlan)
7620 goto nla_put_failure;
7621
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007622 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007623 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007624 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007625 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007626 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007627 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007628 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007629 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007630 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007631 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007632 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007633 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007634 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007635 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7636 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007637
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007638 if (nl80211_send_wowlan_patterns(msg, rdev))
7639 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007640
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007641 if (nl80211_send_wowlan_tcp(msg,
7642 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007643 goto nla_put_failure;
7644
Johannes Bergff1b6e62011-05-04 15:37:28 +02007645 nla_nest_end(msg, nl_wowlan);
7646 }
7647
7648 genlmsg_end(msg, hdr);
7649 return genlmsg_reply(msg, info);
7650
7651nla_put_failure:
7652 nlmsg_free(msg);
7653 return -ENOBUFS;
7654}
7655
Johannes Berg2a0e0472013-01-23 22:57:40 +01007656static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7657 struct nlattr *attr,
7658 struct cfg80211_wowlan *trig)
7659{
7660 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7661 struct cfg80211_wowlan_tcp *cfg;
7662 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7663 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7664 u32 size;
7665 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7666 int err, port;
7667
7668 if (!rdev->wiphy.wowlan.tcp)
7669 return -EINVAL;
7670
7671 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7672 nla_data(attr), nla_len(attr),
7673 nl80211_wowlan_tcp_policy);
7674 if (err)
7675 return err;
7676
7677 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7678 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7679 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7680 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7681 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7682 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7683 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7684 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7685 return -EINVAL;
7686
7687 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7688 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7689 return -EINVAL;
7690
7691 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007692 rdev->wiphy.wowlan.tcp->data_interval_max ||
7693 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007694 return -EINVAL;
7695
7696 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7697 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7698 return -EINVAL;
7699
7700 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7701 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7702 return -EINVAL;
7703
7704 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7705 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7706
7707 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7708 tokens_size = tokln - sizeof(*tok);
7709
7710 if (!tok->len || tokens_size % tok->len)
7711 return -EINVAL;
7712 if (!rdev->wiphy.wowlan.tcp->tok)
7713 return -EINVAL;
7714 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7715 return -EINVAL;
7716 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7717 return -EINVAL;
7718 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7719 return -EINVAL;
7720 if (tok->offset + tok->len > data_size)
7721 return -EINVAL;
7722 }
7723
7724 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7725 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7726 if (!rdev->wiphy.wowlan.tcp->seq)
7727 return -EINVAL;
7728 if (seq->len == 0 || seq->len > 4)
7729 return -EINVAL;
7730 if (seq->len + seq->offset > data_size)
7731 return -EINVAL;
7732 }
7733
7734 size = sizeof(*cfg);
7735 size += data_size;
7736 size += wake_size + wake_mask_size;
7737 size += tokens_size;
7738
7739 cfg = kzalloc(size, GFP_KERNEL);
7740 if (!cfg)
7741 return -ENOMEM;
7742 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7743 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7744 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7745 ETH_ALEN);
7746 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7747 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7748 else
7749 port = 0;
7750#ifdef CONFIG_INET
7751 /* allocate a socket and port for it and use it */
7752 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7753 IPPROTO_TCP, &cfg->sock, 1);
7754 if (err) {
7755 kfree(cfg);
7756 return err;
7757 }
7758 if (inet_csk_get_port(cfg->sock->sk, port)) {
7759 sock_release(cfg->sock);
7760 kfree(cfg);
7761 return -EADDRINUSE;
7762 }
7763 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7764#else
7765 if (!port) {
7766 kfree(cfg);
7767 return -EINVAL;
7768 }
7769 cfg->src_port = port;
7770#endif
7771
7772 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7773 cfg->payload_len = data_size;
7774 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7775 memcpy((void *)cfg->payload,
7776 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7777 data_size);
7778 if (seq)
7779 cfg->payload_seq = *seq;
7780 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7781 cfg->wake_len = wake_size;
7782 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7783 memcpy((void *)cfg->wake_data,
7784 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7785 wake_size);
7786 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7787 data_size + wake_size;
7788 memcpy((void *)cfg->wake_mask,
7789 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7790 wake_mask_size);
7791 if (tok) {
7792 cfg->tokens_size = tokens_size;
7793 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7794 }
7795
7796 trig->tcp = cfg;
7797
7798 return 0;
7799}
7800
Johannes Bergff1b6e62011-05-04 15:37:28 +02007801static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7802{
7803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7804 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007805 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007806 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007807 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7808 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007809 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007810
Johannes Berg2a0e0472013-01-23 22:57:40 +01007811 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7812 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007813 return -EOPNOTSUPP;
7814
Johannes Bergae33bd82012-07-12 16:25:02 +02007815 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7816 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007817 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007818 goto set_wakeup;
7819 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007820
7821 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7822 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7823 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7824 nl80211_wowlan_policy);
7825 if (err)
7826 return err;
7827
7828 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7829 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7830 return -EINVAL;
7831 new_triggers.any = true;
7832 }
7833
7834 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7835 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7836 return -EINVAL;
7837 new_triggers.disconnect = true;
7838 }
7839
7840 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7841 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7842 return -EINVAL;
7843 new_triggers.magic_pkt = true;
7844 }
7845
Johannes Berg77dbbb132011-07-13 10:48:55 +02007846 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7847 return -EINVAL;
7848
7849 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7850 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7851 return -EINVAL;
7852 new_triggers.gtk_rekey_failure = true;
7853 }
7854
7855 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7856 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7857 return -EINVAL;
7858 new_triggers.eap_identity_req = true;
7859 }
7860
7861 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7862 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7863 return -EINVAL;
7864 new_triggers.four_way_handshake = true;
7865 }
7866
7867 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7868 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7869 return -EINVAL;
7870 new_triggers.rfkill_release = true;
7871 }
7872
Johannes Bergff1b6e62011-05-04 15:37:28 +02007873 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7874 struct nlattr *pat;
7875 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007876 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007877 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7878
7879 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7880 rem)
7881 n_patterns++;
7882 if (n_patterns > wowlan->n_patterns)
7883 return -EINVAL;
7884
7885 new_triggers.patterns = kcalloc(n_patterns,
7886 sizeof(new_triggers.patterns[0]),
7887 GFP_KERNEL);
7888 if (!new_triggers.patterns)
7889 return -ENOMEM;
7890
7891 new_triggers.n_patterns = n_patterns;
7892 i = 0;
7893
7894 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7895 rem) {
7896 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7897 nla_data(pat), nla_len(pat), NULL);
7898 err = -EINVAL;
7899 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7900 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7901 goto error;
7902 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7903 mask_len = DIV_ROUND_UP(pat_len, 8);
7904 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7905 mask_len)
7906 goto error;
7907 if (pat_len > wowlan->pattern_max_len ||
7908 pat_len < wowlan->pattern_min_len)
7909 goto error;
7910
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007911 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7912 pkt_offset = 0;
7913 else
7914 pkt_offset = nla_get_u32(
7915 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7916 if (pkt_offset > wowlan->max_pkt_offset)
7917 goto error;
7918 new_triggers.patterns[i].pkt_offset = pkt_offset;
7919
Johannes Bergff1b6e62011-05-04 15:37:28 +02007920 new_triggers.patterns[i].mask =
7921 kmalloc(mask_len + pat_len, GFP_KERNEL);
7922 if (!new_triggers.patterns[i].mask) {
7923 err = -ENOMEM;
7924 goto error;
7925 }
7926 new_triggers.patterns[i].pattern =
7927 new_triggers.patterns[i].mask + mask_len;
7928 memcpy(new_triggers.patterns[i].mask,
7929 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7930 mask_len);
7931 new_triggers.patterns[i].pattern_len = pat_len;
7932 memcpy(new_triggers.patterns[i].pattern,
7933 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7934 pat_len);
7935 i++;
7936 }
7937 }
7938
Johannes Berg2a0e0472013-01-23 22:57:40 +01007939 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7940 err = nl80211_parse_wowlan_tcp(
7941 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7942 &new_triggers);
7943 if (err)
7944 goto error;
7945 }
7946
Johannes Bergae33bd82012-07-12 16:25:02 +02007947 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7948 if (!ntrig) {
7949 err = -ENOMEM;
7950 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007951 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007952 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007953 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007954
Johannes Bergae33bd82012-07-12 16:25:02 +02007955 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007956 if (rdev->ops->set_wakeup &&
7957 prev_enabled != !!rdev->wiphy.wowlan_config)
7958 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02007959
Johannes Bergff1b6e62011-05-04 15:37:28 +02007960 return 0;
7961 error:
7962 for (i = 0; i < new_triggers.n_patterns; i++)
7963 kfree(new_triggers.patterns[i].mask);
7964 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007965 if (new_triggers.tcp && new_triggers.tcp->sock)
7966 sock_release(new_triggers.tcp->sock);
7967 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007968 return err;
7969}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007970#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007971
Johannes Berge5497d72011-07-05 16:35:40 +02007972static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7973{
7974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7975 struct net_device *dev = info->user_ptr[1];
7976 struct wireless_dev *wdev = dev->ieee80211_ptr;
7977 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7978 struct cfg80211_gtk_rekey_data rekey_data;
7979 int err;
7980
7981 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7982 return -EINVAL;
7983
7984 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7985 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7986 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7987 nl80211_rekey_policy);
7988 if (err)
7989 return err;
7990
7991 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7992 return -ERANGE;
7993 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7994 return -ERANGE;
7995 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7996 return -ERANGE;
7997
7998 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7999 NL80211_KEK_LEN);
8000 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8001 NL80211_KCK_LEN);
8002 memcpy(rekey_data.replay_ctr,
8003 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8004 NL80211_REPLAY_CTR_LEN);
8005
8006 wdev_lock(wdev);
8007 if (!wdev->current_bss) {
8008 err = -ENOTCONN;
8009 goto out;
8010 }
8011
8012 if (!rdev->ops->set_rekey_data) {
8013 err = -EOPNOTSUPP;
8014 goto out;
8015 }
8016
Hila Gonene35e4d22012-06-27 17:19:42 +03008017 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008018 out:
8019 wdev_unlock(wdev);
8020 return err;
8021}
8022
Johannes Berg28946da2011-11-04 11:18:12 +01008023static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8024 struct genl_info *info)
8025{
8026 struct net_device *dev = info->user_ptr[1];
8027 struct wireless_dev *wdev = dev->ieee80211_ptr;
8028
8029 if (wdev->iftype != NL80211_IFTYPE_AP &&
8030 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8031 return -EINVAL;
8032
Eric W. Biederman15e47302012-09-07 20:12:54 +00008033 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008034 return -EBUSY;
8035
Eric W. Biederman15e47302012-09-07 20:12:54 +00008036 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008037 return 0;
8038}
8039
Johannes Berg7f6cf312011-11-04 11:18:15 +01008040static int nl80211_probe_client(struct sk_buff *skb,
8041 struct genl_info *info)
8042{
8043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8044 struct net_device *dev = info->user_ptr[1];
8045 struct wireless_dev *wdev = dev->ieee80211_ptr;
8046 struct sk_buff *msg;
8047 void *hdr;
8048 const u8 *addr;
8049 u64 cookie;
8050 int err;
8051
8052 if (wdev->iftype != NL80211_IFTYPE_AP &&
8053 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8054 return -EOPNOTSUPP;
8055
8056 if (!info->attrs[NL80211_ATTR_MAC])
8057 return -EINVAL;
8058
8059 if (!rdev->ops->probe_client)
8060 return -EOPNOTSUPP;
8061
8062 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8063 if (!msg)
8064 return -ENOMEM;
8065
Eric W. Biederman15e47302012-09-07 20:12:54 +00008066 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008067 NL80211_CMD_PROBE_CLIENT);
8068
8069 if (IS_ERR(hdr)) {
8070 err = PTR_ERR(hdr);
8071 goto free_msg;
8072 }
8073
8074 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8075
Hila Gonene35e4d22012-06-27 17:19:42 +03008076 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008077 if (err)
8078 goto free_msg;
8079
David S. Miller9360ffd2012-03-29 04:41:26 -04008080 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8081 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008082
8083 genlmsg_end(msg, hdr);
8084
8085 return genlmsg_reply(msg, info);
8086
8087 nla_put_failure:
8088 err = -ENOBUFS;
8089 free_msg:
8090 nlmsg_free(msg);
8091 return err;
8092}
8093
Johannes Berg5e760232011-11-04 11:18:17 +01008094static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8095{
8096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008097 struct cfg80211_beacon_registration *reg, *nreg;
8098 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008099
8100 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8101 return -EOPNOTSUPP;
8102
Ben Greear37c73b52012-10-26 14:49:25 -07008103 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8104 if (!nreg)
8105 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008106
Ben Greear37c73b52012-10-26 14:49:25 -07008107 /* First, check if already registered. */
8108 spin_lock_bh(&rdev->beacon_registrations_lock);
8109 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8110 if (reg->nlportid == info->snd_portid) {
8111 rv = -EALREADY;
8112 goto out_err;
8113 }
8114 }
8115 /* Add it to the list */
8116 nreg->nlportid = info->snd_portid;
8117 list_add(&nreg->list, &rdev->beacon_registrations);
8118
8119 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008120
8121 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008122out_err:
8123 spin_unlock_bh(&rdev->beacon_registrations_lock);
8124 kfree(nreg);
8125 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008126}
8127
Johannes Berg98104fde2012-06-16 00:19:54 +02008128static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8129{
8130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8131 struct wireless_dev *wdev = info->user_ptr[1];
8132 int err;
8133
8134 if (!rdev->ops->start_p2p_device)
8135 return -EOPNOTSUPP;
8136
8137 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8138 return -EOPNOTSUPP;
8139
8140 if (wdev->p2p_started)
8141 return 0;
8142
Johannes Berg98104fde2012-06-16 00:19:54 +02008143 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008144 if (err)
8145 return err;
8146
Johannes Bergeeb126e2012-10-23 15:16:50 +02008147 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008148 if (err)
8149 return err;
8150
8151 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008152 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008153
8154 return 0;
8155}
8156
8157static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8158{
8159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8160 struct wireless_dev *wdev = info->user_ptr[1];
8161
8162 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8163 return -EOPNOTSUPP;
8164
8165 if (!rdev->ops->stop_p2p_device)
8166 return -EOPNOTSUPP;
8167
Johannes Bergf9f47522013-03-19 15:04:07 +01008168 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008169
8170 return 0;
8171}
8172
Johannes Berg3713b4e2013-02-14 16:19:38 +01008173static int nl80211_get_protocol_features(struct sk_buff *skb,
8174 struct genl_info *info)
8175{
8176 void *hdr;
8177 struct sk_buff *msg;
8178
8179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8180 if (!msg)
8181 return -ENOMEM;
8182
8183 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8184 NL80211_CMD_GET_PROTOCOL_FEATURES);
8185 if (!hdr)
8186 goto nla_put_failure;
8187
8188 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8189 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8190 goto nla_put_failure;
8191
8192 genlmsg_end(msg, hdr);
8193 return genlmsg_reply(msg, info);
8194
8195 nla_put_failure:
8196 kfree_skb(msg);
8197 return -ENOBUFS;
8198}
8199
Jouni Malinen355199e2013-02-27 17:14:27 +02008200static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8201{
8202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8203 struct cfg80211_update_ft_ies_params ft_params;
8204 struct net_device *dev = info->user_ptr[1];
8205
8206 if (!rdev->ops->update_ft_ies)
8207 return -EOPNOTSUPP;
8208
8209 if (!info->attrs[NL80211_ATTR_MDID] ||
8210 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8211 return -EINVAL;
8212
8213 memset(&ft_params, 0, sizeof(ft_params));
8214 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8215 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8216 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8217
8218 return rdev_update_ft_ies(rdev, dev, &ft_params);
8219}
8220
Arend van Spriel5de17982013-04-18 15:49:00 +02008221static int nl80211_crit_protocol_start(struct sk_buff *skb,
8222 struct genl_info *info)
8223{
8224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8225 struct wireless_dev *wdev = info->user_ptr[1];
8226 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8227 u16 duration;
8228 int ret;
8229
8230 if (!rdev->ops->crit_proto_start)
8231 return -EOPNOTSUPP;
8232
8233 if (WARN_ON(!rdev->ops->crit_proto_stop))
8234 return -EINVAL;
8235
8236 if (rdev->crit_proto_nlportid)
8237 return -EBUSY;
8238
8239 /* determine protocol if provided */
8240 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8241 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8242
8243 if (proto >= NUM_NL80211_CRIT_PROTO)
8244 return -EINVAL;
8245
8246 /* timeout must be provided */
8247 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8248 return -EINVAL;
8249
8250 duration =
8251 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8252
8253 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8254 return -ERANGE;
8255
8256 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8257 if (!ret)
8258 rdev->crit_proto_nlportid = info->snd_portid;
8259
8260 return ret;
8261}
8262
8263static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8264 struct genl_info *info)
8265{
8266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8267 struct wireless_dev *wdev = info->user_ptr[1];
8268
8269 if (!rdev->ops->crit_proto_stop)
8270 return -EOPNOTSUPP;
8271
8272 if (rdev->crit_proto_nlportid) {
8273 rdev->crit_proto_nlportid = 0;
8274 rdev_crit_proto_stop(rdev, wdev);
8275 }
8276 return 0;
8277}
8278
Johannes Berg4c476992010-10-04 21:36:35 +02008279#define NL80211_FLAG_NEED_WIPHY 0x01
8280#define NL80211_FLAG_NEED_NETDEV 0x02
8281#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008282#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8283#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8284 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008285#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008286/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008287#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8288 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008289
8290static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8291 struct genl_info *info)
8292{
8293 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008294 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008295 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008296 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8297
8298 if (rtnl)
8299 rtnl_lock();
8300
8301 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008302 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008303 if (IS_ERR(rdev)) {
8304 if (rtnl)
8305 rtnl_unlock();
8306 return PTR_ERR(rdev);
8307 }
8308 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008309 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8310 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008311 ASSERT_RTNL();
8312
Johannes Berg89a54e42012-06-15 14:33:17 +02008313 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8314 info->attrs);
8315 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008316 if (rtnl)
8317 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008318 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008319 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008320
Johannes Berg89a54e42012-06-15 14:33:17 +02008321 dev = wdev->netdev;
8322 rdev = wiphy_to_dev(wdev->wiphy);
8323
Johannes Berg1bf614e2012-06-15 15:23:36 +02008324 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8325 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008326 if (rtnl)
8327 rtnl_unlock();
8328 return -EINVAL;
8329 }
8330
8331 info->user_ptr[1] = dev;
8332 } else {
8333 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008334 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008335
Johannes Berg1bf614e2012-06-15 15:23:36 +02008336 if (dev) {
8337 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8338 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008339 if (rtnl)
8340 rtnl_unlock();
8341 return -ENETDOWN;
8342 }
8343
8344 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008345 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8346 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008347 if (rtnl)
8348 rtnl_unlock();
8349 return -ENETDOWN;
8350 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008351 }
8352
Johannes Berg4c476992010-10-04 21:36:35 +02008353 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008354 }
8355
8356 return 0;
8357}
8358
8359static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8360 struct genl_info *info)
8361{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008362 if (info->user_ptr[1]) {
8363 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8364 struct wireless_dev *wdev = info->user_ptr[1];
8365
8366 if (wdev->netdev)
8367 dev_put(wdev->netdev);
8368 } else {
8369 dev_put(info->user_ptr[1]);
8370 }
8371 }
Johannes Berg4c476992010-10-04 21:36:35 +02008372 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8373 rtnl_unlock();
8374}
8375
Johannes Berg55682962007-09-20 13:09:35 -04008376static struct genl_ops nl80211_ops[] = {
8377 {
8378 .cmd = NL80211_CMD_GET_WIPHY,
8379 .doit = nl80211_get_wiphy,
8380 .dumpit = nl80211_dump_wiphy,
8381 .policy = nl80211_policy,
8382 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008383 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8384 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008385 },
8386 {
8387 .cmd = NL80211_CMD_SET_WIPHY,
8388 .doit = nl80211_set_wiphy,
8389 .policy = nl80211_policy,
8390 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008391 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008392 },
8393 {
8394 .cmd = NL80211_CMD_GET_INTERFACE,
8395 .doit = nl80211_get_interface,
8396 .dumpit = nl80211_dump_interface,
8397 .policy = nl80211_policy,
8398 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008399 .internal_flags = NL80211_FLAG_NEED_WDEV |
8400 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008401 },
8402 {
8403 .cmd = NL80211_CMD_SET_INTERFACE,
8404 .doit = nl80211_set_interface,
8405 .policy = nl80211_policy,
8406 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008407 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8408 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008409 },
8410 {
8411 .cmd = NL80211_CMD_NEW_INTERFACE,
8412 .doit = nl80211_new_interface,
8413 .policy = nl80211_policy,
8414 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008415 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8416 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008417 },
8418 {
8419 .cmd = NL80211_CMD_DEL_INTERFACE,
8420 .doit = nl80211_del_interface,
8421 .policy = nl80211_policy,
8422 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008423 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008424 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008425 },
Johannes Berg41ade002007-12-19 02:03:29 +01008426 {
8427 .cmd = NL80211_CMD_GET_KEY,
8428 .doit = nl80211_get_key,
8429 .policy = nl80211_policy,
8430 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008432 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008433 },
8434 {
8435 .cmd = NL80211_CMD_SET_KEY,
8436 .doit = nl80211_set_key,
8437 .policy = nl80211_policy,
8438 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008440 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008441 },
8442 {
8443 .cmd = NL80211_CMD_NEW_KEY,
8444 .doit = nl80211_new_key,
8445 .policy = nl80211_policy,
8446 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008448 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008449 },
8450 {
8451 .cmd = NL80211_CMD_DEL_KEY,
8452 .doit = nl80211_del_key,
8453 .policy = nl80211_policy,
8454 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008456 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008457 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008458 {
8459 .cmd = NL80211_CMD_SET_BEACON,
8460 .policy = nl80211_policy,
8461 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008462 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008464 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008465 },
8466 {
Johannes Berg88600202012-02-13 15:17:18 +01008467 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008468 .policy = nl80211_policy,
8469 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008470 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008472 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008473 },
8474 {
Johannes Berg88600202012-02-13 15:17:18 +01008475 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008476 .policy = nl80211_policy,
8477 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008478 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008480 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008481 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008482 {
8483 .cmd = NL80211_CMD_GET_STATION,
8484 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008485 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008486 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008487 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8488 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008489 },
8490 {
8491 .cmd = NL80211_CMD_SET_STATION,
8492 .doit = nl80211_set_station,
8493 .policy = nl80211_policy,
8494 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008496 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008497 },
8498 {
8499 .cmd = NL80211_CMD_NEW_STATION,
8500 .doit = nl80211_new_station,
8501 .policy = nl80211_policy,
8502 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008503 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008504 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008505 },
8506 {
8507 .cmd = NL80211_CMD_DEL_STATION,
8508 .doit = nl80211_del_station,
8509 .policy = nl80211_policy,
8510 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008511 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008512 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008513 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008514 {
8515 .cmd = NL80211_CMD_GET_MPATH,
8516 .doit = nl80211_get_mpath,
8517 .dumpit = nl80211_dump_mpath,
8518 .policy = nl80211_policy,
8519 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008521 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008522 },
8523 {
8524 .cmd = NL80211_CMD_SET_MPATH,
8525 .doit = nl80211_set_mpath,
8526 .policy = nl80211_policy,
8527 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008529 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008530 },
8531 {
8532 .cmd = NL80211_CMD_NEW_MPATH,
8533 .doit = nl80211_new_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008538 },
8539 {
8540 .cmd = NL80211_CMD_DEL_MPATH,
8541 .doit = nl80211_del_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008546 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008547 {
8548 .cmd = NL80211_CMD_SET_BSS,
8549 .doit = nl80211_set_bss,
8550 .policy = nl80211_policy,
8551 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008552 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008553 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008554 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008555 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008556 .cmd = NL80211_CMD_GET_REG,
8557 .doit = nl80211_get_reg,
8558 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008559 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008560 /* can be retrieved by unprivileged users */
8561 },
8562 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008563 .cmd = NL80211_CMD_SET_REG,
8564 .doit = nl80211_set_reg,
8565 .policy = nl80211_policy,
8566 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008567 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008568 },
8569 {
8570 .cmd = NL80211_CMD_REQ_SET_REG,
8571 .doit = nl80211_req_set_reg,
8572 .policy = nl80211_policy,
8573 .flags = GENL_ADMIN_PERM,
8574 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008575 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008576 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8577 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008578 .policy = nl80211_policy,
8579 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008580 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008581 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008582 },
8583 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008584 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8585 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008586 .policy = nl80211_policy,
8587 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008588 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008589 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008590 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008591 {
Johannes Berg2a519312009-02-10 21:25:55 +01008592 .cmd = NL80211_CMD_TRIGGER_SCAN,
8593 .doit = nl80211_trigger_scan,
8594 .policy = nl80211_policy,
8595 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008596 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008597 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008598 },
8599 {
8600 .cmd = NL80211_CMD_GET_SCAN,
8601 .policy = nl80211_policy,
8602 .dumpit = nl80211_dump_scan,
8603 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008604 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008605 .cmd = NL80211_CMD_START_SCHED_SCAN,
8606 .doit = nl80211_start_sched_scan,
8607 .policy = nl80211_policy,
8608 .flags = GENL_ADMIN_PERM,
8609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8610 NL80211_FLAG_NEED_RTNL,
8611 },
8612 {
8613 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8614 .doit = nl80211_stop_sched_scan,
8615 .policy = nl80211_policy,
8616 .flags = GENL_ADMIN_PERM,
8617 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8618 NL80211_FLAG_NEED_RTNL,
8619 },
8620 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008621 .cmd = NL80211_CMD_AUTHENTICATE,
8622 .doit = nl80211_authenticate,
8623 .policy = nl80211_policy,
8624 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008625 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008626 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008627 },
8628 {
8629 .cmd = NL80211_CMD_ASSOCIATE,
8630 .doit = nl80211_associate,
8631 .policy = nl80211_policy,
8632 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008634 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008635 },
8636 {
8637 .cmd = NL80211_CMD_DEAUTHENTICATE,
8638 .doit = nl80211_deauthenticate,
8639 .policy = nl80211_policy,
8640 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008642 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008643 },
8644 {
8645 .cmd = NL80211_CMD_DISASSOCIATE,
8646 .doit = nl80211_disassociate,
8647 .policy = nl80211_policy,
8648 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008649 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008650 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008651 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008652 {
8653 .cmd = NL80211_CMD_JOIN_IBSS,
8654 .doit = nl80211_join_ibss,
8655 .policy = nl80211_policy,
8656 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008658 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008659 },
8660 {
8661 .cmd = NL80211_CMD_LEAVE_IBSS,
8662 .doit = nl80211_leave_ibss,
8663 .policy = nl80211_policy,
8664 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008665 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008666 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008667 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008668#ifdef CONFIG_NL80211_TESTMODE
8669 {
8670 .cmd = NL80211_CMD_TESTMODE,
8671 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008672 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008673 .policy = nl80211_policy,
8674 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008675 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8676 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008677 },
8678#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008679 {
8680 .cmd = NL80211_CMD_CONNECT,
8681 .doit = nl80211_connect,
8682 .policy = nl80211_policy,
8683 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008685 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008686 },
8687 {
8688 .cmd = NL80211_CMD_DISCONNECT,
8689 .doit = nl80211_disconnect,
8690 .policy = nl80211_policy,
8691 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008693 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008694 },
Johannes Berg463d0182009-07-14 00:33:35 +02008695 {
8696 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8697 .doit = nl80211_wiphy_netns,
8698 .policy = nl80211_policy,
8699 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008700 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8701 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008702 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008703 {
8704 .cmd = NL80211_CMD_GET_SURVEY,
8705 .policy = nl80211_policy,
8706 .dumpit = nl80211_dump_survey,
8707 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008708 {
8709 .cmd = NL80211_CMD_SET_PMKSA,
8710 .doit = nl80211_setdel_pmksa,
8711 .policy = nl80211_policy,
8712 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008714 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008715 },
8716 {
8717 .cmd = NL80211_CMD_DEL_PMKSA,
8718 .doit = nl80211_setdel_pmksa,
8719 .policy = nl80211_policy,
8720 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008721 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008722 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008723 },
8724 {
8725 .cmd = NL80211_CMD_FLUSH_PMKSA,
8726 .doit = nl80211_flush_pmksa,
8727 .policy = nl80211_policy,
8728 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008729 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008730 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008731 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008732 {
8733 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8734 .doit = nl80211_remain_on_channel,
8735 .policy = nl80211_policy,
8736 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008737 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008738 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008739 },
8740 {
8741 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8742 .doit = nl80211_cancel_remain_on_channel,
8743 .policy = nl80211_policy,
8744 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008745 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008746 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008747 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008748 {
8749 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8750 .doit = nl80211_set_tx_bitrate_mask,
8751 .policy = nl80211_policy,
8752 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008753 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8754 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008755 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008756 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008757 .cmd = NL80211_CMD_REGISTER_FRAME,
8758 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008759 .policy = nl80211_policy,
8760 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008761 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008762 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008763 },
8764 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008765 .cmd = NL80211_CMD_FRAME,
8766 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008767 .policy = nl80211_policy,
8768 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008769 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008770 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008771 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008772 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008773 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8774 .doit = nl80211_tx_mgmt_cancel_wait,
8775 .policy = nl80211_policy,
8776 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008777 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008778 NL80211_FLAG_NEED_RTNL,
8779 },
8780 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008781 .cmd = NL80211_CMD_SET_POWER_SAVE,
8782 .doit = nl80211_set_power_save,
8783 .policy = nl80211_policy,
8784 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008785 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8786 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008787 },
8788 {
8789 .cmd = NL80211_CMD_GET_POWER_SAVE,
8790 .doit = nl80211_get_power_save,
8791 .policy = nl80211_policy,
8792 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008793 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8794 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008795 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008796 {
8797 .cmd = NL80211_CMD_SET_CQM,
8798 .doit = nl80211_set_cqm,
8799 .policy = nl80211_policy,
8800 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008801 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8802 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008803 },
Johannes Bergf444de02010-05-05 15:25:02 +02008804 {
8805 .cmd = NL80211_CMD_SET_CHANNEL,
8806 .doit = nl80211_set_channel,
8807 .policy = nl80211_policy,
8808 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008809 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8810 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008811 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008812 {
8813 .cmd = NL80211_CMD_SET_WDS_PEER,
8814 .doit = nl80211_set_wds_peer,
8815 .policy = nl80211_policy,
8816 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008817 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8818 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008819 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008820 {
8821 .cmd = NL80211_CMD_JOIN_MESH,
8822 .doit = nl80211_join_mesh,
8823 .policy = nl80211_policy,
8824 .flags = GENL_ADMIN_PERM,
8825 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8826 NL80211_FLAG_NEED_RTNL,
8827 },
8828 {
8829 .cmd = NL80211_CMD_LEAVE_MESH,
8830 .doit = nl80211_leave_mesh,
8831 .policy = nl80211_policy,
8832 .flags = GENL_ADMIN_PERM,
8833 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8834 NL80211_FLAG_NEED_RTNL,
8835 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008836#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008837 {
8838 .cmd = NL80211_CMD_GET_WOWLAN,
8839 .doit = nl80211_get_wowlan,
8840 .policy = nl80211_policy,
8841 /* can be retrieved by unprivileged users */
8842 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8843 NL80211_FLAG_NEED_RTNL,
8844 },
8845 {
8846 .cmd = NL80211_CMD_SET_WOWLAN,
8847 .doit = nl80211_set_wowlan,
8848 .policy = nl80211_policy,
8849 .flags = GENL_ADMIN_PERM,
8850 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8851 NL80211_FLAG_NEED_RTNL,
8852 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008853#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008854 {
8855 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8856 .doit = nl80211_set_rekey_data,
8857 .policy = nl80211_policy,
8858 .flags = GENL_ADMIN_PERM,
8859 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8860 NL80211_FLAG_NEED_RTNL,
8861 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008862 {
8863 .cmd = NL80211_CMD_TDLS_MGMT,
8864 .doit = nl80211_tdls_mgmt,
8865 .policy = nl80211_policy,
8866 .flags = GENL_ADMIN_PERM,
8867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8868 NL80211_FLAG_NEED_RTNL,
8869 },
8870 {
8871 .cmd = NL80211_CMD_TDLS_OPER,
8872 .doit = nl80211_tdls_oper,
8873 .policy = nl80211_policy,
8874 .flags = GENL_ADMIN_PERM,
8875 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8876 NL80211_FLAG_NEED_RTNL,
8877 },
Johannes Berg28946da2011-11-04 11:18:12 +01008878 {
8879 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8880 .doit = nl80211_register_unexpected_frame,
8881 .policy = nl80211_policy,
8882 .flags = GENL_ADMIN_PERM,
8883 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8884 NL80211_FLAG_NEED_RTNL,
8885 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008886 {
8887 .cmd = NL80211_CMD_PROBE_CLIENT,
8888 .doit = nl80211_probe_client,
8889 .policy = nl80211_policy,
8890 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008891 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008892 NL80211_FLAG_NEED_RTNL,
8893 },
Johannes Berg5e760232011-11-04 11:18:17 +01008894 {
8895 .cmd = NL80211_CMD_REGISTER_BEACONS,
8896 .doit = nl80211_register_beacons,
8897 .policy = nl80211_policy,
8898 .flags = GENL_ADMIN_PERM,
8899 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8900 NL80211_FLAG_NEED_RTNL,
8901 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008902 {
8903 .cmd = NL80211_CMD_SET_NOACK_MAP,
8904 .doit = nl80211_set_noack_map,
8905 .policy = nl80211_policy,
8906 .flags = GENL_ADMIN_PERM,
8907 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8908 NL80211_FLAG_NEED_RTNL,
8909 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008910 {
8911 .cmd = NL80211_CMD_START_P2P_DEVICE,
8912 .doit = nl80211_start_p2p_device,
8913 .policy = nl80211_policy,
8914 .flags = GENL_ADMIN_PERM,
8915 .internal_flags = NL80211_FLAG_NEED_WDEV |
8916 NL80211_FLAG_NEED_RTNL,
8917 },
8918 {
8919 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8920 .doit = nl80211_stop_p2p_device,
8921 .policy = nl80211_policy,
8922 .flags = GENL_ADMIN_PERM,
8923 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8924 NL80211_FLAG_NEED_RTNL,
8925 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008926 {
8927 .cmd = NL80211_CMD_SET_MCAST_RATE,
8928 .doit = nl80211_set_mcast_rate,
8929 .policy = nl80211_policy,
8930 .flags = GENL_ADMIN_PERM,
8931 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8932 NL80211_FLAG_NEED_RTNL,
8933 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308934 {
8935 .cmd = NL80211_CMD_SET_MAC_ACL,
8936 .doit = nl80211_set_mac_acl,
8937 .policy = nl80211_policy,
8938 .flags = GENL_ADMIN_PERM,
8939 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8940 NL80211_FLAG_NEED_RTNL,
8941 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008942 {
8943 .cmd = NL80211_CMD_RADAR_DETECT,
8944 .doit = nl80211_start_radar_detection,
8945 .policy = nl80211_policy,
8946 .flags = GENL_ADMIN_PERM,
8947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8948 NL80211_FLAG_NEED_RTNL,
8949 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008950 {
8951 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8952 .doit = nl80211_get_protocol_features,
8953 .policy = nl80211_policy,
8954 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008955 {
8956 .cmd = NL80211_CMD_UPDATE_FT_IES,
8957 .doit = nl80211_update_ft_ies,
8958 .policy = nl80211_policy,
8959 .flags = GENL_ADMIN_PERM,
8960 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8961 NL80211_FLAG_NEED_RTNL,
8962 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008963 {
8964 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8965 .doit = nl80211_crit_protocol_start,
8966 .policy = nl80211_policy,
8967 .flags = GENL_ADMIN_PERM,
8968 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8969 NL80211_FLAG_NEED_RTNL,
8970 },
8971 {
8972 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
8973 .doit = nl80211_crit_protocol_stop,
8974 .policy = nl80211_policy,
8975 .flags = GENL_ADMIN_PERM,
8976 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8977 NL80211_FLAG_NEED_RTNL,
8978 }
Johannes Berg55682962007-09-20 13:09:35 -04008979};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008980
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008981static struct genl_multicast_group nl80211_mlme_mcgrp = {
8982 .name = "mlme",
8983};
Johannes Berg55682962007-09-20 13:09:35 -04008984
8985/* multicast groups */
8986static struct genl_multicast_group nl80211_config_mcgrp = {
8987 .name = "config",
8988};
Johannes Berg2a519312009-02-10 21:25:55 +01008989static struct genl_multicast_group nl80211_scan_mcgrp = {
8990 .name = "scan",
8991};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008992static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8993 .name = "regulatory",
8994};
Johannes Berg55682962007-09-20 13:09:35 -04008995
8996/* notification functions */
8997
8998void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8999{
9000 struct sk_buff *msg;
9001
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009003 if (!msg)
9004 return;
9005
Johannes Berg3713b4e2013-02-14 16:19:38 +01009006 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
9007 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009008 nlmsg_free(msg);
9009 return;
9010 }
9011
Johannes Berg463d0182009-07-14 00:33:35 +02009012 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9013 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009014}
9015
Johannes Berg362a4152009-05-24 16:43:15 +02009016static int nl80211_add_scan_req(struct sk_buff *msg,
9017 struct cfg80211_registered_device *rdev)
9018{
9019 struct cfg80211_scan_request *req = rdev->scan_req;
9020 struct nlattr *nest;
9021 int i;
9022
9023 if (WARN_ON(!req))
9024 return 0;
9025
9026 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9027 if (!nest)
9028 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009029 for (i = 0; i < req->n_ssids; i++) {
9030 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9031 goto nla_put_failure;
9032 }
Johannes Berg362a4152009-05-24 16:43:15 +02009033 nla_nest_end(msg, nest);
9034
9035 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9036 if (!nest)
9037 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009038 for (i = 0; i < req->n_channels; i++) {
9039 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9040 goto nla_put_failure;
9041 }
Johannes Berg362a4152009-05-24 16:43:15 +02009042 nla_nest_end(msg, nest);
9043
David S. Miller9360ffd2012-03-29 04:41:26 -04009044 if (req->ie &&
9045 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9046 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009047
Sam Lefflered4737712012-10-11 21:03:31 -07009048 if (req->flags)
9049 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9050
Johannes Berg362a4152009-05-24 16:43:15 +02009051 return 0;
9052 nla_put_failure:
9053 return -ENOBUFS;
9054}
9055
Johannes Berga538e2d2009-06-16 19:56:42 +02009056static int nl80211_send_scan_msg(struct sk_buff *msg,
9057 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009058 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009059 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009060 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009061{
9062 void *hdr;
9063
Eric W. Biederman15e47302012-09-07 20:12:54 +00009064 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009065 if (!hdr)
9066 return -1;
9067
David S. Miller9360ffd2012-03-29 04:41:26 -04009068 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009069 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9070 wdev->netdev->ifindex)) ||
9071 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009072 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009073
Johannes Berg362a4152009-05-24 16:43:15 +02009074 /* ignore errors and send incomplete event anyway */
9075 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009076
9077 return genlmsg_end(msg, hdr);
9078
9079 nla_put_failure:
9080 genlmsg_cancel(msg, hdr);
9081 return -EMSGSIZE;
9082}
9083
Luciano Coelho807f8a82011-05-11 17:09:35 +03009084static int
9085nl80211_send_sched_scan_msg(struct sk_buff *msg,
9086 struct cfg80211_registered_device *rdev,
9087 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009088 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009089{
9090 void *hdr;
9091
Eric W. Biederman15e47302012-09-07 20:12:54 +00009092 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009093 if (!hdr)
9094 return -1;
9095
David S. Miller9360ffd2012-03-29 04:41:26 -04009096 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9097 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9098 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009099
9100 return genlmsg_end(msg, hdr);
9101
9102 nla_put_failure:
9103 genlmsg_cancel(msg, hdr);
9104 return -EMSGSIZE;
9105}
9106
Johannes Berga538e2d2009-06-16 19:56:42 +02009107void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009108 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009109{
9110 struct sk_buff *msg;
9111
Thomas Graf58050fc2012-06-28 03:57:45 +00009112 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009113 if (!msg)
9114 return;
9115
Johannes Bergfd014282012-06-18 19:17:03 +02009116 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009117 NL80211_CMD_TRIGGER_SCAN) < 0) {
9118 nlmsg_free(msg);
9119 return;
9120 }
9121
Johannes Berg463d0182009-07-14 00:33:35 +02009122 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9123 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009124}
9125
Johannes Berg2a519312009-02-10 21:25:55 +01009126void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009127 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009128{
9129 struct sk_buff *msg;
9130
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009131 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009132 if (!msg)
9133 return;
9134
Johannes Bergfd014282012-06-18 19:17:03 +02009135 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009136 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009137 nlmsg_free(msg);
9138 return;
9139 }
9140
Johannes Berg463d0182009-07-14 00:33:35 +02009141 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9142 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009143}
9144
9145void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009146 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009147{
9148 struct sk_buff *msg;
9149
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009151 if (!msg)
9152 return;
9153
Johannes Bergfd014282012-06-18 19:17:03 +02009154 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009155 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009156 nlmsg_free(msg);
9157 return;
9158 }
9159
Johannes Berg463d0182009-07-14 00:33:35 +02009160 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9161 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009162}
9163
Luciano Coelho807f8a82011-05-11 17:09:35 +03009164void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9165 struct net_device *netdev)
9166{
9167 struct sk_buff *msg;
9168
9169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9170 if (!msg)
9171 return;
9172
9173 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9174 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9175 nlmsg_free(msg);
9176 return;
9177 }
9178
9179 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9180 nl80211_scan_mcgrp.id, GFP_KERNEL);
9181}
9182
9183void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9184 struct net_device *netdev, u32 cmd)
9185{
9186 struct sk_buff *msg;
9187
Thomas Graf58050fc2012-06-28 03:57:45 +00009188 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009189 if (!msg)
9190 return;
9191
9192 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9193 nlmsg_free(msg);
9194 return;
9195 }
9196
9197 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9198 nl80211_scan_mcgrp.id, GFP_KERNEL);
9199}
9200
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009201/*
9202 * This can happen on global regulatory changes or device specific settings
9203 * based on custom world regulatory domains.
9204 */
9205void nl80211_send_reg_change_event(struct regulatory_request *request)
9206{
9207 struct sk_buff *msg;
9208 void *hdr;
9209
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009211 if (!msg)
9212 return;
9213
9214 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9215 if (!hdr) {
9216 nlmsg_free(msg);
9217 return;
9218 }
9219
9220 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009221 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9222 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009223
David S. Miller9360ffd2012-03-29 04:41:26 -04009224 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9225 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9226 NL80211_REGDOM_TYPE_WORLD))
9227 goto nla_put_failure;
9228 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9229 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9230 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9231 goto nla_put_failure;
9232 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9233 request->intersect) {
9234 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9235 NL80211_REGDOM_TYPE_INTERSECTION))
9236 goto nla_put_failure;
9237 } else {
9238 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9239 NL80211_REGDOM_TYPE_COUNTRY) ||
9240 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9241 request->alpha2))
9242 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009243 }
9244
Johannes Bergf4173762012-12-03 18:23:37 +01009245 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009246 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9247 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009248
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009249 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009250
Johannes Bergbc43b282009-07-25 10:54:13 +02009251 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009252 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009253 GFP_ATOMIC);
9254 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009255
9256 return;
9257
9258nla_put_failure:
9259 genlmsg_cancel(msg, hdr);
9260 nlmsg_free(msg);
9261}
9262
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009263static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9264 struct net_device *netdev,
9265 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009266 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009267{
9268 struct sk_buff *msg;
9269 void *hdr;
9270
Johannes Berge6d6e342009-07-01 21:26:47 +02009271 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009272 if (!msg)
9273 return;
9274
9275 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9276 if (!hdr) {
9277 nlmsg_free(msg);
9278 return;
9279 }
9280
David S. Miller9360ffd2012-03-29 04:41:26 -04009281 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9282 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9283 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9284 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009285
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009286 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009287
Johannes Berg463d0182009-07-14 00:33:35 +02009288 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9289 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009290 return;
9291
9292 nla_put_failure:
9293 genlmsg_cancel(msg, hdr);
9294 nlmsg_free(msg);
9295}
9296
9297void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009298 struct net_device *netdev, const u8 *buf,
9299 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009300{
9301 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009302 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009303}
9304
9305void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9306 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009307 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009308{
Johannes Berge6d6e342009-07-01 21:26:47 +02009309 nl80211_send_mlme_event(rdev, netdev, buf, len,
9310 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009311}
9312
Jouni Malinen53b46b82009-03-27 20:53:56 +02009313void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009314 struct net_device *netdev, const u8 *buf,
9315 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009316{
9317 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009318 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009319}
9320
Jouni Malinen53b46b82009-03-27 20:53:56 +02009321void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9322 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009323 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009324{
9325 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009326 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009327}
9328
Johannes Berg947add32013-02-22 22:05:20 +01009329void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9330 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009331{
Johannes Berg947add32013-02-22 22:05:20 +01009332 struct wireless_dev *wdev = dev->ieee80211_ptr;
9333 struct wiphy *wiphy = wdev->wiphy;
9334 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009335
Johannes Berg947add32013-02-22 22:05:20 +01009336 trace_cfg80211_send_unprot_deauth(dev);
9337 nl80211_send_mlme_event(rdev, dev, buf, len,
9338 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009339}
Johannes Berg947add32013-02-22 22:05:20 +01009340EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9341
9342void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9343 size_t len)
9344{
9345 struct wireless_dev *wdev = dev->ieee80211_ptr;
9346 struct wiphy *wiphy = wdev->wiphy;
9347 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9348
9349 trace_cfg80211_send_unprot_disassoc(dev);
9350 nl80211_send_mlme_event(rdev, dev, buf, len,
9351 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9352}
9353EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009354
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009355static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9356 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009357 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009358{
9359 struct sk_buff *msg;
9360 void *hdr;
9361
Johannes Berge6d6e342009-07-01 21:26:47 +02009362 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009363 if (!msg)
9364 return;
9365
9366 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9367 if (!hdr) {
9368 nlmsg_free(msg);
9369 return;
9370 }
9371
David S. Miller9360ffd2012-03-29 04:41:26 -04009372 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9373 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9374 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9375 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9376 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009377
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009378 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009379
Johannes Berg463d0182009-07-14 00:33:35 +02009380 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9381 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009382 return;
9383
9384 nla_put_failure:
9385 genlmsg_cancel(msg, hdr);
9386 nlmsg_free(msg);
9387}
9388
9389void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009390 struct net_device *netdev, const u8 *addr,
9391 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009392{
9393 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009394 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009395}
9396
9397void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009398 struct net_device *netdev, const u8 *addr,
9399 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009400{
Johannes Berge6d6e342009-07-01 21:26:47 +02009401 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9402 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009403}
9404
Samuel Ortizb23aa672009-07-01 21:26:54 +02009405void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9406 struct net_device *netdev, const u8 *bssid,
9407 const u8 *req_ie, size_t req_ie_len,
9408 const u8 *resp_ie, size_t resp_ie_len,
9409 u16 status, gfp_t gfp)
9410{
9411 struct sk_buff *msg;
9412 void *hdr;
9413
Thomas Graf58050fc2012-06-28 03:57:45 +00009414 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009415 if (!msg)
9416 return;
9417
9418 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9419 if (!hdr) {
9420 nlmsg_free(msg);
9421 return;
9422 }
9423
David S. Miller9360ffd2012-03-29 04:41:26 -04009424 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9426 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9427 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9428 (req_ie &&
9429 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9430 (resp_ie &&
9431 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9432 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009433
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009434 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009435
Johannes Berg463d0182009-07-14 00:33:35 +02009436 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9437 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009438 return;
9439
9440 nla_put_failure:
9441 genlmsg_cancel(msg, hdr);
9442 nlmsg_free(msg);
9443
9444}
9445
9446void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9447 struct net_device *netdev, const u8 *bssid,
9448 const u8 *req_ie, size_t req_ie_len,
9449 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9450{
9451 struct sk_buff *msg;
9452 void *hdr;
9453
Thomas Graf58050fc2012-06-28 03:57:45 +00009454 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009455 if (!msg)
9456 return;
9457
9458 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9459 if (!hdr) {
9460 nlmsg_free(msg);
9461 return;
9462 }
9463
David S. Miller9360ffd2012-03-29 04:41:26 -04009464 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9465 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9466 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9467 (req_ie &&
9468 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9469 (resp_ie &&
9470 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9471 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009472
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009473 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009474
Johannes Berg463d0182009-07-14 00:33:35 +02009475 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9476 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009477 return;
9478
9479 nla_put_failure:
9480 genlmsg_cancel(msg, hdr);
9481 nlmsg_free(msg);
9482
9483}
9484
9485void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9486 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009487 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009488{
9489 struct sk_buff *msg;
9490 void *hdr;
9491
Thomas Graf58050fc2012-06-28 03:57:45 +00009492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009493 if (!msg)
9494 return;
9495
9496 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9497 if (!hdr) {
9498 nlmsg_free(msg);
9499 return;
9500 }
9501
David S. Miller9360ffd2012-03-29 04:41:26 -04009502 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9503 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9504 (from_ap && reason &&
9505 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9506 (from_ap &&
9507 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9508 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9509 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009510
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009511 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009512
Johannes Berg463d0182009-07-14 00:33:35 +02009513 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9514 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009515 return;
9516
9517 nla_put_failure:
9518 genlmsg_cancel(msg, hdr);
9519 nlmsg_free(msg);
9520
9521}
9522
Johannes Berg04a773a2009-04-19 21:24:32 +02009523void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9524 struct net_device *netdev, const u8 *bssid,
9525 gfp_t gfp)
9526{
9527 struct sk_buff *msg;
9528 void *hdr;
9529
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009530 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009531 if (!msg)
9532 return;
9533
9534 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9535 if (!hdr) {
9536 nlmsg_free(msg);
9537 return;
9538 }
9539
David S. Miller9360ffd2012-03-29 04:41:26 -04009540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9542 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9543 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009544
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009545 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009546
Johannes Berg463d0182009-07-14 00:33:35 +02009547 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9548 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009549 return;
9550
9551 nla_put_failure:
9552 genlmsg_cancel(msg, hdr);
9553 nlmsg_free(msg);
9554}
9555
Johannes Berg947add32013-02-22 22:05:20 +01009556void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9557 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009558{
Johannes Berg947add32013-02-22 22:05:20 +01009559 struct wireless_dev *wdev = dev->ieee80211_ptr;
9560 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009561 struct sk_buff *msg;
9562 void *hdr;
9563
Johannes Berg947add32013-02-22 22:05:20 +01009564 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9565 return;
9566
9567 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9568
Javier Cardonac93b5e72011-04-07 15:08:34 -07009569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9570 if (!msg)
9571 return;
9572
9573 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9574 if (!hdr) {
9575 nlmsg_free(msg);
9576 return;
9577 }
9578
David S. Miller9360ffd2012-03-29 04:41:26 -04009579 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009580 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9581 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009582 (ie_len && ie &&
9583 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9584 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009585
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009586 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009587
9588 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9589 nl80211_mlme_mcgrp.id, gfp);
9590 return;
9591
9592 nla_put_failure:
9593 genlmsg_cancel(msg, hdr);
9594 nlmsg_free(msg);
9595}
Johannes Berg947add32013-02-22 22:05:20 +01009596EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009597
Jouni Malinena3b8b052009-03-27 21:59:49 +02009598void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9599 struct net_device *netdev, const u8 *addr,
9600 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009601 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009602{
9603 struct sk_buff *msg;
9604 void *hdr;
9605
Johannes Berge6d6e342009-07-01 21:26:47 +02009606 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009607 if (!msg)
9608 return;
9609
9610 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9611 if (!hdr) {
9612 nlmsg_free(msg);
9613 return;
9614 }
9615
David S. Miller9360ffd2012-03-29 04:41:26 -04009616 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9617 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9618 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9619 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9620 (key_id != -1 &&
9621 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9622 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9623 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009624
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009625 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009626
Johannes Berg463d0182009-07-14 00:33:35 +02009627 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9628 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009629 return;
9630
9631 nla_put_failure:
9632 genlmsg_cancel(msg, hdr);
9633 nlmsg_free(msg);
9634}
9635
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009636void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9637 struct ieee80211_channel *channel_before,
9638 struct ieee80211_channel *channel_after)
9639{
9640 struct sk_buff *msg;
9641 void *hdr;
9642 struct nlattr *nl_freq;
9643
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009644 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009645 if (!msg)
9646 return;
9647
9648 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9649 if (!hdr) {
9650 nlmsg_free(msg);
9651 return;
9652 }
9653
9654 /*
9655 * Since we are applying the beacon hint to a wiphy we know its
9656 * wiphy_idx is valid
9657 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009658 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9659 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009660
9661 /* Before */
9662 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9663 if (!nl_freq)
9664 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009665 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009666 goto nla_put_failure;
9667 nla_nest_end(msg, nl_freq);
9668
9669 /* After */
9670 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9671 if (!nl_freq)
9672 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009673 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009674 goto nla_put_failure;
9675 nla_nest_end(msg, nl_freq);
9676
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009677 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009678
Johannes Berg463d0182009-07-14 00:33:35 +02009679 rcu_read_lock();
9680 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9681 GFP_ATOMIC);
9682 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009683
9684 return;
9685
9686nla_put_failure:
9687 genlmsg_cancel(msg, hdr);
9688 nlmsg_free(msg);
9689}
9690
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009691static void nl80211_send_remain_on_chan_event(
9692 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009693 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009694 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009695 unsigned int duration, gfp_t gfp)
9696{
9697 struct sk_buff *msg;
9698 void *hdr;
9699
9700 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9701 if (!msg)
9702 return;
9703
9704 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9705 if (!hdr) {
9706 nlmsg_free(msg);
9707 return;
9708 }
9709
David S. Miller9360ffd2012-03-29 04:41:26 -04009710 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009711 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9712 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009713 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009714 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009715 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9716 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009717 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9718 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009719
David S. Miller9360ffd2012-03-29 04:41:26 -04009720 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9721 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9722 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009723
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009724 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009725
9726 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9727 nl80211_mlme_mcgrp.id, gfp);
9728 return;
9729
9730 nla_put_failure:
9731 genlmsg_cancel(msg, hdr);
9732 nlmsg_free(msg);
9733}
9734
Johannes Berg947add32013-02-22 22:05:20 +01009735void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9736 struct ieee80211_channel *chan,
9737 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009738{
Johannes Berg947add32013-02-22 22:05:20 +01009739 struct wiphy *wiphy = wdev->wiphy;
9740 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9741
9742 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009743 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009744 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009745 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009746}
Johannes Berg947add32013-02-22 22:05:20 +01009747EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009748
Johannes Berg947add32013-02-22 22:05:20 +01009749void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9750 struct ieee80211_channel *chan,
9751 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009752{
Johannes Berg947add32013-02-22 22:05:20 +01009753 struct wiphy *wiphy = wdev->wiphy;
9754 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9755
9756 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009757 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009758 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009759}
Johannes Berg947add32013-02-22 22:05:20 +01009760EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009761
Johannes Berg947add32013-02-22 22:05:20 +01009762void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9763 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009764{
Johannes Berg947add32013-02-22 22:05:20 +01009765 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9766 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009767 struct sk_buff *msg;
9768
Johannes Berg947add32013-02-22 22:05:20 +01009769 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9770
Thomas Graf58050fc2012-06-28 03:57:45 +00009771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009772 if (!msg)
9773 return;
9774
John W. Linville66266b32012-03-15 13:25:41 -04009775 if (nl80211_send_station(msg, 0, 0, 0,
9776 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009777 nlmsg_free(msg);
9778 return;
9779 }
9780
9781 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9782 nl80211_mlme_mcgrp.id, gfp);
9783}
Johannes Berg947add32013-02-22 22:05:20 +01009784EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009785
Johannes Berg947add32013-02-22 22:05:20 +01009786void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009787{
Johannes Berg947add32013-02-22 22:05:20 +01009788 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9789 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009790 struct sk_buff *msg;
9791 void *hdr;
9792
Johannes Berg947add32013-02-22 22:05:20 +01009793 trace_cfg80211_del_sta(dev, mac_addr);
9794
Thomas Graf58050fc2012-06-28 03:57:45 +00009795 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009796 if (!msg)
9797 return;
9798
9799 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9800 if (!hdr) {
9801 nlmsg_free(msg);
9802 return;
9803 }
9804
David S. Miller9360ffd2012-03-29 04:41:26 -04009805 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9806 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9807 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009808
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009809 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009810
9811 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9812 nl80211_mlme_mcgrp.id, gfp);
9813 return;
9814
9815 nla_put_failure:
9816 genlmsg_cancel(msg, hdr);
9817 nlmsg_free(msg);
9818}
Johannes Berg947add32013-02-22 22:05:20 +01009819EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009820
Johannes Berg947add32013-02-22 22:05:20 +01009821void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9822 enum nl80211_connect_failed_reason reason,
9823 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309824{
Johannes Berg947add32013-02-22 22:05:20 +01009825 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9826 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309827 struct sk_buff *msg;
9828 void *hdr;
9829
9830 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9831 if (!msg)
9832 return;
9833
9834 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9835 if (!hdr) {
9836 nlmsg_free(msg);
9837 return;
9838 }
9839
9840 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9841 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9842 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9843 goto nla_put_failure;
9844
9845 genlmsg_end(msg, hdr);
9846
9847 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9848 nl80211_mlme_mcgrp.id, gfp);
9849 return;
9850
9851 nla_put_failure:
9852 genlmsg_cancel(msg, hdr);
9853 nlmsg_free(msg);
9854}
Johannes Berg947add32013-02-22 22:05:20 +01009855EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309856
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009857static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9858 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009859{
9860 struct wireless_dev *wdev = dev->ieee80211_ptr;
9861 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9862 struct sk_buff *msg;
9863 void *hdr;
9864 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009865 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009866
Eric W. Biederman15e47302012-09-07 20:12:54 +00009867 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009868 return false;
9869
9870 msg = nlmsg_new(100, gfp);
9871 if (!msg)
9872 return true;
9873
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009874 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009875 if (!hdr) {
9876 nlmsg_free(msg);
9877 return true;
9878 }
9879
David S. Miller9360ffd2012-03-29 04:41:26 -04009880 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9881 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9882 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9883 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009884
9885 err = genlmsg_end(msg, hdr);
9886 if (err < 0) {
9887 nlmsg_free(msg);
9888 return true;
9889 }
9890
Eric W. Biederman15e47302012-09-07 20:12:54 +00009891 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009892 return true;
9893
9894 nla_put_failure:
9895 genlmsg_cancel(msg, hdr);
9896 nlmsg_free(msg);
9897 return true;
9898}
9899
Johannes Berg947add32013-02-22 22:05:20 +01009900bool cfg80211_rx_spurious_frame(struct net_device *dev,
9901 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009902{
Johannes Berg947add32013-02-22 22:05:20 +01009903 struct wireless_dev *wdev = dev->ieee80211_ptr;
9904 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009905
Johannes Berg947add32013-02-22 22:05:20 +01009906 trace_cfg80211_rx_spurious_frame(dev, addr);
9907
9908 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9909 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9910 trace_cfg80211_return_bool(false);
9911 return false;
9912 }
9913 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9914 addr, gfp);
9915 trace_cfg80211_return_bool(ret);
9916 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009917}
Johannes Berg947add32013-02-22 22:05:20 +01009918EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9919
9920bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9921 const u8 *addr, gfp_t gfp)
9922{
9923 struct wireless_dev *wdev = dev->ieee80211_ptr;
9924 bool ret;
9925
9926 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9927
9928 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9929 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9930 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9931 trace_cfg80211_return_bool(false);
9932 return false;
9933 }
9934 ret = __nl80211_unexpected_frame(dev,
9935 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9936 addr, gfp);
9937 trace_cfg80211_return_bool(ret);
9938 return ret;
9939}
9940EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009941
Johannes Berg2e161f72010-08-12 15:38:38 +02009942int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009943 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009944 int freq, int sig_dbm,
9945 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009946{
Johannes Berg71bbc992012-06-15 15:30:18 +02009947 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009948 struct sk_buff *msg;
9949 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009950
9951 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9952 if (!msg)
9953 return -ENOMEM;
9954
Johannes Berg2e161f72010-08-12 15:38:38 +02009955 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009956 if (!hdr) {
9957 nlmsg_free(msg);
9958 return -ENOMEM;
9959 }
9960
David S. Miller9360ffd2012-03-29 04:41:26 -04009961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009962 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9963 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009964 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009965 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9966 (sig_dbm &&
9967 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9968 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9969 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009970
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009971 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009972
Eric W. Biederman15e47302012-09-07 20:12:54 +00009973 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009974
9975 nla_put_failure:
9976 genlmsg_cancel(msg, hdr);
9977 nlmsg_free(msg);
9978 return -ENOBUFS;
9979}
9980
Johannes Berg947add32013-02-22 22:05:20 +01009981void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9982 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009983{
Johannes Berg947add32013-02-22 22:05:20 +01009984 struct wiphy *wiphy = wdev->wiphy;
9985 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009986 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009987 struct sk_buff *msg;
9988 void *hdr;
9989
Johannes Berg947add32013-02-22 22:05:20 +01009990 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9991
Jouni Malinen026331c2010-02-15 12:53:10 +02009992 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9993 if (!msg)
9994 return;
9995
Johannes Berg2e161f72010-08-12 15:38:38 +02009996 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009997 if (!hdr) {
9998 nlmsg_free(msg);
9999 return;
10000 }
10001
David S. Miller9360ffd2012-03-29 04:41:26 -040010002 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010003 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10004 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010005 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010006 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10007 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10008 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10009 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010010
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010011 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010012
10013 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10014 return;
10015
10016 nla_put_failure:
10017 genlmsg_cancel(msg, hdr);
10018 nlmsg_free(msg);
10019}
Johannes Berg947add32013-02-22 22:05:20 +010010020EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010021
Johannes Berg947add32013-02-22 22:05:20 +010010022void cfg80211_cqm_rssi_notify(struct net_device *dev,
10023 enum nl80211_cqm_rssi_threshold_event rssi_event,
10024 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010025{
Johannes Berg947add32013-02-22 22:05:20 +010010026 struct wireless_dev *wdev = dev->ieee80211_ptr;
10027 struct wiphy *wiphy = wdev->wiphy;
10028 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010029 struct sk_buff *msg;
10030 struct nlattr *pinfoattr;
10031 void *hdr;
10032
Johannes Berg947add32013-02-22 22:05:20 +010010033 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10034
Thomas Graf58050fc2012-06-28 03:57:45 +000010035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010036 if (!msg)
10037 return;
10038
10039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10040 if (!hdr) {
10041 nlmsg_free(msg);
10042 return;
10043 }
10044
David S. Miller9360ffd2012-03-29 04:41:26 -040010045 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010046 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010047 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010048
10049 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10050 if (!pinfoattr)
10051 goto nla_put_failure;
10052
David S. Miller9360ffd2012-03-29 04:41:26 -040010053 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10054 rssi_event))
10055 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010056
10057 nla_nest_end(msg, pinfoattr);
10058
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010059 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010060
10061 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10062 nl80211_mlme_mcgrp.id, gfp);
10063 return;
10064
10065 nla_put_failure:
10066 genlmsg_cancel(msg, hdr);
10067 nlmsg_free(msg);
10068}
Johannes Berg947add32013-02-22 22:05:20 +010010069EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010070
Johannes Berg947add32013-02-22 22:05:20 +010010071static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10072 struct net_device *netdev, const u8 *bssid,
10073 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010074{
10075 struct sk_buff *msg;
10076 struct nlattr *rekey_attr;
10077 void *hdr;
10078
Thomas Graf58050fc2012-06-28 03:57:45 +000010079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010080 if (!msg)
10081 return;
10082
10083 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10084 if (!hdr) {
10085 nlmsg_free(msg);
10086 return;
10087 }
10088
David S. Miller9360ffd2012-03-29 04:41:26 -040010089 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10090 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10091 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10092 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010093
10094 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10095 if (!rekey_attr)
10096 goto nla_put_failure;
10097
David S. Miller9360ffd2012-03-29 04:41:26 -040010098 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10099 NL80211_REPLAY_CTR_LEN, replay_ctr))
10100 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010101
10102 nla_nest_end(msg, rekey_attr);
10103
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010104 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010105
10106 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10107 nl80211_mlme_mcgrp.id, gfp);
10108 return;
10109
10110 nla_put_failure:
10111 genlmsg_cancel(msg, hdr);
10112 nlmsg_free(msg);
10113}
10114
Johannes Berg947add32013-02-22 22:05:20 +010010115void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10116 const u8 *replay_ctr, gfp_t gfp)
10117{
10118 struct wireless_dev *wdev = dev->ieee80211_ptr;
10119 struct wiphy *wiphy = wdev->wiphy;
10120 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10121
10122 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10123 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10124}
10125EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10126
10127static void
10128nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10129 struct net_device *netdev, int index,
10130 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010131{
10132 struct sk_buff *msg;
10133 struct nlattr *attr;
10134 void *hdr;
10135
Thomas Graf58050fc2012-06-28 03:57:45 +000010136 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010137 if (!msg)
10138 return;
10139
10140 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10141 if (!hdr) {
10142 nlmsg_free(msg);
10143 return;
10144 }
10145
David S. Miller9360ffd2012-03-29 04:41:26 -040010146 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10148 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010149
10150 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10151 if (!attr)
10152 goto nla_put_failure;
10153
David S. Miller9360ffd2012-03-29 04:41:26 -040010154 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10155 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10156 (preauth &&
10157 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10158 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010159
10160 nla_nest_end(msg, attr);
10161
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010162 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010163
10164 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10165 nl80211_mlme_mcgrp.id, gfp);
10166 return;
10167
10168 nla_put_failure:
10169 genlmsg_cancel(msg, hdr);
10170 nlmsg_free(msg);
10171}
10172
Johannes Berg947add32013-02-22 22:05:20 +010010173void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10174 const u8 *bssid, bool preauth, gfp_t gfp)
10175{
10176 struct wireless_dev *wdev = dev->ieee80211_ptr;
10177 struct wiphy *wiphy = wdev->wiphy;
10178 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10179
10180 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10181 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10182}
10183EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10184
10185static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10186 struct net_device *netdev,
10187 struct cfg80211_chan_def *chandef,
10188 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010189{
10190 struct sk_buff *msg;
10191 void *hdr;
10192
Thomas Graf58050fc2012-06-28 03:57:45 +000010193 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010194 if (!msg)
10195 return;
10196
10197 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10198 if (!hdr) {
10199 nlmsg_free(msg);
10200 return;
10201 }
10202
Johannes Berg683b6d32012-11-08 21:25:48 +010010203 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10204 goto nla_put_failure;
10205
10206 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010207 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010208
10209 genlmsg_end(msg, hdr);
10210
10211 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10212 nl80211_mlme_mcgrp.id, gfp);
10213 return;
10214
10215 nla_put_failure:
10216 genlmsg_cancel(msg, hdr);
10217 nlmsg_free(msg);
10218}
10219
Johannes Berg947add32013-02-22 22:05:20 +010010220void cfg80211_ch_switch_notify(struct net_device *dev,
10221 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010222{
Johannes Berg947add32013-02-22 22:05:20 +010010223 struct wireless_dev *wdev = dev->ieee80211_ptr;
10224 struct wiphy *wiphy = wdev->wiphy;
10225 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10226
10227 trace_cfg80211_ch_switch_notify(dev, chandef);
10228
10229 wdev_lock(wdev);
10230
10231 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10232 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10233 goto out;
10234
10235 wdev->channel = chandef->chan;
10236 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10237out:
10238 wdev_unlock(wdev);
10239 return;
10240}
10241EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10242
10243void cfg80211_cqm_txe_notify(struct net_device *dev,
10244 const u8 *peer, u32 num_packets,
10245 u32 rate, u32 intvl, gfp_t gfp)
10246{
10247 struct wireless_dev *wdev = dev->ieee80211_ptr;
10248 struct wiphy *wiphy = wdev->wiphy;
10249 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010250 struct sk_buff *msg;
10251 struct nlattr *pinfoattr;
10252 void *hdr;
10253
10254 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10255 if (!msg)
10256 return;
10257
10258 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10259 if (!hdr) {
10260 nlmsg_free(msg);
10261 return;
10262 }
10263
10264 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010265 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010266 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10267 goto nla_put_failure;
10268
10269 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10270 if (!pinfoattr)
10271 goto nla_put_failure;
10272
10273 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10274 goto nla_put_failure;
10275
10276 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10277 goto nla_put_failure;
10278
10279 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10280 goto nla_put_failure;
10281
10282 nla_nest_end(msg, pinfoattr);
10283
10284 genlmsg_end(msg, hdr);
10285
10286 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10287 nl80211_mlme_mcgrp.id, gfp);
10288 return;
10289
10290 nla_put_failure:
10291 genlmsg_cancel(msg, hdr);
10292 nlmsg_free(msg);
10293}
Johannes Berg947add32013-02-22 22:05:20 +010010294EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010295
10296void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010297nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10298 struct cfg80211_chan_def *chandef,
10299 enum nl80211_radar_event event,
10300 struct net_device *netdev, gfp_t gfp)
10301{
10302 struct sk_buff *msg;
10303 void *hdr;
10304
10305 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10306 if (!msg)
10307 return;
10308
10309 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10310 if (!hdr) {
10311 nlmsg_free(msg);
10312 return;
10313 }
10314
10315 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10316 goto nla_put_failure;
10317
10318 /* NOP and radar events don't need a netdev parameter */
10319 if (netdev) {
10320 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10321
10322 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10323 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10324 goto nla_put_failure;
10325 }
10326
10327 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10328 goto nla_put_failure;
10329
10330 if (nl80211_send_chandef(msg, chandef))
10331 goto nla_put_failure;
10332
10333 if (genlmsg_end(msg, hdr) < 0) {
10334 nlmsg_free(msg);
10335 return;
10336 }
10337
10338 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10339 nl80211_mlme_mcgrp.id, gfp);
10340 return;
10341
10342 nla_put_failure:
10343 genlmsg_cancel(msg, hdr);
10344 nlmsg_free(msg);
10345}
10346
Johannes Berg947add32013-02-22 22:05:20 +010010347void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10348 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010349{
Johannes Berg947add32013-02-22 22:05:20 +010010350 struct wireless_dev *wdev = dev->ieee80211_ptr;
10351 struct wiphy *wiphy = wdev->wiphy;
10352 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010353 struct sk_buff *msg;
10354 struct nlattr *pinfoattr;
10355 void *hdr;
10356
Johannes Berg947add32013-02-22 22:05:20 +010010357 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10358
Thomas Graf58050fc2012-06-28 03:57:45 +000010359 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010360 if (!msg)
10361 return;
10362
10363 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10364 if (!hdr) {
10365 nlmsg_free(msg);
10366 return;
10367 }
10368
David S. Miller9360ffd2012-03-29 04:41:26 -040010369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010370 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010371 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10372 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010373
10374 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10375 if (!pinfoattr)
10376 goto nla_put_failure;
10377
David S. Miller9360ffd2012-03-29 04:41:26 -040010378 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10379 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010380
10381 nla_nest_end(msg, pinfoattr);
10382
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010383 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010384
10385 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10386 nl80211_mlme_mcgrp.id, gfp);
10387 return;
10388
10389 nla_put_failure:
10390 genlmsg_cancel(msg, hdr);
10391 nlmsg_free(msg);
10392}
Johannes Berg947add32013-02-22 22:05:20 +010010393EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010394
Johannes Berg7f6cf312011-11-04 11:18:15 +010010395void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10396 u64 cookie, bool acked, gfp_t gfp)
10397{
10398 struct wireless_dev *wdev = dev->ieee80211_ptr;
10399 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10400 struct sk_buff *msg;
10401 void *hdr;
10402 int err;
10403
Beni Lev4ee3e062012-08-27 12:49:39 +030010404 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10405
Thomas Graf58050fc2012-06-28 03:57:45 +000010406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010407
Johannes Berg7f6cf312011-11-04 11:18:15 +010010408 if (!msg)
10409 return;
10410
10411 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10412 if (!hdr) {
10413 nlmsg_free(msg);
10414 return;
10415 }
10416
David S. Miller9360ffd2012-03-29 04:41:26 -040010417 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10418 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10419 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10420 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10421 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10422 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010423
10424 err = genlmsg_end(msg, hdr);
10425 if (err < 0) {
10426 nlmsg_free(msg);
10427 return;
10428 }
10429
10430 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10431 nl80211_mlme_mcgrp.id, gfp);
10432 return;
10433
10434 nla_put_failure:
10435 genlmsg_cancel(msg, hdr);
10436 nlmsg_free(msg);
10437}
10438EXPORT_SYMBOL(cfg80211_probe_status);
10439
Johannes Berg5e760232011-11-04 11:18:17 +010010440void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10441 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010442 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010443{
10444 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10445 struct sk_buff *msg;
10446 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010447 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010448
Beni Lev4ee3e062012-08-27 12:49:39 +030010449 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10450
Ben Greear37c73b52012-10-26 14:49:25 -070010451 spin_lock_bh(&rdev->beacon_registrations_lock);
10452 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10453 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10454 if (!msg) {
10455 spin_unlock_bh(&rdev->beacon_registrations_lock);
10456 return;
10457 }
Johannes Berg5e760232011-11-04 11:18:17 +010010458
Ben Greear37c73b52012-10-26 14:49:25 -070010459 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10460 if (!hdr)
10461 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010462
Ben Greear37c73b52012-10-26 14:49:25 -070010463 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10464 (freq &&
10465 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10466 (sig_dbm &&
10467 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10468 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10469 goto nla_put_failure;
10470
10471 genlmsg_end(msg, hdr);
10472
10473 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010474 }
Ben Greear37c73b52012-10-26 14:49:25 -070010475 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010476 return;
10477
10478 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010479 spin_unlock_bh(&rdev->beacon_registrations_lock);
10480 if (hdr)
10481 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010482 nlmsg_free(msg);
10483}
10484EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10485
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010486#ifdef CONFIG_PM
10487void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10488 struct cfg80211_wowlan_wakeup *wakeup,
10489 gfp_t gfp)
10490{
10491 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10492 struct sk_buff *msg;
10493 void *hdr;
10494 int err, size = 200;
10495
10496 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10497
10498 if (wakeup)
10499 size += wakeup->packet_present_len;
10500
10501 msg = nlmsg_new(size, gfp);
10502 if (!msg)
10503 return;
10504
10505 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10506 if (!hdr)
10507 goto free_msg;
10508
10509 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10510 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10511 goto free_msg;
10512
10513 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10514 wdev->netdev->ifindex))
10515 goto free_msg;
10516
10517 if (wakeup) {
10518 struct nlattr *reasons;
10519
10520 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10521
10522 if (wakeup->disconnect &&
10523 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10524 goto free_msg;
10525 if (wakeup->magic_pkt &&
10526 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10527 goto free_msg;
10528 if (wakeup->gtk_rekey_failure &&
10529 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10530 goto free_msg;
10531 if (wakeup->eap_identity_req &&
10532 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10533 goto free_msg;
10534 if (wakeup->four_way_handshake &&
10535 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10536 goto free_msg;
10537 if (wakeup->rfkill_release &&
10538 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10539 goto free_msg;
10540
10541 if (wakeup->pattern_idx >= 0 &&
10542 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10543 wakeup->pattern_idx))
10544 goto free_msg;
10545
Johannes Berg2a0e0472013-01-23 22:57:40 +010010546 if (wakeup->tcp_match)
10547 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10548
10549 if (wakeup->tcp_connlost)
10550 nla_put_flag(msg,
10551 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10552
10553 if (wakeup->tcp_nomoretokens)
10554 nla_put_flag(msg,
10555 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10556
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010557 if (wakeup->packet) {
10558 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10559 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10560
10561 if (!wakeup->packet_80211) {
10562 pkt_attr =
10563 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10564 len_attr =
10565 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10566 }
10567
10568 if (wakeup->packet_len &&
10569 nla_put_u32(msg, len_attr, wakeup->packet_len))
10570 goto free_msg;
10571
10572 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10573 wakeup->packet))
10574 goto free_msg;
10575 }
10576
10577 nla_nest_end(msg, reasons);
10578 }
10579
10580 err = genlmsg_end(msg, hdr);
10581 if (err < 0)
10582 goto free_msg;
10583
10584 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10585 nl80211_mlme_mcgrp.id, gfp);
10586 return;
10587
10588 free_msg:
10589 nlmsg_free(msg);
10590}
10591EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10592#endif
10593
Jouni Malinen3475b092012-11-16 22:49:57 +020010594void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10595 enum nl80211_tdls_operation oper,
10596 u16 reason_code, gfp_t gfp)
10597{
10598 struct wireless_dev *wdev = dev->ieee80211_ptr;
10599 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10600 struct sk_buff *msg;
10601 void *hdr;
10602 int err;
10603
10604 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10605 reason_code);
10606
10607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10608 if (!msg)
10609 return;
10610
10611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10612 if (!hdr) {
10613 nlmsg_free(msg);
10614 return;
10615 }
10616
10617 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10618 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10619 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10620 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10621 (reason_code > 0 &&
10622 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10623 goto nla_put_failure;
10624
10625 err = genlmsg_end(msg, hdr);
10626 if (err < 0) {
10627 nlmsg_free(msg);
10628 return;
10629 }
10630
10631 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10632 nl80211_mlme_mcgrp.id, gfp);
10633 return;
10634
10635 nla_put_failure:
10636 genlmsg_cancel(msg, hdr);
10637 nlmsg_free(msg);
10638}
10639EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10640
Jouni Malinen026331c2010-02-15 12:53:10 +020010641static int nl80211_netlink_notify(struct notifier_block * nb,
10642 unsigned long state,
10643 void *_notify)
10644{
10645 struct netlink_notify *notify = _notify;
10646 struct cfg80211_registered_device *rdev;
10647 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010648 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010649
10650 if (state != NETLINK_URELEASE)
10651 return NOTIFY_DONE;
10652
10653 rcu_read_lock();
10654
Johannes Berg5e760232011-11-04 11:18:17 +010010655 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010656 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010657 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010658
10659 spin_lock_bh(&rdev->beacon_registrations_lock);
10660 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10661 list) {
10662 if (reg->nlportid == notify->portid) {
10663 list_del(&reg->list);
10664 kfree(reg);
10665 break;
10666 }
10667 }
10668 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010669 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010670
10671 rcu_read_unlock();
10672
10673 return NOTIFY_DONE;
10674}
10675
10676static struct notifier_block nl80211_netlink_notifier = {
10677 .notifier_call = nl80211_netlink_notify,
10678};
10679
Jouni Malinen355199e2013-02-27 17:14:27 +020010680void cfg80211_ft_event(struct net_device *netdev,
10681 struct cfg80211_ft_event_params *ft_event)
10682{
10683 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10684 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10685 struct sk_buff *msg;
10686 void *hdr;
10687 int err;
10688
10689 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10690
10691 if (!ft_event->target_ap)
10692 return;
10693
10694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10695 if (!msg)
10696 return;
10697
10698 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10699 if (!hdr) {
10700 nlmsg_free(msg);
10701 return;
10702 }
10703
10704 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10705 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10706 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10707 if (ft_event->ies)
10708 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10709 if (ft_event->ric_ies)
10710 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10711 ft_event->ric_ies);
10712
10713 err = genlmsg_end(msg, hdr);
10714 if (err < 0) {
10715 nlmsg_free(msg);
10716 return;
10717 }
10718
10719 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10720 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10721}
10722EXPORT_SYMBOL(cfg80211_ft_event);
10723
Arend van Spriel5de17982013-04-18 15:49:00 +020010724void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10725{
10726 struct cfg80211_registered_device *rdev;
10727 struct sk_buff *msg;
10728 void *hdr;
10729 u32 nlportid;
10730
10731 rdev = wiphy_to_dev(wdev->wiphy);
10732 if (!rdev->crit_proto_nlportid)
10733 return;
10734
10735 nlportid = rdev->crit_proto_nlportid;
10736 rdev->crit_proto_nlportid = 0;
10737
10738 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10739 if (!msg)
10740 return;
10741
10742 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10743 if (!hdr)
10744 goto nla_put_failure;
10745
10746 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10747 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10748 goto nla_put_failure;
10749
10750 genlmsg_end(msg, hdr);
10751
10752 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10753 return;
10754
10755 nla_put_failure:
10756 if (hdr)
10757 genlmsg_cancel(msg, hdr);
10758 nlmsg_free(msg);
10759
10760}
10761EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10762
Johannes Berg55682962007-09-20 13:09:35 -040010763/* initialisation/exit functions */
10764
10765int nl80211_init(void)
10766{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010767 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010768
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010769 err = genl_register_family_with_ops(&nl80211_fam,
10770 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010771 if (err)
10772 return err;
10773
Johannes Berg55682962007-09-20 13:09:35 -040010774 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10775 if (err)
10776 goto err_out;
10777
Johannes Berg2a519312009-02-10 21:25:55 +010010778 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10779 if (err)
10780 goto err_out;
10781
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010782 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10783 if (err)
10784 goto err_out;
10785
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010786 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10787 if (err)
10788 goto err_out;
10789
Johannes Bergaff89a92009-07-01 21:26:51 +020010790#ifdef CONFIG_NL80211_TESTMODE
10791 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10792 if (err)
10793 goto err_out;
10794#endif
10795
Jouni Malinen026331c2010-02-15 12:53:10 +020010796 err = netlink_register_notifier(&nl80211_netlink_notifier);
10797 if (err)
10798 goto err_out;
10799
Johannes Berg55682962007-09-20 13:09:35 -040010800 return 0;
10801 err_out:
10802 genl_unregister_family(&nl80211_fam);
10803 return err;
10804}
10805
10806void nl80211_exit(void)
10807{
Jouni Malinen026331c2010-02-15 12:53:10 +020010808 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010809 genl_unregister_family(&nl80211_fam);
10810}