blob: bdcf256e3628abfc3848cd8f17625672eed1c741 [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 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200352 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
353 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
354 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
355 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
356 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530357 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
358 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200359 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100360 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400361};
362
Johannes Berge31b8212010-10-05 19:39:30 +0200363/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000364static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200365 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200366 [NL80211_KEY_IDX] = { .type = NLA_U8 },
367 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200368 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200369 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200371 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100372 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
373};
374
375/* policy for the key default flags */
376static const struct nla_policy
377nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
378 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
379 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200380};
381
Johannes Bergff1b6e62011-05-04 15:37:28 +0200382/* policy for WoWLAN attributes */
383static const struct nla_policy
384nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
385 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200389 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
390 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
391 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
392 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100393 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
394};
395
396static const struct nla_policy
397nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
398 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
399 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
400 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
401 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
402 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
403 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
404 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
405 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
406 },
407 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
408 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
409 },
410 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
411 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
412 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200413};
414
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700415/* policy for coalesce rule attributes */
416static const struct nla_policy
417nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
418 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
419 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
420 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
421};
422
Johannes Berge5497d72011-07-05 16:35:40 +0200423/* policy for GTK rekey offload attributes */
424static const struct nla_policy
425nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
426 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
427 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
428 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
429};
430
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300431static const struct nla_policy
432nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200433 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300434 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700435 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300436};
437
Johannes Berg97990a02013-04-19 01:02:55 +0200438static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
439 struct netlink_callback *cb,
440 struct cfg80211_registered_device **rdev,
441 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100442{
Johannes Berg67748892010-10-04 21:14:06 +0200443 int err;
444
Johannes Berg67748892010-10-04 21:14:06 +0200445 rtnl_lock();
446
Johannes Berg97990a02013-04-19 01:02:55 +0200447 if (!cb->args[0]) {
448 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
449 nl80211_fam.attrbuf, nl80211_fam.maxattr,
450 nl80211_policy);
451 if (err)
452 goto out_unlock;
453
454 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
455 nl80211_fam.attrbuf);
456 if (IS_ERR(*wdev)) {
457 err = PTR_ERR(*wdev);
458 goto out_unlock;
459 }
460 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200461 /* 0 is the first index - add 1 to parse only once */
462 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200463 cb->args[1] = (*wdev)->identifier;
464 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200465 /* subtract the 1 again here */
466 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200467 struct wireless_dev *tmp;
468
469 if (!wiphy) {
470 err = -ENODEV;
471 goto out_unlock;
472 }
473 *rdev = wiphy_to_dev(wiphy);
474 *wdev = NULL;
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
477 if (tmp->identifier == cb->args[1]) {
478 *wdev = tmp;
479 break;
480 }
481 }
Johannes Berg97990a02013-04-19 01:02:55 +0200482
483 if (!*wdev) {
484 err = -ENODEV;
485 goto out_unlock;
486 }
Johannes Berg67748892010-10-04 21:14:06 +0200487 }
488
Johannes Berg67748892010-10-04 21:14:06 +0200489 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200490 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200491 rtnl_unlock();
492 return err;
493}
494
Johannes Berg97990a02013-04-19 01:02:55 +0200495static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200496{
Johannes Berg67748892010-10-04 21:14:06 +0200497 rtnl_unlock();
498}
499
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100500/* IE validation */
501static bool is_valid_ie_attr(const struct nlattr *attr)
502{
503 const u8 *pos;
504 int len;
505
506 if (!attr)
507 return true;
508
509 pos = nla_data(attr);
510 len = nla_len(attr);
511
512 while (len) {
513 u8 elemlen;
514
515 if (len < 2)
516 return false;
517 len -= 2;
518
519 elemlen = pos[1];
520 if (elemlen > len)
521 return false;
522
523 len -= elemlen;
524 pos += 2 + elemlen;
525 }
526
527 return true;
528}
529
Johannes Berg55682962007-09-20 13:09:35 -0400530/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000531static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400532 int flags, u8 cmd)
533{
534 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000535 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400536}
537
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400538static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100539 struct ieee80211_channel *chan,
540 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400541{
David S. Miller9360ffd2012-03-29 04:41:26 -0400542 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
543 chan->center_freq))
544 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400545
David S. Miller9360ffd2012-03-29 04:41:26 -0400546 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
547 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
548 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200549 if (chan->flags & IEEE80211_CHAN_NO_IR) {
550 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
551 goto nla_put_failure;
552 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
553 goto nla_put_failure;
554 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100555 if (chan->flags & IEEE80211_CHAN_RADAR) {
556 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
557 goto nla_put_failure;
558 if (large) {
559 u32 time;
560
561 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
562
563 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
564 chan->dfs_state))
565 goto nla_put_failure;
566 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
567 time))
568 goto nla_put_failure;
569 }
570 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100572 if (large) {
573 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
574 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
575 goto nla_put_failure;
576 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
577 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
578 goto nla_put_failure;
579 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
580 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
581 goto nla_put_failure;
582 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
583 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
584 goto nla_put_failure;
585 }
586
David S. Miller9360ffd2012-03-29 04:41:26 -0400587 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
588 DBM_TO_MBM(chan->max_power)))
589 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400590
591 return 0;
592
593 nla_put_failure:
594 return -ENOBUFS;
595}
596
Johannes Berg55682962007-09-20 13:09:35 -0400597/* netlink command implementations */
598
Johannes Bergb9454e82009-07-08 13:29:08 +0200599struct key_parse {
600 struct key_params p;
601 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200602 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200603 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100604 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200605};
606
607static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
608{
609 struct nlattr *tb[NL80211_KEY_MAX + 1];
610 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
611 nl80211_key_policy);
612 if (err)
613 return err;
614
615 k->def = !!tb[NL80211_KEY_DEFAULT];
616 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
617
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100618 if (k->def) {
619 k->def_uni = true;
620 k->def_multi = true;
621 }
622 if (k->defmgmt)
623 k->def_multi = true;
624
Johannes Bergb9454e82009-07-08 13:29:08 +0200625 if (tb[NL80211_KEY_IDX])
626 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
627
628 if (tb[NL80211_KEY_DATA]) {
629 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
630 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
631 }
632
633 if (tb[NL80211_KEY_SEQ]) {
634 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
635 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
636 }
637
638 if (tb[NL80211_KEY_CIPHER])
639 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
640
Johannes Berge31b8212010-10-05 19:39:30 +0200641 if (tb[NL80211_KEY_TYPE]) {
642 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
643 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
644 return -EINVAL;
645 }
646
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100647 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
648 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100649 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
650 tb[NL80211_KEY_DEFAULT_TYPES],
651 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100652 if (err)
653 return err;
654
655 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
656 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
657 }
658
Johannes Bergb9454e82009-07-08 13:29:08 +0200659 return 0;
660}
661
662static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
663{
664 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
665 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
666 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
667 }
668
669 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
670 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
671 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
672 }
673
674 if (info->attrs[NL80211_ATTR_KEY_IDX])
675 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
676
677 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
678 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
679
680 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
681 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
682
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100683 if (k->def) {
684 k->def_uni = true;
685 k->def_multi = true;
686 }
687 if (k->defmgmt)
688 k->def_multi = true;
689
Johannes Berge31b8212010-10-05 19:39:30 +0200690 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
691 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
692 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
693 return -EINVAL;
694 }
695
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100696 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
697 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
698 int err = nla_parse_nested(
699 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
700 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
701 nl80211_key_default_policy);
702 if (err)
703 return err;
704
705 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
706 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
707 }
708
Johannes Bergb9454e82009-07-08 13:29:08 +0200709 return 0;
710}
711
712static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
713{
714 int err;
715
716 memset(k, 0, sizeof(*k));
717 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200718 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200719
720 if (info->attrs[NL80211_ATTR_KEY])
721 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
722 else
723 err = nl80211_parse_key_old(info, k);
724
725 if (err)
726 return err;
727
728 if (k->def && k->defmgmt)
729 return -EINVAL;
730
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100731 if (k->defmgmt) {
732 if (k->def_uni || !k->def_multi)
733 return -EINVAL;
734 }
735
Johannes Bergb9454e82009-07-08 13:29:08 +0200736 if (k->idx != -1) {
737 if (k->defmgmt) {
738 if (k->idx < 4 || k->idx > 5)
739 return -EINVAL;
740 } else if (k->def) {
741 if (k->idx < 0 || k->idx > 3)
742 return -EINVAL;
743 } else {
744 if (k->idx < 0 || k->idx > 5)
745 return -EINVAL;
746 }
747 }
748
749 return 0;
750}
751
Johannes Bergfffd0932009-07-08 14:22:54 +0200752static struct cfg80211_cached_keys *
753nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530754 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200755{
756 struct key_parse parse;
757 struct nlattr *key;
758 struct cfg80211_cached_keys *result;
759 int rem, err, def = 0;
760
761 result = kzalloc(sizeof(*result), GFP_KERNEL);
762 if (!result)
763 return ERR_PTR(-ENOMEM);
764
765 result->def = -1;
766 result->defmgmt = -1;
767
768 nla_for_each_nested(key, keys, rem) {
769 memset(&parse, 0, sizeof(parse));
770 parse.idx = -1;
771
772 err = nl80211_parse_key_new(key, &parse);
773 if (err)
774 goto error;
775 err = -EINVAL;
776 if (!parse.p.key)
777 goto error;
778 if (parse.idx < 0 || parse.idx > 4)
779 goto error;
780 if (parse.def) {
781 if (def)
782 goto error;
783 def = 1;
784 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100785 if (!parse.def_uni || !parse.def_multi)
786 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200787 } else if (parse.defmgmt)
788 goto error;
789 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200790 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200791 if (err)
792 goto error;
793 result->params[parse.idx].cipher = parse.p.cipher;
794 result->params[parse.idx].key_len = parse.p.key_len;
795 result->params[parse.idx].key = result->data[parse.idx];
796 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530797
798 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
799 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
800 if (no_ht)
801 *no_ht = true;
802 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200803 }
804
805 return result;
806 error:
807 kfree(result);
808 return ERR_PTR(err);
809}
810
811static int nl80211_key_allowed(struct wireless_dev *wdev)
812{
813 ASSERT_WDEV_LOCK(wdev);
814
Johannes Bergfffd0932009-07-08 14:22:54 +0200815 switch (wdev->iftype) {
816 case NL80211_IFTYPE_AP:
817 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200818 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700819 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200820 break;
821 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200822 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200823 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200824 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200825 return -ENOLINK;
826 break;
827 default:
828 return -EINVAL;
829 }
830
831 return 0;
832}
833
Johannes Berg7527a782011-05-13 10:58:57 +0200834static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
835{
836 struct nlattr *nl_modes = nla_nest_start(msg, attr);
837 int i;
838
839 if (!nl_modes)
840 goto nla_put_failure;
841
842 i = 0;
843 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400844 if ((ifmodes & 1) && nla_put_flag(msg, i))
845 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200846 ifmodes >>= 1;
847 i++;
848 }
849
850 nla_nest_end(msg, nl_modes);
851 return 0;
852
853nla_put_failure:
854 return -ENOBUFS;
855}
856
857static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100858 struct sk_buff *msg,
859 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200860{
861 struct nlattr *nl_combis;
862 int i, j;
863
864 nl_combis = nla_nest_start(msg,
865 NL80211_ATTR_INTERFACE_COMBINATIONS);
866 if (!nl_combis)
867 goto nla_put_failure;
868
869 for (i = 0; i < wiphy->n_iface_combinations; i++) {
870 const struct ieee80211_iface_combination *c;
871 struct nlattr *nl_combi, *nl_limits;
872
873 c = &wiphy->iface_combinations[i];
874
875 nl_combi = nla_nest_start(msg, i + 1);
876 if (!nl_combi)
877 goto nla_put_failure;
878
879 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
880 if (!nl_limits)
881 goto nla_put_failure;
882
883 for (j = 0; j < c->n_limits; j++) {
884 struct nlattr *nl_limit;
885
886 nl_limit = nla_nest_start(msg, j + 1);
887 if (!nl_limit)
888 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400889 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
890 c->limits[j].max))
891 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200892 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
893 c->limits[j].types))
894 goto nla_put_failure;
895 nla_nest_end(msg, nl_limit);
896 }
897
898 nla_nest_end(msg, nl_limits);
899
David S. Miller9360ffd2012-03-29 04:41:26 -0400900 if (c->beacon_int_infra_match &&
901 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
902 goto nla_put_failure;
903 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
904 c->num_different_channels) ||
905 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
906 c->max_interfaces))
907 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100908 if (large &&
909 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
910 c->radar_detect_widths))
911 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200912
913 nla_nest_end(msg, nl_combi);
914 }
915
916 nla_nest_end(msg, nl_combis);
917
918 return 0;
919nla_put_failure:
920 return -ENOBUFS;
921}
922
Johannes Berg3713b4e2013-02-14 16:19:38 +0100923#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100924static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
925 struct sk_buff *msg)
926{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200927 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100928 struct nlattr *nl_tcp;
929
930 if (!tcp)
931 return 0;
932
933 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
934 if (!nl_tcp)
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
938 tcp->data_payload_max))
939 return -ENOBUFS;
940
941 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
942 tcp->data_payload_max))
943 return -ENOBUFS;
944
945 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
946 return -ENOBUFS;
947
948 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
949 sizeof(*tcp->tok), tcp->tok))
950 return -ENOBUFS;
951
952 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
953 tcp->data_interval_max))
954 return -ENOBUFS;
955
956 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
957 tcp->wake_payload_max))
958 return -ENOBUFS;
959
960 nla_nest_end(msg, nl_tcp);
961 return 0;
962}
963
Johannes Berg3713b4e2013-02-14 16:19:38 +0100964static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100965 struct cfg80211_registered_device *dev,
966 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967{
968 struct nlattr *nl_wowlan;
969
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 return 0;
972
973 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
974 if (!nl_wowlan)
975 return -ENOBUFS;
976
Johannes Berg964dc9e2013-06-03 17:25:34 +0200977 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200979 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100980 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200981 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200983 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100984 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200985 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100986 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200987 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100988 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200989 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200991 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
993 return -ENOBUFS;
994
Johannes Berg964dc9e2013-06-03 17:25:34 +0200995 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700996 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200997 .max_patterns = dev->wiphy.wowlan->n_patterns,
998 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
999 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1000 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001001 };
1002
1003 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1004 sizeof(pat), &pat))
1005 return -ENOBUFS;
1006 }
1007
Johannes Bergb56cf722013-02-20 01:02:38 +01001008 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1009 return -ENOBUFS;
1010
Johannes Berg3713b4e2013-02-14 16:19:38 +01001011 nla_nest_end(msg, nl_wowlan);
1012
1013 return 0;
1014}
1015#endif
1016
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001017static int nl80211_send_coalesce(struct sk_buff *msg,
1018 struct cfg80211_registered_device *dev)
1019{
1020 struct nl80211_coalesce_rule_support rule;
1021
1022 if (!dev->wiphy.coalesce)
1023 return 0;
1024
1025 rule.max_rules = dev->wiphy.coalesce->n_rules;
1026 rule.max_delay = dev->wiphy.coalesce->max_delay;
1027 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1028 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1029 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1030 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1031
1032 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1033 return -ENOBUFS;
1034
1035 return 0;
1036}
1037
Johannes Berg3713b4e2013-02-14 16:19:38 +01001038static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1039 struct ieee80211_supported_band *sband)
1040{
1041 struct nlattr *nl_rates, *nl_rate;
1042 struct ieee80211_rate *rate;
1043 int i;
1044
1045 /* add HT info */
1046 if (sband->ht_cap.ht_supported &&
1047 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1048 sizeof(sband->ht_cap.mcs),
1049 &sband->ht_cap.mcs) ||
1050 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1051 sband->ht_cap.cap) ||
1052 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1053 sband->ht_cap.ampdu_factor) ||
1054 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1055 sband->ht_cap.ampdu_density)))
1056 return -ENOBUFS;
1057
1058 /* add VHT info */
1059 if (sband->vht_cap.vht_supported &&
1060 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1061 sizeof(sband->vht_cap.vht_mcs),
1062 &sband->vht_cap.vht_mcs) ||
1063 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1064 sband->vht_cap.cap)))
1065 return -ENOBUFS;
1066
1067 /* add bitrates */
1068 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1069 if (!nl_rates)
1070 return -ENOBUFS;
1071
1072 for (i = 0; i < sband->n_bitrates; i++) {
1073 nl_rate = nla_nest_start(msg, i);
1074 if (!nl_rate)
1075 return -ENOBUFS;
1076
1077 rate = &sband->bitrates[i];
1078 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1079 rate->bitrate))
1080 return -ENOBUFS;
1081 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1082 nla_put_flag(msg,
1083 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1084 return -ENOBUFS;
1085
1086 nla_nest_end(msg, nl_rate);
1087 }
1088
1089 nla_nest_end(msg, nl_rates);
1090
1091 return 0;
1092}
1093
1094static int
1095nl80211_send_mgmt_stypes(struct sk_buff *msg,
1096 const struct ieee80211_txrx_stypes *mgmt_stypes)
1097{
1098 u16 stypes;
1099 struct nlattr *nl_ftypes, *nl_ifs;
1100 enum nl80211_iftype ift;
1101 int i;
1102
1103 if (!mgmt_stypes)
1104 return 0;
1105
1106 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1107 if (!nl_ifs)
1108 return -ENOBUFS;
1109
1110 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1111 nl_ftypes = nla_nest_start(msg, ift);
1112 if (!nl_ftypes)
1113 return -ENOBUFS;
1114 i = 0;
1115 stypes = mgmt_stypes[ift].tx;
1116 while (stypes) {
1117 if ((stypes & 1) &&
1118 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1119 (i << 4) | IEEE80211_FTYPE_MGMT))
1120 return -ENOBUFS;
1121 stypes >>= 1;
1122 i++;
1123 }
1124 nla_nest_end(msg, nl_ftypes);
1125 }
1126
1127 nla_nest_end(msg, nl_ifs);
1128
1129 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1130 if (!nl_ifs)
1131 return -ENOBUFS;
1132
1133 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1134 nl_ftypes = nla_nest_start(msg, ift);
1135 if (!nl_ftypes)
1136 return -ENOBUFS;
1137 i = 0;
1138 stypes = mgmt_stypes[ift].rx;
1139 while (stypes) {
1140 if ((stypes & 1) &&
1141 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1142 (i << 4) | IEEE80211_FTYPE_MGMT))
1143 return -ENOBUFS;
1144 stypes >>= 1;
1145 i++;
1146 }
1147 nla_nest_end(msg, nl_ftypes);
1148 }
1149 nla_nest_end(msg, nl_ifs);
1150
1151 return 0;
1152}
1153
Johannes Berg86e8cf92013-06-19 10:57:22 +02001154struct nl80211_dump_wiphy_state {
1155 s64 filter_wiphy;
1156 long start;
1157 long split_start, band_start, chan_start;
1158 bool split;
1159};
1160
Johannes Berg3713b4e2013-02-14 16:19:38 +01001161static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1162 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001163 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001164{
1165 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001166 struct nlattr *nl_bands, *nl_band;
1167 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001168 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001169 enum ieee80211_band band;
1170 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001171 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001172 const struct ieee80211_txrx_stypes *mgmt_stypes =
1173 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001174 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001175
Eric W. Biederman15e47302012-09-07 20:12:54 +00001176 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001177 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001178 return -ENOBUFS;
1179
Johannes Berg86e8cf92013-06-19 10:57:22 +02001180 if (WARN_ON(!state))
1181 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001182
David S. Miller9360ffd2012-03-29 04:41:26 -04001183 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001184 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1185 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001186 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001187 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001188 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001189
Johannes Berg86e8cf92013-06-19 10:57:22 +02001190 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001191 case 0:
1192 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1193 dev->wiphy.retry_short) ||
1194 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1195 dev->wiphy.retry_long) ||
1196 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1197 dev->wiphy.frag_threshold) ||
1198 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1199 dev->wiphy.rts_threshold) ||
1200 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1201 dev->wiphy.coverage_class) ||
1202 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1203 dev->wiphy.max_scan_ssids) ||
1204 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1205 dev->wiphy.max_sched_scan_ssids) ||
1206 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1207 dev->wiphy.max_scan_ie_len) ||
1208 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1209 dev->wiphy.max_sched_scan_ie_len) ||
1210 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1211 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001212 goto nla_put_failure;
1213
Johannes Berg3713b4e2013-02-14 16:19:38 +01001214 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1215 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1216 goto nla_put_failure;
1217 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1218 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1219 goto nla_put_failure;
1220 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1221 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1222 goto nla_put_failure;
1223 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1224 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1225 goto nla_put_failure;
1226 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1227 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1228 goto nla_put_failure;
1229 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1230 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001231 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001232 state->split_start++;
1233 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 break;
1235 case 1:
1236 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1237 sizeof(u32) * dev->wiphy.n_cipher_suites,
1238 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001239 goto nla_put_failure;
1240
Johannes Berg3713b4e2013-02-14 16:19:38 +01001241 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1242 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001243 goto nla_put_failure;
1244
Johannes Berg3713b4e2013-02-14 16:19:38 +01001245 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1246 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1247 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001248
Johannes Berg3713b4e2013-02-14 16:19:38 +01001249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1250 dev->wiphy.available_antennas_tx) ||
1251 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1252 dev->wiphy.available_antennas_rx))
1253 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001254
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1256 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1257 dev->wiphy.probe_resp_offload))
1258 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001259
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 if ((dev->wiphy.available_antennas_tx ||
1261 dev->wiphy.available_antennas_rx) &&
1262 dev->ops->get_antenna) {
1263 u32 tx_ant = 0, rx_ant = 0;
1264 int res;
1265 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1266 if (!res) {
1267 if (nla_put_u32(msg,
1268 NL80211_ATTR_WIPHY_ANTENNA_TX,
1269 tx_ant) ||
1270 nla_put_u32(msg,
1271 NL80211_ATTR_WIPHY_ANTENNA_RX,
1272 rx_ant))
1273 goto nla_put_failure;
1274 }
Johannes Bergee688b002008-01-24 19:38:39 +01001275 }
1276
Johannes Berg86e8cf92013-06-19 10:57:22 +02001277 state->split_start++;
1278 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 break;
1280 case 2:
1281 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1282 dev->wiphy.interface_modes))
1283 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001284 state->split_start++;
1285 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 break;
1287 case 3:
1288 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1289 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001290 goto nla_put_failure;
1291
Johannes Berg86e8cf92013-06-19 10:57:22 +02001292 for (band = state->band_start;
1293 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 struct ieee80211_supported_band *sband;
1295
1296 sband = dev->wiphy.bands[band];
1297
1298 if (!sband)
1299 continue;
1300
1301 nl_band = nla_nest_start(msg, band);
1302 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001303 goto nla_put_failure;
1304
Johannes Berg86e8cf92013-06-19 10:57:22 +02001305 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 case 0:
1307 if (nl80211_send_band_rateinfo(msg, sband))
1308 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001309 state->chan_start++;
1310 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 break;
1312 default:
1313 /* add frequencies */
1314 nl_freqs = nla_nest_start(
1315 msg, NL80211_BAND_ATTR_FREQS);
1316 if (!nl_freqs)
1317 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001318
Johannes Berg86e8cf92013-06-19 10:57:22 +02001319 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 i < sband->n_channels;
1321 i++) {
1322 nl_freq = nla_nest_start(msg, i);
1323 if (!nl_freq)
1324 goto nla_put_failure;
1325
1326 chan = &sband->channels[i];
1327
Johannes Berg86e8cf92013-06-19 10:57:22 +02001328 if (nl80211_msg_put_channel(
1329 msg, chan,
1330 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001331 goto nla_put_failure;
1332
1333 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001334 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 break;
1336 }
1337 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001338 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001340 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_nest_end(msg, nl_freqs);
1342 }
1343
1344 nla_nest_end(msg, nl_band);
1345
Johannes Berg86e8cf92013-06-19 10:57:22 +02001346 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001349 band--;
1350 break;
1351 }
Johannes Bergee688b002008-01-24 19:38:39 +01001352 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001354
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001359
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001361 if (state->band_start == 0 && state->chan_start == 0)
1362 state->split_start++;
1363 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 break;
1365 case 4:
1366 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1367 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001368 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369
1370 i = 0;
1371#define CMD(op, n) \
1372 do { \
1373 if (dev->ops->op) { \
1374 i++; \
1375 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1376 goto nla_put_failure; \
1377 } \
1378 } while (0)
1379
1380 CMD(add_virtual_intf, NEW_INTERFACE);
1381 CMD(change_virtual_intf, SET_INTERFACE);
1382 CMD(add_key, NEW_KEY);
1383 CMD(start_ap, START_AP);
1384 CMD(add_station, NEW_STATION);
1385 CMD(add_mpath, NEW_MPATH);
1386 CMD(update_mesh_config, SET_MESH_CONFIG);
1387 CMD(change_bss, SET_BSS);
1388 CMD(auth, AUTHENTICATE);
1389 CMD(assoc, ASSOCIATE);
1390 CMD(deauth, DEAUTHENTICATE);
1391 CMD(disassoc, DISASSOCIATE);
1392 CMD(join_ibss, JOIN_IBSS);
1393 CMD(join_mesh, JOIN_MESH);
1394 CMD(set_pmksa, SET_PMKSA);
1395 CMD(del_pmksa, DEL_PMKSA);
1396 CMD(flush_pmksa, FLUSH_PMKSA);
1397 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1398 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1399 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1400 CMD(mgmt_tx, FRAME);
1401 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1402 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1403 i++;
1404 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1405 goto nla_put_failure;
1406 }
1407 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1408 dev->ops->join_mesh) {
1409 i++;
1410 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1411 goto nla_put_failure;
1412 }
1413 CMD(set_wds_peer, SET_WDS_PEER);
1414 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1415 CMD(tdls_mgmt, TDLS_MGMT);
1416 CMD(tdls_oper, TDLS_OPER);
1417 }
1418 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1419 CMD(sched_scan_start, START_SCHED_SCAN);
1420 CMD(probe_client, PROBE_CLIENT);
1421 CMD(set_noack_map, SET_NOACK_MAP);
1422 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1423 i++;
1424 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1425 goto nla_put_failure;
1426 }
1427 CMD(start_p2p_device, START_P2P_DEVICE);
1428 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001430 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1431 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001432 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1433 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001434 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001435
Kalle Valo4745fc02011-11-17 19:06:10 +02001436#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001438#endif
1439
Johannes Berg8fdc6212009-03-14 09:34:01 +01001440#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001441
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 if (dev->ops->connect || dev->ops->auth) {
1443 i++;
1444 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001445 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001446 }
1447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 if (dev->ops->disconnect || dev->ops->deauth) {
1449 i++;
1450 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1451 goto nla_put_failure;
1452 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001453
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 state->split_start++;
1456 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 break;
1458 case 5:
1459 if (dev->ops->remain_on_channel &&
1460 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1461 nla_put_u32(msg,
1462 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1463 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001464 goto nla_put_failure;
1465
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1467 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1468 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001469
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1471 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001472 state->split_start++;
1473 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 break;
1475 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001476#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001477 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001479 state->split_start++;
1480 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 break;
1482#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001483 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484#endif
1485 case 7:
1486 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1487 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001488 goto nla_put_failure;
1489
Johannes Berg86e8cf92013-06-19 10:57:22 +02001490 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1491 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001493
Johannes Berg86e8cf92013-06-19 10:57:22 +02001494 state->split_start++;
1495 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 break;
1497 case 8:
1498 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1499 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1500 dev->wiphy.ap_sme_capa))
1501 goto nla_put_failure;
1502
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001503 features = dev->wiphy.features;
1504 /*
1505 * We can only add the per-channel limit information if the
1506 * dump is split, otherwise it makes it too big. Therefore
1507 * only advertise it in that case.
1508 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001509 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001510 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1511 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 goto nla_put_failure;
1513
1514 if (dev->wiphy.ht_capa_mod_mask &&
1515 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1516 sizeof(*dev->wiphy.ht_capa_mod_mask),
1517 dev->wiphy.ht_capa_mod_mask))
1518 goto nla_put_failure;
1519
1520 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1521 dev->wiphy.max_acl_mac_addrs &&
1522 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1523 dev->wiphy.max_acl_mac_addrs))
1524 goto nla_put_failure;
1525
1526 /*
1527 * Any information below this point is only available to
1528 * applications that can deal with it being split. This
1529 * helps ensure that newly added capabilities don't break
1530 * older tools by overrunning their buffers.
1531 *
1532 * We still increment split_start so that in the split
1533 * case we'll continue with more data in the next round,
1534 * but break unconditionally so unsplit data stops here.
1535 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001536 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001537 break;
1538 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001539 if (dev->wiphy.extended_capabilities &&
1540 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1541 dev->wiphy.extended_capabilities_len,
1542 dev->wiphy.extended_capabilities) ||
1543 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1544 dev->wiphy.extended_capabilities_len,
1545 dev->wiphy.extended_capabilities_mask)))
1546 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547
Johannes Bergee2aca32013-02-21 17:36:01 +01001548 if (dev->wiphy.vht_capa_mod_mask &&
1549 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1550 sizeof(*dev->wiphy.vht_capa_mod_mask),
1551 dev->wiphy.vht_capa_mod_mask))
1552 goto nla_put_failure;
1553
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001554 state->split_start++;
1555 break;
1556 case 10:
1557 if (nl80211_send_coalesce(msg, dev))
1558 goto nla_put_failure;
1559
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001560 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1561 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1562 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1563 goto nla_put_failure;
1564
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001567 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001568 }
Johannes Berg55682962007-09-20 13:09:35 -04001569 return genlmsg_end(msg, hdr);
1570
1571 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001572 genlmsg_cancel(msg, hdr);
1573 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001574}
1575
Johannes Berg86e8cf92013-06-19 10:57:22 +02001576static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1577 struct netlink_callback *cb,
1578 struct nl80211_dump_wiphy_state *state)
1579{
1580 struct nlattr **tb = nl80211_fam.attrbuf;
1581 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1582 tb, nl80211_fam.maxattr, nl80211_policy);
1583 /* ignore parse errors for backward compatibility */
1584 if (ret)
1585 return 0;
1586
1587 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1588 if (tb[NL80211_ATTR_WIPHY])
1589 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1590 if (tb[NL80211_ATTR_WDEV])
1591 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1592 if (tb[NL80211_ATTR_IFINDEX]) {
1593 struct net_device *netdev;
1594 struct cfg80211_registered_device *rdev;
1595 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1596
1597 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1598 if (!netdev)
1599 return -ENODEV;
1600 if (netdev->ieee80211_ptr) {
1601 rdev = wiphy_to_dev(
1602 netdev->ieee80211_ptr->wiphy);
1603 state->filter_wiphy = rdev->wiphy_idx;
1604 }
1605 dev_put(netdev);
1606 }
1607
1608 return 0;
1609}
1610
Johannes Berg55682962007-09-20 13:09:35 -04001611static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1612{
Johannes Berg645e77d2013-03-01 14:03:49 +01001613 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001614 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001615 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001616
Johannes Berg5fe231e2013-05-08 21:45:15 +02001617 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 if (!state) {
1619 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001620 if (!state) {
1621 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001622 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 state->filter_wiphy = -1;
1625 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1626 if (ret) {
1627 kfree(state);
1628 rtnl_unlock();
1629 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001630 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001631 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001632 }
1633
Johannes Berg79c97e92009-07-07 03:56:12 +02001634 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001635 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1636 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001637 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001638 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 if (state->filter_wiphy != -1 &&
1640 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 continue;
1642 /* attempt to fit multiple wiphy data chunks into the skb */
1643 do {
1644 ret = nl80211_send_wiphy(dev, skb,
1645 NETLINK_CB(cb->skb).portid,
1646 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001647 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 if (ret < 0) {
1649 /*
1650 * If sending the wiphy data didn't fit (ENOBUFS
1651 * or EMSGSIZE returned), this SKB is still
1652 * empty (so it's not too big because another
1653 * wiphy dataset is already in the skb) and
1654 * we've not tried to adjust the dump allocation
1655 * yet ... then adjust the alloc size to be
1656 * bigger, and return 1 but with the empty skb.
1657 * This results in an empty message being RX'ed
1658 * in userspace, but that is ignored.
1659 *
1660 * We can then retry with the larger buffer.
1661 */
1662 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1663 !skb->len &&
1664 cb->min_dump_alloc < 4096) {
1665 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001666 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001667 return 1;
1668 }
1669 idx--;
1670 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001671 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001672 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673 break;
Johannes Berg55682962007-09-20 13:09:35 -04001674 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001675 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001676
Johannes Berg86e8cf92013-06-19 10:57:22 +02001677 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001678
1679 return skb->len;
1680}
1681
Johannes Berg86e8cf92013-06-19 10:57:22 +02001682static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1683{
1684 kfree((void *)cb->args[0]);
1685 return 0;
1686}
1687
Johannes Berg55682962007-09-20 13:09:35 -04001688static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1689{
1690 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001691 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001692 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001693
Johannes Berg645e77d2013-03-01 14:03:49 +01001694 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001695 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001696 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001697
Johannes Berg3713b4e2013-02-14 16:19:38 +01001698 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001699 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001700 nlmsg_free(msg);
1701 return -ENOBUFS;
1702 }
Johannes Berg55682962007-09-20 13:09:35 -04001703
Johannes Berg134e6372009-07-10 09:51:34 +00001704 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001705}
1706
Jouni Malinen31888482008-10-30 16:59:24 +02001707static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1708 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1709 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1710 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1711 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1712 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1713};
1714
1715static int parse_txq_params(struct nlattr *tb[],
1716 struct ieee80211_txq_params *txq_params)
1717{
Johannes Berga3304b02012-03-28 11:04:24 +02001718 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001719 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1720 !tb[NL80211_TXQ_ATTR_AIFS])
1721 return -EINVAL;
1722
Johannes Berga3304b02012-03-28 11:04:24 +02001723 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001724 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1725 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1726 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1727 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1728
Johannes Berga3304b02012-03-28 11:04:24 +02001729 if (txq_params->ac >= NL80211_NUM_ACS)
1730 return -EINVAL;
1731
Jouni Malinen31888482008-10-30 16:59:24 +02001732 return 0;
1733}
1734
Johannes Bergf444de02010-05-05 15:25:02 +02001735static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1736{
1737 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001738 * You can only set the channel explicitly for WDS interfaces,
1739 * all others have their channel managed via their respective
1740 * "establish a connection" command (connect, join, ...)
1741 *
1742 * For AP/GO and mesh mode, the channel can be set with the
1743 * channel userspace API, but is only stored and passed to the
1744 * low-level driver when the AP starts or the mesh is joined.
1745 * This is for backward compatibility, userspace can also give
1746 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001747 *
1748 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001749 * whatever else is going on, so they have their own special
1750 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001751 */
1752 return !wdev ||
1753 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001754 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001755 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1756 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001757}
1758
Johannes Berg683b6d32012-11-08 21:25:48 +01001759static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1760 struct genl_info *info,
1761 struct cfg80211_chan_def *chandef)
1762{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301763 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001764
1765 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1766 return -EINVAL;
1767
1768 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1769
1770 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001771 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1772 chandef->center_freq1 = control_freq;
1773 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001774
1775 /* Primary channel not allowed */
1776 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1777 return -EINVAL;
1778
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001779 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1780 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001781
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001782 chantype = nla_get_u32(
1783 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1784
1785 switch (chantype) {
1786 case NL80211_CHAN_NO_HT:
1787 case NL80211_CHAN_HT20:
1788 case NL80211_CHAN_HT40PLUS:
1789 case NL80211_CHAN_HT40MINUS:
1790 cfg80211_chandef_create(chandef, chandef->chan,
1791 chantype);
1792 break;
1793 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001794 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001795 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001796 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1797 chandef->width =
1798 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1799 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1800 chandef->center_freq1 =
1801 nla_get_u32(
1802 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1803 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1804 chandef->center_freq2 =
1805 nla_get_u32(
1806 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1807 }
1808
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001809 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001810 return -EINVAL;
1811
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001812 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1813 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001814 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001815
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001816 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1817 chandef->width == NL80211_CHAN_WIDTH_10) &&
1818 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1819 return -EINVAL;
1820
Johannes Berg683b6d32012-11-08 21:25:48 +01001821 return 0;
1822}
1823
Johannes Bergf444de02010-05-05 15:25:02 +02001824static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1825 struct wireless_dev *wdev,
1826 struct genl_info *info)
1827{
Johannes Berg683b6d32012-11-08 21:25:48 +01001828 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001829 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001830 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1831
1832 if (wdev)
1833 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001834
Johannes Bergf444de02010-05-05 15:25:02 +02001835 if (!nl80211_can_set_dev_channel(wdev))
1836 return -EOPNOTSUPP;
1837
Johannes Berg683b6d32012-11-08 21:25:48 +01001838 result = nl80211_parse_chandef(rdev, info, &chandef);
1839 if (result)
1840 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001841
Johannes Berge8c9bd52012-06-06 08:18:22 +02001842 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001843 case NL80211_IFTYPE_AP:
1844 case NL80211_IFTYPE_P2P_GO:
1845 if (wdev->beacon_interval) {
1846 result = -EBUSY;
1847 break;
1848 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001849 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001850 result = -EINVAL;
1851 break;
1852 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001853 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001854 result = 0;
1855 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001856 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001857 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001858 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001859 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001860 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001861 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001862 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001863 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001864 }
Johannes Bergf444de02010-05-05 15:25:02 +02001865
1866 return result;
1867}
1868
1869static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1870{
Johannes Berg4c476992010-10-04 21:36:35 +02001871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1872 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001873
Johannes Berg4c476992010-10-04 21:36:35 +02001874 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001875}
1876
Bill Jordane8347eb2010-10-01 13:54:28 -04001877static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1878{
Johannes Berg43b19952010-10-07 13:10:30 +02001879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1880 struct net_device *dev = info->user_ptr[1];
1881 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001882 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001883
1884 if (!info->attrs[NL80211_ATTR_MAC])
1885 return -EINVAL;
1886
Johannes Berg43b19952010-10-07 13:10:30 +02001887 if (netif_running(dev))
1888 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001889
Johannes Berg43b19952010-10-07 13:10:30 +02001890 if (!rdev->ops->set_wds_peer)
1891 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001892
Johannes Berg43b19952010-10-07 13:10:30 +02001893 if (wdev->iftype != NL80211_IFTYPE_WDS)
1894 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001895
1896 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001897 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001898}
1899
1900
Johannes Berg55682962007-09-20 13:09:35 -04001901static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1902{
1903 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001904 struct net_device *netdev = NULL;
1905 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001906 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001907 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001908 u32 changed;
1909 u8 retry_short = 0, retry_long = 0;
1910 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001911 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001912
Johannes Berg5fe231e2013-05-08 21:45:15 +02001913 ASSERT_RTNL();
1914
Johannes Bergf444de02010-05-05 15:25:02 +02001915 /*
1916 * Try to find the wiphy and netdev. Normally this
1917 * function shouldn't need the netdev, but this is
1918 * done for backward compatibility -- previously
1919 * setting the channel was done per wiphy, but now
1920 * it is per netdev. Previous userland like hostapd
1921 * also passed a netdev to set_wiphy, so that it is
1922 * possible to let that go to the right netdev!
1923 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001924
Johannes Bergf444de02010-05-05 15:25:02 +02001925 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1926 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1927
1928 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001929 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001930 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001931 else
Johannes Bergf444de02010-05-05 15:25:02 +02001932 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001933 }
1934
Johannes Bergf444de02010-05-05 15:25:02 +02001935 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001936 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1937 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001938 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001939 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001940 wdev = NULL;
1941 netdev = NULL;
1942 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001943 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001944 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001945
1946 /*
1947 * end workaround code, by now the rdev is available
1948 * and locked, and wdev may or may not be NULL.
1949 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001950
1951 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001952 result = cfg80211_dev_rename(
1953 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001954
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001955 if (result)
1956 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001957
Jouni Malinen31888482008-10-30 16:59:24 +02001958 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1959 struct ieee80211_txq_params txq_params;
1960 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1961
1962 if (!rdev->ops->set_txq_params) {
1963 result = -EOPNOTSUPP;
1964 goto bad_res;
1965 }
1966
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001967 if (!netdev) {
1968 result = -EINVAL;
1969 goto bad_res;
1970 }
1971
Johannes Berg133a3ff2011-11-03 14:50:13 +01001972 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1973 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1974 result = -EINVAL;
1975 goto bad_res;
1976 }
1977
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001978 if (!netif_running(netdev)) {
1979 result = -ENETDOWN;
1980 goto bad_res;
1981 }
1982
Jouni Malinen31888482008-10-30 16:59:24 +02001983 nla_for_each_nested(nl_txq_params,
1984 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1985 rem_txq_params) {
1986 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1987 nla_data(nl_txq_params),
1988 nla_len(nl_txq_params),
1989 txq_params_policy);
1990 result = parse_txq_params(tb, &txq_params);
1991 if (result)
1992 goto bad_res;
1993
Hila Gonene35e4d22012-06-27 17:19:42 +03001994 result = rdev_set_txq_params(rdev, netdev,
1995 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001996 if (result)
1997 goto bad_res;
1998 }
1999 }
2000
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002001 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002002 result = __nl80211_set_channel(rdev,
2003 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2004 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002005 if (result)
2006 goto bad_res;
2007 }
2008
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002009 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002010 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002011 enum nl80211_tx_power_setting type;
2012 int idx, mbm = 0;
2013
Johannes Bergc8442112012-10-24 10:17:18 +02002014 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2015 txp_wdev = NULL;
2016
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002017 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002018 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002019 goto bad_res;
2020 }
2021
2022 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2023 type = nla_get_u32(info->attrs[idx]);
2024
2025 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2026 (type != NL80211_TX_POWER_AUTOMATIC)) {
2027 result = -EINVAL;
2028 goto bad_res;
2029 }
2030
2031 if (type != NL80211_TX_POWER_AUTOMATIC) {
2032 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2033 mbm = nla_get_u32(info->attrs[idx]);
2034 }
2035
Johannes Bergc8442112012-10-24 10:17:18 +02002036 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002037 if (result)
2038 goto bad_res;
2039 }
2040
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002041 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2042 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2043 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002044 if ((!rdev->wiphy.available_antennas_tx &&
2045 !rdev->wiphy.available_antennas_rx) ||
2046 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002047 result = -EOPNOTSUPP;
2048 goto bad_res;
2049 }
2050
2051 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2052 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2053
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002054 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002055 * available antenna masks, except for the "all" mask */
2056 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2057 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002058 result = -EINVAL;
2059 goto bad_res;
2060 }
2061
Bruno Randolf7f531e02010-12-16 11:30:22 +09002062 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2063 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002064
Hila Gonene35e4d22012-06-27 17:19:42 +03002065 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002066 if (result)
2067 goto bad_res;
2068 }
2069
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070 changed = 0;
2071
2072 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2073 retry_short = nla_get_u8(
2074 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2075 if (retry_short == 0) {
2076 result = -EINVAL;
2077 goto bad_res;
2078 }
2079 changed |= WIPHY_PARAM_RETRY_SHORT;
2080 }
2081
2082 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2083 retry_long = nla_get_u8(
2084 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2085 if (retry_long == 0) {
2086 result = -EINVAL;
2087 goto bad_res;
2088 }
2089 changed |= WIPHY_PARAM_RETRY_LONG;
2090 }
2091
2092 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2093 frag_threshold = nla_get_u32(
2094 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2095 if (frag_threshold < 256) {
2096 result = -EINVAL;
2097 goto bad_res;
2098 }
2099 if (frag_threshold != (u32) -1) {
2100 /*
2101 * Fragments (apart from the last one) are required to
2102 * have even length. Make the fragmentation code
2103 * simpler by stripping LSB should someone try to use
2104 * odd threshold value.
2105 */
2106 frag_threshold &= ~0x1;
2107 }
2108 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2109 }
2110
2111 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2112 rts_threshold = nla_get_u32(
2113 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2114 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2115 }
2116
Lukáš Turek81077e82009-12-21 22:50:47 +01002117 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2118 coverage_class = nla_get_u8(
2119 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2120 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2121 }
2122
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002123 if (changed) {
2124 u8 old_retry_short, old_retry_long;
2125 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002126 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002127
2128 if (!rdev->ops->set_wiphy_params) {
2129 result = -EOPNOTSUPP;
2130 goto bad_res;
2131 }
2132
2133 old_retry_short = rdev->wiphy.retry_short;
2134 old_retry_long = rdev->wiphy.retry_long;
2135 old_frag_threshold = rdev->wiphy.frag_threshold;
2136 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002137 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002138
2139 if (changed & WIPHY_PARAM_RETRY_SHORT)
2140 rdev->wiphy.retry_short = retry_short;
2141 if (changed & WIPHY_PARAM_RETRY_LONG)
2142 rdev->wiphy.retry_long = retry_long;
2143 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2144 rdev->wiphy.frag_threshold = frag_threshold;
2145 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2146 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002147 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2148 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002149
Hila Gonene35e4d22012-06-27 17:19:42 +03002150 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002151 if (result) {
2152 rdev->wiphy.retry_short = old_retry_short;
2153 rdev->wiphy.retry_long = old_retry_long;
2154 rdev->wiphy.frag_threshold = old_frag_threshold;
2155 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002156 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002157 }
2158 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002159
Johannes Berg306d6112008-12-08 12:39:04 +01002160 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002161 if (netdev)
2162 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002163 return result;
2164}
2165
Johannes Berg71bbc992012-06-15 15:30:18 +02002166static inline u64 wdev_id(struct wireless_dev *wdev)
2167{
2168 return (u64)wdev->identifier |
2169 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2170}
Johannes Berg55682962007-09-20 13:09:35 -04002171
Johannes Berg683b6d32012-11-08 21:25:48 +01002172static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002173 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002174{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002175 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002176
Johannes Berg683b6d32012-11-08 21:25:48 +01002177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2178 chandef->chan->center_freq))
2179 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002180 switch (chandef->width) {
2181 case NL80211_CHAN_WIDTH_20_NOHT:
2182 case NL80211_CHAN_WIDTH_20:
2183 case NL80211_CHAN_WIDTH_40:
2184 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2185 cfg80211_get_chandef_type(chandef)))
2186 return -ENOBUFS;
2187 break;
2188 default:
2189 break;
2190 }
2191 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2192 return -ENOBUFS;
2193 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2194 return -ENOBUFS;
2195 if (chandef->center_freq2 &&
2196 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002197 return -ENOBUFS;
2198 return 0;
2199}
2200
Eric W. Biederman15e47302012-09-07 20:12:54 +00002201static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002202 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002203 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002204{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002205 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002206 void *hdr;
2207
Eric W. Biederman15e47302012-09-07 20:12:54 +00002208 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002209 if (!hdr)
2210 return -1;
2211
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002212 if (dev &&
2213 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002214 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002215 goto nla_put_failure;
2216
2217 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2218 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002219 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002220 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002221 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2222 rdev->devlist_generation ^
2223 (cfg80211_rdev_list_generation << 2)))
2224 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002225
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002226 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002227 int ret;
2228 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002229
Johannes Berg683b6d32012-11-08 21:25:48 +01002230 ret = rdev_get_channel(rdev, wdev, &chandef);
2231 if (ret == 0) {
2232 if (nl80211_send_chandef(msg, &chandef))
2233 goto nla_put_failure;
2234 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002235 }
2236
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002237 if (wdev->ssid_len) {
2238 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2239 goto nla_put_failure;
2240 }
2241
Johannes Berg55682962007-09-20 13:09:35 -04002242 return genlmsg_end(msg, hdr);
2243
2244 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002245 genlmsg_cancel(msg, hdr);
2246 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002247}
2248
2249static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2250{
2251 int wp_idx = 0;
2252 int if_idx = 0;
2253 int wp_start = cb->args[0];
2254 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002255 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002256 struct wireless_dev *wdev;
2257
Johannes Berg5fe231e2013-05-08 21:45:15 +02002258 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002259 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2260 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002261 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 if (wp_idx < wp_start) {
2263 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002264 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002265 }
Johannes Berg55682962007-09-20 13:09:35 -04002266 if_idx = 0;
2267
Johannes Berg89a54e42012-06-15 14:33:17 +02002268 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 if (if_idx < if_start) {
2270 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002271 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002272 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002273 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002274 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002275 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002276 goto out;
2277 }
2278 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002279 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002280
2281 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002282 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002283 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002284 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002285
2286 cb->args[0] = wp_idx;
2287 cb->args[1] = if_idx;
2288
2289 return skb->len;
2290}
2291
2292static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2293{
2294 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002295 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002296 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002297
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002298 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002299 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002300 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002301
Eric W. Biederman15e47302012-09-07 20:12:54 +00002302 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002303 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002304 nlmsg_free(msg);
2305 return -ENOBUFS;
2306 }
Johannes Berg55682962007-09-20 13:09:35 -04002307
Johannes Berg134e6372009-07-10 09:51:34 +00002308 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002309}
2310
Michael Wu66f7ac52008-01-31 19:48:22 +01002311static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2312 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2313 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2314 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2315 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2316 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002317 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002318};
2319
2320static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2321{
2322 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2323 int flag;
2324
2325 *mntrflags = 0;
2326
2327 if (!nla)
2328 return -EINVAL;
2329
2330 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2331 nla, mntr_flags_policy))
2332 return -EINVAL;
2333
2334 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2335 if (flags[flag])
2336 *mntrflags |= (1<<flag);
2337
2338 return 0;
2339}
2340
Johannes Berg9bc383d2009-11-19 11:55:19 +01002341static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002342 struct net_device *netdev, u8 use_4addr,
2343 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002344{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002345 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002346 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002347 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002348 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002349 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002350
2351 switch (iftype) {
2352 case NL80211_IFTYPE_AP_VLAN:
2353 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2354 return 0;
2355 break;
2356 case NL80211_IFTYPE_STATION:
2357 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2358 return 0;
2359 break;
2360 default:
2361 break;
2362 }
2363
2364 return -EOPNOTSUPP;
2365}
2366
Johannes Berg55682962007-09-20 13:09:35 -04002367static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2368{
Johannes Berg4c476992010-10-04 21:36:35 +02002369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002370 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002371 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002372 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002373 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002374 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002375 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002376
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002377 memset(&params, 0, sizeof(params));
2378
Johannes Berg04a773a2009-04-19 21:24:32 +02002379 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002380
Johannes Berg723b0382008-09-16 20:22:09 +02002381 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002382 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002383 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002384 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002385 if (ntype > NL80211_IFTYPE_MAX)
2386 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002387 }
2388
Johannes Berg92ffe052008-09-16 20:39:36 +02002389 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002390 struct wireless_dev *wdev = dev->ieee80211_ptr;
2391
Johannes Berg4c476992010-10-04 21:36:35 +02002392 if (ntype != NL80211_IFTYPE_MESH_POINT)
2393 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002394 if (netif_running(dev))
2395 return -EBUSY;
2396
2397 wdev_lock(wdev);
2398 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2399 IEEE80211_MAX_MESH_ID_LEN);
2400 wdev->mesh_id_up_len =
2401 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2402 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2403 wdev->mesh_id_up_len);
2404 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002405 }
2406
Felix Fietkau8b787642009-11-10 18:53:10 +01002407 if (info->attrs[NL80211_ATTR_4ADDR]) {
2408 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2409 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002410 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002411 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002412 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002413 } else {
2414 params.use_4addr = -1;
2415 }
2416
Johannes Berg92ffe052008-09-16 20:39:36 +02002417 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002418 if (ntype != NL80211_IFTYPE_MONITOR)
2419 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002420 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2421 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002422 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002423 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002424
2425 flags = &_flags;
2426 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002427 }
Johannes Berg3b858752009-03-12 09:55:09 +01002428
Luciano Coelho18003292013-08-29 13:26:57 +03002429 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002430 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2431 return -EOPNOTSUPP;
2432
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002433 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002434 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002435 else
2436 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002437
Johannes Berg9bc383d2009-11-19 11:55:19 +01002438 if (!err && params.use_4addr != -1)
2439 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2440
Johannes Berg55682962007-09-20 13:09:35 -04002441 return err;
2442}
2443
2444static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2445{
Johannes Berg4c476992010-10-04 21:36:35 +02002446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002447 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002448 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002449 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002450 int err;
2451 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002452 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002453
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002454 memset(&params, 0, sizeof(params));
2455
Johannes Berg55682962007-09-20 13:09:35 -04002456 if (!info->attrs[NL80211_ATTR_IFNAME])
2457 return -EINVAL;
2458
2459 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2460 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2461 if (type > NL80211_IFTYPE_MAX)
2462 return -EINVAL;
2463 }
2464
Johannes Berg79c97e92009-07-07 03:56:12 +02002465 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002466 !(rdev->wiphy.interface_modes & (1 << type)))
2467 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002468
Arend van Spriel1c18f142013-01-08 10:17:27 +01002469 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2470 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2471 ETH_ALEN);
2472 if (!is_valid_ether_addr(params.macaddr))
2473 return -EADDRNOTAVAIL;
2474 }
2475
Johannes Berg9bc383d2009-11-19 11:55:19 +01002476 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002477 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002478 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002479 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002480 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002481 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002482
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2484 if (!msg)
2485 return -ENOMEM;
2486
Michael Wu66f7ac52008-01-31 19:48:22 +01002487 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2488 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2489 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002490
Luciano Coelho18003292013-08-29 13:26:57 +03002491 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002492 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2493 return -EOPNOTSUPP;
2494
Hila Gonene35e4d22012-06-27 17:19:42 +03002495 wdev = rdev_add_virtual_intf(rdev,
2496 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2497 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002498 if (IS_ERR(wdev)) {
2499 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002500 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002501 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002502
Johannes Berg98104fde2012-06-16 00:19:54 +02002503 switch (type) {
2504 case NL80211_IFTYPE_MESH_POINT:
2505 if (!info->attrs[NL80211_ATTR_MESH_ID])
2506 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002507 wdev_lock(wdev);
2508 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2509 IEEE80211_MAX_MESH_ID_LEN);
2510 wdev->mesh_id_up_len =
2511 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2512 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2513 wdev->mesh_id_up_len);
2514 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002515 break;
2516 case NL80211_IFTYPE_P2P_DEVICE:
2517 /*
2518 * P2P Device doesn't have a netdev, so doesn't go
2519 * through the netdev notifier and must be added here
2520 */
2521 mutex_init(&wdev->mtx);
2522 INIT_LIST_HEAD(&wdev->event_list);
2523 spin_lock_init(&wdev->event_lock);
2524 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2525 spin_lock_init(&wdev->mgmt_registrations_lock);
2526
Johannes Berg98104fde2012-06-16 00:19:54 +02002527 wdev->identifier = ++rdev->wdev_id;
2528 list_add_rcu(&wdev->list, &rdev->wdev_list);
2529 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002530 break;
2531 default:
2532 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002533 }
2534
Eric W. Biederman15e47302012-09-07 20:12:54 +00002535 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002536 rdev, wdev) < 0) {
2537 nlmsg_free(msg);
2538 return -ENOBUFS;
2539 }
2540
2541 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002542}
2543
2544static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2545{
Johannes Berg4c476992010-10-04 21:36:35 +02002546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002547 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002548
Johannes Berg4c476992010-10-04 21:36:35 +02002549 if (!rdev->ops->del_virtual_intf)
2550 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002551
Johannes Berg84efbb82012-06-16 00:00:26 +02002552 /*
2553 * If we remove a wireless device without a netdev then clear
2554 * user_ptr[1] so that nl80211_post_doit won't dereference it
2555 * to check if it needs to do dev_put(). Otherwise it crashes
2556 * since the wdev has been freed, unlike with a netdev where
2557 * we need the dev_put() for the netdev to really be freed.
2558 */
2559 if (!wdev->netdev)
2560 info->user_ptr[1] = NULL;
2561
Hila Gonene35e4d22012-06-27 17:19:42 +03002562 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002563}
2564
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002565static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2566{
2567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2568 struct net_device *dev = info->user_ptr[1];
2569 u16 noack_map;
2570
2571 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2572 return -EINVAL;
2573
2574 if (!rdev->ops->set_noack_map)
2575 return -EOPNOTSUPP;
2576
2577 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2578
Hila Gonene35e4d22012-06-27 17:19:42 +03002579 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002580}
2581
Johannes Berg41ade002007-12-19 02:03:29 +01002582struct get_key_cookie {
2583 struct sk_buff *msg;
2584 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002585 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002586};
2587
2588static void get_key_callback(void *c, struct key_params *params)
2589{
Johannes Bergb9454e82009-07-08 13:29:08 +02002590 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002591 struct get_key_cookie *cookie = c;
2592
David S. Miller9360ffd2012-03-29 04:41:26 -04002593 if ((params->key &&
2594 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2595 params->key_len, params->key)) ||
2596 (params->seq &&
2597 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2598 params->seq_len, params->seq)) ||
2599 (params->cipher &&
2600 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2601 params->cipher)))
2602 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002603
Johannes Bergb9454e82009-07-08 13:29:08 +02002604 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2605 if (!key)
2606 goto nla_put_failure;
2607
David S. Miller9360ffd2012-03-29 04:41:26 -04002608 if ((params->key &&
2609 nla_put(cookie->msg, NL80211_KEY_DATA,
2610 params->key_len, params->key)) ||
2611 (params->seq &&
2612 nla_put(cookie->msg, NL80211_KEY_SEQ,
2613 params->seq_len, params->seq)) ||
2614 (params->cipher &&
2615 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2616 params->cipher)))
2617 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002618
David S. Miller9360ffd2012-03-29 04:41:26 -04002619 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2620 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002621
2622 nla_nest_end(cookie->msg, key);
2623
Johannes Berg41ade002007-12-19 02:03:29 +01002624 return;
2625 nla_put_failure:
2626 cookie->error = 1;
2627}
2628
2629static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2630{
Johannes Berg4c476992010-10-04 21:36:35 +02002631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002632 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002633 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002634 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002635 const u8 *mac_addr = NULL;
2636 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002637 struct get_key_cookie cookie = {
2638 .error = 0,
2639 };
2640 void *hdr;
2641 struct sk_buff *msg;
2642
2643 if (info->attrs[NL80211_ATTR_KEY_IDX])
2644 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2645
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002646 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002647 return -EINVAL;
2648
2649 if (info->attrs[NL80211_ATTR_MAC])
2650 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2651
Johannes Berge31b8212010-10-05 19:39:30 +02002652 pairwise = !!mac_addr;
2653 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2654 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2655 if (kt >= NUM_NL80211_KEYTYPES)
2656 return -EINVAL;
2657 if (kt != NL80211_KEYTYPE_GROUP &&
2658 kt != NL80211_KEYTYPE_PAIRWISE)
2659 return -EINVAL;
2660 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2661 }
2662
Johannes Berg4c476992010-10-04 21:36:35 +02002663 if (!rdev->ops->get_key)
2664 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002665
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002667 if (!msg)
2668 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002669
Eric W. Biederman15e47302012-09-07 20:12:54 +00002670 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002671 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002672 if (!hdr)
2673 return -ENOBUFS;
Johannes Berg41ade002007-12-19 02:03:29 +01002674
2675 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002676 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002677
David S. Miller9360ffd2012-03-29 04:41:26 -04002678 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2679 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2680 goto nla_put_failure;
2681 if (mac_addr &&
2682 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2683 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002684
Johannes Berge31b8212010-10-05 19:39:30 +02002685 if (pairwise && mac_addr &&
2686 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2687 return -ENOENT;
2688
Hila Gonene35e4d22012-06-27 17:19:42 +03002689 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2690 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002691
2692 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002693 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002694
2695 if (cookie.error)
2696 goto nla_put_failure;
2697
2698 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002699 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002700
2701 nla_put_failure:
2702 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002703 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002704 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002705 return err;
2706}
2707
2708static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2709{
Johannes Berg4c476992010-10-04 21:36:35 +02002710 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002711 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002712 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002713 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002714
Johannes Bergb9454e82009-07-08 13:29:08 +02002715 err = nl80211_parse_key(info, &key);
2716 if (err)
2717 return err;
2718
2719 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002720 return -EINVAL;
2721
Johannes Bergb9454e82009-07-08 13:29:08 +02002722 /* only support setting default key */
2723 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002724 return -EINVAL;
2725
Johannes Bergfffd0932009-07-08 14:22:54 +02002726 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002727
2728 if (key.def) {
2729 if (!rdev->ops->set_default_key) {
2730 err = -EOPNOTSUPP;
2731 goto out;
2732 }
2733
2734 err = nl80211_key_allowed(dev->ieee80211_ptr);
2735 if (err)
2736 goto out;
2737
Hila Gonene35e4d22012-06-27 17:19:42 +03002738 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002739 key.def_uni, key.def_multi);
2740
2741 if (err)
2742 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002743
Johannes Berg3d23e342009-09-29 23:27:28 +02002744#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002745 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002746#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002747 } else {
2748 if (key.def_uni || !key.def_multi) {
2749 err = -EINVAL;
2750 goto out;
2751 }
2752
2753 if (!rdev->ops->set_default_mgmt_key) {
2754 err = -EOPNOTSUPP;
2755 goto out;
2756 }
2757
2758 err = nl80211_key_allowed(dev->ieee80211_ptr);
2759 if (err)
2760 goto out;
2761
Hila Gonene35e4d22012-06-27 17:19:42 +03002762 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002763 if (err)
2764 goto out;
2765
2766#ifdef CONFIG_CFG80211_WEXT
2767 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2768#endif
2769 }
2770
2771 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002772 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002773
Johannes Berg41ade002007-12-19 02:03:29 +01002774 return err;
2775}
2776
2777static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2778{
Johannes Berg4c476992010-10-04 21:36:35 +02002779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002780 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002781 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002782 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002783 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002784
Johannes Bergb9454e82009-07-08 13:29:08 +02002785 err = nl80211_parse_key(info, &key);
2786 if (err)
2787 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002788
Johannes Bergb9454e82009-07-08 13:29:08 +02002789 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002790 return -EINVAL;
2791
Johannes Berg41ade002007-12-19 02:03:29 +01002792 if (info->attrs[NL80211_ATTR_MAC])
2793 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2794
Johannes Berge31b8212010-10-05 19:39:30 +02002795 if (key.type == -1) {
2796 if (mac_addr)
2797 key.type = NL80211_KEYTYPE_PAIRWISE;
2798 else
2799 key.type = NL80211_KEYTYPE_GROUP;
2800 }
2801
2802 /* for now */
2803 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2804 key.type != NL80211_KEYTYPE_GROUP)
2805 return -EINVAL;
2806
Johannes Berg4c476992010-10-04 21:36:35 +02002807 if (!rdev->ops->add_key)
2808 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002809
Johannes Berge31b8212010-10-05 19:39:30 +02002810 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2811 key.type == NL80211_KEYTYPE_PAIRWISE,
2812 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002813 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002814
2815 wdev_lock(dev->ieee80211_ptr);
2816 err = nl80211_key_allowed(dev->ieee80211_ptr);
2817 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002818 err = rdev_add_key(rdev, dev, key.idx,
2819 key.type == NL80211_KEYTYPE_PAIRWISE,
2820 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002821 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002822
Johannes Berg41ade002007-12-19 02:03:29 +01002823 return err;
2824}
2825
2826static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2827{
Johannes Berg4c476992010-10-04 21:36:35 +02002828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002829 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002830 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002831 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002832 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002833
Johannes Bergb9454e82009-07-08 13:29:08 +02002834 err = nl80211_parse_key(info, &key);
2835 if (err)
2836 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002837
2838 if (info->attrs[NL80211_ATTR_MAC])
2839 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2840
Johannes Berge31b8212010-10-05 19:39:30 +02002841 if (key.type == -1) {
2842 if (mac_addr)
2843 key.type = NL80211_KEYTYPE_PAIRWISE;
2844 else
2845 key.type = NL80211_KEYTYPE_GROUP;
2846 }
2847
2848 /* for now */
2849 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2850 key.type != NL80211_KEYTYPE_GROUP)
2851 return -EINVAL;
2852
Johannes Berg4c476992010-10-04 21:36:35 +02002853 if (!rdev->ops->del_key)
2854 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002855
Johannes Bergfffd0932009-07-08 14:22:54 +02002856 wdev_lock(dev->ieee80211_ptr);
2857 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002858
2859 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2860 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2861 err = -ENOENT;
2862
Johannes Bergfffd0932009-07-08 14:22:54 +02002863 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002864 err = rdev_del_key(rdev, dev, key.idx,
2865 key.type == NL80211_KEYTYPE_PAIRWISE,
2866 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002867
Johannes Berg3d23e342009-09-29 23:27:28 +02002868#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002869 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002870 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002871 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002872 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002873 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2874 }
2875#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002876 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002877
Johannes Berg41ade002007-12-19 02:03:29 +01002878 return err;
2879}
2880
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302881/* This function returns an error or the number of nested attributes */
2882static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2883{
2884 struct nlattr *attr;
2885 int n_entries = 0, tmp;
2886
2887 nla_for_each_nested(attr, nl_attr, tmp) {
2888 if (nla_len(attr) != ETH_ALEN)
2889 return -EINVAL;
2890
2891 n_entries++;
2892 }
2893
2894 return n_entries;
2895}
2896
2897/*
2898 * This function parses ACL information and allocates memory for ACL data.
2899 * On successful return, the calling function is responsible to free the
2900 * ACL buffer returned by this function.
2901 */
2902static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2903 struct genl_info *info)
2904{
2905 enum nl80211_acl_policy acl_policy;
2906 struct nlattr *attr;
2907 struct cfg80211_acl_data *acl;
2908 int i = 0, n_entries, tmp;
2909
2910 if (!wiphy->max_acl_mac_addrs)
2911 return ERR_PTR(-EOPNOTSUPP);
2912
2913 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2914 return ERR_PTR(-EINVAL);
2915
2916 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2917 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2918 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2919 return ERR_PTR(-EINVAL);
2920
2921 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2922 return ERR_PTR(-EINVAL);
2923
2924 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2925 if (n_entries < 0)
2926 return ERR_PTR(n_entries);
2927
2928 if (n_entries > wiphy->max_acl_mac_addrs)
2929 return ERR_PTR(-ENOTSUPP);
2930
2931 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2932 GFP_KERNEL);
2933 if (!acl)
2934 return ERR_PTR(-ENOMEM);
2935
2936 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2937 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2938 i++;
2939 }
2940
2941 acl->n_acl_entries = n_entries;
2942 acl->acl_policy = acl_policy;
2943
2944 return acl;
2945}
2946
2947static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2948{
2949 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2950 struct net_device *dev = info->user_ptr[1];
2951 struct cfg80211_acl_data *acl;
2952 int err;
2953
2954 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2955 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2956 return -EOPNOTSUPP;
2957
2958 if (!dev->ieee80211_ptr->beacon_interval)
2959 return -EINVAL;
2960
2961 acl = parse_acl_data(&rdev->wiphy, info);
2962 if (IS_ERR(acl))
2963 return PTR_ERR(acl);
2964
2965 err = rdev_set_mac_acl(rdev, dev, acl);
2966
2967 kfree(acl);
2968
2969 return err;
2970}
2971
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002972static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002973 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002974{
Johannes Berg88600202012-02-13 15:17:18 +01002975 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002976
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002977 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2978 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2979 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2980 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002981 return -EINVAL;
2982
Johannes Berg88600202012-02-13 15:17:18 +01002983 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002984
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002985 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2986 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2987 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002988 if (!bcn->head_len)
2989 return -EINVAL;
2990 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002991 }
2992
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002993 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2994 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2995 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002996 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002997 }
2998
Johannes Berg4c476992010-10-04 21:36:35 +02002999 if (!haveinfo)
3000 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003001
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 if (attrs[NL80211_ATTR_IE]) {
3003 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3004 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003005 }
3006
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003007 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003008 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003009 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003010 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003011 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003012 }
3013
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003014 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003015 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003016 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003017 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003018 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003019 }
3020
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003021 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3022 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3023 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003024 }
3025
Johannes Berg88600202012-02-13 15:17:18 +01003026 return 0;
3027}
3028
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003029static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3030 struct cfg80211_ap_settings *params)
3031{
3032 struct wireless_dev *wdev;
3033 bool ret = false;
3034
Johannes Berg89a54e42012-06-15 14:33:17 +02003035 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003036 if (wdev->iftype != NL80211_IFTYPE_AP &&
3037 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3038 continue;
3039
Johannes Berg683b6d32012-11-08 21:25:48 +01003040 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003041 continue;
3042
Johannes Berg683b6d32012-11-08 21:25:48 +01003043 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003044 ret = true;
3045 break;
3046 }
3047
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003048 return ret;
3049}
3050
Jouni Malinene39e5b52012-09-30 19:29:39 +03003051static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3052 enum nl80211_auth_type auth_type,
3053 enum nl80211_commands cmd)
3054{
3055 if (auth_type > NL80211_AUTHTYPE_MAX)
3056 return false;
3057
3058 switch (cmd) {
3059 case NL80211_CMD_AUTHENTICATE:
3060 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3061 auth_type == NL80211_AUTHTYPE_SAE)
3062 return false;
3063 return true;
3064 case NL80211_CMD_CONNECT:
3065 case NL80211_CMD_START_AP:
3066 /* SAE not supported yet */
3067 if (auth_type == NL80211_AUTHTYPE_SAE)
3068 return false;
3069 return true;
3070 default:
3071 return false;
3072 }
3073}
3074
Johannes Berg88600202012-02-13 15:17:18 +01003075static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3076{
3077 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3078 struct net_device *dev = info->user_ptr[1];
3079 struct wireless_dev *wdev = dev->ieee80211_ptr;
3080 struct cfg80211_ap_settings params;
3081 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003082 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003083
3084 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3085 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3086 return -EOPNOTSUPP;
3087
3088 if (!rdev->ops->start_ap)
3089 return -EOPNOTSUPP;
3090
3091 if (wdev->beacon_interval)
3092 return -EALREADY;
3093
3094 memset(&params, 0, sizeof(params));
3095
3096 /* these are required for START_AP */
3097 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3098 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3099 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3100 return -EINVAL;
3101
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003102 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003103 if (err)
3104 return err;
3105
3106 params.beacon_interval =
3107 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3108 params.dtim_period =
3109 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3110
3111 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3112 if (err)
3113 return err;
3114
3115 /*
3116 * In theory, some of these attributes should be required here
3117 * but since they were not used when the command was originally
3118 * added, keep them optional for old user space programs to let
3119 * them continue to work with drivers that do not need the
3120 * additional information -- drivers must check!
3121 */
3122 if (info->attrs[NL80211_ATTR_SSID]) {
3123 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3124 params.ssid_len =
3125 nla_len(info->attrs[NL80211_ATTR_SSID]);
3126 if (params.ssid_len == 0 ||
3127 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3128 return -EINVAL;
3129 }
3130
3131 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3132 params.hidden_ssid = nla_get_u32(
3133 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3134 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3135 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3136 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3137 return -EINVAL;
3138 }
3139
3140 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3141
3142 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3143 params.auth_type = nla_get_u32(
3144 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003145 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3146 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003147 return -EINVAL;
3148 } else
3149 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3150
3151 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3152 NL80211_MAX_NR_CIPHER_SUITES);
3153 if (err)
3154 return err;
3155
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303156 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3157 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3158 return -EOPNOTSUPP;
3159 params.inactivity_timeout = nla_get_u16(
3160 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3161 }
3162
Johannes Berg53cabad2012-11-14 15:17:28 +01003163 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3165 return -EINVAL;
3166 params.p2p_ctwindow =
3167 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3168 if (params.p2p_ctwindow > 127)
3169 return -EINVAL;
3170 if (params.p2p_ctwindow != 0 &&
3171 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3172 return -EINVAL;
3173 }
3174
3175 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3176 u8 tmp;
3177
3178 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3179 return -EINVAL;
3180 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3181 if (tmp > 1)
3182 return -EINVAL;
3183 params.p2p_opp_ps = tmp;
3184 if (params.p2p_opp_ps != 0 &&
3185 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3186 return -EINVAL;
3187 }
3188
Johannes Bergaa430da2012-05-16 23:50:18 +02003189 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003190 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3191 if (err)
3192 return err;
3193 } else if (wdev->preset_chandef.chan) {
3194 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003195 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003196 return -EINVAL;
3197
Johannes Berg683b6d32012-11-08 21:25:48 +01003198 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003199 return -EINVAL;
3200
Simon Wunderlich04f39042013-02-08 18:16:19 +01003201 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3202 if (err < 0)
3203 return err;
3204 if (err) {
3205 radar_detect_width = BIT(params.chandef.width);
3206 params.radar_required = true;
3207 }
3208
Simon Wunderlich04f39042013-02-08 18:16:19 +01003209 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3210 params.chandef.chan,
3211 CHAN_MODE_SHARED,
3212 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003213 if (err)
3214 return err;
3215
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303216 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3217 params.acl = parse_acl_data(&rdev->wiphy, info);
3218 if (IS_ERR(params.acl))
3219 return PTR_ERR(params.acl);
3220 }
3221
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003222 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003223 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003224 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003225 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003226 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003227 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003228 wdev->ssid_len = params.ssid_len;
3229 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003230 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003231 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303232
3233 kfree(params.acl);
3234
Johannes Berg56d18932011-05-09 18:41:15 +02003235 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003236}
3237
Johannes Berg88600202012-02-13 15:17:18 +01003238static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3239{
3240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3241 struct net_device *dev = info->user_ptr[1];
3242 struct wireless_dev *wdev = dev->ieee80211_ptr;
3243 struct cfg80211_beacon_data params;
3244 int err;
3245
3246 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3247 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3248 return -EOPNOTSUPP;
3249
3250 if (!rdev->ops->change_beacon)
3251 return -EOPNOTSUPP;
3252
3253 if (!wdev->beacon_interval)
3254 return -EINVAL;
3255
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003256 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003257 if (err)
3258 return err;
3259
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003260 wdev_lock(wdev);
3261 err = rdev_change_beacon(rdev, dev, &params);
3262 wdev_unlock(wdev);
3263
3264 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003265}
3266
3267static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003268{
Johannes Berg4c476992010-10-04 21:36:35 +02003269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3270 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003271
Michal Kazior60771782012-06-29 12:46:56 +02003272 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003273}
3274
Johannes Berg5727ef12007-12-19 02:03:34 +01003275static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3276 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3277 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3278 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003279 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003280 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003281 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003282};
3283
Johannes Bergeccb8e82009-05-11 21:57:56 +03003284static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003285 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003286 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003287{
3288 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003289 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003290 int flag;
3291
Johannes Bergeccb8e82009-05-11 21:57:56 +03003292 /*
3293 * Try parsing the new attribute first so userspace
3294 * can specify both for older kernels.
3295 */
3296 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3297 if (nla) {
3298 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003299
Johannes Bergeccb8e82009-05-11 21:57:56 +03003300 sta_flags = nla_data(nla);
3301 params->sta_flags_mask = sta_flags->mask;
3302 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003303 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003304 if ((params->sta_flags_mask |
3305 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3306 return -EINVAL;
3307 return 0;
3308 }
3309
3310 /* if present, parse the old attribute */
3311
3312 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003313 if (!nla)
3314 return 0;
3315
3316 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3317 nla, sta_flags_policy))
3318 return -EINVAL;
3319
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003320 /*
3321 * Only allow certain flags for interface types so that
3322 * other attributes are silently ignored. Remember that
3323 * this is backward compatibility code with old userspace
3324 * and shouldn't be hit in other cases anyway.
3325 */
3326 switch (iftype) {
3327 case NL80211_IFTYPE_AP:
3328 case NL80211_IFTYPE_AP_VLAN:
3329 case NL80211_IFTYPE_P2P_GO:
3330 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3331 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3332 BIT(NL80211_STA_FLAG_WME) |
3333 BIT(NL80211_STA_FLAG_MFP);
3334 break;
3335 case NL80211_IFTYPE_P2P_CLIENT:
3336 case NL80211_IFTYPE_STATION:
3337 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3338 BIT(NL80211_STA_FLAG_TDLS_PEER);
3339 break;
3340 case NL80211_IFTYPE_MESH_POINT:
3341 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3342 BIT(NL80211_STA_FLAG_MFP) |
3343 BIT(NL80211_STA_FLAG_AUTHORIZED);
3344 default:
3345 return -EINVAL;
3346 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003347
Johannes Berg3383b5a2012-05-10 20:14:43 +02003348 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3349 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003350 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003351
Johannes Berg3383b5a2012-05-10 20:14:43 +02003352 /* no longer support new API additions in old API */
3353 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3354 return -EINVAL;
3355 }
3356 }
3357
Johannes Berg5727ef12007-12-19 02:03:34 +01003358 return 0;
3359}
3360
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003361static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3362 int attr)
3363{
3364 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003365 u32 bitrate;
3366 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003367
3368 rate = nla_nest_start(msg, attr);
3369 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003370 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003371
3372 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3373 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003374 /* report 16-bit bitrate only if we can */
3375 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003376 if (bitrate > 0 &&
3377 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3378 return false;
3379 if (bitrate_compat > 0 &&
3380 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3381 return false;
3382
3383 if (info->flags & RATE_INFO_FLAGS_MCS) {
3384 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3385 return false;
3386 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3387 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3388 return false;
3389 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3390 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3391 return false;
3392 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3393 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3394 return false;
3395 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3396 return false;
3397 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3398 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3399 return false;
3400 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3401 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3402 return false;
3403 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3404 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3405 return false;
3406 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3407 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3408 return false;
3409 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3410 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3411 return false;
3412 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003413
3414 nla_nest_end(msg, rate);
3415 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003416}
3417
Felix Fietkau119363c2013-04-22 16:29:30 +02003418static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3419 int id)
3420{
3421 void *attr;
3422 int i = 0;
3423
3424 if (!mask)
3425 return true;
3426
3427 attr = nla_nest_start(msg, id);
3428 if (!attr)
3429 return false;
3430
3431 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3432 if (!(mask & BIT(i)))
3433 continue;
3434
3435 if (nla_put_u8(msg, i, signal[i]))
3436 return false;
3437 }
3438
3439 nla_nest_end(msg, attr);
3440
3441 return true;
3442}
3443
Eric W. Biederman15e47302012-09-07 20:12:54 +00003444static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003445 int flags,
3446 struct cfg80211_registered_device *rdev,
3447 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003448 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003449{
3450 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003451 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003452
Eric W. Biederman15e47302012-09-07 20:12:54 +00003453 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003454 if (!hdr)
3455 return -1;
3456
David S. Miller9360ffd2012-03-29 04:41:26 -04003457 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3458 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3459 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3460 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003461
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003462 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3463 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003464 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003465 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3466 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3467 sinfo->connected_time))
3468 goto nla_put_failure;
3469 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3470 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3471 sinfo->inactive_time))
3472 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003473 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3474 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003475 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003476 (u32)sinfo->rx_bytes))
3477 goto nla_put_failure;
3478 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003479 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003480 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3481 (u32)sinfo->tx_bytes))
3482 goto nla_put_failure;
3483 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3484 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003485 sinfo->rx_bytes))
3486 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003487 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3488 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003489 sinfo->tx_bytes))
3490 goto nla_put_failure;
3491 if ((sinfo->filled & STATION_INFO_LLID) &&
3492 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3493 goto nla_put_failure;
3494 if ((sinfo->filled & STATION_INFO_PLID) &&
3495 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3496 goto nla_put_failure;
3497 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3498 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3499 sinfo->plink_state))
3500 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003501 switch (rdev->wiphy.signal_type) {
3502 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003503 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3504 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3505 sinfo->signal))
3506 goto nla_put_failure;
3507 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3508 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3509 sinfo->signal_avg))
3510 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003511 break;
3512 default:
3513 break;
3514 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003515 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3516 if (!nl80211_put_signal(msg, sinfo->chains,
3517 sinfo->chain_signal,
3518 NL80211_STA_INFO_CHAIN_SIGNAL))
3519 goto nla_put_failure;
3520 }
3521 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3522 if (!nl80211_put_signal(msg, sinfo->chains,
3523 sinfo->chain_signal_avg,
3524 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3525 goto nla_put_failure;
3526 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003527 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003528 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3529 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003530 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003531 }
3532 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3533 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3534 NL80211_STA_INFO_RX_BITRATE))
3535 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003536 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003537 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3538 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3539 sinfo->rx_packets))
3540 goto nla_put_failure;
3541 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3542 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3543 sinfo->tx_packets))
3544 goto nla_put_failure;
3545 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3546 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3547 sinfo->tx_retries))
3548 goto nla_put_failure;
3549 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3550 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3551 sinfo->tx_failed))
3552 goto nla_put_failure;
3553 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3554 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3555 sinfo->beacon_loss_count))
3556 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003557 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3558 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3559 sinfo->local_pm))
3560 goto nla_put_failure;
3561 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3562 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3563 sinfo->peer_pm))
3564 goto nla_put_failure;
3565 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3566 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3567 sinfo->nonpeer_pm))
3568 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003569 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3570 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3571 if (!bss_param)
3572 goto nla_put_failure;
3573
David S. Miller9360ffd2012-03-29 04:41:26 -04003574 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3575 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3576 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3577 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3578 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3579 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3580 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3581 sinfo->bss_param.dtim_period) ||
3582 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3583 sinfo->bss_param.beacon_interval))
3584 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003585
3586 nla_nest_end(msg, bss_param);
3587 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003588 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3589 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3590 sizeof(struct nl80211_sta_flag_update),
3591 &sinfo->sta_flags))
3592 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003593 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3594 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3595 sinfo->t_offset))
3596 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003597 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003598
David S. Miller9360ffd2012-03-29 04:41:26 -04003599 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3600 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3601 sinfo->assoc_req_ies))
3602 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003603
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003604 return genlmsg_end(msg, hdr);
3605
3606 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003607 genlmsg_cancel(msg, hdr);
3608 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003609}
3610
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003611static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003612 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003613{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003614 struct station_info sinfo;
3615 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003616 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003617 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003618 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003619 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003620
Johannes Berg97990a02013-04-19 01:02:55 +02003621 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003622 if (err)
3623 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003624
Johannes Berg97990a02013-04-19 01:02:55 +02003625 if (!wdev->netdev) {
3626 err = -EINVAL;
3627 goto out_err;
3628 }
3629
Johannes Bergbba95fe2008-07-29 13:22:51 +02003630 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003631 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003632 goto out_err;
3633 }
3634
Johannes Bergbba95fe2008-07-29 13:22:51 +02003635 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003636 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003637 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003638 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003639 if (err == -ENOENT)
3640 break;
3641 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003642 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003643
3644 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003645 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003646 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003647 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003648 &sinfo) < 0)
3649 goto out;
3650
3651 sta_idx++;
3652 }
3653
3654
3655 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003656 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003657 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003658 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003659 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003660
3661 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003662}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003663
Johannes Berg5727ef12007-12-19 02:03:34 +01003664static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3665{
Johannes Berg4c476992010-10-04 21:36:35 +02003666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3667 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003668 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003669 struct sk_buff *msg;
3670 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003671 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003672
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003673 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003674
3675 if (!info->attrs[NL80211_ATTR_MAC])
3676 return -EINVAL;
3677
3678 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3679
Johannes Berg4c476992010-10-04 21:36:35 +02003680 if (!rdev->ops->get_station)
3681 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003682
Hila Gonene35e4d22012-06-27 17:19:42 +03003683 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003684 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003685 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003686
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003688 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003689 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003690
Eric W. Biederman15e47302012-09-07 20:12:54 +00003691 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003692 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003693 nlmsg_free(msg);
3694 return -ENOBUFS;
3695 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003696
Johannes Berg4c476992010-10-04 21:36:35 +02003697 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003698}
3699
Johannes Berg77ee7c82013-02-15 00:48:33 +01003700int cfg80211_check_station_change(struct wiphy *wiphy,
3701 struct station_parameters *params,
3702 enum cfg80211_station_type statype)
3703{
3704 if (params->listen_interval != -1)
3705 return -EINVAL;
3706 if (params->aid)
3707 return -EINVAL;
3708
3709 /* When you run into this, adjust the code below for the new flag */
3710 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3711
3712 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003713 case CFG80211_STA_MESH_PEER_KERNEL:
3714 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003715 /*
3716 * No ignoring the TDLS flag here -- the userspace mesh
3717 * code doesn't have the bug of including TDLS in the
3718 * mask everywhere.
3719 */
3720 if (params->sta_flags_mask &
3721 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3722 BIT(NL80211_STA_FLAG_MFP) |
3723 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3724 return -EINVAL;
3725 break;
3726 case CFG80211_STA_TDLS_PEER_SETUP:
3727 case CFG80211_STA_TDLS_PEER_ACTIVE:
3728 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3729 return -EINVAL;
3730 /* ignore since it can't change */
3731 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3732 break;
3733 default:
3734 /* disallow mesh-specific things */
3735 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3736 return -EINVAL;
3737 if (params->local_pm)
3738 return -EINVAL;
3739 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3740 return -EINVAL;
3741 }
3742
3743 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3744 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3745 /* TDLS can't be set, ... */
3746 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3747 return -EINVAL;
3748 /*
3749 * ... but don't bother the driver with it. This works around
3750 * a hostapd/wpa_supplicant issue -- it always includes the
3751 * TLDS_PEER flag in the mask even for AP mode.
3752 */
3753 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3754 }
3755
3756 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3757 /* reject other things that can't change */
3758 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3759 return -EINVAL;
3760 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3761 return -EINVAL;
3762 if (params->supported_rates)
3763 return -EINVAL;
3764 if (params->ext_capab || params->ht_capa || params->vht_capa)
3765 return -EINVAL;
3766 }
3767
3768 if (statype != CFG80211_STA_AP_CLIENT) {
3769 if (params->vlan)
3770 return -EINVAL;
3771 }
3772
3773 switch (statype) {
3774 case CFG80211_STA_AP_MLME_CLIENT:
3775 /* Use this only for authorizing/unauthorizing a station */
3776 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3777 return -EOPNOTSUPP;
3778 break;
3779 case CFG80211_STA_AP_CLIENT:
3780 /* accept only the listed bits */
3781 if (params->sta_flags_mask &
3782 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3783 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3784 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3785 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3786 BIT(NL80211_STA_FLAG_WME) |
3787 BIT(NL80211_STA_FLAG_MFP)))
3788 return -EINVAL;
3789
3790 /* but authenticated/associated only if driver handles it */
3791 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3792 params->sta_flags_mask &
3793 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3794 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3795 return -EINVAL;
3796 break;
3797 case CFG80211_STA_IBSS:
3798 case CFG80211_STA_AP_STA:
3799 /* reject any changes other than AUTHORIZED */
3800 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3801 return -EINVAL;
3802 break;
3803 case CFG80211_STA_TDLS_PEER_SETUP:
3804 /* reject any changes other than AUTHORIZED or WME */
3805 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3806 BIT(NL80211_STA_FLAG_WME)))
3807 return -EINVAL;
3808 /* force (at least) rates when authorizing */
3809 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3810 !params->supported_rates)
3811 return -EINVAL;
3812 break;
3813 case CFG80211_STA_TDLS_PEER_ACTIVE:
3814 /* reject any changes */
3815 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003816 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003817 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3818 return -EINVAL;
3819 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003820 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003821 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3822 return -EINVAL;
3823 break;
3824 }
3825
3826 return 0;
3827}
3828EXPORT_SYMBOL(cfg80211_check_station_change);
3829
Johannes Berg5727ef12007-12-19 02:03:34 +01003830/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003831 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003832 */
Johannes Berg80b99892011-11-18 16:23:01 +01003833static struct net_device *get_vlan(struct genl_info *info,
3834 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003835{
Johannes Berg463d0182009-07-14 00:33:35 +02003836 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003837 struct net_device *v;
3838 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003839
Johannes Berg80b99892011-11-18 16:23:01 +01003840 if (!vlanattr)
3841 return NULL;
3842
3843 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3844 if (!v)
3845 return ERR_PTR(-ENODEV);
3846
3847 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3848 ret = -EINVAL;
3849 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003850 }
Johannes Berg80b99892011-11-18 16:23:01 +01003851
Johannes Berg77ee7c82013-02-15 00:48:33 +01003852 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3853 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3854 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3855 ret = -EINVAL;
3856 goto error;
3857 }
3858
Johannes Berg80b99892011-11-18 16:23:01 +01003859 if (!netif_running(v)) {
3860 ret = -ENETDOWN;
3861 goto error;
3862 }
3863
3864 return v;
3865 error:
3866 dev_put(v);
3867 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003868}
3869
Jouni Malinendf881292013-02-14 21:10:54 +02003870static struct nla_policy
3871nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3872 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3873 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3874};
3875
Johannes Bergff276692013-02-15 00:09:01 +01003876static int nl80211_parse_sta_wme(struct genl_info *info,
3877 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003878{
Jouni Malinendf881292013-02-14 21:10:54 +02003879 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3880 struct nlattr *nla;
3881 int err;
3882
Jouni Malinendf881292013-02-14 21:10:54 +02003883 /* parse WME attributes if present */
3884 if (!info->attrs[NL80211_ATTR_STA_WME])
3885 return 0;
3886
3887 nla = info->attrs[NL80211_ATTR_STA_WME];
3888 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3889 nl80211_sta_wme_policy);
3890 if (err)
3891 return err;
3892
3893 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3894 params->uapsd_queues = nla_get_u8(
3895 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3896 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3897 return -EINVAL;
3898
3899 if (tb[NL80211_STA_WME_MAX_SP])
3900 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3901
3902 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3903 return -EINVAL;
3904
3905 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3906
3907 return 0;
3908}
3909
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303910static int nl80211_parse_sta_channel_info(struct genl_info *info,
3911 struct station_parameters *params)
3912{
3913 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3914 params->supported_channels =
3915 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3916 params->supported_channels_len =
3917 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3918 /*
3919 * Need to include at least one (first channel, number of
3920 * channels) tuple for each subband, and must have proper
3921 * tuples for the rest of the data as well.
3922 */
3923 if (params->supported_channels_len < 2)
3924 return -EINVAL;
3925 if (params->supported_channels_len % 2)
3926 return -EINVAL;
3927 }
3928
3929 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3930 params->supported_oper_classes =
3931 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3932 params->supported_oper_classes_len =
3933 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3934 /*
3935 * The value of the Length field of the Supported Operating
3936 * Classes element is between 2 and 253.
3937 */
3938 if (params->supported_oper_classes_len < 2 ||
3939 params->supported_oper_classes_len > 253)
3940 return -EINVAL;
3941 }
3942 return 0;
3943}
3944
Johannes Bergff276692013-02-15 00:09:01 +01003945static int nl80211_set_station_tdls(struct genl_info *info,
3946 struct station_parameters *params)
3947{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303948 int err;
Johannes Bergff276692013-02-15 00:09:01 +01003949 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003950 if (info->attrs[NL80211_ATTR_PEER_AID])
3951 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003952 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3953 params->ht_capa =
3954 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3955 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3956 params->vht_capa =
3957 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3958
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303959 err = nl80211_parse_sta_channel_info(info, params);
3960 if (err)
3961 return err;
3962
Johannes Bergff276692013-02-15 00:09:01 +01003963 return nl80211_parse_sta_wme(info, params);
3964}
3965
Johannes Berg5727ef12007-12-19 02:03:34 +01003966static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3967{
Johannes Berg4c476992010-10-04 21:36:35 +02003968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003969 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003970 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003971 u8 *mac_addr;
3972 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003973
3974 memset(&params, 0, sizeof(params));
3975
3976 params.listen_interval = -1;
3977
Johannes Berg77ee7c82013-02-15 00:48:33 +01003978 if (!rdev->ops->change_station)
3979 return -EOPNOTSUPP;
3980
Johannes Berg5727ef12007-12-19 02:03:34 +01003981 if (info->attrs[NL80211_ATTR_STA_AID])
3982 return -EINVAL;
3983
3984 if (!info->attrs[NL80211_ATTR_MAC])
3985 return -EINVAL;
3986
3987 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3988
3989 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3990 params.supported_rates =
3991 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3992 params.supported_rates_len =
3993 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3994 }
3995
Jouni Malinen9d62a982013-02-14 21:10:13 +02003996 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3997 params.capability =
3998 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3999 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4000 }
4001
4002 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4003 params.ext_capab =
4004 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4005 params.ext_capab_len =
4006 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4007 }
4008
Jouni Malinendf881292013-02-14 21:10:54 +02004009 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004010 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004011
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004012 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004013 return -EINVAL;
4014
Johannes Bergf8bacc22013-02-14 23:27:01 +01004015 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004016 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004017 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4018 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4019 return -EINVAL;
4020 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004021
Johannes Bergf8bacc22013-02-14 23:27:01 +01004022 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004023 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004024 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4025 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4026 return -EINVAL;
4027 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4028 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004029
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004030 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4031 enum nl80211_mesh_power_mode pm = nla_get_u32(
4032 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4033
4034 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4035 pm > NL80211_MESH_POWER_MAX)
4036 return -EINVAL;
4037
4038 params.local_pm = pm;
4039 }
4040
Johannes Berg77ee7c82013-02-15 00:48:33 +01004041 /* Include parameters for TDLS peer (will check later) */
4042 err = nl80211_set_station_tdls(info, &params);
4043 if (err)
4044 return err;
4045
4046 params.vlan = get_vlan(info, rdev);
4047 if (IS_ERR(params.vlan))
4048 return PTR_ERR(params.vlan);
4049
Johannes Berga97f4422009-06-18 17:23:43 +02004050 switch (dev->ieee80211_ptr->iftype) {
4051 case NL80211_IFTYPE_AP:
4052 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004053 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004054 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004055 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004056 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004057 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004058 break;
4059 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004060 err = -EOPNOTSUPP;
4061 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004062 }
4063
Johannes Berg77ee7c82013-02-15 00:48:33 +01004064 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004065 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004066
Johannes Berg77ee7c82013-02-15 00:48:33 +01004067 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004068 if (params.vlan)
4069 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004070
Johannes Berg5727ef12007-12-19 02:03:34 +01004071 return err;
4072}
4073
4074static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4075{
Johannes Berg4c476992010-10-04 21:36:35 +02004076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004077 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004078 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004079 struct station_parameters params;
4080 u8 *mac_addr = NULL;
4081
4082 memset(&params, 0, sizeof(params));
4083
Johannes Berg984c3112013-02-14 23:43:25 +01004084 if (!rdev->ops->add_station)
4085 return -EOPNOTSUPP;
4086
Johannes Berg5727ef12007-12-19 02:03:34 +01004087 if (!info->attrs[NL80211_ATTR_MAC])
4088 return -EINVAL;
4089
Johannes Berg5727ef12007-12-19 02:03:34 +01004090 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4091 return -EINVAL;
4092
4093 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4094 return -EINVAL;
4095
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004096 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4097 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004098 return -EINVAL;
4099
Johannes Berg5727ef12007-12-19 02:03:34 +01004100 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4101 params.supported_rates =
4102 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4103 params.supported_rates_len =
4104 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4105 params.listen_interval =
4106 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004107
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004108 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004109 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004110 else
4111 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004112 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4113 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004114
Jouni Malinen9d62a982013-02-14 21:10:13 +02004115 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4116 params.capability =
4117 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4118 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4119 }
4120
4121 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4122 params.ext_capab =
4123 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4124 params.ext_capab_len =
4125 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4126 }
4127
Jouni Malinen36aedc902008-08-25 11:58:58 +03004128 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4129 params.ht_capa =
4130 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004131
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004132 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4133 params.vht_capa =
4134 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4135
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004136 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4137 params.opmode_notif_used = true;
4138 params.opmode_notif =
4139 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4140 }
4141
Johannes Bergf8bacc22013-02-14 23:27:01 +01004142 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004143 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004144 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4145 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4146 return -EINVAL;
4147 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004148
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304149 err = nl80211_parse_sta_channel_info(info, &params);
4150 if (err)
4151 return err;
4152
Johannes Bergff276692013-02-15 00:09:01 +01004153 err = nl80211_parse_sta_wme(info, &params);
4154 if (err)
4155 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004156
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004157 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004158 return -EINVAL;
4159
Johannes Berg77ee7c82013-02-15 00:48:33 +01004160 /* When you run into this, adjust the code below for the new flag */
4161 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4162
Johannes Bergbdd90d52011-12-14 12:20:27 +01004163 switch (dev->ieee80211_ptr->iftype) {
4164 case NL80211_IFTYPE_AP:
4165 case NL80211_IFTYPE_AP_VLAN:
4166 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004167 /* ignore WME attributes if iface/sta is not capable */
4168 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4169 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4170 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004171
Johannes Bergbdd90d52011-12-14 12:20:27 +01004172 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004173 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4174 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004175 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004176 /* but don't bother the driver with it */
4177 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004178
Johannes Bergd582cff2012-10-26 17:53:44 +02004179 /* allow authenticated/associated only if driver handles it */
4180 if (!(rdev->wiphy.features &
4181 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4182 params.sta_flags_mask &
4183 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4184 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4185 return -EINVAL;
4186
Johannes Bergbdd90d52011-12-14 12:20:27 +01004187 /* must be last in here for error handling */
4188 params.vlan = get_vlan(info, rdev);
4189 if (IS_ERR(params.vlan))
4190 return PTR_ERR(params.vlan);
4191 break;
4192 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004193 /* ignore uAPSD data */
4194 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4195
Johannes Bergd582cff2012-10-26 17:53:44 +02004196 /* associated is disallowed */
4197 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4198 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004199 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004200 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4201 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004202 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004203 break;
4204 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004205 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004206 /* ignore uAPSD data */
4207 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4208
Johannes Berg77ee7c82013-02-15 00:48:33 +01004209 /* these are disallowed */
4210 if (params.sta_flags_mask &
4211 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4212 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004213 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004214 /* Only TDLS peers can be added */
4215 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4216 return -EINVAL;
4217 /* Can only add if TDLS ... */
4218 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4219 return -EOPNOTSUPP;
4220 /* ... with external setup is supported */
4221 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4222 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004223 /*
4224 * Older wpa_supplicant versions always mark the TDLS peer
4225 * as authorized, but it shouldn't yet be.
4226 */
4227 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004228 break;
4229 default:
4230 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004231 }
4232
Johannes Bergbdd90d52011-12-14 12:20:27 +01004233 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004234
Hila Gonene35e4d22012-06-27 17:19:42 +03004235 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004236
Johannes Berg5727ef12007-12-19 02:03:34 +01004237 if (params.vlan)
4238 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004239 return err;
4240}
4241
4242static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4243{
Johannes Berg4c476992010-10-04 21:36:35 +02004244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4245 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004246 u8 *mac_addr = NULL;
4247
4248 if (info->attrs[NL80211_ATTR_MAC])
4249 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4250
Johannes Berge80cf852009-05-11 14:43:13 +02004251 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004252 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004253 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004254 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4255 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004256
Johannes Berg4c476992010-10-04 21:36:35 +02004257 if (!rdev->ops->del_station)
4258 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004259
Hila Gonene35e4d22012-06-27 17:19:42 +03004260 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004261}
4262
Eric W. Biederman15e47302012-09-07 20:12:54 +00004263static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004264 int flags, struct net_device *dev,
4265 u8 *dst, u8 *next_hop,
4266 struct mpath_info *pinfo)
4267{
4268 void *hdr;
4269 struct nlattr *pinfoattr;
4270
Eric W. Biederman15e47302012-09-07 20:12:54 +00004271 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004272 if (!hdr)
4273 return -1;
4274
David S. Miller9360ffd2012-03-29 04:41:26 -04004275 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4276 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4277 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4278 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4279 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004280
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004281 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4282 if (!pinfoattr)
4283 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004284 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4285 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4286 pinfo->frame_qlen))
4287 goto nla_put_failure;
4288 if (((pinfo->filled & MPATH_INFO_SN) &&
4289 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4290 ((pinfo->filled & MPATH_INFO_METRIC) &&
4291 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4292 pinfo->metric)) ||
4293 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4294 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4295 pinfo->exptime)) ||
4296 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4297 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4298 pinfo->flags)) ||
4299 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4300 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4301 pinfo->discovery_timeout)) ||
4302 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4303 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4304 pinfo->discovery_retries)))
4305 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004306
4307 nla_nest_end(msg, pinfoattr);
4308
4309 return genlmsg_end(msg, hdr);
4310
4311 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004312 genlmsg_cancel(msg, hdr);
4313 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004314}
4315
4316static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004317 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004318{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004319 struct mpath_info pinfo;
4320 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004321 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004322 u8 dst[ETH_ALEN];
4323 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004324 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004326
Johannes Berg97990a02013-04-19 01:02:55 +02004327 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004328 if (err)
4329 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004330
4331 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004332 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004333 goto out_err;
4334 }
4335
Johannes Berg97990a02013-04-19 01:02:55 +02004336 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004337 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004338 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004339 }
4340
Johannes Bergbba95fe2008-07-29 13:22:51 +02004341 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004342 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4343 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004344 if (err == -ENOENT)
4345 break;
4346 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004347 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004348
Eric W. Biederman15e47302012-09-07 20:12:54 +00004349 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004350 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004351 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004352 &pinfo) < 0)
4353 goto out;
4354
4355 path_idx++;
4356 }
4357
4358
4359 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004360 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004361 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004362 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004363 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004364 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004365}
4366
4367static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4368{
Johannes Berg4c476992010-10-04 21:36:35 +02004369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004370 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004371 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004372 struct mpath_info pinfo;
4373 struct sk_buff *msg;
4374 u8 *dst = NULL;
4375 u8 next_hop[ETH_ALEN];
4376
4377 memset(&pinfo, 0, sizeof(pinfo));
4378
4379 if (!info->attrs[NL80211_ATTR_MAC])
4380 return -EINVAL;
4381
4382 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4383
Johannes Berg4c476992010-10-04 21:36:35 +02004384 if (!rdev->ops->get_mpath)
4385 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004386
Johannes Berg4c476992010-10-04 21:36:35 +02004387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4388 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004389
Hila Gonene35e4d22012-06-27 17:19:42 +03004390 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004392 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004393
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004395 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004396 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004397
Eric W. Biederman15e47302012-09-07 20:12:54 +00004398 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004399 dev, dst, next_hop, &pinfo) < 0) {
4400 nlmsg_free(msg);
4401 return -ENOBUFS;
4402 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004403
Johannes Berg4c476992010-10-04 21:36:35 +02004404 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004405}
4406
4407static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4408{
Johannes Berg4c476992010-10-04 21:36:35 +02004409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4410 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004411 u8 *dst = NULL;
4412 u8 *next_hop = NULL;
4413
4414 if (!info->attrs[NL80211_ATTR_MAC])
4415 return -EINVAL;
4416
4417 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4418 return -EINVAL;
4419
4420 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4421 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4422
Johannes Berg4c476992010-10-04 21:36:35 +02004423 if (!rdev->ops->change_mpath)
4424 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004425
Johannes Berg4c476992010-10-04 21:36:35 +02004426 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4427 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004428
Hila Gonene35e4d22012-06-27 17:19:42 +03004429 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430}
Johannes Berg4c476992010-10-04 21:36:35 +02004431
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004432static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4433{
Johannes Berg4c476992010-10-04 21:36:35 +02004434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4435 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004436 u8 *dst = NULL;
4437 u8 *next_hop = NULL;
4438
4439 if (!info->attrs[NL80211_ATTR_MAC])
4440 return -EINVAL;
4441
4442 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4443 return -EINVAL;
4444
4445 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4446 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4447
Johannes Berg4c476992010-10-04 21:36:35 +02004448 if (!rdev->ops->add_mpath)
4449 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004450
Johannes Berg4c476992010-10-04 21:36:35 +02004451 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4452 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004453
Hila Gonene35e4d22012-06-27 17:19:42 +03004454 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004455}
4456
4457static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4458{
Johannes Berg4c476992010-10-04 21:36:35 +02004459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4460 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004461 u8 *dst = NULL;
4462
4463 if (info->attrs[NL80211_ATTR_MAC])
4464 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4465
Johannes Berg4c476992010-10-04 21:36:35 +02004466 if (!rdev->ops->del_mpath)
4467 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004468
Hila Gonene35e4d22012-06-27 17:19:42 +03004469 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004470}
4471
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004472static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4473{
Johannes Berg4c476992010-10-04 21:36:35 +02004474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4475 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004476 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004477 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004478 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004479
4480 memset(&params, 0, sizeof(params));
4481 /* default to not changing parameters */
4482 params.use_cts_prot = -1;
4483 params.use_short_preamble = -1;
4484 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004485 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004486 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004487 params.p2p_ctwindow = -1;
4488 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004489
4490 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4491 params.use_cts_prot =
4492 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4493 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4494 params.use_short_preamble =
4495 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4496 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4497 params.use_short_slot_time =
4498 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004499 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4500 params.basic_rates =
4501 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4502 params.basic_rates_len =
4503 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4504 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004505 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4506 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004507 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4508 params.ht_opmode =
4509 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004510
Johannes Berg53cabad2012-11-14 15:17:28 +01004511 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4512 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4513 return -EINVAL;
4514 params.p2p_ctwindow =
4515 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4516 if (params.p2p_ctwindow < 0)
4517 return -EINVAL;
4518 if (params.p2p_ctwindow != 0 &&
4519 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4520 return -EINVAL;
4521 }
4522
4523 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4524 u8 tmp;
4525
4526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4527 return -EINVAL;
4528 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4529 if (tmp > 1)
4530 return -EINVAL;
4531 params.p2p_opp_ps = tmp;
4532 if (params.p2p_opp_ps &&
4533 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4534 return -EINVAL;
4535 }
4536
Johannes Berg4c476992010-10-04 21:36:35 +02004537 if (!rdev->ops->change_bss)
4538 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004539
Johannes Berg074ac8d2010-09-16 14:58:22 +02004540 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004541 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4542 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004543
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004544 wdev_lock(wdev);
4545 err = rdev_change_bss(rdev, dev, &params);
4546 wdev_unlock(wdev);
4547
4548 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004549}
4550
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004551static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004552 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4553 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4554 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4555 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4556 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4557 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4558};
4559
4560static int parse_reg_rule(struct nlattr *tb[],
4561 struct ieee80211_reg_rule *reg_rule)
4562{
4563 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4564 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4565
4566 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4567 return -EINVAL;
4568 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4569 return -EINVAL;
4570 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4571 return -EINVAL;
4572 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4573 return -EINVAL;
4574 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4575 return -EINVAL;
4576
4577 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4578
4579 freq_range->start_freq_khz =
4580 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4581 freq_range->end_freq_khz =
4582 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4583 freq_range->max_bandwidth_khz =
4584 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4585
4586 power_rule->max_eirp =
4587 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4588
4589 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4590 power_rule->max_antenna_gain =
4591 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4592
4593 return 0;
4594}
4595
4596static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4597{
4598 int r;
4599 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004600 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004601
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004602 /*
4603 * You should only get this when cfg80211 hasn't yet initialized
4604 * completely when built-in to the kernel right between the time
4605 * window between nl80211_init() and regulatory_init(), if that is
4606 * even possible.
4607 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004608 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004609 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004610
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004611 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4612 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004613
4614 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4615
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004616 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4617 user_reg_hint_type =
4618 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4619 else
4620 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4621
4622 switch (user_reg_hint_type) {
4623 case NL80211_USER_REG_HINT_USER:
4624 case NL80211_USER_REG_HINT_CELL_BASE:
4625 break;
4626 default:
4627 return -EINVAL;
4628 }
4629
4630 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004631
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004632 return r;
4633}
4634
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004635static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004636 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004637{
Johannes Berg4c476992010-10-04 21:36:35 +02004638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004639 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004640 struct wireless_dev *wdev = dev->ieee80211_ptr;
4641 struct mesh_config cur_params;
4642 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004643 void *hdr;
4644 struct nlattr *pinfoattr;
4645 struct sk_buff *msg;
4646
Johannes Berg29cbe682010-12-03 09:20:44 +01004647 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4648 return -EOPNOTSUPP;
4649
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004650 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004651 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004652
Johannes Berg29cbe682010-12-03 09:20:44 +01004653 wdev_lock(wdev);
4654 /* If not connected, get default parameters */
4655 if (!wdev->mesh_id_len)
4656 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4657 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004658 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004659 wdev_unlock(wdev);
4660
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004661 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004662 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004663
4664 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004666 if (!msg)
4667 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004668 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004669 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004670 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004671 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004672 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004673 if (!pinfoattr)
4674 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004675 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4676 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4677 cur_params.dot11MeshRetryTimeout) ||
4678 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4679 cur_params.dot11MeshConfirmTimeout) ||
4680 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4681 cur_params.dot11MeshHoldingTimeout) ||
4682 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4683 cur_params.dot11MeshMaxPeerLinks) ||
4684 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4685 cur_params.dot11MeshMaxRetries) ||
4686 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4687 cur_params.dot11MeshTTL) ||
4688 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4689 cur_params.element_ttl) ||
4690 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4691 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004692 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4693 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004694 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4695 cur_params.dot11MeshHWMPmaxPREQretries) ||
4696 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4697 cur_params.path_refresh_time) ||
4698 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4699 cur_params.min_discovery_timeout) ||
4700 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4701 cur_params.dot11MeshHWMPactivePathTimeout) ||
4702 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4703 cur_params.dot11MeshHWMPpreqMinInterval) ||
4704 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4705 cur_params.dot11MeshHWMPperrMinInterval) ||
4706 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4707 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4708 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4709 cur_params.dot11MeshHWMPRootMode) ||
4710 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4711 cur_params.dot11MeshHWMPRannInterval) ||
4712 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4713 cur_params.dot11MeshGateAnnouncementProtocol) ||
4714 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4715 cur_params.dot11MeshForwarding) ||
4716 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004717 cur_params.rssi_threshold) ||
4718 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004719 cur_params.ht_opmode) ||
4720 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4721 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4722 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004723 cur_params.dot11MeshHWMProotInterval) ||
4724 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004725 cur_params.dot11MeshHWMPconfirmationInterval) ||
4726 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4727 cur_params.power_mode) ||
4728 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004729 cur_params.dot11MeshAwakeWindowDuration) ||
4730 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4731 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004732 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004733 nla_nest_end(msg, pinfoattr);
4734 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004735 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004736
Johannes Berg3b858752009-03-12 09:55:09 +01004737 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004738 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004739 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004740 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004741 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004742}
4743
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004744static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004745 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4746 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4747 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4748 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4749 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4750 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004751 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004752 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004753 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004754 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4755 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4756 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4757 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4758 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004759 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004760 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004761 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004762 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004763 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004764 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004765 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4766 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004767 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4768 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004769 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004770 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4771 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004772 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004773};
4774
Javier Cardonac80d5452010-12-16 17:37:49 -08004775static const struct nla_policy
4776 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004777 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004778 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4779 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004780 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004781 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004782 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004783 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004784 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004785 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004786};
4787
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004788static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004789 struct mesh_config *cfg,
4790 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004791{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004792 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004793 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004794
Marco Porschea54fba2013-01-07 16:04:48 +01004795#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4796do { \
4797 if (tb[attr]) { \
4798 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4799 return -EINVAL; \
4800 cfg->param = fn(tb[attr]); \
4801 mask |= (1 << (attr - 1)); \
4802 } \
4803} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004804
4805
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004806 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004807 return -EINVAL;
4808 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004809 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004810 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004811 return -EINVAL;
4812
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004813 /* This makes sure that there aren't more than 32 mesh config
4814 * parameters (otherwise our bitfield scheme would not work.) */
4815 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4816
4817 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004819 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4820 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004822 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4823 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004824 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004825 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4826 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004827 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004828 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4829 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004830 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004831 mask, NL80211_MESHCONF_MAX_RETRIES,
4832 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004834 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004835 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004836 mask, NL80211_MESHCONF_ELEMENT_TTL,
4837 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004838 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004839 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4840 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004841 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4842 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004843 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4844 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004845 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004846 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4847 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004848 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004849 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4850 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004851 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004852 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4853 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4855 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004856 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4857 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004858 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004859 1, 65535, mask,
4860 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004861 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004862 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004863 1, 65535, mask,
4864 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004865 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004866 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004867 dot11MeshHWMPnetDiameterTraversalTime,
4868 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004869 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4870 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004871 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4872 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4873 nla_get_u8);
4874 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4875 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004876 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004877 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004878 dot11MeshGateAnnouncementProtocol, 0, 1,
4879 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004880 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004882 mask, NL80211_MESHCONF_FORWARDING,
4883 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004885 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004886 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004888 mask, NL80211_MESHCONF_HT_OPMODE,
4889 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004891 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004892 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4893 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004895 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4896 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004897 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004898 dot11MeshHWMPconfirmationInterval,
4899 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004900 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4901 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4903 NL80211_MESH_POWER_ACTIVE,
4904 NL80211_MESH_POWER_MAX,
4905 mask, NL80211_MESHCONF_POWER_MODE,
4906 nla_get_u32);
4907 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4908 0, 65535, mask,
4909 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4911 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4912 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004913 if (mask_out)
4914 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004915
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004916 return 0;
4917
4918#undef FILL_IN_MESH_PARAM_IF_SET
4919}
4920
Javier Cardonac80d5452010-12-16 17:37:49 -08004921static int nl80211_parse_mesh_setup(struct genl_info *info,
4922 struct mesh_setup *setup)
4923{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004925 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4926
4927 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4928 return -EINVAL;
4929 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4930 info->attrs[NL80211_ATTR_MESH_SETUP],
4931 nl80211_mesh_setup_params_policy))
4932 return -EINVAL;
4933
Javier Cardonad299a1f2012-03-31 11:31:33 -07004934 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4935 setup->sync_method =
4936 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4937 IEEE80211_SYNC_METHOD_VENDOR :
4938 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4939
Javier Cardonac80d5452010-12-16 17:37:49 -08004940 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4941 setup->path_sel_proto =
4942 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4943 IEEE80211_PATH_PROTOCOL_VENDOR :
4944 IEEE80211_PATH_PROTOCOL_HWMP;
4945
4946 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4947 setup->path_metric =
4948 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4949 IEEE80211_PATH_METRIC_VENDOR :
4950 IEEE80211_PATH_METRIC_AIRTIME;
4951
Javier Cardona581a8b02011-04-07 15:08:27 -07004952
4953 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004954 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004955 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004956 if (!is_valid_ie_attr(ieattr))
4957 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004958 setup->ie = nla_data(ieattr);
4959 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004960 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004961 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4962 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4963 return -EINVAL;
4964 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004965 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4966 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004967 if (setup->is_secure)
4968 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004969
Colleen Twitty6e16d902013-05-08 11:45:59 -07004970 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4971 if (!setup->user_mpm)
4972 return -EINVAL;
4973 setup->auth_id =
4974 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4975 }
4976
Javier Cardonac80d5452010-12-16 17:37:49 -08004977 return 0;
4978}
4979
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004980static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004981 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004982{
4983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4984 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004985 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004986 struct mesh_config cfg;
4987 u32 mask;
4988 int err;
4989
Johannes Berg29cbe682010-12-03 09:20:44 +01004990 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4991 return -EOPNOTSUPP;
4992
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004993 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004994 return -EOPNOTSUPP;
4995
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004996 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004997 if (err)
4998 return err;
4999
Johannes Berg29cbe682010-12-03 09:20:44 +01005000 wdev_lock(wdev);
5001 if (!wdev->mesh_id_len)
5002 err = -ENOLINK;
5003
5004 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005005 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005006
5007 wdev_unlock(wdev);
5008
5009 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005010}
5011
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005012static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5013{
Johannes Berg458f4f92012-12-06 15:47:38 +01005014 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005015 struct sk_buff *msg;
5016 void *hdr = NULL;
5017 struct nlattr *nl_reg_rules;
5018 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005019
5020 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005021 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005022
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005023 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005024 if (!msg)
5025 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005026
Eric W. Biederman15e47302012-09-07 20:12:54 +00005027 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005028 NL80211_CMD_GET_REG);
5029 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005030 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005031
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005032 if (reg_last_request_cell_base() &&
5033 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5034 NL80211_USER_REG_HINT_CELL_BASE))
5035 goto nla_put_failure;
5036
Johannes Berg458f4f92012-12-06 15:47:38 +01005037 rcu_read_lock();
5038 regdom = rcu_dereference(cfg80211_regdomain);
5039
5040 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5041 (regdom->dfs_region &&
5042 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5043 goto nla_put_failure_rcu;
5044
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005045 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5046 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005047 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005048
Johannes Berg458f4f92012-12-06 15:47:38 +01005049 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005050 struct nlattr *nl_reg_rule;
5051 const struct ieee80211_reg_rule *reg_rule;
5052 const struct ieee80211_freq_range *freq_range;
5053 const struct ieee80211_power_rule *power_rule;
5054
Johannes Berg458f4f92012-12-06 15:47:38 +01005055 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005056 freq_range = &reg_rule->freq_range;
5057 power_rule = &reg_rule->power_rule;
5058
5059 nl_reg_rule = nla_nest_start(msg, i);
5060 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005061 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005062
David S. Miller9360ffd2012-03-29 04:41:26 -04005063 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5064 reg_rule->flags) ||
5065 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5066 freq_range->start_freq_khz) ||
5067 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5068 freq_range->end_freq_khz) ||
5069 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5070 freq_range->max_bandwidth_khz) ||
5071 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5072 power_rule->max_antenna_gain) ||
5073 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5074 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005075 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005076
5077 nla_nest_end(msg, nl_reg_rule);
5078 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005079 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005080
5081 nla_nest_end(msg, nl_reg_rules);
5082
5083 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005084 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005085
Johannes Berg458f4f92012-12-06 15:47:38 +01005086nla_put_failure_rcu:
5087 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005088nla_put_failure:
5089 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005090put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005091 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005092 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005093}
5094
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005095static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5096{
5097 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5098 struct nlattr *nl_reg_rule;
5099 char *alpha2 = NULL;
5100 int rem_reg_rules = 0, r = 0;
5101 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005102 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005103 struct ieee80211_regdomain *rd = NULL;
5104
5105 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5106 return -EINVAL;
5107
5108 if (!info->attrs[NL80211_ATTR_REG_RULES])
5109 return -EINVAL;
5110
5111 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5112
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005113 if (info->attrs[NL80211_ATTR_DFS_REGION])
5114 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5115
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005116 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005117 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005118 num_rules++;
5119 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005120 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005121 }
5122
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005123 if (!reg_is_valid_request(alpha2))
5124 return -EINVAL;
5125
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005126 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005127 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005128
5129 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005130 if (!rd)
5131 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005132
5133 rd->n_reg_rules = num_rules;
5134 rd->alpha2[0] = alpha2[0];
5135 rd->alpha2[1] = alpha2[1];
5136
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005137 /*
5138 * Disable DFS master mode if the DFS region was
5139 * not supported or known on this kernel.
5140 */
5141 if (reg_supported_dfs_region(dfs_region))
5142 rd->dfs_region = dfs_region;
5143
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005144 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005145 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005146 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005147 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5148 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005149 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5150 if (r)
5151 goto bad_reg;
5152
5153 rule_idx++;
5154
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005155 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5156 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005157 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005158 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005159 }
5160
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005161 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005162 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005163 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005164
Johannes Bergd2372b32008-10-24 20:32:20 +02005165 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005166 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005167 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005168}
5169
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005170static int validate_scan_freqs(struct nlattr *freqs)
5171{
5172 struct nlattr *attr1, *attr2;
5173 int n_channels = 0, tmp1, tmp2;
5174
5175 nla_for_each_nested(attr1, freqs, tmp1) {
5176 n_channels++;
5177 /*
5178 * Some hardware has a limited channel list for
5179 * scanning, and it is pretty much nonsensical
5180 * to scan for a channel twice, so disallow that
5181 * and don't require drivers to check that the
5182 * channel list they get isn't longer than what
5183 * they can scan, as long as they can scan all
5184 * the channels they registered at once.
5185 */
5186 nla_for_each_nested(attr2, freqs, tmp2)
5187 if (attr1 != attr2 &&
5188 nla_get_u32(attr1) == nla_get_u32(attr2))
5189 return 0;
5190 }
5191
5192 return n_channels;
5193}
5194
Johannes Berg2a519312009-02-10 21:25:55 +01005195static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5196{
Johannes Berg4c476992010-10-04 21:36:35 +02005197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005198 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005199 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005200 struct nlattr *attr;
5201 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005202 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005203 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005204
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005205 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5206 return -EINVAL;
5207
Johannes Berg79c97e92009-07-07 03:56:12 +02005208 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005209
Johannes Berg4c476992010-10-04 21:36:35 +02005210 if (!rdev->ops->scan)
5211 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005212
Johannes Bergf9f47522013-03-19 15:04:07 +01005213 if (rdev->scan_req) {
5214 err = -EBUSY;
5215 goto unlock;
5216 }
Johannes Berg2a519312009-02-10 21:25:55 +01005217
5218 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005219 n_channels = validate_scan_freqs(
5220 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005221 if (!n_channels) {
5222 err = -EINVAL;
5223 goto unlock;
5224 }
Johannes Berg2a519312009-02-10 21:25:55 +01005225 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005226 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005227 n_channels = 0;
5228
Johannes Berg2a519312009-02-10 21:25:55 +01005229 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5230 if (wiphy->bands[band])
5231 n_channels += wiphy->bands[band]->n_channels;
5232 }
5233
5234 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5235 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5236 n_ssids++;
5237
Johannes Bergf9f47522013-03-19 15:04:07 +01005238 if (n_ssids > wiphy->max_scan_ssids) {
5239 err = -EINVAL;
5240 goto unlock;
5241 }
Johannes Berg2a519312009-02-10 21:25:55 +01005242
Jouni Malinen70692ad2009-02-16 19:39:13 +02005243 if (info->attrs[NL80211_ATTR_IE])
5244 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5245 else
5246 ie_len = 0;
5247
Johannes Bergf9f47522013-03-19 15:04:07 +01005248 if (ie_len > wiphy->max_scan_ie_len) {
5249 err = -EINVAL;
5250 goto unlock;
5251 }
Johannes Berg18a83652009-03-31 12:12:05 +02005252
Johannes Berg2a519312009-02-10 21:25:55 +01005253 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005254 + sizeof(*request->ssids) * n_ssids
5255 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005256 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005257 if (!request) {
5258 err = -ENOMEM;
5259 goto unlock;
5260 }
Johannes Berg2a519312009-02-10 21:25:55 +01005261
Johannes Berg2a519312009-02-10 21:25:55 +01005262 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005263 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005264 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005265 if (ie_len) {
5266 if (request->ssids)
5267 request->ie = (void *)(request->ssids + n_ssids);
5268 else
5269 request->ie = (void *)(request->channels + n_channels);
5270 }
Johannes Berg2a519312009-02-10 21:25:55 +01005271
Johannes Berg584991d2009-11-02 13:32:03 +01005272 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005273 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5274 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005275 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005276 struct ieee80211_channel *chan;
5277
5278 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5279
5280 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005281 err = -EINVAL;
5282 goto out_free;
5283 }
Johannes Berg584991d2009-11-02 13:32:03 +01005284
5285 /* ignore disabled channels */
5286 if (chan->flags & IEEE80211_CHAN_DISABLED)
5287 continue;
5288
5289 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005290 i++;
5291 }
5292 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005293 enum ieee80211_band band;
5294
Johannes Berg2a519312009-02-10 21:25:55 +01005295 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005296 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5297 int j;
5298 if (!wiphy->bands[band])
5299 continue;
5300 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005301 struct ieee80211_channel *chan;
5302
5303 chan = &wiphy->bands[band]->channels[j];
5304
5305 if (chan->flags & IEEE80211_CHAN_DISABLED)
5306 continue;
5307
5308 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005309 i++;
5310 }
5311 }
5312 }
5313
Johannes Berg584991d2009-11-02 13:32:03 +01005314 if (!i) {
5315 err = -EINVAL;
5316 goto out_free;
5317 }
5318
5319 request->n_channels = i;
5320
Johannes Berg2a519312009-02-10 21:25:55 +01005321 i = 0;
5322 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5323 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005324 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005325 err = -EINVAL;
5326 goto out_free;
5327 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005328 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005329 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005330 i++;
5331 }
5332 }
5333
Jouni Malinen70692ad2009-02-16 19:39:13 +02005334 if (info->attrs[NL80211_ATTR_IE]) {
5335 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005336 memcpy((void *)request->ie,
5337 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005338 request->ie_len);
5339 }
5340
Johannes Berg34850ab2011-07-18 18:08:35 +02005341 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005342 if (wiphy->bands[i])
5343 request->rates[i] =
5344 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005345
5346 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5347 nla_for_each_nested(attr,
5348 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5349 tmp) {
5350 enum ieee80211_band band = nla_type(attr);
5351
Dan Carpenter84404622011-07-29 11:52:18 +03005352 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005353 err = -EINVAL;
5354 goto out_free;
5355 }
5356 err = ieee80211_get_ratemask(wiphy->bands[band],
5357 nla_data(attr),
5358 nla_len(attr),
5359 &request->rates[band]);
5360 if (err)
5361 goto out_free;
5362 }
5363 }
5364
Sam Leffler46856bb2012-10-11 21:03:32 -07005365 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005366 request->flags = nla_get_u32(
5367 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005368 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5369 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005370 err = -EOPNOTSUPP;
5371 goto out_free;
5372 }
5373 }
Sam Lefflered4737712012-10-11 21:03:31 -07005374
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305375 request->no_cck =
5376 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5377
Johannes Bergfd014282012-06-18 19:17:03 +02005378 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005379 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005380 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005381
Johannes Berg79c97e92009-07-07 03:56:12 +02005382 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005383 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005384
Johannes Berg463d0182009-07-14 00:33:35 +02005385 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005386 nl80211_send_scan_start(rdev, wdev);
5387 if (wdev->netdev)
5388 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005389 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005390 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005391 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005392 kfree(request);
5393 }
Johannes Berg3b858752009-03-12 09:55:09 +01005394
Johannes Bergf9f47522013-03-19 15:04:07 +01005395 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005396 return err;
5397}
5398
Luciano Coelho807f8a82011-05-11 17:09:35 +03005399static int nl80211_start_sched_scan(struct sk_buff *skb,
5400 struct genl_info *info)
5401{
5402 struct cfg80211_sched_scan_request *request;
5403 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5404 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005405 struct nlattr *attr;
5406 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005407 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005408 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005409 enum ieee80211_band band;
5410 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005411 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005412
5413 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5414 !rdev->ops->sched_scan_start)
5415 return -EOPNOTSUPP;
5416
5417 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5418 return -EINVAL;
5419
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005420 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5421 return -EINVAL;
5422
5423 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5424 if (interval == 0)
5425 return -EINVAL;
5426
Luciano Coelho807f8a82011-05-11 17:09:35 +03005427 wiphy = &rdev->wiphy;
5428
5429 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5430 n_channels = validate_scan_freqs(
5431 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5432 if (!n_channels)
5433 return -EINVAL;
5434 } else {
5435 n_channels = 0;
5436
5437 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5438 if (wiphy->bands[band])
5439 n_channels += wiphy->bands[band]->n_channels;
5440 }
5441
5442 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5443 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5444 tmp)
5445 n_ssids++;
5446
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005447 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005448 return -EINVAL;
5449
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005450 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5451 nla_for_each_nested(attr,
5452 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5453 tmp)
5454 n_match_sets++;
5455
5456 if (n_match_sets > wiphy->max_match_sets)
5457 return -EINVAL;
5458
Luciano Coelho807f8a82011-05-11 17:09:35 +03005459 if (info->attrs[NL80211_ATTR_IE])
5460 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5461 else
5462 ie_len = 0;
5463
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005464 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005465 return -EINVAL;
5466
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005467 if (rdev->sched_scan_req) {
5468 err = -EINPROGRESS;
5469 goto out;
5470 }
5471
Luciano Coelho807f8a82011-05-11 17:09:35 +03005472 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005473 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005474 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005475 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005476 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005477 if (!request) {
5478 err = -ENOMEM;
5479 goto out;
5480 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005481
5482 if (n_ssids)
5483 request->ssids = (void *)&request->channels[n_channels];
5484 request->n_ssids = n_ssids;
5485 if (ie_len) {
5486 if (request->ssids)
5487 request->ie = (void *)(request->ssids + n_ssids);
5488 else
5489 request->ie = (void *)(request->channels + n_channels);
5490 }
5491
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005492 if (n_match_sets) {
5493 if (request->ie)
5494 request->match_sets = (void *)(request->ie + ie_len);
5495 else if (request->ssids)
5496 request->match_sets =
5497 (void *)(request->ssids + n_ssids);
5498 else
5499 request->match_sets =
5500 (void *)(request->channels + n_channels);
5501 }
5502 request->n_match_sets = n_match_sets;
5503
Luciano Coelho807f8a82011-05-11 17:09:35 +03005504 i = 0;
5505 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5506 /* user specified, bail out if channel not found */
5507 nla_for_each_nested(attr,
5508 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5509 tmp) {
5510 struct ieee80211_channel *chan;
5511
5512 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5513
5514 if (!chan) {
5515 err = -EINVAL;
5516 goto out_free;
5517 }
5518
5519 /* ignore disabled channels */
5520 if (chan->flags & IEEE80211_CHAN_DISABLED)
5521 continue;
5522
5523 request->channels[i] = chan;
5524 i++;
5525 }
5526 } else {
5527 /* all channels */
5528 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5529 int j;
5530 if (!wiphy->bands[band])
5531 continue;
5532 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5533 struct ieee80211_channel *chan;
5534
5535 chan = &wiphy->bands[band]->channels[j];
5536
5537 if (chan->flags & IEEE80211_CHAN_DISABLED)
5538 continue;
5539
5540 request->channels[i] = chan;
5541 i++;
5542 }
5543 }
5544 }
5545
5546 if (!i) {
5547 err = -EINVAL;
5548 goto out_free;
5549 }
5550
5551 request->n_channels = i;
5552
5553 i = 0;
5554 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5555 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5556 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005557 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005558 err = -EINVAL;
5559 goto out_free;
5560 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005561 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005562 memcpy(request->ssids[i].ssid, nla_data(attr),
5563 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005564 i++;
5565 }
5566 }
5567
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005568 i = 0;
5569 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5570 nla_for_each_nested(attr,
5571 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5572 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005573 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005574
5575 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5576 nla_data(attr), nla_len(attr),
5577 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005578 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005579 if (ssid) {
5580 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5581 err = -EINVAL;
5582 goto out_free;
5583 }
5584 memcpy(request->match_sets[i].ssid.ssid,
5585 nla_data(ssid), nla_len(ssid));
5586 request->match_sets[i].ssid.ssid_len =
5587 nla_len(ssid);
5588 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005589 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5590 if (rssi)
5591 request->rssi_thold = nla_get_u32(rssi);
5592 else
5593 request->rssi_thold =
5594 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005595 i++;
5596 }
5597 }
5598
Luciano Coelho807f8a82011-05-11 17:09:35 +03005599 if (info->attrs[NL80211_ATTR_IE]) {
5600 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5601 memcpy((void *)request->ie,
5602 nla_data(info->attrs[NL80211_ATTR_IE]),
5603 request->ie_len);
5604 }
5605
Sam Leffler46856bb2012-10-11 21:03:32 -07005606 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005607 request->flags = nla_get_u32(
5608 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005609 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5610 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005611 err = -EOPNOTSUPP;
5612 goto out_free;
5613 }
5614 }
Sam Lefflered4737712012-10-11 21:03:31 -07005615
Luciano Coelho807f8a82011-05-11 17:09:35 +03005616 request->dev = dev;
5617 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005618 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005619 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005620
Hila Gonene35e4d22012-06-27 17:19:42 +03005621 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005622 if (!err) {
5623 rdev->sched_scan_req = request;
5624 nl80211_send_sched_scan(rdev, dev,
5625 NL80211_CMD_START_SCHED_SCAN);
5626 goto out;
5627 }
5628
5629out_free:
5630 kfree(request);
5631out:
5632 return err;
5633}
5634
5635static int nl80211_stop_sched_scan(struct sk_buff *skb,
5636 struct genl_info *info)
5637{
5638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5639
5640 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5641 !rdev->ops->sched_scan_stop)
5642 return -EOPNOTSUPP;
5643
Johannes Berg5fe231e2013-05-08 21:45:15 +02005644 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005645}
5646
Simon Wunderlich04f39042013-02-08 18:16:19 +01005647static int nl80211_start_radar_detection(struct sk_buff *skb,
5648 struct genl_info *info)
5649{
5650 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5651 struct net_device *dev = info->user_ptr[1];
5652 struct wireless_dev *wdev = dev->ieee80211_ptr;
5653 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005654 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005655 int err;
5656
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005657 dfs_region = reg_get_dfs_region(wdev->wiphy);
5658 if (dfs_region == NL80211_DFS_UNSET)
5659 return -EINVAL;
5660
Simon Wunderlich04f39042013-02-08 18:16:19 +01005661 err = nl80211_parse_chandef(rdev, info, &chandef);
5662 if (err)
5663 return err;
5664
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005665 if (netif_carrier_ok(dev))
5666 return -EBUSY;
5667
Simon Wunderlich04f39042013-02-08 18:16:19 +01005668 if (wdev->cac_started)
5669 return -EBUSY;
5670
5671 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5672 if (err < 0)
5673 return err;
5674
5675 if (err == 0)
5676 return -EINVAL;
5677
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005678 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005679 return -EINVAL;
5680
5681 if (!rdev->ops->start_radar_detection)
5682 return -EOPNOTSUPP;
5683
Simon Wunderlich04f39042013-02-08 18:16:19 +01005684 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5685 chandef.chan, CHAN_MODE_SHARED,
5686 BIT(chandef.width));
5687 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005688 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005689
5690 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5691 if (!err) {
5692 wdev->channel = chandef.chan;
5693 wdev->cac_started = true;
5694 wdev->cac_start_time = jiffies;
5695 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005696 return err;
5697}
5698
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005699static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5700{
5701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5702 struct net_device *dev = info->user_ptr[1];
5703 struct wireless_dev *wdev = dev->ieee80211_ptr;
5704 struct cfg80211_csa_settings params;
5705 /* csa_attrs is defined static to avoid waste of stack size - this
5706 * function is called under RTNL lock, so this should not be a problem.
5707 */
5708 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5709 u8 radar_detect_width = 0;
5710 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005711 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005712
5713 if (!rdev->ops->channel_switch ||
5714 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5715 return -EOPNOTSUPP;
5716
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005717 switch (dev->ieee80211_ptr->iftype) {
5718 case NL80211_IFTYPE_AP:
5719 case NL80211_IFTYPE_P2P_GO:
5720 need_new_beacon = true;
5721
5722 /* useless if AP is not running */
5723 if (!wdev->beacon_interval)
5724 return -EINVAL;
5725 break;
5726 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005727 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005728 break;
5729 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005730 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005731 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005732
5733 memset(&params, 0, sizeof(params));
5734
5735 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5736 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5737 return -EINVAL;
5738
5739 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005740 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005741 return -EINVAL;
5742
5743 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5744
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005745 if (!need_new_beacon)
5746 goto skip_beacons;
5747
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005748 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5749 if (err)
5750 return err;
5751
5752 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5753 info->attrs[NL80211_ATTR_CSA_IES],
5754 nl80211_policy);
5755 if (err)
5756 return err;
5757
5758 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5759 if (err)
5760 return err;
5761
5762 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5763 return -EINVAL;
5764
5765 params.counter_offset_beacon =
5766 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5767 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5768 return -EINVAL;
5769
5770 /* sanity check - counters should be the same */
5771 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5772 params.count)
5773 return -EINVAL;
5774
5775 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5776 params.counter_offset_presp =
5777 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5778 if (params.counter_offset_presp >=
5779 params.beacon_csa.probe_resp_len)
5780 return -EINVAL;
5781
5782 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5783 params.count)
5784 return -EINVAL;
5785 }
5786
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005787skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005788 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5789 if (err)
5790 return err;
5791
5792 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5793 return -EINVAL;
5794
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005795 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005796 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5797 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005798 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5799 &params.chandef);
5800 if (err < 0) {
5801 return err;
5802 } else if (err) {
5803 radar_detect_width = BIT(params.chandef.width);
5804 params.radar_required = true;
5805 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005806 }
5807
5808 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5809 params.chandef.chan,
5810 CHAN_MODE_SHARED,
5811 radar_detect_width);
5812 if (err)
5813 return err;
5814
5815 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5816 params.block_tx = true;
5817
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005818 wdev_lock(wdev);
5819 err = rdev_channel_switch(rdev, dev, &params);
5820 wdev_unlock(wdev);
5821
5822 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005823}
5824
Johannes Berg9720bb32011-06-21 09:45:33 +02005825static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5826 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005827 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005828 struct wireless_dev *wdev,
5829 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005830{
Johannes Berg48ab9052009-07-10 18:42:31 +02005831 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005832 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005833 void *hdr;
5834 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005835 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005836
5837 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005838
Eric W. Biederman15e47302012-09-07 20:12:54 +00005839 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005840 NL80211_CMD_NEW_SCAN_RESULTS);
5841 if (!hdr)
5842 return -1;
5843
Johannes Berg9720bb32011-06-21 09:45:33 +02005844 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5845
Johannes Berg97990a02013-04-19 01:02:55 +02005846 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5847 goto nla_put_failure;
5848 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005849 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5850 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005851 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5852 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005853
5854 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5855 if (!bss)
5856 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005857 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005858 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005859 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005860
5861 rcu_read_lock();
5862 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005863 if (ies) {
5864 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5865 goto fail_unlock_rcu;
5866 tsf = true;
5867 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5868 ies->len, ies->data))
5869 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005870 }
5871 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005872 if (ies) {
5873 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5874 goto fail_unlock_rcu;
5875 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5876 ies->len, ies->data))
5877 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005878 }
5879 rcu_read_unlock();
5880
David S. Miller9360ffd2012-03-29 04:41:26 -04005881 if (res->beacon_interval &&
5882 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5883 goto nla_put_failure;
5884 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5885 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005886 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005887 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5888 jiffies_to_msecs(jiffies - intbss->ts)))
5889 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005890
Johannes Berg77965c92009-02-18 18:45:06 +01005891 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005892 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005893 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5894 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005895 break;
5896 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005897 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5898 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005899 break;
5900 default:
5901 break;
5902 }
5903
Johannes Berg48ab9052009-07-10 18:42:31 +02005904 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005905 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005906 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005907 if (intbss == wdev->current_bss &&
5908 nla_put_u32(msg, NL80211_BSS_STATUS,
5909 NL80211_BSS_STATUS_ASSOCIATED))
5910 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005911 break;
5912 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005913 if (intbss == wdev->current_bss &&
5914 nla_put_u32(msg, NL80211_BSS_STATUS,
5915 NL80211_BSS_STATUS_IBSS_JOINED))
5916 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005917 break;
5918 default:
5919 break;
5920 }
5921
Johannes Berg2a519312009-02-10 21:25:55 +01005922 nla_nest_end(msg, bss);
5923
5924 return genlmsg_end(msg, hdr);
5925
Johannes Berg8cef2c92013-02-05 16:54:31 +01005926 fail_unlock_rcu:
5927 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005928 nla_put_failure:
5929 genlmsg_cancel(msg, hdr);
5930 return -EMSGSIZE;
5931}
5932
Johannes Berg97990a02013-04-19 01:02:55 +02005933static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005934{
Johannes Berg48ab9052009-07-10 18:42:31 +02005935 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005936 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005937 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005938 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005939 int err;
5940
Johannes Berg97990a02013-04-19 01:02:55 +02005941 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005942 if (err)
5943 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005944
Johannes Berg48ab9052009-07-10 18:42:31 +02005945 wdev_lock(wdev);
5946 spin_lock_bh(&rdev->bss_lock);
5947 cfg80211_bss_expire(rdev);
5948
Johannes Berg9720bb32011-06-21 09:45:33 +02005949 cb->seq = rdev->bss_generation;
5950
Johannes Berg48ab9052009-07-10 18:42:31 +02005951 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005952 if (++idx <= start)
5953 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005954 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005955 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005956 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005957 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005958 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005959 }
5960 }
5961
Johannes Berg48ab9052009-07-10 18:42:31 +02005962 spin_unlock_bh(&rdev->bss_lock);
5963 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005964
Johannes Berg97990a02013-04-19 01:02:55 +02005965 cb->args[2] = idx;
5966 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005967
Johannes Berg67748892010-10-04 21:14:06 +02005968 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005969}
5970
Eric W. Biederman15e47302012-09-07 20:12:54 +00005971static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005972 int flags, struct net_device *dev,
5973 struct survey_info *survey)
5974{
5975 void *hdr;
5976 struct nlattr *infoattr;
5977
Eric W. Biederman15e47302012-09-07 20:12:54 +00005978 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005979 NL80211_CMD_NEW_SURVEY_RESULTS);
5980 if (!hdr)
5981 return -ENOMEM;
5982
David S. Miller9360ffd2012-03-29 04:41:26 -04005983 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5984 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005985
5986 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5987 if (!infoattr)
5988 goto nla_put_failure;
5989
David S. Miller9360ffd2012-03-29 04:41:26 -04005990 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5991 survey->channel->center_freq))
5992 goto nla_put_failure;
5993
5994 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5995 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5996 goto nla_put_failure;
5997 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5998 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5999 goto nla_put_failure;
6000 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6001 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6002 survey->channel_time))
6003 goto nla_put_failure;
6004 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6005 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6006 survey->channel_time_busy))
6007 goto nla_put_failure;
6008 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6009 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6010 survey->channel_time_ext_busy))
6011 goto nla_put_failure;
6012 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6013 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6014 survey->channel_time_rx))
6015 goto nla_put_failure;
6016 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6017 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6018 survey->channel_time_tx))
6019 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006020
6021 nla_nest_end(msg, infoattr);
6022
6023 return genlmsg_end(msg, hdr);
6024
6025 nla_put_failure:
6026 genlmsg_cancel(msg, hdr);
6027 return -EMSGSIZE;
6028}
6029
6030static int nl80211_dump_survey(struct sk_buff *skb,
6031 struct netlink_callback *cb)
6032{
6033 struct survey_info survey;
6034 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006035 struct wireless_dev *wdev;
6036 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006037 int res;
6038
Johannes Berg97990a02013-04-19 01:02:55 +02006039 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006040 if (res)
6041 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006042
Johannes Berg97990a02013-04-19 01:02:55 +02006043 if (!wdev->netdev) {
6044 res = -EINVAL;
6045 goto out_err;
6046 }
6047
Holger Schurig61fa7132009-11-11 12:25:40 +01006048 if (!dev->ops->dump_survey) {
6049 res = -EOPNOTSUPP;
6050 goto out_err;
6051 }
6052
6053 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006054 struct ieee80211_channel *chan;
6055
Johannes Berg97990a02013-04-19 01:02:55 +02006056 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006057 if (res == -ENOENT)
6058 break;
6059 if (res)
6060 goto out_err;
6061
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006062 /* Survey without a channel doesn't make sense */
6063 if (!survey.channel) {
6064 res = -EINVAL;
6065 goto out;
6066 }
6067
6068 chan = ieee80211_get_channel(&dev->wiphy,
6069 survey.channel->center_freq);
6070 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6071 survey_idx++;
6072 continue;
6073 }
6074
Holger Schurig61fa7132009-11-11 12:25:40 +01006075 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006076 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006077 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006078 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006079 goto out;
6080 survey_idx++;
6081 }
6082
6083 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006084 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006085 res = skb->len;
6086 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006087 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006088 return res;
6089}
6090
Samuel Ortizb23aa672009-07-01 21:26:54 +02006091static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6092{
6093 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6094 NL80211_WPA_VERSION_2));
6095}
6096
Jouni Malinen636a5d32009-03-19 13:39:22 +02006097static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6098{
Johannes Berg4c476992010-10-04 21:36:35 +02006099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6100 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006101 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006102 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6103 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006104 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006105 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006106 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006107
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006108 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6109 return -EINVAL;
6110
6111 if (!info->attrs[NL80211_ATTR_MAC])
6112 return -EINVAL;
6113
Jouni Malinen17780922009-03-27 20:52:47 +02006114 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6115 return -EINVAL;
6116
Johannes Berg19957bb2009-07-02 17:20:43 +02006117 if (!info->attrs[NL80211_ATTR_SSID])
6118 return -EINVAL;
6119
6120 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6121 return -EINVAL;
6122
Johannes Bergfffd0932009-07-08 14:22:54 +02006123 err = nl80211_parse_key(info, &key);
6124 if (err)
6125 return err;
6126
6127 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006128 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6129 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006130 if (!key.p.key || !key.p.key_len)
6131 return -EINVAL;
6132 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6133 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6134 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6135 key.p.key_len != WLAN_KEY_LEN_WEP104))
6136 return -EINVAL;
6137 if (key.idx > 4)
6138 return -EINVAL;
6139 } else {
6140 key.p.key_len = 0;
6141 key.p.key = NULL;
6142 }
6143
Johannes Bergafea0b72010-08-10 09:46:42 +02006144 if (key.idx >= 0) {
6145 int i;
6146 bool ok = false;
6147 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6148 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6149 ok = true;
6150 break;
6151 }
6152 }
Johannes Berg4c476992010-10-04 21:36:35 +02006153 if (!ok)
6154 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006155 }
6156
Johannes Berg4c476992010-10-04 21:36:35 +02006157 if (!rdev->ops->auth)
6158 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006159
Johannes Berg074ac8d2010-09-16 14:58:22 +02006160 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006161 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6162 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006163
Johannes Berg19957bb2009-07-02 17:20:43 +02006164 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006165 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006166 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006167 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6168 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006169
Johannes Berg19957bb2009-07-02 17:20:43 +02006170 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6171 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6172
6173 if (info->attrs[NL80211_ATTR_IE]) {
6174 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6175 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6176 }
6177
6178 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006179 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006180 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006181
Jouni Malinene39e5b52012-09-30 19:29:39 +03006182 if (auth_type == NL80211_AUTHTYPE_SAE &&
6183 !info->attrs[NL80211_ATTR_SAE_DATA])
6184 return -EINVAL;
6185
6186 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6187 if (auth_type != NL80211_AUTHTYPE_SAE)
6188 return -EINVAL;
6189 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6190 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6191 /* need to include at least Auth Transaction and Status Code */
6192 if (sae_data_len < 4)
6193 return -EINVAL;
6194 }
6195
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006196 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6197
Johannes Berg95de8172012-01-20 13:55:25 +01006198 /*
6199 * Since we no longer track auth state, ignore
6200 * requests to only change local state.
6201 */
6202 if (local_state_change)
6203 return 0;
6204
Johannes Berg91bf9b22013-05-15 17:44:01 +02006205 wdev_lock(dev->ieee80211_ptr);
6206 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6207 ssid, ssid_len, ie, ie_len,
6208 key.p.key, key.p.key_len, key.idx,
6209 sae_data, sae_data_len);
6210 wdev_unlock(dev->ieee80211_ptr);
6211 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006212}
6213
Johannes Bergc0692b82010-08-27 14:26:53 +03006214static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6215 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006216 struct cfg80211_crypto_settings *settings,
6217 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006218{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006219 memset(settings, 0, sizeof(*settings));
6220
Samuel Ortizb23aa672009-07-01 21:26:54 +02006221 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6222
Johannes Bergc0692b82010-08-27 14:26:53 +03006223 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6224 u16 proto;
6225 proto = nla_get_u16(
6226 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6227 settings->control_port_ethertype = cpu_to_be16(proto);
6228 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6229 proto != ETH_P_PAE)
6230 return -EINVAL;
6231 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6232 settings->control_port_no_encrypt = true;
6233 } else
6234 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6235
Samuel Ortizb23aa672009-07-01 21:26:54 +02006236 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6237 void *data;
6238 int len, i;
6239
6240 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6241 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6242 settings->n_ciphers_pairwise = len / sizeof(u32);
6243
6244 if (len % sizeof(u32))
6245 return -EINVAL;
6246
Johannes Berg3dc27d22009-07-02 21:36:37 +02006247 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006248 return -EINVAL;
6249
6250 memcpy(settings->ciphers_pairwise, data, len);
6251
6252 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006253 if (!cfg80211_supported_cipher_suite(
6254 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006255 settings->ciphers_pairwise[i]))
6256 return -EINVAL;
6257 }
6258
6259 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6260 settings->cipher_group =
6261 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006262 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6263 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006264 return -EINVAL;
6265 }
6266
6267 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6268 settings->wpa_versions =
6269 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6270 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6271 return -EINVAL;
6272 }
6273
6274 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6275 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006276 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006277
6278 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6279 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6280 settings->n_akm_suites = len / sizeof(u32);
6281
6282 if (len % sizeof(u32))
6283 return -EINVAL;
6284
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006285 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6286 return -EINVAL;
6287
Samuel Ortizb23aa672009-07-01 21:26:54 +02006288 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006289 }
6290
6291 return 0;
6292}
6293
Jouni Malinen636a5d32009-03-19 13:39:22 +02006294static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6295{
Johannes Berg4c476992010-10-04 21:36:35 +02006296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6297 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006298 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006299 struct cfg80211_assoc_request req = {};
6300 const u8 *bssid, *ssid;
6301 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006302
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006303 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6304 return -EINVAL;
6305
6306 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006307 !info->attrs[NL80211_ATTR_SSID] ||
6308 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006309 return -EINVAL;
6310
Johannes Berg4c476992010-10-04 21:36:35 +02006311 if (!rdev->ops->assoc)
6312 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006313
Johannes Berg074ac8d2010-09-16 14:58:22 +02006314 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006315 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6316 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006317
Johannes Berg19957bb2009-07-02 17:20:43 +02006318 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006319
Johannes Berg19957bb2009-07-02 17:20:43 +02006320 chan = ieee80211_get_channel(&rdev->wiphy,
6321 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006322 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6323 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006324
Johannes Berg19957bb2009-07-02 17:20:43 +02006325 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6326 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006327
6328 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006329 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6330 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006331 }
6332
Jouni Malinendc6382c2009-05-06 22:09:37 +03006333 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006334 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006335 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006336 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006337 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006338 else if (mfp != NL80211_MFP_NO)
6339 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006340 }
6341
Johannes Berg3e5d7642009-07-07 14:37:26 +02006342 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006343 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006344
Ben Greear7e7c8922011-11-18 11:31:59 -08006345 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006346 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006347
6348 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006349 memcpy(&req.ht_capa_mask,
6350 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6351 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006352
6353 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006354 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006355 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006356 memcpy(&req.ht_capa,
6357 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6358 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006359 }
6360
Johannes Bergee2aca32013-02-21 17:36:01 +01006361 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006362 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006363
6364 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006365 memcpy(&req.vht_capa_mask,
6366 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6367 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006368
6369 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006370 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006371 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006372 memcpy(&req.vht_capa,
6373 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6374 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006375 }
6376
Johannes Bergf62fab72013-02-21 20:09:09 +01006377 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006378 if (!err) {
6379 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006380 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6381 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006382 wdev_unlock(dev->ieee80211_ptr);
6383 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006384
Jouni Malinen636a5d32009-03-19 13:39:22 +02006385 return err;
6386}
6387
6388static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6389{
Johannes Berg4c476992010-10-04 21:36:35 +02006390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6391 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006392 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006393 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006394 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006395 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006396
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006397 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6398 return -EINVAL;
6399
6400 if (!info->attrs[NL80211_ATTR_MAC])
6401 return -EINVAL;
6402
6403 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6404 return -EINVAL;
6405
Johannes Berg4c476992010-10-04 21:36:35 +02006406 if (!rdev->ops->deauth)
6407 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006408
Johannes Berg074ac8d2010-09-16 14:58:22 +02006409 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006410 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6411 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006412
Johannes Berg19957bb2009-07-02 17:20:43 +02006413 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006414
Johannes Berg19957bb2009-07-02 17:20:43 +02006415 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6416 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006417 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006418 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006419 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006420
6421 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006422 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6423 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006424 }
6425
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006426 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6427
Johannes Berg91bf9b22013-05-15 17:44:01 +02006428 wdev_lock(dev->ieee80211_ptr);
6429 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6430 local_state_change);
6431 wdev_unlock(dev->ieee80211_ptr);
6432 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006433}
6434
6435static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6436{
Johannes Berg4c476992010-10-04 21:36:35 +02006437 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6438 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006439 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006440 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006441 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006442 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006443
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006444 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6445 return -EINVAL;
6446
6447 if (!info->attrs[NL80211_ATTR_MAC])
6448 return -EINVAL;
6449
6450 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6451 return -EINVAL;
6452
Johannes Berg4c476992010-10-04 21:36:35 +02006453 if (!rdev->ops->disassoc)
6454 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006455
Johannes Berg074ac8d2010-09-16 14:58:22 +02006456 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006457 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6458 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006459
Johannes Berg19957bb2009-07-02 17:20:43 +02006460 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006461
Johannes Berg19957bb2009-07-02 17:20:43 +02006462 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6463 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006464 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006465 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006466 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006467
6468 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006469 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6470 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006471 }
6472
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006473 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6474
Johannes Berg91bf9b22013-05-15 17:44:01 +02006475 wdev_lock(dev->ieee80211_ptr);
6476 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6477 local_state_change);
6478 wdev_unlock(dev->ieee80211_ptr);
6479 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006480}
6481
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006482static bool
6483nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6484 int mcast_rate[IEEE80211_NUM_BANDS],
6485 int rateval)
6486{
6487 struct wiphy *wiphy = &rdev->wiphy;
6488 bool found = false;
6489 int band, i;
6490
6491 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6492 struct ieee80211_supported_band *sband;
6493
6494 sband = wiphy->bands[band];
6495 if (!sband)
6496 continue;
6497
6498 for (i = 0; i < sband->n_bitrates; i++) {
6499 if (sband->bitrates[i].bitrate == rateval) {
6500 mcast_rate[band] = i + 1;
6501 found = true;
6502 break;
6503 }
6504 }
6505 }
6506
6507 return found;
6508}
6509
Johannes Berg04a773a2009-04-19 21:24:32 +02006510static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6511{
Johannes Berg4c476992010-10-04 21:36:35 +02006512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6513 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006514 struct cfg80211_ibss_params ibss;
6515 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006516 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006517 int err;
6518
Johannes Berg8e30bc52009-04-22 17:45:38 +02006519 memset(&ibss, 0, sizeof(ibss));
6520
Johannes Berg04a773a2009-04-19 21:24:32 +02006521 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6522 return -EINVAL;
6523
Johannes Berg683b6d32012-11-08 21:25:48 +01006524 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006525 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6526 return -EINVAL;
6527
Johannes Berg8e30bc52009-04-22 17:45:38 +02006528 ibss.beacon_interval = 100;
6529
6530 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6531 ibss.beacon_interval =
6532 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6533 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6534 return -EINVAL;
6535 }
6536
Johannes Berg4c476992010-10-04 21:36:35 +02006537 if (!rdev->ops->join_ibss)
6538 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006539
Johannes Berg4c476992010-10-04 21:36:35 +02006540 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6541 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006542
Johannes Berg79c97e92009-07-07 03:56:12 +02006543 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006544
Johannes Berg39193492011-09-16 13:45:25 +02006545 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006546 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006547
6548 if (!is_valid_ether_addr(ibss.bssid))
6549 return -EINVAL;
6550 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006551 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6552 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6553
6554 if (info->attrs[NL80211_ATTR_IE]) {
6555 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6556 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6557 }
6558
Johannes Berg683b6d32012-11-08 21:25:48 +01006559 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6560 if (err)
6561 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006562
Johannes Berg683b6d32012-11-08 21:25:48 +01006563 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006564 return -EINVAL;
6565
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006566 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006567 case NL80211_CHAN_WIDTH_5:
6568 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006569 case NL80211_CHAN_WIDTH_20_NOHT:
6570 break;
6571 case NL80211_CHAN_WIDTH_20:
6572 case NL80211_CHAN_WIDTH_40:
6573 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6574 break;
6575 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006576 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006577 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006578
Johannes Berg04a773a2009-04-19 21:24:32 +02006579 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006580 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006581
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006582 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6583 u8 *rates =
6584 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6585 int n_rates =
6586 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6587 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006588 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006589
Johannes Berg34850ab2011-07-18 18:08:35 +02006590 err = ieee80211_get_ratemask(sband, rates, n_rates,
6591 &ibss.basic_rates);
6592 if (err)
6593 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006594 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006595
Simon Wunderlich803768f2013-06-28 10:39:58 +02006596 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6597 memcpy(&ibss.ht_capa_mask,
6598 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6599 sizeof(ibss.ht_capa_mask));
6600
6601 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6602 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6603 return -EINVAL;
6604 memcpy(&ibss.ht_capa,
6605 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6606 sizeof(ibss.ht_capa));
6607 }
6608
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006609 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6610 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6611 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6612 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006613
Johannes Berg4c476992010-10-04 21:36:35 +02006614 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306615 bool no_ht = false;
6616
Johannes Berg4c476992010-10-04 21:36:35 +02006617 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306618 info->attrs[NL80211_ATTR_KEYS],
6619 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006620 if (IS_ERR(connkeys))
6621 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306622
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006623 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6624 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306625 kfree(connkeys);
6626 return -EINVAL;
6627 }
Johannes Berg4c476992010-10-04 21:36:35 +02006628 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006629
Antonio Quartulli267335d2012-01-31 20:25:47 +01006630 ibss.control_port =
6631 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6632
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006633 ibss.userspace_handles_dfs =
6634 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6635
Johannes Berg4c476992010-10-04 21:36:35 +02006636 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006637 if (err)
6638 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006639 return err;
6640}
6641
6642static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6643{
Johannes Berg4c476992010-10-04 21:36:35 +02006644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6645 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006646
Johannes Berg4c476992010-10-04 21:36:35 +02006647 if (!rdev->ops->leave_ibss)
6648 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006649
Johannes Berg4c476992010-10-04 21:36:35 +02006650 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6651 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006652
Johannes Berg4c476992010-10-04 21:36:35 +02006653 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006654}
6655
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006656static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6657{
6658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6659 struct net_device *dev = info->user_ptr[1];
6660 int mcast_rate[IEEE80211_NUM_BANDS];
6661 u32 nla_rate;
6662 int err;
6663
6664 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6665 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6666 return -EOPNOTSUPP;
6667
6668 if (!rdev->ops->set_mcast_rate)
6669 return -EOPNOTSUPP;
6670
6671 memset(mcast_rate, 0, sizeof(mcast_rate));
6672
6673 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6674 return -EINVAL;
6675
6676 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6677 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6678 return -EINVAL;
6679
6680 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6681
6682 return err;
6683}
6684
6685
Johannes Bergaff89a92009-07-01 21:26:51 +02006686#ifdef CONFIG_NL80211_TESTMODE
6687static struct genl_multicast_group nl80211_testmode_mcgrp = {
6688 .name = "testmode",
6689};
6690
6691static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6692{
Johannes Berg4c476992010-10-04 21:36:35 +02006693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006694 struct wireless_dev *wdev =
6695 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006696 int err;
6697
David Spinadelfc73f112013-07-31 18:04:15 +03006698 if (!rdev->ops->testmode_cmd)
6699 return -EOPNOTSUPP;
6700
6701 if (IS_ERR(wdev)) {
6702 err = PTR_ERR(wdev);
6703 if (err != -EINVAL)
6704 return err;
6705 wdev = NULL;
6706 } else if (wdev->wiphy != &rdev->wiphy) {
6707 return -EINVAL;
6708 }
6709
Johannes Bergaff89a92009-07-01 21:26:51 +02006710 if (!info->attrs[NL80211_ATTR_TESTDATA])
6711 return -EINVAL;
6712
David Spinadelfc73f112013-07-31 18:04:15 +03006713 rdev->testmode_info = info;
6714 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006715 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6716 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
David Spinadelfc73f112013-07-31 18:04:15 +03006717 rdev->testmode_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006718
Johannes Bergaff89a92009-07-01 21:26:51 +02006719 return err;
6720}
6721
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006722static int nl80211_testmode_dump(struct sk_buff *skb,
6723 struct netlink_callback *cb)
6724{
Johannes Berg00918d32011-12-13 17:22:05 +01006725 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006726 int err;
6727 long phy_idx;
6728 void *data = NULL;
6729 int data_len = 0;
6730
Johannes Berg5fe231e2013-05-08 21:45:15 +02006731 rtnl_lock();
6732
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006733 if (cb->args[0]) {
6734 /*
6735 * 0 is a valid index, but not valid for args[0],
6736 * so we need to offset by 1.
6737 */
6738 phy_idx = cb->args[0] - 1;
6739 } else {
6740 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6741 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6742 nl80211_policy);
6743 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006744 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006745
Johannes Berg2bd7e352012-06-15 14:23:16 +02006746 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6747 nl80211_fam.attrbuf);
6748 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006749 err = PTR_ERR(rdev);
6750 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006751 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006752 phy_idx = rdev->wiphy_idx;
6753 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006754
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006755 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6756 cb->args[1] =
6757 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6758 }
6759
6760 if (cb->args[1]) {
6761 data = nla_data((void *)cb->args[1]);
6762 data_len = nla_len((void *)cb->args[1]);
6763 }
6764
Johannes Berg00918d32011-12-13 17:22:05 +01006765 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6766 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006767 err = -ENOENT;
6768 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006769 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006770
Johannes Berg00918d32011-12-13 17:22:05 +01006771 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006772 err = -EOPNOTSUPP;
6773 goto out_err;
6774 }
6775
6776 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006777 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006778 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6779 NL80211_CMD_TESTMODE);
6780 struct nlattr *tmdata;
6781
Dan Carpentercb35fba2013-08-14 14:50:01 +03006782 if (!hdr)
6783 break;
6784
David S. Miller9360ffd2012-03-29 04:41:26 -04006785 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006786 genlmsg_cancel(skb, hdr);
6787 break;
6788 }
6789
6790 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6791 if (!tmdata) {
6792 genlmsg_cancel(skb, hdr);
6793 break;
6794 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006795 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006796 nla_nest_end(skb, tmdata);
6797
6798 if (err == -ENOBUFS || err == -ENOENT) {
6799 genlmsg_cancel(skb, hdr);
6800 break;
6801 } else if (err) {
6802 genlmsg_cancel(skb, hdr);
6803 goto out_err;
6804 }
6805
6806 genlmsg_end(skb, hdr);
6807 }
6808
6809 err = skb->len;
6810 /* see above */
6811 cb->args[0] = phy_idx + 1;
6812 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006813 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006814 return err;
6815}
6816
Johannes Bergaff89a92009-07-01 21:26:51 +02006817static struct sk_buff *
6818__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006819 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006820{
6821 struct sk_buff *skb;
6822 void *hdr;
6823 struct nlattr *data;
6824
6825 skb = nlmsg_new(approxlen + 100, gfp);
6826 if (!skb)
6827 return NULL;
6828
Eric W. Biederman15e47302012-09-07 20:12:54 +00006829 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006830 if (!hdr) {
6831 kfree_skb(skb);
6832 return NULL;
6833 }
6834
David S. Miller9360ffd2012-03-29 04:41:26 -04006835 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6836 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006837 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6838
6839 ((void **)skb->cb)[0] = rdev;
6840 ((void **)skb->cb)[1] = hdr;
6841 ((void **)skb->cb)[2] = data;
6842
6843 return skb;
6844
6845 nla_put_failure:
6846 kfree_skb(skb);
6847 return NULL;
6848}
6849
6850struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6851 int approxlen)
6852{
6853 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6854
6855 if (WARN_ON(!rdev->testmode_info))
6856 return NULL;
6857
6858 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006859 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006860 rdev->testmode_info->snd_seq,
6861 GFP_KERNEL);
6862}
6863EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6864
6865int cfg80211_testmode_reply(struct sk_buff *skb)
6866{
6867 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6868 void *hdr = ((void **)skb->cb)[1];
6869 struct nlattr *data = ((void **)skb->cb)[2];
6870
6871 if (WARN_ON(!rdev->testmode_info)) {
6872 kfree_skb(skb);
6873 return -EINVAL;
6874 }
6875
6876 nla_nest_end(skb, data);
6877 genlmsg_end(skb, hdr);
6878 return genlmsg_reply(skb, rdev->testmode_info);
6879}
6880EXPORT_SYMBOL(cfg80211_testmode_reply);
6881
6882struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6883 int approxlen, gfp_t gfp)
6884{
6885 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6886
6887 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6888}
6889EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6890
6891void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6892{
Michal Kaziora0ec5702013-06-25 09:17:17 +02006893 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006894 void *hdr = ((void **)skb->cb)[1];
6895 struct nlattr *data = ((void **)skb->cb)[2];
6896
6897 nla_nest_end(skb, data);
6898 genlmsg_end(skb, hdr);
Michal Kaziora0ec5702013-06-25 09:17:17 +02006899 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
6900 nl80211_testmode_mcgrp.id, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006901}
6902EXPORT_SYMBOL(cfg80211_testmode_event);
6903#endif
6904
Samuel Ortizb23aa672009-07-01 21:26:54 +02006905static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6906{
Johannes Berg4c476992010-10-04 21:36:35 +02006907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6908 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006909 struct cfg80211_connect_params connect;
6910 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006911 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006912 int err;
6913
6914 memset(&connect, 0, sizeof(connect));
6915
6916 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6917 return -EINVAL;
6918
6919 if (!info->attrs[NL80211_ATTR_SSID] ||
6920 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6921 return -EINVAL;
6922
6923 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6924 connect.auth_type =
6925 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006926 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6927 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006928 return -EINVAL;
6929 } else
6930 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6931
6932 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6933
Johannes Bergc0692b82010-08-27 14:26:53 +03006934 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006935 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006936 if (err)
6937 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006938
Johannes Berg074ac8d2010-09-16 14:58:22 +02006939 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006940 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6941 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006942
Johannes Berg79c97e92009-07-07 03:56:12 +02006943 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006944
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306945 connect.bg_scan_period = -1;
6946 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6947 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6948 connect.bg_scan_period =
6949 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6950 }
6951
Samuel Ortizb23aa672009-07-01 21:26:54 +02006952 if (info->attrs[NL80211_ATTR_MAC])
6953 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6954 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6955 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6956
6957 if (info->attrs[NL80211_ATTR_IE]) {
6958 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6959 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6960 }
6961
Jouni Malinencee00a92013-01-15 17:15:57 +02006962 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6963 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6964 if (connect.mfp != NL80211_MFP_REQUIRED &&
6965 connect.mfp != NL80211_MFP_NO)
6966 return -EINVAL;
6967 } else {
6968 connect.mfp = NL80211_MFP_NO;
6969 }
6970
Samuel Ortizb23aa672009-07-01 21:26:54 +02006971 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6972 connect.channel =
6973 ieee80211_get_channel(wiphy,
6974 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6975 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006976 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6977 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006978 }
6979
Johannes Bergfffd0932009-07-08 14:22:54 +02006980 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6981 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306982 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006983 if (IS_ERR(connkeys))
6984 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006985 }
6986
Ben Greear7e7c8922011-11-18 11:31:59 -08006987 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6988 connect.flags |= ASSOC_REQ_DISABLE_HT;
6989
6990 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6991 memcpy(&connect.ht_capa_mask,
6992 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6993 sizeof(connect.ht_capa_mask));
6994
6995 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006996 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6997 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006998 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006999 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007000 memcpy(&connect.ht_capa,
7001 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7002 sizeof(connect.ht_capa));
7003 }
7004
Johannes Bergee2aca32013-02-21 17:36:01 +01007005 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7006 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7007
7008 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7009 memcpy(&connect.vht_capa_mask,
7010 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7011 sizeof(connect.vht_capa_mask));
7012
7013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7014 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7015 kfree(connkeys);
7016 return -EINVAL;
7017 }
7018 memcpy(&connect.vht_capa,
7019 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7020 sizeof(connect.vht_capa));
7021 }
7022
Johannes Berg83739b02013-05-15 17:44:01 +02007023 wdev_lock(dev->ieee80211_ptr);
7024 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7025 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007026 if (err)
7027 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007028 return err;
7029}
7030
7031static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7032{
Johannes Berg4c476992010-10-04 21:36:35 +02007033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7034 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007035 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007036 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007037
7038 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7039 reason = WLAN_REASON_DEAUTH_LEAVING;
7040 else
7041 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7042
7043 if (reason == 0)
7044 return -EINVAL;
7045
Johannes Berg074ac8d2010-09-16 14:58:22 +02007046 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007047 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7048 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007049
Johannes Berg83739b02013-05-15 17:44:01 +02007050 wdev_lock(dev->ieee80211_ptr);
7051 ret = cfg80211_disconnect(rdev, dev, reason, true);
7052 wdev_unlock(dev->ieee80211_ptr);
7053 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007054}
7055
Johannes Berg463d0182009-07-14 00:33:35 +02007056static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7057{
Johannes Berg4c476992010-10-04 21:36:35 +02007058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007059 struct net *net;
7060 int err;
7061 u32 pid;
7062
7063 if (!info->attrs[NL80211_ATTR_PID])
7064 return -EINVAL;
7065
7066 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7067
Johannes Berg463d0182009-07-14 00:33:35 +02007068 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007069 if (IS_ERR(net))
7070 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007071
7072 err = 0;
7073
7074 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007075 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7076 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007077
Johannes Berg463d0182009-07-14 00:33:35 +02007078 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007079 return err;
7080}
7081
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007082static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7083{
Johannes Berg4c476992010-10-04 21:36:35 +02007084 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007085 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7086 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007087 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007088 struct cfg80211_pmksa pmksa;
7089
7090 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7091
7092 if (!info->attrs[NL80211_ATTR_MAC])
7093 return -EINVAL;
7094
7095 if (!info->attrs[NL80211_ATTR_PMKID])
7096 return -EINVAL;
7097
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007098 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7099 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7100
Johannes Berg074ac8d2010-09-16 14:58:22 +02007101 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7103 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007104
7105 switch (info->genlhdr->cmd) {
7106 case NL80211_CMD_SET_PMKSA:
7107 rdev_ops = rdev->ops->set_pmksa;
7108 break;
7109 case NL80211_CMD_DEL_PMKSA:
7110 rdev_ops = rdev->ops->del_pmksa;
7111 break;
7112 default:
7113 WARN_ON(1);
7114 break;
7115 }
7116
Johannes Berg4c476992010-10-04 21:36:35 +02007117 if (!rdev_ops)
7118 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007119
Johannes Berg4c476992010-10-04 21:36:35 +02007120 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007121}
7122
7123static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7124{
Johannes Berg4c476992010-10-04 21:36:35 +02007125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7126 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007127
Johannes Berg074ac8d2010-09-16 14:58:22 +02007128 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007129 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7130 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007131
Johannes Berg4c476992010-10-04 21:36:35 +02007132 if (!rdev->ops->flush_pmksa)
7133 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007134
Hila Gonene35e4d22012-06-27 17:19:42 +03007135 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007136}
7137
Arik Nemtsov109086c2011-09-28 14:12:50 +03007138static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7139{
7140 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7141 struct net_device *dev = info->user_ptr[1];
7142 u8 action_code, dialog_token;
7143 u16 status_code;
7144 u8 *peer;
7145
7146 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7147 !rdev->ops->tdls_mgmt)
7148 return -EOPNOTSUPP;
7149
7150 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7151 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7152 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7153 !info->attrs[NL80211_ATTR_IE] ||
7154 !info->attrs[NL80211_ATTR_MAC])
7155 return -EINVAL;
7156
7157 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7158 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7159 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7160 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7161
Hila Gonene35e4d22012-06-27 17:19:42 +03007162 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7163 dialog_token, status_code,
7164 nla_data(info->attrs[NL80211_ATTR_IE]),
7165 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007166}
7167
7168static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7169{
7170 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7171 struct net_device *dev = info->user_ptr[1];
7172 enum nl80211_tdls_operation operation;
7173 u8 *peer;
7174
7175 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7176 !rdev->ops->tdls_oper)
7177 return -EOPNOTSUPP;
7178
7179 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7180 !info->attrs[NL80211_ATTR_MAC])
7181 return -EINVAL;
7182
7183 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7184 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7185
Hila Gonene35e4d22012-06-27 17:19:42 +03007186 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007187}
7188
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007189static int nl80211_remain_on_channel(struct sk_buff *skb,
7190 struct genl_info *info)
7191{
Johannes Berg4c476992010-10-04 21:36:35 +02007192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007193 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007194 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007195 struct sk_buff *msg;
7196 void *hdr;
7197 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007198 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007199 int err;
7200
7201 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7202 !info->attrs[NL80211_ATTR_DURATION])
7203 return -EINVAL;
7204
7205 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7206
Johannes Berg7c4ef712011-11-18 15:33:48 +01007207 if (!rdev->ops->remain_on_channel ||
7208 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007209 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007210
Johannes Bergebf348f2012-06-01 12:50:54 +02007211 /*
7212 * We should be on that channel for at least a minimum amount of
7213 * time (10ms) but no longer than the driver supports.
7214 */
7215 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7216 duration > rdev->wiphy.max_remain_on_channel_duration)
7217 return -EINVAL;
7218
Johannes Berg683b6d32012-11-08 21:25:48 +01007219 err = nl80211_parse_chandef(rdev, info, &chandef);
7220 if (err)
7221 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007222
7223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007224 if (!msg)
7225 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007226
Eric W. Biederman15e47302012-09-07 20:12:54 +00007227 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007228 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007229 if (!hdr) {
7230 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007231 goto free_msg;
7232 }
7233
Johannes Berg683b6d32012-11-08 21:25:48 +01007234 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7235 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007236
7237 if (err)
7238 goto free_msg;
7239
David S. Miller9360ffd2012-03-29 04:41:26 -04007240 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7241 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007242
7243 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007244
7245 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007246
7247 nla_put_failure:
7248 err = -ENOBUFS;
7249 free_msg:
7250 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007251 return err;
7252}
7253
7254static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7255 struct genl_info *info)
7256{
Johannes Berg4c476992010-10-04 21:36:35 +02007257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007258 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007259 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007260
7261 if (!info->attrs[NL80211_ATTR_COOKIE])
7262 return -EINVAL;
7263
Johannes Berg4c476992010-10-04 21:36:35 +02007264 if (!rdev->ops->cancel_remain_on_channel)
7265 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007266
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007267 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7268
Hila Gonene35e4d22012-06-27 17:19:42 +03007269 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007270}
7271
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007272static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7273 u8 *rates, u8 rates_len)
7274{
7275 u8 i;
7276 u32 mask = 0;
7277
7278 for (i = 0; i < rates_len; i++) {
7279 int rate = (rates[i] & 0x7f) * 5;
7280 int ridx;
7281 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7282 struct ieee80211_rate *srate =
7283 &sband->bitrates[ridx];
7284 if (rate == srate->bitrate) {
7285 mask |= 1 << ridx;
7286 break;
7287 }
7288 }
7289 if (ridx == sband->n_bitrates)
7290 return 0; /* rate not found */
7291 }
7292
7293 return mask;
7294}
7295
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007296static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7297 u8 *rates, u8 rates_len,
7298 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7299{
7300 u8 i;
7301
7302 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7303
7304 for (i = 0; i < rates_len; i++) {
7305 int ridx, rbit;
7306
7307 ridx = rates[i] / 8;
7308 rbit = BIT(rates[i] % 8);
7309
7310 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007311 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007312 return false;
7313
7314 /* check availability */
7315 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7316 mcs[ridx] |= rbit;
7317 else
7318 return false;
7319 }
7320
7321 return true;
7322}
7323
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007324static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007325 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7326 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007327 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7328 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007329};
7330
7331static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7332 struct genl_info *info)
7333{
7334 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007336 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007337 int rem, i;
7338 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007339 struct nlattr *tx_rates;
7340 struct ieee80211_supported_band *sband;
7341
7342 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7343 return -EINVAL;
7344
Johannes Berg4c476992010-10-04 21:36:35 +02007345 if (!rdev->ops->set_bitrate_mask)
7346 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007347
7348 memset(&mask, 0, sizeof(mask));
7349 /* Default to all rates enabled */
7350 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7351 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007352
7353 if (!sband)
7354 continue;
7355
7356 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
7357 memcpy(mask.control[i].mcs,
7358 sband->ht_cap.mcs.rx_mask,
7359 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007360 }
7361
7362 /*
7363 * The nested attribute uses enum nl80211_band as the index. This maps
7364 * directly to the enum ieee80211_band values used in cfg80211.
7365 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007366 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007367 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7368 {
7369 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007370 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7371 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007372 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007373 if (sband == NULL)
7374 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007375 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7376 nla_len(tx_rates), nl80211_txattr_policy);
7377 if (tb[NL80211_TXRATE_LEGACY]) {
7378 mask.control[band].legacy = rateset_to_mask(
7379 sband,
7380 nla_data(tb[NL80211_TXRATE_LEGACY]),
7381 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307382 if ((mask.control[band].legacy == 0) &&
7383 nla_len(tb[NL80211_TXRATE_LEGACY]))
7384 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007385 }
7386 if (tb[NL80211_TXRATE_MCS]) {
7387 if (!ht_rateset_to_mask(
7388 sband,
7389 nla_data(tb[NL80211_TXRATE_MCS]),
7390 nla_len(tb[NL80211_TXRATE_MCS]),
7391 mask.control[band].mcs))
7392 return -EINVAL;
7393 }
7394
7395 if (mask.control[band].legacy == 0) {
7396 /* don't allow empty legacy rates if HT
7397 * is not even supported. */
7398 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7399 return -EINVAL;
7400
7401 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7402 if (mask.control[band].mcs[i])
7403 break;
7404
7405 /* legacy and mcs rates may not be both empty */
7406 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007407 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007408 }
7409 }
7410
Hila Gonene35e4d22012-06-27 17:19:42 +03007411 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007412}
7413
Johannes Berg2e161f72010-08-12 15:38:38 +02007414static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007415{
Johannes Berg4c476992010-10-04 21:36:35 +02007416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007417 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007418 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007419
7420 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7421 return -EINVAL;
7422
Johannes Berg2e161f72010-08-12 15:38:38 +02007423 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7424 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007425
Johannes Berg71bbc992012-06-15 15:30:18 +02007426 switch (wdev->iftype) {
7427 case NL80211_IFTYPE_STATION:
7428 case NL80211_IFTYPE_ADHOC:
7429 case NL80211_IFTYPE_P2P_CLIENT:
7430 case NL80211_IFTYPE_AP:
7431 case NL80211_IFTYPE_AP_VLAN:
7432 case NL80211_IFTYPE_MESH_POINT:
7433 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007434 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007435 break;
7436 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007437 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007438 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007439
7440 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007441 if (!rdev->ops->mgmt_tx)
7442 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007443
Eric W. Biederman15e47302012-09-07 20:12:54 +00007444 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007445 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7446 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007447}
7448
Johannes Berg2e161f72010-08-12 15:38:38 +02007449static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007450{
Johannes Berg4c476992010-10-04 21:36:35 +02007451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007452 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007453 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007454 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007455 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007456 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007457 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007458 struct cfg80211_mgmt_tx_params params = {
7459 .dont_wait_for_ack =
7460 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7461 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007462
Johannes Berg683b6d32012-11-08 21:25:48 +01007463 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007464 return -EINVAL;
7465
Johannes Berg4c476992010-10-04 21:36:35 +02007466 if (!rdev->ops->mgmt_tx)
7467 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007468
Johannes Berg71bbc992012-06-15 15:30:18 +02007469 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007470 case NL80211_IFTYPE_P2P_DEVICE:
7471 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7472 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007473 case NL80211_IFTYPE_STATION:
7474 case NL80211_IFTYPE_ADHOC:
7475 case NL80211_IFTYPE_P2P_CLIENT:
7476 case NL80211_IFTYPE_AP:
7477 case NL80211_IFTYPE_AP_VLAN:
7478 case NL80211_IFTYPE_MESH_POINT:
7479 case NL80211_IFTYPE_P2P_GO:
7480 break;
7481 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007482 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007483 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007484
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007485 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007486 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007487 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007488 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007489
7490 /*
7491 * We should wait on the channel for at least a minimum amount
7492 * of time (10ms) but no longer than the driver supports.
7493 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007494 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7495 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007496 return -EINVAL;
7497
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007498 }
7499
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007500 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007501
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007502 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007503 return -EINVAL;
7504
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007505 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307506
Antonio Quartulliea141b752013-06-11 14:20:03 +02007507 /* get the channel if any has been specified, otherwise pass NULL to
7508 * the driver. The latter will use the current one
7509 */
7510 chandef.chan = NULL;
7511 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7512 err = nl80211_parse_chandef(rdev, info, &chandef);
7513 if (err)
7514 return err;
7515 }
7516
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007517 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007518 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007519
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007520 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7522 if (!msg)
7523 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007524
Eric W. Biederman15e47302012-09-07 20:12:54 +00007525 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007526 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007527 if (!hdr) {
7528 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007529 goto free_msg;
7530 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007531 }
Johannes Berge247bd902011-11-04 11:18:21 +01007532
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007533 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7534 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7535 params.chan = chandef.chan;
7536 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007537 if (err)
7538 goto free_msg;
7539
Johannes Berge247bd902011-11-04 11:18:21 +01007540 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007541 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7542 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007543
Johannes Berge247bd902011-11-04 11:18:21 +01007544 genlmsg_end(msg, hdr);
7545 return genlmsg_reply(msg, info);
7546 }
7547
7548 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007549
7550 nla_put_failure:
7551 err = -ENOBUFS;
7552 free_msg:
7553 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007554 return err;
7555}
7556
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007557static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7558{
7559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007560 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007561 u64 cookie;
7562
7563 if (!info->attrs[NL80211_ATTR_COOKIE])
7564 return -EINVAL;
7565
7566 if (!rdev->ops->mgmt_tx_cancel_wait)
7567 return -EOPNOTSUPP;
7568
Johannes Berg71bbc992012-06-15 15:30:18 +02007569 switch (wdev->iftype) {
7570 case NL80211_IFTYPE_STATION:
7571 case NL80211_IFTYPE_ADHOC:
7572 case NL80211_IFTYPE_P2P_CLIENT:
7573 case NL80211_IFTYPE_AP:
7574 case NL80211_IFTYPE_AP_VLAN:
7575 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007576 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007577 break;
7578 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007579 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007580 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007581
7582 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7583
Hila Gonene35e4d22012-06-27 17:19:42 +03007584 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007585}
7586
Kalle Valoffb9eb32010-02-17 17:58:10 +02007587static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7588{
Johannes Berg4c476992010-10-04 21:36:35 +02007589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007590 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007591 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007592 u8 ps_state;
7593 bool state;
7594 int err;
7595
Johannes Berg4c476992010-10-04 21:36:35 +02007596 if (!info->attrs[NL80211_ATTR_PS_STATE])
7597 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007598
7599 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7600
Johannes Berg4c476992010-10-04 21:36:35 +02007601 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7602 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007603
7604 wdev = dev->ieee80211_ptr;
7605
Johannes Berg4c476992010-10-04 21:36:35 +02007606 if (!rdev->ops->set_power_mgmt)
7607 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007608
7609 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7610
7611 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007612 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007613
Hila Gonene35e4d22012-06-27 17:19:42 +03007614 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007615 if (!err)
7616 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007617 return err;
7618}
7619
7620static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7621{
Johannes Berg4c476992010-10-04 21:36:35 +02007622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007623 enum nl80211_ps_state ps_state;
7624 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007625 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007626 struct sk_buff *msg;
7627 void *hdr;
7628 int err;
7629
Kalle Valoffb9eb32010-02-17 17:58:10 +02007630 wdev = dev->ieee80211_ptr;
7631
Johannes Berg4c476992010-10-04 21:36:35 +02007632 if (!rdev->ops->set_power_mgmt)
7633 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007634
7635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007636 if (!msg)
7637 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007638
Eric W. Biederman15e47302012-09-07 20:12:54 +00007639 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007640 NL80211_CMD_GET_POWER_SAVE);
7641 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007642 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007643 goto free_msg;
7644 }
7645
7646 if (wdev->ps)
7647 ps_state = NL80211_PS_ENABLED;
7648 else
7649 ps_state = NL80211_PS_DISABLED;
7650
David S. Miller9360ffd2012-03-29 04:41:26 -04007651 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7652 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007653
7654 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007655 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007656
Johannes Berg4c476992010-10-04 21:36:35 +02007657 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007658 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007659 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007660 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007661 return err;
7662}
7663
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007664static struct nla_policy
7665nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7666 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7667 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7668 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007669 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7670 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7671 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007672};
7673
Thomas Pedersen84f10702012-07-12 16:17:33 -07007674static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007675 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007676{
7677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007678 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007679 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007680
Johannes Bergd9d8b012012-11-26 12:51:52 +01007681 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007682 return -EINVAL;
7683
Thomas Pedersen84f10702012-07-12 16:17:33 -07007684 if (!rdev->ops->set_cqm_txe_config)
7685 return -EOPNOTSUPP;
7686
7687 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7688 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7689 return -EOPNOTSUPP;
7690
Hila Gonene35e4d22012-06-27 17:19:42 +03007691 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007692}
7693
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007694static int nl80211_set_cqm_rssi(struct genl_info *info,
7695 s32 threshold, u32 hysteresis)
7696{
Johannes Berg4c476992010-10-04 21:36:35 +02007697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007698 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007699 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007700
7701 if (threshold > 0)
7702 return -EINVAL;
7703
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007704 /* disabling - hysteresis should also be zero then */
7705 if (threshold == 0)
7706 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007707
Johannes Berg4c476992010-10-04 21:36:35 +02007708 if (!rdev->ops->set_cqm_rssi_config)
7709 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007710
Johannes Berg074ac8d2010-09-16 14:58:22 +02007711 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007712 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7713 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007714
Hila Gonene35e4d22012-06-27 17:19:42 +03007715 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007716}
7717
7718static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7719{
7720 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7721 struct nlattr *cqm;
7722 int err;
7723
7724 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007725 if (!cqm)
7726 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007727
7728 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7729 nl80211_attr_cqm_policy);
7730 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007731 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007732
7733 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7734 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007735 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7736 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007737
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007738 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7739 }
7740
7741 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7742 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7743 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7744 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7745 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7746 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7747
7748 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7749 }
7750
7751 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007752}
7753
Johannes Berg29cbe682010-12-03 09:20:44 +01007754static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7755{
7756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7757 struct net_device *dev = info->user_ptr[1];
7758 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007759 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007760 int err;
7761
7762 /* start with default */
7763 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007764 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007765
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007766 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007767 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007768 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007769 if (err)
7770 return err;
7771 }
7772
7773 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7774 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7775 return -EINVAL;
7776
Javier Cardonac80d5452010-12-16 17:37:49 -08007777 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7778 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7779
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007780 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7781 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7782 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7783 return -EINVAL;
7784
Marco Porsch9bdbf042013-01-07 16:04:51 +01007785 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7786 setup.beacon_interval =
7787 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7788 if (setup.beacon_interval < 10 ||
7789 setup.beacon_interval > 10000)
7790 return -EINVAL;
7791 }
7792
7793 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7794 setup.dtim_period =
7795 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7796 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7797 return -EINVAL;
7798 }
7799
Javier Cardonac80d5452010-12-16 17:37:49 -08007800 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7801 /* parse additional setup parameters if given */
7802 err = nl80211_parse_mesh_setup(info, &setup);
7803 if (err)
7804 return err;
7805 }
7806
Thomas Pedersend37bb182013-03-04 13:06:13 -08007807 if (setup.user_mpm)
7808 cfg.auto_open_plinks = false;
7809
Johannes Bergcc1d2802012-05-16 23:50:20 +02007810 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007811 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7812 if (err)
7813 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007814 } else {
7815 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007816 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007817 }
7818
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007819 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7820 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7821 int n_rates =
7822 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7823 struct ieee80211_supported_band *sband;
7824
7825 if (!setup.chandef.chan)
7826 return -EINVAL;
7827
7828 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7829
7830 err = ieee80211_get_ratemask(sband, rates, n_rates,
7831 &setup.basic_rates);
7832 if (err)
7833 return err;
7834 }
7835
Javier Cardonac80d5452010-12-16 17:37:49 -08007836 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007837}
7838
7839static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7840{
7841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7842 struct net_device *dev = info->user_ptr[1];
7843
7844 return cfg80211_leave_mesh(rdev, dev);
7845}
7846
Johannes Bergdfb89c52012-06-27 09:23:48 +02007847#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007848static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7849 struct cfg80211_registered_device *rdev)
7850{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007851 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007852 struct nlattr *nl_pats, *nl_pat;
7853 int i, pat_len;
7854
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007855 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007856 return 0;
7857
7858 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7859 if (!nl_pats)
7860 return -ENOBUFS;
7861
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007862 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007863 nl_pat = nla_nest_start(msg, i + 1);
7864 if (!nl_pat)
7865 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007866 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007867 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007868 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007869 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7870 wowlan->patterns[i].pattern) ||
7871 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007872 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007873 return -ENOBUFS;
7874 nla_nest_end(msg, nl_pat);
7875 }
7876 nla_nest_end(msg, nl_pats);
7877
7878 return 0;
7879}
7880
Johannes Berg2a0e0472013-01-23 22:57:40 +01007881static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7882 struct cfg80211_wowlan_tcp *tcp)
7883{
7884 struct nlattr *nl_tcp;
7885
7886 if (!tcp)
7887 return 0;
7888
7889 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7890 if (!nl_tcp)
7891 return -ENOBUFS;
7892
7893 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7894 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7895 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7896 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7897 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7898 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7899 tcp->payload_len, tcp->payload) ||
7900 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7901 tcp->data_interval) ||
7902 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7903 tcp->wake_len, tcp->wake_data) ||
7904 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7905 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7906 return -ENOBUFS;
7907
7908 if (tcp->payload_seq.len &&
7909 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7910 sizeof(tcp->payload_seq), &tcp->payload_seq))
7911 return -ENOBUFS;
7912
7913 if (tcp->payload_tok.len &&
7914 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7915 sizeof(tcp->payload_tok) + tcp->tokens_size,
7916 &tcp->payload_tok))
7917 return -ENOBUFS;
7918
Johannes Berge248ad32013-05-16 10:24:28 +02007919 nla_nest_end(msg, nl_tcp);
7920
Johannes Berg2a0e0472013-01-23 22:57:40 +01007921 return 0;
7922}
7923
Johannes Bergff1b6e62011-05-04 15:37:28 +02007924static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7925{
7926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7927 struct sk_buff *msg;
7928 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007929 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007930
Johannes Berg964dc9e2013-06-03 17:25:34 +02007931 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007932 return -EOPNOTSUPP;
7933
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007934 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007935 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007936 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7937 rdev->wiphy.wowlan_config->tcp->payload_len +
7938 rdev->wiphy.wowlan_config->tcp->wake_len +
7939 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007940 }
7941
7942 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007943 if (!msg)
7944 return -ENOMEM;
7945
Eric W. Biederman15e47302012-09-07 20:12:54 +00007946 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007947 NL80211_CMD_GET_WOWLAN);
7948 if (!hdr)
7949 goto nla_put_failure;
7950
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007951 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007952 struct nlattr *nl_wowlan;
7953
7954 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7955 if (!nl_wowlan)
7956 goto nla_put_failure;
7957
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007958 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007960 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007962 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007964 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007966 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007968 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007970 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7972 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007973
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007974 if (nl80211_send_wowlan_patterns(msg, rdev))
7975 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007976
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007977 if (nl80211_send_wowlan_tcp(msg,
7978 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007979 goto nla_put_failure;
7980
Johannes Bergff1b6e62011-05-04 15:37:28 +02007981 nla_nest_end(msg, nl_wowlan);
7982 }
7983
7984 genlmsg_end(msg, hdr);
7985 return genlmsg_reply(msg, info);
7986
7987nla_put_failure:
7988 nlmsg_free(msg);
7989 return -ENOBUFS;
7990}
7991
Johannes Berg2a0e0472013-01-23 22:57:40 +01007992static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7993 struct nlattr *attr,
7994 struct cfg80211_wowlan *trig)
7995{
7996 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7997 struct cfg80211_wowlan_tcp *cfg;
7998 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7999 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8000 u32 size;
8001 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8002 int err, port;
8003
Johannes Berg964dc9e2013-06-03 17:25:34 +02008004 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008005 return -EINVAL;
8006
8007 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8008 nla_data(attr), nla_len(attr),
8009 nl80211_wowlan_tcp_policy);
8010 if (err)
8011 return err;
8012
8013 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8014 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8015 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8016 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8017 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8018 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8019 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8020 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8021 return -EINVAL;
8022
8023 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008024 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008025 return -EINVAL;
8026
8027 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008028 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008029 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008030 return -EINVAL;
8031
8032 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008033 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008034 return -EINVAL;
8035
8036 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8037 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8038 return -EINVAL;
8039
8040 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8041 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8042
8043 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8044 tokens_size = tokln - sizeof(*tok);
8045
8046 if (!tok->len || tokens_size % tok->len)
8047 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008048 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008049 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008050 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008051 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008052 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008053 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008054 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008055 return -EINVAL;
8056 if (tok->offset + tok->len > data_size)
8057 return -EINVAL;
8058 }
8059
8060 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8061 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008062 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008063 return -EINVAL;
8064 if (seq->len == 0 || seq->len > 4)
8065 return -EINVAL;
8066 if (seq->len + seq->offset > data_size)
8067 return -EINVAL;
8068 }
8069
8070 size = sizeof(*cfg);
8071 size += data_size;
8072 size += wake_size + wake_mask_size;
8073 size += tokens_size;
8074
8075 cfg = kzalloc(size, GFP_KERNEL);
8076 if (!cfg)
8077 return -ENOMEM;
8078 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8079 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8080 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8081 ETH_ALEN);
8082 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8083 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8084 else
8085 port = 0;
8086#ifdef CONFIG_INET
8087 /* allocate a socket and port for it and use it */
8088 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8089 IPPROTO_TCP, &cfg->sock, 1);
8090 if (err) {
8091 kfree(cfg);
8092 return err;
8093 }
8094 if (inet_csk_get_port(cfg->sock->sk, port)) {
8095 sock_release(cfg->sock);
8096 kfree(cfg);
8097 return -EADDRINUSE;
8098 }
8099 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8100#else
8101 if (!port) {
8102 kfree(cfg);
8103 return -EINVAL;
8104 }
8105 cfg->src_port = port;
8106#endif
8107
8108 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8109 cfg->payload_len = data_size;
8110 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8111 memcpy((void *)cfg->payload,
8112 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8113 data_size);
8114 if (seq)
8115 cfg->payload_seq = *seq;
8116 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8117 cfg->wake_len = wake_size;
8118 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8119 memcpy((void *)cfg->wake_data,
8120 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8121 wake_size);
8122 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8123 data_size + wake_size;
8124 memcpy((void *)cfg->wake_mask,
8125 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8126 wake_mask_size);
8127 if (tok) {
8128 cfg->tokens_size = tokens_size;
8129 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8130 }
8131
8132 trig->tcp = cfg;
8133
8134 return 0;
8135}
8136
Johannes Bergff1b6e62011-05-04 15:37:28 +02008137static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8138{
8139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8140 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008141 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008142 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008143 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008144 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008145 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008146
Johannes Berg964dc9e2013-06-03 17:25:34 +02008147 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008148 return -EOPNOTSUPP;
8149
Johannes Bergae33bd82012-07-12 16:25:02 +02008150 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8151 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008152 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008153 goto set_wakeup;
8154 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008155
8156 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8157 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8158 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8159 nl80211_wowlan_policy);
8160 if (err)
8161 return err;
8162
8163 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8164 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8165 return -EINVAL;
8166 new_triggers.any = true;
8167 }
8168
8169 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8170 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8171 return -EINVAL;
8172 new_triggers.disconnect = true;
8173 }
8174
8175 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8176 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8177 return -EINVAL;
8178 new_triggers.magic_pkt = true;
8179 }
8180
Johannes Berg77dbbb12011-07-13 10:48:55 +02008181 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8182 return -EINVAL;
8183
8184 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8185 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8186 return -EINVAL;
8187 new_triggers.gtk_rekey_failure = true;
8188 }
8189
8190 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8191 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8192 return -EINVAL;
8193 new_triggers.eap_identity_req = true;
8194 }
8195
8196 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8197 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8198 return -EINVAL;
8199 new_triggers.four_way_handshake = true;
8200 }
8201
8202 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8203 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8204 return -EINVAL;
8205 new_triggers.rfkill_release = true;
8206 }
8207
Johannes Bergff1b6e62011-05-04 15:37:28 +02008208 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8209 struct nlattr *pat;
8210 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008211 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008212 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008213
8214 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8215 rem)
8216 n_patterns++;
8217 if (n_patterns > wowlan->n_patterns)
8218 return -EINVAL;
8219
8220 new_triggers.patterns = kcalloc(n_patterns,
8221 sizeof(new_triggers.patterns[0]),
8222 GFP_KERNEL);
8223 if (!new_triggers.patterns)
8224 return -ENOMEM;
8225
8226 new_triggers.n_patterns = n_patterns;
8227 i = 0;
8228
8229 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8230 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008231 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8232 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008233 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008234 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8235 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008236 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008237 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008238 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008239 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008240 goto error;
8241 if (pat_len > wowlan->pattern_max_len ||
8242 pat_len < wowlan->pattern_min_len)
8243 goto error;
8244
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008245 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008246 pkt_offset = 0;
8247 else
8248 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008249 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008250 if (pkt_offset > wowlan->max_pkt_offset)
8251 goto error;
8252 new_triggers.patterns[i].pkt_offset = pkt_offset;
8253
Johannes Bergff1b6e62011-05-04 15:37:28 +02008254 new_triggers.patterns[i].mask =
8255 kmalloc(mask_len + pat_len, GFP_KERNEL);
8256 if (!new_triggers.patterns[i].mask) {
8257 err = -ENOMEM;
8258 goto error;
8259 }
8260 new_triggers.patterns[i].pattern =
8261 new_triggers.patterns[i].mask + mask_len;
8262 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008263 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008264 mask_len);
8265 new_triggers.patterns[i].pattern_len = pat_len;
8266 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008267 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008268 pat_len);
8269 i++;
8270 }
8271 }
8272
Johannes Berg2a0e0472013-01-23 22:57:40 +01008273 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8274 err = nl80211_parse_wowlan_tcp(
8275 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8276 &new_triggers);
8277 if (err)
8278 goto error;
8279 }
8280
Johannes Bergae33bd82012-07-12 16:25:02 +02008281 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8282 if (!ntrig) {
8283 err = -ENOMEM;
8284 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008285 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008286 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008287 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008288
Johannes Bergae33bd82012-07-12 16:25:02 +02008289 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008290 if (rdev->ops->set_wakeup &&
8291 prev_enabled != !!rdev->wiphy.wowlan_config)
8292 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008293
Johannes Bergff1b6e62011-05-04 15:37:28 +02008294 return 0;
8295 error:
8296 for (i = 0; i < new_triggers.n_patterns; i++)
8297 kfree(new_triggers.patterns[i].mask);
8298 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008299 if (new_triggers.tcp && new_triggers.tcp->sock)
8300 sock_release(new_triggers.tcp->sock);
8301 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008302 return err;
8303}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008304#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008305
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008306static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8307 struct cfg80211_registered_device *rdev)
8308{
8309 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8310 int i, j, pat_len;
8311 struct cfg80211_coalesce_rules *rule;
8312
8313 if (!rdev->coalesce->n_rules)
8314 return 0;
8315
8316 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8317 if (!nl_rules)
8318 return -ENOBUFS;
8319
8320 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8321 nl_rule = nla_nest_start(msg, i + 1);
8322 if (!nl_rule)
8323 return -ENOBUFS;
8324
8325 rule = &rdev->coalesce->rules[i];
8326 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8327 rule->delay))
8328 return -ENOBUFS;
8329
8330 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8331 rule->condition))
8332 return -ENOBUFS;
8333
8334 nl_pats = nla_nest_start(msg,
8335 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8336 if (!nl_pats)
8337 return -ENOBUFS;
8338
8339 for (j = 0; j < rule->n_patterns; j++) {
8340 nl_pat = nla_nest_start(msg, j + 1);
8341 if (!nl_pat)
8342 return -ENOBUFS;
8343 pat_len = rule->patterns[j].pattern_len;
8344 if (nla_put(msg, NL80211_PKTPAT_MASK,
8345 DIV_ROUND_UP(pat_len, 8),
8346 rule->patterns[j].mask) ||
8347 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8348 rule->patterns[j].pattern) ||
8349 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8350 rule->patterns[j].pkt_offset))
8351 return -ENOBUFS;
8352 nla_nest_end(msg, nl_pat);
8353 }
8354 nla_nest_end(msg, nl_pats);
8355 nla_nest_end(msg, nl_rule);
8356 }
8357 nla_nest_end(msg, nl_rules);
8358
8359 return 0;
8360}
8361
8362static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8363{
8364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8365 struct sk_buff *msg;
8366 void *hdr;
8367
8368 if (!rdev->wiphy.coalesce)
8369 return -EOPNOTSUPP;
8370
8371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8372 if (!msg)
8373 return -ENOMEM;
8374
8375 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8376 NL80211_CMD_GET_COALESCE);
8377 if (!hdr)
8378 goto nla_put_failure;
8379
8380 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8381 goto nla_put_failure;
8382
8383 genlmsg_end(msg, hdr);
8384 return genlmsg_reply(msg, info);
8385
8386nla_put_failure:
8387 nlmsg_free(msg);
8388 return -ENOBUFS;
8389}
8390
8391void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8392{
8393 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8394 int i, j;
8395 struct cfg80211_coalesce_rules *rule;
8396
8397 if (!coalesce)
8398 return;
8399
8400 for (i = 0; i < coalesce->n_rules; i++) {
8401 rule = &coalesce->rules[i];
8402 for (j = 0; j < rule->n_patterns; j++)
8403 kfree(rule->patterns[j].mask);
8404 kfree(rule->patterns);
8405 }
8406 kfree(coalesce->rules);
8407 kfree(coalesce);
8408 rdev->coalesce = NULL;
8409}
8410
8411static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8412 struct nlattr *rule,
8413 struct cfg80211_coalesce_rules *new_rule)
8414{
8415 int err, i;
8416 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8417 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8418 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8419 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8420
8421 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8422 nla_len(rule), nl80211_coalesce_policy);
8423 if (err)
8424 return err;
8425
8426 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8427 new_rule->delay =
8428 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8429 if (new_rule->delay > coalesce->max_delay)
8430 return -EINVAL;
8431
8432 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8433 new_rule->condition =
8434 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8435 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8436 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8437 return -EINVAL;
8438
8439 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8440 return -EINVAL;
8441
8442 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8443 rem)
8444 n_patterns++;
8445 if (n_patterns > coalesce->n_patterns)
8446 return -EINVAL;
8447
8448 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8449 GFP_KERNEL);
8450 if (!new_rule->patterns)
8451 return -ENOMEM;
8452
8453 new_rule->n_patterns = n_patterns;
8454 i = 0;
8455
8456 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8457 rem) {
8458 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8459 nla_len(pat), NULL);
8460 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8461 !pat_tb[NL80211_PKTPAT_PATTERN])
8462 return -EINVAL;
8463 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8464 mask_len = DIV_ROUND_UP(pat_len, 8);
8465 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8466 return -EINVAL;
8467 if (pat_len > coalesce->pattern_max_len ||
8468 pat_len < coalesce->pattern_min_len)
8469 return -EINVAL;
8470
8471 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8472 pkt_offset = 0;
8473 else
8474 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8475 if (pkt_offset > coalesce->max_pkt_offset)
8476 return -EINVAL;
8477 new_rule->patterns[i].pkt_offset = pkt_offset;
8478
8479 new_rule->patterns[i].mask =
8480 kmalloc(mask_len + pat_len, GFP_KERNEL);
8481 if (!new_rule->patterns[i].mask)
8482 return -ENOMEM;
8483 new_rule->patterns[i].pattern =
8484 new_rule->patterns[i].mask + mask_len;
8485 memcpy(new_rule->patterns[i].mask,
8486 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8487 new_rule->patterns[i].pattern_len = pat_len;
8488 memcpy(new_rule->patterns[i].pattern,
8489 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8490 i++;
8491 }
8492
8493 return 0;
8494}
8495
8496static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8497{
8498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8499 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8500 struct cfg80211_coalesce new_coalesce = {};
8501 struct cfg80211_coalesce *n_coalesce;
8502 int err, rem_rule, n_rules = 0, i, j;
8503 struct nlattr *rule;
8504 struct cfg80211_coalesce_rules *tmp_rule;
8505
8506 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8507 return -EOPNOTSUPP;
8508
8509 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8510 cfg80211_rdev_free_coalesce(rdev);
8511 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8512 return 0;
8513 }
8514
8515 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8516 rem_rule)
8517 n_rules++;
8518 if (n_rules > coalesce->n_rules)
8519 return -EINVAL;
8520
8521 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8522 GFP_KERNEL);
8523 if (!new_coalesce.rules)
8524 return -ENOMEM;
8525
8526 new_coalesce.n_rules = n_rules;
8527 i = 0;
8528
8529 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8530 rem_rule) {
8531 err = nl80211_parse_coalesce_rule(rdev, rule,
8532 &new_coalesce.rules[i]);
8533 if (err)
8534 goto error;
8535
8536 i++;
8537 }
8538
8539 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8540 if (err)
8541 goto error;
8542
8543 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8544 if (!n_coalesce) {
8545 err = -ENOMEM;
8546 goto error;
8547 }
8548 cfg80211_rdev_free_coalesce(rdev);
8549 rdev->coalesce = n_coalesce;
8550
8551 return 0;
8552error:
8553 for (i = 0; i < new_coalesce.n_rules; i++) {
8554 tmp_rule = &new_coalesce.rules[i];
8555 for (j = 0; j < tmp_rule->n_patterns; j++)
8556 kfree(tmp_rule->patterns[j].mask);
8557 kfree(tmp_rule->patterns);
8558 }
8559 kfree(new_coalesce.rules);
8560
8561 return err;
8562}
8563
Johannes Berge5497d72011-07-05 16:35:40 +02008564static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8565{
8566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8567 struct net_device *dev = info->user_ptr[1];
8568 struct wireless_dev *wdev = dev->ieee80211_ptr;
8569 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8570 struct cfg80211_gtk_rekey_data rekey_data;
8571 int err;
8572
8573 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8574 return -EINVAL;
8575
8576 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8577 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8578 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8579 nl80211_rekey_policy);
8580 if (err)
8581 return err;
8582
8583 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8584 return -ERANGE;
8585 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8586 return -ERANGE;
8587 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8588 return -ERANGE;
8589
8590 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8591 NL80211_KEK_LEN);
8592 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8593 NL80211_KCK_LEN);
8594 memcpy(rekey_data.replay_ctr,
8595 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8596 NL80211_REPLAY_CTR_LEN);
8597
8598 wdev_lock(wdev);
8599 if (!wdev->current_bss) {
8600 err = -ENOTCONN;
8601 goto out;
8602 }
8603
8604 if (!rdev->ops->set_rekey_data) {
8605 err = -EOPNOTSUPP;
8606 goto out;
8607 }
8608
Hila Gonene35e4d22012-06-27 17:19:42 +03008609 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008610 out:
8611 wdev_unlock(wdev);
8612 return err;
8613}
8614
Johannes Berg28946da2011-11-04 11:18:12 +01008615static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8616 struct genl_info *info)
8617{
8618 struct net_device *dev = info->user_ptr[1];
8619 struct wireless_dev *wdev = dev->ieee80211_ptr;
8620
8621 if (wdev->iftype != NL80211_IFTYPE_AP &&
8622 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8623 return -EINVAL;
8624
Eric W. Biederman15e47302012-09-07 20:12:54 +00008625 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008626 return -EBUSY;
8627
Eric W. Biederman15e47302012-09-07 20:12:54 +00008628 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008629 return 0;
8630}
8631
Johannes Berg7f6cf312011-11-04 11:18:15 +01008632static int nl80211_probe_client(struct sk_buff *skb,
8633 struct genl_info *info)
8634{
8635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8636 struct net_device *dev = info->user_ptr[1];
8637 struct wireless_dev *wdev = dev->ieee80211_ptr;
8638 struct sk_buff *msg;
8639 void *hdr;
8640 const u8 *addr;
8641 u64 cookie;
8642 int err;
8643
8644 if (wdev->iftype != NL80211_IFTYPE_AP &&
8645 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8646 return -EOPNOTSUPP;
8647
8648 if (!info->attrs[NL80211_ATTR_MAC])
8649 return -EINVAL;
8650
8651 if (!rdev->ops->probe_client)
8652 return -EOPNOTSUPP;
8653
8654 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8655 if (!msg)
8656 return -ENOMEM;
8657
Eric W. Biederman15e47302012-09-07 20:12:54 +00008658 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008659 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008660 if (!hdr) {
8661 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008662 goto free_msg;
8663 }
8664
8665 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8666
Hila Gonene35e4d22012-06-27 17:19:42 +03008667 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008668 if (err)
8669 goto free_msg;
8670
David S. Miller9360ffd2012-03-29 04:41:26 -04008671 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8672 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008673
8674 genlmsg_end(msg, hdr);
8675
8676 return genlmsg_reply(msg, info);
8677
8678 nla_put_failure:
8679 err = -ENOBUFS;
8680 free_msg:
8681 nlmsg_free(msg);
8682 return err;
8683}
8684
Johannes Berg5e7602302011-11-04 11:18:17 +01008685static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8686{
8687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008688 struct cfg80211_beacon_registration *reg, *nreg;
8689 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008690
8691 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8692 return -EOPNOTSUPP;
8693
Ben Greear37c73b52012-10-26 14:49:25 -07008694 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8695 if (!nreg)
8696 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008697
Ben Greear37c73b52012-10-26 14:49:25 -07008698 /* First, check if already registered. */
8699 spin_lock_bh(&rdev->beacon_registrations_lock);
8700 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8701 if (reg->nlportid == info->snd_portid) {
8702 rv = -EALREADY;
8703 goto out_err;
8704 }
8705 }
8706 /* Add it to the list */
8707 nreg->nlportid = info->snd_portid;
8708 list_add(&nreg->list, &rdev->beacon_registrations);
8709
8710 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008711
8712 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008713out_err:
8714 spin_unlock_bh(&rdev->beacon_registrations_lock);
8715 kfree(nreg);
8716 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008717}
8718
Johannes Berg98104fde2012-06-16 00:19:54 +02008719static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8720{
8721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8722 struct wireless_dev *wdev = info->user_ptr[1];
8723 int err;
8724
8725 if (!rdev->ops->start_p2p_device)
8726 return -EOPNOTSUPP;
8727
8728 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8729 return -EOPNOTSUPP;
8730
8731 if (wdev->p2p_started)
8732 return 0;
8733
Johannes Berg98104fde2012-06-16 00:19:54 +02008734 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008735 if (err)
8736 return err;
8737
Johannes Bergeeb126e2012-10-23 15:16:50 +02008738 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008739 if (err)
8740 return err;
8741
8742 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008743 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008744
8745 return 0;
8746}
8747
8748static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8749{
8750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8751 struct wireless_dev *wdev = info->user_ptr[1];
8752
8753 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8754 return -EOPNOTSUPP;
8755
8756 if (!rdev->ops->stop_p2p_device)
8757 return -EOPNOTSUPP;
8758
Johannes Bergf9f47522013-03-19 15:04:07 +01008759 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008760
8761 return 0;
8762}
8763
Johannes Berg3713b4e2013-02-14 16:19:38 +01008764static int nl80211_get_protocol_features(struct sk_buff *skb,
8765 struct genl_info *info)
8766{
8767 void *hdr;
8768 struct sk_buff *msg;
8769
8770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8771 if (!msg)
8772 return -ENOMEM;
8773
8774 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8775 NL80211_CMD_GET_PROTOCOL_FEATURES);
8776 if (!hdr)
8777 goto nla_put_failure;
8778
8779 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8780 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8781 goto nla_put_failure;
8782
8783 genlmsg_end(msg, hdr);
8784 return genlmsg_reply(msg, info);
8785
8786 nla_put_failure:
8787 kfree_skb(msg);
8788 return -ENOBUFS;
8789}
8790
Jouni Malinen355199e2013-02-27 17:14:27 +02008791static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8792{
8793 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8794 struct cfg80211_update_ft_ies_params ft_params;
8795 struct net_device *dev = info->user_ptr[1];
8796
8797 if (!rdev->ops->update_ft_ies)
8798 return -EOPNOTSUPP;
8799
8800 if (!info->attrs[NL80211_ATTR_MDID] ||
8801 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8802 return -EINVAL;
8803
8804 memset(&ft_params, 0, sizeof(ft_params));
8805 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8806 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8807 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8808
8809 return rdev_update_ft_ies(rdev, dev, &ft_params);
8810}
8811
Arend van Spriel5de17982013-04-18 15:49:00 +02008812static int nl80211_crit_protocol_start(struct sk_buff *skb,
8813 struct genl_info *info)
8814{
8815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8816 struct wireless_dev *wdev = info->user_ptr[1];
8817 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8818 u16 duration;
8819 int ret;
8820
8821 if (!rdev->ops->crit_proto_start)
8822 return -EOPNOTSUPP;
8823
8824 if (WARN_ON(!rdev->ops->crit_proto_stop))
8825 return -EINVAL;
8826
8827 if (rdev->crit_proto_nlportid)
8828 return -EBUSY;
8829
8830 /* determine protocol if provided */
8831 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8832 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8833
8834 if (proto >= NUM_NL80211_CRIT_PROTO)
8835 return -EINVAL;
8836
8837 /* timeout must be provided */
8838 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8839 return -EINVAL;
8840
8841 duration =
8842 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8843
8844 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8845 return -ERANGE;
8846
8847 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8848 if (!ret)
8849 rdev->crit_proto_nlportid = info->snd_portid;
8850
8851 return ret;
8852}
8853
8854static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8855 struct genl_info *info)
8856{
8857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8858 struct wireless_dev *wdev = info->user_ptr[1];
8859
8860 if (!rdev->ops->crit_proto_stop)
8861 return -EOPNOTSUPP;
8862
8863 if (rdev->crit_proto_nlportid) {
8864 rdev->crit_proto_nlportid = 0;
8865 rdev_crit_proto_stop(rdev, wdev);
8866 }
8867 return 0;
8868}
8869
Johannes Berg4c476992010-10-04 21:36:35 +02008870#define NL80211_FLAG_NEED_WIPHY 0x01
8871#define NL80211_FLAG_NEED_NETDEV 0x02
8872#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008873#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8874#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8875 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008876#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008877/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008878#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8879 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008880
8881static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8882 struct genl_info *info)
8883{
8884 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008885 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008886 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008887 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8888
8889 if (rtnl)
8890 rtnl_lock();
8891
8892 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008893 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008894 if (IS_ERR(rdev)) {
8895 if (rtnl)
8896 rtnl_unlock();
8897 return PTR_ERR(rdev);
8898 }
8899 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008900 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8901 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008902 ASSERT_RTNL();
8903
Johannes Berg89a54e42012-06-15 14:33:17 +02008904 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8905 info->attrs);
8906 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008907 if (rtnl)
8908 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008909 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008910 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008911
Johannes Berg89a54e42012-06-15 14:33:17 +02008912 dev = wdev->netdev;
8913 rdev = wiphy_to_dev(wdev->wiphy);
8914
Johannes Berg1bf614e2012-06-15 15:23:36 +02008915 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8916 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008917 if (rtnl)
8918 rtnl_unlock();
8919 return -EINVAL;
8920 }
8921
8922 info->user_ptr[1] = dev;
8923 } else {
8924 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008925 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008926
Johannes Berg1bf614e2012-06-15 15:23:36 +02008927 if (dev) {
8928 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8929 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008930 if (rtnl)
8931 rtnl_unlock();
8932 return -ENETDOWN;
8933 }
8934
8935 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008936 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8937 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008938 if (rtnl)
8939 rtnl_unlock();
8940 return -ENETDOWN;
8941 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008942 }
8943
Johannes Berg4c476992010-10-04 21:36:35 +02008944 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008945 }
8946
8947 return 0;
8948}
8949
8950static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8951 struct genl_info *info)
8952{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008953 if (info->user_ptr[1]) {
8954 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8955 struct wireless_dev *wdev = info->user_ptr[1];
8956
8957 if (wdev->netdev)
8958 dev_put(wdev->netdev);
8959 } else {
8960 dev_put(info->user_ptr[1]);
8961 }
8962 }
Johannes Berg4c476992010-10-04 21:36:35 +02008963 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8964 rtnl_unlock();
8965}
8966
Johannes Berg55682962007-09-20 13:09:35 -04008967static struct genl_ops nl80211_ops[] = {
8968 {
8969 .cmd = NL80211_CMD_GET_WIPHY,
8970 .doit = nl80211_get_wiphy,
8971 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008972 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008973 .policy = nl80211_policy,
8974 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008975 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8976 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008977 },
8978 {
8979 .cmd = NL80211_CMD_SET_WIPHY,
8980 .doit = nl80211_set_wiphy,
8981 .policy = nl80211_policy,
8982 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008983 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008984 },
8985 {
8986 .cmd = NL80211_CMD_GET_INTERFACE,
8987 .doit = nl80211_get_interface,
8988 .dumpit = nl80211_dump_interface,
8989 .policy = nl80211_policy,
8990 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008991 .internal_flags = NL80211_FLAG_NEED_WDEV |
8992 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008993 },
8994 {
8995 .cmd = NL80211_CMD_SET_INTERFACE,
8996 .doit = nl80211_set_interface,
8997 .policy = nl80211_policy,
8998 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008999 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9000 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009001 },
9002 {
9003 .cmd = NL80211_CMD_NEW_INTERFACE,
9004 .doit = nl80211_new_interface,
9005 .policy = nl80211_policy,
9006 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009007 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9008 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009009 },
9010 {
9011 .cmd = NL80211_CMD_DEL_INTERFACE,
9012 .doit = nl80211_del_interface,
9013 .policy = nl80211_policy,
9014 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009015 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009016 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009017 },
Johannes Berg41ade002007-12-19 02:03:29 +01009018 {
9019 .cmd = NL80211_CMD_GET_KEY,
9020 .doit = nl80211_get_key,
9021 .policy = nl80211_policy,
9022 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009024 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009025 },
9026 {
9027 .cmd = NL80211_CMD_SET_KEY,
9028 .doit = nl80211_set_key,
9029 .policy = nl80211_policy,
9030 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009032 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009033 },
9034 {
9035 .cmd = NL80211_CMD_NEW_KEY,
9036 .doit = nl80211_new_key,
9037 .policy = nl80211_policy,
9038 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009040 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009041 },
9042 {
9043 .cmd = NL80211_CMD_DEL_KEY,
9044 .doit = nl80211_del_key,
9045 .policy = nl80211_policy,
9046 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009048 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009049 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009050 {
9051 .cmd = NL80211_CMD_SET_BEACON,
9052 .policy = nl80211_policy,
9053 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009054 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009056 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009057 },
9058 {
Johannes Berg88600202012-02-13 15:17:18 +01009059 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009060 .policy = nl80211_policy,
9061 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009062 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009064 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009065 },
9066 {
Johannes Berg88600202012-02-13 15:17:18 +01009067 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009068 .policy = nl80211_policy,
9069 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009070 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009072 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009073 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009074 {
9075 .cmd = NL80211_CMD_GET_STATION,
9076 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009077 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009078 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009079 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9080 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009081 },
9082 {
9083 .cmd = NL80211_CMD_SET_STATION,
9084 .doit = nl80211_set_station,
9085 .policy = nl80211_policy,
9086 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009088 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009089 },
9090 {
9091 .cmd = NL80211_CMD_NEW_STATION,
9092 .doit = nl80211_new_station,
9093 .policy = nl80211_policy,
9094 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009096 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009097 },
9098 {
9099 .cmd = NL80211_CMD_DEL_STATION,
9100 .doit = nl80211_del_station,
9101 .policy = nl80211_policy,
9102 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009103 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009104 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009105 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009106 {
9107 .cmd = NL80211_CMD_GET_MPATH,
9108 .doit = nl80211_get_mpath,
9109 .dumpit = nl80211_dump_mpath,
9110 .policy = nl80211_policy,
9111 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009112 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009113 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009114 },
9115 {
9116 .cmd = NL80211_CMD_SET_MPATH,
9117 .doit = nl80211_set_mpath,
9118 .policy = nl80211_policy,
9119 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009121 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009122 },
9123 {
9124 .cmd = NL80211_CMD_NEW_MPATH,
9125 .doit = nl80211_new_mpath,
9126 .policy = nl80211_policy,
9127 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009128 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009129 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009130 },
9131 {
9132 .cmd = NL80211_CMD_DEL_MPATH,
9133 .doit = nl80211_del_mpath,
9134 .policy = nl80211_policy,
9135 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009136 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009137 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009138 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009139 {
9140 .cmd = NL80211_CMD_SET_BSS,
9141 .doit = nl80211_set_bss,
9142 .policy = nl80211_policy,
9143 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009145 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009146 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009147 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009148 .cmd = NL80211_CMD_GET_REG,
9149 .doit = nl80211_get_reg,
9150 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009151 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009152 /* can be retrieved by unprivileged users */
9153 },
9154 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009155 .cmd = NL80211_CMD_SET_REG,
9156 .doit = nl80211_set_reg,
9157 .policy = nl80211_policy,
9158 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009159 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009160 },
9161 {
9162 .cmd = NL80211_CMD_REQ_SET_REG,
9163 .doit = nl80211_req_set_reg,
9164 .policy = nl80211_policy,
9165 .flags = GENL_ADMIN_PERM,
9166 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009167 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009168 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9169 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009170 .policy = nl80211_policy,
9171 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009173 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009174 },
9175 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009176 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9177 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009178 .policy = nl80211_policy,
9179 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009180 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009181 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009182 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009183 {
Johannes Berg2a519312009-02-10 21:25:55 +01009184 .cmd = NL80211_CMD_TRIGGER_SCAN,
9185 .doit = nl80211_trigger_scan,
9186 .policy = nl80211_policy,
9187 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009188 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009189 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009190 },
9191 {
9192 .cmd = NL80211_CMD_GET_SCAN,
9193 .policy = nl80211_policy,
9194 .dumpit = nl80211_dump_scan,
9195 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009196 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009197 .cmd = NL80211_CMD_START_SCHED_SCAN,
9198 .doit = nl80211_start_sched_scan,
9199 .policy = nl80211_policy,
9200 .flags = GENL_ADMIN_PERM,
9201 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9202 NL80211_FLAG_NEED_RTNL,
9203 },
9204 {
9205 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9206 .doit = nl80211_stop_sched_scan,
9207 .policy = nl80211_policy,
9208 .flags = GENL_ADMIN_PERM,
9209 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9210 NL80211_FLAG_NEED_RTNL,
9211 },
9212 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009213 .cmd = NL80211_CMD_AUTHENTICATE,
9214 .doit = nl80211_authenticate,
9215 .policy = nl80211_policy,
9216 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009218 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009219 },
9220 {
9221 .cmd = NL80211_CMD_ASSOCIATE,
9222 .doit = nl80211_associate,
9223 .policy = nl80211_policy,
9224 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009225 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009226 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009227 },
9228 {
9229 .cmd = NL80211_CMD_DEAUTHENTICATE,
9230 .doit = nl80211_deauthenticate,
9231 .policy = nl80211_policy,
9232 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009234 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009235 },
9236 {
9237 .cmd = NL80211_CMD_DISASSOCIATE,
9238 .doit = nl80211_disassociate,
9239 .policy = nl80211_policy,
9240 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009242 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009243 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009244 {
9245 .cmd = NL80211_CMD_JOIN_IBSS,
9246 .doit = nl80211_join_ibss,
9247 .policy = nl80211_policy,
9248 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009250 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009251 },
9252 {
9253 .cmd = NL80211_CMD_LEAVE_IBSS,
9254 .doit = nl80211_leave_ibss,
9255 .policy = nl80211_policy,
9256 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009258 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009259 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009260#ifdef CONFIG_NL80211_TESTMODE
9261 {
9262 .cmd = NL80211_CMD_TESTMODE,
9263 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009264 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009265 .policy = nl80211_policy,
9266 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009267 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9268 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009269 },
9270#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009271 {
9272 .cmd = NL80211_CMD_CONNECT,
9273 .doit = nl80211_connect,
9274 .policy = nl80211_policy,
9275 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009277 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009278 },
9279 {
9280 .cmd = NL80211_CMD_DISCONNECT,
9281 .doit = nl80211_disconnect,
9282 .policy = nl80211_policy,
9283 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009284 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009285 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009286 },
Johannes Berg463d0182009-07-14 00:33:35 +02009287 {
9288 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9289 .doit = nl80211_wiphy_netns,
9290 .policy = nl80211_policy,
9291 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009292 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9293 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009294 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009295 {
9296 .cmd = NL80211_CMD_GET_SURVEY,
9297 .policy = nl80211_policy,
9298 .dumpit = nl80211_dump_survey,
9299 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009300 {
9301 .cmd = NL80211_CMD_SET_PMKSA,
9302 .doit = nl80211_setdel_pmksa,
9303 .policy = nl80211_policy,
9304 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009305 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009306 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009307 },
9308 {
9309 .cmd = NL80211_CMD_DEL_PMKSA,
9310 .doit = nl80211_setdel_pmksa,
9311 .policy = nl80211_policy,
9312 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009313 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009314 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009315 },
9316 {
9317 .cmd = NL80211_CMD_FLUSH_PMKSA,
9318 .doit = nl80211_flush_pmksa,
9319 .policy = nl80211_policy,
9320 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009321 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009322 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009323 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009324 {
9325 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9326 .doit = nl80211_remain_on_channel,
9327 .policy = nl80211_policy,
9328 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009329 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009330 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009331 },
9332 {
9333 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9334 .doit = nl80211_cancel_remain_on_channel,
9335 .policy = nl80211_policy,
9336 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009337 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009338 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009339 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009340 {
9341 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9342 .doit = nl80211_set_tx_bitrate_mask,
9343 .policy = nl80211_policy,
9344 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009345 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9346 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009347 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009348 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009349 .cmd = NL80211_CMD_REGISTER_FRAME,
9350 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009351 .policy = nl80211_policy,
9352 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009353 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009354 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009355 },
9356 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009357 .cmd = NL80211_CMD_FRAME,
9358 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009359 .policy = nl80211_policy,
9360 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009361 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009362 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009363 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009364 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009365 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9366 .doit = nl80211_tx_mgmt_cancel_wait,
9367 .policy = nl80211_policy,
9368 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009369 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009370 NL80211_FLAG_NEED_RTNL,
9371 },
9372 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009373 .cmd = NL80211_CMD_SET_POWER_SAVE,
9374 .doit = nl80211_set_power_save,
9375 .policy = nl80211_policy,
9376 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009377 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9378 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009379 },
9380 {
9381 .cmd = NL80211_CMD_GET_POWER_SAVE,
9382 .doit = nl80211_get_power_save,
9383 .policy = nl80211_policy,
9384 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009385 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9386 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009387 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009388 {
9389 .cmd = NL80211_CMD_SET_CQM,
9390 .doit = nl80211_set_cqm,
9391 .policy = nl80211_policy,
9392 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009393 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9394 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009395 },
Johannes Bergf444de02010-05-05 15:25:02 +02009396 {
9397 .cmd = NL80211_CMD_SET_CHANNEL,
9398 .doit = nl80211_set_channel,
9399 .policy = nl80211_policy,
9400 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009401 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9402 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009403 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009404 {
9405 .cmd = NL80211_CMD_SET_WDS_PEER,
9406 .doit = nl80211_set_wds_peer,
9407 .policy = nl80211_policy,
9408 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009409 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9410 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009411 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009412 {
9413 .cmd = NL80211_CMD_JOIN_MESH,
9414 .doit = nl80211_join_mesh,
9415 .policy = nl80211_policy,
9416 .flags = GENL_ADMIN_PERM,
9417 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9418 NL80211_FLAG_NEED_RTNL,
9419 },
9420 {
9421 .cmd = NL80211_CMD_LEAVE_MESH,
9422 .doit = nl80211_leave_mesh,
9423 .policy = nl80211_policy,
9424 .flags = GENL_ADMIN_PERM,
9425 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9426 NL80211_FLAG_NEED_RTNL,
9427 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009428#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009429 {
9430 .cmd = NL80211_CMD_GET_WOWLAN,
9431 .doit = nl80211_get_wowlan,
9432 .policy = nl80211_policy,
9433 /* can be retrieved by unprivileged users */
9434 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9435 NL80211_FLAG_NEED_RTNL,
9436 },
9437 {
9438 .cmd = NL80211_CMD_SET_WOWLAN,
9439 .doit = nl80211_set_wowlan,
9440 .policy = nl80211_policy,
9441 .flags = GENL_ADMIN_PERM,
9442 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9443 NL80211_FLAG_NEED_RTNL,
9444 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009445#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009446 {
9447 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9448 .doit = nl80211_set_rekey_data,
9449 .policy = nl80211_policy,
9450 .flags = GENL_ADMIN_PERM,
9451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9452 NL80211_FLAG_NEED_RTNL,
9453 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009454 {
9455 .cmd = NL80211_CMD_TDLS_MGMT,
9456 .doit = nl80211_tdls_mgmt,
9457 .policy = nl80211_policy,
9458 .flags = GENL_ADMIN_PERM,
9459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9460 NL80211_FLAG_NEED_RTNL,
9461 },
9462 {
9463 .cmd = NL80211_CMD_TDLS_OPER,
9464 .doit = nl80211_tdls_oper,
9465 .policy = nl80211_policy,
9466 .flags = GENL_ADMIN_PERM,
9467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9468 NL80211_FLAG_NEED_RTNL,
9469 },
Johannes Berg28946da2011-11-04 11:18:12 +01009470 {
9471 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9472 .doit = nl80211_register_unexpected_frame,
9473 .policy = nl80211_policy,
9474 .flags = GENL_ADMIN_PERM,
9475 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9476 NL80211_FLAG_NEED_RTNL,
9477 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009478 {
9479 .cmd = NL80211_CMD_PROBE_CLIENT,
9480 .doit = nl80211_probe_client,
9481 .policy = nl80211_policy,
9482 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009483 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009484 NL80211_FLAG_NEED_RTNL,
9485 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009486 {
9487 .cmd = NL80211_CMD_REGISTER_BEACONS,
9488 .doit = nl80211_register_beacons,
9489 .policy = nl80211_policy,
9490 .flags = GENL_ADMIN_PERM,
9491 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9492 NL80211_FLAG_NEED_RTNL,
9493 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009494 {
9495 .cmd = NL80211_CMD_SET_NOACK_MAP,
9496 .doit = nl80211_set_noack_map,
9497 .policy = nl80211_policy,
9498 .flags = GENL_ADMIN_PERM,
9499 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9500 NL80211_FLAG_NEED_RTNL,
9501 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009502 {
9503 .cmd = NL80211_CMD_START_P2P_DEVICE,
9504 .doit = nl80211_start_p2p_device,
9505 .policy = nl80211_policy,
9506 .flags = GENL_ADMIN_PERM,
9507 .internal_flags = NL80211_FLAG_NEED_WDEV |
9508 NL80211_FLAG_NEED_RTNL,
9509 },
9510 {
9511 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9512 .doit = nl80211_stop_p2p_device,
9513 .policy = nl80211_policy,
9514 .flags = GENL_ADMIN_PERM,
9515 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9516 NL80211_FLAG_NEED_RTNL,
9517 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009518 {
9519 .cmd = NL80211_CMD_SET_MCAST_RATE,
9520 .doit = nl80211_set_mcast_rate,
9521 .policy = nl80211_policy,
9522 .flags = GENL_ADMIN_PERM,
9523 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9524 NL80211_FLAG_NEED_RTNL,
9525 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309526 {
9527 .cmd = NL80211_CMD_SET_MAC_ACL,
9528 .doit = nl80211_set_mac_acl,
9529 .policy = nl80211_policy,
9530 .flags = GENL_ADMIN_PERM,
9531 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9532 NL80211_FLAG_NEED_RTNL,
9533 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009534 {
9535 .cmd = NL80211_CMD_RADAR_DETECT,
9536 .doit = nl80211_start_radar_detection,
9537 .policy = nl80211_policy,
9538 .flags = GENL_ADMIN_PERM,
9539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9540 NL80211_FLAG_NEED_RTNL,
9541 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009542 {
9543 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9544 .doit = nl80211_get_protocol_features,
9545 .policy = nl80211_policy,
9546 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009547 {
9548 .cmd = NL80211_CMD_UPDATE_FT_IES,
9549 .doit = nl80211_update_ft_ies,
9550 .policy = nl80211_policy,
9551 .flags = GENL_ADMIN_PERM,
9552 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9553 NL80211_FLAG_NEED_RTNL,
9554 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009555 {
9556 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9557 .doit = nl80211_crit_protocol_start,
9558 .policy = nl80211_policy,
9559 .flags = GENL_ADMIN_PERM,
9560 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9561 NL80211_FLAG_NEED_RTNL,
9562 },
9563 {
9564 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9565 .doit = nl80211_crit_protocol_stop,
9566 .policy = nl80211_policy,
9567 .flags = GENL_ADMIN_PERM,
9568 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9569 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009570 },
9571 {
9572 .cmd = NL80211_CMD_GET_COALESCE,
9573 .doit = nl80211_get_coalesce,
9574 .policy = nl80211_policy,
9575 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9576 NL80211_FLAG_NEED_RTNL,
9577 },
9578 {
9579 .cmd = NL80211_CMD_SET_COALESCE,
9580 .doit = nl80211_set_coalesce,
9581 .policy = nl80211_policy,
9582 .flags = GENL_ADMIN_PERM,
9583 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9584 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009585 },
9586 {
9587 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9588 .doit = nl80211_channel_switch,
9589 .policy = nl80211_policy,
9590 .flags = GENL_ADMIN_PERM,
9591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9592 NL80211_FLAG_NEED_RTNL,
9593 },
Johannes Berg55682962007-09-20 13:09:35 -04009594};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009595
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009596static struct genl_multicast_group nl80211_mlme_mcgrp = {
9597 .name = "mlme",
9598};
Johannes Berg55682962007-09-20 13:09:35 -04009599
9600/* multicast groups */
9601static struct genl_multicast_group nl80211_config_mcgrp = {
9602 .name = "config",
9603};
Johannes Berg2a519312009-02-10 21:25:55 +01009604static struct genl_multicast_group nl80211_scan_mcgrp = {
9605 .name = "scan",
9606};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009607static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9608 .name = "regulatory",
9609};
Johannes Berg55682962007-09-20 13:09:35 -04009610
9611/* notification functions */
9612
9613void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9614{
9615 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009616 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009617
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009618 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009619 if (!msg)
9620 return;
9621
Johannes Berg86e8cf92013-06-19 10:57:22 +02009622 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009623 nlmsg_free(msg);
9624 return;
9625 }
9626
Johannes Berg463d0182009-07-14 00:33:35 +02009627 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9628 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009629}
9630
Johannes Berg362a4152009-05-24 16:43:15 +02009631static int nl80211_add_scan_req(struct sk_buff *msg,
9632 struct cfg80211_registered_device *rdev)
9633{
9634 struct cfg80211_scan_request *req = rdev->scan_req;
9635 struct nlattr *nest;
9636 int i;
9637
9638 if (WARN_ON(!req))
9639 return 0;
9640
9641 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9642 if (!nest)
9643 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009644 for (i = 0; i < req->n_ssids; i++) {
9645 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9646 goto nla_put_failure;
9647 }
Johannes Berg362a4152009-05-24 16:43:15 +02009648 nla_nest_end(msg, nest);
9649
9650 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9651 if (!nest)
9652 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009653 for (i = 0; i < req->n_channels; i++) {
9654 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9655 goto nla_put_failure;
9656 }
Johannes Berg362a4152009-05-24 16:43:15 +02009657 nla_nest_end(msg, nest);
9658
David S. Miller9360ffd2012-03-29 04:41:26 -04009659 if (req->ie &&
9660 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9661 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009662
Sam Lefflered4737712012-10-11 21:03:31 -07009663 if (req->flags)
9664 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9665
Johannes Berg362a4152009-05-24 16:43:15 +02009666 return 0;
9667 nla_put_failure:
9668 return -ENOBUFS;
9669}
9670
Johannes Berga538e2d2009-06-16 19:56:42 +02009671static int nl80211_send_scan_msg(struct sk_buff *msg,
9672 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009673 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009674 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009675 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009676{
9677 void *hdr;
9678
Eric W. Biederman15e47302012-09-07 20:12:54 +00009679 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009680 if (!hdr)
9681 return -1;
9682
David S. Miller9360ffd2012-03-29 04:41:26 -04009683 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009684 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9685 wdev->netdev->ifindex)) ||
9686 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009687 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009688
Johannes Berg362a4152009-05-24 16:43:15 +02009689 /* ignore errors and send incomplete event anyway */
9690 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009691
9692 return genlmsg_end(msg, hdr);
9693
9694 nla_put_failure:
9695 genlmsg_cancel(msg, hdr);
9696 return -EMSGSIZE;
9697}
9698
Luciano Coelho807f8a82011-05-11 17:09:35 +03009699static int
9700nl80211_send_sched_scan_msg(struct sk_buff *msg,
9701 struct cfg80211_registered_device *rdev,
9702 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009703 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009704{
9705 void *hdr;
9706
Eric W. Biederman15e47302012-09-07 20:12:54 +00009707 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009708 if (!hdr)
9709 return -1;
9710
David S. Miller9360ffd2012-03-29 04:41:26 -04009711 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9712 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9713 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009714
9715 return genlmsg_end(msg, hdr);
9716
9717 nla_put_failure:
9718 genlmsg_cancel(msg, hdr);
9719 return -EMSGSIZE;
9720}
9721
Johannes Berga538e2d2009-06-16 19:56:42 +02009722void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009723 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009724{
9725 struct sk_buff *msg;
9726
Thomas Graf58050fc2012-06-28 03:57:45 +00009727 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009728 if (!msg)
9729 return;
9730
Johannes Bergfd014282012-06-18 19:17:03 +02009731 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009732 NL80211_CMD_TRIGGER_SCAN) < 0) {
9733 nlmsg_free(msg);
9734 return;
9735 }
9736
Johannes Berg463d0182009-07-14 00:33:35 +02009737 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9738 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009739}
9740
Johannes Berg2a519312009-02-10 21:25:55 +01009741void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009742 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009743{
9744 struct sk_buff *msg;
9745
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009746 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009747 if (!msg)
9748 return;
9749
Johannes Bergfd014282012-06-18 19:17:03 +02009750 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009751 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009752 nlmsg_free(msg);
9753 return;
9754 }
9755
Johannes Berg463d0182009-07-14 00:33:35 +02009756 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9757 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009758}
9759
9760void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009761 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009762{
9763 struct sk_buff *msg;
9764
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009766 if (!msg)
9767 return;
9768
Johannes Bergfd014282012-06-18 19:17:03 +02009769 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009770 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009771 nlmsg_free(msg);
9772 return;
9773 }
9774
Johannes Berg463d0182009-07-14 00:33:35 +02009775 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9776 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009777}
9778
Luciano Coelho807f8a82011-05-11 17:09:35 +03009779void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9780 struct net_device *netdev)
9781{
9782 struct sk_buff *msg;
9783
9784 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9785 if (!msg)
9786 return;
9787
9788 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9789 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9790 nlmsg_free(msg);
9791 return;
9792 }
9793
9794 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9795 nl80211_scan_mcgrp.id, GFP_KERNEL);
9796}
9797
9798void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9799 struct net_device *netdev, u32 cmd)
9800{
9801 struct sk_buff *msg;
9802
Thomas Graf58050fc2012-06-28 03:57:45 +00009803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009804 if (!msg)
9805 return;
9806
9807 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9808 nlmsg_free(msg);
9809 return;
9810 }
9811
9812 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9813 nl80211_scan_mcgrp.id, GFP_KERNEL);
9814}
9815
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009816/*
9817 * This can happen on global regulatory changes or device specific settings
9818 * based on custom world regulatory domains.
9819 */
9820void nl80211_send_reg_change_event(struct regulatory_request *request)
9821{
9822 struct sk_buff *msg;
9823 void *hdr;
9824
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009825 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009826 if (!msg)
9827 return;
9828
9829 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9830 if (!hdr) {
9831 nlmsg_free(msg);
9832 return;
9833 }
9834
9835 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009836 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9837 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009838
David S. Miller9360ffd2012-03-29 04:41:26 -04009839 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9840 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9841 NL80211_REGDOM_TYPE_WORLD))
9842 goto nla_put_failure;
9843 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9844 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9845 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9846 goto nla_put_failure;
9847 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9848 request->intersect) {
9849 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9850 NL80211_REGDOM_TYPE_INTERSECTION))
9851 goto nla_put_failure;
9852 } else {
9853 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9854 NL80211_REGDOM_TYPE_COUNTRY) ||
9855 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9856 request->alpha2))
9857 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009858 }
9859
Johannes Bergf4173762012-12-03 18:23:37 +01009860 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009861 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9862 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009863
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009864 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009865
Johannes Bergbc43b282009-07-25 10:54:13 +02009866 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009867 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009868 GFP_ATOMIC);
9869 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009870
9871 return;
9872
9873nla_put_failure:
9874 genlmsg_cancel(msg, hdr);
9875 nlmsg_free(msg);
9876}
9877
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009878static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9879 struct net_device *netdev,
9880 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009881 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009882{
9883 struct sk_buff *msg;
9884 void *hdr;
9885
Johannes Berge6d6e342009-07-01 21:26:47 +02009886 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009887 if (!msg)
9888 return;
9889
9890 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9891 if (!hdr) {
9892 nlmsg_free(msg);
9893 return;
9894 }
9895
David S. Miller9360ffd2012-03-29 04:41:26 -04009896 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9897 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9898 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9899 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009900
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009901 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009902
Johannes Berg463d0182009-07-14 00:33:35 +02009903 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9904 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009905 return;
9906
9907 nla_put_failure:
9908 genlmsg_cancel(msg, hdr);
9909 nlmsg_free(msg);
9910}
9911
9912void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009913 struct net_device *netdev, const u8 *buf,
9914 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009915{
9916 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009917 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009918}
9919
9920void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9921 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009922 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009923{
Johannes Berge6d6e342009-07-01 21:26:47 +02009924 nl80211_send_mlme_event(rdev, netdev, buf, len,
9925 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009926}
9927
Jouni Malinen53b46b82009-03-27 20:53:56 +02009928void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009929 struct net_device *netdev, const u8 *buf,
9930 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009931{
9932 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009933 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009934}
9935
Jouni Malinen53b46b82009-03-27 20:53:56 +02009936void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9937 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009938 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009939{
9940 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009941 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009942}
9943
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009944void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9945 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009946{
Johannes Berg947add32013-02-22 22:05:20 +01009947 struct wireless_dev *wdev = dev->ieee80211_ptr;
9948 struct wiphy *wiphy = wdev->wiphy;
9949 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009950 const struct ieee80211_mgmt *mgmt = (void *)buf;
9951 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009952
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009953 if (WARN_ON(len < 2))
9954 return;
9955
9956 if (ieee80211_is_deauth(mgmt->frame_control))
9957 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9958 else
9959 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9960
9961 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9962 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009963}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009964EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009965
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009966static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9967 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009968 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009969{
9970 struct sk_buff *msg;
9971 void *hdr;
9972
Johannes Berge6d6e342009-07-01 21:26:47 +02009973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009974 if (!msg)
9975 return;
9976
9977 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9978 if (!hdr) {
9979 nlmsg_free(msg);
9980 return;
9981 }
9982
David S. Miller9360ffd2012-03-29 04:41:26 -04009983 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9984 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9985 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9986 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9987 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009988
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009989 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009990
Johannes Berg463d0182009-07-14 00:33:35 +02009991 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9992 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009993 return;
9994
9995 nla_put_failure:
9996 genlmsg_cancel(msg, hdr);
9997 nlmsg_free(msg);
9998}
9999
10000void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010001 struct net_device *netdev, const u8 *addr,
10002 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010003{
10004 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010005 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010006}
10007
10008void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010009 struct net_device *netdev, const u8 *addr,
10010 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010011{
Johannes Berge6d6e342009-07-01 21:26:47 +020010012 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10013 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010014}
10015
Samuel Ortizb23aa672009-07-01 21:26:54 +020010016void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10017 struct net_device *netdev, const u8 *bssid,
10018 const u8 *req_ie, size_t req_ie_len,
10019 const u8 *resp_ie, size_t resp_ie_len,
10020 u16 status, gfp_t gfp)
10021{
10022 struct sk_buff *msg;
10023 void *hdr;
10024
Thomas Graf58050fc2012-06-28 03:57:45 +000010025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010026 if (!msg)
10027 return;
10028
10029 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10030 if (!hdr) {
10031 nlmsg_free(msg);
10032 return;
10033 }
10034
David S. Miller9360ffd2012-03-29 04:41:26 -040010035 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10036 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10037 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10038 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10039 (req_ie &&
10040 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10041 (resp_ie &&
10042 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10043 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010044
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010045 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010046
Johannes Berg463d0182009-07-14 00:33:35 +020010047 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10048 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010049 return;
10050
10051 nla_put_failure:
10052 genlmsg_cancel(msg, hdr);
10053 nlmsg_free(msg);
10054
10055}
10056
10057void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10058 struct net_device *netdev, const u8 *bssid,
10059 const u8 *req_ie, size_t req_ie_len,
10060 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10061{
10062 struct sk_buff *msg;
10063 void *hdr;
10064
Thomas Graf58050fc2012-06-28 03:57:45 +000010065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010066 if (!msg)
10067 return;
10068
10069 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10070 if (!hdr) {
10071 nlmsg_free(msg);
10072 return;
10073 }
10074
David S. Miller9360ffd2012-03-29 04:41:26 -040010075 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10076 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10077 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10078 (req_ie &&
10079 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10080 (resp_ie &&
10081 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10082 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010083
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010084 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010085
Johannes Berg463d0182009-07-14 00:33:35 +020010086 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10087 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010088 return;
10089
10090 nla_put_failure:
10091 genlmsg_cancel(msg, hdr);
10092 nlmsg_free(msg);
10093
10094}
10095
10096void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10097 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010098 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010099{
10100 struct sk_buff *msg;
10101 void *hdr;
10102
Thomas Graf58050fc2012-06-28 03:57:45 +000010103 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010104 if (!msg)
10105 return;
10106
10107 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10108 if (!hdr) {
10109 nlmsg_free(msg);
10110 return;
10111 }
10112
David S. Miller9360ffd2012-03-29 04:41:26 -040010113 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10114 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10115 (from_ap && reason &&
10116 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10117 (from_ap &&
10118 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10119 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10120 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010121
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010122 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010123
Johannes Berg463d0182009-07-14 00:33:35 +020010124 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10125 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010126 return;
10127
10128 nla_put_failure:
10129 genlmsg_cancel(msg, hdr);
10130 nlmsg_free(msg);
10131
10132}
10133
Johannes Berg04a773a2009-04-19 21:24:32 +020010134void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10135 struct net_device *netdev, const u8 *bssid,
10136 gfp_t gfp)
10137{
10138 struct sk_buff *msg;
10139 void *hdr;
10140
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010142 if (!msg)
10143 return;
10144
10145 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10146 if (!hdr) {
10147 nlmsg_free(msg);
10148 return;
10149 }
10150
David S. Miller9360ffd2012-03-29 04:41:26 -040010151 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10152 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10153 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10154 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010155
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010156 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010157
Johannes Berg463d0182009-07-14 00:33:35 +020010158 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10159 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010160 return;
10161
10162 nla_put_failure:
10163 genlmsg_cancel(msg, hdr);
10164 nlmsg_free(msg);
10165}
10166
Johannes Berg947add32013-02-22 22:05:20 +010010167void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10168 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010169{
Johannes Berg947add32013-02-22 22:05:20 +010010170 struct wireless_dev *wdev = dev->ieee80211_ptr;
10171 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010172 struct sk_buff *msg;
10173 void *hdr;
10174
Johannes Berg947add32013-02-22 22:05:20 +010010175 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10176 return;
10177
10178 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10179
Javier Cardonac93b5e72011-04-07 15:08:34 -070010180 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10181 if (!msg)
10182 return;
10183
10184 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10185 if (!hdr) {
10186 nlmsg_free(msg);
10187 return;
10188 }
10189
David S. Miller9360ffd2012-03-29 04:41:26 -040010190 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10192 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010193 (ie_len && ie &&
10194 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10195 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010196
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010197 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010198
10199 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10200 nl80211_mlme_mcgrp.id, gfp);
10201 return;
10202
10203 nla_put_failure:
10204 genlmsg_cancel(msg, hdr);
10205 nlmsg_free(msg);
10206}
Johannes Berg947add32013-02-22 22:05:20 +010010207EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010208
Jouni Malinena3b8b052009-03-27 21:59:49 +020010209void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10210 struct net_device *netdev, const u8 *addr,
10211 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010212 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010213{
10214 struct sk_buff *msg;
10215 void *hdr;
10216
Johannes Berge6d6e342009-07-01 21:26:47 +020010217 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010218 if (!msg)
10219 return;
10220
10221 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10222 if (!hdr) {
10223 nlmsg_free(msg);
10224 return;
10225 }
10226
David S. Miller9360ffd2012-03-29 04:41:26 -040010227 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10228 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10229 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10230 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10231 (key_id != -1 &&
10232 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10233 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10234 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010235
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010236 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010237
Johannes Berg463d0182009-07-14 00:33:35 +020010238 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10239 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010240 return;
10241
10242 nla_put_failure:
10243 genlmsg_cancel(msg, hdr);
10244 nlmsg_free(msg);
10245}
10246
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010247void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10248 struct ieee80211_channel *channel_before,
10249 struct ieee80211_channel *channel_after)
10250{
10251 struct sk_buff *msg;
10252 void *hdr;
10253 struct nlattr *nl_freq;
10254
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010255 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010256 if (!msg)
10257 return;
10258
10259 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10260 if (!hdr) {
10261 nlmsg_free(msg);
10262 return;
10263 }
10264
10265 /*
10266 * Since we are applying the beacon hint to a wiphy we know its
10267 * wiphy_idx is valid
10268 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10270 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010271
10272 /* Before */
10273 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10274 if (!nl_freq)
10275 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010276 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010277 goto nla_put_failure;
10278 nla_nest_end(msg, nl_freq);
10279
10280 /* After */
10281 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10282 if (!nl_freq)
10283 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010284 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010285 goto nla_put_failure;
10286 nla_nest_end(msg, nl_freq);
10287
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010288 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010289
Johannes Berg463d0182009-07-14 00:33:35 +020010290 rcu_read_lock();
10291 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10292 GFP_ATOMIC);
10293 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010294
10295 return;
10296
10297nla_put_failure:
10298 genlmsg_cancel(msg, hdr);
10299 nlmsg_free(msg);
10300}
10301
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010302static void nl80211_send_remain_on_chan_event(
10303 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010304 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010305 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010306 unsigned int duration, gfp_t gfp)
10307{
10308 struct sk_buff *msg;
10309 void *hdr;
10310
10311 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10312 if (!msg)
10313 return;
10314
10315 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10316 if (!hdr) {
10317 nlmsg_free(msg);
10318 return;
10319 }
10320
David S. Miller9360ffd2012-03-29 04:41:26 -040010321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010322 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10323 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010324 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010325 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010326 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10327 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010328 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10329 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010330
David S. Miller9360ffd2012-03-29 04:41:26 -040010331 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10332 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10333 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010334
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010335 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010336
10337 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10338 nl80211_mlme_mcgrp.id, gfp);
10339 return;
10340
10341 nla_put_failure:
10342 genlmsg_cancel(msg, hdr);
10343 nlmsg_free(msg);
10344}
10345
Johannes Berg947add32013-02-22 22:05:20 +010010346void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10347 struct ieee80211_channel *chan,
10348 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010349{
Johannes Berg947add32013-02-22 22:05:20 +010010350 struct wiphy *wiphy = wdev->wiphy;
10351 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10352
10353 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010354 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010355 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010356 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010357}
Johannes Berg947add32013-02-22 22:05:20 +010010358EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010359
Johannes Berg947add32013-02-22 22:05:20 +010010360void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10361 struct ieee80211_channel *chan,
10362 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010363{
Johannes Berg947add32013-02-22 22:05:20 +010010364 struct wiphy *wiphy = wdev->wiphy;
10365 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10366
10367 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010368 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010369 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010370}
Johannes Berg947add32013-02-22 22:05:20 +010010371EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010372
Johannes Berg947add32013-02-22 22:05:20 +010010373void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10374 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010375{
Johannes Berg947add32013-02-22 22:05:20 +010010376 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10377 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010378 struct sk_buff *msg;
10379
Johannes Berg947add32013-02-22 22:05:20 +010010380 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10381
Thomas Graf58050fc2012-06-28 03:57:45 +000010382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010383 if (!msg)
10384 return;
10385
John W. Linville66266b32012-03-15 13:25:41 -040010386 if (nl80211_send_station(msg, 0, 0, 0,
10387 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010388 nlmsg_free(msg);
10389 return;
10390 }
10391
10392 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10393 nl80211_mlme_mcgrp.id, gfp);
10394}
Johannes Berg947add32013-02-22 22:05:20 +010010395EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010396
Johannes Berg947add32013-02-22 22:05:20 +010010397void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010398{
Johannes Berg947add32013-02-22 22:05:20 +010010399 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10400 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010401 struct sk_buff *msg;
10402 void *hdr;
10403
Johannes Berg947add32013-02-22 22:05:20 +010010404 trace_cfg80211_del_sta(dev, mac_addr);
10405
Thomas Graf58050fc2012-06-28 03:57:45 +000010406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010407 if (!msg)
10408 return;
10409
10410 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10411 if (!hdr) {
10412 nlmsg_free(msg);
10413 return;
10414 }
10415
David S. Miller9360ffd2012-03-29 04:41:26 -040010416 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10417 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10418 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010419
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010420 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010421
10422 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10423 nl80211_mlme_mcgrp.id, gfp);
10424 return;
10425
10426 nla_put_failure:
10427 genlmsg_cancel(msg, hdr);
10428 nlmsg_free(msg);
10429}
Johannes Berg947add32013-02-22 22:05:20 +010010430EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010431
Johannes Berg947add32013-02-22 22:05:20 +010010432void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10433 enum nl80211_connect_failed_reason reason,
10434 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010435{
Johannes Berg947add32013-02-22 22:05:20 +010010436 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10437 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010438 struct sk_buff *msg;
10439 void *hdr;
10440
10441 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10442 if (!msg)
10443 return;
10444
10445 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10446 if (!hdr) {
10447 nlmsg_free(msg);
10448 return;
10449 }
10450
10451 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10452 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10453 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10454 goto nla_put_failure;
10455
10456 genlmsg_end(msg, hdr);
10457
10458 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10459 nl80211_mlme_mcgrp.id, gfp);
10460 return;
10461
10462 nla_put_failure:
10463 genlmsg_cancel(msg, hdr);
10464 nlmsg_free(msg);
10465}
Johannes Berg947add32013-02-22 22:05:20 +010010466EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010467
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010468static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10469 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010470{
10471 struct wireless_dev *wdev = dev->ieee80211_ptr;
10472 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10473 struct sk_buff *msg;
10474 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010475 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010476
Eric W. Biederman15e47302012-09-07 20:12:54 +000010477 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010478 return false;
10479
10480 msg = nlmsg_new(100, gfp);
10481 if (!msg)
10482 return true;
10483
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010484 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010485 if (!hdr) {
10486 nlmsg_free(msg);
10487 return true;
10488 }
10489
David S. Miller9360ffd2012-03-29 04:41:26 -040010490 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10491 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10492 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10493 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010494
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010495 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010496 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010497 return true;
10498
10499 nla_put_failure:
10500 genlmsg_cancel(msg, hdr);
10501 nlmsg_free(msg);
10502 return true;
10503}
10504
Johannes Berg947add32013-02-22 22:05:20 +010010505bool cfg80211_rx_spurious_frame(struct net_device *dev,
10506 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010507{
Johannes Berg947add32013-02-22 22:05:20 +010010508 struct wireless_dev *wdev = dev->ieee80211_ptr;
10509 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010510
Johannes Berg947add32013-02-22 22:05:20 +010010511 trace_cfg80211_rx_spurious_frame(dev, addr);
10512
10513 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10514 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10515 trace_cfg80211_return_bool(false);
10516 return false;
10517 }
10518 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10519 addr, gfp);
10520 trace_cfg80211_return_bool(ret);
10521 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010522}
Johannes Berg947add32013-02-22 22:05:20 +010010523EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10524
10525bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10526 const u8 *addr, gfp_t gfp)
10527{
10528 struct wireless_dev *wdev = dev->ieee80211_ptr;
10529 bool ret;
10530
10531 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10532
10533 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10534 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10535 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10536 trace_cfg80211_return_bool(false);
10537 return false;
10538 }
10539 ret = __nl80211_unexpected_frame(dev,
10540 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10541 addr, gfp);
10542 trace_cfg80211_return_bool(ret);
10543 return ret;
10544}
10545EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010546
Johannes Berg2e161f72010-08-12 15:38:38 +020010547int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010548 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010549 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010550 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010551{
Johannes Berg71bbc992012-06-15 15:30:18 +020010552 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010553 struct sk_buff *msg;
10554 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010555
10556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10557 if (!msg)
10558 return -ENOMEM;
10559
Johannes Berg2e161f72010-08-12 15:38:38 +020010560 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010561 if (!hdr) {
10562 nlmsg_free(msg);
10563 return -ENOMEM;
10564 }
10565
David S. Miller9360ffd2012-03-29 04:41:26 -040010566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010567 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10568 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010569 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010570 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10571 (sig_dbm &&
10572 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010573 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10574 (flags &&
10575 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010576 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010577
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010578 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010579
Eric W. Biederman15e47302012-09-07 20:12:54 +000010580 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010581
10582 nla_put_failure:
10583 genlmsg_cancel(msg, hdr);
10584 nlmsg_free(msg);
10585 return -ENOBUFS;
10586}
10587
Johannes Berg947add32013-02-22 22:05:20 +010010588void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10589 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010590{
Johannes Berg947add32013-02-22 22:05:20 +010010591 struct wiphy *wiphy = wdev->wiphy;
10592 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010593 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010594 struct sk_buff *msg;
10595 void *hdr;
10596
Johannes Berg947add32013-02-22 22:05:20 +010010597 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10598
Jouni Malinen026331c2010-02-15 12:53:10 +020010599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10600 if (!msg)
10601 return;
10602
Johannes Berg2e161f72010-08-12 15:38:38 +020010603 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010604 if (!hdr) {
10605 nlmsg_free(msg);
10606 return;
10607 }
10608
David S. Miller9360ffd2012-03-29 04:41:26 -040010609 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010610 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10611 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010612 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010613 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10614 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10615 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10616 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010617
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010618 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010619
Michal Kaziora0ec5702013-06-25 09:17:17 +020010620 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10621 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010622 return;
10623
10624 nla_put_failure:
10625 genlmsg_cancel(msg, hdr);
10626 nlmsg_free(msg);
10627}
Johannes Berg947add32013-02-22 22:05:20 +010010628EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010629
Johannes Berg947add32013-02-22 22:05:20 +010010630void cfg80211_cqm_rssi_notify(struct net_device *dev,
10631 enum nl80211_cqm_rssi_threshold_event rssi_event,
10632 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010633{
Johannes Berg947add32013-02-22 22:05:20 +010010634 struct wireless_dev *wdev = dev->ieee80211_ptr;
10635 struct wiphy *wiphy = wdev->wiphy;
10636 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010637 struct sk_buff *msg;
10638 struct nlattr *pinfoattr;
10639 void *hdr;
10640
Johannes Berg947add32013-02-22 22:05:20 +010010641 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10642
Thomas Graf58050fc2012-06-28 03:57:45 +000010643 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010644 if (!msg)
10645 return;
10646
10647 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10648 if (!hdr) {
10649 nlmsg_free(msg);
10650 return;
10651 }
10652
David S. Miller9360ffd2012-03-29 04:41:26 -040010653 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010654 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010655 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010656
10657 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10658 if (!pinfoattr)
10659 goto nla_put_failure;
10660
David S. Miller9360ffd2012-03-29 04:41:26 -040010661 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10662 rssi_event))
10663 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010664
10665 nla_nest_end(msg, pinfoattr);
10666
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010667 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010668
10669 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10670 nl80211_mlme_mcgrp.id, gfp);
10671 return;
10672
10673 nla_put_failure:
10674 genlmsg_cancel(msg, hdr);
10675 nlmsg_free(msg);
10676}
Johannes Berg947add32013-02-22 22:05:20 +010010677EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010678
Johannes Berg947add32013-02-22 22:05:20 +010010679static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10680 struct net_device *netdev, const u8 *bssid,
10681 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010682{
10683 struct sk_buff *msg;
10684 struct nlattr *rekey_attr;
10685 void *hdr;
10686
Thomas Graf58050fc2012-06-28 03:57:45 +000010687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010688 if (!msg)
10689 return;
10690
10691 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10692 if (!hdr) {
10693 nlmsg_free(msg);
10694 return;
10695 }
10696
David S. Miller9360ffd2012-03-29 04:41:26 -040010697 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10698 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10699 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10700 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010701
10702 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10703 if (!rekey_attr)
10704 goto nla_put_failure;
10705
David S. Miller9360ffd2012-03-29 04:41:26 -040010706 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10707 NL80211_REPLAY_CTR_LEN, replay_ctr))
10708 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010709
10710 nla_nest_end(msg, rekey_attr);
10711
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010712 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010713
10714 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10715 nl80211_mlme_mcgrp.id, gfp);
10716 return;
10717
10718 nla_put_failure:
10719 genlmsg_cancel(msg, hdr);
10720 nlmsg_free(msg);
10721}
10722
Johannes Berg947add32013-02-22 22:05:20 +010010723void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10724 const u8 *replay_ctr, gfp_t gfp)
10725{
10726 struct wireless_dev *wdev = dev->ieee80211_ptr;
10727 struct wiphy *wiphy = wdev->wiphy;
10728 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10729
10730 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10731 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10732}
10733EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10734
10735static void
10736nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10737 struct net_device *netdev, int index,
10738 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010739{
10740 struct sk_buff *msg;
10741 struct nlattr *attr;
10742 void *hdr;
10743
Thomas Graf58050fc2012-06-28 03:57:45 +000010744 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010745 if (!msg)
10746 return;
10747
10748 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10749 if (!hdr) {
10750 nlmsg_free(msg);
10751 return;
10752 }
10753
David S. Miller9360ffd2012-03-29 04:41:26 -040010754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10755 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10756 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010757
10758 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10759 if (!attr)
10760 goto nla_put_failure;
10761
David S. Miller9360ffd2012-03-29 04:41:26 -040010762 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10763 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10764 (preauth &&
10765 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10766 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010767
10768 nla_nest_end(msg, attr);
10769
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010770 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010771
10772 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10773 nl80211_mlme_mcgrp.id, gfp);
10774 return;
10775
10776 nla_put_failure:
10777 genlmsg_cancel(msg, hdr);
10778 nlmsg_free(msg);
10779}
10780
Johannes Berg947add32013-02-22 22:05:20 +010010781void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10782 const u8 *bssid, bool preauth, gfp_t gfp)
10783{
10784 struct wireless_dev *wdev = dev->ieee80211_ptr;
10785 struct wiphy *wiphy = wdev->wiphy;
10786 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10787
10788 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10789 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10790}
10791EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10792
10793static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10794 struct net_device *netdev,
10795 struct cfg80211_chan_def *chandef,
10796 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010797{
10798 struct sk_buff *msg;
10799 void *hdr;
10800
Thomas Graf58050fc2012-06-28 03:57:45 +000010801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010802 if (!msg)
10803 return;
10804
10805 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10806 if (!hdr) {
10807 nlmsg_free(msg);
10808 return;
10809 }
10810
Johannes Berg683b6d32012-11-08 21:25:48 +010010811 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10812 goto nla_put_failure;
10813
10814 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010815 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010816
10817 genlmsg_end(msg, hdr);
10818
10819 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10820 nl80211_mlme_mcgrp.id, gfp);
10821 return;
10822
10823 nla_put_failure:
10824 genlmsg_cancel(msg, hdr);
10825 nlmsg_free(msg);
10826}
10827
Johannes Berg947add32013-02-22 22:05:20 +010010828void cfg80211_ch_switch_notify(struct net_device *dev,
10829 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010830{
Johannes Berg947add32013-02-22 22:05:20 +010010831 struct wireless_dev *wdev = dev->ieee80211_ptr;
10832 struct wiphy *wiphy = wdev->wiphy;
10833 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10834
Simon Wunderliche487eae2013-11-21 18:19:51 +010010835 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010010836
Simon Wunderliche487eae2013-11-21 18:19:51 +010010837 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010010838
10839 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020010840 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070010841 wdev->iftype != NL80211_IFTYPE_ADHOC &&
10842 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010010843 return;
Johannes Berg947add32013-02-22 22:05:20 +010010844
10845 wdev->channel = chandef->chan;
10846 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010010847}
10848EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10849
10850void cfg80211_cqm_txe_notify(struct net_device *dev,
10851 const u8 *peer, u32 num_packets,
10852 u32 rate, u32 intvl, gfp_t gfp)
10853{
10854 struct wireless_dev *wdev = dev->ieee80211_ptr;
10855 struct wiphy *wiphy = wdev->wiphy;
10856 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010857 struct sk_buff *msg;
10858 struct nlattr *pinfoattr;
10859 void *hdr;
10860
10861 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10862 if (!msg)
10863 return;
10864
10865 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10866 if (!hdr) {
10867 nlmsg_free(msg);
10868 return;
10869 }
10870
10871 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010872 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010873 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10874 goto nla_put_failure;
10875
10876 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10877 if (!pinfoattr)
10878 goto nla_put_failure;
10879
10880 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10881 goto nla_put_failure;
10882
10883 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10884 goto nla_put_failure;
10885
10886 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10887 goto nla_put_failure;
10888
10889 nla_nest_end(msg, pinfoattr);
10890
10891 genlmsg_end(msg, hdr);
10892
10893 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10894 nl80211_mlme_mcgrp.id, gfp);
10895 return;
10896
10897 nla_put_failure:
10898 genlmsg_cancel(msg, hdr);
10899 nlmsg_free(msg);
10900}
Johannes Berg947add32013-02-22 22:05:20 +010010901EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010902
10903void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010904nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010010905 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010010906 enum nl80211_radar_event event,
10907 struct net_device *netdev, gfp_t gfp)
10908{
10909 struct sk_buff *msg;
10910 void *hdr;
10911
10912 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10913 if (!msg)
10914 return;
10915
10916 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10917 if (!hdr) {
10918 nlmsg_free(msg);
10919 return;
10920 }
10921
10922 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10923 goto nla_put_failure;
10924
10925 /* NOP and radar events don't need a netdev parameter */
10926 if (netdev) {
10927 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10928
10929 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10930 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10931 goto nla_put_failure;
10932 }
10933
10934 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10935 goto nla_put_failure;
10936
10937 if (nl80211_send_chandef(msg, chandef))
10938 goto nla_put_failure;
10939
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010940 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010941
10942 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10943 nl80211_mlme_mcgrp.id, gfp);
10944 return;
10945
10946 nla_put_failure:
10947 genlmsg_cancel(msg, hdr);
10948 nlmsg_free(msg);
10949}
10950
Johannes Berg947add32013-02-22 22:05:20 +010010951void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10952 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010953{
Johannes Berg947add32013-02-22 22:05:20 +010010954 struct wireless_dev *wdev = dev->ieee80211_ptr;
10955 struct wiphy *wiphy = wdev->wiphy;
10956 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010957 struct sk_buff *msg;
10958 struct nlattr *pinfoattr;
10959 void *hdr;
10960
Johannes Berg947add32013-02-22 22:05:20 +010010961 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10962
Thomas Graf58050fc2012-06-28 03:57:45 +000010963 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010964 if (!msg)
10965 return;
10966
10967 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10968 if (!hdr) {
10969 nlmsg_free(msg);
10970 return;
10971 }
10972
David S. Miller9360ffd2012-03-29 04:41:26 -040010973 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010974 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010975 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10976 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010977
10978 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10979 if (!pinfoattr)
10980 goto nla_put_failure;
10981
David S. Miller9360ffd2012-03-29 04:41:26 -040010982 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10983 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010984
10985 nla_nest_end(msg, pinfoattr);
10986
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010987 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010988
10989 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10990 nl80211_mlme_mcgrp.id, gfp);
10991 return;
10992
10993 nla_put_failure:
10994 genlmsg_cancel(msg, hdr);
10995 nlmsg_free(msg);
10996}
Johannes Berg947add32013-02-22 22:05:20 +010010997EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010998
Johannes Berg7f6cf312011-11-04 11:18:15 +010010999void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11000 u64 cookie, bool acked, gfp_t gfp)
11001{
11002 struct wireless_dev *wdev = dev->ieee80211_ptr;
11003 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11004 struct sk_buff *msg;
11005 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011006
Beni Lev4ee3e062012-08-27 12:49:39 +030011007 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11008
Thomas Graf58050fc2012-06-28 03:57:45 +000011009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011010
Johannes Berg7f6cf312011-11-04 11:18:15 +010011011 if (!msg)
11012 return;
11013
11014 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11015 if (!hdr) {
11016 nlmsg_free(msg);
11017 return;
11018 }
11019
David S. Miller9360ffd2012-03-29 04:41:26 -040011020 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11021 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11022 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11023 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11024 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11025 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011026
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011027 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011028
11029 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11030 nl80211_mlme_mcgrp.id, gfp);
11031 return;
11032
11033 nla_put_failure:
11034 genlmsg_cancel(msg, hdr);
11035 nlmsg_free(msg);
11036}
11037EXPORT_SYMBOL(cfg80211_probe_status);
11038
Johannes Berg5e7602302011-11-04 11:18:17 +010011039void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11040 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011041 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010011042{
11043 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11044 struct sk_buff *msg;
11045 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011046 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010011047
Beni Lev4ee3e062012-08-27 12:49:39 +030011048 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11049
Ben Greear37c73b52012-10-26 14:49:25 -070011050 spin_lock_bh(&rdev->beacon_registrations_lock);
11051 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11052 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11053 if (!msg) {
11054 spin_unlock_bh(&rdev->beacon_registrations_lock);
11055 return;
11056 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011057
Ben Greear37c73b52012-10-26 14:49:25 -070011058 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11059 if (!hdr)
11060 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010011061
Ben Greear37c73b52012-10-26 14:49:25 -070011062 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11063 (freq &&
11064 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11065 (sig_dbm &&
11066 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11067 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11068 goto nla_put_failure;
11069
11070 genlmsg_end(msg, hdr);
11071
11072 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010011073 }
Ben Greear37c73b52012-10-26 14:49:25 -070011074 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011075 return;
11076
11077 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011078 spin_unlock_bh(&rdev->beacon_registrations_lock);
11079 if (hdr)
11080 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011081 nlmsg_free(msg);
11082}
11083EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11084
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011085#ifdef CONFIG_PM
11086void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11087 struct cfg80211_wowlan_wakeup *wakeup,
11088 gfp_t gfp)
11089{
11090 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11091 struct sk_buff *msg;
11092 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011093 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011094
11095 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11096
11097 if (wakeup)
11098 size += wakeup->packet_present_len;
11099
11100 msg = nlmsg_new(size, gfp);
11101 if (!msg)
11102 return;
11103
11104 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11105 if (!hdr)
11106 goto free_msg;
11107
11108 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11109 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11110 goto free_msg;
11111
11112 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11113 wdev->netdev->ifindex))
11114 goto free_msg;
11115
11116 if (wakeup) {
11117 struct nlattr *reasons;
11118
11119 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11120
11121 if (wakeup->disconnect &&
11122 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11123 goto free_msg;
11124 if (wakeup->magic_pkt &&
11125 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11126 goto free_msg;
11127 if (wakeup->gtk_rekey_failure &&
11128 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11129 goto free_msg;
11130 if (wakeup->eap_identity_req &&
11131 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11132 goto free_msg;
11133 if (wakeup->four_way_handshake &&
11134 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11135 goto free_msg;
11136 if (wakeup->rfkill_release &&
11137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11138 goto free_msg;
11139
11140 if (wakeup->pattern_idx >= 0 &&
11141 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11142 wakeup->pattern_idx))
11143 goto free_msg;
11144
Johannes Berg2a0e0472013-01-23 22:57:40 +010011145 if (wakeup->tcp_match)
11146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11147
11148 if (wakeup->tcp_connlost)
11149 nla_put_flag(msg,
11150 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11151
11152 if (wakeup->tcp_nomoretokens)
11153 nla_put_flag(msg,
11154 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11155
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011156 if (wakeup->packet) {
11157 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11158 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11159
11160 if (!wakeup->packet_80211) {
11161 pkt_attr =
11162 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11163 len_attr =
11164 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11165 }
11166
11167 if (wakeup->packet_len &&
11168 nla_put_u32(msg, len_attr, wakeup->packet_len))
11169 goto free_msg;
11170
11171 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11172 wakeup->packet))
11173 goto free_msg;
11174 }
11175
11176 nla_nest_end(msg, reasons);
11177 }
11178
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011179 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011180
11181 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11182 nl80211_mlme_mcgrp.id, gfp);
11183 return;
11184
11185 free_msg:
11186 nlmsg_free(msg);
11187}
11188EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11189#endif
11190
Jouni Malinen3475b092012-11-16 22:49:57 +020011191void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11192 enum nl80211_tdls_operation oper,
11193 u16 reason_code, gfp_t gfp)
11194{
11195 struct wireless_dev *wdev = dev->ieee80211_ptr;
11196 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11197 struct sk_buff *msg;
11198 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011199
11200 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11201 reason_code);
11202
11203 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11204 if (!msg)
11205 return;
11206
11207 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11208 if (!hdr) {
11209 nlmsg_free(msg);
11210 return;
11211 }
11212
11213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11214 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11215 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11216 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11217 (reason_code > 0 &&
11218 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11219 goto nla_put_failure;
11220
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011221 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011222
11223 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11224 nl80211_mlme_mcgrp.id, gfp);
11225 return;
11226
11227 nla_put_failure:
11228 genlmsg_cancel(msg, hdr);
11229 nlmsg_free(msg);
11230}
11231EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11232
Jouni Malinen026331c2010-02-15 12:53:10 +020011233static int nl80211_netlink_notify(struct notifier_block * nb,
11234 unsigned long state,
11235 void *_notify)
11236{
11237 struct netlink_notify *notify = _notify;
11238 struct cfg80211_registered_device *rdev;
11239 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011240 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011241
11242 if (state != NETLINK_URELEASE)
11243 return NOTIFY_DONE;
11244
11245 rcu_read_lock();
11246
Johannes Berg5e7602302011-11-04 11:18:17 +010011247 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011248 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011249 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011250
11251 spin_lock_bh(&rdev->beacon_registrations_lock);
11252 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11253 list) {
11254 if (reg->nlportid == notify->portid) {
11255 list_del(&reg->list);
11256 kfree(reg);
11257 break;
11258 }
11259 }
11260 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011261 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011262
11263 rcu_read_unlock();
11264
11265 return NOTIFY_DONE;
11266}
11267
11268static struct notifier_block nl80211_netlink_notifier = {
11269 .notifier_call = nl80211_netlink_notify,
11270};
11271
Jouni Malinen355199e2013-02-27 17:14:27 +020011272void cfg80211_ft_event(struct net_device *netdev,
11273 struct cfg80211_ft_event_params *ft_event)
11274{
11275 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11276 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11277 struct sk_buff *msg;
11278 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011279
11280 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11281
11282 if (!ft_event->target_ap)
11283 return;
11284
11285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11286 if (!msg)
11287 return;
11288
11289 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11290 if (!hdr) {
11291 nlmsg_free(msg);
11292 return;
11293 }
11294
11295 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11296 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11297 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11298 if (ft_event->ies)
11299 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11300 if (ft_event->ric_ies)
11301 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11302 ft_event->ric_ies);
11303
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011304 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011305
11306 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11307 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11308}
11309EXPORT_SYMBOL(cfg80211_ft_event);
11310
Arend van Spriel5de17982013-04-18 15:49:00 +020011311void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11312{
11313 struct cfg80211_registered_device *rdev;
11314 struct sk_buff *msg;
11315 void *hdr;
11316 u32 nlportid;
11317
11318 rdev = wiphy_to_dev(wdev->wiphy);
11319 if (!rdev->crit_proto_nlportid)
11320 return;
11321
11322 nlportid = rdev->crit_proto_nlportid;
11323 rdev->crit_proto_nlportid = 0;
11324
11325 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11326 if (!msg)
11327 return;
11328
11329 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11330 if (!hdr)
11331 goto nla_put_failure;
11332
11333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11334 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11335 goto nla_put_failure;
11336
11337 genlmsg_end(msg, hdr);
11338
11339 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11340 return;
11341
11342 nla_put_failure:
11343 if (hdr)
11344 genlmsg_cancel(msg, hdr);
11345 nlmsg_free(msg);
11346
11347}
11348EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11349
Johannes Berg55682962007-09-20 13:09:35 -040011350/* initialisation/exit functions */
11351
11352int nl80211_init(void)
11353{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011354 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011355
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011356 err = genl_register_family_with_ops(&nl80211_fam,
11357 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011358 if (err)
11359 return err;
11360
Johannes Berg55682962007-09-20 13:09:35 -040011361 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11362 if (err)
11363 goto err_out;
11364
Johannes Berg2a519312009-02-10 21:25:55 +010011365 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11366 if (err)
11367 goto err_out;
11368
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011369 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11370 if (err)
11371 goto err_out;
11372
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011373 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11374 if (err)
11375 goto err_out;
11376
Johannes Bergaff89a92009-07-01 21:26:51 +020011377#ifdef CONFIG_NL80211_TESTMODE
11378 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11379 if (err)
11380 goto err_out;
11381#endif
11382
Jouni Malinen026331c2010-02-15 12:53:10 +020011383 err = netlink_register_notifier(&nl80211_netlink_notifier);
11384 if (err)
11385 goto err_out;
11386
Johannes Berg55682962007-09-20 13:09:35 -040011387 return 0;
11388 err_out:
11389 genl_unregister_family(&nl80211_fam);
11390 return err;
11391}
11392
11393void nl80211_exit(void)
11394{
Jouni Malinen026331c2010-02-15 12:53:10 +020011395 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011396 genl_unregister_family(&nl80211_fam);
11397}