blob: 398ce2c5968675f074cf0d0e54f8864a6892d285 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Johannes Berge5497d72011-07-05 16:35:40 +0200406/* policy for GTK rekey offload attributes */
407static const struct nla_policy
408nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
409 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
410 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
411 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
412};
413
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300414static const struct nla_policy
415nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300417 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300419};
420
Johannes Berg97990a02013-04-19 01:02:55 +0200421static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
422 struct netlink_callback *cb,
423 struct cfg80211_registered_device **rdev,
424 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100425{
Johannes Berg67748892010-10-04 21:14:06 +0200426 int err;
427
Johannes Berg67748892010-10-04 21:14:06 +0200428 rtnl_lock();
429
Johannes Berg97990a02013-04-19 01:02:55 +0200430 if (!cb->args[0]) {
431 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
432 nl80211_fam.attrbuf, nl80211_fam.maxattr,
433 nl80211_policy);
434 if (err)
435 goto out_unlock;
436
437 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
438 nl80211_fam.attrbuf);
439 if (IS_ERR(*wdev)) {
440 err = PTR_ERR(*wdev);
441 goto out_unlock;
442 }
443 *rdev = wiphy_to_dev((*wdev)->wiphy);
444 cb->args[0] = (*rdev)->wiphy_idx;
445 cb->args[1] = (*wdev)->identifier;
446 } else {
447 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
448 struct wireless_dev *tmp;
449
450 if (!wiphy) {
451 err = -ENODEV;
452 goto out_unlock;
453 }
454 *rdev = wiphy_to_dev(wiphy);
455 *wdev = NULL;
456
Johannes Berg97990a02013-04-19 01:02:55 +0200457 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
458 if (tmp->identifier == cb->args[1]) {
459 *wdev = tmp;
460 break;
461 }
462 }
Johannes Berg97990a02013-04-19 01:02:55 +0200463
464 if (!*wdev) {
465 err = -ENODEV;
466 goto out_unlock;
467 }
Johannes Berg67748892010-10-04 21:14:06 +0200468 }
469
Johannes Berg67748892010-10-04 21:14:06 +0200470 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200471 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200472 rtnl_unlock();
473 return err;
474}
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200477{
Johannes Berg67748892010-10-04 21:14:06 +0200478 rtnl_unlock();
479}
480
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100481/* IE validation */
482static bool is_valid_ie_attr(const struct nlattr *attr)
483{
484 const u8 *pos;
485 int len;
486
487 if (!attr)
488 return true;
489
490 pos = nla_data(attr);
491 len = nla_len(attr);
492
493 while (len) {
494 u8 elemlen;
495
496 if (len < 2)
497 return false;
498 len -= 2;
499
500 elemlen = pos[1];
501 if (elemlen > len)
502 return false;
503
504 len -= elemlen;
505 pos += 2 + elemlen;
506 }
507
508 return true;
509}
510
Johannes Berg55682962007-09-20 13:09:35 -0400511/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000512static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400513 int flags, u8 cmd)
514{
515 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000516 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400517}
518
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400519static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100520 struct ieee80211_channel *chan,
521 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400522{
David S. Miller9360ffd2012-03-29 04:41:26 -0400523 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
524 chan->center_freq))
525 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400526
David S. Miller9360ffd2012-03-29 04:41:26 -0400527 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
528 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
529 goto nla_put_failure;
530 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
531 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
532 goto nla_put_failure;
533 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
534 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
535 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100536 if (chan->flags & IEEE80211_CHAN_RADAR) {
537 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
538 goto nla_put_failure;
539 if (large) {
540 u32 time;
541
542 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
543
544 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
545 chan->dfs_state))
546 goto nla_put_failure;
547 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
548 time))
549 goto nla_put_failure;
550 }
551 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100553 if (large) {
554 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
565 goto nla_put_failure;
566 }
567
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
569 DBM_TO_MBM(chan->max_power)))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
572 return 0;
573
574 nla_put_failure:
575 return -ENOBUFS;
576}
577
Johannes Berg55682962007-09-20 13:09:35 -0400578/* netlink command implementations */
579
Johannes Bergb9454e82009-07-08 13:29:08 +0200580struct key_parse {
581 struct key_params p;
582 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200583 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200584 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100585 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200586};
587
588static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
589{
590 struct nlattr *tb[NL80211_KEY_MAX + 1];
591 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
592 nl80211_key_policy);
593 if (err)
594 return err;
595
596 k->def = !!tb[NL80211_KEY_DEFAULT];
597 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
598
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100599 if (k->def) {
600 k->def_uni = true;
601 k->def_multi = true;
602 }
603 if (k->defmgmt)
604 k->def_multi = true;
605
Johannes Bergb9454e82009-07-08 13:29:08 +0200606 if (tb[NL80211_KEY_IDX])
607 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
608
609 if (tb[NL80211_KEY_DATA]) {
610 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
611 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
612 }
613
614 if (tb[NL80211_KEY_SEQ]) {
615 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
616 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
617 }
618
619 if (tb[NL80211_KEY_CIPHER])
620 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
621
Johannes Berge31b8212010-10-05 19:39:30 +0200622 if (tb[NL80211_KEY_TYPE]) {
623 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
624 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
625 return -EINVAL;
626 }
627
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100628 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
629 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100630 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
631 tb[NL80211_KEY_DEFAULT_TYPES],
632 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100633 if (err)
634 return err;
635
636 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
637 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
638 }
639
Johannes Bergb9454e82009-07-08 13:29:08 +0200640 return 0;
641}
642
643static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
644{
645 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
646 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
647 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
648 }
649
650 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
651 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
652 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
653 }
654
655 if (info->attrs[NL80211_ATTR_KEY_IDX])
656 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
657
658 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
659 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
660
661 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
662 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
663
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 if (k->def) {
665 k->def_uni = true;
666 k->def_multi = true;
667 }
668 if (k->defmgmt)
669 k->def_multi = true;
670
Johannes Berge31b8212010-10-05 19:39:30 +0200671 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
672 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
673 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
674 return -EINVAL;
675 }
676
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
678 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
679 int err = nla_parse_nested(
680 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
681 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
682 nl80211_key_default_policy);
683 if (err)
684 return err;
685
686 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
687 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
688 }
689
Johannes Bergb9454e82009-07-08 13:29:08 +0200690 return 0;
691}
692
693static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
694{
695 int err;
696
697 memset(k, 0, sizeof(*k));
698 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200699 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200700
701 if (info->attrs[NL80211_ATTR_KEY])
702 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
703 else
704 err = nl80211_parse_key_old(info, k);
705
706 if (err)
707 return err;
708
709 if (k->def && k->defmgmt)
710 return -EINVAL;
711
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (k->defmgmt) {
713 if (k->def_uni || !k->def_multi)
714 return -EINVAL;
715 }
716
Johannes Bergb9454e82009-07-08 13:29:08 +0200717 if (k->idx != -1) {
718 if (k->defmgmt) {
719 if (k->idx < 4 || k->idx > 5)
720 return -EINVAL;
721 } else if (k->def) {
722 if (k->idx < 0 || k->idx > 3)
723 return -EINVAL;
724 } else {
725 if (k->idx < 0 || k->idx > 5)
726 return -EINVAL;
727 }
728 }
729
730 return 0;
731}
732
Johannes Bergfffd0932009-07-08 14:22:54 +0200733static struct cfg80211_cached_keys *
734nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530735 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200736{
737 struct key_parse parse;
738 struct nlattr *key;
739 struct cfg80211_cached_keys *result;
740 int rem, err, def = 0;
741
742 result = kzalloc(sizeof(*result), GFP_KERNEL);
743 if (!result)
744 return ERR_PTR(-ENOMEM);
745
746 result->def = -1;
747 result->defmgmt = -1;
748
749 nla_for_each_nested(key, keys, rem) {
750 memset(&parse, 0, sizeof(parse));
751 parse.idx = -1;
752
753 err = nl80211_parse_key_new(key, &parse);
754 if (err)
755 goto error;
756 err = -EINVAL;
757 if (!parse.p.key)
758 goto error;
759 if (parse.idx < 0 || parse.idx > 4)
760 goto error;
761 if (parse.def) {
762 if (def)
763 goto error;
764 def = 1;
765 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100766 if (!parse.def_uni || !parse.def_multi)
767 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200768 } else if (parse.defmgmt)
769 goto error;
770 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200771 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (err)
773 goto error;
774 result->params[parse.idx].cipher = parse.p.cipher;
775 result->params[parse.idx].key_len = parse.p.key_len;
776 result->params[parse.idx].key = result->data[parse.idx];
777 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530778
779 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
780 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
781 if (no_ht)
782 *no_ht = true;
783 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200784 }
785
786 return result;
787 error:
788 kfree(result);
789 return ERR_PTR(err);
790}
791
792static int nl80211_key_allowed(struct wireless_dev *wdev)
793{
794 ASSERT_WDEV_LOCK(wdev);
795
Johannes Bergfffd0932009-07-08 14:22:54 +0200796 switch (wdev->iftype) {
797 case NL80211_IFTYPE_AP:
798 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200799 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700800 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200801 break;
802 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200803 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200804 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200805 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806 return -ENOLINK;
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 return 0;
813}
814
Johannes Berg7527a782011-05-13 10:58:57 +0200815static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
816{
817 struct nlattr *nl_modes = nla_nest_start(msg, attr);
818 int i;
819
820 if (!nl_modes)
821 goto nla_put_failure;
822
823 i = 0;
824 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400825 if ((ifmodes & 1) && nla_put_flag(msg, i))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 ifmodes >>= 1;
828 i++;
829 }
830
831 nla_nest_end(msg, nl_modes);
832 return 0;
833
834nla_put_failure:
835 return -ENOBUFS;
836}
837
838static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100839 struct sk_buff *msg,
840 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200841{
842 struct nlattr *nl_combis;
843 int i, j;
844
845 nl_combis = nla_nest_start(msg,
846 NL80211_ATTR_INTERFACE_COMBINATIONS);
847 if (!nl_combis)
848 goto nla_put_failure;
849
850 for (i = 0; i < wiphy->n_iface_combinations; i++) {
851 const struct ieee80211_iface_combination *c;
852 struct nlattr *nl_combi, *nl_limits;
853
854 c = &wiphy->iface_combinations[i];
855
856 nl_combi = nla_nest_start(msg, i + 1);
857 if (!nl_combi)
858 goto nla_put_failure;
859
860 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
861 if (!nl_limits)
862 goto nla_put_failure;
863
864 for (j = 0; j < c->n_limits; j++) {
865 struct nlattr *nl_limit;
866
867 nl_limit = nla_nest_start(msg, j + 1);
868 if (!nl_limit)
869 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
871 c->limits[j].max))
872 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200873 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
874 c->limits[j].types))
875 goto nla_put_failure;
876 nla_nest_end(msg, nl_limit);
877 }
878
879 nla_nest_end(msg, nl_limits);
880
David S. Miller9360ffd2012-03-29 04:41:26 -0400881 if (c->beacon_int_infra_match &&
882 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
883 goto nla_put_failure;
884 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
885 c->num_different_channels) ||
886 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
887 c->max_interfaces))
888 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100889 if (large &&
890 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
891 c->radar_detect_widths))
892 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200893
894 nla_nest_end(msg, nl_combi);
895 }
896
897 nla_nest_end(msg, nl_combis);
898
899 return 0;
900nla_put_failure:
901 return -ENOBUFS;
902}
903
Johannes Berg3713b4e2013-02-14 16:19:38 +0100904#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100905static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
906 struct sk_buff *msg)
907{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200908 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100909 struct nlattr *nl_tcp;
910
911 if (!tcp)
912 return 0;
913
914 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
915 if (!nl_tcp)
916 return -ENOBUFS;
917
918 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
919 tcp->data_payload_max))
920 return -ENOBUFS;
921
922 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
923 tcp->data_payload_max))
924 return -ENOBUFS;
925
926 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
927 return -ENOBUFS;
928
929 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
930 sizeof(*tcp->tok), tcp->tok))
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
934 tcp->data_interval_max))
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
938 tcp->wake_payload_max))
939 return -ENOBUFS;
940
941 nla_nest_end(msg, nl_tcp);
942 return 0;
943}
944
Johannes Berg3713b4e2013-02-14 16:19:38 +0100945static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100946 struct cfg80211_registered_device *dev,
947 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948{
949 struct nlattr *nl_wowlan;
950
Johannes Berg964dc9e2013-06-03 17:25:34 +0200951 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100952 return 0;
953
954 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
955 if (!nl_wowlan)
956 return -ENOBUFS;
957
Johannes Berg964dc9e2013-06-03 17:25:34 +0200958 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200960 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200962 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200964 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
974 return -ENOBUFS;
975
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 if (dev->wiphy.wowlan->n_patterns) {
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 struct nl80211_wowlan_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 .max_patterns = dev->wiphy.wowlan->n_patterns,
979 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
980 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
981 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 };
983
984 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
985 sizeof(pat), &pat))
986 return -ENOBUFS;
987 }
988
Johannes Bergb56cf722013-02-20 01:02:38 +0100989 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
990 return -ENOBUFS;
991
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992 nla_nest_end(msg, nl_wowlan);
993
994 return 0;
995}
996#endif
997
998static int nl80211_send_band_rateinfo(struct sk_buff *msg,
999 struct ieee80211_supported_band *sband)
1000{
1001 struct nlattr *nl_rates, *nl_rate;
1002 struct ieee80211_rate *rate;
1003 int i;
1004
1005 /* add HT info */
1006 if (sband->ht_cap.ht_supported &&
1007 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1008 sizeof(sband->ht_cap.mcs),
1009 &sband->ht_cap.mcs) ||
1010 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1011 sband->ht_cap.cap) ||
1012 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1013 sband->ht_cap.ampdu_factor) ||
1014 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1015 sband->ht_cap.ampdu_density)))
1016 return -ENOBUFS;
1017
1018 /* add VHT info */
1019 if (sband->vht_cap.vht_supported &&
1020 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1021 sizeof(sband->vht_cap.vht_mcs),
1022 &sband->vht_cap.vht_mcs) ||
1023 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1024 sband->vht_cap.cap)))
1025 return -ENOBUFS;
1026
1027 /* add bitrates */
1028 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1029 if (!nl_rates)
1030 return -ENOBUFS;
1031
1032 for (i = 0; i < sband->n_bitrates; i++) {
1033 nl_rate = nla_nest_start(msg, i);
1034 if (!nl_rate)
1035 return -ENOBUFS;
1036
1037 rate = &sband->bitrates[i];
1038 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1039 rate->bitrate))
1040 return -ENOBUFS;
1041 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1042 nla_put_flag(msg,
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_rate);
1047 }
1048
1049 nla_nest_end(msg, nl_rates);
1050
1051 return 0;
1052}
1053
1054static int
1055nl80211_send_mgmt_stypes(struct sk_buff *msg,
1056 const struct ieee80211_txrx_stypes *mgmt_stypes)
1057{
1058 u16 stypes;
1059 struct nlattr *nl_ftypes, *nl_ifs;
1060 enum nl80211_iftype ift;
1061 int i;
1062
1063 if (!mgmt_stypes)
1064 return 0;
1065
1066 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1067 if (!nl_ifs)
1068 return -ENOBUFS;
1069
1070 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1071 nl_ftypes = nla_nest_start(msg, ift);
1072 if (!nl_ftypes)
1073 return -ENOBUFS;
1074 i = 0;
1075 stypes = mgmt_stypes[ift].tx;
1076 while (stypes) {
1077 if ((stypes & 1) &&
1078 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1079 (i << 4) | IEEE80211_FTYPE_MGMT))
1080 return -ENOBUFS;
1081 stypes >>= 1;
1082 i++;
1083 }
1084 nla_nest_end(msg, nl_ftypes);
1085 }
1086
1087 nla_nest_end(msg, nl_ifs);
1088
1089 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1090 if (!nl_ifs)
1091 return -ENOBUFS;
1092
1093 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1094 nl_ftypes = nla_nest_start(msg, ift);
1095 if (!nl_ftypes)
1096 return -ENOBUFS;
1097 i = 0;
1098 stypes = mgmt_stypes[ift].rx;
1099 while (stypes) {
1100 if ((stypes & 1) &&
1101 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1102 (i << 4) | IEEE80211_FTYPE_MGMT))
1103 return -ENOBUFS;
1104 stypes >>= 1;
1105 i++;
1106 }
1107 nla_nest_end(msg, nl_ftypes);
1108 }
1109 nla_nest_end(msg, nl_ifs);
1110
1111 return 0;
1112}
1113
1114static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1115 struct sk_buff *msg, u32 portid, u32 seq,
1116 int flags, bool split, long *split_start,
1117 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001118{
1119 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001120 struct nlattr *nl_bands, *nl_band;
1121 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001122 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001123 enum ieee80211_band band;
1124 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001125 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001126 const struct ieee80211_txrx_stypes *mgmt_stypes =
1127 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001129 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001130
Eric W. Biederman15e47302012-09-07 20:12:54 +00001131 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001132 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133 return -ENOBUFS;
1134
1135 /* allow always using the variables */
1136 if (!split) {
1137 split_start = &start;
1138 band_start = &start_band;
1139 chan_start = &start_chan;
1140 }
Johannes Berg55682962007-09-20 13:09:35 -04001141
David S. Miller9360ffd2012-03-29 04:41:26 -04001142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1144 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001145 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001148
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 switch (*split_start) {
1150 case 0:
1151 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1152 dev->wiphy.retry_short) ||
1153 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1154 dev->wiphy.retry_long) ||
1155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1156 dev->wiphy.frag_threshold) ||
1157 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1158 dev->wiphy.rts_threshold) ||
1159 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1160 dev->wiphy.coverage_class) ||
1161 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1162 dev->wiphy.max_scan_ssids) ||
1163 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1164 dev->wiphy.max_sched_scan_ssids) ||
1165 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1166 dev->wiphy.max_scan_ie_len) ||
1167 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1168 dev->wiphy.max_sched_scan_ie_len) ||
1169 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1170 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001171 goto nla_put_failure;
1172
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1174 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1175 goto nla_put_failure;
1176 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1178 goto nla_put_failure;
1179 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1180 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1181 goto nla_put_failure;
1182 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1183 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1184 goto nla_put_failure;
1185 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1186 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1187 goto nla_put_failure;
1188 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1189 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001190 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001191
Johannes Berg3713b4e2013-02-14 16:19:38 +01001192 (*split_start)++;
1193 if (split)
1194 break;
1195 case 1:
1196 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1197 sizeof(u32) * dev->wiphy.n_cipher_suites,
1198 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001199 goto nla_put_failure;
1200
Johannes Berg3713b4e2013-02-14 16:19:38 +01001201 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1202 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001203 goto nla_put_failure;
1204
Johannes Berg3713b4e2013-02-14 16:19:38 +01001205 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1206 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1207 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001208
Johannes Berg3713b4e2013-02-14 16:19:38 +01001209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1210 dev->wiphy.available_antennas_tx) ||
1211 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1212 dev->wiphy.available_antennas_rx))
1213 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001214
Johannes Berg3713b4e2013-02-14 16:19:38 +01001215 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1216 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1217 dev->wiphy.probe_resp_offload))
1218 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001219
Johannes Berg3713b4e2013-02-14 16:19:38 +01001220 if ((dev->wiphy.available_antennas_tx ||
1221 dev->wiphy.available_antennas_rx) &&
1222 dev->ops->get_antenna) {
1223 u32 tx_ant = 0, rx_ant = 0;
1224 int res;
1225 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1226 if (!res) {
1227 if (nla_put_u32(msg,
1228 NL80211_ATTR_WIPHY_ANTENNA_TX,
1229 tx_ant) ||
1230 nla_put_u32(msg,
1231 NL80211_ATTR_WIPHY_ANTENNA_RX,
1232 rx_ant))
1233 goto nla_put_failure;
1234 }
Johannes Bergee688b002008-01-24 19:38:39 +01001235 }
1236
Johannes Berg3713b4e2013-02-14 16:19:38 +01001237 (*split_start)++;
1238 if (split)
1239 break;
1240 case 2:
1241 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1242 dev->wiphy.interface_modes))
1243 goto nla_put_failure;
1244 (*split_start)++;
1245 if (split)
1246 break;
1247 case 3:
1248 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1249 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001250 goto nla_put_failure;
1251
Johannes Berg3713b4e2013-02-14 16:19:38 +01001252 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1253 struct ieee80211_supported_band *sband;
1254
1255 sband = dev->wiphy.bands[band];
1256
1257 if (!sband)
1258 continue;
1259
1260 nl_band = nla_nest_start(msg, band);
1261 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001262 goto nla_put_failure;
1263
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 switch (*chan_start) {
1265 case 0:
1266 if (nl80211_send_band_rateinfo(msg, sband))
1267 goto nla_put_failure;
1268 (*chan_start)++;
1269 if (split)
1270 break;
1271 default:
1272 /* add frequencies */
1273 nl_freqs = nla_nest_start(
1274 msg, NL80211_BAND_ATTR_FREQS);
1275 if (!nl_freqs)
1276 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001277
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 for (i = *chan_start - 1;
1279 i < sband->n_channels;
1280 i++) {
1281 nl_freq = nla_nest_start(msg, i);
1282 if (!nl_freq)
1283 goto nla_put_failure;
1284
1285 chan = &sband->channels[i];
1286
Johannes Bergcdc89b92013-02-18 23:54:36 +01001287 if (nl80211_msg_put_channel(msg, chan,
1288 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 goto nla_put_failure;
1290
1291 nla_nest_end(msg, nl_freq);
1292 if (split)
1293 break;
1294 }
1295 if (i < sband->n_channels)
1296 *chan_start = i + 2;
1297 else
1298 *chan_start = 0;
1299 nla_nest_end(msg, nl_freqs);
1300 }
1301
1302 nla_nest_end(msg, nl_band);
1303
1304 if (split) {
1305 /* start again here */
1306 if (*chan_start)
1307 band--;
1308 break;
1309 }
Johannes Bergee688b002008-01-24 19:38:39 +01001310 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (band < IEEE80211_NUM_BANDS)
1314 *band_start = band + 1;
1315 else
1316 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001317
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 /* if bands & channels are done, continue outside */
1319 if (*band_start == 0 && *chan_start == 0)
1320 (*split_start)++;
1321 if (split)
1322 break;
1323 case 4:
1324 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1325 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327
1328 i = 0;
1329#define CMD(op, n) \
1330 do { \
1331 if (dev->ops->op) { \
1332 i++; \
1333 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1334 goto nla_put_failure; \
1335 } \
1336 } while (0)
1337
1338 CMD(add_virtual_intf, NEW_INTERFACE);
1339 CMD(change_virtual_intf, SET_INTERFACE);
1340 CMD(add_key, NEW_KEY);
1341 CMD(start_ap, START_AP);
1342 CMD(add_station, NEW_STATION);
1343 CMD(add_mpath, NEW_MPATH);
1344 CMD(update_mesh_config, SET_MESH_CONFIG);
1345 CMD(change_bss, SET_BSS);
1346 CMD(auth, AUTHENTICATE);
1347 CMD(assoc, ASSOCIATE);
1348 CMD(deauth, DEAUTHENTICATE);
1349 CMD(disassoc, DISASSOCIATE);
1350 CMD(join_ibss, JOIN_IBSS);
1351 CMD(join_mesh, JOIN_MESH);
1352 CMD(set_pmksa, SET_PMKSA);
1353 CMD(del_pmksa, DEL_PMKSA);
1354 CMD(flush_pmksa, FLUSH_PMKSA);
1355 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1356 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1357 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1358 CMD(mgmt_tx, FRAME);
1359 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1360 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1361 i++;
1362 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1363 goto nla_put_failure;
1364 }
1365 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1366 dev->ops->join_mesh) {
1367 i++;
1368 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1369 goto nla_put_failure;
1370 }
1371 CMD(set_wds_peer, SET_WDS_PEER);
1372 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1373 CMD(tdls_mgmt, TDLS_MGMT);
1374 CMD(tdls_oper, TDLS_OPER);
1375 }
1376 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1377 CMD(sched_scan_start, START_SCHED_SCAN);
1378 CMD(probe_client, PROBE_CLIENT);
1379 CMD(set_noack_map, SET_NOACK_MAP);
1380 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1381 i++;
1382 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1383 goto nla_put_failure;
1384 }
1385 CMD(start_p2p_device, START_P2P_DEVICE);
1386 CMD(set_mcast_rate, SET_MCAST_RATE);
Arend van Spriel5de17982013-04-18 15:49:00 +02001387 if (split) {
1388 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1389 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1390 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001391
Kalle Valo4745fc02011-11-17 19:06:10 +02001392#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001394#endif
1395
Johannes Berg8fdc6212009-03-14 09:34:01 +01001396#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001397
Johannes Berg3713b4e2013-02-14 16:19:38 +01001398 if (dev->ops->connect || dev->ops->auth) {
1399 i++;
1400 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001401 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001402 }
1403
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 if (dev->ops->disconnect || dev->ops->deauth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1407 goto nla_put_failure;
1408 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001409
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 nla_nest_end(msg, nl_cmds);
1411 (*split_start)++;
1412 if (split)
1413 break;
1414 case 5:
1415 if (dev->ops->remain_on_channel &&
1416 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1417 nla_put_u32(msg,
1418 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1419 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001420 goto nla_put_failure;
1421
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1423 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1424 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001425
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1427 goto nla_put_failure;
1428 (*split_start)++;
1429 if (split)
1430 break;
1431 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001432#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001433 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 goto nla_put_failure;
1435 (*split_start)++;
1436 if (split)
1437 break;
1438#else
1439 (*split_start)++;
1440#endif
1441 case 7:
1442 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1443 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001444 goto nla_put_failure;
1445
Johannes Bergcdc89b92013-02-18 23:54:36 +01001446 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001448
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 (*split_start)++;
1450 if (split)
1451 break;
1452 case 8:
1453 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1454 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1455 dev->wiphy.ap_sme_capa))
1456 goto nla_put_failure;
1457
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001458 features = dev->wiphy.features;
1459 /*
1460 * We can only add the per-channel limit information if the
1461 * dump is split, otherwise it makes it too big. Therefore
1462 * only advertise it in that case.
1463 */
1464 if (split)
1465 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1466 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 goto nla_put_failure;
1468
1469 if (dev->wiphy.ht_capa_mod_mask &&
1470 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1471 sizeof(*dev->wiphy.ht_capa_mod_mask),
1472 dev->wiphy.ht_capa_mod_mask))
1473 goto nla_put_failure;
1474
1475 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1476 dev->wiphy.max_acl_mac_addrs &&
1477 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1478 dev->wiphy.max_acl_mac_addrs))
1479 goto nla_put_failure;
1480
1481 /*
1482 * Any information below this point is only available to
1483 * applications that can deal with it being split. This
1484 * helps ensure that newly added capabilities don't break
1485 * older tools by overrunning their buffers.
1486 *
1487 * We still increment split_start so that in the split
1488 * case we'll continue with more data in the next round,
1489 * but break unconditionally so unsplit data stops here.
1490 */
1491 (*split_start)++;
1492 break;
1493 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001494 if (dev->wiphy.extended_capabilities &&
1495 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1496 dev->wiphy.extended_capabilities_len,
1497 dev->wiphy.extended_capabilities) ||
1498 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1499 dev->wiphy.extended_capabilities_len,
1500 dev->wiphy.extended_capabilities_mask)))
1501 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502
Johannes Bergee2aca32013-02-21 17:36:01 +01001503 if (dev->wiphy.vht_capa_mod_mask &&
1504 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1505 sizeof(*dev->wiphy.vht_capa_mod_mask),
1506 dev->wiphy.vht_capa_mod_mask))
1507 goto nla_put_failure;
1508
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509 /* done */
1510 *split_start = 0;
1511 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001512 }
Johannes Berg55682962007-09-20 13:09:35 -04001513 return genlmsg_end(msg, hdr);
1514
1515 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001516 genlmsg_cancel(msg, hdr);
1517 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001518}
1519
1520static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1521{
Johannes Berg645e77d2013-03-01 14:03:49 +01001522 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001523 int start = cb->args[0];
1524 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 s64 filter_wiphy = -1;
1526 bool split = false;
1527 struct nlattr **tb = nl80211_fam.attrbuf;
1528 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001529
Johannes Berg5fe231e2013-05-08 21:45:15 +02001530 rtnl_lock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1532 tb, nl80211_fam.maxattr, nl80211_policy);
1533 if (res == 0) {
1534 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1535 if (tb[NL80211_ATTR_WIPHY])
1536 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1537 if (tb[NL80211_ATTR_WDEV])
1538 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1539 if (tb[NL80211_ATTR_IFINDEX]) {
1540 struct net_device *netdev;
1541 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1542
1543 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001544 if (!netdev)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 return -ENODEV;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 if (netdev->ieee80211_ptr) {
1547 dev = wiphy_to_dev(
1548 netdev->ieee80211_ptr->wiphy);
1549 filter_wiphy = dev->wiphy_idx;
1550 }
1551 dev_put(netdev);
1552 }
1553 }
1554
Johannes Berg79c97e92009-07-07 03:56:12 +02001555 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001556 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1557 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001558 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001559 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1561 continue;
1562 /* attempt to fit multiple wiphy data chunks into the skb */
1563 do {
1564 ret = nl80211_send_wiphy(dev, skb,
1565 NETLINK_CB(cb->skb).portid,
1566 cb->nlh->nlmsg_seq,
1567 NLM_F_MULTI,
1568 split, &cb->args[1],
1569 &cb->args[2],
1570 &cb->args[3]);
1571 if (ret < 0) {
1572 /*
1573 * If sending the wiphy data didn't fit (ENOBUFS
1574 * or EMSGSIZE returned), this SKB is still
1575 * empty (so it's not too big because another
1576 * wiphy dataset is already in the skb) and
1577 * we've not tried to adjust the dump allocation
1578 * yet ... then adjust the alloc size to be
1579 * bigger, and return 1 but with the empty skb.
1580 * This results in an empty message being RX'ed
1581 * in userspace, but that is ignored.
1582 *
1583 * We can then retry with the larger buffer.
1584 */
1585 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1586 !skb->len &&
1587 cb->min_dump_alloc < 4096) {
1588 cb->min_dump_alloc = 4096;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 return 1;
1590 }
1591 idx--;
1592 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001593 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 } while (cb->args[1] > 0);
1595 break;
Johannes Berg55682962007-09-20 13:09:35 -04001596 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001597 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001598
1599 cb->args[0] = idx;
1600
1601 return skb->len;
1602}
1603
1604static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1605{
1606 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001607 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001608
Johannes Berg645e77d2013-03-01 14:03:49 +01001609 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001610 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001611 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001612
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1614 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001615 nlmsg_free(msg);
1616 return -ENOBUFS;
1617 }
Johannes Berg55682962007-09-20 13:09:35 -04001618
Johannes Berg134e6372009-07-10 09:51:34 +00001619 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001620}
1621
Jouni Malinen31888482008-10-30 16:59:24 +02001622static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1623 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1624 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1625 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1626 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1627 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1628};
1629
1630static int parse_txq_params(struct nlattr *tb[],
1631 struct ieee80211_txq_params *txq_params)
1632{
Johannes Berga3304b02012-03-28 11:04:24 +02001633 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001634 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1635 !tb[NL80211_TXQ_ATTR_AIFS])
1636 return -EINVAL;
1637
Johannes Berga3304b02012-03-28 11:04:24 +02001638 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001639 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1640 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1641 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1642 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1643
Johannes Berga3304b02012-03-28 11:04:24 +02001644 if (txq_params->ac >= NL80211_NUM_ACS)
1645 return -EINVAL;
1646
Jouni Malinen31888482008-10-30 16:59:24 +02001647 return 0;
1648}
1649
Johannes Bergf444de02010-05-05 15:25:02 +02001650static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1651{
1652 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001653 * You can only set the channel explicitly for WDS interfaces,
1654 * all others have their channel managed via their respective
1655 * "establish a connection" command (connect, join, ...)
1656 *
1657 * For AP/GO and mesh mode, the channel can be set with the
1658 * channel userspace API, but is only stored and passed to the
1659 * low-level driver when the AP starts or the mesh is joined.
1660 * This is for backward compatibility, userspace can also give
1661 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001662 *
1663 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001664 * whatever else is going on, so they have their own special
1665 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001666 */
1667 return !wdev ||
1668 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001669 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001670 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1671 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001672}
1673
Johannes Berg683b6d32012-11-08 21:25:48 +01001674static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1675 struct genl_info *info,
1676 struct cfg80211_chan_def *chandef)
1677{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301678 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001679
1680 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1681 return -EINVAL;
1682
1683 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1684
1685 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001686 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1687 chandef->center_freq1 = control_freq;
1688 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001689
1690 /* Primary channel not allowed */
1691 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1692 return -EINVAL;
1693
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001694 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1695 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001696
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001697 chantype = nla_get_u32(
1698 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1699
1700 switch (chantype) {
1701 case NL80211_CHAN_NO_HT:
1702 case NL80211_CHAN_HT20:
1703 case NL80211_CHAN_HT40PLUS:
1704 case NL80211_CHAN_HT40MINUS:
1705 cfg80211_chandef_create(chandef, chandef->chan,
1706 chantype);
1707 break;
1708 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001709 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001710 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001711 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1712 chandef->width =
1713 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1714 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1715 chandef->center_freq1 =
1716 nla_get_u32(
1717 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1718 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1719 chandef->center_freq2 =
1720 nla_get_u32(
1721 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1722 }
1723
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001724 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001725 return -EINVAL;
1726
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001727 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1728 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001729 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001730
Johannes Berg683b6d32012-11-08 21:25:48 +01001731 return 0;
1732}
1733
Johannes Bergf444de02010-05-05 15:25:02 +02001734static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1735 struct wireless_dev *wdev,
1736 struct genl_info *info)
1737{
Johannes Berg683b6d32012-11-08 21:25:48 +01001738 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001739 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001740 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1741
1742 if (wdev)
1743 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001744
Johannes Bergf444de02010-05-05 15:25:02 +02001745 if (!nl80211_can_set_dev_channel(wdev))
1746 return -EOPNOTSUPP;
1747
Johannes Berg683b6d32012-11-08 21:25:48 +01001748 result = nl80211_parse_chandef(rdev, info, &chandef);
1749 if (result)
1750 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001751
Johannes Berge8c9bd52012-06-06 08:18:22 +02001752 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001753 case NL80211_IFTYPE_AP:
1754 case NL80211_IFTYPE_P2P_GO:
1755 if (wdev->beacon_interval) {
1756 result = -EBUSY;
1757 break;
1758 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001759 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001760 result = -EINVAL;
1761 break;
1762 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001763 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001764 result = 0;
1765 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001766 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001767 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001768 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001769 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001771 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001772 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001773 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001774 }
Johannes Bergf444de02010-05-05 15:25:02 +02001775
1776 return result;
1777}
1778
1779static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1780{
Johannes Berg4c476992010-10-04 21:36:35 +02001781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1782 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001783
Johannes Berg4c476992010-10-04 21:36:35 +02001784 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001785}
1786
Bill Jordane8347eb2010-10-01 13:54:28 -04001787static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1788{
Johannes Berg43b19952010-10-07 13:10:30 +02001789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1790 struct net_device *dev = info->user_ptr[1];
1791 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001792 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001793
1794 if (!info->attrs[NL80211_ATTR_MAC])
1795 return -EINVAL;
1796
Johannes Berg43b19952010-10-07 13:10:30 +02001797 if (netif_running(dev))
1798 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001799
Johannes Berg43b19952010-10-07 13:10:30 +02001800 if (!rdev->ops->set_wds_peer)
1801 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001802
Johannes Berg43b19952010-10-07 13:10:30 +02001803 if (wdev->iftype != NL80211_IFTYPE_WDS)
1804 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001805
1806 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001807 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001808}
1809
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1812{
1813 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001814 struct net_device *netdev = NULL;
1815 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001816 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001817 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001818 u32 changed;
1819 u8 retry_short = 0, retry_long = 0;
1820 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001821 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001822
Johannes Berg5fe231e2013-05-08 21:45:15 +02001823 ASSERT_RTNL();
1824
Johannes Bergf444de02010-05-05 15:25:02 +02001825 /*
1826 * Try to find the wiphy and netdev. Normally this
1827 * function shouldn't need the netdev, but this is
1828 * done for backward compatibility -- previously
1829 * setting the channel was done per wiphy, but now
1830 * it is per netdev. Previous userland like hostapd
1831 * also passed a netdev to set_wiphy, so that it is
1832 * possible to let that go to the right netdev!
1833 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001834
Johannes Bergf444de02010-05-05 15:25:02 +02001835 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1836 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1837
1838 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001839 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001840 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001841 else
Johannes Bergf444de02010-05-05 15:25:02 +02001842 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001843 }
1844
Johannes Bergf444de02010-05-05 15:25:02 +02001845 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001846 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1847 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001848 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001849 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001850 wdev = NULL;
1851 netdev = NULL;
1852 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001853 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001854 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001855
1856 /*
1857 * end workaround code, by now the rdev is available
1858 * and locked, and wdev may or may not be NULL.
1859 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001860
1861 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001862 result = cfg80211_dev_rename(
1863 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001864
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001865 if (result)
1866 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001867
Jouni Malinen31888482008-10-30 16:59:24 +02001868 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1869 struct ieee80211_txq_params txq_params;
1870 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1871
1872 if (!rdev->ops->set_txq_params) {
1873 result = -EOPNOTSUPP;
1874 goto bad_res;
1875 }
1876
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001877 if (!netdev) {
1878 result = -EINVAL;
1879 goto bad_res;
1880 }
1881
Johannes Berg133a3ff2011-11-03 14:50:13 +01001882 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1883 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1884 result = -EINVAL;
1885 goto bad_res;
1886 }
1887
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001888 if (!netif_running(netdev)) {
1889 result = -ENETDOWN;
1890 goto bad_res;
1891 }
1892
Jouni Malinen31888482008-10-30 16:59:24 +02001893 nla_for_each_nested(nl_txq_params,
1894 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1895 rem_txq_params) {
1896 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1897 nla_data(nl_txq_params),
1898 nla_len(nl_txq_params),
1899 txq_params_policy);
1900 result = parse_txq_params(tb, &txq_params);
1901 if (result)
1902 goto bad_res;
1903
Hila Gonene35e4d22012-06-27 17:19:42 +03001904 result = rdev_set_txq_params(rdev, netdev,
1905 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001906 if (result)
1907 goto bad_res;
1908 }
1909 }
1910
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001911 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001912 result = __nl80211_set_channel(rdev,
1913 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1914 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001915 if (result)
1916 goto bad_res;
1917 }
1918
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001919 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001920 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001921 enum nl80211_tx_power_setting type;
1922 int idx, mbm = 0;
1923
Johannes Bergc8442112012-10-24 10:17:18 +02001924 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1925 txp_wdev = NULL;
1926
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001927 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001928 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001929 goto bad_res;
1930 }
1931
1932 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1933 type = nla_get_u32(info->attrs[idx]);
1934
1935 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1936 (type != NL80211_TX_POWER_AUTOMATIC)) {
1937 result = -EINVAL;
1938 goto bad_res;
1939 }
1940
1941 if (type != NL80211_TX_POWER_AUTOMATIC) {
1942 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1943 mbm = nla_get_u32(info->attrs[idx]);
1944 }
1945
Johannes Bergc8442112012-10-24 10:17:18 +02001946 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001947 if (result)
1948 goto bad_res;
1949 }
1950
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001951 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1952 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1953 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001954 if ((!rdev->wiphy.available_antennas_tx &&
1955 !rdev->wiphy.available_antennas_rx) ||
1956 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001957 result = -EOPNOTSUPP;
1958 goto bad_res;
1959 }
1960
1961 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1962 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1963
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001964 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001965 * available antenna masks, except for the "all" mask */
1966 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1967 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001968 result = -EINVAL;
1969 goto bad_res;
1970 }
1971
Bruno Randolf7f531e02010-12-16 11:30:22 +09001972 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1973 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001974
Hila Gonene35e4d22012-06-27 17:19:42 +03001975 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001976 if (result)
1977 goto bad_res;
1978 }
1979
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001980 changed = 0;
1981
1982 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1983 retry_short = nla_get_u8(
1984 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1985 if (retry_short == 0) {
1986 result = -EINVAL;
1987 goto bad_res;
1988 }
1989 changed |= WIPHY_PARAM_RETRY_SHORT;
1990 }
1991
1992 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1993 retry_long = nla_get_u8(
1994 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1995 if (retry_long == 0) {
1996 result = -EINVAL;
1997 goto bad_res;
1998 }
1999 changed |= WIPHY_PARAM_RETRY_LONG;
2000 }
2001
2002 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2003 frag_threshold = nla_get_u32(
2004 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2005 if (frag_threshold < 256) {
2006 result = -EINVAL;
2007 goto bad_res;
2008 }
2009 if (frag_threshold != (u32) -1) {
2010 /*
2011 * Fragments (apart from the last one) are required to
2012 * have even length. Make the fragmentation code
2013 * simpler by stripping LSB should someone try to use
2014 * odd threshold value.
2015 */
2016 frag_threshold &= ~0x1;
2017 }
2018 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2019 }
2020
2021 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2022 rts_threshold = nla_get_u32(
2023 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2024 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2025 }
2026
Lukáš Turek81077e82009-12-21 22:50:47 +01002027 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2028 coverage_class = nla_get_u8(
2029 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2030 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2031 }
2032
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002033 if (changed) {
2034 u8 old_retry_short, old_retry_long;
2035 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002036 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002037
2038 if (!rdev->ops->set_wiphy_params) {
2039 result = -EOPNOTSUPP;
2040 goto bad_res;
2041 }
2042
2043 old_retry_short = rdev->wiphy.retry_short;
2044 old_retry_long = rdev->wiphy.retry_long;
2045 old_frag_threshold = rdev->wiphy.frag_threshold;
2046 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002047 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002048
2049 if (changed & WIPHY_PARAM_RETRY_SHORT)
2050 rdev->wiphy.retry_short = retry_short;
2051 if (changed & WIPHY_PARAM_RETRY_LONG)
2052 rdev->wiphy.retry_long = retry_long;
2053 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2054 rdev->wiphy.frag_threshold = frag_threshold;
2055 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2056 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002057 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2058 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002059
Hila Gonene35e4d22012-06-27 17:19:42 +03002060 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002061 if (result) {
2062 rdev->wiphy.retry_short = old_retry_short;
2063 rdev->wiphy.retry_long = old_retry_long;
2064 rdev->wiphy.frag_threshold = old_frag_threshold;
2065 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002066 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002067 }
2068 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002069
Johannes Berg306d6112008-12-08 12:39:04 +01002070 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002071 if (netdev)
2072 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002073 return result;
2074}
2075
Johannes Berg71bbc992012-06-15 15:30:18 +02002076static inline u64 wdev_id(struct wireless_dev *wdev)
2077{
2078 return (u64)wdev->identifier |
2079 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2080}
Johannes Berg55682962007-09-20 13:09:35 -04002081
Johannes Berg683b6d32012-11-08 21:25:48 +01002082static int nl80211_send_chandef(struct sk_buff *msg,
2083 struct cfg80211_chan_def *chandef)
2084{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002085 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002086
Johannes Berg683b6d32012-11-08 21:25:48 +01002087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2088 chandef->chan->center_freq))
2089 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002090 switch (chandef->width) {
2091 case NL80211_CHAN_WIDTH_20_NOHT:
2092 case NL80211_CHAN_WIDTH_20:
2093 case NL80211_CHAN_WIDTH_40:
2094 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2095 cfg80211_get_chandef_type(chandef)))
2096 return -ENOBUFS;
2097 break;
2098 default:
2099 break;
2100 }
2101 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2102 return -ENOBUFS;
2103 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2104 return -ENOBUFS;
2105 if (chandef->center_freq2 &&
2106 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002107 return -ENOBUFS;
2108 return 0;
2109}
2110
Eric W. Biederman15e47302012-09-07 20:12:54 +00002111static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002112 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002113 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002114{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002115 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002116 void *hdr;
2117
Eric W. Biederman15e47302012-09-07 20:12:54 +00002118 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002119 if (!hdr)
2120 return -1;
2121
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002122 if (dev &&
2123 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002124 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002125 goto nla_put_failure;
2126
2127 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2128 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002129 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002130 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002131 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2132 rdev->devlist_generation ^
2133 (cfg80211_rdev_list_generation << 2)))
2134 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002135
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002136 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002137 int ret;
2138 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002139
Johannes Berg683b6d32012-11-08 21:25:48 +01002140 ret = rdev_get_channel(rdev, wdev, &chandef);
2141 if (ret == 0) {
2142 if (nl80211_send_chandef(msg, &chandef))
2143 goto nla_put_failure;
2144 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002145 }
2146
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002147 if (wdev->ssid_len) {
2148 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2149 goto nla_put_failure;
2150 }
2151
Johannes Berg55682962007-09-20 13:09:35 -04002152 return genlmsg_end(msg, hdr);
2153
2154 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002155 genlmsg_cancel(msg, hdr);
2156 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002157}
2158
2159static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2160{
2161 int wp_idx = 0;
2162 int if_idx = 0;
2163 int wp_start = cb->args[0];
2164 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002165 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002166 struct wireless_dev *wdev;
2167
Johannes Berg5fe231e2013-05-08 21:45:15 +02002168 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002169 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2170 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002171 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002172 if (wp_idx < wp_start) {
2173 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002174 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002175 }
Johannes Berg55682962007-09-20 13:09:35 -04002176 if_idx = 0;
2177
Johannes Berg89a54e42012-06-15 14:33:17 +02002178 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002179 if (if_idx < if_start) {
2180 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002181 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002182 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002183 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002184 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002185 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002186 goto out;
2187 }
2188 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002189 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002190
2191 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002192 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002194 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002195
2196 cb->args[0] = wp_idx;
2197 cb->args[1] = if_idx;
2198
2199 return skb->len;
2200}
2201
2202static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2203{
2204 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002205 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002206 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002207
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002209 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002210 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002211
Eric W. Biederman15e47302012-09-07 20:12:54 +00002212 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002213 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002214 nlmsg_free(msg);
2215 return -ENOBUFS;
2216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217
Johannes Berg134e6372009-07-10 09:51:34 +00002218 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002219}
2220
Michael Wu66f7ac52008-01-31 19:48:22 +01002221static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2222 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2223 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2224 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2225 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2226 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002227 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002228};
2229
2230static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2231{
2232 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2233 int flag;
2234
2235 *mntrflags = 0;
2236
2237 if (!nla)
2238 return -EINVAL;
2239
2240 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2241 nla, mntr_flags_policy))
2242 return -EINVAL;
2243
2244 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2245 if (flags[flag])
2246 *mntrflags |= (1<<flag);
2247
2248 return 0;
2249}
2250
Johannes Berg9bc383d2009-11-19 11:55:19 +01002251static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002252 struct net_device *netdev, u8 use_4addr,
2253 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002254{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002255 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002256 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002257 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002258 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002259 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002260
2261 switch (iftype) {
2262 case NL80211_IFTYPE_AP_VLAN:
2263 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2264 return 0;
2265 break;
2266 case NL80211_IFTYPE_STATION:
2267 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2268 return 0;
2269 break;
2270 default:
2271 break;
2272 }
2273
2274 return -EOPNOTSUPP;
2275}
2276
Johannes Berg55682962007-09-20 13:09:35 -04002277static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2278{
Johannes Berg4c476992010-10-04 21:36:35 +02002279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002280 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002281 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002282 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002283 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002284 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002285 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002286
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002287 memset(&params, 0, sizeof(params));
2288
Johannes Berg04a773a2009-04-19 21:24:32 +02002289 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002290
Johannes Berg723b0382008-09-16 20:22:09 +02002291 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002292 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002293 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002294 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002295 if (ntype > NL80211_IFTYPE_MAX)
2296 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002297 }
2298
Johannes Berg92ffe052008-09-16 20:39:36 +02002299 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002300 struct wireless_dev *wdev = dev->ieee80211_ptr;
2301
Johannes Berg4c476992010-10-04 21:36:35 +02002302 if (ntype != NL80211_IFTYPE_MESH_POINT)
2303 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002304 if (netif_running(dev))
2305 return -EBUSY;
2306
2307 wdev_lock(wdev);
2308 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2309 IEEE80211_MAX_MESH_ID_LEN);
2310 wdev->mesh_id_up_len =
2311 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2312 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2313 wdev->mesh_id_up_len);
2314 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002315 }
2316
Felix Fietkau8b787642009-11-10 18:53:10 +01002317 if (info->attrs[NL80211_ATTR_4ADDR]) {
2318 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2319 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002320 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002322 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002323 } else {
2324 params.use_4addr = -1;
2325 }
2326
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002328 if (ntype != NL80211_IFTYPE_MONITOR)
2329 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002330 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2331 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002332 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002333 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002334
2335 flags = &_flags;
2336 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002337 }
Johannes Berg3b858752009-03-12 09:55:09 +01002338
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002339 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2340 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2341 return -EOPNOTSUPP;
2342
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002343 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002344 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002345 else
2346 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002347
Johannes Berg9bc383d2009-11-19 11:55:19 +01002348 if (!err && params.use_4addr != -1)
2349 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2350
Johannes Berg55682962007-09-20 13:09:35 -04002351 return err;
2352}
2353
2354static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2355{
Johannes Berg4c476992010-10-04 21:36:35 +02002356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002357 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002358 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002359 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002360 int err;
2361 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002362 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002363
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002364 memset(&params, 0, sizeof(params));
2365
Johannes Berg55682962007-09-20 13:09:35 -04002366 if (!info->attrs[NL80211_ATTR_IFNAME])
2367 return -EINVAL;
2368
2369 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2370 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2371 if (type > NL80211_IFTYPE_MAX)
2372 return -EINVAL;
2373 }
2374
Johannes Berg79c97e92009-07-07 03:56:12 +02002375 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002376 !(rdev->wiphy.interface_modes & (1 << type)))
2377 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002378
Arend van Spriel1c18f142013-01-08 10:17:27 +01002379 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2380 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2381 ETH_ALEN);
2382 if (!is_valid_ether_addr(params.macaddr))
2383 return -EADDRNOTAVAIL;
2384 }
2385
Johannes Berg9bc383d2009-11-19 11:55:19 +01002386 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002387 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002388 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002389 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002390 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002391 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002392
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2394 if (!msg)
2395 return -ENOMEM;
2396
Michael Wu66f7ac52008-01-31 19:48:22 +01002397 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2398 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2399 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002400
2401 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2402 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2403 return -EOPNOTSUPP;
2404
Hila Gonene35e4d22012-06-27 17:19:42 +03002405 wdev = rdev_add_virtual_intf(rdev,
2406 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2407 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002408 if (IS_ERR(wdev)) {
2409 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002410 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002411 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002412
Johannes Berg98104fde2012-06-16 00:19:54 +02002413 switch (type) {
2414 case NL80211_IFTYPE_MESH_POINT:
2415 if (!info->attrs[NL80211_ATTR_MESH_ID])
2416 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002417 wdev_lock(wdev);
2418 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2419 IEEE80211_MAX_MESH_ID_LEN);
2420 wdev->mesh_id_up_len =
2421 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2422 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2423 wdev->mesh_id_up_len);
2424 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002425 break;
2426 case NL80211_IFTYPE_P2P_DEVICE:
2427 /*
2428 * P2P Device doesn't have a netdev, so doesn't go
2429 * through the netdev notifier and must be added here
2430 */
2431 mutex_init(&wdev->mtx);
2432 INIT_LIST_HEAD(&wdev->event_list);
2433 spin_lock_init(&wdev->event_lock);
2434 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2435 spin_lock_init(&wdev->mgmt_registrations_lock);
2436
Johannes Berg98104fde2012-06-16 00:19:54 +02002437 wdev->identifier = ++rdev->wdev_id;
2438 list_add_rcu(&wdev->list, &rdev->wdev_list);
2439 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002440 break;
2441 default:
2442 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002443 }
2444
Eric W. Biederman15e47302012-09-07 20:12:54 +00002445 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002446 rdev, wdev) < 0) {
2447 nlmsg_free(msg);
2448 return -ENOBUFS;
2449 }
2450
2451 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002452}
2453
2454static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2455{
Johannes Berg4c476992010-10-04 21:36:35 +02002456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002457 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002458
Johannes Berg4c476992010-10-04 21:36:35 +02002459 if (!rdev->ops->del_virtual_intf)
2460 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002461
Johannes Berg84efbb82012-06-16 00:00:26 +02002462 /*
2463 * If we remove a wireless device without a netdev then clear
2464 * user_ptr[1] so that nl80211_post_doit won't dereference it
2465 * to check if it needs to do dev_put(). Otherwise it crashes
2466 * since the wdev has been freed, unlike with a netdev where
2467 * we need the dev_put() for the netdev to really be freed.
2468 */
2469 if (!wdev->netdev)
2470 info->user_ptr[1] = NULL;
2471
Hila Gonene35e4d22012-06-27 17:19:42 +03002472 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002473}
2474
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002475static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2476{
2477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2478 struct net_device *dev = info->user_ptr[1];
2479 u16 noack_map;
2480
2481 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2482 return -EINVAL;
2483
2484 if (!rdev->ops->set_noack_map)
2485 return -EOPNOTSUPP;
2486
2487 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2488
Hila Gonene35e4d22012-06-27 17:19:42 +03002489 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002490}
2491
Johannes Berg41ade002007-12-19 02:03:29 +01002492struct get_key_cookie {
2493 struct sk_buff *msg;
2494 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002495 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002496};
2497
2498static void get_key_callback(void *c, struct key_params *params)
2499{
Johannes Bergb9454e82009-07-08 13:29:08 +02002500 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002501 struct get_key_cookie *cookie = c;
2502
David S. Miller9360ffd2012-03-29 04:41:26 -04002503 if ((params->key &&
2504 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2505 params->key_len, params->key)) ||
2506 (params->seq &&
2507 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2508 params->seq_len, params->seq)) ||
2509 (params->cipher &&
2510 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2511 params->cipher)))
2512 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002513
Johannes Bergb9454e82009-07-08 13:29:08 +02002514 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2515 if (!key)
2516 goto nla_put_failure;
2517
David S. Miller9360ffd2012-03-29 04:41:26 -04002518 if ((params->key &&
2519 nla_put(cookie->msg, NL80211_KEY_DATA,
2520 params->key_len, params->key)) ||
2521 (params->seq &&
2522 nla_put(cookie->msg, NL80211_KEY_SEQ,
2523 params->seq_len, params->seq)) ||
2524 (params->cipher &&
2525 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2526 params->cipher)))
2527 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002528
David S. Miller9360ffd2012-03-29 04:41:26 -04002529 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2530 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531
2532 nla_nest_end(cookie->msg, key);
2533
Johannes Berg41ade002007-12-19 02:03:29 +01002534 return;
2535 nla_put_failure:
2536 cookie->error = 1;
2537}
2538
2539static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2540{
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002542 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002543 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002544 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002545 const u8 *mac_addr = NULL;
2546 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002547 struct get_key_cookie cookie = {
2548 .error = 0,
2549 };
2550 void *hdr;
2551 struct sk_buff *msg;
2552
2553 if (info->attrs[NL80211_ATTR_KEY_IDX])
2554 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2555
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002556 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002557 return -EINVAL;
2558
2559 if (info->attrs[NL80211_ATTR_MAC])
2560 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2561
Johannes Berge31b8212010-10-05 19:39:30 +02002562 pairwise = !!mac_addr;
2563 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2564 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2565 if (kt >= NUM_NL80211_KEYTYPES)
2566 return -EINVAL;
2567 if (kt != NL80211_KEYTYPE_GROUP &&
2568 kt != NL80211_KEYTYPE_PAIRWISE)
2569 return -EINVAL;
2570 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2571 }
2572
Johannes Berg4c476992010-10-04 21:36:35 +02002573 if (!rdev->ops->get_key)
2574 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002575
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002577 if (!msg)
2578 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002579
Eric W. Biederman15e47302012-09-07 20:12:54 +00002580 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002581 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002582 if (IS_ERR(hdr))
2583 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002584
2585 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002586 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002587
David S. Miller9360ffd2012-03-29 04:41:26 -04002588 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2589 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2590 goto nla_put_failure;
2591 if (mac_addr &&
2592 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2593 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002594
Johannes Berge31b8212010-10-05 19:39:30 +02002595 if (pairwise && mac_addr &&
2596 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2597 return -ENOENT;
2598
Hila Gonene35e4d22012-06-27 17:19:42 +03002599 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2600 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002601
2602 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002603 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002604
2605 if (cookie.error)
2606 goto nla_put_failure;
2607
2608 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002609 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002610
2611 nla_put_failure:
2612 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002613 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002614 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002615 return err;
2616}
2617
2618static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2619{
Johannes Berg4c476992010-10-04 21:36:35 +02002620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002621 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002622 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002623 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002624
Johannes Bergb9454e82009-07-08 13:29:08 +02002625 err = nl80211_parse_key(info, &key);
2626 if (err)
2627 return err;
2628
2629 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002630 return -EINVAL;
2631
Johannes Bergb9454e82009-07-08 13:29:08 +02002632 /* only support setting default key */
2633 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002634 return -EINVAL;
2635
Johannes Bergfffd0932009-07-08 14:22:54 +02002636 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002637
2638 if (key.def) {
2639 if (!rdev->ops->set_default_key) {
2640 err = -EOPNOTSUPP;
2641 goto out;
2642 }
2643
2644 err = nl80211_key_allowed(dev->ieee80211_ptr);
2645 if (err)
2646 goto out;
2647
Hila Gonene35e4d22012-06-27 17:19:42 +03002648 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002649 key.def_uni, key.def_multi);
2650
2651 if (err)
2652 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002653
Johannes Berg3d23e342009-09-29 23:27:28 +02002654#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002655 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002656#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002657 } else {
2658 if (key.def_uni || !key.def_multi) {
2659 err = -EINVAL;
2660 goto out;
2661 }
2662
2663 if (!rdev->ops->set_default_mgmt_key) {
2664 err = -EOPNOTSUPP;
2665 goto out;
2666 }
2667
2668 err = nl80211_key_allowed(dev->ieee80211_ptr);
2669 if (err)
2670 goto out;
2671
Hila Gonene35e4d22012-06-27 17:19:42 +03002672 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002673 if (err)
2674 goto out;
2675
2676#ifdef CONFIG_CFG80211_WEXT
2677 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2678#endif
2679 }
2680
2681 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002682 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002683
Johannes Berg41ade002007-12-19 02:03:29 +01002684 return err;
2685}
2686
2687static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2688{
Johannes Berg4c476992010-10-04 21:36:35 +02002689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002690 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002691 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002692 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002693 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002694
Johannes Bergb9454e82009-07-08 13:29:08 +02002695 err = nl80211_parse_key(info, &key);
2696 if (err)
2697 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002698
Johannes Bergb9454e82009-07-08 13:29:08 +02002699 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002700 return -EINVAL;
2701
Johannes Berg41ade002007-12-19 02:03:29 +01002702 if (info->attrs[NL80211_ATTR_MAC])
2703 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2704
Johannes Berge31b8212010-10-05 19:39:30 +02002705 if (key.type == -1) {
2706 if (mac_addr)
2707 key.type = NL80211_KEYTYPE_PAIRWISE;
2708 else
2709 key.type = NL80211_KEYTYPE_GROUP;
2710 }
2711
2712 /* for now */
2713 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2714 key.type != NL80211_KEYTYPE_GROUP)
2715 return -EINVAL;
2716
Johannes Berg4c476992010-10-04 21:36:35 +02002717 if (!rdev->ops->add_key)
2718 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002719
Johannes Berge31b8212010-10-05 19:39:30 +02002720 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2721 key.type == NL80211_KEYTYPE_PAIRWISE,
2722 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002723 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002724
2725 wdev_lock(dev->ieee80211_ptr);
2726 err = nl80211_key_allowed(dev->ieee80211_ptr);
2727 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002728 err = rdev_add_key(rdev, dev, key.idx,
2729 key.type == NL80211_KEYTYPE_PAIRWISE,
2730 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002731 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002732
Johannes Berg41ade002007-12-19 02:03:29 +01002733 return err;
2734}
2735
2736static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2737{
Johannes Berg4c476992010-10-04 21:36:35 +02002738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002739 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002740 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002741 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002742 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002743
Johannes Bergb9454e82009-07-08 13:29:08 +02002744 err = nl80211_parse_key(info, &key);
2745 if (err)
2746 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002747
2748 if (info->attrs[NL80211_ATTR_MAC])
2749 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2750
Johannes Berge31b8212010-10-05 19:39:30 +02002751 if (key.type == -1) {
2752 if (mac_addr)
2753 key.type = NL80211_KEYTYPE_PAIRWISE;
2754 else
2755 key.type = NL80211_KEYTYPE_GROUP;
2756 }
2757
2758 /* for now */
2759 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2760 key.type != NL80211_KEYTYPE_GROUP)
2761 return -EINVAL;
2762
Johannes Berg4c476992010-10-04 21:36:35 +02002763 if (!rdev->ops->del_key)
2764 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002765
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 wdev_lock(dev->ieee80211_ptr);
2767 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002768
2769 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2770 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2771 err = -ENOENT;
2772
Johannes Bergfffd0932009-07-08 14:22:54 +02002773 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002774 err = rdev_del_key(rdev, dev, key.idx,
2775 key.type == NL80211_KEYTYPE_PAIRWISE,
2776 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002777
Johannes Berg3d23e342009-09-29 23:27:28 +02002778#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002779 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002781 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002782 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002783 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2784 }
2785#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002786 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002787
Johannes Berg41ade002007-12-19 02:03:29 +01002788 return err;
2789}
2790
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302791/* This function returns an error or the number of nested attributes */
2792static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2793{
2794 struct nlattr *attr;
2795 int n_entries = 0, tmp;
2796
2797 nla_for_each_nested(attr, nl_attr, tmp) {
2798 if (nla_len(attr) != ETH_ALEN)
2799 return -EINVAL;
2800
2801 n_entries++;
2802 }
2803
2804 return n_entries;
2805}
2806
2807/*
2808 * This function parses ACL information and allocates memory for ACL data.
2809 * On successful return, the calling function is responsible to free the
2810 * ACL buffer returned by this function.
2811 */
2812static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2813 struct genl_info *info)
2814{
2815 enum nl80211_acl_policy acl_policy;
2816 struct nlattr *attr;
2817 struct cfg80211_acl_data *acl;
2818 int i = 0, n_entries, tmp;
2819
2820 if (!wiphy->max_acl_mac_addrs)
2821 return ERR_PTR(-EOPNOTSUPP);
2822
2823 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2824 return ERR_PTR(-EINVAL);
2825
2826 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2827 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2828 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2829 return ERR_PTR(-EINVAL);
2830
2831 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2832 return ERR_PTR(-EINVAL);
2833
2834 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2835 if (n_entries < 0)
2836 return ERR_PTR(n_entries);
2837
2838 if (n_entries > wiphy->max_acl_mac_addrs)
2839 return ERR_PTR(-ENOTSUPP);
2840
2841 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2842 GFP_KERNEL);
2843 if (!acl)
2844 return ERR_PTR(-ENOMEM);
2845
2846 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2847 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2848 i++;
2849 }
2850
2851 acl->n_acl_entries = n_entries;
2852 acl->acl_policy = acl_policy;
2853
2854 return acl;
2855}
2856
2857static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2858{
2859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2860 struct net_device *dev = info->user_ptr[1];
2861 struct cfg80211_acl_data *acl;
2862 int err;
2863
2864 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2865 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2866 return -EOPNOTSUPP;
2867
2868 if (!dev->ieee80211_ptr->beacon_interval)
2869 return -EINVAL;
2870
2871 acl = parse_acl_data(&rdev->wiphy, info);
2872 if (IS_ERR(acl))
2873 return PTR_ERR(acl);
2874
2875 err = rdev_set_mac_acl(rdev, dev, acl);
2876
2877 kfree(acl);
2878
2879 return err;
2880}
2881
Johannes Berg88600202012-02-13 15:17:18 +01002882static int nl80211_parse_beacon(struct genl_info *info,
2883 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002884{
Johannes Berg88600202012-02-13 15:17:18 +01002885 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002886
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002887 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2888 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2889 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2890 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002891 return -EINVAL;
2892
Johannes Berg88600202012-02-13 15:17:18 +01002893 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002894
Johannes Berged1b6cc2007-12-19 02:03:32 +01002895 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002896 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2897 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2898 if (!bcn->head_len)
2899 return -EINVAL;
2900 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002901 }
2902
2903 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002904 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2905 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002906 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002907 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002908 }
2909
Johannes Berg4c476992010-10-04 21:36:35 +02002910 if (!haveinfo)
2911 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002912
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002913 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002914 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2915 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002916 }
2917
2918 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002919 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002920 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002921 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002922 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2923 }
2924
2925 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002926 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002927 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002928 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002929 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2930 }
2931
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002932 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002933 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002934 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002935 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002936 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2937 }
2938
Johannes Berg88600202012-02-13 15:17:18 +01002939 return 0;
2940}
2941
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002942static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2943 struct cfg80211_ap_settings *params)
2944{
2945 struct wireless_dev *wdev;
2946 bool ret = false;
2947
Johannes Berg89a54e42012-06-15 14:33:17 +02002948 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002949 if (wdev->iftype != NL80211_IFTYPE_AP &&
2950 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2951 continue;
2952
Johannes Berg683b6d32012-11-08 21:25:48 +01002953 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002954 continue;
2955
Johannes Berg683b6d32012-11-08 21:25:48 +01002956 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002957 ret = true;
2958 break;
2959 }
2960
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002961 return ret;
2962}
2963
Jouni Malinene39e5b52012-09-30 19:29:39 +03002964static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2965 enum nl80211_auth_type auth_type,
2966 enum nl80211_commands cmd)
2967{
2968 if (auth_type > NL80211_AUTHTYPE_MAX)
2969 return false;
2970
2971 switch (cmd) {
2972 case NL80211_CMD_AUTHENTICATE:
2973 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2974 auth_type == NL80211_AUTHTYPE_SAE)
2975 return false;
2976 return true;
2977 case NL80211_CMD_CONNECT:
2978 case NL80211_CMD_START_AP:
2979 /* SAE not supported yet */
2980 if (auth_type == NL80211_AUTHTYPE_SAE)
2981 return false;
2982 return true;
2983 default:
2984 return false;
2985 }
2986}
2987
Johannes Berg88600202012-02-13 15:17:18 +01002988static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2989{
2990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2991 struct net_device *dev = info->user_ptr[1];
2992 struct wireless_dev *wdev = dev->ieee80211_ptr;
2993 struct cfg80211_ap_settings params;
2994 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01002995 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01002996
2997 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2998 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2999 return -EOPNOTSUPP;
3000
3001 if (!rdev->ops->start_ap)
3002 return -EOPNOTSUPP;
3003
3004 if (wdev->beacon_interval)
3005 return -EALREADY;
3006
3007 memset(&params, 0, sizeof(params));
3008
3009 /* these are required for START_AP */
3010 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3011 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3012 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3013 return -EINVAL;
3014
3015 err = nl80211_parse_beacon(info, &params.beacon);
3016 if (err)
3017 return err;
3018
3019 params.beacon_interval =
3020 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3021 params.dtim_period =
3022 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3023
3024 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3025 if (err)
3026 return err;
3027
3028 /*
3029 * In theory, some of these attributes should be required here
3030 * but since they were not used when the command was originally
3031 * added, keep them optional for old user space programs to let
3032 * them continue to work with drivers that do not need the
3033 * additional information -- drivers must check!
3034 */
3035 if (info->attrs[NL80211_ATTR_SSID]) {
3036 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3037 params.ssid_len =
3038 nla_len(info->attrs[NL80211_ATTR_SSID]);
3039 if (params.ssid_len == 0 ||
3040 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3041 return -EINVAL;
3042 }
3043
3044 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3045 params.hidden_ssid = nla_get_u32(
3046 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3047 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3048 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3049 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3050 return -EINVAL;
3051 }
3052
3053 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3054
3055 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3056 params.auth_type = nla_get_u32(
3057 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003058 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3059 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003060 return -EINVAL;
3061 } else
3062 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3063
3064 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3065 NL80211_MAX_NR_CIPHER_SUITES);
3066 if (err)
3067 return err;
3068
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303069 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3070 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3071 return -EOPNOTSUPP;
3072 params.inactivity_timeout = nla_get_u16(
3073 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3074 }
3075
Johannes Berg53cabad2012-11-14 15:17:28 +01003076 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3078 return -EINVAL;
3079 params.p2p_ctwindow =
3080 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3081 if (params.p2p_ctwindow > 127)
3082 return -EINVAL;
3083 if (params.p2p_ctwindow != 0 &&
3084 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3085 return -EINVAL;
3086 }
3087
3088 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3089 u8 tmp;
3090
3091 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3092 return -EINVAL;
3093 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3094 if (tmp > 1)
3095 return -EINVAL;
3096 params.p2p_opp_ps = tmp;
3097 if (params.p2p_opp_ps != 0 &&
3098 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3099 return -EINVAL;
3100 }
3101
Johannes Bergaa430da2012-05-16 23:50:18 +02003102 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003103 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3104 if (err)
3105 return err;
3106 } else if (wdev->preset_chandef.chan) {
3107 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003108 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003109 return -EINVAL;
3110
Johannes Berg683b6d32012-11-08 21:25:48 +01003111 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003112 return -EINVAL;
3113
Simon Wunderlich04f39042013-02-08 18:16:19 +01003114 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3115 if (err < 0)
3116 return err;
3117 if (err) {
3118 radar_detect_width = BIT(params.chandef.width);
3119 params.radar_required = true;
3120 }
3121
Simon Wunderlich04f39042013-02-08 18:16:19 +01003122 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3123 params.chandef.chan,
3124 CHAN_MODE_SHARED,
3125 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003126 if (err)
3127 return err;
3128
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303129 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3130 params.acl = parse_acl_data(&rdev->wiphy, info);
3131 if (IS_ERR(params.acl))
3132 return PTR_ERR(params.acl);
3133 }
3134
Hila Gonene35e4d22012-06-27 17:19:42 +03003135 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003136 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003137 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003138 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003139 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003140 wdev->ssid_len = params.ssid_len;
3141 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003142 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303143
3144 kfree(params.acl);
3145
Johannes Berg56d18932011-05-09 18:41:15 +02003146 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003147}
3148
Johannes Berg88600202012-02-13 15:17:18 +01003149static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3150{
3151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3152 struct net_device *dev = info->user_ptr[1];
3153 struct wireless_dev *wdev = dev->ieee80211_ptr;
3154 struct cfg80211_beacon_data params;
3155 int err;
3156
3157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3158 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3159 return -EOPNOTSUPP;
3160
3161 if (!rdev->ops->change_beacon)
3162 return -EOPNOTSUPP;
3163
3164 if (!wdev->beacon_interval)
3165 return -EINVAL;
3166
3167 err = nl80211_parse_beacon(info, &params);
3168 if (err)
3169 return err;
3170
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003172}
3173
3174static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003175{
Johannes Berg4c476992010-10-04 21:36:35 +02003176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3177 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003178
Michal Kazior60771782012-06-29 12:46:56 +02003179 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003180}
3181
Johannes Berg5727ef12007-12-19 02:03:34 +01003182static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3183 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3184 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3185 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003186 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003187 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003188 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003189};
3190
Johannes Bergeccb8e82009-05-11 21:57:56 +03003191static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003192 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003193 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003194{
3195 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003196 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003197 int flag;
3198
Johannes Bergeccb8e82009-05-11 21:57:56 +03003199 /*
3200 * Try parsing the new attribute first so userspace
3201 * can specify both for older kernels.
3202 */
3203 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3204 if (nla) {
3205 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003206
Johannes Bergeccb8e82009-05-11 21:57:56 +03003207 sta_flags = nla_data(nla);
3208 params->sta_flags_mask = sta_flags->mask;
3209 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003210 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003211 if ((params->sta_flags_mask |
3212 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3213 return -EINVAL;
3214 return 0;
3215 }
3216
3217 /* if present, parse the old attribute */
3218
3219 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003220 if (!nla)
3221 return 0;
3222
3223 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3224 nla, sta_flags_policy))
3225 return -EINVAL;
3226
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003227 /*
3228 * Only allow certain flags for interface types so that
3229 * other attributes are silently ignored. Remember that
3230 * this is backward compatibility code with old userspace
3231 * and shouldn't be hit in other cases anyway.
3232 */
3233 switch (iftype) {
3234 case NL80211_IFTYPE_AP:
3235 case NL80211_IFTYPE_AP_VLAN:
3236 case NL80211_IFTYPE_P2P_GO:
3237 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3238 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3239 BIT(NL80211_STA_FLAG_WME) |
3240 BIT(NL80211_STA_FLAG_MFP);
3241 break;
3242 case NL80211_IFTYPE_P2P_CLIENT:
3243 case NL80211_IFTYPE_STATION:
3244 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3245 BIT(NL80211_STA_FLAG_TDLS_PEER);
3246 break;
3247 case NL80211_IFTYPE_MESH_POINT:
3248 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3249 BIT(NL80211_STA_FLAG_MFP) |
3250 BIT(NL80211_STA_FLAG_AUTHORIZED);
3251 default:
3252 return -EINVAL;
3253 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003254
Johannes Berg3383b5a2012-05-10 20:14:43 +02003255 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3256 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003257 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003258
Johannes Berg3383b5a2012-05-10 20:14:43 +02003259 /* no longer support new API additions in old API */
3260 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3261 return -EINVAL;
3262 }
3263 }
3264
Johannes Berg5727ef12007-12-19 02:03:34 +01003265 return 0;
3266}
3267
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003268static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3269 int attr)
3270{
3271 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003272 u32 bitrate;
3273 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003274
3275 rate = nla_nest_start(msg, attr);
3276 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003277 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003278
3279 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3280 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003281 /* report 16-bit bitrate only if we can */
3282 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003283 if (bitrate > 0 &&
3284 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3285 return false;
3286 if (bitrate_compat > 0 &&
3287 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3288 return false;
3289
3290 if (info->flags & RATE_INFO_FLAGS_MCS) {
3291 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3292 return false;
3293 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3294 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3295 return false;
3296 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3297 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3298 return false;
3299 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3300 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3301 return false;
3302 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3303 return false;
3304 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3305 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3306 return false;
3307 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3308 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3309 return false;
3310 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3311 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3312 return false;
3313 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3314 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3315 return false;
3316 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3317 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3318 return false;
3319 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003320
3321 nla_nest_end(msg, rate);
3322 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003323}
3324
Felix Fietkau119363c2013-04-22 16:29:30 +02003325static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3326 int id)
3327{
3328 void *attr;
3329 int i = 0;
3330
3331 if (!mask)
3332 return true;
3333
3334 attr = nla_nest_start(msg, id);
3335 if (!attr)
3336 return false;
3337
3338 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3339 if (!(mask & BIT(i)))
3340 continue;
3341
3342 if (nla_put_u8(msg, i, signal[i]))
3343 return false;
3344 }
3345
3346 nla_nest_end(msg, attr);
3347
3348 return true;
3349}
3350
Eric W. Biederman15e47302012-09-07 20:12:54 +00003351static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003352 int flags,
3353 struct cfg80211_registered_device *rdev,
3354 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003355 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003356{
3357 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003358 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003359
Eric W. Biederman15e47302012-09-07 20:12:54 +00003360 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003361 if (!hdr)
3362 return -1;
3363
David S. Miller9360ffd2012-03-29 04:41:26 -04003364 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3366 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3367 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003368
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003369 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3370 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003371 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003372 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3373 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3374 sinfo->connected_time))
3375 goto nla_put_failure;
3376 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3377 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3378 sinfo->inactive_time))
3379 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003380 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3381 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003382 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003383 (u32)sinfo->rx_bytes))
3384 goto nla_put_failure;
3385 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003386 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003387 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3388 (u32)sinfo->tx_bytes))
3389 goto nla_put_failure;
3390 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3391 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003392 sinfo->rx_bytes))
3393 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003394 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3395 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003396 sinfo->tx_bytes))
3397 goto nla_put_failure;
3398 if ((sinfo->filled & STATION_INFO_LLID) &&
3399 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3400 goto nla_put_failure;
3401 if ((sinfo->filled & STATION_INFO_PLID) &&
3402 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3403 goto nla_put_failure;
3404 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3405 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3406 sinfo->plink_state))
3407 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003408 switch (rdev->wiphy.signal_type) {
3409 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3411 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3412 sinfo->signal))
3413 goto nla_put_failure;
3414 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3415 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3416 sinfo->signal_avg))
3417 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003418 break;
3419 default:
3420 break;
3421 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003422 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3423 if (!nl80211_put_signal(msg, sinfo->chains,
3424 sinfo->chain_signal,
3425 NL80211_STA_INFO_CHAIN_SIGNAL))
3426 goto nla_put_failure;
3427 }
3428 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3429 if (!nl80211_put_signal(msg, sinfo->chains,
3430 sinfo->chain_signal_avg,
3431 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3432 goto nla_put_failure;
3433 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003434 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003435 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3436 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003437 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003438 }
3439 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3440 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3441 NL80211_STA_INFO_RX_BITRATE))
3442 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003443 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003444 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3445 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3446 sinfo->rx_packets))
3447 goto nla_put_failure;
3448 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3449 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3450 sinfo->tx_packets))
3451 goto nla_put_failure;
3452 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3453 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3454 sinfo->tx_retries))
3455 goto nla_put_failure;
3456 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3458 sinfo->tx_failed))
3459 goto nla_put_failure;
3460 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3461 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3462 sinfo->beacon_loss_count))
3463 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003464 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3465 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3466 sinfo->local_pm))
3467 goto nla_put_failure;
3468 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3469 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3470 sinfo->peer_pm))
3471 goto nla_put_failure;
3472 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3473 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3474 sinfo->nonpeer_pm))
3475 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003476 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3477 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3478 if (!bss_param)
3479 goto nla_put_failure;
3480
David S. Miller9360ffd2012-03-29 04:41:26 -04003481 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3482 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3483 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3484 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3485 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3486 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3487 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3488 sinfo->bss_param.dtim_period) ||
3489 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3490 sinfo->bss_param.beacon_interval))
3491 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003492
3493 nla_nest_end(msg, bss_param);
3494 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003495 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3496 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3497 sizeof(struct nl80211_sta_flag_update),
3498 &sinfo->sta_flags))
3499 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003500 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3501 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3502 sinfo->t_offset))
3503 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003505
David S. Miller9360ffd2012-03-29 04:41:26 -04003506 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3507 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3508 sinfo->assoc_req_ies))
3509 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003510
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003511 return genlmsg_end(msg, hdr);
3512
3513 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003514 genlmsg_cancel(msg, hdr);
3515 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516}
3517
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003518static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003519 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003520{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003521 struct station_info sinfo;
3522 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003523 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003524 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003525 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003527
Johannes Berg97990a02013-04-19 01:02:55 +02003528 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003529 if (err)
3530 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003531
Johannes Berg97990a02013-04-19 01:02:55 +02003532 if (!wdev->netdev) {
3533 err = -EINVAL;
3534 goto out_err;
3535 }
3536
Johannes Bergbba95fe2008-07-29 13:22:51 +02003537 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 goto out_err;
3540 }
3541
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003543 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003544 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 if (err == -ENOENT)
3547 break;
3548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550
3551 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003554 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003555 &sinfo) < 0)
3556 goto out;
3557
3558 sta_idx++;
3559 }
3560
3561
3562 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003563 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003565 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003566 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567
3568 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570
Johannes Berg5727ef12007-12-19 02:03:34 +01003571static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3572{
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003575 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003578 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003581
3582 if (!info->attrs[NL80211_ATTR_MAC])
3583 return -EINVAL;
3584
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 if (!rdev->ops->get_station)
3588 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003592 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003596 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Eric W. Biederman15e47302012-09-07 20:12:54 +00003598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003600 nlmsg_free(msg);
3601 return -ENOBUFS;
3602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003605}
3606
Johannes Berg77ee7c82013-02-15 00:48:33 +01003607int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3610{
3611 if (params->listen_interval != -1)
3612 return -EINVAL;
3613 if (params->aid)
3614 return -EINVAL;
3615
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3618
3619 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003620 case CFG80211_STA_MESH_PEER_KERNEL:
3621 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003622 /*
3623 * No ignoring the TDLS flag here -- the userspace mesh
3624 * code doesn't have the bug of including TDLS in the
3625 * mask everywhere.
3626 */
3627 if (params->sta_flags_mask &
3628 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3629 BIT(NL80211_STA_FLAG_MFP) |
3630 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3631 return -EINVAL;
3632 break;
3633 case CFG80211_STA_TDLS_PEER_SETUP:
3634 case CFG80211_STA_TDLS_PEER_ACTIVE:
3635 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3636 return -EINVAL;
3637 /* ignore since it can't change */
3638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3639 break;
3640 default:
3641 /* disallow mesh-specific things */
3642 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3643 return -EINVAL;
3644 if (params->local_pm)
3645 return -EINVAL;
3646 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3647 return -EINVAL;
3648 }
3649
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3651 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3652 /* TDLS can't be set, ... */
3653 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3654 return -EINVAL;
3655 /*
3656 * ... but don't bother the driver with it. This works around
3657 * a hostapd/wpa_supplicant issue -- it always includes the
3658 * TLDS_PEER flag in the mask even for AP mode.
3659 */
3660 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3661 }
3662
3663 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3664 /* reject other things that can't change */
3665 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3666 return -EINVAL;
3667 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3668 return -EINVAL;
3669 if (params->supported_rates)
3670 return -EINVAL;
3671 if (params->ext_capab || params->ht_capa || params->vht_capa)
3672 return -EINVAL;
3673 }
3674
3675 if (statype != CFG80211_STA_AP_CLIENT) {
3676 if (params->vlan)
3677 return -EINVAL;
3678 }
3679
3680 switch (statype) {
3681 case CFG80211_STA_AP_MLME_CLIENT:
3682 /* Use this only for authorizing/unauthorizing a station */
3683 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3684 return -EOPNOTSUPP;
3685 break;
3686 case CFG80211_STA_AP_CLIENT:
3687 /* accept only the listed bits */
3688 if (params->sta_flags_mask &
3689 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3691 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3692 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3693 BIT(NL80211_STA_FLAG_WME) |
3694 BIT(NL80211_STA_FLAG_MFP)))
3695 return -EINVAL;
3696
3697 /* but authenticated/associated only if driver handles it */
3698 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3699 params->sta_flags_mask &
3700 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3702 return -EINVAL;
3703 break;
3704 case CFG80211_STA_IBSS:
3705 case CFG80211_STA_AP_STA:
3706 /* reject any changes other than AUTHORIZED */
3707 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3708 return -EINVAL;
3709 break;
3710 case CFG80211_STA_TDLS_PEER_SETUP:
3711 /* reject any changes other than AUTHORIZED or WME */
3712 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3713 BIT(NL80211_STA_FLAG_WME)))
3714 return -EINVAL;
3715 /* force (at least) rates when authorizing */
3716 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3717 !params->supported_rates)
3718 return -EINVAL;
3719 break;
3720 case CFG80211_STA_TDLS_PEER_ACTIVE:
3721 /* reject any changes */
3722 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003723 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3725 return -EINVAL;
3726 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003727 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3729 return -EINVAL;
3730 break;
3731 }
3732
3733 return 0;
3734}
3735EXPORT_SYMBOL(cfg80211_check_station_change);
3736
Johannes Berg5727ef12007-12-19 02:03:34 +01003737/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003738 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003739 */
Johannes Berg80b99892011-11-18 16:23:01 +01003740static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003742{
Johannes Berg463d0182009-07-14 00:33:35 +02003743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003744 struct net_device *v;
3745 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003746
Johannes Berg80b99892011-11-18 16:23:01 +01003747 if (!vlanattr)
3748 return NULL;
3749
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3751 if (!v)
3752 return ERR_PTR(-ENODEV);
3753
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3755 ret = -EINVAL;
3756 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003757 }
Johannes Berg80b99892011-11-18 16:23:01 +01003758
Johannes Berg77ee7c82013-02-15 00:48:33 +01003759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3762 ret = -EINVAL;
3763 goto error;
3764 }
3765
Johannes Berg80b99892011-11-18 16:23:01 +01003766 if (!netif_running(v)) {
3767 ret = -ENETDOWN;
3768 goto error;
3769 }
3770
3771 return v;
3772 error:
3773 dev_put(v);
3774 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003775}
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777static struct nla_policy
3778nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3781};
3782
Johannes Bergff276692013-02-15 00:09:01 +01003783static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003785{
Jouni Malinendf881292013-02-14 21:10:54 +02003786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3787 struct nlattr *nla;
3788 int err;
3789
Jouni Malinendf881292013-02-14 21:10:54 +02003790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3792 return 0;
3793
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3797 if (err)
3798 return err;
3799
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3804 return -EINVAL;
3805
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3808
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3810 return -EINVAL;
3811
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3813
3814 return 0;
3815}
3816
Johannes Bergff276692013-02-15 00:09:01 +01003817static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3819{
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003821 if (info->attrs[NL80211_ATTR_PEER_AID])
3822 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003823 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3824 params->ht_capa =
3825 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3826 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3827 params->vht_capa =
3828 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3829
3830 return nl80211_parse_sta_wme(info, params);
3831}
3832
Johannes Berg5727ef12007-12-19 02:03:34 +01003833static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3834{
Johannes Berg4c476992010-10-04 21:36:35 +02003835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003836 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003837 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003838 u8 *mac_addr;
3839 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003840
3841 memset(&params, 0, sizeof(params));
3842
3843 params.listen_interval = -1;
3844
Johannes Berg77ee7c82013-02-15 00:48:33 +01003845 if (!rdev->ops->change_station)
3846 return -EOPNOTSUPP;
3847
Johannes Berg5727ef12007-12-19 02:03:34 +01003848 if (info->attrs[NL80211_ATTR_STA_AID])
3849 return -EINVAL;
3850
3851 if (!info->attrs[NL80211_ATTR_MAC])
3852 return -EINVAL;
3853
3854 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3855
3856 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3857 params.supported_rates =
3858 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3859 params.supported_rates_len =
3860 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3861 }
3862
Jouni Malinen9d62a982013-02-14 21:10:13 +02003863 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3864 params.capability =
3865 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3866 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3867 }
3868
3869 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3870 params.ext_capab =
3871 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3872 params.ext_capab_len =
3873 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3874 }
3875
Jouni Malinendf881292013-02-14 21:10:54 +02003876 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003877 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003878
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003879 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003880 return -EINVAL;
3881
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003883 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003884 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3885 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3886 return -EINVAL;
3887 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003888
Johannes Bergf8bacc22013-02-14 23:27:01 +01003889 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003890 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003891 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3892 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3893 return -EINVAL;
3894 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3895 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003896
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003897 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3898 enum nl80211_mesh_power_mode pm = nla_get_u32(
3899 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3900
3901 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3902 pm > NL80211_MESH_POWER_MAX)
3903 return -EINVAL;
3904
3905 params.local_pm = pm;
3906 }
3907
Johannes Berg77ee7c82013-02-15 00:48:33 +01003908 /* Include parameters for TDLS peer (will check later) */
3909 err = nl80211_set_station_tdls(info, &params);
3910 if (err)
3911 return err;
3912
3913 params.vlan = get_vlan(info, rdev);
3914 if (IS_ERR(params.vlan))
3915 return PTR_ERR(params.vlan);
3916
Johannes Berga97f4422009-06-18 17:23:43 +02003917 switch (dev->ieee80211_ptr->iftype) {
3918 case NL80211_IFTYPE_AP:
3919 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003920 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003921 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003922 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003923 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003924 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003925 break;
3926 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003927 err = -EOPNOTSUPP;
3928 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003929 }
3930
Johannes Berg77ee7c82013-02-15 00:48:33 +01003931 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003932 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003933
Johannes Berg77ee7c82013-02-15 00:48:33 +01003934 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003935 if (params.vlan)
3936 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003937
Johannes Berg5727ef12007-12-19 02:03:34 +01003938 return err;
3939}
3940
3941static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3942{
Johannes Berg4c476992010-10-04 21:36:35 +02003943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003945 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003946 struct station_parameters params;
3947 u8 *mac_addr = NULL;
3948
3949 memset(&params, 0, sizeof(params));
3950
Johannes Berg984c3112013-02-14 23:43:25 +01003951 if (!rdev->ops->add_station)
3952 return -EOPNOTSUPP;
3953
Johannes Berg5727ef12007-12-19 02:03:34 +01003954 if (!info->attrs[NL80211_ATTR_MAC])
3955 return -EINVAL;
3956
Johannes Berg5727ef12007-12-19 02:03:34 +01003957 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3958 return -EINVAL;
3959
3960 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3961 return -EINVAL;
3962
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003963 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3964 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003965 return -EINVAL;
3966
Johannes Berg5727ef12007-12-19 02:03:34 +01003967 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3968 params.supported_rates =
3969 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3970 params.supported_rates_len =
3971 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3972 params.listen_interval =
3973 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003974
Jouni Malinen3d124ea2013-05-27 18:24:02 +03003975 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003976 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03003977 else
3978 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003979 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3980 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003981
Jouni Malinen9d62a982013-02-14 21:10:13 +02003982 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3983 params.capability =
3984 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3985 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3986 }
3987
3988 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3989 params.ext_capab =
3990 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3991 params.ext_capab_len =
3992 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3993 }
3994
Jouni Malinen36aedc902008-08-25 11:58:58 +03003995 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3996 params.ht_capa =
3997 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003998
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003999 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4000 params.vht_capa =
4001 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4002
Johannes Bergf8bacc22013-02-14 23:27:01 +01004003 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004004 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004005 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4006 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4007 return -EINVAL;
4008 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004009
Johannes Bergff276692013-02-15 00:09:01 +01004010 err = nl80211_parse_sta_wme(info, &params);
4011 if (err)
4012 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004013
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004014 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004015 return -EINVAL;
4016
Johannes Berg77ee7c82013-02-15 00:48:33 +01004017 /* When you run into this, adjust the code below for the new flag */
4018 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4019
Johannes Bergbdd90d52011-12-14 12:20:27 +01004020 switch (dev->ieee80211_ptr->iftype) {
4021 case NL80211_IFTYPE_AP:
4022 case NL80211_IFTYPE_AP_VLAN:
4023 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004024 /* ignore WME attributes if iface/sta is not capable */
4025 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4026 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4027 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004028
Johannes Bergbdd90d52011-12-14 12:20:27 +01004029 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004030 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4031 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004032 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004033 /* but don't bother the driver with it */
4034 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004035
Johannes Bergd582cff2012-10-26 17:53:44 +02004036 /* allow authenticated/associated only if driver handles it */
4037 if (!(rdev->wiphy.features &
4038 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4039 params.sta_flags_mask &
4040 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4041 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4042 return -EINVAL;
4043
Johannes Bergbdd90d52011-12-14 12:20:27 +01004044 /* must be last in here for error handling */
4045 params.vlan = get_vlan(info, rdev);
4046 if (IS_ERR(params.vlan))
4047 return PTR_ERR(params.vlan);
4048 break;
4049 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004050 /* ignore uAPSD data */
4051 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4052
Johannes Bergd582cff2012-10-26 17:53:44 +02004053 /* associated is disallowed */
4054 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4055 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004056 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004057 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4058 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004059 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004060 break;
4061 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004062 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004063 /* ignore uAPSD data */
4064 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4065
Johannes Berg77ee7c82013-02-15 00:48:33 +01004066 /* these are disallowed */
4067 if (params.sta_flags_mask &
4068 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4069 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004070 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004071 /* Only TDLS peers can be added */
4072 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4073 return -EINVAL;
4074 /* Can only add if TDLS ... */
4075 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4076 return -EOPNOTSUPP;
4077 /* ... with external setup is supported */
4078 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4079 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004080 /*
4081 * Older wpa_supplicant versions always mark the TDLS peer
4082 * as authorized, but it shouldn't yet be.
4083 */
4084 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004085 break;
4086 default:
4087 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004088 }
4089
Johannes Bergbdd90d52011-12-14 12:20:27 +01004090 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004091
Hila Gonene35e4d22012-06-27 17:19:42 +03004092 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004093
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 if (params.vlan)
4095 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004096 return err;
4097}
4098
4099static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4100{
Johannes Berg4c476992010-10-04 21:36:35 +02004101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4102 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004103 u8 *mac_addr = NULL;
4104
4105 if (info->attrs[NL80211_ATTR_MAC])
4106 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4107
Johannes Berge80cf852009-05-11 14:43:13 +02004108 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004109 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004110 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004111 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4112 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004113
Johannes Berg4c476992010-10-04 21:36:35 +02004114 if (!rdev->ops->del_station)
4115 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004116
Hila Gonene35e4d22012-06-27 17:19:42 +03004117 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004118}
4119
Eric W. Biederman15e47302012-09-07 20:12:54 +00004120static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004121 int flags, struct net_device *dev,
4122 u8 *dst, u8 *next_hop,
4123 struct mpath_info *pinfo)
4124{
4125 void *hdr;
4126 struct nlattr *pinfoattr;
4127
Eric W. Biederman15e47302012-09-07 20:12:54 +00004128 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004129 if (!hdr)
4130 return -1;
4131
David S. Miller9360ffd2012-03-29 04:41:26 -04004132 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4133 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4134 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4135 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4136 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004137
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004138 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4139 if (!pinfoattr)
4140 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004141 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4142 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4143 pinfo->frame_qlen))
4144 goto nla_put_failure;
4145 if (((pinfo->filled & MPATH_INFO_SN) &&
4146 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4147 ((pinfo->filled & MPATH_INFO_METRIC) &&
4148 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4149 pinfo->metric)) ||
4150 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4151 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4152 pinfo->exptime)) ||
4153 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4154 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4155 pinfo->flags)) ||
4156 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4157 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4158 pinfo->discovery_timeout)) ||
4159 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4160 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4161 pinfo->discovery_retries)))
4162 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004163
4164 nla_nest_end(msg, pinfoattr);
4165
4166 return genlmsg_end(msg, hdr);
4167
4168 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004169 genlmsg_cancel(msg, hdr);
4170 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004171}
4172
4173static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004174 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004175{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004176 struct mpath_info pinfo;
4177 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004178 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004179 u8 dst[ETH_ALEN];
4180 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004181 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004182 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004183
Johannes Berg97990a02013-04-19 01:02:55 +02004184 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004185 if (err)
4186 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004187
4188 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004189 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004190 goto out_err;
4191 }
4192
Johannes Berg97990a02013-04-19 01:02:55 +02004193 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004194 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004195 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004196 }
4197
Johannes Bergbba95fe2008-07-29 13:22:51 +02004198 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004199 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4200 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004201 if (err == -ENOENT)
4202 break;
4203 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004204 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004205
Eric W. Biederman15e47302012-09-07 20:12:54 +00004206 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004207 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004208 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004209 &pinfo) < 0)
4210 goto out;
4211
4212 path_idx++;
4213 }
4214
4215
4216 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004217 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004218 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004219 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004220 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004221 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004222}
4223
4224static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4225{
Johannes Berg4c476992010-10-04 21:36:35 +02004226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004227 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004228 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004229 struct mpath_info pinfo;
4230 struct sk_buff *msg;
4231 u8 *dst = NULL;
4232 u8 next_hop[ETH_ALEN];
4233
4234 memset(&pinfo, 0, sizeof(pinfo));
4235
4236 if (!info->attrs[NL80211_ATTR_MAC])
4237 return -EINVAL;
4238
4239 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4240
Johannes Berg4c476992010-10-04 21:36:35 +02004241 if (!rdev->ops->get_mpath)
4242 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004243
Johannes Berg4c476992010-10-04 21:36:35 +02004244 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4245 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004246
Hila Gonene35e4d22012-06-27 17:19:42 +03004247 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004249 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004250
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004253 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004254
Eric W. Biederman15e47302012-09-07 20:12:54 +00004255 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004256 dev, dst, next_hop, &pinfo) < 0) {
4257 nlmsg_free(msg);
4258 return -ENOBUFS;
4259 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260
Johannes Berg4c476992010-10-04 21:36:35 +02004261 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262}
4263
4264static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4265{
Johannes Berg4c476992010-10-04 21:36:35 +02004266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4267 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004268 u8 *dst = NULL;
4269 u8 *next_hop = NULL;
4270
4271 if (!info->attrs[NL80211_ATTR_MAC])
4272 return -EINVAL;
4273
4274 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4275 return -EINVAL;
4276
4277 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4278 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4279
Johannes Berg4c476992010-10-04 21:36:35 +02004280 if (!rdev->ops->change_mpath)
4281 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004282
Johannes Berg4c476992010-10-04 21:36:35 +02004283 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4284 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004285
Hila Gonene35e4d22012-06-27 17:19:42 +03004286 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004287}
Johannes Berg4c476992010-10-04 21:36:35 +02004288
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004289static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4290{
Johannes Berg4c476992010-10-04 21:36:35 +02004291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4292 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004293 u8 *dst = NULL;
4294 u8 *next_hop = NULL;
4295
4296 if (!info->attrs[NL80211_ATTR_MAC])
4297 return -EINVAL;
4298
4299 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4300 return -EINVAL;
4301
4302 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4303 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4304
Johannes Berg4c476992010-10-04 21:36:35 +02004305 if (!rdev->ops->add_mpath)
4306 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004307
Johannes Berg4c476992010-10-04 21:36:35 +02004308 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4309 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004310
Hila Gonene35e4d22012-06-27 17:19:42 +03004311 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004312}
4313
4314static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4315{
Johannes Berg4c476992010-10-04 21:36:35 +02004316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4317 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004318 u8 *dst = NULL;
4319
4320 if (info->attrs[NL80211_ATTR_MAC])
4321 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4322
Johannes Berg4c476992010-10-04 21:36:35 +02004323 if (!rdev->ops->del_mpath)
4324 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004325
Hila Gonene35e4d22012-06-27 17:19:42 +03004326 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004327}
4328
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004329static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4330{
Johannes Berg4c476992010-10-04 21:36:35 +02004331 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4332 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004333 struct bss_parameters params;
4334
4335 memset(&params, 0, sizeof(params));
4336 /* default to not changing parameters */
4337 params.use_cts_prot = -1;
4338 params.use_short_preamble = -1;
4339 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004340 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004341 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004342 params.p2p_ctwindow = -1;
4343 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004344
4345 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4346 params.use_cts_prot =
4347 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4348 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4349 params.use_short_preamble =
4350 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4351 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4352 params.use_short_slot_time =
4353 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004354 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4355 params.basic_rates =
4356 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4357 params.basic_rates_len =
4358 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4359 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004360 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4361 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004362 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4363 params.ht_opmode =
4364 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004365
Johannes Berg53cabad2012-11-14 15:17:28 +01004366 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4367 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4368 return -EINVAL;
4369 params.p2p_ctwindow =
4370 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4371 if (params.p2p_ctwindow < 0)
4372 return -EINVAL;
4373 if (params.p2p_ctwindow != 0 &&
4374 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4375 return -EINVAL;
4376 }
4377
4378 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4379 u8 tmp;
4380
4381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4382 return -EINVAL;
4383 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4384 if (tmp > 1)
4385 return -EINVAL;
4386 params.p2p_opp_ps = tmp;
4387 if (params.p2p_opp_ps &&
4388 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4389 return -EINVAL;
4390 }
4391
Johannes Berg4c476992010-10-04 21:36:35 +02004392 if (!rdev->ops->change_bss)
4393 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004394
Johannes Berg074ac8d2010-09-16 14:58:22 +02004395 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004396 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4397 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004398
Hila Gonene35e4d22012-06-27 17:19:42 +03004399 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004400}
4401
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004402static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004403 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4404 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4405 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4406 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4407 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4408 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4409};
4410
4411static int parse_reg_rule(struct nlattr *tb[],
4412 struct ieee80211_reg_rule *reg_rule)
4413{
4414 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4415 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4416
4417 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4418 return -EINVAL;
4419 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4420 return -EINVAL;
4421 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4422 return -EINVAL;
4423 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4424 return -EINVAL;
4425 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4426 return -EINVAL;
4427
4428 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4429
4430 freq_range->start_freq_khz =
4431 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4432 freq_range->end_freq_khz =
4433 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4434 freq_range->max_bandwidth_khz =
4435 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4436
4437 power_rule->max_eirp =
4438 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4439
4440 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4441 power_rule->max_antenna_gain =
4442 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4443
4444 return 0;
4445}
4446
4447static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4448{
4449 int r;
4450 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004451 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004452
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004453 /*
4454 * You should only get this when cfg80211 hasn't yet initialized
4455 * completely when built-in to the kernel right between the time
4456 * window between nl80211_init() and regulatory_init(), if that is
4457 * even possible.
4458 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004459 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004460 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004461
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004462 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4463 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004464
4465 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4466
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004467 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4468 user_reg_hint_type =
4469 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4470 else
4471 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4472
4473 switch (user_reg_hint_type) {
4474 case NL80211_USER_REG_HINT_USER:
4475 case NL80211_USER_REG_HINT_CELL_BASE:
4476 break;
4477 default:
4478 return -EINVAL;
4479 }
4480
4481 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004482
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004483 return r;
4484}
4485
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004486static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004487 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004488{
Johannes Berg4c476992010-10-04 21:36:35 +02004489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004490 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004491 struct wireless_dev *wdev = dev->ieee80211_ptr;
4492 struct mesh_config cur_params;
4493 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004494 void *hdr;
4495 struct nlattr *pinfoattr;
4496 struct sk_buff *msg;
4497
Johannes Berg29cbe682010-12-03 09:20:44 +01004498 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4499 return -EOPNOTSUPP;
4500
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004501 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004502 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004503
Johannes Berg29cbe682010-12-03 09:20:44 +01004504 wdev_lock(wdev);
4505 /* If not connected, get default parameters */
4506 if (!wdev->mesh_id_len)
4507 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4508 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004509 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004510 wdev_unlock(wdev);
4511
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004512 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004513 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004514
4515 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004516 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004517 if (!msg)
4518 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004519 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004520 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004521 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004522 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004523 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004524 if (!pinfoattr)
4525 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004526 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4527 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4528 cur_params.dot11MeshRetryTimeout) ||
4529 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4530 cur_params.dot11MeshConfirmTimeout) ||
4531 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4532 cur_params.dot11MeshHoldingTimeout) ||
4533 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4534 cur_params.dot11MeshMaxPeerLinks) ||
4535 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4536 cur_params.dot11MeshMaxRetries) ||
4537 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4538 cur_params.dot11MeshTTL) ||
4539 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4540 cur_params.element_ttl) ||
4541 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4542 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004543 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4544 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004545 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4546 cur_params.dot11MeshHWMPmaxPREQretries) ||
4547 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4548 cur_params.path_refresh_time) ||
4549 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4550 cur_params.min_discovery_timeout) ||
4551 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4552 cur_params.dot11MeshHWMPactivePathTimeout) ||
4553 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4554 cur_params.dot11MeshHWMPpreqMinInterval) ||
4555 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4556 cur_params.dot11MeshHWMPperrMinInterval) ||
4557 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4558 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4559 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4560 cur_params.dot11MeshHWMPRootMode) ||
4561 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4562 cur_params.dot11MeshHWMPRannInterval) ||
4563 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4564 cur_params.dot11MeshGateAnnouncementProtocol) ||
4565 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4566 cur_params.dot11MeshForwarding) ||
4567 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004568 cur_params.rssi_threshold) ||
4569 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004570 cur_params.ht_opmode) ||
4571 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4572 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4573 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004574 cur_params.dot11MeshHWMProotInterval) ||
4575 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004576 cur_params.dot11MeshHWMPconfirmationInterval) ||
4577 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4578 cur_params.power_mode) ||
4579 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004580 cur_params.dot11MeshAwakeWindowDuration) ||
4581 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4582 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004583 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004584 nla_nest_end(msg, pinfoattr);
4585 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004586 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587
Johannes Berg3b858752009-03-12 09:55:09 +01004588 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004589 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004590 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004591 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004592 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004593}
4594
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004595static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004596 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4597 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4598 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4599 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4600 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4601 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004602 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004603 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004604 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004605 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4606 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4607 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4608 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4609 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004610 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004611 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004612 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004613 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004614 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004615 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004616 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4617 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004618 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4619 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004620 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004621 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4622 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004623 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004624};
4625
Javier Cardonac80d5452010-12-16 17:37:49 -08004626static const struct nla_policy
4627 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004628 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004629 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4630 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004631 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004632 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004633 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004634 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004635 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004636 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004637};
4638
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004639static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004640 struct mesh_config *cfg,
4641 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004642{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004643 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004644 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004645
Marco Porschea54fba2013-01-07 16:04:48 +01004646#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4647do { \
4648 if (tb[attr]) { \
4649 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4650 return -EINVAL; \
4651 cfg->param = fn(tb[attr]); \
4652 mask |= (1 << (attr - 1)); \
4653 } \
4654} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004655
4656
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004657 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004658 return -EINVAL;
4659 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004660 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004661 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662 return -EINVAL;
4663
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004664 /* This makes sure that there aren't more than 32 mesh config
4665 * parameters (otherwise our bitfield scheme would not work.) */
4666 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4667
4668 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004670 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4671 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4674 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004676 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4677 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004679 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4680 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 mask, NL80211_MESHCONF_MAX_RETRIES,
4683 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004686 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004687 mask, NL80211_MESHCONF_ELEMENT_TTL,
4688 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004690 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4691 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4693 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004694 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4695 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004696 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004697 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4698 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004699 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004700 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4701 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004702 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004703 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4704 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4706 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004707 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4708 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004710 1, 65535, mask,
4711 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004712 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004714 1, 65535, mask,
4715 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004716 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004717 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004718 dot11MeshHWMPnetDiameterTraversalTime,
4719 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004720 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4721 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004722 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4723 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4724 nla_get_u8);
4725 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4726 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004727 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004728 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004729 dot11MeshGateAnnouncementProtocol, 0, 1,
4730 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004731 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004732 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004733 mask, NL80211_MESHCONF_FORWARDING,
4734 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004735 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004736 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4737 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004738 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004739 mask, NL80211_MESHCONF_HT_OPMODE,
4740 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004742 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004743 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4744 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004745 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004746 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4747 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004749 dot11MeshHWMPconfirmationInterval,
4750 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004751 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4752 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004753 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4754 NL80211_MESH_POWER_ACTIVE,
4755 NL80211_MESH_POWER_MAX,
4756 mask, NL80211_MESHCONF_POWER_MODE,
4757 nla_get_u32);
4758 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4759 0, 65535, mask,
4760 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004761 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4762 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4763 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004764 if (mask_out)
4765 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004766
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004767 return 0;
4768
4769#undef FILL_IN_MESH_PARAM_IF_SET
4770}
4771
Javier Cardonac80d5452010-12-16 17:37:49 -08004772static int nl80211_parse_mesh_setup(struct genl_info *info,
4773 struct mesh_setup *setup)
4774{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004776 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4777
4778 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4779 return -EINVAL;
4780 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4781 info->attrs[NL80211_ATTR_MESH_SETUP],
4782 nl80211_mesh_setup_params_policy))
4783 return -EINVAL;
4784
Javier Cardonad299a1f2012-03-31 11:31:33 -07004785 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4786 setup->sync_method =
4787 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4788 IEEE80211_SYNC_METHOD_VENDOR :
4789 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4790
Javier Cardonac80d5452010-12-16 17:37:49 -08004791 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4792 setup->path_sel_proto =
4793 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4794 IEEE80211_PATH_PROTOCOL_VENDOR :
4795 IEEE80211_PATH_PROTOCOL_HWMP;
4796
4797 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4798 setup->path_metric =
4799 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4800 IEEE80211_PATH_METRIC_VENDOR :
4801 IEEE80211_PATH_METRIC_AIRTIME;
4802
Javier Cardona581a8b02011-04-07 15:08:27 -07004803
4804 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004805 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004806 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004807 if (!is_valid_ie_attr(ieattr))
4808 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004809 setup->ie = nla_data(ieattr);
4810 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004811 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004812 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4813 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4814 return -EINVAL;
4815 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004816 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4817 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004818 if (setup->is_secure)
4819 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004820
Colleen Twitty6e16d902013-05-08 11:45:59 -07004821 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4822 if (!setup->user_mpm)
4823 return -EINVAL;
4824 setup->auth_id =
4825 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4826 }
4827
Javier Cardonac80d5452010-12-16 17:37:49 -08004828 return 0;
4829}
4830
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004831static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004832 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004833{
4834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4835 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004836 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004837 struct mesh_config cfg;
4838 u32 mask;
4839 int err;
4840
Johannes Berg29cbe682010-12-03 09:20:44 +01004841 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4842 return -EOPNOTSUPP;
4843
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004844 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004845 return -EOPNOTSUPP;
4846
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004847 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004848 if (err)
4849 return err;
4850
Johannes Berg29cbe682010-12-03 09:20:44 +01004851 wdev_lock(wdev);
4852 if (!wdev->mesh_id_len)
4853 err = -ENOLINK;
4854
4855 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004856 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004857
4858 wdev_unlock(wdev);
4859
4860 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004861}
4862
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004863static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4864{
Johannes Berg458f4f92012-12-06 15:47:38 +01004865 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004866 struct sk_buff *msg;
4867 void *hdr = NULL;
4868 struct nlattr *nl_reg_rules;
4869 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004870
4871 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004872 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004873
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004875 if (!msg)
4876 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004877
Eric W. Biederman15e47302012-09-07 20:12:54 +00004878 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004879 NL80211_CMD_GET_REG);
4880 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004881 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004882
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004883 if (reg_last_request_cell_base() &&
4884 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4885 NL80211_USER_REG_HINT_CELL_BASE))
4886 goto nla_put_failure;
4887
Johannes Berg458f4f92012-12-06 15:47:38 +01004888 rcu_read_lock();
4889 regdom = rcu_dereference(cfg80211_regdomain);
4890
4891 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4892 (regdom->dfs_region &&
4893 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4894 goto nla_put_failure_rcu;
4895
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004896 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4897 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004898 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004899
Johannes Berg458f4f92012-12-06 15:47:38 +01004900 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004901 struct nlattr *nl_reg_rule;
4902 const struct ieee80211_reg_rule *reg_rule;
4903 const struct ieee80211_freq_range *freq_range;
4904 const struct ieee80211_power_rule *power_rule;
4905
Johannes Berg458f4f92012-12-06 15:47:38 +01004906 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004907 freq_range = &reg_rule->freq_range;
4908 power_rule = &reg_rule->power_rule;
4909
4910 nl_reg_rule = nla_nest_start(msg, i);
4911 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004912 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004913
David S. Miller9360ffd2012-03-29 04:41:26 -04004914 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4915 reg_rule->flags) ||
4916 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4917 freq_range->start_freq_khz) ||
4918 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4919 freq_range->end_freq_khz) ||
4920 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4921 freq_range->max_bandwidth_khz) ||
4922 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4923 power_rule->max_antenna_gain) ||
4924 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4925 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004926 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004927
4928 nla_nest_end(msg, nl_reg_rule);
4929 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004930 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004931
4932 nla_nest_end(msg, nl_reg_rules);
4933
4934 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004935 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004936
Johannes Berg458f4f92012-12-06 15:47:38 +01004937nla_put_failure_rcu:
4938 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939nla_put_failure:
4940 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004941put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004942 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004943 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004944}
4945
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004946static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4947{
4948 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4949 struct nlattr *nl_reg_rule;
4950 char *alpha2 = NULL;
4951 int rem_reg_rules = 0, r = 0;
4952 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004953 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954 struct ieee80211_regdomain *rd = NULL;
4955
4956 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4957 return -EINVAL;
4958
4959 if (!info->attrs[NL80211_ATTR_REG_RULES])
4960 return -EINVAL;
4961
4962 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4963
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004964 if (info->attrs[NL80211_ATTR_DFS_REGION])
4965 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4966
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004967 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004968 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004969 num_rules++;
4970 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004971 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 }
4973
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004974 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004975 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004976
4977 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004978 if (!rd)
4979 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004980
4981 rd->n_reg_rules = num_rules;
4982 rd->alpha2[0] = alpha2[0];
4983 rd->alpha2[1] = alpha2[1];
4984
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004985 /*
4986 * Disable DFS master mode if the DFS region was
4987 * not supported or known on this kernel.
4988 */
4989 if (reg_supported_dfs_region(dfs_region))
4990 rd->dfs_region = dfs_region;
4991
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004993 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004994 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004995 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4996 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004997 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4998 if (r)
4999 goto bad_reg;
5000
5001 rule_idx++;
5002
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005003 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5004 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005005 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005006 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005007 }
5008
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005009 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005010 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005011 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005012
Johannes Bergd2372b32008-10-24 20:32:20 +02005013 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005014 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005015 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005016}
5017
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005018static int validate_scan_freqs(struct nlattr *freqs)
5019{
5020 struct nlattr *attr1, *attr2;
5021 int n_channels = 0, tmp1, tmp2;
5022
5023 nla_for_each_nested(attr1, freqs, tmp1) {
5024 n_channels++;
5025 /*
5026 * Some hardware has a limited channel list for
5027 * scanning, and it is pretty much nonsensical
5028 * to scan for a channel twice, so disallow that
5029 * and don't require drivers to check that the
5030 * channel list they get isn't longer than what
5031 * they can scan, as long as they can scan all
5032 * the channels they registered at once.
5033 */
5034 nla_for_each_nested(attr2, freqs, tmp2)
5035 if (attr1 != attr2 &&
5036 nla_get_u32(attr1) == nla_get_u32(attr2))
5037 return 0;
5038 }
5039
5040 return n_channels;
5041}
5042
Johannes Berg2a519312009-02-10 21:25:55 +01005043static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5044{
Johannes Berg4c476992010-10-04 21:36:35 +02005045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005046 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005047 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005048 struct nlattr *attr;
5049 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005050 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005051 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005052
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005053 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5054 return -EINVAL;
5055
Johannes Berg79c97e92009-07-07 03:56:12 +02005056 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005057
Johannes Berg4c476992010-10-04 21:36:35 +02005058 if (!rdev->ops->scan)
5059 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005060
Johannes Bergf9f47522013-03-19 15:04:07 +01005061 if (rdev->scan_req) {
5062 err = -EBUSY;
5063 goto unlock;
5064 }
Johannes Berg2a519312009-02-10 21:25:55 +01005065
5066 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005067 n_channels = validate_scan_freqs(
5068 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005069 if (!n_channels) {
5070 err = -EINVAL;
5071 goto unlock;
5072 }
Johannes Berg2a519312009-02-10 21:25:55 +01005073 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005074 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005075 n_channels = 0;
5076
Johannes Berg2a519312009-02-10 21:25:55 +01005077 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5078 if (wiphy->bands[band])
5079 n_channels += wiphy->bands[band]->n_channels;
5080 }
5081
5082 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5083 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5084 n_ssids++;
5085
Johannes Bergf9f47522013-03-19 15:04:07 +01005086 if (n_ssids > wiphy->max_scan_ssids) {
5087 err = -EINVAL;
5088 goto unlock;
5089 }
Johannes Berg2a519312009-02-10 21:25:55 +01005090
Jouni Malinen70692ad2009-02-16 19:39:13 +02005091 if (info->attrs[NL80211_ATTR_IE])
5092 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5093 else
5094 ie_len = 0;
5095
Johannes Bergf9f47522013-03-19 15:04:07 +01005096 if (ie_len > wiphy->max_scan_ie_len) {
5097 err = -EINVAL;
5098 goto unlock;
5099 }
Johannes Berg18a83652009-03-31 12:12:05 +02005100
Johannes Berg2a519312009-02-10 21:25:55 +01005101 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005102 + sizeof(*request->ssids) * n_ssids
5103 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005104 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005105 if (!request) {
5106 err = -ENOMEM;
5107 goto unlock;
5108 }
Johannes Berg2a519312009-02-10 21:25:55 +01005109
Johannes Berg2a519312009-02-10 21:25:55 +01005110 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005111 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005112 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005113 if (ie_len) {
5114 if (request->ssids)
5115 request->ie = (void *)(request->ssids + n_ssids);
5116 else
5117 request->ie = (void *)(request->channels + n_channels);
5118 }
Johannes Berg2a519312009-02-10 21:25:55 +01005119
Johannes Berg584991d2009-11-02 13:32:03 +01005120 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005121 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5122 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005123 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005124 struct ieee80211_channel *chan;
5125
5126 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5127
5128 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005129 err = -EINVAL;
5130 goto out_free;
5131 }
Johannes Berg584991d2009-11-02 13:32:03 +01005132
5133 /* ignore disabled channels */
5134 if (chan->flags & IEEE80211_CHAN_DISABLED)
5135 continue;
5136
5137 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005138 i++;
5139 }
5140 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005141 enum ieee80211_band band;
5142
Johannes Berg2a519312009-02-10 21:25:55 +01005143 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005144 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5145 int j;
5146 if (!wiphy->bands[band])
5147 continue;
5148 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005149 struct ieee80211_channel *chan;
5150
5151 chan = &wiphy->bands[band]->channels[j];
5152
5153 if (chan->flags & IEEE80211_CHAN_DISABLED)
5154 continue;
5155
5156 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005157 i++;
5158 }
5159 }
5160 }
5161
Johannes Berg584991d2009-11-02 13:32:03 +01005162 if (!i) {
5163 err = -EINVAL;
5164 goto out_free;
5165 }
5166
5167 request->n_channels = i;
5168
Johannes Berg2a519312009-02-10 21:25:55 +01005169 i = 0;
5170 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5171 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005172 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005173 err = -EINVAL;
5174 goto out_free;
5175 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005176 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005177 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005178 i++;
5179 }
5180 }
5181
Jouni Malinen70692ad2009-02-16 19:39:13 +02005182 if (info->attrs[NL80211_ATTR_IE]) {
5183 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005184 memcpy((void *)request->ie,
5185 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005186 request->ie_len);
5187 }
5188
Johannes Berg34850ab2011-07-18 18:08:35 +02005189 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005190 if (wiphy->bands[i])
5191 request->rates[i] =
5192 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005193
5194 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5195 nla_for_each_nested(attr,
5196 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5197 tmp) {
5198 enum ieee80211_band band = nla_type(attr);
5199
Dan Carpenter84404622011-07-29 11:52:18 +03005200 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005201 err = -EINVAL;
5202 goto out_free;
5203 }
5204 err = ieee80211_get_ratemask(wiphy->bands[band],
5205 nla_data(attr),
5206 nla_len(attr),
5207 &request->rates[band]);
5208 if (err)
5209 goto out_free;
5210 }
5211 }
5212
Sam Leffler46856bb2012-10-11 21:03:32 -07005213 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005214 request->flags = nla_get_u32(
5215 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005216 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5217 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5218 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5219 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005220 err = -EOPNOTSUPP;
5221 goto out_free;
5222 }
5223 }
Sam Lefflered4737712012-10-11 21:03:31 -07005224
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305225 request->no_cck =
5226 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5227
Johannes Bergfd014282012-06-18 19:17:03 +02005228 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005229 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005230 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005231
Johannes Berg79c97e92009-07-07 03:56:12 +02005232 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005233 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005234
Johannes Berg463d0182009-07-14 00:33:35 +02005235 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005236 nl80211_send_scan_start(rdev, wdev);
5237 if (wdev->netdev)
5238 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005239 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005240 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005241 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005242 kfree(request);
5243 }
Johannes Berg3b858752009-03-12 09:55:09 +01005244
Johannes Bergf9f47522013-03-19 15:04:07 +01005245 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005246 return err;
5247}
5248
Luciano Coelho807f8a82011-05-11 17:09:35 +03005249static int nl80211_start_sched_scan(struct sk_buff *skb,
5250 struct genl_info *info)
5251{
5252 struct cfg80211_sched_scan_request *request;
5253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5254 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005255 struct nlattr *attr;
5256 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005257 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005258 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005259 enum ieee80211_band band;
5260 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005261 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005262
5263 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5264 !rdev->ops->sched_scan_start)
5265 return -EOPNOTSUPP;
5266
5267 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5268 return -EINVAL;
5269
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005270 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5271 return -EINVAL;
5272
5273 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5274 if (interval == 0)
5275 return -EINVAL;
5276
Luciano Coelho807f8a82011-05-11 17:09:35 +03005277 wiphy = &rdev->wiphy;
5278
5279 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5280 n_channels = validate_scan_freqs(
5281 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5282 if (!n_channels)
5283 return -EINVAL;
5284 } else {
5285 n_channels = 0;
5286
5287 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5288 if (wiphy->bands[band])
5289 n_channels += wiphy->bands[band]->n_channels;
5290 }
5291
5292 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5293 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5294 tmp)
5295 n_ssids++;
5296
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005297 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005298 return -EINVAL;
5299
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005300 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5301 nla_for_each_nested(attr,
5302 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5303 tmp)
5304 n_match_sets++;
5305
5306 if (n_match_sets > wiphy->max_match_sets)
5307 return -EINVAL;
5308
Luciano Coelho807f8a82011-05-11 17:09:35 +03005309 if (info->attrs[NL80211_ATTR_IE])
5310 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5311 else
5312 ie_len = 0;
5313
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005314 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005315 return -EINVAL;
5316
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005317 if (rdev->sched_scan_req) {
5318 err = -EINPROGRESS;
5319 goto out;
5320 }
5321
Luciano Coelho807f8a82011-05-11 17:09:35 +03005322 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005323 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005324 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005325 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005326 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005327 if (!request) {
5328 err = -ENOMEM;
5329 goto out;
5330 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005331
5332 if (n_ssids)
5333 request->ssids = (void *)&request->channels[n_channels];
5334 request->n_ssids = n_ssids;
5335 if (ie_len) {
5336 if (request->ssids)
5337 request->ie = (void *)(request->ssids + n_ssids);
5338 else
5339 request->ie = (void *)(request->channels + n_channels);
5340 }
5341
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005342 if (n_match_sets) {
5343 if (request->ie)
5344 request->match_sets = (void *)(request->ie + ie_len);
5345 else if (request->ssids)
5346 request->match_sets =
5347 (void *)(request->ssids + n_ssids);
5348 else
5349 request->match_sets =
5350 (void *)(request->channels + n_channels);
5351 }
5352 request->n_match_sets = n_match_sets;
5353
Luciano Coelho807f8a82011-05-11 17:09:35 +03005354 i = 0;
5355 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5356 /* user specified, bail out if channel not found */
5357 nla_for_each_nested(attr,
5358 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5359 tmp) {
5360 struct ieee80211_channel *chan;
5361
5362 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5363
5364 if (!chan) {
5365 err = -EINVAL;
5366 goto out_free;
5367 }
5368
5369 /* ignore disabled channels */
5370 if (chan->flags & IEEE80211_CHAN_DISABLED)
5371 continue;
5372
5373 request->channels[i] = chan;
5374 i++;
5375 }
5376 } else {
5377 /* all channels */
5378 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5379 int j;
5380 if (!wiphy->bands[band])
5381 continue;
5382 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5383 struct ieee80211_channel *chan;
5384
5385 chan = &wiphy->bands[band]->channels[j];
5386
5387 if (chan->flags & IEEE80211_CHAN_DISABLED)
5388 continue;
5389
5390 request->channels[i] = chan;
5391 i++;
5392 }
5393 }
5394 }
5395
5396 if (!i) {
5397 err = -EINVAL;
5398 goto out_free;
5399 }
5400
5401 request->n_channels = i;
5402
5403 i = 0;
5404 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5405 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5406 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005407 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005408 err = -EINVAL;
5409 goto out_free;
5410 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005411 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005412 memcpy(request->ssids[i].ssid, nla_data(attr),
5413 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005414 i++;
5415 }
5416 }
5417
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005418 i = 0;
5419 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5420 nla_for_each_nested(attr,
5421 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5422 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005423 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005424
5425 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5426 nla_data(attr), nla_len(attr),
5427 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005428 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005429 if (ssid) {
5430 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5431 err = -EINVAL;
5432 goto out_free;
5433 }
5434 memcpy(request->match_sets[i].ssid.ssid,
5435 nla_data(ssid), nla_len(ssid));
5436 request->match_sets[i].ssid.ssid_len =
5437 nla_len(ssid);
5438 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005439 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5440 if (rssi)
5441 request->rssi_thold = nla_get_u32(rssi);
5442 else
5443 request->rssi_thold =
5444 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005445 i++;
5446 }
5447 }
5448
Luciano Coelho807f8a82011-05-11 17:09:35 +03005449 if (info->attrs[NL80211_ATTR_IE]) {
5450 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5451 memcpy((void *)request->ie,
5452 nla_data(info->attrs[NL80211_ATTR_IE]),
5453 request->ie_len);
5454 }
5455
Sam Leffler46856bb2012-10-11 21:03:32 -07005456 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005457 request->flags = nla_get_u32(
5458 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005459 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5460 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5461 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5462 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005463 err = -EOPNOTSUPP;
5464 goto out_free;
5465 }
5466 }
Sam Lefflered4737712012-10-11 21:03:31 -07005467
Luciano Coelho807f8a82011-05-11 17:09:35 +03005468 request->dev = dev;
5469 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005470 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005471 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005472
Hila Gonene35e4d22012-06-27 17:19:42 +03005473 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005474 if (!err) {
5475 rdev->sched_scan_req = request;
5476 nl80211_send_sched_scan(rdev, dev,
5477 NL80211_CMD_START_SCHED_SCAN);
5478 goto out;
5479 }
5480
5481out_free:
5482 kfree(request);
5483out:
5484 return err;
5485}
5486
5487static int nl80211_stop_sched_scan(struct sk_buff *skb,
5488 struct genl_info *info)
5489{
5490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5491
5492 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5493 !rdev->ops->sched_scan_stop)
5494 return -EOPNOTSUPP;
5495
Johannes Berg5fe231e2013-05-08 21:45:15 +02005496 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005497}
5498
Simon Wunderlich04f39042013-02-08 18:16:19 +01005499static int nl80211_start_radar_detection(struct sk_buff *skb,
5500 struct genl_info *info)
5501{
5502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5503 struct net_device *dev = info->user_ptr[1];
5504 struct wireless_dev *wdev = dev->ieee80211_ptr;
5505 struct cfg80211_chan_def chandef;
5506 int err;
5507
5508 err = nl80211_parse_chandef(rdev, info, &chandef);
5509 if (err)
5510 return err;
5511
5512 if (wdev->cac_started)
5513 return -EBUSY;
5514
5515 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5516 if (err < 0)
5517 return err;
5518
5519 if (err == 0)
5520 return -EINVAL;
5521
5522 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5523 return -EINVAL;
5524
5525 if (!rdev->ops->start_radar_detection)
5526 return -EOPNOTSUPP;
5527
Simon Wunderlich04f39042013-02-08 18:16:19 +01005528 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5529 chandef.chan, CHAN_MODE_SHARED,
5530 BIT(chandef.width));
5531 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005532 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005533
5534 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5535 if (!err) {
5536 wdev->channel = chandef.chan;
5537 wdev->cac_started = true;
5538 wdev->cac_start_time = jiffies;
5539 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005540 return err;
5541}
5542
Johannes Berg9720bb32011-06-21 09:45:33 +02005543static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5544 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005545 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005546 struct wireless_dev *wdev,
5547 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005548{
Johannes Berg48ab9052009-07-10 18:42:31 +02005549 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005550 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005551 void *hdr;
5552 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005553 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005554
5555 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005556
Eric W. Biederman15e47302012-09-07 20:12:54 +00005557 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005558 NL80211_CMD_NEW_SCAN_RESULTS);
5559 if (!hdr)
5560 return -1;
5561
Johannes Berg9720bb32011-06-21 09:45:33 +02005562 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5563
Johannes Berg97990a02013-04-19 01:02:55 +02005564 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5565 goto nla_put_failure;
5566 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005567 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5568 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005569 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5570 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005571
5572 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5573 if (!bss)
5574 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005575 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005576 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005577 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005578
5579 rcu_read_lock();
5580 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005581 if (ies) {
5582 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5583 goto fail_unlock_rcu;
5584 tsf = true;
5585 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5586 ies->len, ies->data))
5587 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005588 }
5589 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005590 if (ies) {
5591 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5592 goto fail_unlock_rcu;
5593 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5594 ies->len, ies->data))
5595 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005596 }
5597 rcu_read_unlock();
5598
David S. Miller9360ffd2012-03-29 04:41:26 -04005599 if (res->beacon_interval &&
5600 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5601 goto nla_put_failure;
5602 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5603 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5604 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5605 jiffies_to_msecs(jiffies - intbss->ts)))
5606 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005607
Johannes Berg77965c92009-02-18 18:45:06 +01005608 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005609 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005610 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5611 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005612 break;
5613 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005614 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5615 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005616 break;
5617 default:
5618 break;
5619 }
5620
Johannes Berg48ab9052009-07-10 18:42:31 +02005621 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005622 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005623 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005624 if (intbss == wdev->current_bss &&
5625 nla_put_u32(msg, NL80211_BSS_STATUS,
5626 NL80211_BSS_STATUS_ASSOCIATED))
5627 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005628 break;
5629 case NL80211_IFTYPE_ADHOC:
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_IBSS_JOINED))
5633 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005634 break;
5635 default:
5636 break;
5637 }
5638
Johannes Berg2a519312009-02-10 21:25:55 +01005639 nla_nest_end(msg, bss);
5640
5641 return genlmsg_end(msg, hdr);
5642
Johannes Berg8cef2c92013-02-05 16:54:31 +01005643 fail_unlock_rcu:
5644 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005645 nla_put_failure:
5646 genlmsg_cancel(msg, hdr);
5647 return -EMSGSIZE;
5648}
5649
Johannes Berg97990a02013-04-19 01:02:55 +02005650static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005651{
Johannes Berg48ab9052009-07-10 18:42:31 +02005652 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005653 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005654 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005655 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005656 int err;
5657
Johannes Berg97990a02013-04-19 01:02:55 +02005658 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005659 if (err)
5660 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005661
Johannes Berg48ab9052009-07-10 18:42:31 +02005662 wdev_lock(wdev);
5663 spin_lock_bh(&rdev->bss_lock);
5664 cfg80211_bss_expire(rdev);
5665
Johannes Berg9720bb32011-06-21 09:45:33 +02005666 cb->seq = rdev->bss_generation;
5667
Johannes Berg48ab9052009-07-10 18:42:31 +02005668 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005669 if (++idx <= start)
5670 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005671 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005672 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005673 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005674 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005675 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005676 }
5677 }
5678
Johannes Berg48ab9052009-07-10 18:42:31 +02005679 spin_unlock_bh(&rdev->bss_lock);
5680 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005681
Johannes Berg97990a02013-04-19 01:02:55 +02005682 cb->args[2] = idx;
5683 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005684
Johannes Berg67748892010-10-04 21:14:06 +02005685 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005686}
5687
Eric W. Biederman15e47302012-09-07 20:12:54 +00005688static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005689 int flags, struct net_device *dev,
5690 struct survey_info *survey)
5691{
5692 void *hdr;
5693 struct nlattr *infoattr;
5694
Eric W. Biederman15e47302012-09-07 20:12:54 +00005695 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005696 NL80211_CMD_NEW_SURVEY_RESULTS);
5697 if (!hdr)
5698 return -ENOMEM;
5699
David S. Miller9360ffd2012-03-29 04:41:26 -04005700 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5701 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005702
5703 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5704 if (!infoattr)
5705 goto nla_put_failure;
5706
David S. Miller9360ffd2012-03-29 04:41:26 -04005707 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5708 survey->channel->center_freq))
5709 goto nla_put_failure;
5710
5711 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5712 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5713 goto nla_put_failure;
5714 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5715 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5716 goto nla_put_failure;
5717 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5718 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5719 survey->channel_time))
5720 goto nla_put_failure;
5721 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5722 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5723 survey->channel_time_busy))
5724 goto nla_put_failure;
5725 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5726 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5727 survey->channel_time_ext_busy))
5728 goto nla_put_failure;
5729 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5730 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5731 survey->channel_time_rx))
5732 goto nla_put_failure;
5733 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5734 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5735 survey->channel_time_tx))
5736 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005737
5738 nla_nest_end(msg, infoattr);
5739
5740 return genlmsg_end(msg, hdr);
5741
5742 nla_put_failure:
5743 genlmsg_cancel(msg, hdr);
5744 return -EMSGSIZE;
5745}
5746
5747static int nl80211_dump_survey(struct sk_buff *skb,
5748 struct netlink_callback *cb)
5749{
5750 struct survey_info survey;
5751 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005752 struct wireless_dev *wdev;
5753 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005754 int res;
5755
Johannes Berg97990a02013-04-19 01:02:55 +02005756 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005757 if (res)
5758 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005759
Johannes Berg97990a02013-04-19 01:02:55 +02005760 if (!wdev->netdev) {
5761 res = -EINVAL;
5762 goto out_err;
5763 }
5764
Holger Schurig61fa7132009-11-11 12:25:40 +01005765 if (!dev->ops->dump_survey) {
5766 res = -EOPNOTSUPP;
5767 goto out_err;
5768 }
5769
5770 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005771 struct ieee80211_channel *chan;
5772
Johannes Berg97990a02013-04-19 01:02:55 +02005773 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005774 if (res == -ENOENT)
5775 break;
5776 if (res)
5777 goto out_err;
5778
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005779 /* Survey without a channel doesn't make sense */
5780 if (!survey.channel) {
5781 res = -EINVAL;
5782 goto out;
5783 }
5784
5785 chan = ieee80211_get_channel(&dev->wiphy,
5786 survey.channel->center_freq);
5787 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5788 survey_idx++;
5789 continue;
5790 }
5791
Holger Schurig61fa7132009-11-11 12:25:40 +01005792 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005793 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005794 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005795 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005796 goto out;
5797 survey_idx++;
5798 }
5799
5800 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005801 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005802 res = skb->len;
5803 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005804 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005805 return res;
5806}
5807
Samuel Ortizb23aa672009-07-01 21:26:54 +02005808static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5809{
5810 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5811 NL80211_WPA_VERSION_2));
5812}
5813
Jouni Malinen636a5d32009-03-19 13:39:22 +02005814static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5815{
Johannes Berg4c476992010-10-04 21:36:35 +02005816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5817 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005818 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005819 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5820 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005821 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005822 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005823 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005824
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005825 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5826 return -EINVAL;
5827
5828 if (!info->attrs[NL80211_ATTR_MAC])
5829 return -EINVAL;
5830
Jouni Malinen17780922009-03-27 20:52:47 +02005831 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5832 return -EINVAL;
5833
Johannes Berg19957bb2009-07-02 17:20:43 +02005834 if (!info->attrs[NL80211_ATTR_SSID])
5835 return -EINVAL;
5836
5837 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5838 return -EINVAL;
5839
Johannes Bergfffd0932009-07-08 14:22:54 +02005840 err = nl80211_parse_key(info, &key);
5841 if (err)
5842 return err;
5843
5844 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005845 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5846 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005847 if (!key.p.key || !key.p.key_len)
5848 return -EINVAL;
5849 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5850 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5851 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5852 key.p.key_len != WLAN_KEY_LEN_WEP104))
5853 return -EINVAL;
5854 if (key.idx > 4)
5855 return -EINVAL;
5856 } else {
5857 key.p.key_len = 0;
5858 key.p.key = NULL;
5859 }
5860
Johannes Bergafea0b72010-08-10 09:46:42 +02005861 if (key.idx >= 0) {
5862 int i;
5863 bool ok = false;
5864 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5865 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5866 ok = true;
5867 break;
5868 }
5869 }
Johannes Berg4c476992010-10-04 21:36:35 +02005870 if (!ok)
5871 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005872 }
5873
Johannes Berg4c476992010-10-04 21:36:35 +02005874 if (!rdev->ops->auth)
5875 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005876
Johannes Berg074ac8d2010-09-16 14:58:22 +02005877 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005878 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5879 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005880
Johannes Berg19957bb2009-07-02 17:20:43 +02005881 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005882 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005883 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005884 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5885 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005886
Johannes Berg19957bb2009-07-02 17:20:43 +02005887 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5888 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5889
5890 if (info->attrs[NL80211_ATTR_IE]) {
5891 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5892 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5893 }
5894
5895 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005896 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005897 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005898
Jouni Malinene39e5b52012-09-30 19:29:39 +03005899 if (auth_type == NL80211_AUTHTYPE_SAE &&
5900 !info->attrs[NL80211_ATTR_SAE_DATA])
5901 return -EINVAL;
5902
5903 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5904 if (auth_type != NL80211_AUTHTYPE_SAE)
5905 return -EINVAL;
5906 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5907 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5908 /* need to include at least Auth Transaction and Status Code */
5909 if (sae_data_len < 4)
5910 return -EINVAL;
5911 }
5912
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005913 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5914
Johannes Berg95de8172012-01-20 13:55:25 +01005915 /*
5916 * Since we no longer track auth state, ignore
5917 * requests to only change local state.
5918 */
5919 if (local_state_change)
5920 return 0;
5921
Johannes Berg91bf9b22013-05-15 17:44:01 +02005922 wdev_lock(dev->ieee80211_ptr);
5923 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5924 ssid, ssid_len, ie, ie_len,
5925 key.p.key, key.p.key_len, key.idx,
5926 sae_data, sae_data_len);
5927 wdev_unlock(dev->ieee80211_ptr);
5928 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005929}
5930
Johannes Bergc0692b82010-08-27 14:26:53 +03005931static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5932 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005933 struct cfg80211_crypto_settings *settings,
5934 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005935{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005936 memset(settings, 0, sizeof(*settings));
5937
Samuel Ortizb23aa672009-07-01 21:26:54 +02005938 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5939
Johannes Bergc0692b82010-08-27 14:26:53 +03005940 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5941 u16 proto;
5942 proto = nla_get_u16(
5943 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5944 settings->control_port_ethertype = cpu_to_be16(proto);
5945 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5946 proto != ETH_P_PAE)
5947 return -EINVAL;
5948 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5949 settings->control_port_no_encrypt = true;
5950 } else
5951 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5952
Samuel Ortizb23aa672009-07-01 21:26:54 +02005953 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5954 void *data;
5955 int len, i;
5956
5957 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5958 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5959 settings->n_ciphers_pairwise = len / sizeof(u32);
5960
5961 if (len % sizeof(u32))
5962 return -EINVAL;
5963
Johannes Berg3dc27d22009-07-02 21:36:37 +02005964 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005965 return -EINVAL;
5966
5967 memcpy(settings->ciphers_pairwise, data, len);
5968
5969 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005970 if (!cfg80211_supported_cipher_suite(
5971 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005972 settings->ciphers_pairwise[i]))
5973 return -EINVAL;
5974 }
5975
5976 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5977 settings->cipher_group =
5978 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005979 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5980 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005981 return -EINVAL;
5982 }
5983
5984 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5985 settings->wpa_versions =
5986 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5987 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5988 return -EINVAL;
5989 }
5990
5991 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5992 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005993 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005994
5995 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5996 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5997 settings->n_akm_suites = len / sizeof(u32);
5998
5999 if (len % sizeof(u32))
6000 return -EINVAL;
6001
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006002 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6003 return -EINVAL;
6004
Samuel Ortizb23aa672009-07-01 21:26:54 +02006005 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006006 }
6007
6008 return 0;
6009}
6010
Jouni Malinen636a5d32009-03-19 13:39:22 +02006011static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6012{
Johannes Berg4c476992010-10-04 21:36:35 +02006013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6014 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006015 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006016 struct cfg80211_assoc_request req = {};
6017 const u8 *bssid, *ssid;
6018 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006019
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006020 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6021 return -EINVAL;
6022
6023 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006024 !info->attrs[NL80211_ATTR_SSID] ||
6025 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006026 return -EINVAL;
6027
Johannes Berg4c476992010-10-04 21:36:35 +02006028 if (!rdev->ops->assoc)
6029 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006030
Johannes Berg074ac8d2010-09-16 14:58:22 +02006031 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006032 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6033 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006034
Johannes Berg19957bb2009-07-02 17:20:43 +02006035 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006036
Johannes Berg19957bb2009-07-02 17:20:43 +02006037 chan = ieee80211_get_channel(&rdev->wiphy,
6038 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006039 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6040 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006041
Johannes Berg19957bb2009-07-02 17:20:43 +02006042 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6043 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006044
6045 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006046 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6047 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006048 }
6049
Jouni Malinendc6382c2009-05-06 22:09:37 +03006050 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006051 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006052 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006053 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006054 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006055 else if (mfp != NL80211_MFP_NO)
6056 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006057 }
6058
Johannes Berg3e5d7642009-07-07 14:37:26 +02006059 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006060 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006061
Ben Greear7e7c8922011-11-18 11:31:59 -08006062 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006063 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006064
6065 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006066 memcpy(&req.ht_capa_mask,
6067 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6068 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006069
6070 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006071 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006072 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006073 memcpy(&req.ht_capa,
6074 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6075 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006076 }
6077
Johannes Bergee2aca32013-02-21 17:36:01 +01006078 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006079 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006080
6081 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006082 memcpy(&req.vht_capa_mask,
6083 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6084 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006085
6086 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006087 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006088 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006089 memcpy(&req.vht_capa,
6090 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6091 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006092 }
6093
Johannes Bergf62fab72013-02-21 20:09:09 +01006094 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006095 if (!err) {
6096 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006097 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6098 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006099 wdev_unlock(dev->ieee80211_ptr);
6100 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006101
Jouni Malinen636a5d32009-03-19 13:39:22 +02006102 return err;
6103}
6104
6105static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6106{
Johannes Berg4c476992010-10-04 21:36:35 +02006107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6108 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006109 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006110 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006111 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006112 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006113
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006114 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6115 return -EINVAL;
6116
6117 if (!info->attrs[NL80211_ATTR_MAC])
6118 return -EINVAL;
6119
6120 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6121 return -EINVAL;
6122
Johannes Berg4c476992010-10-04 21:36:35 +02006123 if (!rdev->ops->deauth)
6124 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006125
Johannes Berg074ac8d2010-09-16 14:58:22 +02006126 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006127 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6128 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006129
Johannes Berg19957bb2009-07-02 17:20:43 +02006130 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006131
Johannes Berg19957bb2009-07-02 17:20:43 +02006132 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6133 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006134 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006135 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006136 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006137
6138 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006139 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6140 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006141 }
6142
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006143 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6144
Johannes Berg91bf9b22013-05-15 17:44:01 +02006145 wdev_lock(dev->ieee80211_ptr);
6146 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6147 local_state_change);
6148 wdev_unlock(dev->ieee80211_ptr);
6149 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006150}
6151
6152static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6153{
Johannes Berg4c476992010-10-04 21:36:35 +02006154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6155 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006156 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006157 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006158 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006159 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006160
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006161 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6162 return -EINVAL;
6163
6164 if (!info->attrs[NL80211_ATTR_MAC])
6165 return -EINVAL;
6166
6167 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6168 return -EINVAL;
6169
Johannes Berg4c476992010-10-04 21:36:35 +02006170 if (!rdev->ops->disassoc)
6171 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006172
Johannes Berg074ac8d2010-09-16 14:58:22 +02006173 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006174 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6175 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006176
Johannes Berg19957bb2009-07-02 17:20:43 +02006177 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006178
Johannes Berg19957bb2009-07-02 17:20:43 +02006179 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6180 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006181 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006182 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006183 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006184
6185 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006186 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6187 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006188 }
6189
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006190 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6191
Johannes Berg91bf9b22013-05-15 17:44:01 +02006192 wdev_lock(dev->ieee80211_ptr);
6193 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6194 local_state_change);
6195 wdev_unlock(dev->ieee80211_ptr);
6196 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006197}
6198
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006199static bool
6200nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6201 int mcast_rate[IEEE80211_NUM_BANDS],
6202 int rateval)
6203{
6204 struct wiphy *wiphy = &rdev->wiphy;
6205 bool found = false;
6206 int band, i;
6207
6208 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6209 struct ieee80211_supported_band *sband;
6210
6211 sband = wiphy->bands[band];
6212 if (!sband)
6213 continue;
6214
6215 for (i = 0; i < sband->n_bitrates; i++) {
6216 if (sband->bitrates[i].bitrate == rateval) {
6217 mcast_rate[band] = i + 1;
6218 found = true;
6219 break;
6220 }
6221 }
6222 }
6223
6224 return found;
6225}
6226
Johannes Berg04a773a2009-04-19 21:24:32 +02006227static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6228{
Johannes Berg4c476992010-10-04 21:36:35 +02006229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6230 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006231 struct cfg80211_ibss_params ibss;
6232 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006233 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006234 int err;
6235
Johannes Berg8e30bc52009-04-22 17:45:38 +02006236 memset(&ibss, 0, sizeof(ibss));
6237
Johannes Berg04a773a2009-04-19 21:24:32 +02006238 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6239 return -EINVAL;
6240
Johannes Berg683b6d32012-11-08 21:25:48 +01006241 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006242 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6243 return -EINVAL;
6244
Johannes Berg8e30bc52009-04-22 17:45:38 +02006245 ibss.beacon_interval = 100;
6246
6247 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6248 ibss.beacon_interval =
6249 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6250 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6251 return -EINVAL;
6252 }
6253
Johannes Berg4c476992010-10-04 21:36:35 +02006254 if (!rdev->ops->join_ibss)
6255 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006256
Johannes Berg4c476992010-10-04 21:36:35 +02006257 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6258 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006259
Johannes Berg79c97e92009-07-07 03:56:12 +02006260 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006261
Johannes Berg39193492011-09-16 13:45:25 +02006262 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006263 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006264
6265 if (!is_valid_ether_addr(ibss.bssid))
6266 return -EINVAL;
6267 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006268 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6269 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6270
6271 if (info->attrs[NL80211_ATTR_IE]) {
6272 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6273 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6274 }
6275
Johannes Berg683b6d32012-11-08 21:25:48 +01006276 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6277 if (err)
6278 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006279
Johannes Berg683b6d32012-11-08 21:25:48 +01006280 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006281 return -EINVAL;
6282
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006283 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6284 return -EINVAL;
6285 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6286 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006287 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006288
Johannes Berg04a773a2009-04-19 21:24:32 +02006289 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006290 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006291
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006292 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6293 u8 *rates =
6294 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6295 int n_rates =
6296 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6297 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006298 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006299
Johannes Berg34850ab2011-07-18 18:08:35 +02006300 err = ieee80211_get_ratemask(sband, rates, n_rates,
6301 &ibss.basic_rates);
6302 if (err)
6303 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006304 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006305
6306 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6307 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6308 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6309 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006310
Johannes Berg4c476992010-10-04 21:36:35 +02006311 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306312 bool no_ht = false;
6313
Johannes Berg4c476992010-10-04 21:36:35 +02006314 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306315 info->attrs[NL80211_ATTR_KEYS],
6316 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006317 if (IS_ERR(connkeys))
6318 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306319
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006320 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6321 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306322 kfree(connkeys);
6323 return -EINVAL;
6324 }
Johannes Berg4c476992010-10-04 21:36:35 +02006325 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006326
Antonio Quartulli267335d2012-01-31 20:25:47 +01006327 ibss.control_port =
6328 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6329
Johannes Berg4c476992010-10-04 21:36:35 +02006330 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006331 if (err)
6332 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006333 return err;
6334}
6335
6336static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6337{
Johannes Berg4c476992010-10-04 21:36:35 +02006338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6339 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006340
Johannes Berg4c476992010-10-04 21:36:35 +02006341 if (!rdev->ops->leave_ibss)
6342 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006343
Johannes Berg4c476992010-10-04 21:36:35 +02006344 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6345 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006346
Johannes Berg4c476992010-10-04 21:36:35 +02006347 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006348}
6349
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006350static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6351{
6352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6353 struct net_device *dev = info->user_ptr[1];
6354 int mcast_rate[IEEE80211_NUM_BANDS];
6355 u32 nla_rate;
6356 int err;
6357
6358 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6359 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6360 return -EOPNOTSUPP;
6361
6362 if (!rdev->ops->set_mcast_rate)
6363 return -EOPNOTSUPP;
6364
6365 memset(mcast_rate, 0, sizeof(mcast_rate));
6366
6367 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6368 return -EINVAL;
6369
6370 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6371 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6372 return -EINVAL;
6373
6374 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6375
6376 return err;
6377}
6378
6379
Johannes Bergaff89a92009-07-01 21:26:51 +02006380#ifdef CONFIG_NL80211_TESTMODE
6381static struct genl_multicast_group nl80211_testmode_mcgrp = {
6382 .name = "testmode",
6383};
6384
6385static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6386{
Johannes Berg4c476992010-10-04 21:36:35 +02006387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006388 int err;
6389
6390 if (!info->attrs[NL80211_ATTR_TESTDATA])
6391 return -EINVAL;
6392
Johannes Bergaff89a92009-07-01 21:26:51 +02006393 err = -EOPNOTSUPP;
6394 if (rdev->ops->testmode_cmd) {
6395 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006396 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006397 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6398 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6399 rdev->testmode_info = NULL;
6400 }
6401
Johannes Bergaff89a92009-07-01 21:26:51 +02006402 return err;
6403}
6404
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006405static int nl80211_testmode_dump(struct sk_buff *skb,
6406 struct netlink_callback *cb)
6407{
Johannes Berg00918d32011-12-13 17:22:05 +01006408 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006409 int err;
6410 long phy_idx;
6411 void *data = NULL;
6412 int data_len = 0;
6413
Johannes Berg5fe231e2013-05-08 21:45:15 +02006414 rtnl_lock();
6415
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006416 if (cb->args[0]) {
6417 /*
6418 * 0 is a valid index, but not valid for args[0],
6419 * so we need to offset by 1.
6420 */
6421 phy_idx = cb->args[0] - 1;
6422 } else {
6423 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6424 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6425 nl80211_policy);
6426 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006427 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006428
Johannes Berg2bd7e352012-06-15 14:23:16 +02006429 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6430 nl80211_fam.attrbuf);
6431 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006432 err = PTR_ERR(rdev);
6433 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006434 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006435 phy_idx = rdev->wiphy_idx;
6436 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006437
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006438 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6439 cb->args[1] =
6440 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6441 }
6442
6443 if (cb->args[1]) {
6444 data = nla_data((void *)cb->args[1]);
6445 data_len = nla_len((void *)cb->args[1]);
6446 }
6447
Johannes Berg00918d32011-12-13 17:22:05 +01006448 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6449 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006450 err = -ENOENT;
6451 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006452 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006453
Johannes Berg00918d32011-12-13 17:22:05 +01006454 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006455 err = -EOPNOTSUPP;
6456 goto out_err;
6457 }
6458
6459 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006460 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006461 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6462 NL80211_CMD_TESTMODE);
6463 struct nlattr *tmdata;
6464
David S. Miller9360ffd2012-03-29 04:41:26 -04006465 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006466 genlmsg_cancel(skb, hdr);
6467 break;
6468 }
6469
6470 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6471 if (!tmdata) {
6472 genlmsg_cancel(skb, hdr);
6473 break;
6474 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006475 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006476 nla_nest_end(skb, tmdata);
6477
6478 if (err == -ENOBUFS || err == -ENOENT) {
6479 genlmsg_cancel(skb, hdr);
6480 break;
6481 } else if (err) {
6482 genlmsg_cancel(skb, hdr);
6483 goto out_err;
6484 }
6485
6486 genlmsg_end(skb, hdr);
6487 }
6488
6489 err = skb->len;
6490 /* see above */
6491 cb->args[0] = phy_idx + 1;
6492 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006493 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006494 return err;
6495}
6496
Johannes Bergaff89a92009-07-01 21:26:51 +02006497static struct sk_buff *
6498__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006499 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006500{
6501 struct sk_buff *skb;
6502 void *hdr;
6503 struct nlattr *data;
6504
6505 skb = nlmsg_new(approxlen + 100, gfp);
6506 if (!skb)
6507 return NULL;
6508
Eric W. Biederman15e47302012-09-07 20:12:54 +00006509 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006510 if (!hdr) {
6511 kfree_skb(skb);
6512 return NULL;
6513 }
6514
David S. Miller9360ffd2012-03-29 04:41:26 -04006515 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6516 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006517 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6518
6519 ((void **)skb->cb)[0] = rdev;
6520 ((void **)skb->cb)[1] = hdr;
6521 ((void **)skb->cb)[2] = data;
6522
6523 return skb;
6524
6525 nla_put_failure:
6526 kfree_skb(skb);
6527 return NULL;
6528}
6529
6530struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6531 int approxlen)
6532{
6533 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6534
6535 if (WARN_ON(!rdev->testmode_info))
6536 return NULL;
6537
6538 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006539 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006540 rdev->testmode_info->snd_seq,
6541 GFP_KERNEL);
6542}
6543EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6544
6545int cfg80211_testmode_reply(struct sk_buff *skb)
6546{
6547 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6548 void *hdr = ((void **)skb->cb)[1];
6549 struct nlattr *data = ((void **)skb->cb)[2];
6550
6551 if (WARN_ON(!rdev->testmode_info)) {
6552 kfree_skb(skb);
6553 return -EINVAL;
6554 }
6555
6556 nla_nest_end(skb, data);
6557 genlmsg_end(skb, hdr);
6558 return genlmsg_reply(skb, rdev->testmode_info);
6559}
6560EXPORT_SYMBOL(cfg80211_testmode_reply);
6561
6562struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6563 int approxlen, gfp_t gfp)
6564{
6565 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6566
6567 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6568}
6569EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6570
6571void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6572{
6573 void *hdr = ((void **)skb->cb)[1];
6574 struct nlattr *data = ((void **)skb->cb)[2];
6575
6576 nla_nest_end(skb, data);
6577 genlmsg_end(skb, hdr);
6578 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6579}
6580EXPORT_SYMBOL(cfg80211_testmode_event);
6581#endif
6582
Samuel Ortizb23aa672009-07-01 21:26:54 +02006583static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6584{
Johannes Berg4c476992010-10-04 21:36:35 +02006585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6586 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006587 struct cfg80211_connect_params connect;
6588 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006589 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006590 int err;
6591
6592 memset(&connect, 0, sizeof(connect));
6593
6594 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6595 return -EINVAL;
6596
6597 if (!info->attrs[NL80211_ATTR_SSID] ||
6598 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6599 return -EINVAL;
6600
6601 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6602 connect.auth_type =
6603 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006604 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6605 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006606 return -EINVAL;
6607 } else
6608 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6609
6610 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6611
Johannes Bergc0692b82010-08-27 14:26:53 +03006612 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006613 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006614 if (err)
6615 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006616
Johannes Berg074ac8d2010-09-16 14:58:22 +02006617 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006618 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6619 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006620
Johannes Berg79c97e92009-07-07 03:56:12 +02006621 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006622
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306623 connect.bg_scan_period = -1;
6624 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6625 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6626 connect.bg_scan_period =
6627 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6628 }
6629
Samuel Ortizb23aa672009-07-01 21:26:54 +02006630 if (info->attrs[NL80211_ATTR_MAC])
6631 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6632 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6633 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6634
6635 if (info->attrs[NL80211_ATTR_IE]) {
6636 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6637 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6638 }
6639
Jouni Malinencee00a92013-01-15 17:15:57 +02006640 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6641 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6642 if (connect.mfp != NL80211_MFP_REQUIRED &&
6643 connect.mfp != NL80211_MFP_NO)
6644 return -EINVAL;
6645 } else {
6646 connect.mfp = NL80211_MFP_NO;
6647 }
6648
Samuel Ortizb23aa672009-07-01 21:26:54 +02006649 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6650 connect.channel =
6651 ieee80211_get_channel(wiphy,
6652 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6653 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006654 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6655 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006656 }
6657
Johannes Bergfffd0932009-07-08 14:22:54 +02006658 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6659 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306660 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006661 if (IS_ERR(connkeys))
6662 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006663 }
6664
Ben Greear7e7c8922011-11-18 11:31:59 -08006665 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6666 connect.flags |= ASSOC_REQ_DISABLE_HT;
6667
6668 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6669 memcpy(&connect.ht_capa_mask,
6670 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6671 sizeof(connect.ht_capa_mask));
6672
6673 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006674 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6675 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006676 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006677 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006678 memcpy(&connect.ht_capa,
6679 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6680 sizeof(connect.ht_capa));
6681 }
6682
Johannes Bergee2aca32013-02-21 17:36:01 +01006683 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6684 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6685
6686 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6687 memcpy(&connect.vht_capa_mask,
6688 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6689 sizeof(connect.vht_capa_mask));
6690
6691 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6692 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6693 kfree(connkeys);
6694 return -EINVAL;
6695 }
6696 memcpy(&connect.vht_capa,
6697 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6698 sizeof(connect.vht_capa));
6699 }
6700
Johannes Berg83739b02013-05-15 17:44:01 +02006701 wdev_lock(dev->ieee80211_ptr);
6702 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6703 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006704 if (err)
6705 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006706 return err;
6707}
6708
6709static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6710{
Johannes Berg4c476992010-10-04 21:36:35 +02006711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6712 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006713 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006714 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006715
6716 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6717 reason = WLAN_REASON_DEAUTH_LEAVING;
6718 else
6719 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6720
6721 if (reason == 0)
6722 return -EINVAL;
6723
Johannes Berg074ac8d2010-09-16 14:58:22 +02006724 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006725 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6726 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006727
Johannes Berg83739b02013-05-15 17:44:01 +02006728 wdev_lock(dev->ieee80211_ptr);
6729 ret = cfg80211_disconnect(rdev, dev, reason, true);
6730 wdev_unlock(dev->ieee80211_ptr);
6731 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006732}
6733
Johannes Berg463d0182009-07-14 00:33:35 +02006734static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6735{
Johannes Berg4c476992010-10-04 21:36:35 +02006736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006737 struct net *net;
6738 int err;
6739 u32 pid;
6740
6741 if (!info->attrs[NL80211_ATTR_PID])
6742 return -EINVAL;
6743
6744 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6745
Johannes Berg463d0182009-07-14 00:33:35 +02006746 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006747 if (IS_ERR(net))
6748 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006749
6750 err = 0;
6751
6752 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006753 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6754 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006755
Johannes Berg463d0182009-07-14 00:33:35 +02006756 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006757 return err;
6758}
6759
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006760static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6761{
Johannes Berg4c476992010-10-04 21:36:35 +02006762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006763 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6764 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006765 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006766 struct cfg80211_pmksa pmksa;
6767
6768 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6769
6770 if (!info->attrs[NL80211_ATTR_MAC])
6771 return -EINVAL;
6772
6773 if (!info->attrs[NL80211_ATTR_PMKID])
6774 return -EINVAL;
6775
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006776 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6777 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6778
Johannes Berg074ac8d2010-09-16 14:58:22 +02006779 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006780 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6781 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006782
6783 switch (info->genlhdr->cmd) {
6784 case NL80211_CMD_SET_PMKSA:
6785 rdev_ops = rdev->ops->set_pmksa;
6786 break;
6787 case NL80211_CMD_DEL_PMKSA:
6788 rdev_ops = rdev->ops->del_pmksa;
6789 break;
6790 default:
6791 WARN_ON(1);
6792 break;
6793 }
6794
Johannes Berg4c476992010-10-04 21:36:35 +02006795 if (!rdev_ops)
6796 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006797
Johannes Berg4c476992010-10-04 21:36:35 +02006798 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006799}
6800
6801static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6802{
Johannes Berg4c476992010-10-04 21:36:35 +02006803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6804 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006805
Johannes Berg074ac8d2010-09-16 14:58:22 +02006806 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006807 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6808 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006809
Johannes Berg4c476992010-10-04 21:36:35 +02006810 if (!rdev->ops->flush_pmksa)
6811 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006812
Hila Gonene35e4d22012-06-27 17:19:42 +03006813 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006814}
6815
Arik Nemtsov109086c2011-09-28 14:12:50 +03006816static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6817{
6818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6819 struct net_device *dev = info->user_ptr[1];
6820 u8 action_code, dialog_token;
6821 u16 status_code;
6822 u8 *peer;
6823
6824 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6825 !rdev->ops->tdls_mgmt)
6826 return -EOPNOTSUPP;
6827
6828 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6829 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6830 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6831 !info->attrs[NL80211_ATTR_IE] ||
6832 !info->attrs[NL80211_ATTR_MAC])
6833 return -EINVAL;
6834
6835 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6836 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6837 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6838 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6839
Hila Gonene35e4d22012-06-27 17:19:42 +03006840 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6841 dialog_token, status_code,
6842 nla_data(info->attrs[NL80211_ATTR_IE]),
6843 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006844}
6845
6846static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6847{
6848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6849 struct net_device *dev = info->user_ptr[1];
6850 enum nl80211_tdls_operation operation;
6851 u8 *peer;
6852
6853 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6854 !rdev->ops->tdls_oper)
6855 return -EOPNOTSUPP;
6856
6857 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6858 !info->attrs[NL80211_ATTR_MAC])
6859 return -EINVAL;
6860
6861 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6862 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6863
Hila Gonene35e4d22012-06-27 17:19:42 +03006864 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006865}
6866
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006867static int nl80211_remain_on_channel(struct sk_buff *skb,
6868 struct genl_info *info)
6869{
Johannes Berg4c476992010-10-04 21:36:35 +02006870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006871 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006872 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006873 struct sk_buff *msg;
6874 void *hdr;
6875 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006876 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006877 int err;
6878
6879 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6880 !info->attrs[NL80211_ATTR_DURATION])
6881 return -EINVAL;
6882
6883 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6884
Johannes Berg7c4ef712011-11-18 15:33:48 +01006885 if (!rdev->ops->remain_on_channel ||
6886 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006887 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006888
Johannes Bergebf348f2012-06-01 12:50:54 +02006889 /*
6890 * We should be on that channel for at least a minimum amount of
6891 * time (10ms) but no longer than the driver supports.
6892 */
6893 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6894 duration > rdev->wiphy.max_remain_on_channel_duration)
6895 return -EINVAL;
6896
Johannes Berg683b6d32012-11-08 21:25:48 +01006897 err = nl80211_parse_chandef(rdev, info, &chandef);
6898 if (err)
6899 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006900
6901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006902 if (!msg)
6903 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006904
Eric W. Biederman15e47302012-09-07 20:12:54 +00006905 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006906 NL80211_CMD_REMAIN_ON_CHANNEL);
6907
6908 if (IS_ERR(hdr)) {
6909 err = PTR_ERR(hdr);
6910 goto free_msg;
6911 }
6912
Johannes Berg683b6d32012-11-08 21:25:48 +01006913 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6914 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006915
6916 if (err)
6917 goto free_msg;
6918
David S. Miller9360ffd2012-03-29 04:41:26 -04006919 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6920 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006921
6922 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006923
6924 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006925
6926 nla_put_failure:
6927 err = -ENOBUFS;
6928 free_msg:
6929 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006930 return err;
6931}
6932
6933static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6934 struct genl_info *info)
6935{
Johannes Berg4c476992010-10-04 21:36:35 +02006936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006937 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006938 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006939
6940 if (!info->attrs[NL80211_ATTR_COOKIE])
6941 return -EINVAL;
6942
Johannes Berg4c476992010-10-04 21:36:35 +02006943 if (!rdev->ops->cancel_remain_on_channel)
6944 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006945
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006946 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6947
Hila Gonene35e4d22012-06-27 17:19:42 +03006948 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006949}
6950
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006951static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6952 u8 *rates, u8 rates_len)
6953{
6954 u8 i;
6955 u32 mask = 0;
6956
6957 for (i = 0; i < rates_len; i++) {
6958 int rate = (rates[i] & 0x7f) * 5;
6959 int ridx;
6960 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6961 struct ieee80211_rate *srate =
6962 &sband->bitrates[ridx];
6963 if (rate == srate->bitrate) {
6964 mask |= 1 << ridx;
6965 break;
6966 }
6967 }
6968 if (ridx == sband->n_bitrates)
6969 return 0; /* rate not found */
6970 }
6971
6972 return mask;
6973}
6974
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006975static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6976 u8 *rates, u8 rates_len,
6977 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6978{
6979 u8 i;
6980
6981 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6982
6983 for (i = 0; i < rates_len; i++) {
6984 int ridx, rbit;
6985
6986 ridx = rates[i] / 8;
6987 rbit = BIT(rates[i] % 8);
6988
6989 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006990 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006991 return false;
6992
6993 /* check availability */
6994 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6995 mcs[ridx] |= rbit;
6996 else
6997 return false;
6998 }
6999
7000 return true;
7001}
7002
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007003static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007004 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7005 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007006 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7007 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007008};
7009
7010static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7011 struct genl_info *info)
7012{
7013 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007015 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007016 int rem, i;
7017 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007018 struct nlattr *tx_rates;
7019 struct ieee80211_supported_band *sband;
7020
7021 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7022 return -EINVAL;
7023
Johannes Berg4c476992010-10-04 21:36:35 +02007024 if (!rdev->ops->set_bitrate_mask)
7025 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007026
7027 memset(&mask, 0, sizeof(mask));
7028 /* Default to all rates enabled */
7029 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7030 sband = rdev->wiphy.bands[i];
7031 mask.control[i].legacy =
7032 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007033 if (sband)
7034 memcpy(mask.control[i].mcs,
7035 sband->ht_cap.mcs.rx_mask,
7036 sizeof(mask.control[i].mcs));
7037 else
7038 memset(mask.control[i].mcs, 0,
7039 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007040 }
7041
7042 /*
7043 * The nested attribute uses enum nl80211_band as the index. This maps
7044 * directly to the enum ieee80211_band values used in cfg80211.
7045 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007046 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007047 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7048 {
7049 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007050 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7051 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007052 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007053 if (sband == NULL)
7054 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007055 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7056 nla_len(tx_rates), nl80211_txattr_policy);
7057 if (tb[NL80211_TXRATE_LEGACY]) {
7058 mask.control[band].legacy = rateset_to_mask(
7059 sband,
7060 nla_data(tb[NL80211_TXRATE_LEGACY]),
7061 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307062 if ((mask.control[band].legacy == 0) &&
7063 nla_len(tb[NL80211_TXRATE_LEGACY]))
7064 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007065 }
7066 if (tb[NL80211_TXRATE_MCS]) {
7067 if (!ht_rateset_to_mask(
7068 sband,
7069 nla_data(tb[NL80211_TXRATE_MCS]),
7070 nla_len(tb[NL80211_TXRATE_MCS]),
7071 mask.control[band].mcs))
7072 return -EINVAL;
7073 }
7074
7075 if (mask.control[band].legacy == 0) {
7076 /* don't allow empty legacy rates if HT
7077 * is not even supported. */
7078 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7079 return -EINVAL;
7080
7081 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7082 if (mask.control[band].mcs[i])
7083 break;
7084
7085 /* legacy and mcs rates may not be both empty */
7086 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007087 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007088 }
7089 }
7090
Hila Gonene35e4d22012-06-27 17:19:42 +03007091 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007092}
7093
Johannes Berg2e161f72010-08-12 15:38:38 +02007094static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007095{
Johannes Berg4c476992010-10-04 21:36:35 +02007096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007097 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007098 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007099
7100 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7101 return -EINVAL;
7102
Johannes Berg2e161f72010-08-12 15:38:38 +02007103 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7104 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007105
Johannes Berg71bbc992012-06-15 15:30:18 +02007106 switch (wdev->iftype) {
7107 case NL80211_IFTYPE_STATION:
7108 case NL80211_IFTYPE_ADHOC:
7109 case NL80211_IFTYPE_P2P_CLIENT:
7110 case NL80211_IFTYPE_AP:
7111 case NL80211_IFTYPE_AP_VLAN:
7112 case NL80211_IFTYPE_MESH_POINT:
7113 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007114 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007115 break;
7116 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007117 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007118 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007119
7120 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007121 if (!rdev->ops->mgmt_tx)
7122 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007123
Eric W. Biederman15e47302012-09-07 20:12:54 +00007124 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007125 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7126 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007127}
7128
Johannes Berg2e161f72010-08-12 15:38:38 +02007129static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007130{
Johannes Berg4c476992010-10-04 21:36:35 +02007131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007132 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007133 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007134 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007135 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007136 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007137 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007138 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007139 bool offchan, no_cck, dont_wait_for_ack;
7140
7141 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007142
Johannes Berg683b6d32012-11-08 21:25:48 +01007143 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007144 return -EINVAL;
7145
Johannes Berg4c476992010-10-04 21:36:35 +02007146 if (!rdev->ops->mgmt_tx)
7147 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007148
Johannes Berg71bbc992012-06-15 15:30:18 +02007149 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007150 case NL80211_IFTYPE_P2P_DEVICE:
7151 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7152 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007153 case NL80211_IFTYPE_STATION:
7154 case NL80211_IFTYPE_ADHOC:
7155 case NL80211_IFTYPE_P2P_CLIENT:
7156 case NL80211_IFTYPE_AP:
7157 case NL80211_IFTYPE_AP_VLAN:
7158 case NL80211_IFTYPE_MESH_POINT:
7159 case NL80211_IFTYPE_P2P_GO:
7160 break;
7161 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007162 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007163 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007164
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007165 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007166 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007167 return -EINVAL;
7168 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007169
7170 /*
7171 * We should wait on the channel for at least a minimum amount
7172 * of time (10ms) but no longer than the driver supports.
7173 */
7174 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7175 wait > rdev->wiphy.max_remain_on_channel_duration)
7176 return -EINVAL;
7177
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007178 }
7179
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007180 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7181
Johannes Berg7c4ef712011-11-18 15:33:48 +01007182 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7183 return -EINVAL;
7184
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307185 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7186
Antonio Quartulliea141b752013-06-11 14:20:03 +02007187 /* get the channel if any has been specified, otherwise pass NULL to
7188 * the driver. The latter will use the current one
7189 */
7190 chandef.chan = NULL;
7191 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7192 err = nl80211_parse_chandef(rdev, info, &chandef);
7193 if (err)
7194 return err;
7195 }
7196
7197 if (!chandef.chan && offchan)
7198 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007199
Johannes Berge247bd902011-11-04 11:18:21 +01007200 if (!dont_wait_for_ack) {
7201 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7202 if (!msg)
7203 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007204
Eric W. Biederman15e47302012-09-07 20:12:54 +00007205 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007206 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007207
Johannes Berge247bd902011-11-04 11:18:21 +01007208 if (IS_ERR(hdr)) {
7209 err = PTR_ERR(hdr);
7210 goto free_msg;
7211 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007212 }
Johannes Berge247bd902011-11-04 11:18:21 +01007213
Johannes Berg683b6d32012-11-08 21:25:48 +01007214 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007215 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7216 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007217 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007218 if (err)
7219 goto free_msg;
7220
Johannes Berge247bd902011-11-04 11:18:21 +01007221 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007222 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7223 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007224
Johannes Berge247bd902011-11-04 11:18:21 +01007225 genlmsg_end(msg, hdr);
7226 return genlmsg_reply(msg, info);
7227 }
7228
7229 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007230
7231 nla_put_failure:
7232 err = -ENOBUFS;
7233 free_msg:
7234 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007235 return err;
7236}
7237
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007238static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7239{
7240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007241 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007242 u64 cookie;
7243
7244 if (!info->attrs[NL80211_ATTR_COOKIE])
7245 return -EINVAL;
7246
7247 if (!rdev->ops->mgmt_tx_cancel_wait)
7248 return -EOPNOTSUPP;
7249
Johannes Berg71bbc992012-06-15 15:30:18 +02007250 switch (wdev->iftype) {
7251 case NL80211_IFTYPE_STATION:
7252 case NL80211_IFTYPE_ADHOC:
7253 case NL80211_IFTYPE_P2P_CLIENT:
7254 case NL80211_IFTYPE_AP:
7255 case NL80211_IFTYPE_AP_VLAN:
7256 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007257 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007258 break;
7259 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007260 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007261 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007262
7263 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7264
Hila Gonene35e4d22012-06-27 17:19:42 +03007265 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007266}
7267
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7269{
Johannes Berg4c476992010-10-04 21:36:35 +02007270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007271 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007272 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007273 u8 ps_state;
7274 bool state;
7275 int err;
7276
Johannes Berg4c476992010-10-04 21:36:35 +02007277 if (!info->attrs[NL80211_ATTR_PS_STATE])
7278 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007279
7280 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7281
Johannes Berg4c476992010-10-04 21:36:35 +02007282 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7283 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007284
7285 wdev = dev->ieee80211_ptr;
7286
Johannes Berg4c476992010-10-04 21:36:35 +02007287 if (!rdev->ops->set_power_mgmt)
7288 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007289
7290 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7291
7292 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007293 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007294
Hila Gonene35e4d22012-06-27 17:19:42 +03007295 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007296 if (!err)
7297 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007298 return err;
7299}
7300
7301static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7302{
Johannes Berg4c476992010-10-04 21:36:35 +02007303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007304 enum nl80211_ps_state ps_state;
7305 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007306 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007307 struct sk_buff *msg;
7308 void *hdr;
7309 int err;
7310
Kalle Valoffb9eb32010-02-17 17:58:10 +02007311 wdev = dev->ieee80211_ptr;
7312
Johannes Berg4c476992010-10-04 21:36:35 +02007313 if (!rdev->ops->set_power_mgmt)
7314 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007315
7316 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007317 if (!msg)
7318 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007319
Eric W. Biederman15e47302012-09-07 20:12:54 +00007320 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007321 NL80211_CMD_GET_POWER_SAVE);
7322 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007323 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007324 goto free_msg;
7325 }
7326
7327 if (wdev->ps)
7328 ps_state = NL80211_PS_ENABLED;
7329 else
7330 ps_state = NL80211_PS_DISABLED;
7331
David S. Miller9360ffd2012-03-29 04:41:26 -04007332 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7333 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007334
7335 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007336 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007337
Johannes Berg4c476992010-10-04 21:36:35 +02007338 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007339 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007340 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007341 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007342 return err;
7343}
7344
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007345static struct nla_policy
7346nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7347 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7348 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7349 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007350 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7351 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7352 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007353};
7354
Thomas Pedersen84f10702012-07-12 16:17:33 -07007355static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007356 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007357{
7358 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7359 struct wireless_dev *wdev;
7360 struct net_device *dev = info->user_ptr[1];
7361
Johannes Bergd9d8b012012-11-26 12:51:52 +01007362 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007363 return -EINVAL;
7364
7365 wdev = dev->ieee80211_ptr;
7366
7367 if (!rdev->ops->set_cqm_txe_config)
7368 return -EOPNOTSUPP;
7369
7370 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7371 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7372 return -EOPNOTSUPP;
7373
Hila Gonene35e4d22012-06-27 17:19:42 +03007374 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007375}
7376
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007377static int nl80211_set_cqm_rssi(struct genl_info *info,
7378 s32 threshold, u32 hysteresis)
7379{
Johannes Berg4c476992010-10-04 21:36:35 +02007380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007381 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007382 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007383
7384 if (threshold > 0)
7385 return -EINVAL;
7386
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007387 wdev = dev->ieee80211_ptr;
7388
Johannes Berg4c476992010-10-04 21:36:35 +02007389 if (!rdev->ops->set_cqm_rssi_config)
7390 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007391
Johannes Berg074ac8d2010-09-16 14:58:22 +02007392 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007393 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7394 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007395
Hila Gonene35e4d22012-06-27 17:19:42 +03007396 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007397}
7398
7399static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7400{
7401 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7402 struct nlattr *cqm;
7403 int err;
7404
7405 cqm = info->attrs[NL80211_ATTR_CQM];
7406 if (!cqm) {
7407 err = -EINVAL;
7408 goto out;
7409 }
7410
7411 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7412 nl80211_attr_cqm_policy);
7413 if (err)
7414 goto out;
7415
7416 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7417 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7418 s32 threshold;
7419 u32 hysteresis;
7420 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7421 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7422 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007423 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7424 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7425 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7426 u32 rate, pkts, intvl;
7427 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7428 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7429 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7430 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007431 } else
7432 err = -EINVAL;
7433
7434out:
7435 return err;
7436}
7437
Johannes Berg29cbe682010-12-03 09:20:44 +01007438static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7439{
7440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7441 struct net_device *dev = info->user_ptr[1];
7442 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007443 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007444 int err;
7445
7446 /* start with default */
7447 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007448 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007449
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007450 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007451 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007452 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007453 if (err)
7454 return err;
7455 }
7456
7457 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7458 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7459 return -EINVAL;
7460
Javier Cardonac80d5452010-12-16 17:37:49 -08007461 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7462 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7463
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007464 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7465 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7466 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7467 return -EINVAL;
7468
Marco Porsch9bdbf042013-01-07 16:04:51 +01007469 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7470 setup.beacon_interval =
7471 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7472 if (setup.beacon_interval < 10 ||
7473 setup.beacon_interval > 10000)
7474 return -EINVAL;
7475 }
7476
7477 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7478 setup.dtim_period =
7479 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7480 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7481 return -EINVAL;
7482 }
7483
Javier Cardonac80d5452010-12-16 17:37:49 -08007484 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7485 /* parse additional setup parameters if given */
7486 err = nl80211_parse_mesh_setup(info, &setup);
7487 if (err)
7488 return err;
7489 }
7490
Thomas Pedersend37bb182013-03-04 13:06:13 -08007491 if (setup.user_mpm)
7492 cfg.auto_open_plinks = false;
7493
Johannes Bergcc1d2802012-05-16 23:50:20 +02007494 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007495 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7496 if (err)
7497 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007498 } else {
7499 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007500 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007501 }
7502
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007503 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7504 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7505 int n_rates =
7506 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7507 struct ieee80211_supported_band *sband;
7508
7509 if (!setup.chandef.chan)
7510 return -EINVAL;
7511
7512 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7513
7514 err = ieee80211_get_ratemask(sband, rates, n_rates,
7515 &setup.basic_rates);
7516 if (err)
7517 return err;
7518 }
7519
Javier Cardonac80d5452010-12-16 17:37:49 -08007520 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007521}
7522
7523static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7524{
7525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7526 struct net_device *dev = info->user_ptr[1];
7527
7528 return cfg80211_leave_mesh(rdev, dev);
7529}
7530
Johannes Bergdfb89c52012-06-27 09:23:48 +02007531#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007532static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7533 struct cfg80211_registered_device *rdev)
7534{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007535 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007536 struct nlattr *nl_pats, *nl_pat;
7537 int i, pat_len;
7538
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007539 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007540 return 0;
7541
7542 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7543 if (!nl_pats)
7544 return -ENOBUFS;
7545
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007546 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007547 nl_pat = nla_nest_start(msg, i + 1);
7548 if (!nl_pat)
7549 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007550 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007551 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7552 DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007553 wowlan->patterns[i].mask) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007554 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007555 pat_len, wowlan->patterns[i].pattern) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007556 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007557 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007558 return -ENOBUFS;
7559 nla_nest_end(msg, nl_pat);
7560 }
7561 nla_nest_end(msg, nl_pats);
7562
7563 return 0;
7564}
7565
Johannes Berg2a0e0472013-01-23 22:57:40 +01007566static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7567 struct cfg80211_wowlan_tcp *tcp)
7568{
7569 struct nlattr *nl_tcp;
7570
7571 if (!tcp)
7572 return 0;
7573
7574 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7575 if (!nl_tcp)
7576 return -ENOBUFS;
7577
7578 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7579 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7580 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7581 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7582 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7583 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7584 tcp->payload_len, tcp->payload) ||
7585 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7586 tcp->data_interval) ||
7587 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7588 tcp->wake_len, tcp->wake_data) ||
7589 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7590 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7591 return -ENOBUFS;
7592
7593 if (tcp->payload_seq.len &&
7594 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7595 sizeof(tcp->payload_seq), &tcp->payload_seq))
7596 return -ENOBUFS;
7597
7598 if (tcp->payload_tok.len &&
7599 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7600 sizeof(tcp->payload_tok) + tcp->tokens_size,
7601 &tcp->payload_tok))
7602 return -ENOBUFS;
7603
Johannes Berge248ad32013-05-16 10:24:28 +02007604 nla_nest_end(msg, nl_tcp);
7605
Johannes Berg2a0e0472013-01-23 22:57:40 +01007606 return 0;
7607}
7608
Johannes Bergff1b6e62011-05-04 15:37:28 +02007609static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7610{
7611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7612 struct sk_buff *msg;
7613 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007614 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007615
Johannes Berg964dc9e2013-06-03 17:25:34 +02007616 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007617 return -EOPNOTSUPP;
7618
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007619 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007620 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007621 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7622 rdev->wiphy.wowlan_config->tcp->payload_len +
7623 rdev->wiphy.wowlan_config->tcp->wake_len +
7624 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007625 }
7626
7627 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007628 if (!msg)
7629 return -ENOMEM;
7630
Eric W. Biederman15e47302012-09-07 20:12:54 +00007631 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007632 NL80211_CMD_GET_WOWLAN);
7633 if (!hdr)
7634 goto nla_put_failure;
7635
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007636 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007637 struct nlattr *nl_wowlan;
7638
7639 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7640 if (!nl_wowlan)
7641 goto nla_put_failure;
7642
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007643 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007644 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007645 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007646 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007647 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007648 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007649 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007650 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007651 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007652 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007653 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007654 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007655 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007656 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7657 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007658
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007659 if (nl80211_send_wowlan_patterns(msg, rdev))
7660 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007661
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007662 if (nl80211_send_wowlan_tcp(msg,
7663 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007664 goto nla_put_failure;
7665
Johannes Bergff1b6e62011-05-04 15:37:28 +02007666 nla_nest_end(msg, nl_wowlan);
7667 }
7668
7669 genlmsg_end(msg, hdr);
7670 return genlmsg_reply(msg, info);
7671
7672nla_put_failure:
7673 nlmsg_free(msg);
7674 return -ENOBUFS;
7675}
7676
Johannes Berg2a0e0472013-01-23 22:57:40 +01007677static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7678 struct nlattr *attr,
7679 struct cfg80211_wowlan *trig)
7680{
7681 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7682 struct cfg80211_wowlan_tcp *cfg;
7683 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7684 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7685 u32 size;
7686 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7687 int err, port;
7688
Johannes Berg964dc9e2013-06-03 17:25:34 +02007689 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007690 return -EINVAL;
7691
7692 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7693 nla_data(attr), nla_len(attr),
7694 nl80211_wowlan_tcp_policy);
7695 if (err)
7696 return err;
7697
7698 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7699 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7700 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7701 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7702 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7703 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7704 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7705 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7706 return -EINVAL;
7707
7708 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007709 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007710 return -EINVAL;
7711
7712 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007713 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007714 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007715 return -EINVAL;
7716
7717 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007718 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007719 return -EINVAL;
7720
7721 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7722 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7723 return -EINVAL;
7724
7725 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7726 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7727
7728 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7729 tokens_size = tokln - sizeof(*tok);
7730
7731 if (!tok->len || tokens_size % tok->len)
7732 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007733 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007734 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007735 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007736 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007737 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007738 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007739 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007740 return -EINVAL;
7741 if (tok->offset + tok->len > data_size)
7742 return -EINVAL;
7743 }
7744
7745 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7746 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007747 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007748 return -EINVAL;
7749 if (seq->len == 0 || seq->len > 4)
7750 return -EINVAL;
7751 if (seq->len + seq->offset > data_size)
7752 return -EINVAL;
7753 }
7754
7755 size = sizeof(*cfg);
7756 size += data_size;
7757 size += wake_size + wake_mask_size;
7758 size += tokens_size;
7759
7760 cfg = kzalloc(size, GFP_KERNEL);
7761 if (!cfg)
7762 return -ENOMEM;
7763 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7764 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7765 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7766 ETH_ALEN);
7767 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7768 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7769 else
7770 port = 0;
7771#ifdef CONFIG_INET
7772 /* allocate a socket and port for it and use it */
7773 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7774 IPPROTO_TCP, &cfg->sock, 1);
7775 if (err) {
7776 kfree(cfg);
7777 return err;
7778 }
7779 if (inet_csk_get_port(cfg->sock->sk, port)) {
7780 sock_release(cfg->sock);
7781 kfree(cfg);
7782 return -EADDRINUSE;
7783 }
7784 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7785#else
7786 if (!port) {
7787 kfree(cfg);
7788 return -EINVAL;
7789 }
7790 cfg->src_port = port;
7791#endif
7792
7793 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7794 cfg->payload_len = data_size;
7795 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7796 memcpy((void *)cfg->payload,
7797 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7798 data_size);
7799 if (seq)
7800 cfg->payload_seq = *seq;
7801 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7802 cfg->wake_len = wake_size;
7803 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7804 memcpy((void *)cfg->wake_data,
7805 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7806 wake_size);
7807 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7808 data_size + wake_size;
7809 memcpy((void *)cfg->wake_mask,
7810 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7811 wake_mask_size);
7812 if (tok) {
7813 cfg->tokens_size = tokens_size;
7814 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7815 }
7816
7817 trig->tcp = cfg;
7818
7819 return 0;
7820}
7821
Johannes Bergff1b6e62011-05-04 15:37:28 +02007822static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7823{
7824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7825 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007826 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007827 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007828 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007829 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007830 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007831
Johannes Berg964dc9e2013-06-03 17:25:34 +02007832 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007833 return -EOPNOTSUPP;
7834
Johannes Bergae33bd82012-07-12 16:25:02 +02007835 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7836 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007837 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007838 goto set_wakeup;
7839 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007840
7841 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7842 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7843 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7844 nl80211_wowlan_policy);
7845 if (err)
7846 return err;
7847
7848 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7849 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7850 return -EINVAL;
7851 new_triggers.any = true;
7852 }
7853
7854 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7855 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7856 return -EINVAL;
7857 new_triggers.disconnect = true;
7858 }
7859
7860 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7861 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7862 return -EINVAL;
7863 new_triggers.magic_pkt = true;
7864 }
7865
Johannes Berg77dbbb12011-07-13 10:48:55 +02007866 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7867 return -EINVAL;
7868
7869 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7870 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7871 return -EINVAL;
7872 new_triggers.gtk_rekey_failure = true;
7873 }
7874
7875 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7876 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7877 return -EINVAL;
7878 new_triggers.eap_identity_req = true;
7879 }
7880
7881 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7882 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7883 return -EINVAL;
7884 new_triggers.four_way_handshake = true;
7885 }
7886
7887 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7888 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7889 return -EINVAL;
7890 new_triggers.rfkill_release = true;
7891 }
7892
Johannes Bergff1b6e62011-05-04 15:37:28 +02007893 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7894 struct nlattr *pat;
7895 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007896 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007897 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7898
7899 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7900 rem)
7901 n_patterns++;
7902 if (n_patterns > wowlan->n_patterns)
7903 return -EINVAL;
7904
7905 new_triggers.patterns = kcalloc(n_patterns,
7906 sizeof(new_triggers.patterns[0]),
7907 GFP_KERNEL);
7908 if (!new_triggers.patterns)
7909 return -ENOMEM;
7910
7911 new_triggers.n_patterns = n_patterns;
7912 i = 0;
7913
7914 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7915 rem) {
7916 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7917 nla_data(pat), nla_len(pat), NULL);
7918 err = -EINVAL;
7919 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7920 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7921 goto error;
7922 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7923 mask_len = DIV_ROUND_UP(pat_len, 8);
7924 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7925 mask_len)
7926 goto error;
7927 if (pat_len > wowlan->pattern_max_len ||
7928 pat_len < wowlan->pattern_min_len)
7929 goto error;
7930
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007931 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7932 pkt_offset = 0;
7933 else
7934 pkt_offset = nla_get_u32(
7935 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7936 if (pkt_offset > wowlan->max_pkt_offset)
7937 goto error;
7938 new_triggers.patterns[i].pkt_offset = pkt_offset;
7939
Johannes Bergff1b6e62011-05-04 15:37:28 +02007940 new_triggers.patterns[i].mask =
7941 kmalloc(mask_len + pat_len, GFP_KERNEL);
7942 if (!new_triggers.patterns[i].mask) {
7943 err = -ENOMEM;
7944 goto error;
7945 }
7946 new_triggers.patterns[i].pattern =
7947 new_triggers.patterns[i].mask + mask_len;
7948 memcpy(new_triggers.patterns[i].mask,
7949 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7950 mask_len);
7951 new_triggers.patterns[i].pattern_len = pat_len;
7952 memcpy(new_triggers.patterns[i].pattern,
7953 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7954 pat_len);
7955 i++;
7956 }
7957 }
7958
Johannes Berg2a0e0472013-01-23 22:57:40 +01007959 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7960 err = nl80211_parse_wowlan_tcp(
7961 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7962 &new_triggers);
7963 if (err)
7964 goto error;
7965 }
7966
Johannes Bergae33bd82012-07-12 16:25:02 +02007967 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7968 if (!ntrig) {
7969 err = -ENOMEM;
7970 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007971 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007972 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007973 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007974
Johannes Bergae33bd82012-07-12 16:25:02 +02007975 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007976 if (rdev->ops->set_wakeup &&
7977 prev_enabled != !!rdev->wiphy.wowlan_config)
7978 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02007979
Johannes Bergff1b6e62011-05-04 15:37:28 +02007980 return 0;
7981 error:
7982 for (i = 0; i < new_triggers.n_patterns; i++)
7983 kfree(new_triggers.patterns[i].mask);
7984 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007985 if (new_triggers.tcp && new_triggers.tcp->sock)
7986 sock_release(new_triggers.tcp->sock);
7987 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007988 return err;
7989}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007990#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007991
Johannes Berge5497d72011-07-05 16:35:40 +02007992static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7993{
7994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7995 struct net_device *dev = info->user_ptr[1];
7996 struct wireless_dev *wdev = dev->ieee80211_ptr;
7997 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7998 struct cfg80211_gtk_rekey_data rekey_data;
7999 int err;
8000
8001 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8002 return -EINVAL;
8003
8004 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8005 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8006 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8007 nl80211_rekey_policy);
8008 if (err)
8009 return err;
8010
8011 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8012 return -ERANGE;
8013 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8014 return -ERANGE;
8015 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8016 return -ERANGE;
8017
8018 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8019 NL80211_KEK_LEN);
8020 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8021 NL80211_KCK_LEN);
8022 memcpy(rekey_data.replay_ctr,
8023 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8024 NL80211_REPLAY_CTR_LEN);
8025
8026 wdev_lock(wdev);
8027 if (!wdev->current_bss) {
8028 err = -ENOTCONN;
8029 goto out;
8030 }
8031
8032 if (!rdev->ops->set_rekey_data) {
8033 err = -EOPNOTSUPP;
8034 goto out;
8035 }
8036
Hila Gonene35e4d22012-06-27 17:19:42 +03008037 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008038 out:
8039 wdev_unlock(wdev);
8040 return err;
8041}
8042
Johannes Berg28946da2011-11-04 11:18:12 +01008043static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8044 struct genl_info *info)
8045{
8046 struct net_device *dev = info->user_ptr[1];
8047 struct wireless_dev *wdev = dev->ieee80211_ptr;
8048
8049 if (wdev->iftype != NL80211_IFTYPE_AP &&
8050 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8051 return -EINVAL;
8052
Eric W. Biederman15e47302012-09-07 20:12:54 +00008053 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008054 return -EBUSY;
8055
Eric W. Biederman15e47302012-09-07 20:12:54 +00008056 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008057 return 0;
8058}
8059
Johannes Berg7f6cf312011-11-04 11:18:15 +01008060static int nl80211_probe_client(struct sk_buff *skb,
8061 struct genl_info *info)
8062{
8063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8064 struct net_device *dev = info->user_ptr[1];
8065 struct wireless_dev *wdev = dev->ieee80211_ptr;
8066 struct sk_buff *msg;
8067 void *hdr;
8068 const u8 *addr;
8069 u64 cookie;
8070 int err;
8071
8072 if (wdev->iftype != NL80211_IFTYPE_AP &&
8073 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8074 return -EOPNOTSUPP;
8075
8076 if (!info->attrs[NL80211_ATTR_MAC])
8077 return -EINVAL;
8078
8079 if (!rdev->ops->probe_client)
8080 return -EOPNOTSUPP;
8081
8082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8083 if (!msg)
8084 return -ENOMEM;
8085
Eric W. Biederman15e47302012-09-07 20:12:54 +00008086 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008087 NL80211_CMD_PROBE_CLIENT);
8088
8089 if (IS_ERR(hdr)) {
8090 err = PTR_ERR(hdr);
8091 goto free_msg;
8092 }
8093
8094 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8095
Hila Gonene35e4d22012-06-27 17:19:42 +03008096 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008097 if (err)
8098 goto free_msg;
8099
David S. Miller9360ffd2012-03-29 04:41:26 -04008100 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8101 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008102
8103 genlmsg_end(msg, hdr);
8104
8105 return genlmsg_reply(msg, info);
8106
8107 nla_put_failure:
8108 err = -ENOBUFS;
8109 free_msg:
8110 nlmsg_free(msg);
8111 return err;
8112}
8113
Johannes Berg5e7602302011-11-04 11:18:17 +01008114static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8115{
8116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008117 struct cfg80211_beacon_registration *reg, *nreg;
8118 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008119
8120 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8121 return -EOPNOTSUPP;
8122
Ben Greear37c73b52012-10-26 14:49:25 -07008123 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8124 if (!nreg)
8125 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008126
Ben Greear37c73b52012-10-26 14:49:25 -07008127 /* First, check if already registered. */
8128 spin_lock_bh(&rdev->beacon_registrations_lock);
8129 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8130 if (reg->nlportid == info->snd_portid) {
8131 rv = -EALREADY;
8132 goto out_err;
8133 }
8134 }
8135 /* Add it to the list */
8136 nreg->nlportid = info->snd_portid;
8137 list_add(&nreg->list, &rdev->beacon_registrations);
8138
8139 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008140
8141 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008142out_err:
8143 spin_unlock_bh(&rdev->beacon_registrations_lock);
8144 kfree(nreg);
8145 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008146}
8147
Johannes Berg98104fde2012-06-16 00:19:54 +02008148static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8149{
8150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8151 struct wireless_dev *wdev = info->user_ptr[1];
8152 int err;
8153
8154 if (!rdev->ops->start_p2p_device)
8155 return -EOPNOTSUPP;
8156
8157 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8158 return -EOPNOTSUPP;
8159
8160 if (wdev->p2p_started)
8161 return 0;
8162
Johannes Berg98104fde2012-06-16 00:19:54 +02008163 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008164 if (err)
8165 return err;
8166
Johannes Bergeeb126e2012-10-23 15:16:50 +02008167 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008168 if (err)
8169 return err;
8170
8171 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008172 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008173
8174 return 0;
8175}
8176
8177static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8178{
8179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8180 struct wireless_dev *wdev = info->user_ptr[1];
8181
8182 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8183 return -EOPNOTSUPP;
8184
8185 if (!rdev->ops->stop_p2p_device)
8186 return -EOPNOTSUPP;
8187
Johannes Bergf9f47522013-03-19 15:04:07 +01008188 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008189
8190 return 0;
8191}
8192
Johannes Berg3713b4e2013-02-14 16:19:38 +01008193static int nl80211_get_protocol_features(struct sk_buff *skb,
8194 struct genl_info *info)
8195{
8196 void *hdr;
8197 struct sk_buff *msg;
8198
8199 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8200 if (!msg)
8201 return -ENOMEM;
8202
8203 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8204 NL80211_CMD_GET_PROTOCOL_FEATURES);
8205 if (!hdr)
8206 goto nla_put_failure;
8207
8208 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8209 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8210 goto nla_put_failure;
8211
8212 genlmsg_end(msg, hdr);
8213 return genlmsg_reply(msg, info);
8214
8215 nla_put_failure:
8216 kfree_skb(msg);
8217 return -ENOBUFS;
8218}
8219
Jouni Malinen355199e2013-02-27 17:14:27 +02008220static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8221{
8222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8223 struct cfg80211_update_ft_ies_params ft_params;
8224 struct net_device *dev = info->user_ptr[1];
8225
8226 if (!rdev->ops->update_ft_ies)
8227 return -EOPNOTSUPP;
8228
8229 if (!info->attrs[NL80211_ATTR_MDID] ||
8230 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8231 return -EINVAL;
8232
8233 memset(&ft_params, 0, sizeof(ft_params));
8234 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8235 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8236 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8237
8238 return rdev_update_ft_ies(rdev, dev, &ft_params);
8239}
8240
Arend van Spriel5de17982013-04-18 15:49:00 +02008241static int nl80211_crit_protocol_start(struct sk_buff *skb,
8242 struct genl_info *info)
8243{
8244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8245 struct wireless_dev *wdev = info->user_ptr[1];
8246 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8247 u16 duration;
8248 int ret;
8249
8250 if (!rdev->ops->crit_proto_start)
8251 return -EOPNOTSUPP;
8252
8253 if (WARN_ON(!rdev->ops->crit_proto_stop))
8254 return -EINVAL;
8255
8256 if (rdev->crit_proto_nlportid)
8257 return -EBUSY;
8258
8259 /* determine protocol if provided */
8260 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8261 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8262
8263 if (proto >= NUM_NL80211_CRIT_PROTO)
8264 return -EINVAL;
8265
8266 /* timeout must be provided */
8267 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8268 return -EINVAL;
8269
8270 duration =
8271 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8272
8273 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8274 return -ERANGE;
8275
8276 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8277 if (!ret)
8278 rdev->crit_proto_nlportid = info->snd_portid;
8279
8280 return ret;
8281}
8282
8283static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8284 struct genl_info *info)
8285{
8286 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8287 struct wireless_dev *wdev = info->user_ptr[1];
8288
8289 if (!rdev->ops->crit_proto_stop)
8290 return -EOPNOTSUPP;
8291
8292 if (rdev->crit_proto_nlportid) {
8293 rdev->crit_proto_nlportid = 0;
8294 rdev_crit_proto_stop(rdev, wdev);
8295 }
8296 return 0;
8297}
8298
Johannes Berg4c476992010-10-04 21:36:35 +02008299#define NL80211_FLAG_NEED_WIPHY 0x01
8300#define NL80211_FLAG_NEED_NETDEV 0x02
8301#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008302#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8303#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8304 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008305#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008306/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008307#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8308 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008309
8310static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8311 struct genl_info *info)
8312{
8313 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008314 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008315 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008316 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8317
8318 if (rtnl)
8319 rtnl_lock();
8320
8321 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008322 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008323 if (IS_ERR(rdev)) {
8324 if (rtnl)
8325 rtnl_unlock();
8326 return PTR_ERR(rdev);
8327 }
8328 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008329 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8330 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008331 ASSERT_RTNL();
8332
Johannes Berg89a54e42012-06-15 14:33:17 +02008333 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8334 info->attrs);
8335 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008336 if (rtnl)
8337 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008338 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008339 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008340
Johannes Berg89a54e42012-06-15 14:33:17 +02008341 dev = wdev->netdev;
8342 rdev = wiphy_to_dev(wdev->wiphy);
8343
Johannes Berg1bf614e2012-06-15 15:23:36 +02008344 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8345 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008346 if (rtnl)
8347 rtnl_unlock();
8348 return -EINVAL;
8349 }
8350
8351 info->user_ptr[1] = dev;
8352 } else {
8353 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008354 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008355
Johannes Berg1bf614e2012-06-15 15:23:36 +02008356 if (dev) {
8357 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8358 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008359 if (rtnl)
8360 rtnl_unlock();
8361 return -ENETDOWN;
8362 }
8363
8364 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008365 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8366 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008367 if (rtnl)
8368 rtnl_unlock();
8369 return -ENETDOWN;
8370 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008371 }
8372
Johannes Berg4c476992010-10-04 21:36:35 +02008373 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008374 }
8375
8376 return 0;
8377}
8378
8379static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8380 struct genl_info *info)
8381{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008382 if (info->user_ptr[1]) {
8383 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8384 struct wireless_dev *wdev = info->user_ptr[1];
8385
8386 if (wdev->netdev)
8387 dev_put(wdev->netdev);
8388 } else {
8389 dev_put(info->user_ptr[1]);
8390 }
8391 }
Johannes Berg4c476992010-10-04 21:36:35 +02008392 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8393 rtnl_unlock();
8394}
8395
Johannes Berg55682962007-09-20 13:09:35 -04008396static struct genl_ops nl80211_ops[] = {
8397 {
8398 .cmd = NL80211_CMD_GET_WIPHY,
8399 .doit = nl80211_get_wiphy,
8400 .dumpit = nl80211_dump_wiphy,
8401 .policy = nl80211_policy,
8402 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008403 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8404 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008405 },
8406 {
8407 .cmd = NL80211_CMD_SET_WIPHY,
8408 .doit = nl80211_set_wiphy,
8409 .policy = nl80211_policy,
8410 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008411 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008412 },
8413 {
8414 .cmd = NL80211_CMD_GET_INTERFACE,
8415 .doit = nl80211_get_interface,
8416 .dumpit = nl80211_dump_interface,
8417 .policy = nl80211_policy,
8418 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008419 .internal_flags = NL80211_FLAG_NEED_WDEV |
8420 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008421 },
8422 {
8423 .cmd = NL80211_CMD_SET_INTERFACE,
8424 .doit = nl80211_set_interface,
8425 .policy = nl80211_policy,
8426 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008427 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8428 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008429 },
8430 {
8431 .cmd = NL80211_CMD_NEW_INTERFACE,
8432 .doit = nl80211_new_interface,
8433 .policy = nl80211_policy,
8434 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008435 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8436 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008437 },
8438 {
8439 .cmd = NL80211_CMD_DEL_INTERFACE,
8440 .doit = nl80211_del_interface,
8441 .policy = nl80211_policy,
8442 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008443 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008444 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008445 },
Johannes Berg41ade002007-12-19 02:03:29 +01008446 {
8447 .cmd = NL80211_CMD_GET_KEY,
8448 .doit = nl80211_get_key,
8449 .policy = nl80211_policy,
8450 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008452 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008453 },
8454 {
8455 .cmd = NL80211_CMD_SET_KEY,
8456 .doit = nl80211_set_key,
8457 .policy = nl80211_policy,
8458 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008460 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008461 },
8462 {
8463 .cmd = NL80211_CMD_NEW_KEY,
8464 .doit = nl80211_new_key,
8465 .policy = nl80211_policy,
8466 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008468 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008469 },
8470 {
8471 .cmd = NL80211_CMD_DEL_KEY,
8472 .doit = nl80211_del_key,
8473 .policy = nl80211_policy,
8474 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008475 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008476 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008477 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008478 {
8479 .cmd = NL80211_CMD_SET_BEACON,
8480 .policy = nl80211_policy,
8481 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008482 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008483 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008484 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008485 },
8486 {
Johannes Berg88600202012-02-13 15:17:18 +01008487 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008488 .policy = nl80211_policy,
8489 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008490 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008492 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008493 },
8494 {
Johannes Berg88600202012-02-13 15:17:18 +01008495 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008496 .policy = nl80211_policy,
8497 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008498 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008500 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008501 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008502 {
8503 .cmd = NL80211_CMD_GET_STATION,
8504 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008505 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008506 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008507 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8508 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008509 },
8510 {
8511 .cmd = NL80211_CMD_SET_STATION,
8512 .doit = nl80211_set_station,
8513 .policy = nl80211_policy,
8514 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008516 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008517 },
8518 {
8519 .cmd = NL80211_CMD_NEW_STATION,
8520 .doit = nl80211_new_station,
8521 .policy = nl80211_policy,
8522 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008524 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008525 },
8526 {
8527 .cmd = NL80211_CMD_DEL_STATION,
8528 .doit = nl80211_del_station,
8529 .policy = nl80211_policy,
8530 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008532 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008533 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008534 {
8535 .cmd = NL80211_CMD_GET_MPATH,
8536 .doit = nl80211_get_mpath,
8537 .dumpit = nl80211_dump_mpath,
8538 .policy = nl80211_policy,
8539 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008540 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008541 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008542 },
8543 {
8544 .cmd = NL80211_CMD_SET_MPATH,
8545 .doit = nl80211_set_mpath,
8546 .policy = nl80211_policy,
8547 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008548 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008549 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008550 },
8551 {
8552 .cmd = NL80211_CMD_NEW_MPATH,
8553 .doit = nl80211_new_mpath,
8554 .policy = nl80211_policy,
8555 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008556 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008557 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008558 },
8559 {
8560 .cmd = NL80211_CMD_DEL_MPATH,
8561 .doit = nl80211_del_mpath,
8562 .policy = nl80211_policy,
8563 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008564 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008565 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008566 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008567 {
8568 .cmd = NL80211_CMD_SET_BSS,
8569 .doit = nl80211_set_bss,
8570 .policy = nl80211_policy,
8571 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008572 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008573 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008574 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008575 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008576 .cmd = NL80211_CMD_GET_REG,
8577 .doit = nl80211_get_reg,
8578 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008579 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008580 /* can be retrieved by unprivileged users */
8581 },
8582 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008583 .cmd = NL80211_CMD_SET_REG,
8584 .doit = nl80211_set_reg,
8585 .policy = nl80211_policy,
8586 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008587 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008588 },
8589 {
8590 .cmd = NL80211_CMD_REQ_SET_REG,
8591 .doit = nl80211_req_set_reg,
8592 .policy = nl80211_policy,
8593 .flags = GENL_ADMIN_PERM,
8594 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008595 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008596 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8597 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008598 .policy = nl80211_policy,
8599 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008600 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008601 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008602 },
8603 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008604 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8605 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008606 .policy = nl80211_policy,
8607 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008608 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008609 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008610 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008611 {
Johannes Berg2a519312009-02-10 21:25:55 +01008612 .cmd = NL80211_CMD_TRIGGER_SCAN,
8613 .doit = nl80211_trigger_scan,
8614 .policy = nl80211_policy,
8615 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008616 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008617 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008618 },
8619 {
8620 .cmd = NL80211_CMD_GET_SCAN,
8621 .policy = nl80211_policy,
8622 .dumpit = nl80211_dump_scan,
8623 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008624 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008625 .cmd = NL80211_CMD_START_SCHED_SCAN,
8626 .doit = nl80211_start_sched_scan,
8627 .policy = nl80211_policy,
8628 .flags = GENL_ADMIN_PERM,
8629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8630 NL80211_FLAG_NEED_RTNL,
8631 },
8632 {
8633 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8634 .doit = nl80211_stop_sched_scan,
8635 .policy = nl80211_policy,
8636 .flags = GENL_ADMIN_PERM,
8637 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8638 NL80211_FLAG_NEED_RTNL,
8639 },
8640 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008641 .cmd = NL80211_CMD_AUTHENTICATE,
8642 .doit = nl80211_authenticate,
8643 .policy = nl80211_policy,
8644 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008645 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008646 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008647 },
8648 {
8649 .cmd = NL80211_CMD_ASSOCIATE,
8650 .doit = nl80211_associate,
8651 .policy = nl80211_policy,
8652 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008653 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008654 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008655 },
8656 {
8657 .cmd = NL80211_CMD_DEAUTHENTICATE,
8658 .doit = nl80211_deauthenticate,
8659 .policy = nl80211_policy,
8660 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008662 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008663 },
8664 {
8665 .cmd = NL80211_CMD_DISASSOCIATE,
8666 .doit = nl80211_disassociate,
8667 .policy = nl80211_policy,
8668 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008670 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008671 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008672 {
8673 .cmd = NL80211_CMD_JOIN_IBSS,
8674 .doit = nl80211_join_ibss,
8675 .policy = nl80211_policy,
8676 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008677 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008678 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008679 },
8680 {
8681 .cmd = NL80211_CMD_LEAVE_IBSS,
8682 .doit = nl80211_leave_ibss,
8683 .policy = nl80211_policy,
8684 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008685 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008686 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008687 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008688#ifdef CONFIG_NL80211_TESTMODE
8689 {
8690 .cmd = NL80211_CMD_TESTMODE,
8691 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008692 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008693 .policy = nl80211_policy,
8694 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008695 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8696 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008697 },
8698#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008699 {
8700 .cmd = NL80211_CMD_CONNECT,
8701 .doit = nl80211_connect,
8702 .policy = nl80211_policy,
8703 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008704 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008705 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008706 },
8707 {
8708 .cmd = NL80211_CMD_DISCONNECT,
8709 .doit = nl80211_disconnect,
8710 .policy = nl80211_policy,
8711 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008712 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008713 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008714 },
Johannes Berg463d0182009-07-14 00:33:35 +02008715 {
8716 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8717 .doit = nl80211_wiphy_netns,
8718 .policy = nl80211_policy,
8719 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008720 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8721 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008722 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008723 {
8724 .cmd = NL80211_CMD_GET_SURVEY,
8725 .policy = nl80211_policy,
8726 .dumpit = nl80211_dump_survey,
8727 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008728 {
8729 .cmd = NL80211_CMD_SET_PMKSA,
8730 .doit = nl80211_setdel_pmksa,
8731 .policy = nl80211_policy,
8732 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008734 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008735 },
8736 {
8737 .cmd = NL80211_CMD_DEL_PMKSA,
8738 .doit = nl80211_setdel_pmksa,
8739 .policy = nl80211_policy,
8740 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008741 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008742 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008743 },
8744 {
8745 .cmd = NL80211_CMD_FLUSH_PMKSA,
8746 .doit = nl80211_flush_pmksa,
8747 .policy = nl80211_policy,
8748 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008749 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008750 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008751 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008752 {
8753 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8754 .doit = nl80211_remain_on_channel,
8755 .policy = nl80211_policy,
8756 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008757 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008758 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008759 },
8760 {
8761 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8762 .doit = nl80211_cancel_remain_on_channel,
8763 .policy = nl80211_policy,
8764 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008765 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008766 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008767 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008768 {
8769 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8770 .doit = nl80211_set_tx_bitrate_mask,
8771 .policy = nl80211_policy,
8772 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008773 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8774 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008775 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008776 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008777 .cmd = NL80211_CMD_REGISTER_FRAME,
8778 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008779 .policy = nl80211_policy,
8780 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008781 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008782 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008783 },
8784 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008785 .cmd = NL80211_CMD_FRAME,
8786 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008787 .policy = nl80211_policy,
8788 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008789 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008790 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008791 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008792 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008793 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8794 .doit = nl80211_tx_mgmt_cancel_wait,
8795 .policy = nl80211_policy,
8796 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008797 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008798 NL80211_FLAG_NEED_RTNL,
8799 },
8800 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008801 .cmd = NL80211_CMD_SET_POWER_SAVE,
8802 .doit = nl80211_set_power_save,
8803 .policy = nl80211_policy,
8804 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008805 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8806 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008807 },
8808 {
8809 .cmd = NL80211_CMD_GET_POWER_SAVE,
8810 .doit = nl80211_get_power_save,
8811 .policy = nl80211_policy,
8812 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008813 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8814 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008815 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008816 {
8817 .cmd = NL80211_CMD_SET_CQM,
8818 .doit = nl80211_set_cqm,
8819 .policy = nl80211_policy,
8820 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008821 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8822 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008823 },
Johannes Bergf444de02010-05-05 15:25:02 +02008824 {
8825 .cmd = NL80211_CMD_SET_CHANNEL,
8826 .doit = nl80211_set_channel,
8827 .policy = nl80211_policy,
8828 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008829 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8830 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008831 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008832 {
8833 .cmd = NL80211_CMD_SET_WDS_PEER,
8834 .doit = nl80211_set_wds_peer,
8835 .policy = nl80211_policy,
8836 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008837 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8838 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008839 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008840 {
8841 .cmd = NL80211_CMD_JOIN_MESH,
8842 .doit = nl80211_join_mesh,
8843 .policy = nl80211_policy,
8844 .flags = GENL_ADMIN_PERM,
8845 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8846 NL80211_FLAG_NEED_RTNL,
8847 },
8848 {
8849 .cmd = NL80211_CMD_LEAVE_MESH,
8850 .doit = nl80211_leave_mesh,
8851 .policy = nl80211_policy,
8852 .flags = GENL_ADMIN_PERM,
8853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8854 NL80211_FLAG_NEED_RTNL,
8855 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008856#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008857 {
8858 .cmd = NL80211_CMD_GET_WOWLAN,
8859 .doit = nl80211_get_wowlan,
8860 .policy = nl80211_policy,
8861 /* can be retrieved by unprivileged users */
8862 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8863 NL80211_FLAG_NEED_RTNL,
8864 },
8865 {
8866 .cmd = NL80211_CMD_SET_WOWLAN,
8867 .doit = nl80211_set_wowlan,
8868 .policy = nl80211_policy,
8869 .flags = GENL_ADMIN_PERM,
8870 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8871 NL80211_FLAG_NEED_RTNL,
8872 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008873#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008874 {
8875 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8876 .doit = nl80211_set_rekey_data,
8877 .policy = nl80211_policy,
8878 .flags = GENL_ADMIN_PERM,
8879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8880 NL80211_FLAG_NEED_RTNL,
8881 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008882 {
8883 .cmd = NL80211_CMD_TDLS_MGMT,
8884 .doit = nl80211_tdls_mgmt,
8885 .policy = nl80211_policy,
8886 .flags = GENL_ADMIN_PERM,
8887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8888 NL80211_FLAG_NEED_RTNL,
8889 },
8890 {
8891 .cmd = NL80211_CMD_TDLS_OPER,
8892 .doit = nl80211_tdls_oper,
8893 .policy = nl80211_policy,
8894 .flags = GENL_ADMIN_PERM,
8895 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8896 NL80211_FLAG_NEED_RTNL,
8897 },
Johannes Berg28946da2011-11-04 11:18:12 +01008898 {
8899 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8900 .doit = nl80211_register_unexpected_frame,
8901 .policy = nl80211_policy,
8902 .flags = GENL_ADMIN_PERM,
8903 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8904 NL80211_FLAG_NEED_RTNL,
8905 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008906 {
8907 .cmd = NL80211_CMD_PROBE_CLIENT,
8908 .doit = nl80211_probe_client,
8909 .policy = nl80211_policy,
8910 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008911 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008912 NL80211_FLAG_NEED_RTNL,
8913 },
Johannes Berg5e7602302011-11-04 11:18:17 +01008914 {
8915 .cmd = NL80211_CMD_REGISTER_BEACONS,
8916 .doit = nl80211_register_beacons,
8917 .policy = nl80211_policy,
8918 .flags = GENL_ADMIN_PERM,
8919 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8920 NL80211_FLAG_NEED_RTNL,
8921 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008922 {
8923 .cmd = NL80211_CMD_SET_NOACK_MAP,
8924 .doit = nl80211_set_noack_map,
8925 .policy = nl80211_policy,
8926 .flags = GENL_ADMIN_PERM,
8927 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8928 NL80211_FLAG_NEED_RTNL,
8929 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008930 {
8931 .cmd = NL80211_CMD_START_P2P_DEVICE,
8932 .doit = nl80211_start_p2p_device,
8933 .policy = nl80211_policy,
8934 .flags = GENL_ADMIN_PERM,
8935 .internal_flags = NL80211_FLAG_NEED_WDEV |
8936 NL80211_FLAG_NEED_RTNL,
8937 },
8938 {
8939 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8940 .doit = nl80211_stop_p2p_device,
8941 .policy = nl80211_policy,
8942 .flags = GENL_ADMIN_PERM,
8943 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8944 NL80211_FLAG_NEED_RTNL,
8945 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008946 {
8947 .cmd = NL80211_CMD_SET_MCAST_RATE,
8948 .doit = nl80211_set_mcast_rate,
8949 .policy = nl80211_policy,
8950 .flags = GENL_ADMIN_PERM,
8951 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8952 NL80211_FLAG_NEED_RTNL,
8953 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308954 {
8955 .cmd = NL80211_CMD_SET_MAC_ACL,
8956 .doit = nl80211_set_mac_acl,
8957 .policy = nl80211_policy,
8958 .flags = GENL_ADMIN_PERM,
8959 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8960 NL80211_FLAG_NEED_RTNL,
8961 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008962 {
8963 .cmd = NL80211_CMD_RADAR_DETECT,
8964 .doit = nl80211_start_radar_detection,
8965 .policy = nl80211_policy,
8966 .flags = GENL_ADMIN_PERM,
8967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8968 NL80211_FLAG_NEED_RTNL,
8969 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008970 {
8971 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8972 .doit = nl80211_get_protocol_features,
8973 .policy = nl80211_policy,
8974 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008975 {
8976 .cmd = NL80211_CMD_UPDATE_FT_IES,
8977 .doit = nl80211_update_ft_ies,
8978 .policy = nl80211_policy,
8979 .flags = GENL_ADMIN_PERM,
8980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8981 NL80211_FLAG_NEED_RTNL,
8982 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008983 {
8984 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8985 .doit = nl80211_crit_protocol_start,
8986 .policy = nl80211_policy,
8987 .flags = GENL_ADMIN_PERM,
8988 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8989 NL80211_FLAG_NEED_RTNL,
8990 },
8991 {
8992 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
8993 .doit = nl80211_crit_protocol_stop,
8994 .policy = nl80211_policy,
8995 .flags = GENL_ADMIN_PERM,
8996 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8997 NL80211_FLAG_NEED_RTNL,
8998 }
Johannes Berg55682962007-09-20 13:09:35 -04008999};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009000
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009001static struct genl_multicast_group nl80211_mlme_mcgrp = {
9002 .name = "mlme",
9003};
Johannes Berg55682962007-09-20 13:09:35 -04009004
9005/* multicast groups */
9006static struct genl_multicast_group nl80211_config_mcgrp = {
9007 .name = "config",
9008};
Johannes Berg2a519312009-02-10 21:25:55 +01009009static struct genl_multicast_group nl80211_scan_mcgrp = {
9010 .name = "scan",
9011};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009012static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9013 .name = "regulatory",
9014};
Johannes Berg55682962007-09-20 13:09:35 -04009015
9016/* notification functions */
9017
9018void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9019{
9020 struct sk_buff *msg;
9021
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009022 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009023 if (!msg)
9024 return;
9025
Johannes Berg3713b4e2013-02-14 16:19:38 +01009026 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
9027 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009028 nlmsg_free(msg);
9029 return;
9030 }
9031
Johannes Berg463d0182009-07-14 00:33:35 +02009032 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9033 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009034}
9035
Johannes Berg362a4152009-05-24 16:43:15 +02009036static int nl80211_add_scan_req(struct sk_buff *msg,
9037 struct cfg80211_registered_device *rdev)
9038{
9039 struct cfg80211_scan_request *req = rdev->scan_req;
9040 struct nlattr *nest;
9041 int i;
9042
9043 if (WARN_ON(!req))
9044 return 0;
9045
9046 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9047 if (!nest)
9048 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009049 for (i = 0; i < req->n_ssids; i++) {
9050 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9051 goto nla_put_failure;
9052 }
Johannes Berg362a4152009-05-24 16:43:15 +02009053 nla_nest_end(msg, nest);
9054
9055 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9056 if (!nest)
9057 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009058 for (i = 0; i < req->n_channels; i++) {
9059 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9060 goto nla_put_failure;
9061 }
Johannes Berg362a4152009-05-24 16:43:15 +02009062 nla_nest_end(msg, nest);
9063
David S. Miller9360ffd2012-03-29 04:41:26 -04009064 if (req->ie &&
9065 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9066 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009067
Sam Lefflered4737712012-10-11 21:03:31 -07009068 if (req->flags)
9069 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9070
Johannes Berg362a4152009-05-24 16:43:15 +02009071 return 0;
9072 nla_put_failure:
9073 return -ENOBUFS;
9074}
9075
Johannes Berga538e2d2009-06-16 19:56:42 +02009076static int nl80211_send_scan_msg(struct sk_buff *msg,
9077 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009078 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009079 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009080 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009081{
9082 void *hdr;
9083
Eric W. Biederman15e47302012-09-07 20:12:54 +00009084 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009085 if (!hdr)
9086 return -1;
9087
David S. Miller9360ffd2012-03-29 04:41:26 -04009088 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009089 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9090 wdev->netdev->ifindex)) ||
9091 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009092 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009093
Johannes Berg362a4152009-05-24 16:43:15 +02009094 /* ignore errors and send incomplete event anyway */
9095 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009096
9097 return genlmsg_end(msg, hdr);
9098
9099 nla_put_failure:
9100 genlmsg_cancel(msg, hdr);
9101 return -EMSGSIZE;
9102}
9103
Luciano Coelho807f8a82011-05-11 17:09:35 +03009104static int
9105nl80211_send_sched_scan_msg(struct sk_buff *msg,
9106 struct cfg80211_registered_device *rdev,
9107 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009108 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009109{
9110 void *hdr;
9111
Eric W. Biederman15e47302012-09-07 20:12:54 +00009112 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009113 if (!hdr)
9114 return -1;
9115
David S. Miller9360ffd2012-03-29 04:41:26 -04009116 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9117 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9118 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009119
9120 return genlmsg_end(msg, hdr);
9121
9122 nla_put_failure:
9123 genlmsg_cancel(msg, hdr);
9124 return -EMSGSIZE;
9125}
9126
Johannes Berga538e2d2009-06-16 19:56:42 +02009127void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009128 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009129{
9130 struct sk_buff *msg;
9131
Thomas Graf58050fc2012-06-28 03:57:45 +00009132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009133 if (!msg)
9134 return;
9135
Johannes Bergfd014282012-06-18 19:17:03 +02009136 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009137 NL80211_CMD_TRIGGER_SCAN) < 0) {
9138 nlmsg_free(msg);
9139 return;
9140 }
9141
Johannes Berg463d0182009-07-14 00:33:35 +02009142 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9143 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009144}
9145
Johannes Berg2a519312009-02-10 21:25:55 +01009146void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009147 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009148{
9149 struct sk_buff *msg;
9150
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009152 if (!msg)
9153 return;
9154
Johannes Bergfd014282012-06-18 19:17:03 +02009155 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009156 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009157 nlmsg_free(msg);
9158 return;
9159 }
9160
Johannes Berg463d0182009-07-14 00:33:35 +02009161 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9162 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009163}
9164
9165void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009166 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009167{
9168 struct sk_buff *msg;
9169
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009171 if (!msg)
9172 return;
9173
Johannes Bergfd014282012-06-18 19:17:03 +02009174 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009175 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009176 nlmsg_free(msg);
9177 return;
9178 }
9179
Johannes Berg463d0182009-07-14 00:33:35 +02009180 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9181 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009182}
9183
Luciano Coelho807f8a82011-05-11 17:09:35 +03009184void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9185 struct net_device *netdev)
9186{
9187 struct sk_buff *msg;
9188
9189 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9190 if (!msg)
9191 return;
9192
9193 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9194 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9195 nlmsg_free(msg);
9196 return;
9197 }
9198
9199 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9200 nl80211_scan_mcgrp.id, GFP_KERNEL);
9201}
9202
9203void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9204 struct net_device *netdev, u32 cmd)
9205{
9206 struct sk_buff *msg;
9207
Thomas Graf58050fc2012-06-28 03:57:45 +00009208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009209 if (!msg)
9210 return;
9211
9212 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9213 nlmsg_free(msg);
9214 return;
9215 }
9216
9217 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9218 nl80211_scan_mcgrp.id, GFP_KERNEL);
9219}
9220
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009221/*
9222 * This can happen on global regulatory changes or device specific settings
9223 * based on custom world regulatory domains.
9224 */
9225void nl80211_send_reg_change_event(struct regulatory_request *request)
9226{
9227 struct sk_buff *msg;
9228 void *hdr;
9229
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009231 if (!msg)
9232 return;
9233
9234 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9235 if (!hdr) {
9236 nlmsg_free(msg);
9237 return;
9238 }
9239
9240 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009241 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9242 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009243
David S. Miller9360ffd2012-03-29 04:41:26 -04009244 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9245 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9246 NL80211_REGDOM_TYPE_WORLD))
9247 goto nla_put_failure;
9248 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9249 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9250 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9251 goto nla_put_failure;
9252 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9253 request->intersect) {
9254 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9255 NL80211_REGDOM_TYPE_INTERSECTION))
9256 goto nla_put_failure;
9257 } else {
9258 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9259 NL80211_REGDOM_TYPE_COUNTRY) ||
9260 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9261 request->alpha2))
9262 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009263 }
9264
Johannes Bergf4173762012-12-03 18:23:37 +01009265 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009266 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9267 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009268
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009269 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009270
Johannes Bergbc43b282009-07-25 10:54:13 +02009271 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009272 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009273 GFP_ATOMIC);
9274 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009275
9276 return;
9277
9278nla_put_failure:
9279 genlmsg_cancel(msg, hdr);
9280 nlmsg_free(msg);
9281}
9282
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009283static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9284 struct net_device *netdev,
9285 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009286 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009287{
9288 struct sk_buff *msg;
9289 void *hdr;
9290
Johannes Berge6d6e342009-07-01 21:26:47 +02009291 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009292 if (!msg)
9293 return;
9294
9295 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9296 if (!hdr) {
9297 nlmsg_free(msg);
9298 return;
9299 }
9300
David S. Miller9360ffd2012-03-29 04:41:26 -04009301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9302 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9303 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9304 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009305
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009306 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009307
Johannes Berg463d0182009-07-14 00:33:35 +02009308 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9309 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009310 return;
9311
9312 nla_put_failure:
9313 genlmsg_cancel(msg, hdr);
9314 nlmsg_free(msg);
9315}
9316
9317void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009318 struct net_device *netdev, const u8 *buf,
9319 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009320{
9321 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009322 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009323}
9324
9325void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9326 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009327 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009328{
Johannes Berge6d6e342009-07-01 21:26:47 +02009329 nl80211_send_mlme_event(rdev, netdev, buf, len,
9330 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009331}
9332
Jouni Malinen53b46b82009-03-27 20:53:56 +02009333void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009334 struct net_device *netdev, const u8 *buf,
9335 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009336{
9337 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009338 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009339}
9340
Jouni Malinen53b46b82009-03-27 20:53:56 +02009341void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9342 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009343 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009344{
9345 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009346 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009347}
9348
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009349void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9350 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009351{
Johannes Berg947add32013-02-22 22:05:20 +01009352 struct wireless_dev *wdev = dev->ieee80211_ptr;
9353 struct wiphy *wiphy = wdev->wiphy;
9354 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009355 const struct ieee80211_mgmt *mgmt = (void *)buf;
9356 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009357
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009358 if (WARN_ON(len < 2))
9359 return;
9360
9361 if (ieee80211_is_deauth(mgmt->frame_control))
9362 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9363 else
9364 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9365
9366 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9367 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009368}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009369EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009370
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009371static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9372 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009373 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009374{
9375 struct sk_buff *msg;
9376 void *hdr;
9377
Johannes Berge6d6e342009-07-01 21:26:47 +02009378 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009379 if (!msg)
9380 return;
9381
9382 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9383 if (!hdr) {
9384 nlmsg_free(msg);
9385 return;
9386 }
9387
David S. Miller9360ffd2012-03-29 04:41:26 -04009388 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9389 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9390 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9391 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9392 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009393
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009394 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009395
Johannes Berg463d0182009-07-14 00:33:35 +02009396 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9397 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009398 return;
9399
9400 nla_put_failure:
9401 genlmsg_cancel(msg, hdr);
9402 nlmsg_free(msg);
9403}
9404
9405void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009406 struct net_device *netdev, const u8 *addr,
9407 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009408{
9409 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009410 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009411}
9412
9413void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009414 struct net_device *netdev, const u8 *addr,
9415 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009416{
Johannes Berge6d6e342009-07-01 21:26:47 +02009417 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9418 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009419}
9420
Samuel Ortizb23aa672009-07-01 21:26:54 +02009421void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9422 struct net_device *netdev, const u8 *bssid,
9423 const u8 *req_ie, size_t req_ie_len,
9424 const u8 *resp_ie, size_t resp_ie_len,
9425 u16 status, gfp_t gfp)
9426{
9427 struct sk_buff *msg;
9428 void *hdr;
9429
Thomas Graf58050fc2012-06-28 03:57:45 +00009430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009431 if (!msg)
9432 return;
9433
9434 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9435 if (!hdr) {
9436 nlmsg_free(msg);
9437 return;
9438 }
9439
David S. Miller9360ffd2012-03-29 04:41:26 -04009440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9441 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9442 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9443 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9444 (req_ie &&
9445 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9446 (resp_ie &&
9447 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9448 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009449
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009450 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009451
Johannes Berg463d0182009-07-14 00:33:35 +02009452 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9453 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009454 return;
9455
9456 nla_put_failure:
9457 genlmsg_cancel(msg, hdr);
9458 nlmsg_free(msg);
9459
9460}
9461
9462void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9463 struct net_device *netdev, const u8 *bssid,
9464 const u8 *req_ie, size_t req_ie_len,
9465 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9466{
9467 struct sk_buff *msg;
9468 void *hdr;
9469
Thomas Graf58050fc2012-06-28 03:57:45 +00009470 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009471 if (!msg)
9472 return;
9473
9474 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9475 if (!hdr) {
9476 nlmsg_free(msg);
9477 return;
9478 }
9479
David S. Miller9360ffd2012-03-29 04:41:26 -04009480 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9481 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9483 (req_ie &&
9484 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9485 (resp_ie &&
9486 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9487 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009488
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009489 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009490
Johannes Berg463d0182009-07-14 00:33:35 +02009491 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9492 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009493 return;
9494
9495 nla_put_failure:
9496 genlmsg_cancel(msg, hdr);
9497 nlmsg_free(msg);
9498
9499}
9500
9501void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9502 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009503 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009504{
9505 struct sk_buff *msg;
9506 void *hdr;
9507
Thomas Graf58050fc2012-06-28 03:57:45 +00009508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009509 if (!msg)
9510 return;
9511
9512 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9513 if (!hdr) {
9514 nlmsg_free(msg);
9515 return;
9516 }
9517
David S. Miller9360ffd2012-03-29 04:41:26 -04009518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9519 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9520 (from_ap && reason &&
9521 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9522 (from_ap &&
9523 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9524 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9525 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009526
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009527 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009528
Johannes Berg463d0182009-07-14 00:33:35 +02009529 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9530 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009531 return;
9532
9533 nla_put_failure:
9534 genlmsg_cancel(msg, hdr);
9535 nlmsg_free(msg);
9536
9537}
9538
Johannes Berg04a773a2009-04-19 21:24:32 +02009539void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9540 struct net_device *netdev, const u8 *bssid,
9541 gfp_t gfp)
9542{
9543 struct sk_buff *msg;
9544 void *hdr;
9545
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009546 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009547 if (!msg)
9548 return;
9549
9550 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9551 if (!hdr) {
9552 nlmsg_free(msg);
9553 return;
9554 }
9555
David S. Miller9360ffd2012-03-29 04:41:26 -04009556 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9557 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9558 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9559 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009560
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009561 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009562
Johannes Berg463d0182009-07-14 00:33:35 +02009563 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9564 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009565 return;
9566
9567 nla_put_failure:
9568 genlmsg_cancel(msg, hdr);
9569 nlmsg_free(msg);
9570}
9571
Johannes Berg947add32013-02-22 22:05:20 +01009572void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9573 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009574{
Johannes Berg947add32013-02-22 22:05:20 +01009575 struct wireless_dev *wdev = dev->ieee80211_ptr;
9576 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009577 struct sk_buff *msg;
9578 void *hdr;
9579
Johannes Berg947add32013-02-22 22:05:20 +01009580 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9581 return;
9582
9583 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9584
Javier Cardonac93b5e72011-04-07 15:08:34 -07009585 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9586 if (!msg)
9587 return;
9588
9589 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9590 if (!hdr) {
9591 nlmsg_free(msg);
9592 return;
9593 }
9594
David S. Miller9360ffd2012-03-29 04:41:26 -04009595 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009596 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9597 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009598 (ie_len && ie &&
9599 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9600 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009601
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009602 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009603
9604 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9605 nl80211_mlme_mcgrp.id, gfp);
9606 return;
9607
9608 nla_put_failure:
9609 genlmsg_cancel(msg, hdr);
9610 nlmsg_free(msg);
9611}
Johannes Berg947add32013-02-22 22:05:20 +01009612EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009613
Jouni Malinena3b8b052009-03-27 21:59:49 +02009614void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9615 struct net_device *netdev, const u8 *addr,
9616 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009617 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009618{
9619 struct sk_buff *msg;
9620 void *hdr;
9621
Johannes Berge6d6e342009-07-01 21:26:47 +02009622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009623 if (!msg)
9624 return;
9625
9626 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9627 if (!hdr) {
9628 nlmsg_free(msg);
9629 return;
9630 }
9631
David S. Miller9360ffd2012-03-29 04:41:26 -04009632 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9633 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9634 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9635 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9636 (key_id != -1 &&
9637 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9638 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9639 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009640
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009641 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009642
Johannes Berg463d0182009-07-14 00:33:35 +02009643 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9644 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009645 return;
9646
9647 nla_put_failure:
9648 genlmsg_cancel(msg, hdr);
9649 nlmsg_free(msg);
9650}
9651
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009652void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9653 struct ieee80211_channel *channel_before,
9654 struct ieee80211_channel *channel_after)
9655{
9656 struct sk_buff *msg;
9657 void *hdr;
9658 struct nlattr *nl_freq;
9659
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009660 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009661 if (!msg)
9662 return;
9663
9664 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9665 if (!hdr) {
9666 nlmsg_free(msg);
9667 return;
9668 }
9669
9670 /*
9671 * Since we are applying the beacon hint to a wiphy we know its
9672 * wiphy_idx is valid
9673 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009674 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9675 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009676
9677 /* Before */
9678 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9679 if (!nl_freq)
9680 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009681 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009682 goto nla_put_failure;
9683 nla_nest_end(msg, nl_freq);
9684
9685 /* After */
9686 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9687 if (!nl_freq)
9688 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009689 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009690 goto nla_put_failure;
9691 nla_nest_end(msg, nl_freq);
9692
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009693 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009694
Johannes Berg463d0182009-07-14 00:33:35 +02009695 rcu_read_lock();
9696 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9697 GFP_ATOMIC);
9698 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009699
9700 return;
9701
9702nla_put_failure:
9703 genlmsg_cancel(msg, hdr);
9704 nlmsg_free(msg);
9705}
9706
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009707static void nl80211_send_remain_on_chan_event(
9708 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009709 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009710 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009711 unsigned int duration, gfp_t gfp)
9712{
9713 struct sk_buff *msg;
9714 void *hdr;
9715
9716 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9717 if (!msg)
9718 return;
9719
9720 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9721 if (!hdr) {
9722 nlmsg_free(msg);
9723 return;
9724 }
9725
David S. Miller9360ffd2012-03-29 04:41:26 -04009726 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009727 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9728 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009729 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009730 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009731 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9732 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009733 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9734 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009735
David S. Miller9360ffd2012-03-29 04:41:26 -04009736 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9737 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9738 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009739
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009740 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009741
9742 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9743 nl80211_mlme_mcgrp.id, gfp);
9744 return;
9745
9746 nla_put_failure:
9747 genlmsg_cancel(msg, hdr);
9748 nlmsg_free(msg);
9749}
9750
Johannes Berg947add32013-02-22 22:05:20 +01009751void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9752 struct ieee80211_channel *chan,
9753 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009754{
Johannes Berg947add32013-02-22 22:05:20 +01009755 struct wiphy *wiphy = wdev->wiphy;
9756 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9757
9758 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009759 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009760 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009761 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009762}
Johannes Berg947add32013-02-22 22:05:20 +01009763EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009764
Johannes Berg947add32013-02-22 22:05:20 +01009765void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9766 struct ieee80211_channel *chan,
9767 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009768{
Johannes Berg947add32013-02-22 22:05:20 +01009769 struct wiphy *wiphy = wdev->wiphy;
9770 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9771
9772 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009773 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009774 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009775}
Johannes Berg947add32013-02-22 22:05:20 +01009776EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009777
Johannes Berg947add32013-02-22 22:05:20 +01009778void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9779 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009780{
Johannes Berg947add32013-02-22 22:05:20 +01009781 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9782 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009783 struct sk_buff *msg;
9784
Johannes Berg947add32013-02-22 22:05:20 +01009785 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9786
Thomas Graf58050fc2012-06-28 03:57:45 +00009787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009788 if (!msg)
9789 return;
9790
John W. Linville66266b32012-03-15 13:25:41 -04009791 if (nl80211_send_station(msg, 0, 0, 0,
9792 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009793 nlmsg_free(msg);
9794 return;
9795 }
9796
9797 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9798 nl80211_mlme_mcgrp.id, gfp);
9799}
Johannes Berg947add32013-02-22 22:05:20 +01009800EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009801
Johannes Berg947add32013-02-22 22:05:20 +01009802void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009803{
Johannes Berg947add32013-02-22 22:05:20 +01009804 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9805 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009806 struct sk_buff *msg;
9807 void *hdr;
9808
Johannes Berg947add32013-02-22 22:05:20 +01009809 trace_cfg80211_del_sta(dev, mac_addr);
9810
Thomas Graf58050fc2012-06-28 03:57:45 +00009811 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009812 if (!msg)
9813 return;
9814
9815 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9816 if (!hdr) {
9817 nlmsg_free(msg);
9818 return;
9819 }
9820
David S. Miller9360ffd2012-03-29 04:41:26 -04009821 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9822 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9823 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009824
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009825 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009826
9827 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9828 nl80211_mlme_mcgrp.id, gfp);
9829 return;
9830
9831 nla_put_failure:
9832 genlmsg_cancel(msg, hdr);
9833 nlmsg_free(msg);
9834}
Johannes Berg947add32013-02-22 22:05:20 +01009835EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009836
Johannes Berg947add32013-02-22 22:05:20 +01009837void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9838 enum nl80211_connect_failed_reason reason,
9839 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309840{
Johannes Berg947add32013-02-22 22:05:20 +01009841 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9842 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309843 struct sk_buff *msg;
9844 void *hdr;
9845
9846 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9847 if (!msg)
9848 return;
9849
9850 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9851 if (!hdr) {
9852 nlmsg_free(msg);
9853 return;
9854 }
9855
9856 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9857 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9858 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9859 goto nla_put_failure;
9860
9861 genlmsg_end(msg, hdr);
9862
9863 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9864 nl80211_mlme_mcgrp.id, gfp);
9865 return;
9866
9867 nla_put_failure:
9868 genlmsg_cancel(msg, hdr);
9869 nlmsg_free(msg);
9870}
Johannes Berg947add32013-02-22 22:05:20 +01009871EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309872
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009873static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9874 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009875{
9876 struct wireless_dev *wdev = dev->ieee80211_ptr;
9877 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9878 struct sk_buff *msg;
9879 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009880 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009881
Eric W. Biederman15e47302012-09-07 20:12:54 +00009882 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009883 return false;
9884
9885 msg = nlmsg_new(100, gfp);
9886 if (!msg)
9887 return true;
9888
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009889 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009890 if (!hdr) {
9891 nlmsg_free(msg);
9892 return true;
9893 }
9894
David S. Miller9360ffd2012-03-29 04:41:26 -04009895 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9896 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9897 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9898 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009899
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009900 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009901 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009902 return true;
9903
9904 nla_put_failure:
9905 genlmsg_cancel(msg, hdr);
9906 nlmsg_free(msg);
9907 return true;
9908}
9909
Johannes Berg947add32013-02-22 22:05:20 +01009910bool cfg80211_rx_spurious_frame(struct net_device *dev,
9911 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009912{
Johannes Berg947add32013-02-22 22:05:20 +01009913 struct wireless_dev *wdev = dev->ieee80211_ptr;
9914 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009915
Johannes Berg947add32013-02-22 22:05:20 +01009916 trace_cfg80211_rx_spurious_frame(dev, addr);
9917
9918 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9919 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9920 trace_cfg80211_return_bool(false);
9921 return false;
9922 }
9923 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9924 addr, gfp);
9925 trace_cfg80211_return_bool(ret);
9926 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009927}
Johannes Berg947add32013-02-22 22:05:20 +01009928EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9929
9930bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9931 const u8 *addr, gfp_t gfp)
9932{
9933 struct wireless_dev *wdev = dev->ieee80211_ptr;
9934 bool ret;
9935
9936 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9937
9938 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9939 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9940 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9941 trace_cfg80211_return_bool(false);
9942 return false;
9943 }
9944 ret = __nl80211_unexpected_frame(dev,
9945 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9946 addr, gfp);
9947 trace_cfg80211_return_bool(ret);
9948 return ret;
9949}
9950EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009951
Johannes Berg2e161f72010-08-12 15:38:38 +02009952int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009953 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009954 int freq, int sig_dbm,
9955 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009956{
Johannes Berg71bbc992012-06-15 15:30:18 +02009957 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009958 struct sk_buff *msg;
9959 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009960
9961 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9962 if (!msg)
9963 return -ENOMEM;
9964
Johannes Berg2e161f72010-08-12 15:38:38 +02009965 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009966 if (!hdr) {
9967 nlmsg_free(msg);
9968 return -ENOMEM;
9969 }
9970
David S. Miller9360ffd2012-03-29 04:41:26 -04009971 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009972 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9973 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009974 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009975 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9976 (sig_dbm &&
9977 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9978 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9979 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009980
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009981 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009982
Eric W. Biederman15e47302012-09-07 20:12:54 +00009983 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009984
9985 nla_put_failure:
9986 genlmsg_cancel(msg, hdr);
9987 nlmsg_free(msg);
9988 return -ENOBUFS;
9989}
9990
Johannes Berg947add32013-02-22 22:05:20 +01009991void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9992 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009993{
Johannes Berg947add32013-02-22 22:05:20 +01009994 struct wiphy *wiphy = wdev->wiphy;
9995 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009996 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009997 struct sk_buff *msg;
9998 void *hdr;
9999
Johannes Berg947add32013-02-22 22:05:20 +010010000 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10001
Jouni Malinen026331c2010-02-15 12:53:10 +020010002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10003 if (!msg)
10004 return;
10005
Johannes Berg2e161f72010-08-12 15:38:38 +020010006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010007 if (!hdr) {
10008 nlmsg_free(msg);
10009 return;
10010 }
10011
David S. Miller9360ffd2012-03-29 04:41:26 -040010012 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010013 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10014 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010015 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010016 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10017 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10018 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10019 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010020
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010021 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010022
10023 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10024 return;
10025
10026 nla_put_failure:
10027 genlmsg_cancel(msg, hdr);
10028 nlmsg_free(msg);
10029}
Johannes Berg947add32013-02-22 22:05:20 +010010030EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010031
Johannes Berg947add32013-02-22 22:05:20 +010010032void cfg80211_cqm_rssi_notify(struct net_device *dev,
10033 enum nl80211_cqm_rssi_threshold_event rssi_event,
10034 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010035{
Johannes Berg947add32013-02-22 22:05:20 +010010036 struct wireless_dev *wdev = dev->ieee80211_ptr;
10037 struct wiphy *wiphy = wdev->wiphy;
10038 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010039 struct sk_buff *msg;
10040 struct nlattr *pinfoattr;
10041 void *hdr;
10042
Johannes Berg947add32013-02-22 22:05:20 +010010043 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10044
Thomas Graf58050fc2012-06-28 03:57:45 +000010045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010046 if (!msg)
10047 return;
10048
10049 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10050 if (!hdr) {
10051 nlmsg_free(msg);
10052 return;
10053 }
10054
David S. Miller9360ffd2012-03-29 04:41:26 -040010055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010057 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010058
10059 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10060 if (!pinfoattr)
10061 goto nla_put_failure;
10062
David S. Miller9360ffd2012-03-29 04:41:26 -040010063 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10064 rssi_event))
10065 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010066
10067 nla_nest_end(msg, pinfoattr);
10068
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010069 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010070
10071 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10072 nl80211_mlme_mcgrp.id, gfp);
10073 return;
10074
10075 nla_put_failure:
10076 genlmsg_cancel(msg, hdr);
10077 nlmsg_free(msg);
10078}
Johannes Berg947add32013-02-22 22:05:20 +010010079EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010080
Johannes Berg947add32013-02-22 22:05:20 +010010081static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10082 struct net_device *netdev, const u8 *bssid,
10083 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010084{
10085 struct sk_buff *msg;
10086 struct nlattr *rekey_attr;
10087 void *hdr;
10088
Thomas Graf58050fc2012-06-28 03:57:45 +000010089 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010090 if (!msg)
10091 return;
10092
10093 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10094 if (!hdr) {
10095 nlmsg_free(msg);
10096 return;
10097 }
10098
David S. Miller9360ffd2012-03-29 04:41:26 -040010099 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10100 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10101 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10102 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010103
10104 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10105 if (!rekey_attr)
10106 goto nla_put_failure;
10107
David S. Miller9360ffd2012-03-29 04:41:26 -040010108 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10109 NL80211_REPLAY_CTR_LEN, replay_ctr))
10110 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010111
10112 nla_nest_end(msg, rekey_attr);
10113
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010114 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010115
10116 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10117 nl80211_mlme_mcgrp.id, gfp);
10118 return;
10119
10120 nla_put_failure:
10121 genlmsg_cancel(msg, hdr);
10122 nlmsg_free(msg);
10123}
10124
Johannes Berg947add32013-02-22 22:05:20 +010010125void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10126 const u8 *replay_ctr, gfp_t gfp)
10127{
10128 struct wireless_dev *wdev = dev->ieee80211_ptr;
10129 struct wiphy *wiphy = wdev->wiphy;
10130 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10131
10132 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10133 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10134}
10135EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10136
10137static void
10138nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10139 struct net_device *netdev, int index,
10140 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010141{
10142 struct sk_buff *msg;
10143 struct nlattr *attr;
10144 void *hdr;
10145
Thomas Graf58050fc2012-06-28 03:57:45 +000010146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010147 if (!msg)
10148 return;
10149
10150 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10151 if (!hdr) {
10152 nlmsg_free(msg);
10153 return;
10154 }
10155
David S. Miller9360ffd2012-03-29 04:41:26 -040010156 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10157 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10158 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010159
10160 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10161 if (!attr)
10162 goto nla_put_failure;
10163
David S. Miller9360ffd2012-03-29 04:41:26 -040010164 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10165 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10166 (preauth &&
10167 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10168 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010169
10170 nla_nest_end(msg, attr);
10171
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010172 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010173
10174 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10175 nl80211_mlme_mcgrp.id, gfp);
10176 return;
10177
10178 nla_put_failure:
10179 genlmsg_cancel(msg, hdr);
10180 nlmsg_free(msg);
10181}
10182
Johannes Berg947add32013-02-22 22:05:20 +010010183void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10184 const u8 *bssid, bool preauth, gfp_t gfp)
10185{
10186 struct wireless_dev *wdev = dev->ieee80211_ptr;
10187 struct wiphy *wiphy = wdev->wiphy;
10188 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10189
10190 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10191 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10192}
10193EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10194
10195static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10196 struct net_device *netdev,
10197 struct cfg80211_chan_def *chandef,
10198 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010199{
10200 struct sk_buff *msg;
10201 void *hdr;
10202
Thomas Graf58050fc2012-06-28 03:57:45 +000010203 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010204 if (!msg)
10205 return;
10206
10207 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10208 if (!hdr) {
10209 nlmsg_free(msg);
10210 return;
10211 }
10212
Johannes Berg683b6d32012-11-08 21:25:48 +010010213 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10214 goto nla_put_failure;
10215
10216 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010217 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010218
10219 genlmsg_end(msg, hdr);
10220
10221 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10222 nl80211_mlme_mcgrp.id, gfp);
10223 return;
10224
10225 nla_put_failure:
10226 genlmsg_cancel(msg, hdr);
10227 nlmsg_free(msg);
10228}
10229
Johannes Berg947add32013-02-22 22:05:20 +010010230void cfg80211_ch_switch_notify(struct net_device *dev,
10231 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010232{
Johannes Berg947add32013-02-22 22:05:20 +010010233 struct wireless_dev *wdev = dev->ieee80211_ptr;
10234 struct wiphy *wiphy = wdev->wiphy;
10235 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10236
10237 trace_cfg80211_ch_switch_notify(dev, chandef);
10238
10239 wdev_lock(wdev);
10240
10241 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10242 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10243 goto out;
10244
10245 wdev->channel = chandef->chan;
10246 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10247out:
10248 wdev_unlock(wdev);
10249 return;
10250}
10251EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10252
10253void cfg80211_cqm_txe_notify(struct net_device *dev,
10254 const u8 *peer, u32 num_packets,
10255 u32 rate, u32 intvl, gfp_t gfp)
10256{
10257 struct wireless_dev *wdev = dev->ieee80211_ptr;
10258 struct wiphy *wiphy = wdev->wiphy;
10259 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010260 struct sk_buff *msg;
10261 struct nlattr *pinfoattr;
10262 void *hdr;
10263
10264 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10265 if (!msg)
10266 return;
10267
10268 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10269 if (!hdr) {
10270 nlmsg_free(msg);
10271 return;
10272 }
10273
10274 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010275 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010276 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10277 goto nla_put_failure;
10278
10279 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10280 if (!pinfoattr)
10281 goto nla_put_failure;
10282
10283 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10284 goto nla_put_failure;
10285
10286 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10287 goto nla_put_failure;
10288
10289 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10290 goto nla_put_failure;
10291
10292 nla_nest_end(msg, pinfoattr);
10293
10294 genlmsg_end(msg, hdr);
10295
10296 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10297 nl80211_mlme_mcgrp.id, gfp);
10298 return;
10299
10300 nla_put_failure:
10301 genlmsg_cancel(msg, hdr);
10302 nlmsg_free(msg);
10303}
Johannes Berg947add32013-02-22 22:05:20 +010010304EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010305
10306void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010307nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10308 struct cfg80211_chan_def *chandef,
10309 enum nl80211_radar_event event,
10310 struct net_device *netdev, gfp_t gfp)
10311{
10312 struct sk_buff *msg;
10313 void *hdr;
10314
10315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10316 if (!msg)
10317 return;
10318
10319 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10320 if (!hdr) {
10321 nlmsg_free(msg);
10322 return;
10323 }
10324
10325 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10326 goto nla_put_failure;
10327
10328 /* NOP and radar events don't need a netdev parameter */
10329 if (netdev) {
10330 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10331
10332 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10333 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10334 goto nla_put_failure;
10335 }
10336
10337 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10338 goto nla_put_failure;
10339
10340 if (nl80211_send_chandef(msg, chandef))
10341 goto nla_put_failure;
10342
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010343 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010344
10345 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10346 nl80211_mlme_mcgrp.id, gfp);
10347 return;
10348
10349 nla_put_failure:
10350 genlmsg_cancel(msg, hdr);
10351 nlmsg_free(msg);
10352}
10353
Johannes Berg947add32013-02-22 22:05:20 +010010354void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10355 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010356{
Johannes Berg947add32013-02-22 22:05:20 +010010357 struct wireless_dev *wdev = dev->ieee80211_ptr;
10358 struct wiphy *wiphy = wdev->wiphy;
10359 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010360 struct sk_buff *msg;
10361 struct nlattr *pinfoattr;
10362 void *hdr;
10363
Johannes Berg947add32013-02-22 22:05:20 +010010364 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10365
Thomas Graf58050fc2012-06-28 03:57:45 +000010366 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010367 if (!msg)
10368 return;
10369
10370 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10371 if (!hdr) {
10372 nlmsg_free(msg);
10373 return;
10374 }
10375
David S. Miller9360ffd2012-03-29 04:41:26 -040010376 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010377 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010378 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10379 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010380
10381 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10382 if (!pinfoattr)
10383 goto nla_put_failure;
10384
David S. Miller9360ffd2012-03-29 04:41:26 -040010385 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10386 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010387
10388 nla_nest_end(msg, pinfoattr);
10389
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010390 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010391
10392 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10393 nl80211_mlme_mcgrp.id, gfp);
10394 return;
10395
10396 nla_put_failure:
10397 genlmsg_cancel(msg, hdr);
10398 nlmsg_free(msg);
10399}
Johannes Berg947add32013-02-22 22:05:20 +010010400EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010401
Johannes Berg7f6cf312011-11-04 11:18:15 +010010402void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10403 u64 cookie, bool acked, gfp_t gfp)
10404{
10405 struct wireless_dev *wdev = dev->ieee80211_ptr;
10406 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10407 struct sk_buff *msg;
10408 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010409
Beni Lev4ee3e062012-08-27 12:49:39 +030010410 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10411
Thomas Graf58050fc2012-06-28 03:57:45 +000010412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010413
Johannes Berg7f6cf312011-11-04 11:18:15 +010010414 if (!msg)
10415 return;
10416
10417 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10418 if (!hdr) {
10419 nlmsg_free(msg);
10420 return;
10421 }
10422
David S. Miller9360ffd2012-03-29 04:41:26 -040010423 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10424 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10425 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10426 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10427 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10428 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010429
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010430 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010431
10432 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10433 nl80211_mlme_mcgrp.id, gfp);
10434 return;
10435
10436 nla_put_failure:
10437 genlmsg_cancel(msg, hdr);
10438 nlmsg_free(msg);
10439}
10440EXPORT_SYMBOL(cfg80211_probe_status);
10441
Johannes Berg5e7602302011-11-04 11:18:17 +010010442void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10443 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010444 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010445{
10446 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10447 struct sk_buff *msg;
10448 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010449 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010450
Beni Lev4ee3e062012-08-27 12:49:39 +030010451 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10452
Ben Greear37c73b52012-10-26 14:49:25 -070010453 spin_lock_bh(&rdev->beacon_registrations_lock);
10454 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10455 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10456 if (!msg) {
10457 spin_unlock_bh(&rdev->beacon_registrations_lock);
10458 return;
10459 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010460
Ben Greear37c73b52012-10-26 14:49:25 -070010461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10462 if (!hdr)
10463 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010464
Ben Greear37c73b52012-10-26 14:49:25 -070010465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10466 (freq &&
10467 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10468 (sig_dbm &&
10469 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10470 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10471 goto nla_put_failure;
10472
10473 genlmsg_end(msg, hdr);
10474
10475 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010476 }
Ben Greear37c73b52012-10-26 14:49:25 -070010477 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010478 return;
10479
10480 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010481 spin_unlock_bh(&rdev->beacon_registrations_lock);
10482 if (hdr)
10483 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010484 nlmsg_free(msg);
10485}
10486EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10487
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010488#ifdef CONFIG_PM
10489void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10490 struct cfg80211_wowlan_wakeup *wakeup,
10491 gfp_t gfp)
10492{
10493 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10494 struct sk_buff *msg;
10495 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010496 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010497
10498 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10499
10500 if (wakeup)
10501 size += wakeup->packet_present_len;
10502
10503 msg = nlmsg_new(size, gfp);
10504 if (!msg)
10505 return;
10506
10507 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10508 if (!hdr)
10509 goto free_msg;
10510
10511 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10512 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10513 goto free_msg;
10514
10515 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10516 wdev->netdev->ifindex))
10517 goto free_msg;
10518
10519 if (wakeup) {
10520 struct nlattr *reasons;
10521
10522 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10523
10524 if (wakeup->disconnect &&
10525 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10526 goto free_msg;
10527 if (wakeup->magic_pkt &&
10528 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10529 goto free_msg;
10530 if (wakeup->gtk_rekey_failure &&
10531 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10532 goto free_msg;
10533 if (wakeup->eap_identity_req &&
10534 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10535 goto free_msg;
10536 if (wakeup->four_way_handshake &&
10537 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10538 goto free_msg;
10539 if (wakeup->rfkill_release &&
10540 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10541 goto free_msg;
10542
10543 if (wakeup->pattern_idx >= 0 &&
10544 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10545 wakeup->pattern_idx))
10546 goto free_msg;
10547
Johannes Berg2a0e0472013-01-23 22:57:40 +010010548 if (wakeup->tcp_match)
10549 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10550
10551 if (wakeup->tcp_connlost)
10552 nla_put_flag(msg,
10553 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10554
10555 if (wakeup->tcp_nomoretokens)
10556 nla_put_flag(msg,
10557 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10558
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010559 if (wakeup->packet) {
10560 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10561 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10562
10563 if (!wakeup->packet_80211) {
10564 pkt_attr =
10565 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10566 len_attr =
10567 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10568 }
10569
10570 if (wakeup->packet_len &&
10571 nla_put_u32(msg, len_attr, wakeup->packet_len))
10572 goto free_msg;
10573
10574 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10575 wakeup->packet))
10576 goto free_msg;
10577 }
10578
10579 nla_nest_end(msg, reasons);
10580 }
10581
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010582 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010583
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;
Jouni Malinen3475b092012-11-16 22:49:57 +020010602
10603 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10604 reason_code);
10605
10606 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10607 if (!msg)
10608 return;
10609
10610 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10611 if (!hdr) {
10612 nlmsg_free(msg);
10613 return;
10614 }
10615
10616 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10617 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10618 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10620 (reason_code > 0 &&
10621 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10622 goto nla_put_failure;
10623
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010624 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010625
10626 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10627 nl80211_mlme_mcgrp.id, gfp);
10628 return;
10629
10630 nla_put_failure:
10631 genlmsg_cancel(msg, hdr);
10632 nlmsg_free(msg);
10633}
10634EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10635
Jouni Malinen026331c2010-02-15 12:53:10 +020010636static int nl80211_netlink_notify(struct notifier_block * nb,
10637 unsigned long state,
10638 void *_notify)
10639{
10640 struct netlink_notify *notify = _notify;
10641 struct cfg80211_registered_device *rdev;
10642 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010643 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010644
10645 if (state != NETLINK_URELEASE)
10646 return NOTIFY_DONE;
10647
10648 rcu_read_lock();
10649
Johannes Berg5e7602302011-11-04 11:18:17 +010010650 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010651 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010652 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010653
10654 spin_lock_bh(&rdev->beacon_registrations_lock);
10655 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10656 list) {
10657 if (reg->nlportid == notify->portid) {
10658 list_del(&reg->list);
10659 kfree(reg);
10660 break;
10661 }
10662 }
10663 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010664 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010665
10666 rcu_read_unlock();
10667
10668 return NOTIFY_DONE;
10669}
10670
10671static struct notifier_block nl80211_netlink_notifier = {
10672 .notifier_call = nl80211_netlink_notify,
10673};
10674
Jouni Malinen355199e2013-02-27 17:14:27 +020010675void cfg80211_ft_event(struct net_device *netdev,
10676 struct cfg80211_ft_event_params *ft_event)
10677{
10678 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10679 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10680 struct sk_buff *msg;
10681 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010682
10683 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10684
10685 if (!ft_event->target_ap)
10686 return;
10687
10688 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10689 if (!msg)
10690 return;
10691
10692 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10693 if (!hdr) {
10694 nlmsg_free(msg);
10695 return;
10696 }
10697
10698 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10699 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10700 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10701 if (ft_event->ies)
10702 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10703 if (ft_event->ric_ies)
10704 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10705 ft_event->ric_ies);
10706
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010707 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010708
10709 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10710 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10711}
10712EXPORT_SYMBOL(cfg80211_ft_event);
10713
Arend van Spriel5de17982013-04-18 15:49:00 +020010714void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10715{
10716 struct cfg80211_registered_device *rdev;
10717 struct sk_buff *msg;
10718 void *hdr;
10719 u32 nlportid;
10720
10721 rdev = wiphy_to_dev(wdev->wiphy);
10722 if (!rdev->crit_proto_nlportid)
10723 return;
10724
10725 nlportid = rdev->crit_proto_nlportid;
10726 rdev->crit_proto_nlportid = 0;
10727
10728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10729 if (!msg)
10730 return;
10731
10732 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10733 if (!hdr)
10734 goto nla_put_failure;
10735
10736 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10737 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10738 goto nla_put_failure;
10739
10740 genlmsg_end(msg, hdr);
10741
10742 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10743 return;
10744
10745 nla_put_failure:
10746 if (hdr)
10747 genlmsg_cancel(msg, hdr);
10748 nlmsg_free(msg);
10749
10750}
10751EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10752
Johannes Berg55682962007-09-20 13:09:35 -040010753/* initialisation/exit functions */
10754
10755int nl80211_init(void)
10756{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010757 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010758
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010759 err = genl_register_family_with_ops(&nl80211_fam,
10760 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010761 if (err)
10762 return err;
10763
Johannes Berg55682962007-09-20 13:09:35 -040010764 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10765 if (err)
10766 goto err_out;
10767
Johannes Berg2a519312009-02-10 21:25:55 +010010768 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10769 if (err)
10770 goto err_out;
10771
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010772 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10773 if (err)
10774 goto err_out;
10775
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010776 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10777 if (err)
10778 goto err_out;
10779
Johannes Bergaff89a92009-07-01 21:26:51 +020010780#ifdef CONFIG_NL80211_TESTMODE
10781 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10782 if (err)
10783 goto err_out;
10784#endif
10785
Jouni Malinen026331c2010-02-15 12:53:10 +020010786 err = netlink_register_notifier(&nl80211_netlink_notifier);
10787 if (err)
10788 goto err_out;
10789
Johannes Berg55682962007-09-20 13:09:35 -040010790 return 0;
10791 err_out:
10792 genl_unregister_family(&nl80211_fam);
10793 return err;
10794}
10795
10796void nl80211_exit(void)
10797{
Jouni Malinen026331c2010-02-15 12:53:10 +020010798 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010799 genl_unregister_family(&nl80211_fam);
10800}