blob: f7cb12178bd23a4e739e91a2a098381aea46a12f [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 },
Johannes Berg55682962007-09-20 13:09:35 -0400357};
358
Johannes Berge31b8212010-10-05 19:39:30 +0200359/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000360static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200361 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200362 [NL80211_KEY_IDX] = { .type = NLA_U8 },
363 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200364 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200365 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
366 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200367 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100368 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
369};
370
371/* policy for the key default flags */
372static const struct nla_policy
373nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
374 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
375 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200376};
377
Johannes Bergff1b6e62011-05-04 15:37:28 +0200378/* policy for WoWLAN attributes */
379static const struct nla_policy
380nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
381 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200385 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100389 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
390};
391
392static const struct nla_policy
393nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
394 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
395 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
396 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
397 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
398 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
399 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
400 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
401 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
402 },
403 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
404 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
405 },
406 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
407 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
408 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200409};
410
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700411/* policy for coalesce rule attributes */
412static const struct nla_policy
413nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
414 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
415 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
416 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
417};
418
Johannes Berge5497d72011-07-05 16:35:40 +0200419/* policy for GTK rekey offload attributes */
420static const struct nla_policy
421nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
422 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
423 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
424 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
425};
426
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300427static const struct nla_policy
428nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200429 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300430 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700431 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300432};
433
Johannes Berg97990a02013-04-19 01:02:55 +0200434static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
435 struct netlink_callback *cb,
436 struct cfg80211_registered_device **rdev,
437 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100438{
Johannes Berg67748892010-10-04 21:14:06 +0200439 int err;
440
Johannes Berg67748892010-10-04 21:14:06 +0200441 rtnl_lock();
442
Johannes Berg97990a02013-04-19 01:02:55 +0200443 if (!cb->args[0]) {
444 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
445 nl80211_fam.attrbuf, nl80211_fam.maxattr,
446 nl80211_policy);
447 if (err)
448 goto out_unlock;
449
450 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
451 nl80211_fam.attrbuf);
452 if (IS_ERR(*wdev)) {
453 err = PTR_ERR(*wdev);
454 goto out_unlock;
455 }
456 *rdev = wiphy_to_dev((*wdev)->wiphy);
457 cb->args[0] = (*rdev)->wiphy_idx;
458 cb->args[1] = (*wdev)->identifier;
459 } else {
460 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
461 struct wireless_dev *tmp;
462
463 if (!wiphy) {
464 err = -ENODEV;
465 goto out_unlock;
466 }
467 *rdev = wiphy_to_dev(wiphy);
468 *wdev = NULL;
469
Johannes Berg97990a02013-04-19 01:02:55 +0200470 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
471 if (tmp->identifier == cb->args[1]) {
472 *wdev = tmp;
473 break;
474 }
475 }
Johannes Berg97990a02013-04-19 01:02:55 +0200476
477 if (!*wdev) {
478 err = -ENODEV;
479 goto out_unlock;
480 }
Johannes Berg67748892010-10-04 21:14:06 +0200481 }
482
Johannes Berg67748892010-10-04 21:14:06 +0200483 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200484 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200485 rtnl_unlock();
486 return err;
487}
488
Johannes Berg97990a02013-04-19 01:02:55 +0200489static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200490{
Johannes Berg67748892010-10-04 21:14:06 +0200491 rtnl_unlock();
492}
493
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100494/* IE validation */
495static bool is_valid_ie_attr(const struct nlattr *attr)
496{
497 const u8 *pos;
498 int len;
499
500 if (!attr)
501 return true;
502
503 pos = nla_data(attr);
504 len = nla_len(attr);
505
506 while (len) {
507 u8 elemlen;
508
509 if (len < 2)
510 return false;
511 len -= 2;
512
513 elemlen = pos[1];
514 if (elemlen > len)
515 return false;
516
517 len -= elemlen;
518 pos += 2 + elemlen;
519 }
520
521 return true;
522}
523
Johannes Berg55682962007-09-20 13:09:35 -0400524/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000525static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400526 int flags, u8 cmd)
527{
528 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000529 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400530}
531
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400532static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100533 struct ieee80211_channel *chan,
534 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400535{
David S. Miller9360ffd2012-03-29 04:41:26 -0400536 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
537 chan->center_freq))
538 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400539
David S. Miller9360ffd2012-03-29 04:41:26 -0400540 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
541 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
542 goto nla_put_failure;
543 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
544 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
545 goto nla_put_failure;
546 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
547 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
548 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100549 if (chan->flags & IEEE80211_CHAN_RADAR) {
550 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
551 goto nla_put_failure;
552 if (large) {
553 u32 time;
554
555 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
556
557 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
558 chan->dfs_state))
559 goto nla_put_failure;
560 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
561 time))
562 goto nla_put_failure;
563 }
564 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400565
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100566 if (large) {
567 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
568 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
569 goto nla_put_failure;
570 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
571 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
572 goto nla_put_failure;
573 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
574 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
575 goto nla_put_failure;
576 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
577 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
578 goto nla_put_failure;
579 }
580
David S. Miller9360ffd2012-03-29 04:41:26 -0400581 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
582 DBM_TO_MBM(chan->max_power)))
583 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584
585 return 0;
586
587 nla_put_failure:
588 return -ENOBUFS;
589}
590
Johannes Berg55682962007-09-20 13:09:35 -0400591/* netlink command implementations */
592
Johannes Bergb9454e82009-07-08 13:29:08 +0200593struct key_parse {
594 struct key_params p;
595 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200596 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200597 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100598 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200599};
600
601static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
602{
603 struct nlattr *tb[NL80211_KEY_MAX + 1];
604 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
605 nl80211_key_policy);
606 if (err)
607 return err;
608
609 k->def = !!tb[NL80211_KEY_DEFAULT];
610 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
611
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100612 if (k->def) {
613 k->def_uni = true;
614 k->def_multi = true;
615 }
616 if (k->defmgmt)
617 k->def_multi = true;
618
Johannes Bergb9454e82009-07-08 13:29:08 +0200619 if (tb[NL80211_KEY_IDX])
620 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
621
622 if (tb[NL80211_KEY_DATA]) {
623 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
624 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
625 }
626
627 if (tb[NL80211_KEY_SEQ]) {
628 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
629 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
630 }
631
632 if (tb[NL80211_KEY_CIPHER])
633 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
634
Johannes Berge31b8212010-10-05 19:39:30 +0200635 if (tb[NL80211_KEY_TYPE]) {
636 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
637 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
638 return -EINVAL;
639 }
640
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100641 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
642 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100643 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
644 tb[NL80211_KEY_DEFAULT_TYPES],
645 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100646 if (err)
647 return err;
648
649 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
650 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
651 }
652
Johannes Bergb9454e82009-07-08 13:29:08 +0200653 return 0;
654}
655
656static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
657{
658 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
659 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
660 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
661 }
662
663 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
664 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
665 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
666 }
667
668 if (info->attrs[NL80211_ATTR_KEY_IDX])
669 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
670
671 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
672 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
673
674 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
675 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
676
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 if (k->def) {
678 k->def_uni = true;
679 k->def_multi = true;
680 }
681 if (k->defmgmt)
682 k->def_multi = true;
683
Johannes Berge31b8212010-10-05 19:39:30 +0200684 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
685 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
686 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
687 return -EINVAL;
688 }
689
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100690 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
691 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
692 int err = nla_parse_nested(
693 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
694 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
695 nl80211_key_default_policy);
696 if (err)
697 return err;
698
699 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
700 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
701 }
702
Johannes Bergb9454e82009-07-08 13:29:08 +0200703 return 0;
704}
705
706static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
707{
708 int err;
709
710 memset(k, 0, sizeof(*k));
711 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200712 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200713
714 if (info->attrs[NL80211_ATTR_KEY])
715 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
716 else
717 err = nl80211_parse_key_old(info, k);
718
719 if (err)
720 return err;
721
722 if (k->def && k->defmgmt)
723 return -EINVAL;
724
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100725 if (k->defmgmt) {
726 if (k->def_uni || !k->def_multi)
727 return -EINVAL;
728 }
729
Johannes Bergb9454e82009-07-08 13:29:08 +0200730 if (k->idx != -1) {
731 if (k->defmgmt) {
732 if (k->idx < 4 || k->idx > 5)
733 return -EINVAL;
734 } else if (k->def) {
735 if (k->idx < 0 || k->idx > 3)
736 return -EINVAL;
737 } else {
738 if (k->idx < 0 || k->idx > 5)
739 return -EINVAL;
740 }
741 }
742
743 return 0;
744}
745
Johannes Bergfffd0932009-07-08 14:22:54 +0200746static struct cfg80211_cached_keys *
747nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530748 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200749{
750 struct key_parse parse;
751 struct nlattr *key;
752 struct cfg80211_cached_keys *result;
753 int rem, err, def = 0;
754
755 result = kzalloc(sizeof(*result), GFP_KERNEL);
756 if (!result)
757 return ERR_PTR(-ENOMEM);
758
759 result->def = -1;
760 result->defmgmt = -1;
761
762 nla_for_each_nested(key, keys, rem) {
763 memset(&parse, 0, sizeof(parse));
764 parse.idx = -1;
765
766 err = nl80211_parse_key_new(key, &parse);
767 if (err)
768 goto error;
769 err = -EINVAL;
770 if (!parse.p.key)
771 goto error;
772 if (parse.idx < 0 || parse.idx > 4)
773 goto error;
774 if (parse.def) {
775 if (def)
776 goto error;
777 def = 1;
778 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100779 if (!parse.def_uni || !parse.def_multi)
780 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200781 } else if (parse.defmgmt)
782 goto error;
783 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200784 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200785 if (err)
786 goto error;
787 result->params[parse.idx].cipher = parse.p.cipher;
788 result->params[parse.idx].key_len = parse.p.key_len;
789 result->params[parse.idx].key = result->data[parse.idx];
790 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530791
792 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
793 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
794 if (no_ht)
795 *no_ht = true;
796 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200797 }
798
799 return result;
800 error:
801 kfree(result);
802 return ERR_PTR(err);
803}
804
805static int nl80211_key_allowed(struct wireless_dev *wdev)
806{
807 ASSERT_WDEV_LOCK(wdev);
808
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 switch (wdev->iftype) {
810 case NL80211_IFTYPE_AP:
811 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200812 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700813 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 break;
815 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200816 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200817 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200818 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200819 return -ENOLINK;
820 break;
821 default:
822 return -EINVAL;
823 }
824
825 return 0;
826}
827
Johannes Berg7527a782011-05-13 10:58:57 +0200828static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
829{
830 struct nlattr *nl_modes = nla_nest_start(msg, attr);
831 int i;
832
833 if (!nl_modes)
834 goto nla_put_failure;
835
836 i = 0;
837 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400838 if ((ifmodes & 1) && nla_put_flag(msg, i))
839 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200840 ifmodes >>= 1;
841 i++;
842 }
843
844 nla_nest_end(msg, nl_modes);
845 return 0;
846
847nla_put_failure:
848 return -ENOBUFS;
849}
850
851static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100852 struct sk_buff *msg,
853 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200854{
855 struct nlattr *nl_combis;
856 int i, j;
857
858 nl_combis = nla_nest_start(msg,
859 NL80211_ATTR_INTERFACE_COMBINATIONS);
860 if (!nl_combis)
861 goto nla_put_failure;
862
863 for (i = 0; i < wiphy->n_iface_combinations; i++) {
864 const struct ieee80211_iface_combination *c;
865 struct nlattr *nl_combi, *nl_limits;
866
867 c = &wiphy->iface_combinations[i];
868
869 nl_combi = nla_nest_start(msg, i + 1);
870 if (!nl_combi)
871 goto nla_put_failure;
872
873 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
874 if (!nl_limits)
875 goto nla_put_failure;
876
877 for (j = 0; j < c->n_limits; j++) {
878 struct nlattr *nl_limit;
879
880 nl_limit = nla_nest_start(msg, j + 1);
881 if (!nl_limit)
882 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400883 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
884 c->limits[j].max))
885 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200886 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
887 c->limits[j].types))
888 goto nla_put_failure;
889 nla_nest_end(msg, nl_limit);
890 }
891
892 nla_nest_end(msg, nl_limits);
893
David S. Miller9360ffd2012-03-29 04:41:26 -0400894 if (c->beacon_int_infra_match &&
895 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
896 goto nla_put_failure;
897 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
898 c->num_different_channels) ||
899 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
900 c->max_interfaces))
901 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100902 if (large &&
903 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
904 c->radar_detect_widths))
905 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200906
907 nla_nest_end(msg, nl_combi);
908 }
909
910 nla_nest_end(msg, nl_combis);
911
912 return 0;
913nla_put_failure:
914 return -ENOBUFS;
915}
916
Johannes Berg3713b4e2013-02-14 16:19:38 +0100917#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100918static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
919 struct sk_buff *msg)
920{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200921 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100922 struct nlattr *nl_tcp;
923
924 if (!tcp)
925 return 0;
926
927 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
928 if (!nl_tcp)
929 return -ENOBUFS;
930
931 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
932 tcp->data_payload_max))
933 return -ENOBUFS;
934
935 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
936 tcp->data_payload_max))
937 return -ENOBUFS;
938
939 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
940 return -ENOBUFS;
941
942 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
943 sizeof(*tcp->tok), tcp->tok))
944 return -ENOBUFS;
945
946 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
947 tcp->data_interval_max))
948 return -ENOBUFS;
949
950 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
951 tcp->wake_payload_max))
952 return -ENOBUFS;
953
954 nla_nest_end(msg, nl_tcp);
955 return 0;
956}
957
Johannes Berg3713b4e2013-02-14 16:19:38 +0100958static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100959 struct cfg80211_registered_device *dev,
960 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100961{
962 struct nlattr *nl_wowlan;
963
Johannes Berg964dc9e2013-06-03 17:25:34 +0200964 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965 return 0;
966
967 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
968 if (!nl_wowlan)
969 return -ENOBUFS;
970
Johannes Berg964dc9e2013-06-03 17:25:34 +0200971 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100972 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200973 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100974 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200975 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200977 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200979 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100980 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200981 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200983 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100984 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200985 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100986 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
987 return -ENOBUFS;
988
Johannes Berg964dc9e2013-06-03 17:25:34 +0200989 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700990 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200991 .max_patterns = dev->wiphy.wowlan->n_patterns,
992 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
993 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
994 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100995 };
996
997 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
998 sizeof(pat), &pat))
999 return -ENOBUFS;
1000 }
1001
Johannes Bergb56cf722013-02-20 01:02:38 +01001002 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1003 return -ENOBUFS;
1004
Johannes Berg3713b4e2013-02-14 16:19:38 +01001005 nla_nest_end(msg, nl_wowlan);
1006
1007 return 0;
1008}
1009#endif
1010
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001011static int nl80211_send_coalesce(struct sk_buff *msg,
1012 struct cfg80211_registered_device *dev)
1013{
1014 struct nl80211_coalesce_rule_support rule;
1015
1016 if (!dev->wiphy.coalesce)
1017 return 0;
1018
1019 rule.max_rules = dev->wiphy.coalesce->n_rules;
1020 rule.max_delay = dev->wiphy.coalesce->max_delay;
1021 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1022 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1023 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1024 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1025
1026 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1027 return -ENOBUFS;
1028
1029 return 0;
1030}
1031
Johannes Berg3713b4e2013-02-14 16:19:38 +01001032static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1033 struct ieee80211_supported_band *sband)
1034{
1035 struct nlattr *nl_rates, *nl_rate;
1036 struct ieee80211_rate *rate;
1037 int i;
1038
1039 /* add HT info */
1040 if (sband->ht_cap.ht_supported &&
1041 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1042 sizeof(sband->ht_cap.mcs),
1043 &sband->ht_cap.mcs) ||
1044 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1045 sband->ht_cap.cap) ||
1046 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1047 sband->ht_cap.ampdu_factor) ||
1048 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1049 sband->ht_cap.ampdu_density)))
1050 return -ENOBUFS;
1051
1052 /* add VHT info */
1053 if (sband->vht_cap.vht_supported &&
1054 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1055 sizeof(sband->vht_cap.vht_mcs),
1056 &sband->vht_cap.vht_mcs) ||
1057 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1058 sband->vht_cap.cap)))
1059 return -ENOBUFS;
1060
1061 /* add bitrates */
1062 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1063 if (!nl_rates)
1064 return -ENOBUFS;
1065
1066 for (i = 0; i < sband->n_bitrates; i++) {
1067 nl_rate = nla_nest_start(msg, i);
1068 if (!nl_rate)
1069 return -ENOBUFS;
1070
1071 rate = &sband->bitrates[i];
1072 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1073 rate->bitrate))
1074 return -ENOBUFS;
1075 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1076 nla_put_flag(msg,
1077 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1078 return -ENOBUFS;
1079
1080 nla_nest_end(msg, nl_rate);
1081 }
1082
1083 nla_nest_end(msg, nl_rates);
1084
1085 return 0;
1086}
1087
1088static int
1089nl80211_send_mgmt_stypes(struct sk_buff *msg,
1090 const struct ieee80211_txrx_stypes *mgmt_stypes)
1091{
1092 u16 stypes;
1093 struct nlattr *nl_ftypes, *nl_ifs;
1094 enum nl80211_iftype ift;
1095 int i;
1096
1097 if (!mgmt_stypes)
1098 return 0;
1099
1100 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1101 if (!nl_ifs)
1102 return -ENOBUFS;
1103
1104 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1105 nl_ftypes = nla_nest_start(msg, ift);
1106 if (!nl_ftypes)
1107 return -ENOBUFS;
1108 i = 0;
1109 stypes = mgmt_stypes[ift].tx;
1110 while (stypes) {
1111 if ((stypes & 1) &&
1112 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1113 (i << 4) | IEEE80211_FTYPE_MGMT))
1114 return -ENOBUFS;
1115 stypes >>= 1;
1116 i++;
1117 }
1118 nla_nest_end(msg, nl_ftypes);
1119 }
1120
1121 nla_nest_end(msg, nl_ifs);
1122
1123 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1124 if (!nl_ifs)
1125 return -ENOBUFS;
1126
1127 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1128 nl_ftypes = nla_nest_start(msg, ift);
1129 if (!nl_ftypes)
1130 return -ENOBUFS;
1131 i = 0;
1132 stypes = mgmt_stypes[ift].rx;
1133 while (stypes) {
1134 if ((stypes & 1) &&
1135 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1136 (i << 4) | IEEE80211_FTYPE_MGMT))
1137 return -ENOBUFS;
1138 stypes >>= 1;
1139 i++;
1140 }
1141 nla_nest_end(msg, nl_ftypes);
1142 }
1143 nla_nest_end(msg, nl_ifs);
1144
1145 return 0;
1146}
1147
Johannes Berg86e8cf92013-06-19 10:57:22 +02001148struct nl80211_dump_wiphy_state {
1149 s64 filter_wiphy;
1150 long start;
1151 long split_start, band_start, chan_start;
1152 bool split;
1153};
1154
Johannes Berg3713b4e2013-02-14 16:19:38 +01001155static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1156 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001157 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001158{
1159 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001160 struct nlattr *nl_bands, *nl_band;
1161 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001162 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001163 enum ieee80211_band band;
1164 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001165 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001166 const struct ieee80211_txrx_stypes *mgmt_stypes =
1167 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001168 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001169
Eric W. Biederman15e47302012-09-07 20:12:54 +00001170 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001171 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001172 return -ENOBUFS;
1173
Johannes Berg86e8cf92013-06-19 10:57:22 +02001174 if (WARN_ON(!state))
1175 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001176
David S. Miller9360ffd2012-03-29 04:41:26 -04001177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001178 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1179 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001180 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001181 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001182 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001183
Johannes Berg86e8cf92013-06-19 10:57:22 +02001184 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001185 case 0:
1186 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1187 dev->wiphy.retry_short) ||
1188 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1189 dev->wiphy.retry_long) ||
1190 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1191 dev->wiphy.frag_threshold) ||
1192 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1193 dev->wiphy.rts_threshold) ||
1194 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1195 dev->wiphy.coverage_class) ||
1196 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1197 dev->wiphy.max_scan_ssids) ||
1198 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1199 dev->wiphy.max_sched_scan_ssids) ||
1200 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1201 dev->wiphy.max_scan_ie_len) ||
1202 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1203 dev->wiphy.max_sched_scan_ie_len) ||
1204 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1205 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001206 goto nla_put_failure;
1207
Johannes Berg3713b4e2013-02-14 16:19:38 +01001208 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1209 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1210 goto nla_put_failure;
1211 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1212 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1213 goto nla_put_failure;
1214 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1215 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1216 goto nla_put_failure;
1217 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1218 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1219 goto nla_put_failure;
1220 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1221 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1222 goto nla_put_failure;
1223 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1224 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001225 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001226 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1227 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1228 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001229
Johannes Berg86e8cf92013-06-19 10:57:22 +02001230 state->split_start++;
1231 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001232 break;
1233 case 1:
1234 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1235 sizeof(u32) * dev->wiphy.n_cipher_suites,
1236 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001237 goto nla_put_failure;
1238
Johannes Berg3713b4e2013-02-14 16:19:38 +01001239 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1240 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001241 goto nla_put_failure;
1242
Johannes Berg3713b4e2013-02-14 16:19:38 +01001243 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1244 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1245 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001246
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1248 dev->wiphy.available_antennas_tx) ||
1249 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1250 dev->wiphy.available_antennas_rx))
1251 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1254 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1255 dev->wiphy.probe_resp_offload))
1256 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001257
Johannes Berg3713b4e2013-02-14 16:19:38 +01001258 if ((dev->wiphy.available_antennas_tx ||
1259 dev->wiphy.available_antennas_rx) &&
1260 dev->ops->get_antenna) {
1261 u32 tx_ant = 0, rx_ant = 0;
1262 int res;
1263 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1264 if (!res) {
1265 if (nla_put_u32(msg,
1266 NL80211_ATTR_WIPHY_ANTENNA_TX,
1267 tx_ant) ||
1268 nla_put_u32(msg,
1269 NL80211_ATTR_WIPHY_ANTENNA_RX,
1270 rx_ant))
1271 goto nla_put_failure;
1272 }
Johannes Bergee688b002008-01-24 19:38:39 +01001273 }
1274
Johannes Berg86e8cf92013-06-19 10:57:22 +02001275 state->split_start++;
1276 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 break;
1278 case 2:
1279 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1280 dev->wiphy.interface_modes))
1281 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001282 state->split_start++;
1283 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 break;
1285 case 3:
1286 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1287 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001288 goto nla_put_failure;
1289
Johannes Berg86e8cf92013-06-19 10:57:22 +02001290 for (band = state->band_start;
1291 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 struct ieee80211_supported_band *sband;
1293
1294 sband = dev->wiphy.bands[band];
1295
1296 if (!sband)
1297 continue;
1298
1299 nl_band = nla_nest_start(msg, band);
1300 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001301 goto nla_put_failure;
1302
Johannes Berg86e8cf92013-06-19 10:57:22 +02001303 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 case 0:
1305 if (nl80211_send_band_rateinfo(msg, sband))
1306 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001307 state->chan_start++;
1308 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 break;
1310 default:
1311 /* add frequencies */
1312 nl_freqs = nla_nest_start(
1313 msg, NL80211_BAND_ATTR_FREQS);
1314 if (!nl_freqs)
1315 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001316
Johannes Berg86e8cf92013-06-19 10:57:22 +02001317 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 i < sband->n_channels;
1319 i++) {
1320 nl_freq = nla_nest_start(msg, i);
1321 if (!nl_freq)
1322 goto nla_put_failure;
1323
1324 chan = &sband->channels[i];
1325
Johannes Berg86e8cf92013-06-19 10:57:22 +02001326 if (nl80211_msg_put_channel(
1327 msg, chan,
1328 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 goto nla_put_failure;
1330
1331 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001332 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 break;
1334 }
1335 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001336 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001338 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 nla_nest_end(msg, nl_freqs);
1340 }
1341
1342 nla_nest_end(msg, nl_band);
1343
Johannes Berg86e8cf92013-06-19 10:57:22 +02001344 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001346 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 band--;
1348 break;
1349 }
Johannes Bergee688b002008-01-24 19:38:39 +01001350 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001352
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001357
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001359 if (state->band_start == 0 && state->chan_start == 0)
1360 state->split_start++;
1361 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 break;
1363 case 4:
1364 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1365 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001366 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367
1368 i = 0;
1369#define CMD(op, n) \
1370 do { \
1371 if (dev->ops->op) { \
1372 i++; \
1373 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1374 goto nla_put_failure; \
1375 } \
1376 } while (0)
1377
1378 CMD(add_virtual_intf, NEW_INTERFACE);
1379 CMD(change_virtual_intf, SET_INTERFACE);
1380 CMD(add_key, NEW_KEY);
1381 CMD(start_ap, START_AP);
1382 CMD(add_station, NEW_STATION);
1383 CMD(add_mpath, NEW_MPATH);
1384 CMD(update_mesh_config, SET_MESH_CONFIG);
1385 CMD(change_bss, SET_BSS);
1386 CMD(auth, AUTHENTICATE);
1387 CMD(assoc, ASSOCIATE);
1388 CMD(deauth, DEAUTHENTICATE);
1389 CMD(disassoc, DISASSOCIATE);
1390 CMD(join_ibss, JOIN_IBSS);
1391 CMD(join_mesh, JOIN_MESH);
1392 CMD(set_pmksa, SET_PMKSA);
1393 CMD(del_pmksa, DEL_PMKSA);
1394 CMD(flush_pmksa, FLUSH_PMKSA);
1395 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1396 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1397 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1398 CMD(mgmt_tx, FRAME);
1399 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1400 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1401 i++;
1402 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1403 goto nla_put_failure;
1404 }
1405 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1406 dev->ops->join_mesh) {
1407 i++;
1408 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1409 goto nla_put_failure;
1410 }
1411 CMD(set_wds_peer, SET_WDS_PEER);
1412 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1413 CMD(tdls_mgmt, TDLS_MGMT);
1414 CMD(tdls_oper, TDLS_OPER);
1415 }
1416 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1417 CMD(sched_scan_start, START_SCHED_SCAN);
1418 CMD(probe_client, PROBE_CLIENT);
1419 CMD(set_noack_map, SET_NOACK_MAP);
1420 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1421 i++;
1422 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1423 goto nla_put_failure;
1424 }
1425 CMD(start_p2p_device, START_P2P_DEVICE);
1426 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001428 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1429 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001430 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1431 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001432 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001433
Kalle Valo4745fc02011-11-17 19:06:10 +02001434#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001436#endif
1437
Johannes Berg8fdc6212009-03-14 09:34:01 +01001438#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001439
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 if (dev->ops->connect || dev->ops->auth) {
1441 i++;
1442 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001443 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001444 }
1445
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 if (dev->ops->disconnect || dev->ops->deauth) {
1447 i++;
1448 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1449 goto nla_put_failure;
1450 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001451
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001453 state->split_start++;
1454 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 break;
1456 case 5:
1457 if (dev->ops->remain_on_channel &&
1458 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1459 nla_put_u32(msg,
1460 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1461 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001462 goto nla_put_failure;
1463
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1465 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1466 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001467
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1469 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001470 state->split_start++;
1471 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 break;
1473 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001474#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001475 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001477 state->split_start++;
1478 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 break;
1480#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482#endif
1483 case 7:
1484 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1485 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001486 goto nla_put_failure;
1487
Johannes Berg86e8cf92013-06-19 10:57:22 +02001488 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1489 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001490 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001491
Johannes Berg86e8cf92013-06-19 10:57:22 +02001492 state->split_start++;
1493 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 break;
1495 case 8:
1496 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1497 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1498 dev->wiphy.ap_sme_capa))
1499 goto nla_put_failure;
1500
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001501 features = dev->wiphy.features;
1502 /*
1503 * We can only add the per-channel limit information if the
1504 * dump is split, otherwise it makes it too big. Therefore
1505 * only advertise it in that case.
1506 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001507 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001508 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1509 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 goto nla_put_failure;
1511
1512 if (dev->wiphy.ht_capa_mod_mask &&
1513 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1514 sizeof(*dev->wiphy.ht_capa_mod_mask),
1515 dev->wiphy.ht_capa_mod_mask))
1516 goto nla_put_failure;
1517
1518 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1519 dev->wiphy.max_acl_mac_addrs &&
1520 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1521 dev->wiphy.max_acl_mac_addrs))
1522 goto nla_put_failure;
1523
1524 /*
1525 * Any information below this point is only available to
1526 * applications that can deal with it being split. This
1527 * helps ensure that newly added capabilities don't break
1528 * older tools by overrunning their buffers.
1529 *
1530 * We still increment split_start so that in the split
1531 * case we'll continue with more data in the next round,
1532 * but break unconditionally so unsplit data stops here.
1533 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001534 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 break;
1536 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001537 if (dev->wiphy.extended_capabilities &&
1538 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1539 dev->wiphy.extended_capabilities_len,
1540 dev->wiphy.extended_capabilities) ||
1541 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1542 dev->wiphy.extended_capabilities_len,
1543 dev->wiphy.extended_capabilities_mask)))
1544 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545
Johannes Bergee2aca32013-02-21 17:36:01 +01001546 if (dev->wiphy.vht_capa_mod_mask &&
1547 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1548 sizeof(*dev->wiphy.vht_capa_mod_mask),
1549 dev->wiphy.vht_capa_mod_mask))
1550 goto nla_put_failure;
1551
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001552 state->split_start++;
1553 break;
1554 case 10:
1555 if (nl80211_send_coalesce(msg, dev))
1556 goto nla_put_failure;
1557
Johannes Berg3713b4e2013-02-14 16:19:38 +01001558 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001561 }
Johannes Berg55682962007-09-20 13:09:35 -04001562 return genlmsg_end(msg, hdr);
1563
1564 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001565 genlmsg_cancel(msg, hdr);
1566 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001567}
1568
Johannes Berg86e8cf92013-06-19 10:57:22 +02001569static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1570 struct netlink_callback *cb,
1571 struct nl80211_dump_wiphy_state *state)
1572{
1573 struct nlattr **tb = nl80211_fam.attrbuf;
1574 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1575 tb, nl80211_fam.maxattr, nl80211_policy);
1576 /* ignore parse errors for backward compatibility */
1577 if (ret)
1578 return 0;
1579
1580 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1581 if (tb[NL80211_ATTR_WIPHY])
1582 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1583 if (tb[NL80211_ATTR_WDEV])
1584 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1585 if (tb[NL80211_ATTR_IFINDEX]) {
1586 struct net_device *netdev;
1587 struct cfg80211_registered_device *rdev;
1588 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1589
1590 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1591 if (!netdev)
1592 return -ENODEV;
1593 if (netdev->ieee80211_ptr) {
1594 rdev = wiphy_to_dev(
1595 netdev->ieee80211_ptr->wiphy);
1596 state->filter_wiphy = rdev->wiphy_idx;
1597 }
1598 dev_put(netdev);
1599 }
1600
1601 return 0;
1602}
1603
Johannes Berg55682962007-09-20 13:09:35 -04001604static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1605{
Johannes Berg645e77d2013-03-01 14:03:49 +01001606 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001607 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001608 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001609
Johannes Berg5fe231e2013-05-08 21:45:15 +02001610 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001611 if (!state) {
1612 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001613 if (!state) {
1614 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001615 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 state->filter_wiphy = -1;
1618 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1619 if (ret) {
1620 kfree(state);
1621 rtnl_unlock();
1622 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001624 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001625 }
1626
Johannes Berg79c97e92009-07-07 03:56:12 +02001627 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001628 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1629 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001630 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001631 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (state->filter_wiphy != -1 &&
1633 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 continue;
1635 /* attempt to fit multiple wiphy data chunks into the skb */
1636 do {
1637 ret = nl80211_send_wiphy(dev, skb,
1638 NETLINK_CB(cb->skb).portid,
1639 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001640 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 if (ret < 0) {
1642 /*
1643 * If sending the wiphy data didn't fit (ENOBUFS
1644 * or EMSGSIZE returned), this SKB is still
1645 * empty (so it's not too big because another
1646 * wiphy dataset is already in the skb) and
1647 * we've not tried to adjust the dump allocation
1648 * yet ... then adjust the alloc size to be
1649 * bigger, and return 1 but with the empty skb.
1650 * This results in an empty message being RX'ed
1651 * in userspace, but that is ignored.
1652 *
1653 * We can then retry with the larger buffer.
1654 */
1655 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1656 !skb->len &&
1657 cb->min_dump_alloc < 4096) {
1658 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001659 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001660 return 1;
1661 }
1662 idx--;
1663 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001664 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001665 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001666 break;
Johannes Berg55682962007-09-20 13:09:35 -04001667 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001668 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001669
Johannes Berg86e8cf92013-06-19 10:57:22 +02001670 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001671
1672 return skb->len;
1673}
1674
Johannes Berg86e8cf92013-06-19 10:57:22 +02001675static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1676{
1677 kfree((void *)cb->args[0]);
1678 return 0;
1679}
1680
Johannes Berg55682962007-09-20 13:09:35 -04001681static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1682{
1683 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001684 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001686
Johannes Berg645e77d2013-03-01 14:03:49 +01001687 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001688 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001689 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001690
Johannes Berg3713b4e2013-02-14 16:19:38 +01001691 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001692 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001693 nlmsg_free(msg);
1694 return -ENOBUFS;
1695 }
Johannes Berg55682962007-09-20 13:09:35 -04001696
Johannes Berg134e6372009-07-10 09:51:34 +00001697 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001698}
1699
Jouni Malinen31888482008-10-30 16:59:24 +02001700static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1701 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1702 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1703 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1704 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1705 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1706};
1707
1708static int parse_txq_params(struct nlattr *tb[],
1709 struct ieee80211_txq_params *txq_params)
1710{
Johannes Berga3304b02012-03-28 11:04:24 +02001711 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001712 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1713 !tb[NL80211_TXQ_ATTR_AIFS])
1714 return -EINVAL;
1715
Johannes Berga3304b02012-03-28 11:04:24 +02001716 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001717 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1718 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1719 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1720 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1721
Johannes Berga3304b02012-03-28 11:04:24 +02001722 if (txq_params->ac >= NL80211_NUM_ACS)
1723 return -EINVAL;
1724
Jouni Malinen31888482008-10-30 16:59:24 +02001725 return 0;
1726}
1727
Johannes Bergf444de02010-05-05 15:25:02 +02001728static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1729{
1730 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001731 * You can only set the channel explicitly for WDS interfaces,
1732 * all others have their channel managed via their respective
1733 * "establish a connection" command (connect, join, ...)
1734 *
1735 * For AP/GO and mesh mode, the channel can be set with the
1736 * channel userspace API, but is only stored and passed to the
1737 * low-level driver when the AP starts or the mesh is joined.
1738 * This is for backward compatibility, userspace can also give
1739 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001740 *
1741 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001742 * whatever else is going on, so they have their own special
1743 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001744 */
1745 return !wdev ||
1746 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001747 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001748 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1749 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001750}
1751
Johannes Berg683b6d32012-11-08 21:25:48 +01001752static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1753 struct genl_info *info,
1754 struct cfg80211_chan_def *chandef)
1755{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301756 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001757
1758 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1759 return -EINVAL;
1760
1761 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1762
1763 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001764 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1765 chandef->center_freq1 = control_freq;
1766 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001767
1768 /* Primary channel not allowed */
1769 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1770 return -EINVAL;
1771
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001772 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1773 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001774
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001775 chantype = nla_get_u32(
1776 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1777
1778 switch (chantype) {
1779 case NL80211_CHAN_NO_HT:
1780 case NL80211_CHAN_HT20:
1781 case NL80211_CHAN_HT40PLUS:
1782 case NL80211_CHAN_HT40MINUS:
1783 cfg80211_chandef_create(chandef, chandef->chan,
1784 chantype);
1785 break;
1786 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001787 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001788 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001789 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1790 chandef->width =
1791 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1792 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1793 chandef->center_freq1 =
1794 nla_get_u32(
1795 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1796 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1797 chandef->center_freq2 =
1798 nla_get_u32(
1799 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1800 }
1801
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001802 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001803 return -EINVAL;
1804
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001805 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1806 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001807 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001808
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001809 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1810 chandef->width == NL80211_CHAN_WIDTH_10) &&
1811 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1812 return -EINVAL;
1813
Johannes Berg683b6d32012-11-08 21:25:48 +01001814 return 0;
1815}
1816
Johannes Bergf444de02010-05-05 15:25:02 +02001817static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1818 struct wireless_dev *wdev,
1819 struct genl_info *info)
1820{
Johannes Berg683b6d32012-11-08 21:25:48 +01001821 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001822 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001823 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1824
1825 if (wdev)
1826 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001827
Johannes Bergf444de02010-05-05 15:25:02 +02001828 if (!nl80211_can_set_dev_channel(wdev))
1829 return -EOPNOTSUPP;
1830
Johannes Berg683b6d32012-11-08 21:25:48 +01001831 result = nl80211_parse_chandef(rdev, info, &chandef);
1832 if (result)
1833 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001834
Johannes Berge8c9bd52012-06-06 08:18:22 +02001835 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001836 case NL80211_IFTYPE_AP:
1837 case NL80211_IFTYPE_P2P_GO:
1838 if (wdev->beacon_interval) {
1839 result = -EBUSY;
1840 break;
1841 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001842 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001843 result = -EINVAL;
1844 break;
1845 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001846 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001847 result = 0;
1848 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001849 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001850 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001851 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001852 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001853 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001854 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001855 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001856 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001857 }
Johannes Bergf444de02010-05-05 15:25:02 +02001858
1859 return result;
1860}
1861
1862static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1863{
Johannes Berg4c476992010-10-04 21:36:35 +02001864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1865 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001866
Johannes Berg4c476992010-10-04 21:36:35 +02001867 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001868}
1869
Bill Jordane8347eb2010-10-01 13:54:28 -04001870static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1871{
Johannes Berg43b19952010-10-07 13:10:30 +02001872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1873 struct net_device *dev = info->user_ptr[1];
1874 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001875 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001876
1877 if (!info->attrs[NL80211_ATTR_MAC])
1878 return -EINVAL;
1879
Johannes Berg43b19952010-10-07 13:10:30 +02001880 if (netif_running(dev))
1881 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001882
Johannes Berg43b19952010-10-07 13:10:30 +02001883 if (!rdev->ops->set_wds_peer)
1884 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001885
Johannes Berg43b19952010-10-07 13:10:30 +02001886 if (wdev->iftype != NL80211_IFTYPE_WDS)
1887 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001888
1889 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001890 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001891}
1892
1893
Johannes Berg55682962007-09-20 13:09:35 -04001894static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1895{
1896 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001897 struct net_device *netdev = NULL;
1898 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001899 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001900 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001901 u32 changed;
1902 u8 retry_short = 0, retry_long = 0;
1903 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001904 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001905
Johannes Berg5fe231e2013-05-08 21:45:15 +02001906 ASSERT_RTNL();
1907
Johannes Bergf444de02010-05-05 15:25:02 +02001908 /*
1909 * Try to find the wiphy and netdev. Normally this
1910 * function shouldn't need the netdev, but this is
1911 * done for backward compatibility -- previously
1912 * setting the channel was done per wiphy, but now
1913 * it is per netdev. Previous userland like hostapd
1914 * also passed a netdev to set_wiphy, so that it is
1915 * possible to let that go to the right netdev!
1916 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001917
Johannes Bergf444de02010-05-05 15:25:02 +02001918 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1919 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1920
1921 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001922 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001923 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001924 else
Johannes Bergf444de02010-05-05 15:25:02 +02001925 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001926 }
1927
Johannes Bergf444de02010-05-05 15:25:02 +02001928 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001929 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1930 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001931 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001932 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001933 wdev = NULL;
1934 netdev = NULL;
1935 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001936 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001937 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001938
1939 /*
1940 * end workaround code, by now the rdev is available
1941 * and locked, and wdev may or may not be NULL.
1942 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001943
1944 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001945 result = cfg80211_dev_rename(
1946 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001947
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001948 if (result)
1949 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001950
Jouni Malinen31888482008-10-30 16:59:24 +02001951 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1952 struct ieee80211_txq_params txq_params;
1953 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1954
1955 if (!rdev->ops->set_txq_params) {
1956 result = -EOPNOTSUPP;
1957 goto bad_res;
1958 }
1959
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001960 if (!netdev) {
1961 result = -EINVAL;
1962 goto bad_res;
1963 }
1964
Johannes Berg133a3ff2011-11-03 14:50:13 +01001965 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1966 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1967 result = -EINVAL;
1968 goto bad_res;
1969 }
1970
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001971 if (!netif_running(netdev)) {
1972 result = -ENETDOWN;
1973 goto bad_res;
1974 }
1975
Jouni Malinen31888482008-10-30 16:59:24 +02001976 nla_for_each_nested(nl_txq_params,
1977 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1978 rem_txq_params) {
1979 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1980 nla_data(nl_txq_params),
1981 nla_len(nl_txq_params),
1982 txq_params_policy);
1983 result = parse_txq_params(tb, &txq_params);
1984 if (result)
1985 goto bad_res;
1986
Hila Gonene35e4d22012-06-27 17:19:42 +03001987 result = rdev_set_txq_params(rdev, netdev,
1988 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001989 if (result)
1990 goto bad_res;
1991 }
1992 }
1993
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001994 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001995 result = __nl80211_set_channel(rdev,
1996 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1997 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001998 if (result)
1999 goto bad_res;
2000 }
2001
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002002 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002003 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002004 enum nl80211_tx_power_setting type;
2005 int idx, mbm = 0;
2006
Johannes Bergc8442112012-10-24 10:17:18 +02002007 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2008 txp_wdev = NULL;
2009
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002010 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002011 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002012 goto bad_res;
2013 }
2014
2015 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2016 type = nla_get_u32(info->attrs[idx]);
2017
2018 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2019 (type != NL80211_TX_POWER_AUTOMATIC)) {
2020 result = -EINVAL;
2021 goto bad_res;
2022 }
2023
2024 if (type != NL80211_TX_POWER_AUTOMATIC) {
2025 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2026 mbm = nla_get_u32(info->attrs[idx]);
2027 }
2028
Johannes Bergc8442112012-10-24 10:17:18 +02002029 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002030 if (result)
2031 goto bad_res;
2032 }
2033
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002034 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2035 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2036 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002037 if ((!rdev->wiphy.available_antennas_tx &&
2038 !rdev->wiphy.available_antennas_rx) ||
2039 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002040 result = -EOPNOTSUPP;
2041 goto bad_res;
2042 }
2043
2044 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2045 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2046
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002047 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002048 * available antenna masks, except for the "all" mask */
2049 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2050 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002051 result = -EINVAL;
2052 goto bad_res;
2053 }
2054
Bruno Randolf7f531e02010-12-16 11:30:22 +09002055 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2056 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002057
Hila Gonene35e4d22012-06-27 17:19:42 +03002058 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002059 if (result)
2060 goto bad_res;
2061 }
2062
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002063 changed = 0;
2064
2065 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2066 retry_short = nla_get_u8(
2067 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2068 if (retry_short == 0) {
2069 result = -EINVAL;
2070 goto bad_res;
2071 }
2072 changed |= WIPHY_PARAM_RETRY_SHORT;
2073 }
2074
2075 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2076 retry_long = nla_get_u8(
2077 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2078 if (retry_long == 0) {
2079 result = -EINVAL;
2080 goto bad_res;
2081 }
2082 changed |= WIPHY_PARAM_RETRY_LONG;
2083 }
2084
2085 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2086 frag_threshold = nla_get_u32(
2087 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2088 if (frag_threshold < 256) {
2089 result = -EINVAL;
2090 goto bad_res;
2091 }
2092 if (frag_threshold != (u32) -1) {
2093 /*
2094 * Fragments (apart from the last one) are required to
2095 * have even length. Make the fragmentation code
2096 * simpler by stripping LSB should someone try to use
2097 * odd threshold value.
2098 */
2099 frag_threshold &= ~0x1;
2100 }
2101 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2102 }
2103
2104 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2105 rts_threshold = nla_get_u32(
2106 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2107 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2108 }
2109
Lukáš Turek81077e82009-12-21 22:50:47 +01002110 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2111 coverage_class = nla_get_u8(
2112 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2113 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2114 }
2115
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002116 if (changed) {
2117 u8 old_retry_short, old_retry_long;
2118 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002119 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002120
2121 if (!rdev->ops->set_wiphy_params) {
2122 result = -EOPNOTSUPP;
2123 goto bad_res;
2124 }
2125
2126 old_retry_short = rdev->wiphy.retry_short;
2127 old_retry_long = rdev->wiphy.retry_long;
2128 old_frag_threshold = rdev->wiphy.frag_threshold;
2129 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002130 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002131
2132 if (changed & WIPHY_PARAM_RETRY_SHORT)
2133 rdev->wiphy.retry_short = retry_short;
2134 if (changed & WIPHY_PARAM_RETRY_LONG)
2135 rdev->wiphy.retry_long = retry_long;
2136 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2137 rdev->wiphy.frag_threshold = frag_threshold;
2138 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2139 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002140 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2141 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002142
Hila Gonene35e4d22012-06-27 17:19:42 +03002143 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002144 if (result) {
2145 rdev->wiphy.retry_short = old_retry_short;
2146 rdev->wiphy.retry_long = old_retry_long;
2147 rdev->wiphy.frag_threshold = old_frag_threshold;
2148 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002149 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002150 }
2151 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002152
Johannes Berg306d6112008-12-08 12:39:04 +01002153 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002154 if (netdev)
2155 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002156 return result;
2157}
2158
Johannes Berg71bbc992012-06-15 15:30:18 +02002159static inline u64 wdev_id(struct wireless_dev *wdev)
2160{
2161 return (u64)wdev->identifier |
2162 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2163}
Johannes Berg55682962007-09-20 13:09:35 -04002164
Johannes Berg683b6d32012-11-08 21:25:48 +01002165static int nl80211_send_chandef(struct sk_buff *msg,
2166 struct cfg80211_chan_def *chandef)
2167{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002168 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002169
Johannes Berg683b6d32012-11-08 21:25:48 +01002170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2171 chandef->chan->center_freq))
2172 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002173 switch (chandef->width) {
2174 case NL80211_CHAN_WIDTH_20_NOHT:
2175 case NL80211_CHAN_WIDTH_20:
2176 case NL80211_CHAN_WIDTH_40:
2177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2178 cfg80211_get_chandef_type(chandef)))
2179 return -ENOBUFS;
2180 break;
2181 default:
2182 break;
2183 }
2184 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2185 return -ENOBUFS;
2186 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2187 return -ENOBUFS;
2188 if (chandef->center_freq2 &&
2189 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002190 return -ENOBUFS;
2191 return 0;
2192}
2193
Eric W. Biederman15e47302012-09-07 20:12:54 +00002194static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002195 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002196 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002197{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002198 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002199 void *hdr;
2200
Eric W. Biederman15e47302012-09-07 20:12:54 +00002201 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002202 if (!hdr)
2203 return -1;
2204
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002205 if (dev &&
2206 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002207 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002208 goto nla_put_failure;
2209
2210 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2211 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002212 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002213 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002214 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2215 rdev->devlist_generation ^
2216 (cfg80211_rdev_list_generation << 2)))
2217 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002218
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002219 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002220 int ret;
2221 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002222
Johannes Berg683b6d32012-11-08 21:25:48 +01002223 ret = rdev_get_channel(rdev, wdev, &chandef);
2224 if (ret == 0) {
2225 if (nl80211_send_chandef(msg, &chandef))
2226 goto nla_put_failure;
2227 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002228 }
2229
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002230 if (wdev->ssid_len) {
2231 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2232 goto nla_put_failure;
2233 }
2234
Johannes Berg55682962007-09-20 13:09:35 -04002235 return genlmsg_end(msg, hdr);
2236
2237 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002238 genlmsg_cancel(msg, hdr);
2239 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002240}
2241
2242static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2243{
2244 int wp_idx = 0;
2245 int if_idx = 0;
2246 int wp_start = cb->args[0];
2247 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002248 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002249 struct wireless_dev *wdev;
2250
Johannes Berg5fe231e2013-05-08 21:45:15 +02002251 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002252 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2253 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002254 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002255 if (wp_idx < wp_start) {
2256 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002257 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002258 }
Johannes Berg55682962007-09-20 13:09:35 -04002259 if_idx = 0;
2260
Johannes Berg89a54e42012-06-15 14:33:17 +02002261 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 if (if_idx < if_start) {
2263 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002264 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002265 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002266 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002267 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002268 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 goto out;
2270 }
2271 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002272 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002273
2274 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002275 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002276 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002277 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002278
2279 cb->args[0] = wp_idx;
2280 cb->args[1] = if_idx;
2281
2282 return skb->len;
2283}
2284
2285static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2286{
2287 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002288 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002289 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002290
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002291 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002292 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002293 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002294
Eric W. Biederman15e47302012-09-07 20:12:54 +00002295 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002296 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002297 nlmsg_free(msg);
2298 return -ENOBUFS;
2299 }
Johannes Berg55682962007-09-20 13:09:35 -04002300
Johannes Berg134e6372009-07-10 09:51:34 +00002301 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002302}
2303
Michael Wu66f7ac52008-01-31 19:48:22 +01002304static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2305 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2306 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2307 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2308 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2309 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002310 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002311};
2312
2313static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2314{
2315 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2316 int flag;
2317
2318 *mntrflags = 0;
2319
2320 if (!nla)
2321 return -EINVAL;
2322
2323 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2324 nla, mntr_flags_policy))
2325 return -EINVAL;
2326
2327 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2328 if (flags[flag])
2329 *mntrflags |= (1<<flag);
2330
2331 return 0;
2332}
2333
Johannes Berg9bc383d2009-11-19 11:55:19 +01002334static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002335 struct net_device *netdev, u8 use_4addr,
2336 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002337{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002338 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002339 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002340 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002341 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002342 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002343
2344 switch (iftype) {
2345 case NL80211_IFTYPE_AP_VLAN:
2346 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2347 return 0;
2348 break;
2349 case NL80211_IFTYPE_STATION:
2350 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2351 return 0;
2352 break;
2353 default:
2354 break;
2355 }
2356
2357 return -EOPNOTSUPP;
2358}
2359
Johannes Berg55682962007-09-20 13:09:35 -04002360static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2361{
Johannes Berg4c476992010-10-04 21:36:35 +02002362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002363 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002364 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002365 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002366 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002367 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002368 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002369
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002370 memset(&params, 0, sizeof(params));
2371
Johannes Berg04a773a2009-04-19 21:24:32 +02002372 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002373
Johannes Berg723b0382008-09-16 20:22:09 +02002374 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002375 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002376 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002377 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (ntype > NL80211_IFTYPE_MAX)
2379 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002380 }
2381
Johannes Berg92ffe052008-09-16 20:39:36 +02002382 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002383 struct wireless_dev *wdev = dev->ieee80211_ptr;
2384
Johannes Berg4c476992010-10-04 21:36:35 +02002385 if (ntype != NL80211_IFTYPE_MESH_POINT)
2386 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002387 if (netif_running(dev))
2388 return -EBUSY;
2389
2390 wdev_lock(wdev);
2391 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2392 IEEE80211_MAX_MESH_ID_LEN);
2393 wdev->mesh_id_up_len =
2394 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2395 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2396 wdev->mesh_id_up_len);
2397 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002398 }
2399
Felix Fietkau8b787642009-11-10 18:53:10 +01002400 if (info->attrs[NL80211_ATTR_4ADDR]) {
2401 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2402 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002403 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002404 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002405 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002406 } else {
2407 params.use_4addr = -1;
2408 }
2409
Johannes Berg92ffe052008-09-16 20:39:36 +02002410 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002411 if (ntype != NL80211_IFTYPE_MONITOR)
2412 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002413 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2414 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002415 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002416 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002417
2418 flags = &_flags;
2419 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002420 }
Johannes Berg3b858752009-03-12 09:55:09 +01002421
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002422 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2423 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2424 return -EOPNOTSUPP;
2425
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002426 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002427 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002428 else
2429 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002430
Johannes Berg9bc383d2009-11-19 11:55:19 +01002431 if (!err && params.use_4addr != -1)
2432 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2433
Johannes Berg55682962007-09-20 13:09:35 -04002434 return err;
2435}
2436
2437static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2438{
Johannes Berg4c476992010-10-04 21:36:35 +02002439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002440 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002441 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002442 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002443 int err;
2444 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002445 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002446
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002447 memset(&params, 0, sizeof(params));
2448
Johannes Berg55682962007-09-20 13:09:35 -04002449 if (!info->attrs[NL80211_ATTR_IFNAME])
2450 return -EINVAL;
2451
2452 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2453 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2454 if (type > NL80211_IFTYPE_MAX)
2455 return -EINVAL;
2456 }
2457
Johannes Berg79c97e92009-07-07 03:56:12 +02002458 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002459 !(rdev->wiphy.interface_modes & (1 << type)))
2460 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002461
Arend van Spriel1c18f142013-01-08 10:17:27 +01002462 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2463 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2464 ETH_ALEN);
2465 if (!is_valid_ether_addr(params.macaddr))
2466 return -EADDRNOTAVAIL;
2467 }
2468
Johannes Berg9bc383d2009-11-19 11:55:19 +01002469 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002470 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002471 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002472 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002473 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002474 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002475
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002476 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2477 if (!msg)
2478 return -ENOMEM;
2479
Michael Wu66f7ac52008-01-31 19:48:22 +01002480 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2481 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2482 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002483
2484 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2485 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2486 return -EOPNOTSUPP;
2487
Hila Gonene35e4d22012-06-27 17:19:42 +03002488 wdev = rdev_add_virtual_intf(rdev,
2489 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2490 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002491 if (IS_ERR(wdev)) {
2492 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002493 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002494 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002495
Johannes Berg98104fde2012-06-16 00:19:54 +02002496 switch (type) {
2497 case NL80211_IFTYPE_MESH_POINT:
2498 if (!info->attrs[NL80211_ATTR_MESH_ID])
2499 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002500 wdev_lock(wdev);
2501 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2502 IEEE80211_MAX_MESH_ID_LEN);
2503 wdev->mesh_id_up_len =
2504 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2505 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2506 wdev->mesh_id_up_len);
2507 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002508 break;
2509 case NL80211_IFTYPE_P2P_DEVICE:
2510 /*
2511 * P2P Device doesn't have a netdev, so doesn't go
2512 * through the netdev notifier and must be added here
2513 */
2514 mutex_init(&wdev->mtx);
2515 INIT_LIST_HEAD(&wdev->event_list);
2516 spin_lock_init(&wdev->event_lock);
2517 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2518 spin_lock_init(&wdev->mgmt_registrations_lock);
2519
Johannes Berg98104fde2012-06-16 00:19:54 +02002520 wdev->identifier = ++rdev->wdev_id;
2521 list_add_rcu(&wdev->list, &rdev->wdev_list);
2522 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002523 break;
2524 default:
2525 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002526 }
2527
Eric W. Biederman15e47302012-09-07 20:12:54 +00002528 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002529 rdev, wdev) < 0) {
2530 nlmsg_free(msg);
2531 return -ENOBUFS;
2532 }
2533
2534 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002535}
2536
2537static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2538{
Johannes Berg4c476992010-10-04 21:36:35 +02002539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002540 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002541
Johannes Berg4c476992010-10-04 21:36:35 +02002542 if (!rdev->ops->del_virtual_intf)
2543 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002544
Johannes Berg84efbb82012-06-16 00:00:26 +02002545 /*
2546 * If we remove a wireless device without a netdev then clear
2547 * user_ptr[1] so that nl80211_post_doit won't dereference it
2548 * to check if it needs to do dev_put(). Otherwise it crashes
2549 * since the wdev has been freed, unlike with a netdev where
2550 * we need the dev_put() for the netdev to really be freed.
2551 */
2552 if (!wdev->netdev)
2553 info->user_ptr[1] = NULL;
2554
Hila Gonene35e4d22012-06-27 17:19:42 +03002555 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002556}
2557
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002558static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2559{
2560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2561 struct net_device *dev = info->user_ptr[1];
2562 u16 noack_map;
2563
2564 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2565 return -EINVAL;
2566
2567 if (!rdev->ops->set_noack_map)
2568 return -EOPNOTSUPP;
2569
2570 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2571
Hila Gonene35e4d22012-06-27 17:19:42 +03002572 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002573}
2574
Johannes Berg41ade002007-12-19 02:03:29 +01002575struct get_key_cookie {
2576 struct sk_buff *msg;
2577 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002578 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002579};
2580
2581static void get_key_callback(void *c, struct key_params *params)
2582{
Johannes Bergb9454e82009-07-08 13:29:08 +02002583 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002584 struct get_key_cookie *cookie = c;
2585
David S. Miller9360ffd2012-03-29 04:41:26 -04002586 if ((params->key &&
2587 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2588 params->key_len, params->key)) ||
2589 (params->seq &&
2590 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2591 params->seq_len, params->seq)) ||
2592 (params->cipher &&
2593 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2594 params->cipher)))
2595 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002596
Johannes Bergb9454e82009-07-08 13:29:08 +02002597 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2598 if (!key)
2599 goto nla_put_failure;
2600
David S. Miller9360ffd2012-03-29 04:41:26 -04002601 if ((params->key &&
2602 nla_put(cookie->msg, NL80211_KEY_DATA,
2603 params->key_len, params->key)) ||
2604 (params->seq &&
2605 nla_put(cookie->msg, NL80211_KEY_SEQ,
2606 params->seq_len, params->seq)) ||
2607 (params->cipher &&
2608 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2609 params->cipher)))
2610 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002611
David S. Miller9360ffd2012-03-29 04:41:26 -04002612 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2613 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002614
2615 nla_nest_end(cookie->msg, key);
2616
Johannes Berg41ade002007-12-19 02:03:29 +01002617 return;
2618 nla_put_failure:
2619 cookie->error = 1;
2620}
2621
2622static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2623{
Johannes Berg4c476992010-10-04 21:36:35 +02002624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002625 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002626 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002627 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002628 const u8 *mac_addr = NULL;
2629 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002630 struct get_key_cookie cookie = {
2631 .error = 0,
2632 };
2633 void *hdr;
2634 struct sk_buff *msg;
2635
2636 if (info->attrs[NL80211_ATTR_KEY_IDX])
2637 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2638
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002639 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002640 return -EINVAL;
2641
2642 if (info->attrs[NL80211_ATTR_MAC])
2643 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2644
Johannes Berge31b8212010-10-05 19:39:30 +02002645 pairwise = !!mac_addr;
2646 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2647 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2648 if (kt >= NUM_NL80211_KEYTYPES)
2649 return -EINVAL;
2650 if (kt != NL80211_KEYTYPE_GROUP &&
2651 kt != NL80211_KEYTYPE_PAIRWISE)
2652 return -EINVAL;
2653 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2654 }
2655
Johannes Berg4c476992010-10-04 21:36:35 +02002656 if (!rdev->ops->get_key)
2657 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002658
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002659 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002660 if (!msg)
2661 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002662
Eric W. Biederman15e47302012-09-07 20:12:54 +00002663 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002664 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002665 if (IS_ERR(hdr))
2666 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002667
2668 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002669 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002670
David S. Miller9360ffd2012-03-29 04:41:26 -04002671 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2672 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2673 goto nla_put_failure;
2674 if (mac_addr &&
2675 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2676 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002677
Johannes Berge31b8212010-10-05 19:39:30 +02002678 if (pairwise && mac_addr &&
2679 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2680 return -ENOENT;
2681
Hila Gonene35e4d22012-06-27 17:19:42 +03002682 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2683 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002684
2685 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002686 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002687
2688 if (cookie.error)
2689 goto nla_put_failure;
2690
2691 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002692 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002693
2694 nla_put_failure:
2695 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002696 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002697 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002698 return err;
2699}
2700
2701static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2702{
Johannes Berg4c476992010-10-04 21:36:35 +02002703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002704 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002705 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002706 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002707
Johannes Bergb9454e82009-07-08 13:29:08 +02002708 err = nl80211_parse_key(info, &key);
2709 if (err)
2710 return err;
2711
2712 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002713 return -EINVAL;
2714
Johannes Bergb9454e82009-07-08 13:29:08 +02002715 /* only support setting default key */
2716 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002717 return -EINVAL;
2718
Johannes Bergfffd0932009-07-08 14:22:54 +02002719 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002720
2721 if (key.def) {
2722 if (!rdev->ops->set_default_key) {
2723 err = -EOPNOTSUPP;
2724 goto out;
2725 }
2726
2727 err = nl80211_key_allowed(dev->ieee80211_ptr);
2728 if (err)
2729 goto out;
2730
Hila Gonene35e4d22012-06-27 17:19:42 +03002731 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002732 key.def_uni, key.def_multi);
2733
2734 if (err)
2735 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002736
Johannes Berg3d23e342009-09-29 23:27:28 +02002737#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002738 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002739#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002740 } else {
2741 if (key.def_uni || !key.def_multi) {
2742 err = -EINVAL;
2743 goto out;
2744 }
2745
2746 if (!rdev->ops->set_default_mgmt_key) {
2747 err = -EOPNOTSUPP;
2748 goto out;
2749 }
2750
2751 err = nl80211_key_allowed(dev->ieee80211_ptr);
2752 if (err)
2753 goto out;
2754
Hila Gonene35e4d22012-06-27 17:19:42 +03002755 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002756 if (err)
2757 goto out;
2758
2759#ifdef CONFIG_CFG80211_WEXT
2760 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2761#endif
2762 }
2763
2764 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002765 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002766
Johannes Berg41ade002007-12-19 02:03:29 +01002767 return err;
2768}
2769
2770static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2771{
Johannes Berg4c476992010-10-04 21:36:35 +02002772 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002773 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002774 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002776 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002777
Johannes Bergb9454e82009-07-08 13:29:08 +02002778 err = nl80211_parse_key(info, &key);
2779 if (err)
2780 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002781
Johannes Bergb9454e82009-07-08 13:29:08 +02002782 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002783 return -EINVAL;
2784
Johannes Berg41ade002007-12-19 02:03:29 +01002785 if (info->attrs[NL80211_ATTR_MAC])
2786 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2787
Johannes Berge31b8212010-10-05 19:39:30 +02002788 if (key.type == -1) {
2789 if (mac_addr)
2790 key.type = NL80211_KEYTYPE_PAIRWISE;
2791 else
2792 key.type = NL80211_KEYTYPE_GROUP;
2793 }
2794
2795 /* for now */
2796 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2797 key.type != NL80211_KEYTYPE_GROUP)
2798 return -EINVAL;
2799
Johannes Berg4c476992010-10-04 21:36:35 +02002800 if (!rdev->ops->add_key)
2801 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002802
Johannes Berge31b8212010-10-05 19:39:30 +02002803 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2804 key.type == NL80211_KEYTYPE_PAIRWISE,
2805 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002806 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002807
2808 wdev_lock(dev->ieee80211_ptr);
2809 err = nl80211_key_allowed(dev->ieee80211_ptr);
2810 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002811 err = rdev_add_key(rdev, dev, key.idx,
2812 key.type == NL80211_KEYTYPE_PAIRWISE,
2813 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002814 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002815
Johannes Berg41ade002007-12-19 02:03:29 +01002816 return err;
2817}
2818
2819static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2820{
Johannes Berg4c476992010-10-04 21:36:35 +02002821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002822 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002823 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002824 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002825 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002826
Johannes Bergb9454e82009-07-08 13:29:08 +02002827 err = nl80211_parse_key(info, &key);
2828 if (err)
2829 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002830
2831 if (info->attrs[NL80211_ATTR_MAC])
2832 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2833
Johannes Berge31b8212010-10-05 19:39:30 +02002834 if (key.type == -1) {
2835 if (mac_addr)
2836 key.type = NL80211_KEYTYPE_PAIRWISE;
2837 else
2838 key.type = NL80211_KEYTYPE_GROUP;
2839 }
2840
2841 /* for now */
2842 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2843 key.type != NL80211_KEYTYPE_GROUP)
2844 return -EINVAL;
2845
Johannes Berg4c476992010-10-04 21:36:35 +02002846 if (!rdev->ops->del_key)
2847 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002848
Johannes Bergfffd0932009-07-08 14:22:54 +02002849 wdev_lock(dev->ieee80211_ptr);
2850 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002851
2852 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2853 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2854 err = -ENOENT;
2855
Johannes Bergfffd0932009-07-08 14:22:54 +02002856 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002857 err = rdev_del_key(rdev, dev, key.idx,
2858 key.type == NL80211_KEYTYPE_PAIRWISE,
2859 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002860
Johannes Berg3d23e342009-09-29 23:27:28 +02002861#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002862 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002863 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002864 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002865 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002866 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2867 }
2868#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002869 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002870
Johannes Berg41ade002007-12-19 02:03:29 +01002871 return err;
2872}
2873
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302874/* This function returns an error or the number of nested attributes */
2875static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2876{
2877 struct nlattr *attr;
2878 int n_entries = 0, tmp;
2879
2880 nla_for_each_nested(attr, nl_attr, tmp) {
2881 if (nla_len(attr) != ETH_ALEN)
2882 return -EINVAL;
2883
2884 n_entries++;
2885 }
2886
2887 return n_entries;
2888}
2889
2890/*
2891 * This function parses ACL information and allocates memory for ACL data.
2892 * On successful return, the calling function is responsible to free the
2893 * ACL buffer returned by this function.
2894 */
2895static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2896 struct genl_info *info)
2897{
2898 enum nl80211_acl_policy acl_policy;
2899 struct nlattr *attr;
2900 struct cfg80211_acl_data *acl;
2901 int i = 0, n_entries, tmp;
2902
2903 if (!wiphy->max_acl_mac_addrs)
2904 return ERR_PTR(-EOPNOTSUPP);
2905
2906 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2907 return ERR_PTR(-EINVAL);
2908
2909 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2910 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2911 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2912 return ERR_PTR(-EINVAL);
2913
2914 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2915 return ERR_PTR(-EINVAL);
2916
2917 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2918 if (n_entries < 0)
2919 return ERR_PTR(n_entries);
2920
2921 if (n_entries > wiphy->max_acl_mac_addrs)
2922 return ERR_PTR(-ENOTSUPP);
2923
2924 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2925 GFP_KERNEL);
2926 if (!acl)
2927 return ERR_PTR(-ENOMEM);
2928
2929 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2930 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2931 i++;
2932 }
2933
2934 acl->n_acl_entries = n_entries;
2935 acl->acl_policy = acl_policy;
2936
2937 return acl;
2938}
2939
2940static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2941{
2942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2943 struct net_device *dev = info->user_ptr[1];
2944 struct cfg80211_acl_data *acl;
2945 int err;
2946
2947 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2948 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2949 return -EOPNOTSUPP;
2950
2951 if (!dev->ieee80211_ptr->beacon_interval)
2952 return -EINVAL;
2953
2954 acl = parse_acl_data(&rdev->wiphy, info);
2955 if (IS_ERR(acl))
2956 return PTR_ERR(acl);
2957
2958 err = rdev_set_mac_acl(rdev, dev, acl);
2959
2960 kfree(acl);
2961
2962 return err;
2963}
2964
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002965static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002966 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002967{
Johannes Berg88600202012-02-13 15:17:18 +01002968 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002969
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002970 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2971 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2972 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2973 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002974 return -EINVAL;
2975
Johannes Berg88600202012-02-13 15:17:18 +01002976 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002977
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002978 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2979 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2980 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002981 if (!bcn->head_len)
2982 return -EINVAL;
2983 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002984 }
2985
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002986 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2987 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2988 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002989 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002990 }
2991
Johannes Berg4c476992010-10-04 21:36:35 +02002992 if (!haveinfo)
2993 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002994
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002995 if (attrs[NL80211_ATTR_IE]) {
2996 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2997 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002998 }
2999
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003000 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003001 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003003 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003004 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003005 }
3006
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003007 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003008 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003009 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003010 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003011 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003012 }
3013
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003014 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3015 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3016 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003017 }
3018
Johannes Berg88600202012-02-13 15:17:18 +01003019 return 0;
3020}
3021
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003022static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3023 struct cfg80211_ap_settings *params)
3024{
3025 struct wireless_dev *wdev;
3026 bool ret = false;
3027
Johannes Berg89a54e42012-06-15 14:33:17 +02003028 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003029 if (wdev->iftype != NL80211_IFTYPE_AP &&
3030 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3031 continue;
3032
Johannes Berg683b6d32012-11-08 21:25:48 +01003033 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003034 continue;
3035
Johannes Berg683b6d32012-11-08 21:25:48 +01003036 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003037 ret = true;
3038 break;
3039 }
3040
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003041 return ret;
3042}
3043
Jouni Malinene39e5b52012-09-30 19:29:39 +03003044static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3045 enum nl80211_auth_type auth_type,
3046 enum nl80211_commands cmd)
3047{
3048 if (auth_type > NL80211_AUTHTYPE_MAX)
3049 return false;
3050
3051 switch (cmd) {
3052 case NL80211_CMD_AUTHENTICATE:
3053 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3054 auth_type == NL80211_AUTHTYPE_SAE)
3055 return false;
3056 return true;
3057 case NL80211_CMD_CONNECT:
3058 case NL80211_CMD_START_AP:
3059 /* SAE not supported yet */
3060 if (auth_type == NL80211_AUTHTYPE_SAE)
3061 return false;
3062 return true;
3063 default:
3064 return false;
3065 }
3066}
3067
Johannes Berg88600202012-02-13 15:17:18 +01003068static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3069{
3070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3071 struct net_device *dev = info->user_ptr[1];
3072 struct wireless_dev *wdev = dev->ieee80211_ptr;
3073 struct cfg80211_ap_settings params;
3074 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003075 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003076
3077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3078 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3079 return -EOPNOTSUPP;
3080
3081 if (!rdev->ops->start_ap)
3082 return -EOPNOTSUPP;
3083
3084 if (wdev->beacon_interval)
3085 return -EALREADY;
3086
3087 memset(&params, 0, sizeof(params));
3088
3089 /* these are required for START_AP */
3090 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3091 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3092 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3093 return -EINVAL;
3094
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003095 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003096 if (err)
3097 return err;
3098
3099 params.beacon_interval =
3100 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3101 params.dtim_period =
3102 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3103
3104 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3105 if (err)
3106 return err;
3107
3108 /*
3109 * In theory, some of these attributes should be required here
3110 * but since they were not used when the command was originally
3111 * added, keep them optional for old user space programs to let
3112 * them continue to work with drivers that do not need the
3113 * additional information -- drivers must check!
3114 */
3115 if (info->attrs[NL80211_ATTR_SSID]) {
3116 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3117 params.ssid_len =
3118 nla_len(info->attrs[NL80211_ATTR_SSID]);
3119 if (params.ssid_len == 0 ||
3120 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3121 return -EINVAL;
3122 }
3123
3124 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3125 params.hidden_ssid = nla_get_u32(
3126 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3127 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3128 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3129 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3130 return -EINVAL;
3131 }
3132
3133 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3134
3135 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3136 params.auth_type = nla_get_u32(
3137 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003138 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3139 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003140 return -EINVAL;
3141 } else
3142 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3143
3144 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3145 NL80211_MAX_NR_CIPHER_SUITES);
3146 if (err)
3147 return err;
3148
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303149 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3150 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3151 return -EOPNOTSUPP;
3152 params.inactivity_timeout = nla_get_u16(
3153 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3154 }
3155
Johannes Berg53cabad2012-11-14 15:17:28 +01003156 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3158 return -EINVAL;
3159 params.p2p_ctwindow =
3160 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3161 if (params.p2p_ctwindow > 127)
3162 return -EINVAL;
3163 if (params.p2p_ctwindow != 0 &&
3164 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3165 return -EINVAL;
3166 }
3167
3168 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3169 u8 tmp;
3170
3171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3172 return -EINVAL;
3173 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3174 if (tmp > 1)
3175 return -EINVAL;
3176 params.p2p_opp_ps = tmp;
3177 if (params.p2p_opp_ps != 0 &&
3178 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3179 return -EINVAL;
3180 }
3181
Johannes Bergaa430da2012-05-16 23:50:18 +02003182 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003183 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3184 if (err)
3185 return err;
3186 } else if (wdev->preset_chandef.chan) {
3187 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003188 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003189 return -EINVAL;
3190
Johannes Berg683b6d32012-11-08 21:25:48 +01003191 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003192 return -EINVAL;
3193
Simon Wunderlich04f39042013-02-08 18:16:19 +01003194 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3195 if (err < 0)
3196 return err;
3197 if (err) {
3198 radar_detect_width = BIT(params.chandef.width);
3199 params.radar_required = true;
3200 }
3201
Simon Wunderlich04f39042013-02-08 18:16:19 +01003202 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3203 params.chandef.chan,
3204 CHAN_MODE_SHARED,
3205 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003206 if (err)
3207 return err;
3208
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303209 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3210 params.acl = parse_acl_data(&rdev->wiphy, info);
3211 if (IS_ERR(params.acl))
3212 return PTR_ERR(params.acl);
3213 }
3214
Hila Gonene35e4d22012-06-27 17:19:42 +03003215 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003216 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003217 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003218 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003219 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003220 wdev->ssid_len = params.ssid_len;
3221 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003222 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303223
3224 kfree(params.acl);
3225
Johannes Berg56d18932011-05-09 18:41:15 +02003226 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003227}
3228
Johannes Berg88600202012-02-13 15:17:18 +01003229static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3230{
3231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3232 struct net_device *dev = info->user_ptr[1];
3233 struct wireless_dev *wdev = dev->ieee80211_ptr;
3234 struct cfg80211_beacon_data params;
3235 int err;
3236
3237 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3238 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3239 return -EOPNOTSUPP;
3240
3241 if (!rdev->ops->change_beacon)
3242 return -EOPNOTSUPP;
3243
3244 if (!wdev->beacon_interval)
3245 return -EINVAL;
3246
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003247 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003248 if (err)
3249 return err;
3250
Hila Gonene35e4d22012-06-27 17:19:42 +03003251 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003252}
3253
3254static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003255{
Johannes Berg4c476992010-10-04 21:36:35 +02003256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3257 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003258
Michal Kazior60771782012-06-29 12:46:56 +02003259 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003260}
3261
Johannes Berg5727ef12007-12-19 02:03:34 +01003262static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3263 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3264 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3265 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003266 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003267 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003268 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003269};
3270
Johannes Bergeccb8e82009-05-11 21:57:56 +03003271static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003272 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003273 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003274{
3275 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003276 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003277 int flag;
3278
Johannes Bergeccb8e82009-05-11 21:57:56 +03003279 /*
3280 * Try parsing the new attribute first so userspace
3281 * can specify both for older kernels.
3282 */
3283 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3284 if (nla) {
3285 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003286
Johannes Bergeccb8e82009-05-11 21:57:56 +03003287 sta_flags = nla_data(nla);
3288 params->sta_flags_mask = sta_flags->mask;
3289 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003290 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003291 if ((params->sta_flags_mask |
3292 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3293 return -EINVAL;
3294 return 0;
3295 }
3296
3297 /* if present, parse the old attribute */
3298
3299 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003300 if (!nla)
3301 return 0;
3302
3303 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3304 nla, sta_flags_policy))
3305 return -EINVAL;
3306
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003307 /*
3308 * Only allow certain flags for interface types so that
3309 * other attributes are silently ignored. Remember that
3310 * this is backward compatibility code with old userspace
3311 * and shouldn't be hit in other cases anyway.
3312 */
3313 switch (iftype) {
3314 case NL80211_IFTYPE_AP:
3315 case NL80211_IFTYPE_AP_VLAN:
3316 case NL80211_IFTYPE_P2P_GO:
3317 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3318 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3319 BIT(NL80211_STA_FLAG_WME) |
3320 BIT(NL80211_STA_FLAG_MFP);
3321 break;
3322 case NL80211_IFTYPE_P2P_CLIENT:
3323 case NL80211_IFTYPE_STATION:
3324 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3325 BIT(NL80211_STA_FLAG_TDLS_PEER);
3326 break;
3327 case NL80211_IFTYPE_MESH_POINT:
3328 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3329 BIT(NL80211_STA_FLAG_MFP) |
3330 BIT(NL80211_STA_FLAG_AUTHORIZED);
3331 default:
3332 return -EINVAL;
3333 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003334
Johannes Berg3383b5a2012-05-10 20:14:43 +02003335 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3336 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003337 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003338
Johannes Berg3383b5a2012-05-10 20:14:43 +02003339 /* no longer support new API additions in old API */
3340 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3341 return -EINVAL;
3342 }
3343 }
3344
Johannes Berg5727ef12007-12-19 02:03:34 +01003345 return 0;
3346}
3347
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003348static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3349 int attr)
3350{
3351 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003352 u32 bitrate;
3353 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003354
3355 rate = nla_nest_start(msg, attr);
3356 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003357 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003358
3359 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3360 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003361 /* report 16-bit bitrate only if we can */
3362 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003363 if (bitrate > 0 &&
3364 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3365 return false;
3366 if (bitrate_compat > 0 &&
3367 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3368 return false;
3369
3370 if (info->flags & RATE_INFO_FLAGS_MCS) {
3371 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3372 return false;
3373 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3374 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3375 return false;
3376 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3377 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3378 return false;
3379 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3380 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3381 return false;
3382 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3383 return false;
3384 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3385 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3386 return false;
3387 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3388 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3389 return false;
3390 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3391 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3392 return false;
3393 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3394 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3395 return false;
3396 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3397 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3398 return false;
3399 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003400
3401 nla_nest_end(msg, rate);
3402 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003403}
3404
Felix Fietkau119363c2013-04-22 16:29:30 +02003405static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3406 int id)
3407{
3408 void *attr;
3409 int i = 0;
3410
3411 if (!mask)
3412 return true;
3413
3414 attr = nla_nest_start(msg, id);
3415 if (!attr)
3416 return false;
3417
3418 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3419 if (!(mask & BIT(i)))
3420 continue;
3421
3422 if (nla_put_u8(msg, i, signal[i]))
3423 return false;
3424 }
3425
3426 nla_nest_end(msg, attr);
3427
3428 return true;
3429}
3430
Eric W. Biederman15e47302012-09-07 20:12:54 +00003431static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003432 int flags,
3433 struct cfg80211_registered_device *rdev,
3434 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003435 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003436{
3437 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003438 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003439
Eric W. Biederman15e47302012-09-07 20:12:54 +00003440 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003441 if (!hdr)
3442 return -1;
3443
David S. Miller9360ffd2012-03-29 04:41:26 -04003444 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3445 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3446 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3447 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003448
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003449 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3450 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003451 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003452 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3453 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3454 sinfo->connected_time))
3455 goto nla_put_failure;
3456 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3458 sinfo->inactive_time))
3459 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003460 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3461 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003462 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003463 (u32)sinfo->rx_bytes))
3464 goto nla_put_failure;
3465 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003466 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003467 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3468 (u32)sinfo->tx_bytes))
3469 goto nla_put_failure;
3470 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3471 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003472 sinfo->rx_bytes))
3473 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003474 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3475 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003476 sinfo->tx_bytes))
3477 goto nla_put_failure;
3478 if ((sinfo->filled & STATION_INFO_LLID) &&
3479 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3480 goto nla_put_failure;
3481 if ((sinfo->filled & STATION_INFO_PLID) &&
3482 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3483 goto nla_put_failure;
3484 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3485 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3486 sinfo->plink_state))
3487 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003488 switch (rdev->wiphy.signal_type) {
3489 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003490 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3491 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3492 sinfo->signal))
3493 goto nla_put_failure;
3494 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3495 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3496 sinfo->signal_avg))
3497 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003498 break;
3499 default:
3500 break;
3501 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003502 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3503 if (!nl80211_put_signal(msg, sinfo->chains,
3504 sinfo->chain_signal,
3505 NL80211_STA_INFO_CHAIN_SIGNAL))
3506 goto nla_put_failure;
3507 }
3508 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3509 if (!nl80211_put_signal(msg, sinfo->chains,
3510 sinfo->chain_signal_avg,
3511 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3512 goto nla_put_failure;
3513 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003514 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003515 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3516 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003517 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003518 }
3519 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3520 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3521 NL80211_STA_INFO_RX_BITRATE))
3522 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003523 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003524 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3525 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3526 sinfo->rx_packets))
3527 goto nla_put_failure;
3528 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3529 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3530 sinfo->tx_packets))
3531 goto nla_put_failure;
3532 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3533 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3534 sinfo->tx_retries))
3535 goto nla_put_failure;
3536 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3537 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3538 sinfo->tx_failed))
3539 goto nla_put_failure;
3540 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3541 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3542 sinfo->beacon_loss_count))
3543 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003544 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3545 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3546 sinfo->local_pm))
3547 goto nla_put_failure;
3548 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3549 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3550 sinfo->peer_pm))
3551 goto nla_put_failure;
3552 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3553 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3554 sinfo->nonpeer_pm))
3555 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003556 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3557 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3558 if (!bss_param)
3559 goto nla_put_failure;
3560
David S. Miller9360ffd2012-03-29 04:41:26 -04003561 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3562 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3563 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3564 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3565 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3566 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3567 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3568 sinfo->bss_param.dtim_period) ||
3569 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3570 sinfo->bss_param.beacon_interval))
3571 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003572
3573 nla_nest_end(msg, bss_param);
3574 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003575 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3576 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3577 sizeof(struct nl80211_sta_flag_update),
3578 &sinfo->sta_flags))
3579 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003580 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3581 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3582 sinfo->t_offset))
3583 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003584 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003585
David S. Miller9360ffd2012-03-29 04:41:26 -04003586 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3587 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3588 sinfo->assoc_req_ies))
3589 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003590
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003591 return genlmsg_end(msg, hdr);
3592
3593 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003594 genlmsg_cancel(msg, hdr);
3595 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003596}
3597
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003598static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003599 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003600{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003601 struct station_info sinfo;
3602 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003603 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003604 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003605 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003606 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003607
Johannes Berg97990a02013-04-19 01:02:55 +02003608 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003609 if (err)
3610 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003611
Johannes Berg97990a02013-04-19 01:02:55 +02003612 if (!wdev->netdev) {
3613 err = -EINVAL;
3614 goto out_err;
3615 }
3616
Johannes Bergbba95fe2008-07-29 13:22:51 +02003617 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003618 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003619 goto out_err;
3620 }
3621
Johannes Bergbba95fe2008-07-29 13:22:51 +02003622 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003623 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003624 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003625 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003626 if (err == -ENOENT)
3627 break;
3628 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003629 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003630
3631 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003632 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003633 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003634 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003635 &sinfo) < 0)
3636 goto out;
3637
3638 sta_idx++;
3639 }
3640
3641
3642 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003643 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003644 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003645 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003646 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003647
3648 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003649}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003650
Johannes Berg5727ef12007-12-19 02:03:34 +01003651static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3652{
Johannes Berg4c476992010-10-04 21:36:35 +02003653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3654 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003655 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003656 struct sk_buff *msg;
3657 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003658 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003659
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003660 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003661
3662 if (!info->attrs[NL80211_ATTR_MAC])
3663 return -EINVAL;
3664
3665 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3666
Johannes Berg4c476992010-10-04 21:36:35 +02003667 if (!rdev->ops->get_station)
3668 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003669
Hila Gonene35e4d22012-06-27 17:19:42 +03003670 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003671 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003672 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003673
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003675 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003676 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003677
Eric W. Biederman15e47302012-09-07 20:12:54 +00003678 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003679 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003680 nlmsg_free(msg);
3681 return -ENOBUFS;
3682 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003683
Johannes Berg4c476992010-10-04 21:36:35 +02003684 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003685}
3686
Johannes Berg77ee7c82013-02-15 00:48:33 +01003687int cfg80211_check_station_change(struct wiphy *wiphy,
3688 struct station_parameters *params,
3689 enum cfg80211_station_type statype)
3690{
3691 if (params->listen_interval != -1)
3692 return -EINVAL;
3693 if (params->aid)
3694 return -EINVAL;
3695
3696 /* When you run into this, adjust the code below for the new flag */
3697 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3698
3699 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003700 case CFG80211_STA_MESH_PEER_KERNEL:
3701 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003702 /*
3703 * No ignoring the TDLS flag here -- the userspace mesh
3704 * code doesn't have the bug of including TDLS in the
3705 * mask everywhere.
3706 */
3707 if (params->sta_flags_mask &
3708 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3709 BIT(NL80211_STA_FLAG_MFP) |
3710 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3711 return -EINVAL;
3712 break;
3713 case CFG80211_STA_TDLS_PEER_SETUP:
3714 case CFG80211_STA_TDLS_PEER_ACTIVE:
3715 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3716 return -EINVAL;
3717 /* ignore since it can't change */
3718 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3719 break;
3720 default:
3721 /* disallow mesh-specific things */
3722 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3723 return -EINVAL;
3724 if (params->local_pm)
3725 return -EINVAL;
3726 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3727 return -EINVAL;
3728 }
3729
3730 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3731 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3732 /* TDLS can't be set, ... */
3733 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3734 return -EINVAL;
3735 /*
3736 * ... but don't bother the driver with it. This works around
3737 * a hostapd/wpa_supplicant issue -- it always includes the
3738 * TLDS_PEER flag in the mask even for AP mode.
3739 */
3740 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3741 }
3742
3743 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3744 /* reject other things that can't change */
3745 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3746 return -EINVAL;
3747 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3748 return -EINVAL;
3749 if (params->supported_rates)
3750 return -EINVAL;
3751 if (params->ext_capab || params->ht_capa || params->vht_capa)
3752 return -EINVAL;
3753 }
3754
3755 if (statype != CFG80211_STA_AP_CLIENT) {
3756 if (params->vlan)
3757 return -EINVAL;
3758 }
3759
3760 switch (statype) {
3761 case CFG80211_STA_AP_MLME_CLIENT:
3762 /* Use this only for authorizing/unauthorizing a station */
3763 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3764 return -EOPNOTSUPP;
3765 break;
3766 case CFG80211_STA_AP_CLIENT:
3767 /* accept only the listed bits */
3768 if (params->sta_flags_mask &
3769 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3770 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3771 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3772 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3773 BIT(NL80211_STA_FLAG_WME) |
3774 BIT(NL80211_STA_FLAG_MFP)))
3775 return -EINVAL;
3776
3777 /* but authenticated/associated only if driver handles it */
3778 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3779 params->sta_flags_mask &
3780 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3781 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3782 return -EINVAL;
3783 break;
3784 case CFG80211_STA_IBSS:
3785 case CFG80211_STA_AP_STA:
3786 /* reject any changes other than AUTHORIZED */
3787 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3788 return -EINVAL;
3789 break;
3790 case CFG80211_STA_TDLS_PEER_SETUP:
3791 /* reject any changes other than AUTHORIZED or WME */
3792 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3793 BIT(NL80211_STA_FLAG_WME)))
3794 return -EINVAL;
3795 /* force (at least) rates when authorizing */
3796 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3797 !params->supported_rates)
3798 return -EINVAL;
3799 break;
3800 case CFG80211_STA_TDLS_PEER_ACTIVE:
3801 /* reject any changes */
3802 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003803 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003804 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3805 return -EINVAL;
3806 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003807 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003808 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3809 return -EINVAL;
3810 break;
3811 }
3812
3813 return 0;
3814}
3815EXPORT_SYMBOL(cfg80211_check_station_change);
3816
Johannes Berg5727ef12007-12-19 02:03:34 +01003817/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003818 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003819 */
Johannes Berg80b99892011-11-18 16:23:01 +01003820static struct net_device *get_vlan(struct genl_info *info,
3821 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003822{
Johannes Berg463d0182009-07-14 00:33:35 +02003823 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003824 struct net_device *v;
3825 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003826
Johannes Berg80b99892011-11-18 16:23:01 +01003827 if (!vlanattr)
3828 return NULL;
3829
3830 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3831 if (!v)
3832 return ERR_PTR(-ENODEV);
3833
3834 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3835 ret = -EINVAL;
3836 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003837 }
Johannes Berg80b99892011-11-18 16:23:01 +01003838
Johannes Berg77ee7c82013-02-15 00:48:33 +01003839 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3840 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3841 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3842 ret = -EINVAL;
3843 goto error;
3844 }
3845
Johannes Berg80b99892011-11-18 16:23:01 +01003846 if (!netif_running(v)) {
3847 ret = -ENETDOWN;
3848 goto error;
3849 }
3850
3851 return v;
3852 error:
3853 dev_put(v);
3854 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003855}
3856
Jouni Malinendf881292013-02-14 21:10:54 +02003857static struct nla_policy
3858nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3859 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3860 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3861};
3862
Johannes Bergff276692013-02-15 00:09:01 +01003863static int nl80211_parse_sta_wme(struct genl_info *info,
3864 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003865{
Jouni Malinendf881292013-02-14 21:10:54 +02003866 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3867 struct nlattr *nla;
3868 int err;
3869
Jouni Malinendf881292013-02-14 21:10:54 +02003870 /* parse WME attributes if present */
3871 if (!info->attrs[NL80211_ATTR_STA_WME])
3872 return 0;
3873
3874 nla = info->attrs[NL80211_ATTR_STA_WME];
3875 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3876 nl80211_sta_wme_policy);
3877 if (err)
3878 return err;
3879
3880 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3881 params->uapsd_queues = nla_get_u8(
3882 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3883 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3884 return -EINVAL;
3885
3886 if (tb[NL80211_STA_WME_MAX_SP])
3887 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3888
3889 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3890 return -EINVAL;
3891
3892 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3893
3894 return 0;
3895}
3896
Johannes Bergff276692013-02-15 00:09:01 +01003897static int nl80211_set_station_tdls(struct genl_info *info,
3898 struct station_parameters *params)
3899{
3900 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003901 if (info->attrs[NL80211_ATTR_PEER_AID])
3902 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003903 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3904 params->ht_capa =
3905 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3906 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3907 params->vht_capa =
3908 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3909
3910 return nl80211_parse_sta_wme(info, params);
3911}
3912
Johannes Berg5727ef12007-12-19 02:03:34 +01003913static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3914{
Johannes Berg4c476992010-10-04 21:36:35 +02003915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003916 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003917 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003918 u8 *mac_addr;
3919 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003920
3921 memset(&params, 0, sizeof(params));
3922
3923 params.listen_interval = -1;
3924
Johannes Berg77ee7c82013-02-15 00:48:33 +01003925 if (!rdev->ops->change_station)
3926 return -EOPNOTSUPP;
3927
Johannes Berg5727ef12007-12-19 02:03:34 +01003928 if (info->attrs[NL80211_ATTR_STA_AID])
3929 return -EINVAL;
3930
3931 if (!info->attrs[NL80211_ATTR_MAC])
3932 return -EINVAL;
3933
3934 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3935
3936 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3937 params.supported_rates =
3938 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3939 params.supported_rates_len =
3940 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3941 }
3942
Jouni Malinen9d62a982013-02-14 21:10:13 +02003943 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3944 params.capability =
3945 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3946 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3947 }
3948
3949 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3950 params.ext_capab =
3951 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3952 params.ext_capab_len =
3953 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3954 }
3955
Jouni Malinendf881292013-02-14 21:10:54 +02003956 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003957 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003958
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003959 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003960 return -EINVAL;
3961
Johannes Bergf8bacc22013-02-14 23:27:01 +01003962 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003963 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003964 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3965 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3966 return -EINVAL;
3967 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003968
Johannes Bergf8bacc22013-02-14 23:27:01 +01003969 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003970 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003971 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3972 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3973 return -EINVAL;
3974 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3975 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003976
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003977 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3978 enum nl80211_mesh_power_mode pm = nla_get_u32(
3979 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3980
3981 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3982 pm > NL80211_MESH_POWER_MAX)
3983 return -EINVAL;
3984
3985 params.local_pm = pm;
3986 }
3987
Johannes Berg77ee7c82013-02-15 00:48:33 +01003988 /* Include parameters for TDLS peer (will check later) */
3989 err = nl80211_set_station_tdls(info, &params);
3990 if (err)
3991 return err;
3992
3993 params.vlan = get_vlan(info, rdev);
3994 if (IS_ERR(params.vlan))
3995 return PTR_ERR(params.vlan);
3996
Johannes Berga97f4422009-06-18 17:23:43 +02003997 switch (dev->ieee80211_ptr->iftype) {
3998 case NL80211_IFTYPE_AP:
3999 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004000 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004001 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004002 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004003 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004004 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004005 break;
4006 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 err = -EOPNOTSUPP;
4008 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004009 }
4010
Johannes Berg77ee7c82013-02-15 00:48:33 +01004011 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004012 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004013
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004015 if (params.vlan)
4016 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004017
Johannes Berg5727ef12007-12-19 02:03:34 +01004018 return err;
4019}
4020
4021static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4022{
Johannes Berg4c476992010-10-04 21:36:35 +02004023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004024 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004025 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004026 struct station_parameters params;
4027 u8 *mac_addr = NULL;
4028
4029 memset(&params, 0, sizeof(params));
4030
Johannes Berg984c3112013-02-14 23:43:25 +01004031 if (!rdev->ops->add_station)
4032 return -EOPNOTSUPP;
4033
Johannes Berg5727ef12007-12-19 02:03:34 +01004034 if (!info->attrs[NL80211_ATTR_MAC])
4035 return -EINVAL;
4036
Johannes Berg5727ef12007-12-19 02:03:34 +01004037 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4038 return -EINVAL;
4039
4040 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4041 return -EINVAL;
4042
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004043 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4044 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004045 return -EINVAL;
4046
Johannes Berg5727ef12007-12-19 02:03:34 +01004047 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4048 params.supported_rates =
4049 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4050 params.supported_rates_len =
4051 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4052 params.listen_interval =
4053 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004054
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004055 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004056 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004057 else
4058 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004059 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4060 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004061
Jouni Malinen9d62a982013-02-14 21:10:13 +02004062 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4063 params.capability =
4064 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4065 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4066 }
4067
4068 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4069 params.ext_capab =
4070 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4071 params.ext_capab_len =
4072 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4073 }
4074
Jouni Malinen36aedc902008-08-25 11:58:58 +03004075 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4076 params.ht_capa =
4077 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004078
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004079 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4080 params.vht_capa =
4081 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4082
Johannes Bergf8bacc22013-02-14 23:27:01 +01004083 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004084 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004085 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4086 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4087 return -EINVAL;
4088 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004089
Johannes Bergff276692013-02-15 00:09:01 +01004090 err = nl80211_parse_sta_wme(info, &params);
4091 if (err)
4092 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004093
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004094 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004095 return -EINVAL;
4096
Johannes Berg77ee7c82013-02-15 00:48:33 +01004097 /* When you run into this, adjust the code below for the new flag */
4098 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4099
Johannes Bergbdd90d52011-12-14 12:20:27 +01004100 switch (dev->ieee80211_ptr->iftype) {
4101 case NL80211_IFTYPE_AP:
4102 case NL80211_IFTYPE_AP_VLAN:
4103 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004104 /* ignore WME attributes if iface/sta is not capable */
4105 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4106 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4107 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004108
Johannes Bergbdd90d52011-12-14 12:20:27 +01004109 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004110 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4111 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004112 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004113 /* but don't bother the driver with it */
4114 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004115
Johannes Bergd582cff2012-10-26 17:53:44 +02004116 /* allow authenticated/associated only if driver handles it */
4117 if (!(rdev->wiphy.features &
4118 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4119 params.sta_flags_mask &
4120 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4121 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4122 return -EINVAL;
4123
Johannes Bergbdd90d52011-12-14 12:20:27 +01004124 /* must be last in here for error handling */
4125 params.vlan = get_vlan(info, rdev);
4126 if (IS_ERR(params.vlan))
4127 return PTR_ERR(params.vlan);
4128 break;
4129 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004130 /* ignore uAPSD data */
4131 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4132
Johannes Bergd582cff2012-10-26 17:53:44 +02004133 /* associated is disallowed */
4134 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4135 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004136 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004137 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4138 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004139 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004140 break;
4141 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004142 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004143 /* ignore uAPSD data */
4144 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4145
Johannes Berg77ee7c82013-02-15 00:48:33 +01004146 /* these are disallowed */
4147 if (params.sta_flags_mask &
4148 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4149 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004150 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004151 /* Only TDLS peers can be added */
4152 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4153 return -EINVAL;
4154 /* Can only add if TDLS ... */
4155 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4156 return -EOPNOTSUPP;
4157 /* ... with external setup is supported */
4158 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4159 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004160 /*
4161 * Older wpa_supplicant versions always mark the TDLS peer
4162 * as authorized, but it shouldn't yet be.
4163 */
4164 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004165 break;
4166 default:
4167 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004168 }
4169
Johannes Bergbdd90d52011-12-14 12:20:27 +01004170 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004171
Hila Gonene35e4d22012-06-27 17:19:42 +03004172 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004173
Johannes Berg5727ef12007-12-19 02:03:34 +01004174 if (params.vlan)
4175 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004176 return err;
4177}
4178
4179static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4180{
Johannes Berg4c476992010-10-04 21:36:35 +02004181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4182 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004183 u8 *mac_addr = NULL;
4184
4185 if (info->attrs[NL80211_ATTR_MAC])
4186 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4187
Johannes Berge80cf852009-05-11 14:43:13 +02004188 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004189 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004190 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004191 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4192 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004193
Johannes Berg4c476992010-10-04 21:36:35 +02004194 if (!rdev->ops->del_station)
4195 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004196
Hila Gonene35e4d22012-06-27 17:19:42 +03004197 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004198}
4199
Eric W. Biederman15e47302012-09-07 20:12:54 +00004200static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004201 int flags, struct net_device *dev,
4202 u8 *dst, u8 *next_hop,
4203 struct mpath_info *pinfo)
4204{
4205 void *hdr;
4206 struct nlattr *pinfoattr;
4207
Eric W. Biederman15e47302012-09-07 20:12:54 +00004208 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004209 if (!hdr)
4210 return -1;
4211
David S. Miller9360ffd2012-03-29 04:41:26 -04004212 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4213 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4214 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4215 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4216 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004217
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004218 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4219 if (!pinfoattr)
4220 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004221 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4222 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4223 pinfo->frame_qlen))
4224 goto nla_put_failure;
4225 if (((pinfo->filled & MPATH_INFO_SN) &&
4226 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4227 ((pinfo->filled & MPATH_INFO_METRIC) &&
4228 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4229 pinfo->metric)) ||
4230 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4231 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4232 pinfo->exptime)) ||
4233 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4234 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4235 pinfo->flags)) ||
4236 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4237 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4238 pinfo->discovery_timeout)) ||
4239 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4240 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4241 pinfo->discovery_retries)))
4242 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004243
4244 nla_nest_end(msg, pinfoattr);
4245
4246 return genlmsg_end(msg, hdr);
4247
4248 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004249 genlmsg_cancel(msg, hdr);
4250 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004251}
4252
4253static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004254 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004255{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004256 struct mpath_info pinfo;
4257 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004258 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004259 u8 dst[ETH_ALEN];
4260 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004261 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004263
Johannes Berg97990a02013-04-19 01:02:55 +02004264 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004265 if (err)
4266 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004267
4268 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004269 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004270 goto out_err;
4271 }
4272
Johannes Berg97990a02013-04-19 01:02:55 +02004273 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004274 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004275 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004276 }
4277
Johannes Bergbba95fe2008-07-29 13:22:51 +02004278 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004279 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4280 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004281 if (err == -ENOENT)
4282 break;
4283 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004284 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004285
Eric W. Biederman15e47302012-09-07 20:12:54 +00004286 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004287 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004288 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004289 &pinfo) < 0)
4290 goto out;
4291
4292 path_idx++;
4293 }
4294
4295
4296 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004297 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004298 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004299 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004300 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004301 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302}
4303
4304static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4305{
Johannes Berg4c476992010-10-04 21:36:35 +02004306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004307 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004308 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004309 struct mpath_info pinfo;
4310 struct sk_buff *msg;
4311 u8 *dst = NULL;
4312 u8 next_hop[ETH_ALEN];
4313
4314 memset(&pinfo, 0, sizeof(pinfo));
4315
4316 if (!info->attrs[NL80211_ATTR_MAC])
4317 return -EINVAL;
4318
4319 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4320
Johannes Berg4c476992010-10-04 21:36:35 +02004321 if (!rdev->ops->get_mpath)
4322 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004323
Johannes Berg4c476992010-10-04 21:36:35 +02004324 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4325 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004326
Hila Gonene35e4d22012-06-27 17:19:42 +03004327 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004328 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004329 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004330
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004331 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004332 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004333 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004334
Eric W. Biederman15e47302012-09-07 20:12:54 +00004335 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004336 dev, dst, next_hop, &pinfo) < 0) {
4337 nlmsg_free(msg);
4338 return -ENOBUFS;
4339 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004340
Johannes Berg4c476992010-10-04 21:36:35 +02004341 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004342}
4343
4344static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4345{
Johannes Berg4c476992010-10-04 21:36:35 +02004346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4347 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004348 u8 *dst = NULL;
4349 u8 *next_hop = NULL;
4350
4351 if (!info->attrs[NL80211_ATTR_MAC])
4352 return -EINVAL;
4353
4354 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4355 return -EINVAL;
4356
4357 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4358 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4359
Johannes Berg4c476992010-10-04 21:36:35 +02004360 if (!rdev->ops->change_mpath)
4361 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004362
Johannes Berg4c476992010-10-04 21:36:35 +02004363 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4364 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004365
Hila Gonene35e4d22012-06-27 17:19:42 +03004366 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004367}
Johannes Berg4c476992010-10-04 21:36:35 +02004368
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004369static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4370{
Johannes Berg4c476992010-10-04 21:36:35 +02004371 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4372 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004373 u8 *dst = NULL;
4374 u8 *next_hop = NULL;
4375
4376 if (!info->attrs[NL80211_ATTR_MAC])
4377 return -EINVAL;
4378
4379 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4380 return -EINVAL;
4381
4382 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4383 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4384
Johannes Berg4c476992010-10-04 21:36:35 +02004385 if (!rdev->ops->add_mpath)
4386 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004387
Johannes Berg4c476992010-10-04 21:36:35 +02004388 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4389 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004390
Hila Gonene35e4d22012-06-27 17:19:42 +03004391 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004392}
4393
4394static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4395{
Johannes Berg4c476992010-10-04 21:36:35 +02004396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4397 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004398 u8 *dst = NULL;
4399
4400 if (info->attrs[NL80211_ATTR_MAC])
4401 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4402
Johannes Berg4c476992010-10-04 21:36:35 +02004403 if (!rdev->ops->del_mpath)
4404 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004405
Hila Gonene35e4d22012-06-27 17:19:42 +03004406 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004407}
4408
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004409static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4410{
Johannes Berg4c476992010-10-04 21:36:35 +02004411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4412 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004413 struct bss_parameters params;
4414
4415 memset(&params, 0, sizeof(params));
4416 /* default to not changing parameters */
4417 params.use_cts_prot = -1;
4418 params.use_short_preamble = -1;
4419 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004420 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004421 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004422 params.p2p_ctwindow = -1;
4423 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004424
4425 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4426 params.use_cts_prot =
4427 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4428 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4429 params.use_short_preamble =
4430 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4431 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4432 params.use_short_slot_time =
4433 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004434 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4435 params.basic_rates =
4436 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4437 params.basic_rates_len =
4438 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4439 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004440 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4441 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004442 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4443 params.ht_opmode =
4444 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004445
Johannes Berg53cabad2012-11-14 15:17:28 +01004446 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4447 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4448 return -EINVAL;
4449 params.p2p_ctwindow =
4450 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4451 if (params.p2p_ctwindow < 0)
4452 return -EINVAL;
4453 if (params.p2p_ctwindow != 0 &&
4454 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4455 return -EINVAL;
4456 }
4457
4458 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4459 u8 tmp;
4460
4461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4462 return -EINVAL;
4463 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4464 if (tmp > 1)
4465 return -EINVAL;
4466 params.p2p_opp_ps = tmp;
4467 if (params.p2p_opp_ps &&
4468 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4469 return -EINVAL;
4470 }
4471
Johannes Berg4c476992010-10-04 21:36:35 +02004472 if (!rdev->ops->change_bss)
4473 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004474
Johannes Berg074ac8d2010-09-16 14:58:22 +02004475 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004476 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4477 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004478
Hila Gonene35e4d22012-06-27 17:19:42 +03004479 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004480}
4481
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004482static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004483 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4484 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4485 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4486 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4487 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4488 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4489};
4490
4491static int parse_reg_rule(struct nlattr *tb[],
4492 struct ieee80211_reg_rule *reg_rule)
4493{
4494 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4495 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4496
4497 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4498 return -EINVAL;
4499 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4500 return -EINVAL;
4501 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4502 return -EINVAL;
4503 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4504 return -EINVAL;
4505 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4506 return -EINVAL;
4507
4508 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4509
4510 freq_range->start_freq_khz =
4511 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4512 freq_range->end_freq_khz =
4513 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4514 freq_range->max_bandwidth_khz =
4515 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4516
4517 power_rule->max_eirp =
4518 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4519
4520 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4521 power_rule->max_antenna_gain =
4522 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4523
4524 return 0;
4525}
4526
4527static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4528{
4529 int r;
4530 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004531 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004532
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004533 /*
4534 * You should only get this when cfg80211 hasn't yet initialized
4535 * completely when built-in to the kernel right between the time
4536 * window between nl80211_init() and regulatory_init(), if that is
4537 * even possible.
4538 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004539 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004540 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004541
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004542 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4543 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004544
4545 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4546
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004547 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4548 user_reg_hint_type =
4549 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4550 else
4551 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4552
4553 switch (user_reg_hint_type) {
4554 case NL80211_USER_REG_HINT_USER:
4555 case NL80211_USER_REG_HINT_CELL_BASE:
4556 break;
4557 default:
4558 return -EINVAL;
4559 }
4560
4561 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004562
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004563 return r;
4564}
4565
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004566static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004567 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004568{
Johannes Berg4c476992010-10-04 21:36:35 +02004569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004570 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004571 struct wireless_dev *wdev = dev->ieee80211_ptr;
4572 struct mesh_config cur_params;
4573 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004574 void *hdr;
4575 struct nlattr *pinfoattr;
4576 struct sk_buff *msg;
4577
Johannes Berg29cbe682010-12-03 09:20:44 +01004578 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4579 return -EOPNOTSUPP;
4580
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004581 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004582 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004583
Johannes Berg29cbe682010-12-03 09:20:44 +01004584 wdev_lock(wdev);
4585 /* If not connected, get default parameters */
4586 if (!wdev->mesh_id_len)
4587 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4588 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004589 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004590 wdev_unlock(wdev);
4591
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004592 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004593 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594
4595 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004597 if (!msg)
4598 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004599 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004600 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004602 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004603 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004604 if (!pinfoattr)
4605 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004606 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4607 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4608 cur_params.dot11MeshRetryTimeout) ||
4609 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4610 cur_params.dot11MeshConfirmTimeout) ||
4611 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4612 cur_params.dot11MeshHoldingTimeout) ||
4613 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4614 cur_params.dot11MeshMaxPeerLinks) ||
4615 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4616 cur_params.dot11MeshMaxRetries) ||
4617 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4618 cur_params.dot11MeshTTL) ||
4619 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4620 cur_params.element_ttl) ||
4621 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4622 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004623 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4624 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004625 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4626 cur_params.dot11MeshHWMPmaxPREQretries) ||
4627 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4628 cur_params.path_refresh_time) ||
4629 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4630 cur_params.min_discovery_timeout) ||
4631 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4632 cur_params.dot11MeshHWMPactivePathTimeout) ||
4633 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4634 cur_params.dot11MeshHWMPpreqMinInterval) ||
4635 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4636 cur_params.dot11MeshHWMPperrMinInterval) ||
4637 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4638 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4639 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4640 cur_params.dot11MeshHWMPRootMode) ||
4641 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4642 cur_params.dot11MeshHWMPRannInterval) ||
4643 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4644 cur_params.dot11MeshGateAnnouncementProtocol) ||
4645 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4646 cur_params.dot11MeshForwarding) ||
4647 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004648 cur_params.rssi_threshold) ||
4649 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004650 cur_params.ht_opmode) ||
4651 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4652 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4653 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004654 cur_params.dot11MeshHWMProotInterval) ||
4655 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004656 cur_params.dot11MeshHWMPconfirmationInterval) ||
4657 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4658 cur_params.power_mode) ||
4659 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004660 cur_params.dot11MeshAwakeWindowDuration) ||
4661 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4662 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004663 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004664 nla_nest_end(msg, pinfoattr);
4665 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004666 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004667
Johannes Berg3b858752009-03-12 09:55:09 +01004668 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004669 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004670 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004671 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004672 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004673}
4674
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004675static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004676 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4677 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4678 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4679 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4680 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4681 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004682 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004683 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004684 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004685 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4686 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4687 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4688 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4689 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004690 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004691 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004692 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004693 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004694 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004695 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004696 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4697 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004698 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4699 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004700 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004701 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4702 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004703 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004704};
4705
Javier Cardonac80d5452010-12-16 17:37:49 -08004706static const struct nla_policy
4707 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004708 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004709 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4710 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004711 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004712 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004713 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004714 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004715 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004716 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004717};
4718
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004719static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004720 struct mesh_config *cfg,
4721 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004722{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004723 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004724 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004725
Marco Porschea54fba2013-01-07 16:04:48 +01004726#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4727do { \
4728 if (tb[attr]) { \
4729 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4730 return -EINVAL; \
4731 cfg->param = fn(tb[attr]); \
4732 mask |= (1 << (attr - 1)); \
4733 } \
4734} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004735
4736
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004737 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004738 return -EINVAL;
4739 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004740 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004741 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004742 return -EINVAL;
4743
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004744 /* This makes sure that there aren't more than 32 mesh config
4745 * parameters (otherwise our bitfield scheme would not work.) */
4746 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4747
4748 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004749 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004750 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4751 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004752 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004753 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4754 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004755 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004756 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4757 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004758 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004759 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4760 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004761 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004762 mask, NL80211_MESHCONF_MAX_RETRIES,
4763 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004764 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004765 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004766 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004767 mask, NL80211_MESHCONF_ELEMENT_TTL,
4768 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004769 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004770 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4771 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004772 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4773 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004774 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4775 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004776 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004777 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4778 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004779 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004780 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4781 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004782 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004783 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4784 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004785 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4786 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004787 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4788 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004789 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004790 1, 65535, mask,
4791 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004792 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004793 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004794 1, 65535, mask,
4795 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004796 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004797 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004798 dot11MeshHWMPnetDiameterTraversalTime,
4799 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004800 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4801 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004802 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4803 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4804 nla_get_u8);
4805 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4806 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004807 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004808 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004809 dot11MeshGateAnnouncementProtocol, 0, 1,
4810 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004811 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004813 mask, NL80211_MESHCONF_FORWARDING,
4814 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004815 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004816 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4817 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004819 mask, NL80211_MESHCONF_HT_OPMODE,
4820 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004822 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004823 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4824 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004825 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004826 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4827 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004828 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004829 dot11MeshHWMPconfirmationInterval,
4830 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004831 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4832 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4834 NL80211_MESH_POWER_ACTIVE,
4835 NL80211_MESH_POWER_MAX,
4836 mask, NL80211_MESHCONF_POWER_MODE,
4837 nla_get_u32);
4838 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4839 0, 65535, mask,
4840 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004841 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4842 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4843 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004844 if (mask_out)
4845 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004846
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004847 return 0;
4848
4849#undef FILL_IN_MESH_PARAM_IF_SET
4850}
4851
Javier Cardonac80d5452010-12-16 17:37:49 -08004852static int nl80211_parse_mesh_setup(struct genl_info *info,
4853 struct mesh_setup *setup)
4854{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004856 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4857
4858 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4859 return -EINVAL;
4860 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4861 info->attrs[NL80211_ATTR_MESH_SETUP],
4862 nl80211_mesh_setup_params_policy))
4863 return -EINVAL;
4864
Javier Cardonad299a1f2012-03-31 11:31:33 -07004865 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4866 setup->sync_method =
4867 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4868 IEEE80211_SYNC_METHOD_VENDOR :
4869 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4870
Javier Cardonac80d5452010-12-16 17:37:49 -08004871 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4872 setup->path_sel_proto =
4873 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4874 IEEE80211_PATH_PROTOCOL_VENDOR :
4875 IEEE80211_PATH_PROTOCOL_HWMP;
4876
4877 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4878 setup->path_metric =
4879 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4880 IEEE80211_PATH_METRIC_VENDOR :
4881 IEEE80211_PATH_METRIC_AIRTIME;
4882
Javier Cardona581a8b02011-04-07 15:08:27 -07004883
4884 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004885 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004886 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004887 if (!is_valid_ie_attr(ieattr))
4888 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004889 setup->ie = nla_data(ieattr);
4890 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004891 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004892 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4893 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4894 return -EINVAL;
4895 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004896 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4897 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004898 if (setup->is_secure)
4899 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004900
Colleen Twitty6e16d902013-05-08 11:45:59 -07004901 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4902 if (!setup->user_mpm)
4903 return -EINVAL;
4904 setup->auth_id =
4905 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4906 }
4907
Javier Cardonac80d5452010-12-16 17:37:49 -08004908 return 0;
4909}
4910
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004911static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004912 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004913{
4914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4915 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004916 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004917 struct mesh_config cfg;
4918 u32 mask;
4919 int err;
4920
Johannes Berg29cbe682010-12-03 09:20:44 +01004921 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4922 return -EOPNOTSUPP;
4923
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004924 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004925 return -EOPNOTSUPP;
4926
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004927 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004928 if (err)
4929 return err;
4930
Johannes Berg29cbe682010-12-03 09:20:44 +01004931 wdev_lock(wdev);
4932 if (!wdev->mesh_id_len)
4933 err = -ENOLINK;
4934
4935 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004936 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004937
4938 wdev_unlock(wdev);
4939
4940 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004941}
4942
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004943static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4944{
Johannes Berg458f4f92012-12-06 15:47:38 +01004945 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004946 struct sk_buff *msg;
4947 void *hdr = NULL;
4948 struct nlattr *nl_reg_rules;
4949 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004950
4951 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004952 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004953
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004954 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004955 if (!msg)
4956 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004957
Eric W. Biederman15e47302012-09-07 20:12:54 +00004958 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004959 NL80211_CMD_GET_REG);
4960 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004961 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004962
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004963 if (reg_last_request_cell_base() &&
4964 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4965 NL80211_USER_REG_HINT_CELL_BASE))
4966 goto nla_put_failure;
4967
Johannes Berg458f4f92012-12-06 15:47:38 +01004968 rcu_read_lock();
4969 regdom = rcu_dereference(cfg80211_regdomain);
4970
4971 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4972 (regdom->dfs_region &&
4973 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4974 goto nla_put_failure_rcu;
4975
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004976 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4977 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004978 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004979
Johannes Berg458f4f92012-12-06 15:47:38 +01004980 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004981 struct nlattr *nl_reg_rule;
4982 const struct ieee80211_reg_rule *reg_rule;
4983 const struct ieee80211_freq_range *freq_range;
4984 const struct ieee80211_power_rule *power_rule;
4985
Johannes Berg458f4f92012-12-06 15:47:38 +01004986 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004987 freq_range = &reg_rule->freq_range;
4988 power_rule = &reg_rule->power_rule;
4989
4990 nl_reg_rule = nla_nest_start(msg, i);
4991 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004992 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004993
David S. Miller9360ffd2012-03-29 04:41:26 -04004994 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4995 reg_rule->flags) ||
4996 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4997 freq_range->start_freq_khz) ||
4998 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4999 freq_range->end_freq_khz) ||
5000 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5001 freq_range->max_bandwidth_khz) ||
5002 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5003 power_rule->max_antenna_gain) ||
5004 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5005 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005006 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005007
5008 nla_nest_end(msg, nl_reg_rule);
5009 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005010 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005011
5012 nla_nest_end(msg, nl_reg_rules);
5013
5014 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005015 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005016
Johannes Berg458f4f92012-12-06 15:47:38 +01005017nla_put_failure_rcu:
5018 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005019nla_put_failure:
5020 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005021put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005022 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005023 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005024}
5025
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005026static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5027{
5028 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5029 struct nlattr *nl_reg_rule;
5030 char *alpha2 = NULL;
5031 int rem_reg_rules = 0, r = 0;
5032 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005033 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005034 struct ieee80211_regdomain *rd = NULL;
5035
5036 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5037 return -EINVAL;
5038
5039 if (!info->attrs[NL80211_ATTR_REG_RULES])
5040 return -EINVAL;
5041
5042 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5043
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005044 if (info->attrs[NL80211_ATTR_DFS_REGION])
5045 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5046
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005047 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005048 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005049 num_rules++;
5050 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005051 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005052 }
5053
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005054 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005055 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005056
5057 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005058 if (!rd)
5059 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005060
5061 rd->n_reg_rules = num_rules;
5062 rd->alpha2[0] = alpha2[0];
5063 rd->alpha2[1] = alpha2[1];
5064
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005065 /*
5066 * Disable DFS master mode if the DFS region was
5067 * not supported or known on this kernel.
5068 */
5069 if (reg_supported_dfs_region(dfs_region))
5070 rd->dfs_region = dfs_region;
5071
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005072 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005073 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005074 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005075 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5076 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005077 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5078 if (r)
5079 goto bad_reg;
5080
5081 rule_idx++;
5082
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005083 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5084 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005085 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005086 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005087 }
5088
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005089 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005090 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005091 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005092
Johannes Bergd2372b32008-10-24 20:32:20 +02005093 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005094 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005095 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005096}
5097
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005098static int validate_scan_freqs(struct nlattr *freqs)
5099{
5100 struct nlattr *attr1, *attr2;
5101 int n_channels = 0, tmp1, tmp2;
5102
5103 nla_for_each_nested(attr1, freqs, tmp1) {
5104 n_channels++;
5105 /*
5106 * Some hardware has a limited channel list for
5107 * scanning, and it is pretty much nonsensical
5108 * to scan for a channel twice, so disallow that
5109 * and don't require drivers to check that the
5110 * channel list they get isn't longer than what
5111 * they can scan, as long as they can scan all
5112 * the channels they registered at once.
5113 */
5114 nla_for_each_nested(attr2, freqs, tmp2)
5115 if (attr1 != attr2 &&
5116 nla_get_u32(attr1) == nla_get_u32(attr2))
5117 return 0;
5118 }
5119
5120 return n_channels;
5121}
5122
Johannes Berg2a519312009-02-10 21:25:55 +01005123static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5124{
Johannes Berg4c476992010-10-04 21:36:35 +02005125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005126 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005127 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005128 struct nlattr *attr;
5129 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005130 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005131 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005132
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005133 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5134 return -EINVAL;
5135
Johannes Berg79c97e92009-07-07 03:56:12 +02005136 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005137
Johannes Berg4c476992010-10-04 21:36:35 +02005138 if (!rdev->ops->scan)
5139 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005140
Johannes Bergf9f47522013-03-19 15:04:07 +01005141 if (rdev->scan_req) {
5142 err = -EBUSY;
5143 goto unlock;
5144 }
Johannes Berg2a519312009-02-10 21:25:55 +01005145
5146 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005147 n_channels = validate_scan_freqs(
5148 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005149 if (!n_channels) {
5150 err = -EINVAL;
5151 goto unlock;
5152 }
Johannes Berg2a519312009-02-10 21:25:55 +01005153 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005154 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005155 n_channels = 0;
5156
Johannes Berg2a519312009-02-10 21:25:55 +01005157 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5158 if (wiphy->bands[band])
5159 n_channels += wiphy->bands[band]->n_channels;
5160 }
5161
5162 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5163 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5164 n_ssids++;
5165
Johannes Bergf9f47522013-03-19 15:04:07 +01005166 if (n_ssids > wiphy->max_scan_ssids) {
5167 err = -EINVAL;
5168 goto unlock;
5169 }
Johannes Berg2a519312009-02-10 21:25:55 +01005170
Jouni Malinen70692ad2009-02-16 19:39:13 +02005171 if (info->attrs[NL80211_ATTR_IE])
5172 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5173 else
5174 ie_len = 0;
5175
Johannes Bergf9f47522013-03-19 15:04:07 +01005176 if (ie_len > wiphy->max_scan_ie_len) {
5177 err = -EINVAL;
5178 goto unlock;
5179 }
Johannes Berg18a83652009-03-31 12:12:05 +02005180
Johannes Berg2a519312009-02-10 21:25:55 +01005181 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005182 + sizeof(*request->ssids) * n_ssids
5183 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005184 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005185 if (!request) {
5186 err = -ENOMEM;
5187 goto unlock;
5188 }
Johannes Berg2a519312009-02-10 21:25:55 +01005189
Johannes Berg2a519312009-02-10 21:25:55 +01005190 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005191 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005192 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005193 if (ie_len) {
5194 if (request->ssids)
5195 request->ie = (void *)(request->ssids + n_ssids);
5196 else
5197 request->ie = (void *)(request->channels + n_channels);
5198 }
Johannes Berg2a519312009-02-10 21:25:55 +01005199
Johannes Berg584991d2009-11-02 13:32:03 +01005200 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005201 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5202 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005203 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005204 struct ieee80211_channel *chan;
5205
5206 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5207
5208 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005209 err = -EINVAL;
5210 goto out_free;
5211 }
Johannes Berg584991d2009-11-02 13:32:03 +01005212
5213 /* ignore disabled channels */
5214 if (chan->flags & IEEE80211_CHAN_DISABLED)
5215 continue;
5216
5217 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005218 i++;
5219 }
5220 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005221 enum ieee80211_band band;
5222
Johannes Berg2a519312009-02-10 21:25:55 +01005223 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005224 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5225 int j;
5226 if (!wiphy->bands[band])
5227 continue;
5228 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005229 struct ieee80211_channel *chan;
5230
5231 chan = &wiphy->bands[band]->channels[j];
5232
5233 if (chan->flags & IEEE80211_CHAN_DISABLED)
5234 continue;
5235
5236 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005237 i++;
5238 }
5239 }
5240 }
5241
Johannes Berg584991d2009-11-02 13:32:03 +01005242 if (!i) {
5243 err = -EINVAL;
5244 goto out_free;
5245 }
5246
5247 request->n_channels = i;
5248
Johannes Berg2a519312009-02-10 21:25:55 +01005249 i = 0;
5250 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5251 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005252 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005253 err = -EINVAL;
5254 goto out_free;
5255 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005256 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005257 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005258 i++;
5259 }
5260 }
5261
Jouni Malinen70692ad2009-02-16 19:39:13 +02005262 if (info->attrs[NL80211_ATTR_IE]) {
5263 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005264 memcpy((void *)request->ie,
5265 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005266 request->ie_len);
5267 }
5268
Johannes Berg34850ab2011-07-18 18:08:35 +02005269 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005270 if (wiphy->bands[i])
5271 request->rates[i] =
5272 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005273
5274 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5275 nla_for_each_nested(attr,
5276 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5277 tmp) {
5278 enum ieee80211_band band = nla_type(attr);
5279
Dan Carpenter84404622011-07-29 11:52:18 +03005280 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005281 err = -EINVAL;
5282 goto out_free;
5283 }
5284 err = ieee80211_get_ratemask(wiphy->bands[band],
5285 nla_data(attr),
5286 nla_len(attr),
5287 &request->rates[band]);
5288 if (err)
5289 goto out_free;
5290 }
5291 }
5292
Sam Leffler46856bb2012-10-11 21:03:32 -07005293 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005294 request->flags = nla_get_u32(
5295 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005296 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5297 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5298 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5299 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005300 err = -EOPNOTSUPP;
5301 goto out_free;
5302 }
5303 }
Sam Lefflered4737712012-10-11 21:03:31 -07005304
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305305 request->no_cck =
5306 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5307
Johannes Bergfd014282012-06-18 19:17:03 +02005308 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005309 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005310 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005311
Johannes Berg79c97e92009-07-07 03:56:12 +02005312 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005313 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005314
Johannes Berg463d0182009-07-14 00:33:35 +02005315 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005316 nl80211_send_scan_start(rdev, wdev);
5317 if (wdev->netdev)
5318 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005319 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005320 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005321 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005322 kfree(request);
5323 }
Johannes Berg3b858752009-03-12 09:55:09 +01005324
Johannes Bergf9f47522013-03-19 15:04:07 +01005325 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005326 return err;
5327}
5328
Luciano Coelho807f8a82011-05-11 17:09:35 +03005329static int nl80211_start_sched_scan(struct sk_buff *skb,
5330 struct genl_info *info)
5331{
5332 struct cfg80211_sched_scan_request *request;
5333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5334 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005335 struct nlattr *attr;
5336 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005337 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005338 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005339 enum ieee80211_band band;
5340 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005341 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005342
5343 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5344 !rdev->ops->sched_scan_start)
5345 return -EOPNOTSUPP;
5346
5347 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5348 return -EINVAL;
5349
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005350 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5351 return -EINVAL;
5352
5353 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5354 if (interval == 0)
5355 return -EINVAL;
5356
Luciano Coelho807f8a82011-05-11 17:09:35 +03005357 wiphy = &rdev->wiphy;
5358
5359 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5360 n_channels = validate_scan_freqs(
5361 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5362 if (!n_channels)
5363 return -EINVAL;
5364 } else {
5365 n_channels = 0;
5366
5367 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5368 if (wiphy->bands[band])
5369 n_channels += wiphy->bands[band]->n_channels;
5370 }
5371
5372 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5373 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5374 tmp)
5375 n_ssids++;
5376
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005377 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005378 return -EINVAL;
5379
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005380 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5381 nla_for_each_nested(attr,
5382 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5383 tmp)
5384 n_match_sets++;
5385
5386 if (n_match_sets > wiphy->max_match_sets)
5387 return -EINVAL;
5388
Luciano Coelho807f8a82011-05-11 17:09:35 +03005389 if (info->attrs[NL80211_ATTR_IE])
5390 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5391 else
5392 ie_len = 0;
5393
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005394 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005395 return -EINVAL;
5396
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005397 if (rdev->sched_scan_req) {
5398 err = -EINPROGRESS;
5399 goto out;
5400 }
5401
Luciano Coelho807f8a82011-05-11 17:09:35 +03005402 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005403 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005404 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005405 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005406 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005407 if (!request) {
5408 err = -ENOMEM;
5409 goto out;
5410 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005411
5412 if (n_ssids)
5413 request->ssids = (void *)&request->channels[n_channels];
5414 request->n_ssids = n_ssids;
5415 if (ie_len) {
5416 if (request->ssids)
5417 request->ie = (void *)(request->ssids + n_ssids);
5418 else
5419 request->ie = (void *)(request->channels + n_channels);
5420 }
5421
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005422 if (n_match_sets) {
5423 if (request->ie)
5424 request->match_sets = (void *)(request->ie + ie_len);
5425 else if (request->ssids)
5426 request->match_sets =
5427 (void *)(request->ssids + n_ssids);
5428 else
5429 request->match_sets =
5430 (void *)(request->channels + n_channels);
5431 }
5432 request->n_match_sets = n_match_sets;
5433
Luciano Coelho807f8a82011-05-11 17:09:35 +03005434 i = 0;
5435 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5436 /* user specified, bail out if channel not found */
5437 nla_for_each_nested(attr,
5438 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5439 tmp) {
5440 struct ieee80211_channel *chan;
5441
5442 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5443
5444 if (!chan) {
5445 err = -EINVAL;
5446 goto out_free;
5447 }
5448
5449 /* ignore disabled channels */
5450 if (chan->flags & IEEE80211_CHAN_DISABLED)
5451 continue;
5452
5453 request->channels[i] = chan;
5454 i++;
5455 }
5456 } else {
5457 /* all channels */
5458 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5459 int j;
5460 if (!wiphy->bands[band])
5461 continue;
5462 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5463 struct ieee80211_channel *chan;
5464
5465 chan = &wiphy->bands[band]->channels[j];
5466
5467 if (chan->flags & IEEE80211_CHAN_DISABLED)
5468 continue;
5469
5470 request->channels[i] = chan;
5471 i++;
5472 }
5473 }
5474 }
5475
5476 if (!i) {
5477 err = -EINVAL;
5478 goto out_free;
5479 }
5480
5481 request->n_channels = i;
5482
5483 i = 0;
5484 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5485 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5486 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005487 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005488 err = -EINVAL;
5489 goto out_free;
5490 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005491 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005492 memcpy(request->ssids[i].ssid, nla_data(attr),
5493 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005494 i++;
5495 }
5496 }
5497
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005498 i = 0;
5499 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5500 nla_for_each_nested(attr,
5501 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5502 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005503 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005504
5505 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5506 nla_data(attr), nla_len(attr),
5507 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005508 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005509 if (ssid) {
5510 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5511 err = -EINVAL;
5512 goto out_free;
5513 }
5514 memcpy(request->match_sets[i].ssid.ssid,
5515 nla_data(ssid), nla_len(ssid));
5516 request->match_sets[i].ssid.ssid_len =
5517 nla_len(ssid);
5518 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005519 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5520 if (rssi)
5521 request->rssi_thold = nla_get_u32(rssi);
5522 else
5523 request->rssi_thold =
5524 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005525 i++;
5526 }
5527 }
5528
Luciano Coelho807f8a82011-05-11 17:09:35 +03005529 if (info->attrs[NL80211_ATTR_IE]) {
5530 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5531 memcpy((void *)request->ie,
5532 nla_data(info->attrs[NL80211_ATTR_IE]),
5533 request->ie_len);
5534 }
5535
Sam Leffler46856bb2012-10-11 21:03:32 -07005536 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005537 request->flags = nla_get_u32(
5538 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005539 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5540 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5541 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5542 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005543 err = -EOPNOTSUPP;
5544 goto out_free;
5545 }
5546 }
Sam Lefflered4737712012-10-11 21:03:31 -07005547
Luciano Coelho807f8a82011-05-11 17:09:35 +03005548 request->dev = dev;
5549 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005550 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005551 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005552
Hila Gonene35e4d22012-06-27 17:19:42 +03005553 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005554 if (!err) {
5555 rdev->sched_scan_req = request;
5556 nl80211_send_sched_scan(rdev, dev,
5557 NL80211_CMD_START_SCHED_SCAN);
5558 goto out;
5559 }
5560
5561out_free:
5562 kfree(request);
5563out:
5564 return err;
5565}
5566
5567static int nl80211_stop_sched_scan(struct sk_buff *skb,
5568 struct genl_info *info)
5569{
5570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5571
5572 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5573 !rdev->ops->sched_scan_stop)
5574 return -EOPNOTSUPP;
5575
Johannes Berg5fe231e2013-05-08 21:45:15 +02005576 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005577}
5578
Simon Wunderlich04f39042013-02-08 18:16:19 +01005579static int nl80211_start_radar_detection(struct sk_buff *skb,
5580 struct genl_info *info)
5581{
5582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5583 struct net_device *dev = info->user_ptr[1];
5584 struct wireless_dev *wdev = dev->ieee80211_ptr;
5585 struct cfg80211_chan_def chandef;
5586 int err;
5587
5588 err = nl80211_parse_chandef(rdev, info, &chandef);
5589 if (err)
5590 return err;
5591
5592 if (wdev->cac_started)
5593 return -EBUSY;
5594
5595 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5596 if (err < 0)
5597 return err;
5598
5599 if (err == 0)
5600 return -EINVAL;
5601
5602 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5603 return -EINVAL;
5604
5605 if (!rdev->ops->start_radar_detection)
5606 return -EOPNOTSUPP;
5607
Simon Wunderlich04f39042013-02-08 18:16:19 +01005608 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5609 chandef.chan, CHAN_MODE_SHARED,
5610 BIT(chandef.width));
5611 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005612 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005613
5614 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5615 if (!err) {
5616 wdev->channel = chandef.chan;
5617 wdev->cac_started = true;
5618 wdev->cac_start_time = jiffies;
5619 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005620 return err;
5621}
5622
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005623static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5624{
5625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5626 struct net_device *dev = info->user_ptr[1];
5627 struct wireless_dev *wdev = dev->ieee80211_ptr;
5628 struct cfg80211_csa_settings params;
5629 /* csa_attrs is defined static to avoid waste of stack size - this
5630 * function is called under RTNL lock, so this should not be a problem.
5631 */
5632 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5633 u8 radar_detect_width = 0;
5634 int err;
5635
5636 if (!rdev->ops->channel_switch ||
5637 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5638 return -EOPNOTSUPP;
5639
5640 /* may add IBSS support later */
5641 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5642 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5643 return -EOPNOTSUPP;
5644
5645 memset(&params, 0, sizeof(params));
5646
5647 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5648 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5649 return -EINVAL;
5650
5651 /* only important for AP, IBSS and mesh create IEs internally */
5652 if (!info->attrs[NL80211_ATTR_CSA_IES])
5653 return -EINVAL;
5654
5655 /* useless if AP is not running */
5656 if (!wdev->beacon_interval)
5657 return -EINVAL;
5658
5659 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5660
5661 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5662 if (err)
5663 return err;
5664
5665 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5666 info->attrs[NL80211_ATTR_CSA_IES],
5667 nl80211_policy);
5668 if (err)
5669 return err;
5670
5671 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5672 if (err)
5673 return err;
5674
5675 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5676 return -EINVAL;
5677
5678 params.counter_offset_beacon =
5679 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5680 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5681 return -EINVAL;
5682
5683 /* sanity check - counters should be the same */
5684 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5685 params.count)
5686 return -EINVAL;
5687
5688 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5689 params.counter_offset_presp =
5690 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5691 if (params.counter_offset_presp >=
5692 params.beacon_csa.probe_resp_len)
5693 return -EINVAL;
5694
5695 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5696 params.count)
5697 return -EINVAL;
5698 }
5699
5700 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5701 if (err)
5702 return err;
5703
5704 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5705 return -EINVAL;
5706
5707 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
5708 if (err < 0) {
5709 return err;
5710 } else if (err) {
5711 radar_detect_width = BIT(params.chandef.width);
5712 params.radar_required = true;
5713 }
5714
5715 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5716 params.chandef.chan,
5717 CHAN_MODE_SHARED,
5718 radar_detect_width);
5719 if (err)
5720 return err;
5721
5722 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5723 params.block_tx = true;
5724
5725 return rdev_channel_switch(rdev, dev, &params);
5726}
5727
Johannes Berg9720bb32011-06-21 09:45:33 +02005728static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5729 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005730 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005731 struct wireless_dev *wdev,
5732 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005733{
Johannes Berg48ab9052009-07-10 18:42:31 +02005734 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005735 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005736 void *hdr;
5737 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005738 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005739
5740 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005741
Eric W. Biederman15e47302012-09-07 20:12:54 +00005742 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005743 NL80211_CMD_NEW_SCAN_RESULTS);
5744 if (!hdr)
5745 return -1;
5746
Johannes Berg9720bb32011-06-21 09:45:33 +02005747 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5748
Johannes Berg97990a02013-04-19 01:02:55 +02005749 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5750 goto nla_put_failure;
5751 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005752 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5753 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005754 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5755 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005756
5757 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5758 if (!bss)
5759 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005760 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005761 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005762 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005763
5764 rcu_read_lock();
5765 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005766 if (ies) {
5767 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5768 goto fail_unlock_rcu;
5769 tsf = true;
5770 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5771 ies->len, ies->data))
5772 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005773 }
5774 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005775 if (ies) {
5776 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5777 goto fail_unlock_rcu;
5778 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5779 ies->len, ies->data))
5780 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005781 }
5782 rcu_read_unlock();
5783
David S. Miller9360ffd2012-03-29 04:41:26 -04005784 if (res->beacon_interval &&
5785 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5786 goto nla_put_failure;
5787 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5788 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005789 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005790 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5791 jiffies_to_msecs(jiffies - intbss->ts)))
5792 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005793
Johannes Berg77965c92009-02-18 18:45:06 +01005794 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005795 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005796 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5797 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005798 break;
5799 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005800 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5801 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005802 break;
5803 default:
5804 break;
5805 }
5806
Johannes Berg48ab9052009-07-10 18:42:31 +02005807 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005808 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005809 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005810 if (intbss == wdev->current_bss &&
5811 nla_put_u32(msg, NL80211_BSS_STATUS,
5812 NL80211_BSS_STATUS_ASSOCIATED))
5813 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005814 break;
5815 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005816 if (intbss == wdev->current_bss &&
5817 nla_put_u32(msg, NL80211_BSS_STATUS,
5818 NL80211_BSS_STATUS_IBSS_JOINED))
5819 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005820 break;
5821 default:
5822 break;
5823 }
5824
Johannes Berg2a519312009-02-10 21:25:55 +01005825 nla_nest_end(msg, bss);
5826
5827 return genlmsg_end(msg, hdr);
5828
Johannes Berg8cef2c92013-02-05 16:54:31 +01005829 fail_unlock_rcu:
5830 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005831 nla_put_failure:
5832 genlmsg_cancel(msg, hdr);
5833 return -EMSGSIZE;
5834}
5835
Johannes Berg97990a02013-04-19 01:02:55 +02005836static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005837{
Johannes Berg48ab9052009-07-10 18:42:31 +02005838 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005839 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005840 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005841 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005842 int err;
5843
Johannes Berg97990a02013-04-19 01:02:55 +02005844 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005845 if (err)
5846 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005847
Johannes Berg48ab9052009-07-10 18:42:31 +02005848 wdev_lock(wdev);
5849 spin_lock_bh(&rdev->bss_lock);
5850 cfg80211_bss_expire(rdev);
5851
Johannes Berg9720bb32011-06-21 09:45:33 +02005852 cb->seq = rdev->bss_generation;
5853
Johannes Berg48ab9052009-07-10 18:42:31 +02005854 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005855 if (++idx <= start)
5856 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005857 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005858 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005859 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005860 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005861 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005862 }
5863 }
5864
Johannes Berg48ab9052009-07-10 18:42:31 +02005865 spin_unlock_bh(&rdev->bss_lock);
5866 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005867
Johannes Berg97990a02013-04-19 01:02:55 +02005868 cb->args[2] = idx;
5869 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005870
Johannes Berg67748892010-10-04 21:14:06 +02005871 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005872}
5873
Eric W. Biederman15e47302012-09-07 20:12:54 +00005874static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005875 int flags, struct net_device *dev,
5876 struct survey_info *survey)
5877{
5878 void *hdr;
5879 struct nlattr *infoattr;
5880
Eric W. Biederman15e47302012-09-07 20:12:54 +00005881 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005882 NL80211_CMD_NEW_SURVEY_RESULTS);
5883 if (!hdr)
5884 return -ENOMEM;
5885
David S. Miller9360ffd2012-03-29 04:41:26 -04005886 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5887 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005888
5889 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5890 if (!infoattr)
5891 goto nla_put_failure;
5892
David S. Miller9360ffd2012-03-29 04:41:26 -04005893 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5894 survey->channel->center_freq))
5895 goto nla_put_failure;
5896
5897 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5898 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5899 goto nla_put_failure;
5900 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5901 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5902 goto nla_put_failure;
5903 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5904 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5905 survey->channel_time))
5906 goto nla_put_failure;
5907 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5908 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5909 survey->channel_time_busy))
5910 goto nla_put_failure;
5911 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5912 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5913 survey->channel_time_ext_busy))
5914 goto nla_put_failure;
5915 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5916 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5917 survey->channel_time_rx))
5918 goto nla_put_failure;
5919 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5920 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5921 survey->channel_time_tx))
5922 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005923
5924 nla_nest_end(msg, infoattr);
5925
5926 return genlmsg_end(msg, hdr);
5927
5928 nla_put_failure:
5929 genlmsg_cancel(msg, hdr);
5930 return -EMSGSIZE;
5931}
5932
5933static int nl80211_dump_survey(struct sk_buff *skb,
5934 struct netlink_callback *cb)
5935{
5936 struct survey_info survey;
5937 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005938 struct wireless_dev *wdev;
5939 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005940 int res;
5941
Johannes Berg97990a02013-04-19 01:02:55 +02005942 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005943 if (res)
5944 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005945
Johannes Berg97990a02013-04-19 01:02:55 +02005946 if (!wdev->netdev) {
5947 res = -EINVAL;
5948 goto out_err;
5949 }
5950
Holger Schurig61fa7132009-11-11 12:25:40 +01005951 if (!dev->ops->dump_survey) {
5952 res = -EOPNOTSUPP;
5953 goto out_err;
5954 }
5955
5956 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005957 struct ieee80211_channel *chan;
5958
Johannes Berg97990a02013-04-19 01:02:55 +02005959 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005960 if (res == -ENOENT)
5961 break;
5962 if (res)
5963 goto out_err;
5964
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005965 /* Survey without a channel doesn't make sense */
5966 if (!survey.channel) {
5967 res = -EINVAL;
5968 goto out;
5969 }
5970
5971 chan = ieee80211_get_channel(&dev->wiphy,
5972 survey.channel->center_freq);
5973 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5974 survey_idx++;
5975 continue;
5976 }
5977
Holger Schurig61fa7132009-11-11 12:25:40 +01005978 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005979 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005980 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005981 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005982 goto out;
5983 survey_idx++;
5984 }
5985
5986 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005987 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005988 res = skb->len;
5989 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005990 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005991 return res;
5992}
5993
Samuel Ortizb23aa672009-07-01 21:26:54 +02005994static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5995{
5996 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5997 NL80211_WPA_VERSION_2));
5998}
5999
Jouni Malinen636a5d32009-03-19 13:39:22 +02006000static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6001{
Johannes Berg4c476992010-10-04 21:36:35 +02006002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6003 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006004 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006005 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6006 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006007 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006008 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006009 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006010
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006011 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6012 return -EINVAL;
6013
6014 if (!info->attrs[NL80211_ATTR_MAC])
6015 return -EINVAL;
6016
Jouni Malinen17780922009-03-27 20:52:47 +02006017 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6018 return -EINVAL;
6019
Johannes Berg19957bb2009-07-02 17:20:43 +02006020 if (!info->attrs[NL80211_ATTR_SSID])
6021 return -EINVAL;
6022
6023 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6024 return -EINVAL;
6025
Johannes Bergfffd0932009-07-08 14:22:54 +02006026 err = nl80211_parse_key(info, &key);
6027 if (err)
6028 return err;
6029
6030 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006031 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6032 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006033 if (!key.p.key || !key.p.key_len)
6034 return -EINVAL;
6035 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6036 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6037 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6038 key.p.key_len != WLAN_KEY_LEN_WEP104))
6039 return -EINVAL;
6040 if (key.idx > 4)
6041 return -EINVAL;
6042 } else {
6043 key.p.key_len = 0;
6044 key.p.key = NULL;
6045 }
6046
Johannes Bergafea0b72010-08-10 09:46:42 +02006047 if (key.idx >= 0) {
6048 int i;
6049 bool ok = false;
6050 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6051 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6052 ok = true;
6053 break;
6054 }
6055 }
Johannes Berg4c476992010-10-04 21:36:35 +02006056 if (!ok)
6057 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006058 }
6059
Johannes Berg4c476992010-10-04 21:36:35 +02006060 if (!rdev->ops->auth)
6061 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006062
Johannes Berg074ac8d2010-09-16 14:58:22 +02006063 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006064 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6065 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006066
Johannes Berg19957bb2009-07-02 17:20:43 +02006067 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006068 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006069 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006070 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6071 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006072
Johannes Berg19957bb2009-07-02 17:20:43 +02006073 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6074 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6075
6076 if (info->attrs[NL80211_ATTR_IE]) {
6077 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6078 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6079 }
6080
6081 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006082 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006083 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006084
Jouni Malinene39e5b52012-09-30 19:29:39 +03006085 if (auth_type == NL80211_AUTHTYPE_SAE &&
6086 !info->attrs[NL80211_ATTR_SAE_DATA])
6087 return -EINVAL;
6088
6089 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6090 if (auth_type != NL80211_AUTHTYPE_SAE)
6091 return -EINVAL;
6092 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6093 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6094 /* need to include at least Auth Transaction and Status Code */
6095 if (sae_data_len < 4)
6096 return -EINVAL;
6097 }
6098
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006099 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6100
Johannes Berg95de8172012-01-20 13:55:25 +01006101 /*
6102 * Since we no longer track auth state, ignore
6103 * requests to only change local state.
6104 */
6105 if (local_state_change)
6106 return 0;
6107
Johannes Berg91bf9b22013-05-15 17:44:01 +02006108 wdev_lock(dev->ieee80211_ptr);
6109 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6110 ssid, ssid_len, ie, ie_len,
6111 key.p.key, key.p.key_len, key.idx,
6112 sae_data, sae_data_len);
6113 wdev_unlock(dev->ieee80211_ptr);
6114 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006115}
6116
Johannes Bergc0692b82010-08-27 14:26:53 +03006117static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6118 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006119 struct cfg80211_crypto_settings *settings,
6120 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006121{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006122 memset(settings, 0, sizeof(*settings));
6123
Samuel Ortizb23aa672009-07-01 21:26:54 +02006124 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6125
Johannes Bergc0692b82010-08-27 14:26:53 +03006126 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6127 u16 proto;
6128 proto = nla_get_u16(
6129 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6130 settings->control_port_ethertype = cpu_to_be16(proto);
6131 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6132 proto != ETH_P_PAE)
6133 return -EINVAL;
6134 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6135 settings->control_port_no_encrypt = true;
6136 } else
6137 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6138
Samuel Ortizb23aa672009-07-01 21:26:54 +02006139 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6140 void *data;
6141 int len, i;
6142
6143 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6144 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6145 settings->n_ciphers_pairwise = len / sizeof(u32);
6146
6147 if (len % sizeof(u32))
6148 return -EINVAL;
6149
Johannes Berg3dc27d22009-07-02 21:36:37 +02006150 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006151 return -EINVAL;
6152
6153 memcpy(settings->ciphers_pairwise, data, len);
6154
6155 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006156 if (!cfg80211_supported_cipher_suite(
6157 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006158 settings->ciphers_pairwise[i]))
6159 return -EINVAL;
6160 }
6161
6162 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6163 settings->cipher_group =
6164 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006165 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6166 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006167 return -EINVAL;
6168 }
6169
6170 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6171 settings->wpa_versions =
6172 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6173 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6174 return -EINVAL;
6175 }
6176
6177 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6178 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006179 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006180
6181 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6182 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6183 settings->n_akm_suites = len / sizeof(u32);
6184
6185 if (len % sizeof(u32))
6186 return -EINVAL;
6187
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006188 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6189 return -EINVAL;
6190
Samuel Ortizb23aa672009-07-01 21:26:54 +02006191 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006192 }
6193
6194 return 0;
6195}
6196
Jouni Malinen636a5d32009-03-19 13:39:22 +02006197static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6198{
Johannes Berg4c476992010-10-04 21:36:35 +02006199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6200 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006201 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006202 struct cfg80211_assoc_request req = {};
6203 const u8 *bssid, *ssid;
6204 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006205
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006206 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6207 return -EINVAL;
6208
6209 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006210 !info->attrs[NL80211_ATTR_SSID] ||
6211 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006212 return -EINVAL;
6213
Johannes Berg4c476992010-10-04 21:36:35 +02006214 if (!rdev->ops->assoc)
6215 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006216
Johannes Berg074ac8d2010-09-16 14:58:22 +02006217 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006218 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6219 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006220
Johannes Berg19957bb2009-07-02 17:20:43 +02006221 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006222
Johannes Berg19957bb2009-07-02 17:20:43 +02006223 chan = ieee80211_get_channel(&rdev->wiphy,
6224 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006225 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6226 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006227
Johannes Berg19957bb2009-07-02 17:20:43 +02006228 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6229 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006230
6231 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006232 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6233 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006234 }
6235
Jouni Malinendc6382c2009-05-06 22:09:37 +03006236 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006237 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006238 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006239 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006240 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006241 else if (mfp != NL80211_MFP_NO)
6242 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006243 }
6244
Johannes Berg3e5d7642009-07-07 14:37:26 +02006245 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006246 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006247
Ben Greear7e7c8922011-11-18 11:31:59 -08006248 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006249 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006250
6251 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006252 memcpy(&req.ht_capa_mask,
6253 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6254 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006255
6256 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006257 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006258 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006259 memcpy(&req.ht_capa,
6260 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6261 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006262 }
6263
Johannes Bergee2aca32013-02-21 17:36:01 +01006264 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006265 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006266
6267 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006268 memcpy(&req.vht_capa_mask,
6269 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6270 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006271
6272 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006273 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006274 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006275 memcpy(&req.vht_capa,
6276 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6277 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006278 }
6279
Johannes Bergf62fab72013-02-21 20:09:09 +01006280 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006281 if (!err) {
6282 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006283 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6284 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006285 wdev_unlock(dev->ieee80211_ptr);
6286 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006287
Jouni Malinen636a5d32009-03-19 13:39:22 +02006288 return err;
6289}
6290
6291static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6292{
Johannes Berg4c476992010-10-04 21:36:35 +02006293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6294 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006295 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006296 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006297 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006298 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006299
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006300 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6301 return -EINVAL;
6302
6303 if (!info->attrs[NL80211_ATTR_MAC])
6304 return -EINVAL;
6305
6306 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6307 return -EINVAL;
6308
Johannes Berg4c476992010-10-04 21:36:35 +02006309 if (!rdev->ops->deauth)
6310 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006311
Johannes Berg074ac8d2010-09-16 14:58:22 +02006312 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006313 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6314 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006315
Johannes Berg19957bb2009-07-02 17:20:43 +02006316 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006317
Johannes Berg19957bb2009-07-02 17:20:43 +02006318 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6319 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006320 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006321 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006322 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006323
6324 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006325 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6326 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006327 }
6328
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006329 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6330
Johannes Berg91bf9b22013-05-15 17:44:01 +02006331 wdev_lock(dev->ieee80211_ptr);
6332 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6333 local_state_change);
6334 wdev_unlock(dev->ieee80211_ptr);
6335 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006336}
6337
6338static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6339{
Johannes Berg4c476992010-10-04 21:36:35 +02006340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6341 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006342 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006343 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006344 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006345 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006346
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006347 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6348 return -EINVAL;
6349
6350 if (!info->attrs[NL80211_ATTR_MAC])
6351 return -EINVAL;
6352
6353 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6354 return -EINVAL;
6355
Johannes Berg4c476992010-10-04 21:36:35 +02006356 if (!rdev->ops->disassoc)
6357 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006358
Johannes Berg074ac8d2010-09-16 14:58:22 +02006359 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006360 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6361 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006362
Johannes Berg19957bb2009-07-02 17:20:43 +02006363 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006364
Johannes Berg19957bb2009-07-02 17:20:43 +02006365 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6366 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006367 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006368 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006369 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006370
6371 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006372 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6373 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006374 }
6375
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006376 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6377
Johannes Berg91bf9b22013-05-15 17:44:01 +02006378 wdev_lock(dev->ieee80211_ptr);
6379 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6380 local_state_change);
6381 wdev_unlock(dev->ieee80211_ptr);
6382 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006383}
6384
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006385static bool
6386nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6387 int mcast_rate[IEEE80211_NUM_BANDS],
6388 int rateval)
6389{
6390 struct wiphy *wiphy = &rdev->wiphy;
6391 bool found = false;
6392 int band, i;
6393
6394 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6395 struct ieee80211_supported_band *sband;
6396
6397 sband = wiphy->bands[band];
6398 if (!sband)
6399 continue;
6400
6401 for (i = 0; i < sband->n_bitrates; i++) {
6402 if (sband->bitrates[i].bitrate == rateval) {
6403 mcast_rate[band] = i + 1;
6404 found = true;
6405 break;
6406 }
6407 }
6408 }
6409
6410 return found;
6411}
6412
Johannes Berg04a773a2009-04-19 21:24:32 +02006413static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6414{
Johannes Berg4c476992010-10-04 21:36:35 +02006415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6416 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006417 struct cfg80211_ibss_params ibss;
6418 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006419 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006420 int err;
6421
Johannes Berg8e30bc52009-04-22 17:45:38 +02006422 memset(&ibss, 0, sizeof(ibss));
6423
Johannes Berg04a773a2009-04-19 21:24:32 +02006424 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6425 return -EINVAL;
6426
Johannes Berg683b6d32012-11-08 21:25:48 +01006427 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006428 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6429 return -EINVAL;
6430
Johannes Berg8e30bc52009-04-22 17:45:38 +02006431 ibss.beacon_interval = 100;
6432
6433 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6434 ibss.beacon_interval =
6435 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6436 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6437 return -EINVAL;
6438 }
6439
Johannes Berg4c476992010-10-04 21:36:35 +02006440 if (!rdev->ops->join_ibss)
6441 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006442
Johannes Berg4c476992010-10-04 21:36:35 +02006443 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6444 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006445
Johannes Berg79c97e92009-07-07 03:56:12 +02006446 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006447
Johannes Berg39193492011-09-16 13:45:25 +02006448 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006449 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006450
6451 if (!is_valid_ether_addr(ibss.bssid))
6452 return -EINVAL;
6453 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006454 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6455 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6456
6457 if (info->attrs[NL80211_ATTR_IE]) {
6458 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6459 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6460 }
6461
Johannes Berg683b6d32012-11-08 21:25:48 +01006462 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6463 if (err)
6464 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006465
Johannes Berg683b6d32012-11-08 21:25:48 +01006466 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006467 return -EINVAL;
6468
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006469 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006470 case NL80211_CHAN_WIDTH_5:
6471 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006472 case NL80211_CHAN_WIDTH_20_NOHT:
6473 break;
6474 case NL80211_CHAN_WIDTH_20:
6475 case NL80211_CHAN_WIDTH_40:
6476 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6477 break;
6478 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006479 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006480 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006481
Johannes Berg04a773a2009-04-19 21:24:32 +02006482 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006483 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006484
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006485 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6486 u8 *rates =
6487 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6488 int n_rates =
6489 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6490 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006491 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006492
Johannes Berg34850ab2011-07-18 18:08:35 +02006493 err = ieee80211_get_ratemask(sband, rates, n_rates,
6494 &ibss.basic_rates);
6495 if (err)
6496 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006497 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006498
Simon Wunderlich803768f2013-06-28 10:39:58 +02006499 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6500 memcpy(&ibss.ht_capa_mask,
6501 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6502 sizeof(ibss.ht_capa_mask));
6503
6504 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6505 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6506 return -EINVAL;
6507 memcpy(&ibss.ht_capa,
6508 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6509 sizeof(ibss.ht_capa));
6510 }
6511
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006512 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6513 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6514 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6515 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006516
Johannes Berg4c476992010-10-04 21:36:35 +02006517 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306518 bool no_ht = false;
6519
Johannes Berg4c476992010-10-04 21:36:35 +02006520 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306521 info->attrs[NL80211_ATTR_KEYS],
6522 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006523 if (IS_ERR(connkeys))
6524 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306525
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006526 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6527 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306528 kfree(connkeys);
6529 return -EINVAL;
6530 }
Johannes Berg4c476992010-10-04 21:36:35 +02006531 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006532
Antonio Quartulli267335d2012-01-31 20:25:47 +01006533 ibss.control_port =
6534 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6535
Johannes Berg4c476992010-10-04 21:36:35 +02006536 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006537 if (err)
6538 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006539 return err;
6540}
6541
6542static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6543{
Johannes Berg4c476992010-10-04 21:36:35 +02006544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6545 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006546
Johannes Berg4c476992010-10-04 21:36:35 +02006547 if (!rdev->ops->leave_ibss)
6548 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006549
Johannes Berg4c476992010-10-04 21:36:35 +02006550 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6551 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006552
Johannes Berg4c476992010-10-04 21:36:35 +02006553 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006554}
6555
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006556static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6557{
6558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6559 struct net_device *dev = info->user_ptr[1];
6560 int mcast_rate[IEEE80211_NUM_BANDS];
6561 u32 nla_rate;
6562 int err;
6563
6564 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6565 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6566 return -EOPNOTSUPP;
6567
6568 if (!rdev->ops->set_mcast_rate)
6569 return -EOPNOTSUPP;
6570
6571 memset(mcast_rate, 0, sizeof(mcast_rate));
6572
6573 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6574 return -EINVAL;
6575
6576 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6577 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6578 return -EINVAL;
6579
6580 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6581
6582 return err;
6583}
6584
6585
Johannes Bergaff89a92009-07-01 21:26:51 +02006586#ifdef CONFIG_NL80211_TESTMODE
6587static struct genl_multicast_group nl80211_testmode_mcgrp = {
6588 .name = "testmode",
6589};
6590
6591static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6592{
Johannes Berg4c476992010-10-04 21:36:35 +02006593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006594 int err;
6595
6596 if (!info->attrs[NL80211_ATTR_TESTDATA])
6597 return -EINVAL;
6598
Johannes Bergaff89a92009-07-01 21:26:51 +02006599 err = -EOPNOTSUPP;
6600 if (rdev->ops->testmode_cmd) {
6601 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006602 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006603 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6604 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6605 rdev->testmode_info = NULL;
6606 }
6607
Johannes Bergaff89a92009-07-01 21:26:51 +02006608 return err;
6609}
6610
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006611static int nl80211_testmode_dump(struct sk_buff *skb,
6612 struct netlink_callback *cb)
6613{
Johannes Berg00918d32011-12-13 17:22:05 +01006614 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006615 int err;
6616 long phy_idx;
6617 void *data = NULL;
6618 int data_len = 0;
6619
Johannes Berg5fe231e2013-05-08 21:45:15 +02006620 rtnl_lock();
6621
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006622 if (cb->args[0]) {
6623 /*
6624 * 0 is a valid index, but not valid for args[0],
6625 * so we need to offset by 1.
6626 */
6627 phy_idx = cb->args[0] - 1;
6628 } else {
6629 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6630 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6631 nl80211_policy);
6632 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006633 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006634
Johannes Berg2bd7e352012-06-15 14:23:16 +02006635 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6636 nl80211_fam.attrbuf);
6637 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006638 err = PTR_ERR(rdev);
6639 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006640 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006641 phy_idx = rdev->wiphy_idx;
6642 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006643
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006644 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6645 cb->args[1] =
6646 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6647 }
6648
6649 if (cb->args[1]) {
6650 data = nla_data((void *)cb->args[1]);
6651 data_len = nla_len((void *)cb->args[1]);
6652 }
6653
Johannes Berg00918d32011-12-13 17:22:05 +01006654 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6655 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006656 err = -ENOENT;
6657 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006658 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006659
Johannes Berg00918d32011-12-13 17:22:05 +01006660 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006661 err = -EOPNOTSUPP;
6662 goto out_err;
6663 }
6664
6665 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006666 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006667 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6668 NL80211_CMD_TESTMODE);
6669 struct nlattr *tmdata;
6670
David S. Miller9360ffd2012-03-29 04:41:26 -04006671 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006672 genlmsg_cancel(skb, hdr);
6673 break;
6674 }
6675
6676 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6677 if (!tmdata) {
6678 genlmsg_cancel(skb, hdr);
6679 break;
6680 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006681 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006682 nla_nest_end(skb, tmdata);
6683
6684 if (err == -ENOBUFS || err == -ENOENT) {
6685 genlmsg_cancel(skb, hdr);
6686 break;
6687 } else if (err) {
6688 genlmsg_cancel(skb, hdr);
6689 goto out_err;
6690 }
6691
6692 genlmsg_end(skb, hdr);
6693 }
6694
6695 err = skb->len;
6696 /* see above */
6697 cb->args[0] = phy_idx + 1;
6698 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006699 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006700 return err;
6701}
6702
Johannes Bergaff89a92009-07-01 21:26:51 +02006703static struct sk_buff *
6704__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006705 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006706{
6707 struct sk_buff *skb;
6708 void *hdr;
6709 struct nlattr *data;
6710
6711 skb = nlmsg_new(approxlen + 100, gfp);
6712 if (!skb)
6713 return NULL;
6714
Eric W. Biederman15e47302012-09-07 20:12:54 +00006715 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006716 if (!hdr) {
6717 kfree_skb(skb);
6718 return NULL;
6719 }
6720
David S. Miller9360ffd2012-03-29 04:41:26 -04006721 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6722 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006723 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6724
6725 ((void **)skb->cb)[0] = rdev;
6726 ((void **)skb->cb)[1] = hdr;
6727 ((void **)skb->cb)[2] = data;
6728
6729 return skb;
6730
6731 nla_put_failure:
6732 kfree_skb(skb);
6733 return NULL;
6734}
6735
6736struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6737 int approxlen)
6738{
6739 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6740
6741 if (WARN_ON(!rdev->testmode_info))
6742 return NULL;
6743
6744 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006745 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006746 rdev->testmode_info->snd_seq,
6747 GFP_KERNEL);
6748}
6749EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6750
6751int cfg80211_testmode_reply(struct sk_buff *skb)
6752{
6753 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6754 void *hdr = ((void **)skb->cb)[1];
6755 struct nlattr *data = ((void **)skb->cb)[2];
6756
6757 if (WARN_ON(!rdev->testmode_info)) {
6758 kfree_skb(skb);
6759 return -EINVAL;
6760 }
6761
6762 nla_nest_end(skb, data);
6763 genlmsg_end(skb, hdr);
6764 return genlmsg_reply(skb, rdev->testmode_info);
6765}
6766EXPORT_SYMBOL(cfg80211_testmode_reply);
6767
6768struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6769 int approxlen, gfp_t gfp)
6770{
6771 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6772
6773 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6774}
6775EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6776
6777void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6778{
6779 void *hdr = ((void **)skb->cb)[1];
6780 struct nlattr *data = ((void **)skb->cb)[2];
6781
6782 nla_nest_end(skb, data);
6783 genlmsg_end(skb, hdr);
6784 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6785}
6786EXPORT_SYMBOL(cfg80211_testmode_event);
6787#endif
6788
Samuel Ortizb23aa672009-07-01 21:26:54 +02006789static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6790{
Johannes Berg4c476992010-10-04 21:36:35 +02006791 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6792 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006793 struct cfg80211_connect_params connect;
6794 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006795 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006796 int err;
6797
6798 memset(&connect, 0, sizeof(connect));
6799
6800 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6801 return -EINVAL;
6802
6803 if (!info->attrs[NL80211_ATTR_SSID] ||
6804 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6805 return -EINVAL;
6806
6807 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6808 connect.auth_type =
6809 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006810 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6811 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006812 return -EINVAL;
6813 } else
6814 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6815
6816 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6817
Johannes Bergc0692b82010-08-27 14:26:53 +03006818 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006819 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006820 if (err)
6821 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006822
Johannes Berg074ac8d2010-09-16 14:58:22 +02006823 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006824 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6825 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006826
Johannes Berg79c97e92009-07-07 03:56:12 +02006827 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006828
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306829 connect.bg_scan_period = -1;
6830 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6831 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6832 connect.bg_scan_period =
6833 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6834 }
6835
Samuel Ortizb23aa672009-07-01 21:26:54 +02006836 if (info->attrs[NL80211_ATTR_MAC])
6837 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6838 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6839 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6840
6841 if (info->attrs[NL80211_ATTR_IE]) {
6842 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6843 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6844 }
6845
Jouni Malinencee00a92013-01-15 17:15:57 +02006846 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6847 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6848 if (connect.mfp != NL80211_MFP_REQUIRED &&
6849 connect.mfp != NL80211_MFP_NO)
6850 return -EINVAL;
6851 } else {
6852 connect.mfp = NL80211_MFP_NO;
6853 }
6854
Samuel Ortizb23aa672009-07-01 21:26:54 +02006855 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6856 connect.channel =
6857 ieee80211_get_channel(wiphy,
6858 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6859 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006860 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6861 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006862 }
6863
Johannes Bergfffd0932009-07-08 14:22:54 +02006864 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6865 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306866 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006867 if (IS_ERR(connkeys))
6868 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006869 }
6870
Ben Greear7e7c8922011-11-18 11:31:59 -08006871 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6872 connect.flags |= ASSOC_REQ_DISABLE_HT;
6873
6874 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6875 memcpy(&connect.ht_capa_mask,
6876 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6877 sizeof(connect.ht_capa_mask));
6878
6879 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006880 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6881 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006882 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006883 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006884 memcpy(&connect.ht_capa,
6885 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6886 sizeof(connect.ht_capa));
6887 }
6888
Johannes Bergee2aca32013-02-21 17:36:01 +01006889 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6890 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6891
6892 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6893 memcpy(&connect.vht_capa_mask,
6894 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6895 sizeof(connect.vht_capa_mask));
6896
6897 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6898 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6899 kfree(connkeys);
6900 return -EINVAL;
6901 }
6902 memcpy(&connect.vht_capa,
6903 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6904 sizeof(connect.vht_capa));
6905 }
6906
Johannes Berg83739b02013-05-15 17:44:01 +02006907 wdev_lock(dev->ieee80211_ptr);
6908 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6909 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006910 if (err)
6911 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006912 return err;
6913}
6914
6915static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6916{
Johannes Berg4c476992010-10-04 21:36:35 +02006917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6918 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006919 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006920 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006921
6922 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6923 reason = WLAN_REASON_DEAUTH_LEAVING;
6924 else
6925 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6926
6927 if (reason == 0)
6928 return -EINVAL;
6929
Johannes Berg074ac8d2010-09-16 14:58:22 +02006930 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006931 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6932 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006933
Johannes Berg83739b02013-05-15 17:44:01 +02006934 wdev_lock(dev->ieee80211_ptr);
6935 ret = cfg80211_disconnect(rdev, dev, reason, true);
6936 wdev_unlock(dev->ieee80211_ptr);
6937 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006938}
6939
Johannes Berg463d0182009-07-14 00:33:35 +02006940static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6941{
Johannes Berg4c476992010-10-04 21:36:35 +02006942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006943 struct net *net;
6944 int err;
6945 u32 pid;
6946
6947 if (!info->attrs[NL80211_ATTR_PID])
6948 return -EINVAL;
6949
6950 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6951
Johannes Berg463d0182009-07-14 00:33:35 +02006952 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006953 if (IS_ERR(net))
6954 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006955
6956 err = 0;
6957
6958 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006959 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6960 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006961
Johannes Berg463d0182009-07-14 00:33:35 +02006962 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006963 return err;
6964}
6965
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006966static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6967{
Johannes Berg4c476992010-10-04 21:36:35 +02006968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006969 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6970 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006971 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006972 struct cfg80211_pmksa pmksa;
6973
6974 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6975
6976 if (!info->attrs[NL80211_ATTR_MAC])
6977 return -EINVAL;
6978
6979 if (!info->attrs[NL80211_ATTR_PMKID])
6980 return -EINVAL;
6981
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006982 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6983 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6984
Johannes Berg074ac8d2010-09-16 14:58:22 +02006985 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006986 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6987 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006988
6989 switch (info->genlhdr->cmd) {
6990 case NL80211_CMD_SET_PMKSA:
6991 rdev_ops = rdev->ops->set_pmksa;
6992 break;
6993 case NL80211_CMD_DEL_PMKSA:
6994 rdev_ops = rdev->ops->del_pmksa;
6995 break;
6996 default:
6997 WARN_ON(1);
6998 break;
6999 }
7000
Johannes Berg4c476992010-10-04 21:36:35 +02007001 if (!rdev_ops)
7002 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007003
Johannes Berg4c476992010-10-04 21:36:35 +02007004 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007005}
7006
7007static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7008{
Johannes Berg4c476992010-10-04 21:36:35 +02007009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7010 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007011
Johannes Berg074ac8d2010-09-16 14:58:22 +02007012 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007013 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7014 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007015
Johannes Berg4c476992010-10-04 21:36:35 +02007016 if (!rdev->ops->flush_pmksa)
7017 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007018
Hila Gonene35e4d22012-06-27 17:19:42 +03007019 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007020}
7021
Arik Nemtsov109086c2011-09-28 14:12:50 +03007022static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7023{
7024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7025 struct net_device *dev = info->user_ptr[1];
7026 u8 action_code, dialog_token;
7027 u16 status_code;
7028 u8 *peer;
7029
7030 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7031 !rdev->ops->tdls_mgmt)
7032 return -EOPNOTSUPP;
7033
7034 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7035 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7036 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7037 !info->attrs[NL80211_ATTR_IE] ||
7038 !info->attrs[NL80211_ATTR_MAC])
7039 return -EINVAL;
7040
7041 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7042 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7043 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7044 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7045
Hila Gonene35e4d22012-06-27 17:19:42 +03007046 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7047 dialog_token, status_code,
7048 nla_data(info->attrs[NL80211_ATTR_IE]),
7049 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007050}
7051
7052static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7053{
7054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7055 struct net_device *dev = info->user_ptr[1];
7056 enum nl80211_tdls_operation operation;
7057 u8 *peer;
7058
7059 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7060 !rdev->ops->tdls_oper)
7061 return -EOPNOTSUPP;
7062
7063 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7064 !info->attrs[NL80211_ATTR_MAC])
7065 return -EINVAL;
7066
7067 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7068 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7069
Hila Gonene35e4d22012-06-27 17:19:42 +03007070 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007071}
7072
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007073static int nl80211_remain_on_channel(struct sk_buff *skb,
7074 struct genl_info *info)
7075{
Johannes Berg4c476992010-10-04 21:36:35 +02007076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007077 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007078 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007079 struct sk_buff *msg;
7080 void *hdr;
7081 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007082 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007083 int err;
7084
7085 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7086 !info->attrs[NL80211_ATTR_DURATION])
7087 return -EINVAL;
7088
7089 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7090
Johannes Berg7c4ef712011-11-18 15:33:48 +01007091 if (!rdev->ops->remain_on_channel ||
7092 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007093 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007094
Johannes Bergebf348f2012-06-01 12:50:54 +02007095 /*
7096 * We should be on that channel for at least a minimum amount of
7097 * time (10ms) but no longer than the driver supports.
7098 */
7099 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7100 duration > rdev->wiphy.max_remain_on_channel_duration)
7101 return -EINVAL;
7102
Johannes Berg683b6d32012-11-08 21:25:48 +01007103 err = nl80211_parse_chandef(rdev, info, &chandef);
7104 if (err)
7105 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007106
7107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007108 if (!msg)
7109 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007110
Eric W. Biederman15e47302012-09-07 20:12:54 +00007111 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007112 NL80211_CMD_REMAIN_ON_CHANNEL);
7113
7114 if (IS_ERR(hdr)) {
7115 err = PTR_ERR(hdr);
7116 goto free_msg;
7117 }
7118
Johannes Berg683b6d32012-11-08 21:25:48 +01007119 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7120 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007121
7122 if (err)
7123 goto free_msg;
7124
David S. Miller9360ffd2012-03-29 04:41:26 -04007125 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7126 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007127
7128 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007129
7130 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007131
7132 nla_put_failure:
7133 err = -ENOBUFS;
7134 free_msg:
7135 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007136 return err;
7137}
7138
7139static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7140 struct genl_info *info)
7141{
Johannes Berg4c476992010-10-04 21:36:35 +02007142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007143 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007144 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007145
7146 if (!info->attrs[NL80211_ATTR_COOKIE])
7147 return -EINVAL;
7148
Johannes Berg4c476992010-10-04 21:36:35 +02007149 if (!rdev->ops->cancel_remain_on_channel)
7150 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007151
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007152 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7153
Hila Gonene35e4d22012-06-27 17:19:42 +03007154 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007155}
7156
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007157static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7158 u8 *rates, u8 rates_len)
7159{
7160 u8 i;
7161 u32 mask = 0;
7162
7163 for (i = 0; i < rates_len; i++) {
7164 int rate = (rates[i] & 0x7f) * 5;
7165 int ridx;
7166 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7167 struct ieee80211_rate *srate =
7168 &sband->bitrates[ridx];
7169 if (rate == srate->bitrate) {
7170 mask |= 1 << ridx;
7171 break;
7172 }
7173 }
7174 if (ridx == sband->n_bitrates)
7175 return 0; /* rate not found */
7176 }
7177
7178 return mask;
7179}
7180
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007181static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7182 u8 *rates, u8 rates_len,
7183 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7184{
7185 u8 i;
7186
7187 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7188
7189 for (i = 0; i < rates_len; i++) {
7190 int ridx, rbit;
7191
7192 ridx = rates[i] / 8;
7193 rbit = BIT(rates[i] % 8);
7194
7195 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007196 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007197 return false;
7198
7199 /* check availability */
7200 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7201 mcs[ridx] |= rbit;
7202 else
7203 return false;
7204 }
7205
7206 return true;
7207}
7208
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007209static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007210 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7211 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007212 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7213 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007214};
7215
7216static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7217 struct genl_info *info)
7218{
7219 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007221 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007222 int rem, i;
7223 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007224 struct nlattr *tx_rates;
7225 struct ieee80211_supported_band *sband;
7226
7227 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7228 return -EINVAL;
7229
Johannes Berg4c476992010-10-04 21:36:35 +02007230 if (!rdev->ops->set_bitrate_mask)
7231 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007232
7233 memset(&mask, 0, sizeof(mask));
7234 /* Default to all rates enabled */
7235 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7236 sband = rdev->wiphy.bands[i];
7237 mask.control[i].legacy =
7238 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007239 if (sband)
7240 memcpy(mask.control[i].mcs,
7241 sband->ht_cap.mcs.rx_mask,
7242 sizeof(mask.control[i].mcs));
7243 else
7244 memset(mask.control[i].mcs, 0,
7245 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007246 }
7247
7248 /*
7249 * The nested attribute uses enum nl80211_band as the index. This maps
7250 * directly to the enum ieee80211_band values used in cfg80211.
7251 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007252 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007253 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7254 {
7255 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007256 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7257 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007258 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007259 if (sband == NULL)
7260 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007261 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7262 nla_len(tx_rates), nl80211_txattr_policy);
7263 if (tb[NL80211_TXRATE_LEGACY]) {
7264 mask.control[band].legacy = rateset_to_mask(
7265 sband,
7266 nla_data(tb[NL80211_TXRATE_LEGACY]),
7267 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307268 if ((mask.control[band].legacy == 0) &&
7269 nla_len(tb[NL80211_TXRATE_LEGACY]))
7270 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007271 }
7272 if (tb[NL80211_TXRATE_MCS]) {
7273 if (!ht_rateset_to_mask(
7274 sband,
7275 nla_data(tb[NL80211_TXRATE_MCS]),
7276 nla_len(tb[NL80211_TXRATE_MCS]),
7277 mask.control[band].mcs))
7278 return -EINVAL;
7279 }
7280
7281 if (mask.control[band].legacy == 0) {
7282 /* don't allow empty legacy rates if HT
7283 * is not even supported. */
7284 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7285 return -EINVAL;
7286
7287 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7288 if (mask.control[band].mcs[i])
7289 break;
7290
7291 /* legacy and mcs rates may not be both empty */
7292 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007293 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007294 }
7295 }
7296
Hila Gonene35e4d22012-06-27 17:19:42 +03007297 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007298}
7299
Johannes Berg2e161f72010-08-12 15:38:38 +02007300static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007301{
Johannes Berg4c476992010-10-04 21:36:35 +02007302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007303 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007304 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007305
7306 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7307 return -EINVAL;
7308
Johannes Berg2e161f72010-08-12 15:38:38 +02007309 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7310 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007311
Johannes Berg71bbc992012-06-15 15:30:18 +02007312 switch (wdev->iftype) {
7313 case NL80211_IFTYPE_STATION:
7314 case NL80211_IFTYPE_ADHOC:
7315 case NL80211_IFTYPE_P2P_CLIENT:
7316 case NL80211_IFTYPE_AP:
7317 case NL80211_IFTYPE_AP_VLAN:
7318 case NL80211_IFTYPE_MESH_POINT:
7319 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007320 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007321 break;
7322 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007323 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007324 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007325
7326 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007327 if (!rdev->ops->mgmt_tx)
7328 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007329
Eric W. Biederman15e47302012-09-07 20:12:54 +00007330 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007331 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7332 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007333}
7334
Johannes Berg2e161f72010-08-12 15:38:38 +02007335static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007336{
Johannes Berg4c476992010-10-04 21:36:35 +02007337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007338 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007339 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007340 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007341 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007342 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007343 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007344 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007345 bool offchan, no_cck, dont_wait_for_ack;
7346
7347 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007348
Johannes Berg683b6d32012-11-08 21:25:48 +01007349 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007350 return -EINVAL;
7351
Johannes Berg4c476992010-10-04 21:36:35 +02007352 if (!rdev->ops->mgmt_tx)
7353 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007354
Johannes Berg71bbc992012-06-15 15:30:18 +02007355 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007356 case NL80211_IFTYPE_P2P_DEVICE:
7357 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7358 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007359 case NL80211_IFTYPE_STATION:
7360 case NL80211_IFTYPE_ADHOC:
7361 case NL80211_IFTYPE_P2P_CLIENT:
7362 case NL80211_IFTYPE_AP:
7363 case NL80211_IFTYPE_AP_VLAN:
7364 case NL80211_IFTYPE_MESH_POINT:
7365 case NL80211_IFTYPE_P2P_GO:
7366 break;
7367 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007368 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007369 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007370
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007371 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007372 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007373 return -EINVAL;
7374 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007375
7376 /*
7377 * We should wait on the channel for at least a minimum amount
7378 * of time (10ms) but no longer than the driver supports.
7379 */
7380 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7381 wait > rdev->wiphy.max_remain_on_channel_duration)
7382 return -EINVAL;
7383
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007384 }
7385
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007386 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7387
Johannes Berg7c4ef712011-11-18 15:33:48 +01007388 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7389 return -EINVAL;
7390
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307391 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7392
Antonio Quartulliea141b752013-06-11 14:20:03 +02007393 /* get the channel if any has been specified, otherwise pass NULL to
7394 * the driver. The latter will use the current one
7395 */
7396 chandef.chan = NULL;
7397 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7398 err = nl80211_parse_chandef(rdev, info, &chandef);
7399 if (err)
7400 return err;
7401 }
7402
7403 if (!chandef.chan && offchan)
7404 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007405
Johannes Berge247bd902011-11-04 11:18:21 +01007406 if (!dont_wait_for_ack) {
7407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7408 if (!msg)
7409 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007410
Eric W. Biederman15e47302012-09-07 20:12:54 +00007411 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007412 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007413
Johannes Berge247bd902011-11-04 11:18:21 +01007414 if (IS_ERR(hdr)) {
7415 err = PTR_ERR(hdr);
7416 goto free_msg;
7417 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007418 }
Johannes Berge247bd902011-11-04 11:18:21 +01007419
Johannes Berg683b6d32012-11-08 21:25:48 +01007420 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007421 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7422 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007423 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007424 if (err)
7425 goto free_msg;
7426
Johannes Berge247bd902011-11-04 11:18:21 +01007427 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007428 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7429 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007430
Johannes Berge247bd902011-11-04 11:18:21 +01007431 genlmsg_end(msg, hdr);
7432 return genlmsg_reply(msg, info);
7433 }
7434
7435 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007436
7437 nla_put_failure:
7438 err = -ENOBUFS;
7439 free_msg:
7440 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007441 return err;
7442}
7443
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007444static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7445{
7446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007447 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007448 u64 cookie;
7449
7450 if (!info->attrs[NL80211_ATTR_COOKIE])
7451 return -EINVAL;
7452
7453 if (!rdev->ops->mgmt_tx_cancel_wait)
7454 return -EOPNOTSUPP;
7455
Johannes Berg71bbc992012-06-15 15:30:18 +02007456 switch (wdev->iftype) {
7457 case NL80211_IFTYPE_STATION:
7458 case NL80211_IFTYPE_ADHOC:
7459 case NL80211_IFTYPE_P2P_CLIENT:
7460 case NL80211_IFTYPE_AP:
7461 case NL80211_IFTYPE_AP_VLAN:
7462 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007463 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007464 break;
7465 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007466 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007467 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007468
7469 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7470
Hila Gonene35e4d22012-06-27 17:19:42 +03007471 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007472}
7473
Kalle Valoffb9eb32010-02-17 17:58:10 +02007474static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7475{
Johannes Berg4c476992010-10-04 21:36:35 +02007476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007477 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007478 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007479 u8 ps_state;
7480 bool state;
7481 int err;
7482
Johannes Berg4c476992010-10-04 21:36:35 +02007483 if (!info->attrs[NL80211_ATTR_PS_STATE])
7484 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007485
7486 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7487
Johannes Berg4c476992010-10-04 21:36:35 +02007488 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7489 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007490
7491 wdev = dev->ieee80211_ptr;
7492
Johannes Berg4c476992010-10-04 21:36:35 +02007493 if (!rdev->ops->set_power_mgmt)
7494 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007495
7496 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7497
7498 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007499 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007500
Hila Gonene35e4d22012-06-27 17:19:42 +03007501 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007502 if (!err)
7503 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007504 return err;
7505}
7506
7507static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7508{
Johannes Berg4c476992010-10-04 21:36:35 +02007509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007510 enum nl80211_ps_state ps_state;
7511 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007512 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007513 struct sk_buff *msg;
7514 void *hdr;
7515 int err;
7516
Kalle Valoffb9eb32010-02-17 17:58:10 +02007517 wdev = dev->ieee80211_ptr;
7518
Johannes Berg4c476992010-10-04 21:36:35 +02007519 if (!rdev->ops->set_power_mgmt)
7520 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007521
7522 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007523 if (!msg)
7524 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007525
Eric W. Biederman15e47302012-09-07 20:12:54 +00007526 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007527 NL80211_CMD_GET_POWER_SAVE);
7528 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007529 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007530 goto free_msg;
7531 }
7532
7533 if (wdev->ps)
7534 ps_state = NL80211_PS_ENABLED;
7535 else
7536 ps_state = NL80211_PS_DISABLED;
7537
David S. Miller9360ffd2012-03-29 04:41:26 -04007538 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7539 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007540
7541 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007542 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007543
Johannes Berg4c476992010-10-04 21:36:35 +02007544 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007545 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007546 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007547 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007548 return err;
7549}
7550
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007551static struct nla_policy
7552nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7553 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7554 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7555 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007556 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7557 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7558 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007559};
7560
Thomas Pedersen84f10702012-07-12 16:17:33 -07007561static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007562 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007563{
7564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7565 struct wireless_dev *wdev;
7566 struct net_device *dev = info->user_ptr[1];
7567
Johannes Bergd9d8b012012-11-26 12:51:52 +01007568 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007569 return -EINVAL;
7570
7571 wdev = dev->ieee80211_ptr;
7572
7573 if (!rdev->ops->set_cqm_txe_config)
7574 return -EOPNOTSUPP;
7575
7576 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7577 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7578 return -EOPNOTSUPP;
7579
Hila Gonene35e4d22012-06-27 17:19:42 +03007580 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007581}
7582
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007583static int nl80211_set_cqm_rssi(struct genl_info *info,
7584 s32 threshold, u32 hysteresis)
7585{
Johannes Berg4c476992010-10-04 21:36:35 +02007586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007587 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007588 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007589
7590 if (threshold > 0)
7591 return -EINVAL;
7592
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007593 wdev = dev->ieee80211_ptr;
7594
Johannes Berg4c476992010-10-04 21:36:35 +02007595 if (!rdev->ops->set_cqm_rssi_config)
7596 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007597
Johannes Berg074ac8d2010-09-16 14:58:22 +02007598 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007599 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7600 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007601
Hila Gonene35e4d22012-06-27 17:19:42 +03007602 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007603}
7604
7605static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7606{
7607 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7608 struct nlattr *cqm;
7609 int err;
7610
7611 cqm = info->attrs[NL80211_ATTR_CQM];
7612 if (!cqm) {
7613 err = -EINVAL;
7614 goto out;
7615 }
7616
7617 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7618 nl80211_attr_cqm_policy);
7619 if (err)
7620 goto out;
7621
7622 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7623 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7624 s32 threshold;
7625 u32 hysteresis;
7626 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7627 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7628 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007629 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7630 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7631 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7632 u32 rate, pkts, intvl;
7633 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7634 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7635 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7636 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007637 } else
7638 err = -EINVAL;
7639
7640out:
7641 return err;
7642}
7643
Johannes Berg29cbe682010-12-03 09:20:44 +01007644static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7645{
7646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7647 struct net_device *dev = info->user_ptr[1];
7648 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007649 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007650 int err;
7651
7652 /* start with default */
7653 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007654 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007655
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007656 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007657 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007658 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007659 if (err)
7660 return err;
7661 }
7662
7663 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7664 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7665 return -EINVAL;
7666
Javier Cardonac80d5452010-12-16 17:37:49 -08007667 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7668 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7669
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007670 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7671 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7672 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7673 return -EINVAL;
7674
Marco Porsch9bdbf042013-01-07 16:04:51 +01007675 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7676 setup.beacon_interval =
7677 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7678 if (setup.beacon_interval < 10 ||
7679 setup.beacon_interval > 10000)
7680 return -EINVAL;
7681 }
7682
7683 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7684 setup.dtim_period =
7685 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7686 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7687 return -EINVAL;
7688 }
7689
Javier Cardonac80d5452010-12-16 17:37:49 -08007690 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7691 /* parse additional setup parameters if given */
7692 err = nl80211_parse_mesh_setup(info, &setup);
7693 if (err)
7694 return err;
7695 }
7696
Thomas Pedersend37bb182013-03-04 13:06:13 -08007697 if (setup.user_mpm)
7698 cfg.auto_open_plinks = false;
7699
Johannes Bergcc1d2802012-05-16 23:50:20 +02007700 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007701 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7702 if (err)
7703 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007704 } else {
7705 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007706 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007707 }
7708
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007709 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7710 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7711 int n_rates =
7712 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7713 struct ieee80211_supported_band *sband;
7714
7715 if (!setup.chandef.chan)
7716 return -EINVAL;
7717
7718 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7719
7720 err = ieee80211_get_ratemask(sband, rates, n_rates,
7721 &setup.basic_rates);
7722 if (err)
7723 return err;
7724 }
7725
Javier Cardonac80d5452010-12-16 17:37:49 -08007726 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007727}
7728
7729static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7730{
7731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7732 struct net_device *dev = info->user_ptr[1];
7733
7734 return cfg80211_leave_mesh(rdev, dev);
7735}
7736
Johannes Bergdfb89c52012-06-27 09:23:48 +02007737#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007738static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7739 struct cfg80211_registered_device *rdev)
7740{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007741 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007742 struct nlattr *nl_pats, *nl_pat;
7743 int i, pat_len;
7744
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007745 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007746 return 0;
7747
7748 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7749 if (!nl_pats)
7750 return -ENOBUFS;
7751
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007752 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007753 nl_pat = nla_nest_start(msg, i + 1);
7754 if (!nl_pat)
7755 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007756 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007757 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007758 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007759 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7760 wowlan->patterns[i].pattern) ||
7761 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007762 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007763 return -ENOBUFS;
7764 nla_nest_end(msg, nl_pat);
7765 }
7766 nla_nest_end(msg, nl_pats);
7767
7768 return 0;
7769}
7770
Johannes Berg2a0e0472013-01-23 22:57:40 +01007771static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7772 struct cfg80211_wowlan_tcp *tcp)
7773{
7774 struct nlattr *nl_tcp;
7775
7776 if (!tcp)
7777 return 0;
7778
7779 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7780 if (!nl_tcp)
7781 return -ENOBUFS;
7782
7783 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7784 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7785 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7786 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7787 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7788 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7789 tcp->payload_len, tcp->payload) ||
7790 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7791 tcp->data_interval) ||
7792 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7793 tcp->wake_len, tcp->wake_data) ||
7794 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7795 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7796 return -ENOBUFS;
7797
7798 if (tcp->payload_seq.len &&
7799 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7800 sizeof(tcp->payload_seq), &tcp->payload_seq))
7801 return -ENOBUFS;
7802
7803 if (tcp->payload_tok.len &&
7804 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7805 sizeof(tcp->payload_tok) + tcp->tokens_size,
7806 &tcp->payload_tok))
7807 return -ENOBUFS;
7808
Johannes Berge248ad32013-05-16 10:24:28 +02007809 nla_nest_end(msg, nl_tcp);
7810
Johannes Berg2a0e0472013-01-23 22:57:40 +01007811 return 0;
7812}
7813
Johannes Bergff1b6e62011-05-04 15:37:28 +02007814static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7815{
7816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7817 struct sk_buff *msg;
7818 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007819 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007820
Johannes Berg964dc9e2013-06-03 17:25:34 +02007821 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007822 return -EOPNOTSUPP;
7823
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007824 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007825 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007826 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7827 rdev->wiphy.wowlan_config->tcp->payload_len +
7828 rdev->wiphy.wowlan_config->tcp->wake_len +
7829 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007830 }
7831
7832 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007833 if (!msg)
7834 return -ENOMEM;
7835
Eric W. Biederman15e47302012-09-07 20:12:54 +00007836 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007837 NL80211_CMD_GET_WOWLAN);
7838 if (!hdr)
7839 goto nla_put_failure;
7840
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007841 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007842 struct nlattr *nl_wowlan;
7843
7844 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7845 if (!nl_wowlan)
7846 goto nla_put_failure;
7847
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007848 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007849 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007850 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007851 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007852 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007853 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007854 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007855 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007856 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007857 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007858 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007859 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007860 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007861 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7862 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007863
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007864 if (nl80211_send_wowlan_patterns(msg, rdev))
7865 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007866
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007867 if (nl80211_send_wowlan_tcp(msg,
7868 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007869 goto nla_put_failure;
7870
Johannes Bergff1b6e62011-05-04 15:37:28 +02007871 nla_nest_end(msg, nl_wowlan);
7872 }
7873
7874 genlmsg_end(msg, hdr);
7875 return genlmsg_reply(msg, info);
7876
7877nla_put_failure:
7878 nlmsg_free(msg);
7879 return -ENOBUFS;
7880}
7881
Johannes Berg2a0e0472013-01-23 22:57:40 +01007882static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7883 struct nlattr *attr,
7884 struct cfg80211_wowlan *trig)
7885{
7886 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7887 struct cfg80211_wowlan_tcp *cfg;
7888 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7889 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7890 u32 size;
7891 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7892 int err, port;
7893
Johannes Berg964dc9e2013-06-03 17:25:34 +02007894 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007895 return -EINVAL;
7896
7897 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7898 nla_data(attr), nla_len(attr),
7899 nl80211_wowlan_tcp_policy);
7900 if (err)
7901 return err;
7902
7903 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7904 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7905 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7906 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7907 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7908 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7909 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7910 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7911 return -EINVAL;
7912
7913 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007914 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007915 return -EINVAL;
7916
7917 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007918 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007919 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007920 return -EINVAL;
7921
7922 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007923 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007924 return -EINVAL;
7925
7926 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7927 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7928 return -EINVAL;
7929
7930 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7931 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7932
7933 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7934 tokens_size = tokln - sizeof(*tok);
7935
7936 if (!tok->len || tokens_size % tok->len)
7937 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007938 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007939 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007940 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007941 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007942 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007943 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007944 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007945 return -EINVAL;
7946 if (tok->offset + tok->len > data_size)
7947 return -EINVAL;
7948 }
7949
7950 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7951 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007952 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007953 return -EINVAL;
7954 if (seq->len == 0 || seq->len > 4)
7955 return -EINVAL;
7956 if (seq->len + seq->offset > data_size)
7957 return -EINVAL;
7958 }
7959
7960 size = sizeof(*cfg);
7961 size += data_size;
7962 size += wake_size + wake_mask_size;
7963 size += tokens_size;
7964
7965 cfg = kzalloc(size, GFP_KERNEL);
7966 if (!cfg)
7967 return -ENOMEM;
7968 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7969 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7970 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7971 ETH_ALEN);
7972 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7973 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7974 else
7975 port = 0;
7976#ifdef CONFIG_INET
7977 /* allocate a socket and port for it and use it */
7978 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7979 IPPROTO_TCP, &cfg->sock, 1);
7980 if (err) {
7981 kfree(cfg);
7982 return err;
7983 }
7984 if (inet_csk_get_port(cfg->sock->sk, port)) {
7985 sock_release(cfg->sock);
7986 kfree(cfg);
7987 return -EADDRINUSE;
7988 }
7989 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7990#else
7991 if (!port) {
7992 kfree(cfg);
7993 return -EINVAL;
7994 }
7995 cfg->src_port = port;
7996#endif
7997
7998 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7999 cfg->payload_len = data_size;
8000 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8001 memcpy((void *)cfg->payload,
8002 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8003 data_size);
8004 if (seq)
8005 cfg->payload_seq = *seq;
8006 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8007 cfg->wake_len = wake_size;
8008 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8009 memcpy((void *)cfg->wake_data,
8010 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8011 wake_size);
8012 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8013 data_size + wake_size;
8014 memcpy((void *)cfg->wake_mask,
8015 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8016 wake_mask_size);
8017 if (tok) {
8018 cfg->tokens_size = tokens_size;
8019 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8020 }
8021
8022 trig->tcp = cfg;
8023
8024 return 0;
8025}
8026
Johannes Bergff1b6e62011-05-04 15:37:28 +02008027static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8028{
8029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8030 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008031 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008032 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008033 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008034 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008035 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008036
Johannes Berg964dc9e2013-06-03 17:25:34 +02008037 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008038 return -EOPNOTSUPP;
8039
Johannes Bergae33bd82012-07-12 16:25:02 +02008040 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8041 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008042 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008043 goto set_wakeup;
8044 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008045
8046 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8047 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8048 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8049 nl80211_wowlan_policy);
8050 if (err)
8051 return err;
8052
8053 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8054 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8055 return -EINVAL;
8056 new_triggers.any = true;
8057 }
8058
8059 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8060 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8061 return -EINVAL;
8062 new_triggers.disconnect = true;
8063 }
8064
8065 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8066 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8067 return -EINVAL;
8068 new_triggers.magic_pkt = true;
8069 }
8070
Johannes Berg77dbbb12011-07-13 10:48:55 +02008071 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8072 return -EINVAL;
8073
8074 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8075 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8076 return -EINVAL;
8077 new_triggers.gtk_rekey_failure = true;
8078 }
8079
8080 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8081 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8082 return -EINVAL;
8083 new_triggers.eap_identity_req = true;
8084 }
8085
8086 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8087 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8088 return -EINVAL;
8089 new_triggers.four_way_handshake = true;
8090 }
8091
8092 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8093 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8094 return -EINVAL;
8095 new_triggers.rfkill_release = true;
8096 }
8097
Johannes Bergff1b6e62011-05-04 15:37:28 +02008098 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8099 struct nlattr *pat;
8100 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008101 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008102 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008103
8104 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8105 rem)
8106 n_patterns++;
8107 if (n_patterns > wowlan->n_patterns)
8108 return -EINVAL;
8109
8110 new_triggers.patterns = kcalloc(n_patterns,
8111 sizeof(new_triggers.patterns[0]),
8112 GFP_KERNEL);
8113 if (!new_triggers.patterns)
8114 return -ENOMEM;
8115
8116 new_triggers.n_patterns = n_patterns;
8117 i = 0;
8118
8119 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8120 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008121 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8122 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008123 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008124 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8125 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008126 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008127 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008128 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008129 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008130 goto error;
8131 if (pat_len > wowlan->pattern_max_len ||
8132 pat_len < wowlan->pattern_min_len)
8133 goto error;
8134
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008135 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008136 pkt_offset = 0;
8137 else
8138 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008139 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008140 if (pkt_offset > wowlan->max_pkt_offset)
8141 goto error;
8142 new_triggers.patterns[i].pkt_offset = pkt_offset;
8143
Johannes Bergff1b6e62011-05-04 15:37:28 +02008144 new_triggers.patterns[i].mask =
8145 kmalloc(mask_len + pat_len, GFP_KERNEL);
8146 if (!new_triggers.patterns[i].mask) {
8147 err = -ENOMEM;
8148 goto error;
8149 }
8150 new_triggers.patterns[i].pattern =
8151 new_triggers.patterns[i].mask + mask_len;
8152 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008153 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008154 mask_len);
8155 new_triggers.patterns[i].pattern_len = pat_len;
8156 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008157 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008158 pat_len);
8159 i++;
8160 }
8161 }
8162
Johannes Berg2a0e0472013-01-23 22:57:40 +01008163 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8164 err = nl80211_parse_wowlan_tcp(
8165 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8166 &new_triggers);
8167 if (err)
8168 goto error;
8169 }
8170
Johannes Bergae33bd82012-07-12 16:25:02 +02008171 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8172 if (!ntrig) {
8173 err = -ENOMEM;
8174 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008175 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008176 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008177 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008178
Johannes Bergae33bd82012-07-12 16:25:02 +02008179 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008180 if (rdev->ops->set_wakeup &&
8181 prev_enabled != !!rdev->wiphy.wowlan_config)
8182 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008183
Johannes Bergff1b6e62011-05-04 15:37:28 +02008184 return 0;
8185 error:
8186 for (i = 0; i < new_triggers.n_patterns; i++)
8187 kfree(new_triggers.patterns[i].mask);
8188 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008189 if (new_triggers.tcp && new_triggers.tcp->sock)
8190 sock_release(new_triggers.tcp->sock);
8191 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008192 return err;
8193}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008194#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008195
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008196static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8197 struct cfg80211_registered_device *rdev)
8198{
8199 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8200 int i, j, pat_len;
8201 struct cfg80211_coalesce_rules *rule;
8202
8203 if (!rdev->coalesce->n_rules)
8204 return 0;
8205
8206 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8207 if (!nl_rules)
8208 return -ENOBUFS;
8209
8210 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8211 nl_rule = nla_nest_start(msg, i + 1);
8212 if (!nl_rule)
8213 return -ENOBUFS;
8214
8215 rule = &rdev->coalesce->rules[i];
8216 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8217 rule->delay))
8218 return -ENOBUFS;
8219
8220 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8221 rule->condition))
8222 return -ENOBUFS;
8223
8224 nl_pats = nla_nest_start(msg,
8225 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8226 if (!nl_pats)
8227 return -ENOBUFS;
8228
8229 for (j = 0; j < rule->n_patterns; j++) {
8230 nl_pat = nla_nest_start(msg, j + 1);
8231 if (!nl_pat)
8232 return -ENOBUFS;
8233 pat_len = rule->patterns[j].pattern_len;
8234 if (nla_put(msg, NL80211_PKTPAT_MASK,
8235 DIV_ROUND_UP(pat_len, 8),
8236 rule->patterns[j].mask) ||
8237 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8238 rule->patterns[j].pattern) ||
8239 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8240 rule->patterns[j].pkt_offset))
8241 return -ENOBUFS;
8242 nla_nest_end(msg, nl_pat);
8243 }
8244 nla_nest_end(msg, nl_pats);
8245 nla_nest_end(msg, nl_rule);
8246 }
8247 nla_nest_end(msg, nl_rules);
8248
8249 return 0;
8250}
8251
8252static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8253{
8254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8255 struct sk_buff *msg;
8256 void *hdr;
8257
8258 if (!rdev->wiphy.coalesce)
8259 return -EOPNOTSUPP;
8260
8261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8262 if (!msg)
8263 return -ENOMEM;
8264
8265 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8266 NL80211_CMD_GET_COALESCE);
8267 if (!hdr)
8268 goto nla_put_failure;
8269
8270 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8271 goto nla_put_failure;
8272
8273 genlmsg_end(msg, hdr);
8274 return genlmsg_reply(msg, info);
8275
8276nla_put_failure:
8277 nlmsg_free(msg);
8278 return -ENOBUFS;
8279}
8280
8281void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8282{
8283 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8284 int i, j;
8285 struct cfg80211_coalesce_rules *rule;
8286
8287 if (!coalesce)
8288 return;
8289
8290 for (i = 0; i < coalesce->n_rules; i++) {
8291 rule = &coalesce->rules[i];
8292 for (j = 0; j < rule->n_patterns; j++)
8293 kfree(rule->patterns[j].mask);
8294 kfree(rule->patterns);
8295 }
8296 kfree(coalesce->rules);
8297 kfree(coalesce);
8298 rdev->coalesce = NULL;
8299}
8300
8301static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8302 struct nlattr *rule,
8303 struct cfg80211_coalesce_rules *new_rule)
8304{
8305 int err, i;
8306 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8307 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8308 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8309 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8310
8311 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8312 nla_len(rule), nl80211_coalesce_policy);
8313 if (err)
8314 return err;
8315
8316 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8317 new_rule->delay =
8318 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8319 if (new_rule->delay > coalesce->max_delay)
8320 return -EINVAL;
8321
8322 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8323 new_rule->condition =
8324 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8325 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8326 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8327 return -EINVAL;
8328
8329 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8330 return -EINVAL;
8331
8332 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8333 rem)
8334 n_patterns++;
8335 if (n_patterns > coalesce->n_patterns)
8336 return -EINVAL;
8337
8338 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8339 GFP_KERNEL);
8340 if (!new_rule->patterns)
8341 return -ENOMEM;
8342
8343 new_rule->n_patterns = n_patterns;
8344 i = 0;
8345
8346 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8347 rem) {
8348 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8349 nla_len(pat), NULL);
8350 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8351 !pat_tb[NL80211_PKTPAT_PATTERN])
8352 return -EINVAL;
8353 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8354 mask_len = DIV_ROUND_UP(pat_len, 8);
8355 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8356 return -EINVAL;
8357 if (pat_len > coalesce->pattern_max_len ||
8358 pat_len < coalesce->pattern_min_len)
8359 return -EINVAL;
8360
8361 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8362 pkt_offset = 0;
8363 else
8364 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8365 if (pkt_offset > coalesce->max_pkt_offset)
8366 return -EINVAL;
8367 new_rule->patterns[i].pkt_offset = pkt_offset;
8368
8369 new_rule->patterns[i].mask =
8370 kmalloc(mask_len + pat_len, GFP_KERNEL);
8371 if (!new_rule->patterns[i].mask)
8372 return -ENOMEM;
8373 new_rule->patterns[i].pattern =
8374 new_rule->patterns[i].mask + mask_len;
8375 memcpy(new_rule->patterns[i].mask,
8376 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8377 new_rule->patterns[i].pattern_len = pat_len;
8378 memcpy(new_rule->patterns[i].pattern,
8379 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8380 i++;
8381 }
8382
8383 return 0;
8384}
8385
8386static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8387{
8388 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8389 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8390 struct cfg80211_coalesce new_coalesce = {};
8391 struct cfg80211_coalesce *n_coalesce;
8392 int err, rem_rule, n_rules = 0, i, j;
8393 struct nlattr *rule;
8394 struct cfg80211_coalesce_rules *tmp_rule;
8395
8396 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8397 return -EOPNOTSUPP;
8398
8399 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8400 cfg80211_rdev_free_coalesce(rdev);
8401 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8402 return 0;
8403 }
8404
8405 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8406 rem_rule)
8407 n_rules++;
8408 if (n_rules > coalesce->n_rules)
8409 return -EINVAL;
8410
8411 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8412 GFP_KERNEL);
8413 if (!new_coalesce.rules)
8414 return -ENOMEM;
8415
8416 new_coalesce.n_rules = n_rules;
8417 i = 0;
8418
8419 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8420 rem_rule) {
8421 err = nl80211_parse_coalesce_rule(rdev, rule,
8422 &new_coalesce.rules[i]);
8423 if (err)
8424 goto error;
8425
8426 i++;
8427 }
8428
8429 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8430 if (err)
8431 goto error;
8432
8433 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8434 if (!n_coalesce) {
8435 err = -ENOMEM;
8436 goto error;
8437 }
8438 cfg80211_rdev_free_coalesce(rdev);
8439 rdev->coalesce = n_coalesce;
8440
8441 return 0;
8442error:
8443 for (i = 0; i < new_coalesce.n_rules; i++) {
8444 tmp_rule = &new_coalesce.rules[i];
8445 for (j = 0; j < tmp_rule->n_patterns; j++)
8446 kfree(tmp_rule->patterns[j].mask);
8447 kfree(tmp_rule->patterns);
8448 }
8449 kfree(new_coalesce.rules);
8450
8451 return err;
8452}
8453
Johannes Berge5497d72011-07-05 16:35:40 +02008454static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8455{
8456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8457 struct net_device *dev = info->user_ptr[1];
8458 struct wireless_dev *wdev = dev->ieee80211_ptr;
8459 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8460 struct cfg80211_gtk_rekey_data rekey_data;
8461 int err;
8462
8463 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8464 return -EINVAL;
8465
8466 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8467 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8468 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8469 nl80211_rekey_policy);
8470 if (err)
8471 return err;
8472
8473 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8474 return -ERANGE;
8475 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8476 return -ERANGE;
8477 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8478 return -ERANGE;
8479
8480 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8481 NL80211_KEK_LEN);
8482 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8483 NL80211_KCK_LEN);
8484 memcpy(rekey_data.replay_ctr,
8485 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8486 NL80211_REPLAY_CTR_LEN);
8487
8488 wdev_lock(wdev);
8489 if (!wdev->current_bss) {
8490 err = -ENOTCONN;
8491 goto out;
8492 }
8493
8494 if (!rdev->ops->set_rekey_data) {
8495 err = -EOPNOTSUPP;
8496 goto out;
8497 }
8498
Hila Gonene35e4d22012-06-27 17:19:42 +03008499 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008500 out:
8501 wdev_unlock(wdev);
8502 return err;
8503}
8504
Johannes Berg28946da2011-11-04 11:18:12 +01008505static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8506 struct genl_info *info)
8507{
8508 struct net_device *dev = info->user_ptr[1];
8509 struct wireless_dev *wdev = dev->ieee80211_ptr;
8510
8511 if (wdev->iftype != NL80211_IFTYPE_AP &&
8512 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8513 return -EINVAL;
8514
Eric W. Biederman15e47302012-09-07 20:12:54 +00008515 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008516 return -EBUSY;
8517
Eric W. Biederman15e47302012-09-07 20:12:54 +00008518 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008519 return 0;
8520}
8521
Johannes Berg7f6cf312011-11-04 11:18:15 +01008522static int nl80211_probe_client(struct sk_buff *skb,
8523 struct genl_info *info)
8524{
8525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8526 struct net_device *dev = info->user_ptr[1];
8527 struct wireless_dev *wdev = dev->ieee80211_ptr;
8528 struct sk_buff *msg;
8529 void *hdr;
8530 const u8 *addr;
8531 u64 cookie;
8532 int err;
8533
8534 if (wdev->iftype != NL80211_IFTYPE_AP &&
8535 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8536 return -EOPNOTSUPP;
8537
8538 if (!info->attrs[NL80211_ATTR_MAC])
8539 return -EINVAL;
8540
8541 if (!rdev->ops->probe_client)
8542 return -EOPNOTSUPP;
8543
8544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8545 if (!msg)
8546 return -ENOMEM;
8547
Eric W. Biederman15e47302012-09-07 20:12:54 +00008548 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008549 NL80211_CMD_PROBE_CLIENT);
8550
8551 if (IS_ERR(hdr)) {
8552 err = PTR_ERR(hdr);
8553 goto free_msg;
8554 }
8555
8556 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8557
Hila Gonene35e4d22012-06-27 17:19:42 +03008558 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008559 if (err)
8560 goto free_msg;
8561
David S. Miller9360ffd2012-03-29 04:41:26 -04008562 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8563 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008564
8565 genlmsg_end(msg, hdr);
8566
8567 return genlmsg_reply(msg, info);
8568
8569 nla_put_failure:
8570 err = -ENOBUFS;
8571 free_msg:
8572 nlmsg_free(msg);
8573 return err;
8574}
8575
Johannes Berg5e7602302011-11-04 11:18:17 +01008576static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8577{
8578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008579 struct cfg80211_beacon_registration *reg, *nreg;
8580 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008581
8582 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8583 return -EOPNOTSUPP;
8584
Ben Greear37c73b52012-10-26 14:49:25 -07008585 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8586 if (!nreg)
8587 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008588
Ben Greear37c73b52012-10-26 14:49:25 -07008589 /* First, check if already registered. */
8590 spin_lock_bh(&rdev->beacon_registrations_lock);
8591 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8592 if (reg->nlportid == info->snd_portid) {
8593 rv = -EALREADY;
8594 goto out_err;
8595 }
8596 }
8597 /* Add it to the list */
8598 nreg->nlportid = info->snd_portid;
8599 list_add(&nreg->list, &rdev->beacon_registrations);
8600
8601 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008602
8603 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008604out_err:
8605 spin_unlock_bh(&rdev->beacon_registrations_lock);
8606 kfree(nreg);
8607 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008608}
8609
Johannes Berg98104fde2012-06-16 00:19:54 +02008610static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8611{
8612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8613 struct wireless_dev *wdev = info->user_ptr[1];
8614 int err;
8615
8616 if (!rdev->ops->start_p2p_device)
8617 return -EOPNOTSUPP;
8618
8619 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8620 return -EOPNOTSUPP;
8621
8622 if (wdev->p2p_started)
8623 return 0;
8624
Johannes Berg98104fde2012-06-16 00:19:54 +02008625 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008626 if (err)
8627 return err;
8628
Johannes Bergeeb126e2012-10-23 15:16:50 +02008629 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008630 if (err)
8631 return err;
8632
8633 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008634 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008635
8636 return 0;
8637}
8638
8639static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8640{
8641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8642 struct wireless_dev *wdev = info->user_ptr[1];
8643
8644 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8645 return -EOPNOTSUPP;
8646
8647 if (!rdev->ops->stop_p2p_device)
8648 return -EOPNOTSUPP;
8649
Johannes Bergf9f47522013-03-19 15:04:07 +01008650 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008651
8652 return 0;
8653}
8654
Johannes Berg3713b4e2013-02-14 16:19:38 +01008655static int nl80211_get_protocol_features(struct sk_buff *skb,
8656 struct genl_info *info)
8657{
8658 void *hdr;
8659 struct sk_buff *msg;
8660
8661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8662 if (!msg)
8663 return -ENOMEM;
8664
8665 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8666 NL80211_CMD_GET_PROTOCOL_FEATURES);
8667 if (!hdr)
8668 goto nla_put_failure;
8669
8670 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8671 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8672 goto nla_put_failure;
8673
8674 genlmsg_end(msg, hdr);
8675 return genlmsg_reply(msg, info);
8676
8677 nla_put_failure:
8678 kfree_skb(msg);
8679 return -ENOBUFS;
8680}
8681
Jouni Malinen355199e2013-02-27 17:14:27 +02008682static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8683{
8684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8685 struct cfg80211_update_ft_ies_params ft_params;
8686 struct net_device *dev = info->user_ptr[1];
8687
8688 if (!rdev->ops->update_ft_ies)
8689 return -EOPNOTSUPP;
8690
8691 if (!info->attrs[NL80211_ATTR_MDID] ||
8692 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8693 return -EINVAL;
8694
8695 memset(&ft_params, 0, sizeof(ft_params));
8696 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8697 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8698 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8699
8700 return rdev_update_ft_ies(rdev, dev, &ft_params);
8701}
8702
Arend van Spriel5de17982013-04-18 15:49:00 +02008703static int nl80211_crit_protocol_start(struct sk_buff *skb,
8704 struct genl_info *info)
8705{
8706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8707 struct wireless_dev *wdev = info->user_ptr[1];
8708 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8709 u16 duration;
8710 int ret;
8711
8712 if (!rdev->ops->crit_proto_start)
8713 return -EOPNOTSUPP;
8714
8715 if (WARN_ON(!rdev->ops->crit_proto_stop))
8716 return -EINVAL;
8717
8718 if (rdev->crit_proto_nlportid)
8719 return -EBUSY;
8720
8721 /* determine protocol if provided */
8722 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8723 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8724
8725 if (proto >= NUM_NL80211_CRIT_PROTO)
8726 return -EINVAL;
8727
8728 /* timeout must be provided */
8729 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8730 return -EINVAL;
8731
8732 duration =
8733 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8734
8735 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8736 return -ERANGE;
8737
8738 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8739 if (!ret)
8740 rdev->crit_proto_nlportid = info->snd_portid;
8741
8742 return ret;
8743}
8744
8745static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8746 struct genl_info *info)
8747{
8748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8749 struct wireless_dev *wdev = info->user_ptr[1];
8750
8751 if (!rdev->ops->crit_proto_stop)
8752 return -EOPNOTSUPP;
8753
8754 if (rdev->crit_proto_nlportid) {
8755 rdev->crit_proto_nlportid = 0;
8756 rdev_crit_proto_stop(rdev, wdev);
8757 }
8758 return 0;
8759}
8760
Johannes Berg4c476992010-10-04 21:36:35 +02008761#define NL80211_FLAG_NEED_WIPHY 0x01
8762#define NL80211_FLAG_NEED_NETDEV 0x02
8763#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008764#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8765#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8766 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008767#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008768/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008769#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8770 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008771
8772static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8773 struct genl_info *info)
8774{
8775 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008776 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008777 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008778 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8779
8780 if (rtnl)
8781 rtnl_lock();
8782
8783 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008784 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008785 if (IS_ERR(rdev)) {
8786 if (rtnl)
8787 rtnl_unlock();
8788 return PTR_ERR(rdev);
8789 }
8790 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008791 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8792 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008793 ASSERT_RTNL();
8794
Johannes Berg89a54e42012-06-15 14:33:17 +02008795 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8796 info->attrs);
8797 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008798 if (rtnl)
8799 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008800 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008801 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008802
Johannes Berg89a54e42012-06-15 14:33:17 +02008803 dev = wdev->netdev;
8804 rdev = wiphy_to_dev(wdev->wiphy);
8805
Johannes Berg1bf614e2012-06-15 15:23:36 +02008806 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8807 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008808 if (rtnl)
8809 rtnl_unlock();
8810 return -EINVAL;
8811 }
8812
8813 info->user_ptr[1] = dev;
8814 } else {
8815 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008816 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008817
Johannes Berg1bf614e2012-06-15 15:23:36 +02008818 if (dev) {
8819 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8820 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008821 if (rtnl)
8822 rtnl_unlock();
8823 return -ENETDOWN;
8824 }
8825
8826 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008827 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8828 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008829 if (rtnl)
8830 rtnl_unlock();
8831 return -ENETDOWN;
8832 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008833 }
8834
Johannes Berg4c476992010-10-04 21:36:35 +02008835 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008836 }
8837
8838 return 0;
8839}
8840
8841static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8842 struct genl_info *info)
8843{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008844 if (info->user_ptr[1]) {
8845 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8846 struct wireless_dev *wdev = info->user_ptr[1];
8847
8848 if (wdev->netdev)
8849 dev_put(wdev->netdev);
8850 } else {
8851 dev_put(info->user_ptr[1]);
8852 }
8853 }
Johannes Berg4c476992010-10-04 21:36:35 +02008854 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8855 rtnl_unlock();
8856}
8857
Johannes Berg55682962007-09-20 13:09:35 -04008858static struct genl_ops nl80211_ops[] = {
8859 {
8860 .cmd = NL80211_CMD_GET_WIPHY,
8861 .doit = nl80211_get_wiphy,
8862 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008863 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008864 .policy = nl80211_policy,
8865 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008866 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8867 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008868 },
8869 {
8870 .cmd = NL80211_CMD_SET_WIPHY,
8871 .doit = nl80211_set_wiphy,
8872 .policy = nl80211_policy,
8873 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008874 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008875 },
8876 {
8877 .cmd = NL80211_CMD_GET_INTERFACE,
8878 .doit = nl80211_get_interface,
8879 .dumpit = nl80211_dump_interface,
8880 .policy = nl80211_policy,
8881 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008882 .internal_flags = NL80211_FLAG_NEED_WDEV |
8883 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008884 },
8885 {
8886 .cmd = NL80211_CMD_SET_INTERFACE,
8887 .doit = nl80211_set_interface,
8888 .policy = nl80211_policy,
8889 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008890 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8891 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008892 },
8893 {
8894 .cmd = NL80211_CMD_NEW_INTERFACE,
8895 .doit = nl80211_new_interface,
8896 .policy = nl80211_policy,
8897 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008898 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8899 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008900 },
8901 {
8902 .cmd = NL80211_CMD_DEL_INTERFACE,
8903 .doit = nl80211_del_interface,
8904 .policy = nl80211_policy,
8905 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008906 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008907 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008908 },
Johannes Berg41ade002007-12-19 02:03:29 +01008909 {
8910 .cmd = NL80211_CMD_GET_KEY,
8911 .doit = nl80211_get_key,
8912 .policy = nl80211_policy,
8913 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008914 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008915 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008916 },
8917 {
8918 .cmd = NL80211_CMD_SET_KEY,
8919 .doit = nl80211_set_key,
8920 .policy = nl80211_policy,
8921 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008922 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008923 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008924 },
8925 {
8926 .cmd = NL80211_CMD_NEW_KEY,
8927 .doit = nl80211_new_key,
8928 .policy = nl80211_policy,
8929 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008930 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008931 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008932 },
8933 {
8934 .cmd = NL80211_CMD_DEL_KEY,
8935 .doit = nl80211_del_key,
8936 .policy = nl80211_policy,
8937 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008938 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008939 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008940 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008941 {
8942 .cmd = NL80211_CMD_SET_BEACON,
8943 .policy = nl80211_policy,
8944 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008945 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008946 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008947 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008948 },
8949 {
Johannes Berg88600202012-02-13 15:17:18 +01008950 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008951 .policy = nl80211_policy,
8952 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008953 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008954 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008955 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008956 },
8957 {
Johannes Berg88600202012-02-13 15:17:18 +01008958 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008959 .policy = nl80211_policy,
8960 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008961 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008962 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008963 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008964 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008965 {
8966 .cmd = NL80211_CMD_GET_STATION,
8967 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008968 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008969 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008970 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8971 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008972 },
8973 {
8974 .cmd = NL80211_CMD_SET_STATION,
8975 .doit = nl80211_set_station,
8976 .policy = nl80211_policy,
8977 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008979 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008980 },
8981 {
8982 .cmd = NL80211_CMD_NEW_STATION,
8983 .doit = nl80211_new_station,
8984 .policy = nl80211_policy,
8985 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008987 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008988 },
8989 {
8990 .cmd = NL80211_CMD_DEL_STATION,
8991 .doit = nl80211_del_station,
8992 .policy = nl80211_policy,
8993 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008994 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008995 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008996 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008997 {
8998 .cmd = NL80211_CMD_GET_MPATH,
8999 .doit = nl80211_get_mpath,
9000 .dumpit = nl80211_dump_mpath,
9001 .policy = nl80211_policy,
9002 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009004 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009005 },
9006 {
9007 .cmd = NL80211_CMD_SET_MPATH,
9008 .doit = nl80211_set_mpath,
9009 .policy = nl80211_policy,
9010 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009012 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009013 },
9014 {
9015 .cmd = NL80211_CMD_NEW_MPATH,
9016 .doit = nl80211_new_mpath,
9017 .policy = nl80211_policy,
9018 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009020 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009021 },
9022 {
9023 .cmd = NL80211_CMD_DEL_MPATH,
9024 .doit = nl80211_del_mpath,
9025 .policy = nl80211_policy,
9026 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009028 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009029 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009030 {
9031 .cmd = NL80211_CMD_SET_BSS,
9032 .doit = nl80211_set_bss,
9033 .policy = nl80211_policy,
9034 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009036 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009037 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009038 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009039 .cmd = NL80211_CMD_GET_REG,
9040 .doit = nl80211_get_reg,
9041 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009042 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009043 /* can be retrieved by unprivileged users */
9044 },
9045 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009046 .cmd = NL80211_CMD_SET_REG,
9047 .doit = nl80211_set_reg,
9048 .policy = nl80211_policy,
9049 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009050 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009051 },
9052 {
9053 .cmd = NL80211_CMD_REQ_SET_REG,
9054 .doit = nl80211_req_set_reg,
9055 .policy = nl80211_policy,
9056 .flags = GENL_ADMIN_PERM,
9057 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009058 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009059 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9060 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009061 .policy = nl80211_policy,
9062 /* can be retrieved by unprivileged users */
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,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009065 },
9066 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009067 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9068 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009069 .policy = nl80211_policy,
9070 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009072 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009073 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009074 {
Johannes Berg2a519312009-02-10 21:25:55 +01009075 .cmd = NL80211_CMD_TRIGGER_SCAN,
9076 .doit = nl80211_trigger_scan,
9077 .policy = nl80211_policy,
9078 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009079 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009080 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009081 },
9082 {
9083 .cmd = NL80211_CMD_GET_SCAN,
9084 .policy = nl80211_policy,
9085 .dumpit = nl80211_dump_scan,
9086 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009087 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009088 .cmd = NL80211_CMD_START_SCHED_SCAN,
9089 .doit = nl80211_start_sched_scan,
9090 .policy = nl80211_policy,
9091 .flags = GENL_ADMIN_PERM,
9092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9093 NL80211_FLAG_NEED_RTNL,
9094 },
9095 {
9096 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9097 .doit = nl80211_stop_sched_scan,
9098 .policy = nl80211_policy,
9099 .flags = GENL_ADMIN_PERM,
9100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9101 NL80211_FLAG_NEED_RTNL,
9102 },
9103 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009104 .cmd = NL80211_CMD_AUTHENTICATE,
9105 .doit = nl80211_authenticate,
9106 .policy = nl80211_policy,
9107 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009109 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009110 },
9111 {
9112 .cmd = NL80211_CMD_ASSOCIATE,
9113 .doit = nl80211_associate,
9114 .policy = nl80211_policy,
9115 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009117 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009118 },
9119 {
9120 .cmd = NL80211_CMD_DEAUTHENTICATE,
9121 .doit = nl80211_deauthenticate,
9122 .policy = nl80211_policy,
9123 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009125 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009126 },
9127 {
9128 .cmd = NL80211_CMD_DISASSOCIATE,
9129 .doit = nl80211_disassociate,
9130 .policy = nl80211_policy,
9131 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009133 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009134 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009135 {
9136 .cmd = NL80211_CMD_JOIN_IBSS,
9137 .doit = nl80211_join_ibss,
9138 .policy = nl80211_policy,
9139 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009141 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009142 },
9143 {
9144 .cmd = NL80211_CMD_LEAVE_IBSS,
9145 .doit = nl80211_leave_ibss,
9146 .policy = nl80211_policy,
9147 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009149 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009150 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009151#ifdef CONFIG_NL80211_TESTMODE
9152 {
9153 .cmd = NL80211_CMD_TESTMODE,
9154 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009155 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009156 .policy = nl80211_policy,
9157 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009158 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9159 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009160 },
9161#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009162 {
9163 .cmd = NL80211_CMD_CONNECT,
9164 .doit = nl80211_connect,
9165 .policy = nl80211_policy,
9166 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009167 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009168 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009169 },
9170 {
9171 .cmd = NL80211_CMD_DISCONNECT,
9172 .doit = nl80211_disconnect,
9173 .policy = nl80211_policy,
9174 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009175 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009176 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009177 },
Johannes Berg463d0182009-07-14 00:33:35 +02009178 {
9179 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9180 .doit = nl80211_wiphy_netns,
9181 .policy = nl80211_policy,
9182 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009183 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9184 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009185 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009186 {
9187 .cmd = NL80211_CMD_GET_SURVEY,
9188 .policy = nl80211_policy,
9189 .dumpit = nl80211_dump_survey,
9190 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009191 {
9192 .cmd = NL80211_CMD_SET_PMKSA,
9193 .doit = nl80211_setdel_pmksa,
9194 .policy = nl80211_policy,
9195 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009197 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009198 },
9199 {
9200 .cmd = NL80211_CMD_DEL_PMKSA,
9201 .doit = nl80211_setdel_pmksa,
9202 .policy = nl80211_policy,
9203 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009205 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009206 },
9207 {
9208 .cmd = NL80211_CMD_FLUSH_PMKSA,
9209 .doit = nl80211_flush_pmksa,
9210 .policy = nl80211_policy,
9211 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009213 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009214 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009215 {
9216 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9217 .doit = nl80211_remain_on_channel,
9218 .policy = nl80211_policy,
9219 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009220 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009221 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009222 },
9223 {
9224 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9225 .doit = nl80211_cancel_remain_on_channel,
9226 .policy = nl80211_policy,
9227 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009228 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009229 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009230 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009231 {
9232 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9233 .doit = nl80211_set_tx_bitrate_mask,
9234 .policy = nl80211_policy,
9235 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009236 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9237 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009238 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009239 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009240 .cmd = NL80211_CMD_REGISTER_FRAME,
9241 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009242 .policy = nl80211_policy,
9243 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009244 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009245 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009246 },
9247 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009248 .cmd = NL80211_CMD_FRAME,
9249 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009250 .policy = nl80211_policy,
9251 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009252 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009253 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009254 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009255 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009256 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9257 .doit = nl80211_tx_mgmt_cancel_wait,
9258 .policy = nl80211_policy,
9259 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009260 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009261 NL80211_FLAG_NEED_RTNL,
9262 },
9263 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009264 .cmd = NL80211_CMD_SET_POWER_SAVE,
9265 .doit = nl80211_set_power_save,
9266 .policy = nl80211_policy,
9267 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009268 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9269 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009270 },
9271 {
9272 .cmd = NL80211_CMD_GET_POWER_SAVE,
9273 .doit = nl80211_get_power_save,
9274 .policy = nl80211_policy,
9275 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009276 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9277 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009278 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009279 {
9280 .cmd = NL80211_CMD_SET_CQM,
9281 .doit = nl80211_set_cqm,
9282 .policy = nl80211_policy,
9283 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009284 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9285 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009286 },
Johannes Bergf444de02010-05-05 15:25:02 +02009287 {
9288 .cmd = NL80211_CMD_SET_CHANNEL,
9289 .doit = nl80211_set_channel,
9290 .policy = nl80211_policy,
9291 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009292 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9293 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009294 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009295 {
9296 .cmd = NL80211_CMD_SET_WDS_PEER,
9297 .doit = nl80211_set_wds_peer,
9298 .policy = nl80211_policy,
9299 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009300 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9301 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009302 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009303 {
9304 .cmd = NL80211_CMD_JOIN_MESH,
9305 .doit = nl80211_join_mesh,
9306 .policy = nl80211_policy,
9307 .flags = GENL_ADMIN_PERM,
9308 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9309 NL80211_FLAG_NEED_RTNL,
9310 },
9311 {
9312 .cmd = NL80211_CMD_LEAVE_MESH,
9313 .doit = nl80211_leave_mesh,
9314 .policy = nl80211_policy,
9315 .flags = GENL_ADMIN_PERM,
9316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9317 NL80211_FLAG_NEED_RTNL,
9318 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009319#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009320 {
9321 .cmd = NL80211_CMD_GET_WOWLAN,
9322 .doit = nl80211_get_wowlan,
9323 .policy = nl80211_policy,
9324 /* can be retrieved by unprivileged users */
9325 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9326 NL80211_FLAG_NEED_RTNL,
9327 },
9328 {
9329 .cmd = NL80211_CMD_SET_WOWLAN,
9330 .doit = nl80211_set_wowlan,
9331 .policy = nl80211_policy,
9332 .flags = GENL_ADMIN_PERM,
9333 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9334 NL80211_FLAG_NEED_RTNL,
9335 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009336#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009337 {
9338 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9339 .doit = nl80211_set_rekey_data,
9340 .policy = nl80211_policy,
9341 .flags = GENL_ADMIN_PERM,
9342 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9343 NL80211_FLAG_NEED_RTNL,
9344 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009345 {
9346 .cmd = NL80211_CMD_TDLS_MGMT,
9347 .doit = nl80211_tdls_mgmt,
9348 .policy = nl80211_policy,
9349 .flags = GENL_ADMIN_PERM,
9350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9351 NL80211_FLAG_NEED_RTNL,
9352 },
9353 {
9354 .cmd = NL80211_CMD_TDLS_OPER,
9355 .doit = nl80211_tdls_oper,
9356 .policy = nl80211_policy,
9357 .flags = GENL_ADMIN_PERM,
9358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9359 NL80211_FLAG_NEED_RTNL,
9360 },
Johannes Berg28946da2011-11-04 11:18:12 +01009361 {
9362 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9363 .doit = nl80211_register_unexpected_frame,
9364 .policy = nl80211_policy,
9365 .flags = GENL_ADMIN_PERM,
9366 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9367 NL80211_FLAG_NEED_RTNL,
9368 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009369 {
9370 .cmd = NL80211_CMD_PROBE_CLIENT,
9371 .doit = nl80211_probe_client,
9372 .policy = nl80211_policy,
9373 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009374 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009375 NL80211_FLAG_NEED_RTNL,
9376 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009377 {
9378 .cmd = NL80211_CMD_REGISTER_BEACONS,
9379 .doit = nl80211_register_beacons,
9380 .policy = nl80211_policy,
9381 .flags = GENL_ADMIN_PERM,
9382 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9383 NL80211_FLAG_NEED_RTNL,
9384 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009385 {
9386 .cmd = NL80211_CMD_SET_NOACK_MAP,
9387 .doit = nl80211_set_noack_map,
9388 .policy = nl80211_policy,
9389 .flags = GENL_ADMIN_PERM,
9390 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9391 NL80211_FLAG_NEED_RTNL,
9392 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009393 {
9394 .cmd = NL80211_CMD_START_P2P_DEVICE,
9395 .doit = nl80211_start_p2p_device,
9396 .policy = nl80211_policy,
9397 .flags = GENL_ADMIN_PERM,
9398 .internal_flags = NL80211_FLAG_NEED_WDEV |
9399 NL80211_FLAG_NEED_RTNL,
9400 },
9401 {
9402 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9403 .doit = nl80211_stop_p2p_device,
9404 .policy = nl80211_policy,
9405 .flags = GENL_ADMIN_PERM,
9406 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9407 NL80211_FLAG_NEED_RTNL,
9408 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009409 {
9410 .cmd = NL80211_CMD_SET_MCAST_RATE,
9411 .doit = nl80211_set_mcast_rate,
9412 .policy = nl80211_policy,
9413 .flags = GENL_ADMIN_PERM,
9414 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9415 NL80211_FLAG_NEED_RTNL,
9416 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309417 {
9418 .cmd = NL80211_CMD_SET_MAC_ACL,
9419 .doit = nl80211_set_mac_acl,
9420 .policy = nl80211_policy,
9421 .flags = GENL_ADMIN_PERM,
9422 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9423 NL80211_FLAG_NEED_RTNL,
9424 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009425 {
9426 .cmd = NL80211_CMD_RADAR_DETECT,
9427 .doit = nl80211_start_radar_detection,
9428 .policy = nl80211_policy,
9429 .flags = GENL_ADMIN_PERM,
9430 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9431 NL80211_FLAG_NEED_RTNL,
9432 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009433 {
9434 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9435 .doit = nl80211_get_protocol_features,
9436 .policy = nl80211_policy,
9437 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009438 {
9439 .cmd = NL80211_CMD_UPDATE_FT_IES,
9440 .doit = nl80211_update_ft_ies,
9441 .policy = nl80211_policy,
9442 .flags = GENL_ADMIN_PERM,
9443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9444 NL80211_FLAG_NEED_RTNL,
9445 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009446 {
9447 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9448 .doit = nl80211_crit_protocol_start,
9449 .policy = nl80211_policy,
9450 .flags = GENL_ADMIN_PERM,
9451 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9452 NL80211_FLAG_NEED_RTNL,
9453 },
9454 {
9455 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9456 .doit = nl80211_crit_protocol_stop,
9457 .policy = nl80211_policy,
9458 .flags = GENL_ADMIN_PERM,
9459 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9460 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009461 },
9462 {
9463 .cmd = NL80211_CMD_GET_COALESCE,
9464 .doit = nl80211_get_coalesce,
9465 .policy = nl80211_policy,
9466 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9467 NL80211_FLAG_NEED_RTNL,
9468 },
9469 {
9470 .cmd = NL80211_CMD_SET_COALESCE,
9471 .doit = nl80211_set_coalesce,
9472 .policy = nl80211_policy,
9473 .flags = GENL_ADMIN_PERM,
9474 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9475 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009476 },
9477 {
9478 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9479 .doit = nl80211_channel_switch,
9480 .policy = nl80211_policy,
9481 .flags = GENL_ADMIN_PERM,
9482 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9483 NL80211_FLAG_NEED_RTNL,
9484 },
Johannes Berg55682962007-09-20 13:09:35 -04009485};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009486
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009487static struct genl_multicast_group nl80211_mlme_mcgrp = {
9488 .name = "mlme",
9489};
Johannes Berg55682962007-09-20 13:09:35 -04009490
9491/* multicast groups */
9492static struct genl_multicast_group nl80211_config_mcgrp = {
9493 .name = "config",
9494};
Johannes Berg2a519312009-02-10 21:25:55 +01009495static struct genl_multicast_group nl80211_scan_mcgrp = {
9496 .name = "scan",
9497};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009498static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9499 .name = "regulatory",
9500};
Johannes Berg55682962007-09-20 13:09:35 -04009501
9502/* notification functions */
9503
9504void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9505{
9506 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009507 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009508
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009509 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009510 if (!msg)
9511 return;
9512
Johannes Berg86e8cf92013-06-19 10:57:22 +02009513 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009514 nlmsg_free(msg);
9515 return;
9516 }
9517
Johannes Berg463d0182009-07-14 00:33:35 +02009518 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9519 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009520}
9521
Johannes Berg362a4152009-05-24 16:43:15 +02009522static int nl80211_add_scan_req(struct sk_buff *msg,
9523 struct cfg80211_registered_device *rdev)
9524{
9525 struct cfg80211_scan_request *req = rdev->scan_req;
9526 struct nlattr *nest;
9527 int i;
9528
9529 if (WARN_ON(!req))
9530 return 0;
9531
9532 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9533 if (!nest)
9534 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009535 for (i = 0; i < req->n_ssids; i++) {
9536 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9537 goto nla_put_failure;
9538 }
Johannes Berg362a4152009-05-24 16:43:15 +02009539 nla_nest_end(msg, nest);
9540
9541 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9542 if (!nest)
9543 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009544 for (i = 0; i < req->n_channels; i++) {
9545 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9546 goto nla_put_failure;
9547 }
Johannes Berg362a4152009-05-24 16:43:15 +02009548 nla_nest_end(msg, nest);
9549
David S. Miller9360ffd2012-03-29 04:41:26 -04009550 if (req->ie &&
9551 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9552 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009553
Sam Lefflered4737712012-10-11 21:03:31 -07009554 if (req->flags)
9555 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9556
Johannes Berg362a4152009-05-24 16:43:15 +02009557 return 0;
9558 nla_put_failure:
9559 return -ENOBUFS;
9560}
9561
Johannes Berga538e2d2009-06-16 19:56:42 +02009562static int nl80211_send_scan_msg(struct sk_buff *msg,
9563 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009564 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009565 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009566 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009567{
9568 void *hdr;
9569
Eric W. Biederman15e47302012-09-07 20:12:54 +00009570 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009571 if (!hdr)
9572 return -1;
9573
David S. Miller9360ffd2012-03-29 04:41:26 -04009574 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009575 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9576 wdev->netdev->ifindex)) ||
9577 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009578 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009579
Johannes Berg362a4152009-05-24 16:43:15 +02009580 /* ignore errors and send incomplete event anyway */
9581 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009582
9583 return genlmsg_end(msg, hdr);
9584
9585 nla_put_failure:
9586 genlmsg_cancel(msg, hdr);
9587 return -EMSGSIZE;
9588}
9589
Luciano Coelho807f8a82011-05-11 17:09:35 +03009590static int
9591nl80211_send_sched_scan_msg(struct sk_buff *msg,
9592 struct cfg80211_registered_device *rdev,
9593 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009594 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009595{
9596 void *hdr;
9597
Eric W. Biederman15e47302012-09-07 20:12:54 +00009598 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009599 if (!hdr)
9600 return -1;
9601
David S. Miller9360ffd2012-03-29 04:41:26 -04009602 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9603 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9604 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009605
9606 return genlmsg_end(msg, hdr);
9607
9608 nla_put_failure:
9609 genlmsg_cancel(msg, hdr);
9610 return -EMSGSIZE;
9611}
9612
Johannes Berga538e2d2009-06-16 19:56:42 +02009613void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009614 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009615{
9616 struct sk_buff *msg;
9617
Thomas Graf58050fc2012-06-28 03:57:45 +00009618 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009619 if (!msg)
9620 return;
9621
Johannes Bergfd014282012-06-18 19:17:03 +02009622 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009623 NL80211_CMD_TRIGGER_SCAN) < 0) {
9624 nlmsg_free(msg);
9625 return;
9626 }
9627
Johannes Berg463d0182009-07-14 00:33:35 +02009628 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9629 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009630}
9631
Johannes Berg2a519312009-02-10 21:25:55 +01009632void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009633 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009634{
9635 struct sk_buff *msg;
9636
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009637 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009638 if (!msg)
9639 return;
9640
Johannes Bergfd014282012-06-18 19:17:03 +02009641 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009642 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009643 nlmsg_free(msg);
9644 return;
9645 }
9646
Johannes Berg463d0182009-07-14 00:33:35 +02009647 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9648 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009649}
9650
9651void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009652 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009653{
9654 struct sk_buff *msg;
9655
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009656 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009657 if (!msg)
9658 return;
9659
Johannes Bergfd014282012-06-18 19:17:03 +02009660 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009661 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009662 nlmsg_free(msg);
9663 return;
9664 }
9665
Johannes Berg463d0182009-07-14 00:33:35 +02009666 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9667 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009668}
9669
Luciano Coelho807f8a82011-05-11 17:09:35 +03009670void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9671 struct net_device *netdev)
9672{
9673 struct sk_buff *msg;
9674
9675 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9676 if (!msg)
9677 return;
9678
9679 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9680 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9681 nlmsg_free(msg);
9682 return;
9683 }
9684
9685 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9686 nl80211_scan_mcgrp.id, GFP_KERNEL);
9687}
9688
9689void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9690 struct net_device *netdev, u32 cmd)
9691{
9692 struct sk_buff *msg;
9693
Thomas Graf58050fc2012-06-28 03:57:45 +00009694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009695 if (!msg)
9696 return;
9697
9698 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9699 nlmsg_free(msg);
9700 return;
9701 }
9702
9703 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9704 nl80211_scan_mcgrp.id, GFP_KERNEL);
9705}
9706
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009707/*
9708 * This can happen on global regulatory changes or device specific settings
9709 * based on custom world regulatory domains.
9710 */
9711void nl80211_send_reg_change_event(struct regulatory_request *request)
9712{
9713 struct sk_buff *msg;
9714 void *hdr;
9715
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009716 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009717 if (!msg)
9718 return;
9719
9720 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9721 if (!hdr) {
9722 nlmsg_free(msg);
9723 return;
9724 }
9725
9726 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009727 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9728 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009729
David S. Miller9360ffd2012-03-29 04:41:26 -04009730 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9731 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9732 NL80211_REGDOM_TYPE_WORLD))
9733 goto nla_put_failure;
9734 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9735 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9736 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9737 goto nla_put_failure;
9738 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9739 request->intersect) {
9740 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9741 NL80211_REGDOM_TYPE_INTERSECTION))
9742 goto nla_put_failure;
9743 } else {
9744 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9745 NL80211_REGDOM_TYPE_COUNTRY) ||
9746 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9747 request->alpha2))
9748 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009749 }
9750
Johannes Bergf4173762012-12-03 18:23:37 +01009751 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009752 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9753 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009754
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009755 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009756
Johannes Bergbc43b282009-07-25 10:54:13 +02009757 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009758 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009759 GFP_ATOMIC);
9760 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009761
9762 return;
9763
9764nla_put_failure:
9765 genlmsg_cancel(msg, hdr);
9766 nlmsg_free(msg);
9767}
9768
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009769static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9770 struct net_device *netdev,
9771 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009772 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009773{
9774 struct sk_buff *msg;
9775 void *hdr;
9776
Johannes Berge6d6e342009-07-01 21:26:47 +02009777 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009778 if (!msg)
9779 return;
9780
9781 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9782 if (!hdr) {
9783 nlmsg_free(msg);
9784 return;
9785 }
9786
David S. Miller9360ffd2012-03-29 04:41:26 -04009787 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9788 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9789 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9790 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009791
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009792 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009793
Johannes Berg463d0182009-07-14 00:33:35 +02009794 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9795 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009796 return;
9797
9798 nla_put_failure:
9799 genlmsg_cancel(msg, hdr);
9800 nlmsg_free(msg);
9801}
9802
9803void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009804 struct net_device *netdev, const u8 *buf,
9805 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009806{
9807 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009808 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009809}
9810
9811void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9812 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009813 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009814{
Johannes Berge6d6e342009-07-01 21:26:47 +02009815 nl80211_send_mlme_event(rdev, netdev, buf, len,
9816 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009817}
9818
Jouni Malinen53b46b82009-03-27 20:53:56 +02009819void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009820 struct net_device *netdev, const u8 *buf,
9821 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009822{
9823 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009824 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009825}
9826
Jouni Malinen53b46b82009-03-27 20:53:56 +02009827void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9828 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009829 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009830{
9831 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009832 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009833}
9834
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009835void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9836 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009837{
Johannes Berg947add32013-02-22 22:05:20 +01009838 struct wireless_dev *wdev = dev->ieee80211_ptr;
9839 struct wiphy *wiphy = wdev->wiphy;
9840 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009841 const struct ieee80211_mgmt *mgmt = (void *)buf;
9842 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009843
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009844 if (WARN_ON(len < 2))
9845 return;
9846
9847 if (ieee80211_is_deauth(mgmt->frame_control))
9848 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9849 else
9850 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9851
9852 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9853 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009854}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009855EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009856
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009857static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9858 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009859 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009860{
9861 struct sk_buff *msg;
9862 void *hdr;
9863
Johannes Berge6d6e342009-07-01 21:26:47 +02009864 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009865 if (!msg)
9866 return;
9867
9868 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9869 if (!hdr) {
9870 nlmsg_free(msg);
9871 return;
9872 }
9873
David S. Miller9360ffd2012-03-29 04:41:26 -04009874 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9875 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9876 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9877 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9878 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009879
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009880 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009881
Johannes Berg463d0182009-07-14 00:33:35 +02009882 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9883 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009884 return;
9885
9886 nla_put_failure:
9887 genlmsg_cancel(msg, hdr);
9888 nlmsg_free(msg);
9889}
9890
9891void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009892 struct net_device *netdev, const u8 *addr,
9893 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009894{
9895 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009896 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009897}
9898
9899void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009900 struct net_device *netdev, const u8 *addr,
9901 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009902{
Johannes Berge6d6e342009-07-01 21:26:47 +02009903 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9904 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009905}
9906
Samuel Ortizb23aa672009-07-01 21:26:54 +02009907void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9908 struct net_device *netdev, const u8 *bssid,
9909 const u8 *req_ie, size_t req_ie_len,
9910 const u8 *resp_ie, size_t resp_ie_len,
9911 u16 status, gfp_t gfp)
9912{
9913 struct sk_buff *msg;
9914 void *hdr;
9915
Thomas Graf58050fc2012-06-28 03:57:45 +00009916 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009917 if (!msg)
9918 return;
9919
9920 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9921 if (!hdr) {
9922 nlmsg_free(msg);
9923 return;
9924 }
9925
David S. Miller9360ffd2012-03-29 04:41:26 -04009926 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9927 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9928 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9929 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9930 (req_ie &&
9931 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9932 (resp_ie &&
9933 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9934 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009935
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009936 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009937
Johannes Berg463d0182009-07-14 00:33:35 +02009938 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9939 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009940 return;
9941
9942 nla_put_failure:
9943 genlmsg_cancel(msg, hdr);
9944 nlmsg_free(msg);
9945
9946}
9947
9948void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9949 struct net_device *netdev, const u8 *bssid,
9950 const u8 *req_ie, size_t req_ie_len,
9951 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9952{
9953 struct sk_buff *msg;
9954 void *hdr;
9955
Thomas Graf58050fc2012-06-28 03:57:45 +00009956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009957 if (!msg)
9958 return;
9959
9960 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9961 if (!hdr) {
9962 nlmsg_free(msg);
9963 return;
9964 }
9965
David S. Miller9360ffd2012-03-29 04:41:26 -04009966 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9967 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9968 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9969 (req_ie &&
9970 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9971 (resp_ie &&
9972 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9973 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009974
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009975 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009976
Johannes Berg463d0182009-07-14 00:33:35 +02009977 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9978 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009979 return;
9980
9981 nla_put_failure:
9982 genlmsg_cancel(msg, hdr);
9983 nlmsg_free(msg);
9984
9985}
9986
9987void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9988 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009989 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009990{
9991 struct sk_buff *msg;
9992 void *hdr;
9993
Thomas Graf58050fc2012-06-28 03:57:45 +00009994 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009995 if (!msg)
9996 return;
9997
9998 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9999 if (!hdr) {
10000 nlmsg_free(msg);
10001 return;
10002 }
10003
David S. Miller9360ffd2012-03-29 04:41:26 -040010004 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10005 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10006 (from_ap && reason &&
10007 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10008 (from_ap &&
10009 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10010 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10011 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010012
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010013 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010014
Johannes Berg463d0182009-07-14 00:33:35 +020010015 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10016 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010017 return;
10018
10019 nla_put_failure:
10020 genlmsg_cancel(msg, hdr);
10021 nlmsg_free(msg);
10022
10023}
10024
Johannes Berg04a773a2009-04-19 21:24:32 +020010025void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10026 struct net_device *netdev, const u8 *bssid,
10027 gfp_t gfp)
10028{
10029 struct sk_buff *msg;
10030 void *hdr;
10031
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010032 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010033 if (!msg)
10034 return;
10035
10036 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10037 if (!hdr) {
10038 nlmsg_free(msg);
10039 return;
10040 }
10041
David S. Miller9360ffd2012-03-29 04:41:26 -040010042 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10043 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10044 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10045 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010046
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010047 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010048
Johannes Berg463d0182009-07-14 00:33:35 +020010049 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10050 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010051 return;
10052
10053 nla_put_failure:
10054 genlmsg_cancel(msg, hdr);
10055 nlmsg_free(msg);
10056}
10057
Johannes Berg947add32013-02-22 22:05:20 +010010058void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10059 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010060{
Johannes Berg947add32013-02-22 22:05:20 +010010061 struct wireless_dev *wdev = dev->ieee80211_ptr;
10062 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010063 struct sk_buff *msg;
10064 void *hdr;
10065
Johannes Berg947add32013-02-22 22:05:20 +010010066 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10067 return;
10068
10069 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10070
Javier Cardonac93b5e72011-04-07 15:08:34 -070010071 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10072 if (!msg)
10073 return;
10074
10075 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10076 if (!hdr) {
10077 nlmsg_free(msg);
10078 return;
10079 }
10080
David S. Miller9360ffd2012-03-29 04:41:26 -040010081 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010082 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10083 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010084 (ie_len && ie &&
10085 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10086 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010087
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010088 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010089
10090 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10091 nl80211_mlme_mcgrp.id, gfp);
10092 return;
10093
10094 nla_put_failure:
10095 genlmsg_cancel(msg, hdr);
10096 nlmsg_free(msg);
10097}
Johannes Berg947add32013-02-22 22:05:20 +010010098EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010099
Jouni Malinena3b8b052009-03-27 21:59:49 +020010100void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10101 struct net_device *netdev, const u8 *addr,
10102 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010103 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010104{
10105 struct sk_buff *msg;
10106 void *hdr;
10107
Johannes Berge6d6e342009-07-01 21:26:47 +020010108 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010109 if (!msg)
10110 return;
10111
10112 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10113 if (!hdr) {
10114 nlmsg_free(msg);
10115 return;
10116 }
10117
David S. Miller9360ffd2012-03-29 04:41:26 -040010118 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10119 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10120 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10121 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10122 (key_id != -1 &&
10123 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10124 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10125 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010126
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010127 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010128
Johannes Berg463d0182009-07-14 00:33:35 +020010129 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10130 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010131 return;
10132
10133 nla_put_failure:
10134 genlmsg_cancel(msg, hdr);
10135 nlmsg_free(msg);
10136}
10137
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010138void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10139 struct ieee80211_channel *channel_before,
10140 struct ieee80211_channel *channel_after)
10141{
10142 struct sk_buff *msg;
10143 void *hdr;
10144 struct nlattr *nl_freq;
10145
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010147 if (!msg)
10148 return;
10149
10150 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10151 if (!hdr) {
10152 nlmsg_free(msg);
10153 return;
10154 }
10155
10156 /*
10157 * Since we are applying the beacon hint to a wiphy we know its
10158 * wiphy_idx is valid
10159 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10161 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010162
10163 /* Before */
10164 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10165 if (!nl_freq)
10166 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010167 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010168 goto nla_put_failure;
10169 nla_nest_end(msg, nl_freq);
10170
10171 /* After */
10172 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10173 if (!nl_freq)
10174 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010175 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010176 goto nla_put_failure;
10177 nla_nest_end(msg, nl_freq);
10178
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010179 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010180
Johannes Berg463d0182009-07-14 00:33:35 +020010181 rcu_read_lock();
10182 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10183 GFP_ATOMIC);
10184 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010185
10186 return;
10187
10188nla_put_failure:
10189 genlmsg_cancel(msg, hdr);
10190 nlmsg_free(msg);
10191}
10192
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010193static void nl80211_send_remain_on_chan_event(
10194 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010195 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010196 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010197 unsigned int duration, gfp_t gfp)
10198{
10199 struct sk_buff *msg;
10200 void *hdr;
10201
10202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10203 if (!msg)
10204 return;
10205
10206 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10207 if (!hdr) {
10208 nlmsg_free(msg);
10209 return;
10210 }
10211
David S. Miller9360ffd2012-03-29 04:41:26 -040010212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010213 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10214 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010215 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010216 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010217 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10218 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010219 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10220 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010221
David S. Miller9360ffd2012-03-29 04:41:26 -040010222 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10223 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10224 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010225
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010226 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010227
10228 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10229 nl80211_mlme_mcgrp.id, gfp);
10230 return;
10231
10232 nla_put_failure:
10233 genlmsg_cancel(msg, hdr);
10234 nlmsg_free(msg);
10235}
10236
Johannes Berg947add32013-02-22 22:05:20 +010010237void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10238 struct ieee80211_channel *chan,
10239 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010240{
Johannes Berg947add32013-02-22 22:05:20 +010010241 struct wiphy *wiphy = wdev->wiphy;
10242 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10243
10244 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010245 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010246 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010247 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010248}
Johannes Berg947add32013-02-22 22:05:20 +010010249EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010250
Johannes Berg947add32013-02-22 22:05:20 +010010251void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10252 struct ieee80211_channel *chan,
10253 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010254{
Johannes Berg947add32013-02-22 22:05:20 +010010255 struct wiphy *wiphy = wdev->wiphy;
10256 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10257
10258 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010259 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010260 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010261}
Johannes Berg947add32013-02-22 22:05:20 +010010262EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010263
Johannes Berg947add32013-02-22 22:05:20 +010010264void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10265 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010266{
Johannes Berg947add32013-02-22 22:05:20 +010010267 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10268 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010269 struct sk_buff *msg;
10270
Johannes Berg947add32013-02-22 22:05:20 +010010271 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10272
Thomas Graf58050fc2012-06-28 03:57:45 +000010273 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010274 if (!msg)
10275 return;
10276
John W. Linville66266b32012-03-15 13:25:41 -040010277 if (nl80211_send_station(msg, 0, 0, 0,
10278 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010279 nlmsg_free(msg);
10280 return;
10281 }
10282
10283 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10284 nl80211_mlme_mcgrp.id, gfp);
10285}
Johannes Berg947add32013-02-22 22:05:20 +010010286EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010287
Johannes Berg947add32013-02-22 22:05:20 +010010288void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010289{
Johannes Berg947add32013-02-22 22:05:20 +010010290 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10291 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010292 struct sk_buff *msg;
10293 void *hdr;
10294
Johannes Berg947add32013-02-22 22:05:20 +010010295 trace_cfg80211_del_sta(dev, mac_addr);
10296
Thomas Graf58050fc2012-06-28 03:57:45 +000010297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010298 if (!msg)
10299 return;
10300
10301 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10302 if (!hdr) {
10303 nlmsg_free(msg);
10304 return;
10305 }
10306
David S. Miller9360ffd2012-03-29 04:41:26 -040010307 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10308 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10309 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010310
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010311 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010312
10313 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10314 nl80211_mlme_mcgrp.id, gfp);
10315 return;
10316
10317 nla_put_failure:
10318 genlmsg_cancel(msg, hdr);
10319 nlmsg_free(msg);
10320}
Johannes Berg947add32013-02-22 22:05:20 +010010321EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010322
Johannes Berg947add32013-02-22 22:05:20 +010010323void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10324 enum nl80211_connect_failed_reason reason,
10325 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010326{
Johannes Berg947add32013-02-22 22:05:20 +010010327 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10328 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010329 struct sk_buff *msg;
10330 void *hdr;
10331
10332 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10333 if (!msg)
10334 return;
10335
10336 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10337 if (!hdr) {
10338 nlmsg_free(msg);
10339 return;
10340 }
10341
10342 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10343 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10344 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10345 goto nla_put_failure;
10346
10347 genlmsg_end(msg, hdr);
10348
10349 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10350 nl80211_mlme_mcgrp.id, gfp);
10351 return;
10352
10353 nla_put_failure:
10354 genlmsg_cancel(msg, hdr);
10355 nlmsg_free(msg);
10356}
Johannes Berg947add32013-02-22 22:05:20 +010010357EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010358
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010359static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10360 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010361{
10362 struct wireless_dev *wdev = dev->ieee80211_ptr;
10363 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10364 struct sk_buff *msg;
10365 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010366 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010367
Eric W. Biederman15e47302012-09-07 20:12:54 +000010368 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010369 return false;
10370
10371 msg = nlmsg_new(100, gfp);
10372 if (!msg)
10373 return true;
10374
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010375 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010376 if (!hdr) {
10377 nlmsg_free(msg);
10378 return true;
10379 }
10380
David S. Miller9360ffd2012-03-29 04:41:26 -040010381 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10382 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10383 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10384 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010385
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010386 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010387 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010388 return true;
10389
10390 nla_put_failure:
10391 genlmsg_cancel(msg, hdr);
10392 nlmsg_free(msg);
10393 return true;
10394}
10395
Johannes Berg947add32013-02-22 22:05:20 +010010396bool cfg80211_rx_spurious_frame(struct net_device *dev,
10397 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010398{
Johannes Berg947add32013-02-22 22:05:20 +010010399 struct wireless_dev *wdev = dev->ieee80211_ptr;
10400 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010401
Johannes Berg947add32013-02-22 22:05:20 +010010402 trace_cfg80211_rx_spurious_frame(dev, addr);
10403
10404 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10405 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10406 trace_cfg80211_return_bool(false);
10407 return false;
10408 }
10409 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10410 addr, gfp);
10411 trace_cfg80211_return_bool(ret);
10412 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010413}
Johannes Berg947add32013-02-22 22:05:20 +010010414EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10415
10416bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10417 const u8 *addr, gfp_t gfp)
10418{
10419 struct wireless_dev *wdev = dev->ieee80211_ptr;
10420 bool ret;
10421
10422 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10423
10424 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10425 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10426 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10427 trace_cfg80211_return_bool(false);
10428 return false;
10429 }
10430 ret = __nl80211_unexpected_frame(dev,
10431 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10432 addr, gfp);
10433 trace_cfg80211_return_bool(ret);
10434 return ret;
10435}
10436EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010437
Johannes Berg2e161f72010-08-12 15:38:38 +020010438int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010439 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010440 int freq, int sig_dbm,
10441 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010442{
Johannes Berg71bbc992012-06-15 15:30:18 +020010443 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010444 struct sk_buff *msg;
10445 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010446
10447 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10448 if (!msg)
10449 return -ENOMEM;
10450
Johannes Berg2e161f72010-08-12 15:38:38 +020010451 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010452 if (!hdr) {
10453 nlmsg_free(msg);
10454 return -ENOMEM;
10455 }
10456
David S. Miller9360ffd2012-03-29 04:41:26 -040010457 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010458 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10459 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010460 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010461 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10462 (sig_dbm &&
10463 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10464 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10465 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010466
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010467 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010468
Eric W. Biederman15e47302012-09-07 20:12:54 +000010469 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010470
10471 nla_put_failure:
10472 genlmsg_cancel(msg, hdr);
10473 nlmsg_free(msg);
10474 return -ENOBUFS;
10475}
10476
Johannes Berg947add32013-02-22 22:05:20 +010010477void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10478 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010479{
Johannes Berg947add32013-02-22 22:05:20 +010010480 struct wiphy *wiphy = wdev->wiphy;
10481 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010482 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010483 struct sk_buff *msg;
10484 void *hdr;
10485
Johannes Berg947add32013-02-22 22:05:20 +010010486 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10487
Jouni Malinen026331c2010-02-15 12:53:10 +020010488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10489 if (!msg)
10490 return;
10491
Johannes Berg2e161f72010-08-12 15:38:38 +020010492 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010493 if (!hdr) {
10494 nlmsg_free(msg);
10495 return;
10496 }
10497
David S. Miller9360ffd2012-03-29 04:41:26 -040010498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010499 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10500 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010501 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010502 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10503 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10504 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10505 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010506
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010507 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010508
10509 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10510 return;
10511
10512 nla_put_failure:
10513 genlmsg_cancel(msg, hdr);
10514 nlmsg_free(msg);
10515}
Johannes Berg947add32013-02-22 22:05:20 +010010516EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010517
Johannes Berg947add32013-02-22 22:05:20 +010010518void cfg80211_cqm_rssi_notify(struct net_device *dev,
10519 enum nl80211_cqm_rssi_threshold_event rssi_event,
10520 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010521{
Johannes Berg947add32013-02-22 22:05:20 +010010522 struct wireless_dev *wdev = dev->ieee80211_ptr;
10523 struct wiphy *wiphy = wdev->wiphy;
10524 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010525 struct sk_buff *msg;
10526 struct nlattr *pinfoattr;
10527 void *hdr;
10528
Johannes Berg947add32013-02-22 22:05:20 +010010529 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10530
Thomas Graf58050fc2012-06-28 03:57:45 +000010531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010532 if (!msg)
10533 return;
10534
10535 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10536 if (!hdr) {
10537 nlmsg_free(msg);
10538 return;
10539 }
10540
David S. Miller9360ffd2012-03-29 04:41:26 -040010541 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010542 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010543 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010544
10545 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10546 if (!pinfoattr)
10547 goto nla_put_failure;
10548
David S. Miller9360ffd2012-03-29 04:41:26 -040010549 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10550 rssi_event))
10551 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010552
10553 nla_nest_end(msg, pinfoattr);
10554
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010555 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010556
10557 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10558 nl80211_mlme_mcgrp.id, gfp);
10559 return;
10560
10561 nla_put_failure:
10562 genlmsg_cancel(msg, hdr);
10563 nlmsg_free(msg);
10564}
Johannes Berg947add32013-02-22 22:05:20 +010010565EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010566
Johannes Berg947add32013-02-22 22:05:20 +010010567static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10568 struct net_device *netdev, const u8 *bssid,
10569 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010570{
10571 struct sk_buff *msg;
10572 struct nlattr *rekey_attr;
10573 void *hdr;
10574
Thomas Graf58050fc2012-06-28 03:57:45 +000010575 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010576 if (!msg)
10577 return;
10578
10579 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10580 if (!hdr) {
10581 nlmsg_free(msg);
10582 return;
10583 }
10584
David S. Miller9360ffd2012-03-29 04:41:26 -040010585 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10586 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10587 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10588 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010589
10590 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10591 if (!rekey_attr)
10592 goto nla_put_failure;
10593
David S. Miller9360ffd2012-03-29 04:41:26 -040010594 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10595 NL80211_REPLAY_CTR_LEN, replay_ctr))
10596 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010597
10598 nla_nest_end(msg, rekey_attr);
10599
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010600 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010601
10602 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10603 nl80211_mlme_mcgrp.id, gfp);
10604 return;
10605
10606 nla_put_failure:
10607 genlmsg_cancel(msg, hdr);
10608 nlmsg_free(msg);
10609}
10610
Johannes Berg947add32013-02-22 22:05:20 +010010611void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10612 const u8 *replay_ctr, gfp_t gfp)
10613{
10614 struct wireless_dev *wdev = dev->ieee80211_ptr;
10615 struct wiphy *wiphy = wdev->wiphy;
10616 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10617
10618 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10619 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10620}
10621EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10622
10623static void
10624nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10625 struct net_device *netdev, int index,
10626 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010627{
10628 struct sk_buff *msg;
10629 struct nlattr *attr;
10630 void *hdr;
10631
Thomas Graf58050fc2012-06-28 03:57:45 +000010632 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010633 if (!msg)
10634 return;
10635
10636 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10637 if (!hdr) {
10638 nlmsg_free(msg);
10639 return;
10640 }
10641
David S. Miller9360ffd2012-03-29 04:41:26 -040010642 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10643 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10644 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010645
10646 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10647 if (!attr)
10648 goto nla_put_failure;
10649
David S. Miller9360ffd2012-03-29 04:41:26 -040010650 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10651 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10652 (preauth &&
10653 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10654 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010655
10656 nla_nest_end(msg, attr);
10657
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010658 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010659
10660 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10661 nl80211_mlme_mcgrp.id, gfp);
10662 return;
10663
10664 nla_put_failure:
10665 genlmsg_cancel(msg, hdr);
10666 nlmsg_free(msg);
10667}
10668
Johannes Berg947add32013-02-22 22:05:20 +010010669void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10670 const u8 *bssid, bool preauth, gfp_t gfp)
10671{
10672 struct wireless_dev *wdev = dev->ieee80211_ptr;
10673 struct wiphy *wiphy = wdev->wiphy;
10674 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10675
10676 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10677 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10678}
10679EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10680
10681static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10682 struct net_device *netdev,
10683 struct cfg80211_chan_def *chandef,
10684 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010685{
10686 struct sk_buff *msg;
10687 void *hdr;
10688
Thomas Graf58050fc2012-06-28 03:57:45 +000010689 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010690 if (!msg)
10691 return;
10692
10693 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10694 if (!hdr) {
10695 nlmsg_free(msg);
10696 return;
10697 }
10698
Johannes Berg683b6d32012-11-08 21:25:48 +010010699 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10700 goto nla_put_failure;
10701
10702 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010703 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010704
10705 genlmsg_end(msg, hdr);
10706
10707 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10708 nl80211_mlme_mcgrp.id, gfp);
10709 return;
10710
10711 nla_put_failure:
10712 genlmsg_cancel(msg, hdr);
10713 nlmsg_free(msg);
10714}
10715
Johannes Berg947add32013-02-22 22:05:20 +010010716void cfg80211_ch_switch_notify(struct net_device *dev,
10717 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010718{
Johannes Berg947add32013-02-22 22:05:20 +010010719 struct wireless_dev *wdev = dev->ieee80211_ptr;
10720 struct wiphy *wiphy = wdev->wiphy;
10721 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10722
10723 trace_cfg80211_ch_switch_notify(dev, chandef);
10724
10725 wdev_lock(wdev);
10726
10727 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10728 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10729 goto out;
10730
10731 wdev->channel = chandef->chan;
10732 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10733out:
10734 wdev_unlock(wdev);
10735 return;
10736}
10737EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10738
10739void cfg80211_cqm_txe_notify(struct net_device *dev,
10740 const u8 *peer, u32 num_packets,
10741 u32 rate, u32 intvl, gfp_t gfp)
10742{
10743 struct wireless_dev *wdev = dev->ieee80211_ptr;
10744 struct wiphy *wiphy = wdev->wiphy;
10745 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010746 struct sk_buff *msg;
10747 struct nlattr *pinfoattr;
10748 void *hdr;
10749
10750 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10751 if (!msg)
10752 return;
10753
10754 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10755 if (!hdr) {
10756 nlmsg_free(msg);
10757 return;
10758 }
10759
10760 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010761 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010762 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10763 goto nla_put_failure;
10764
10765 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10766 if (!pinfoattr)
10767 goto nla_put_failure;
10768
10769 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10770 goto nla_put_failure;
10771
10772 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10773 goto nla_put_failure;
10774
10775 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10776 goto nla_put_failure;
10777
10778 nla_nest_end(msg, pinfoattr);
10779
10780 genlmsg_end(msg, hdr);
10781
10782 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10783 nl80211_mlme_mcgrp.id, gfp);
10784 return;
10785
10786 nla_put_failure:
10787 genlmsg_cancel(msg, hdr);
10788 nlmsg_free(msg);
10789}
Johannes Berg947add32013-02-22 22:05:20 +010010790EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010791
10792void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010793nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10794 struct cfg80211_chan_def *chandef,
10795 enum nl80211_radar_event event,
10796 struct net_device *netdev, gfp_t gfp)
10797{
10798 struct sk_buff *msg;
10799 void *hdr;
10800
10801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10802 if (!msg)
10803 return;
10804
10805 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10806 if (!hdr) {
10807 nlmsg_free(msg);
10808 return;
10809 }
10810
10811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10812 goto nla_put_failure;
10813
10814 /* NOP and radar events don't need a netdev parameter */
10815 if (netdev) {
10816 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10817
10818 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10819 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10820 goto nla_put_failure;
10821 }
10822
10823 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10824 goto nla_put_failure;
10825
10826 if (nl80211_send_chandef(msg, chandef))
10827 goto nla_put_failure;
10828
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010829 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010830
10831 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10832 nl80211_mlme_mcgrp.id, gfp);
10833 return;
10834
10835 nla_put_failure:
10836 genlmsg_cancel(msg, hdr);
10837 nlmsg_free(msg);
10838}
10839
Johannes Berg947add32013-02-22 22:05:20 +010010840void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10841 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010842{
Johannes Berg947add32013-02-22 22:05:20 +010010843 struct wireless_dev *wdev = dev->ieee80211_ptr;
10844 struct wiphy *wiphy = wdev->wiphy;
10845 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010846 struct sk_buff *msg;
10847 struct nlattr *pinfoattr;
10848 void *hdr;
10849
Johannes Berg947add32013-02-22 22:05:20 +010010850 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10851
Thomas Graf58050fc2012-06-28 03:57:45 +000010852 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010853 if (!msg)
10854 return;
10855
10856 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10857 if (!hdr) {
10858 nlmsg_free(msg);
10859 return;
10860 }
10861
David S. Miller9360ffd2012-03-29 04:41:26 -040010862 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010863 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010864 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10865 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010866
10867 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10868 if (!pinfoattr)
10869 goto nla_put_failure;
10870
David S. Miller9360ffd2012-03-29 04:41:26 -040010871 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10872 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010873
10874 nla_nest_end(msg, pinfoattr);
10875
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010876 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010877
10878 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10879 nl80211_mlme_mcgrp.id, gfp);
10880 return;
10881
10882 nla_put_failure:
10883 genlmsg_cancel(msg, hdr);
10884 nlmsg_free(msg);
10885}
Johannes Berg947add32013-02-22 22:05:20 +010010886EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010887
Johannes Berg7f6cf312011-11-04 11:18:15 +010010888void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10889 u64 cookie, bool acked, gfp_t gfp)
10890{
10891 struct wireless_dev *wdev = dev->ieee80211_ptr;
10892 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10893 struct sk_buff *msg;
10894 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010895
Beni Lev4ee3e062012-08-27 12:49:39 +030010896 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10897
Thomas Graf58050fc2012-06-28 03:57:45 +000010898 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010899
Johannes Berg7f6cf312011-11-04 11:18:15 +010010900 if (!msg)
10901 return;
10902
10903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10904 if (!hdr) {
10905 nlmsg_free(msg);
10906 return;
10907 }
10908
David S. Miller9360ffd2012-03-29 04:41:26 -040010909 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10910 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10911 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10912 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10913 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10914 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010915
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010916 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010917
10918 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10919 nl80211_mlme_mcgrp.id, gfp);
10920 return;
10921
10922 nla_put_failure:
10923 genlmsg_cancel(msg, hdr);
10924 nlmsg_free(msg);
10925}
10926EXPORT_SYMBOL(cfg80211_probe_status);
10927
Johannes Berg5e7602302011-11-04 11:18:17 +010010928void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10929 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010930 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010931{
10932 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10933 struct sk_buff *msg;
10934 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010935 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010936
Beni Lev4ee3e062012-08-27 12:49:39 +030010937 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10938
Ben Greear37c73b52012-10-26 14:49:25 -070010939 spin_lock_bh(&rdev->beacon_registrations_lock);
10940 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10941 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10942 if (!msg) {
10943 spin_unlock_bh(&rdev->beacon_registrations_lock);
10944 return;
10945 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010946
Ben Greear37c73b52012-10-26 14:49:25 -070010947 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10948 if (!hdr)
10949 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010950
Ben Greear37c73b52012-10-26 14:49:25 -070010951 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10952 (freq &&
10953 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10954 (sig_dbm &&
10955 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10956 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10957 goto nla_put_failure;
10958
10959 genlmsg_end(msg, hdr);
10960
10961 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010962 }
Ben Greear37c73b52012-10-26 14:49:25 -070010963 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010964 return;
10965
10966 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010967 spin_unlock_bh(&rdev->beacon_registrations_lock);
10968 if (hdr)
10969 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010970 nlmsg_free(msg);
10971}
10972EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10973
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010974#ifdef CONFIG_PM
10975void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10976 struct cfg80211_wowlan_wakeup *wakeup,
10977 gfp_t gfp)
10978{
10979 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10980 struct sk_buff *msg;
10981 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010982 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010983
10984 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10985
10986 if (wakeup)
10987 size += wakeup->packet_present_len;
10988
10989 msg = nlmsg_new(size, gfp);
10990 if (!msg)
10991 return;
10992
10993 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10994 if (!hdr)
10995 goto free_msg;
10996
10997 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10998 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10999 goto free_msg;
11000
11001 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11002 wdev->netdev->ifindex))
11003 goto free_msg;
11004
11005 if (wakeup) {
11006 struct nlattr *reasons;
11007
11008 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11009
11010 if (wakeup->disconnect &&
11011 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11012 goto free_msg;
11013 if (wakeup->magic_pkt &&
11014 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11015 goto free_msg;
11016 if (wakeup->gtk_rekey_failure &&
11017 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11018 goto free_msg;
11019 if (wakeup->eap_identity_req &&
11020 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11021 goto free_msg;
11022 if (wakeup->four_way_handshake &&
11023 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11024 goto free_msg;
11025 if (wakeup->rfkill_release &&
11026 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11027 goto free_msg;
11028
11029 if (wakeup->pattern_idx >= 0 &&
11030 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11031 wakeup->pattern_idx))
11032 goto free_msg;
11033
Johannes Berg2a0e0472013-01-23 22:57:40 +010011034 if (wakeup->tcp_match)
11035 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11036
11037 if (wakeup->tcp_connlost)
11038 nla_put_flag(msg,
11039 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11040
11041 if (wakeup->tcp_nomoretokens)
11042 nla_put_flag(msg,
11043 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11044
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011045 if (wakeup->packet) {
11046 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11047 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11048
11049 if (!wakeup->packet_80211) {
11050 pkt_attr =
11051 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11052 len_attr =
11053 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11054 }
11055
11056 if (wakeup->packet_len &&
11057 nla_put_u32(msg, len_attr, wakeup->packet_len))
11058 goto free_msg;
11059
11060 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11061 wakeup->packet))
11062 goto free_msg;
11063 }
11064
11065 nla_nest_end(msg, reasons);
11066 }
11067
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011068 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011069
11070 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11071 nl80211_mlme_mcgrp.id, gfp);
11072 return;
11073
11074 free_msg:
11075 nlmsg_free(msg);
11076}
11077EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11078#endif
11079
Jouni Malinen3475b092012-11-16 22:49:57 +020011080void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11081 enum nl80211_tdls_operation oper,
11082 u16 reason_code, gfp_t gfp)
11083{
11084 struct wireless_dev *wdev = dev->ieee80211_ptr;
11085 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11086 struct sk_buff *msg;
11087 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011088
11089 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11090 reason_code);
11091
11092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11093 if (!msg)
11094 return;
11095
11096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11097 if (!hdr) {
11098 nlmsg_free(msg);
11099 return;
11100 }
11101
11102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11103 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11104 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11105 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11106 (reason_code > 0 &&
11107 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11108 goto nla_put_failure;
11109
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011110 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011111
11112 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11113 nl80211_mlme_mcgrp.id, gfp);
11114 return;
11115
11116 nla_put_failure:
11117 genlmsg_cancel(msg, hdr);
11118 nlmsg_free(msg);
11119}
11120EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11121
Jouni Malinen026331c2010-02-15 12:53:10 +020011122static int nl80211_netlink_notify(struct notifier_block * nb,
11123 unsigned long state,
11124 void *_notify)
11125{
11126 struct netlink_notify *notify = _notify;
11127 struct cfg80211_registered_device *rdev;
11128 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011129 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011130
11131 if (state != NETLINK_URELEASE)
11132 return NOTIFY_DONE;
11133
11134 rcu_read_lock();
11135
Johannes Berg5e7602302011-11-04 11:18:17 +010011136 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011137 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011138 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011139
11140 spin_lock_bh(&rdev->beacon_registrations_lock);
11141 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11142 list) {
11143 if (reg->nlportid == notify->portid) {
11144 list_del(&reg->list);
11145 kfree(reg);
11146 break;
11147 }
11148 }
11149 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011150 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011151
11152 rcu_read_unlock();
11153
11154 return NOTIFY_DONE;
11155}
11156
11157static struct notifier_block nl80211_netlink_notifier = {
11158 .notifier_call = nl80211_netlink_notify,
11159};
11160
Jouni Malinen355199e2013-02-27 17:14:27 +020011161void cfg80211_ft_event(struct net_device *netdev,
11162 struct cfg80211_ft_event_params *ft_event)
11163{
11164 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11165 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11166 struct sk_buff *msg;
11167 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011168
11169 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11170
11171 if (!ft_event->target_ap)
11172 return;
11173
11174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11175 if (!msg)
11176 return;
11177
11178 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11179 if (!hdr) {
11180 nlmsg_free(msg);
11181 return;
11182 }
11183
11184 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11185 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11186 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11187 if (ft_event->ies)
11188 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11189 if (ft_event->ric_ies)
11190 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11191 ft_event->ric_ies);
11192
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011193 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011194
11195 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11196 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11197}
11198EXPORT_SYMBOL(cfg80211_ft_event);
11199
Arend van Spriel5de17982013-04-18 15:49:00 +020011200void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11201{
11202 struct cfg80211_registered_device *rdev;
11203 struct sk_buff *msg;
11204 void *hdr;
11205 u32 nlportid;
11206
11207 rdev = wiphy_to_dev(wdev->wiphy);
11208 if (!rdev->crit_proto_nlportid)
11209 return;
11210
11211 nlportid = rdev->crit_proto_nlportid;
11212 rdev->crit_proto_nlportid = 0;
11213
11214 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11215 if (!msg)
11216 return;
11217
11218 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11219 if (!hdr)
11220 goto nla_put_failure;
11221
11222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11223 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11224 goto nla_put_failure;
11225
11226 genlmsg_end(msg, hdr);
11227
11228 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11229 return;
11230
11231 nla_put_failure:
11232 if (hdr)
11233 genlmsg_cancel(msg, hdr);
11234 nlmsg_free(msg);
11235
11236}
11237EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11238
Johannes Berg55682962007-09-20 13:09:35 -040011239/* initialisation/exit functions */
11240
11241int nl80211_init(void)
11242{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011243 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011244
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011245 err = genl_register_family_with_ops(&nl80211_fam,
11246 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011247 if (err)
11248 return err;
11249
Johannes Berg55682962007-09-20 13:09:35 -040011250 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11251 if (err)
11252 goto err_out;
11253
Johannes Berg2a519312009-02-10 21:25:55 +010011254 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11255 if (err)
11256 goto err_out;
11257
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011258 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11259 if (err)
11260 goto err_out;
11261
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011262 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11263 if (err)
11264 goto err_out;
11265
Johannes Bergaff89a92009-07-01 21:26:51 +020011266#ifdef CONFIG_NL80211_TESTMODE
11267 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11268 if (err)
11269 goto err_out;
11270#endif
11271
Jouni Malinen026331c2010-02-15 12:53:10 +020011272 err = netlink_register_notifier(&nl80211_netlink_notifier);
11273 if (err)
11274 goto err_out;
11275
Johannes Berg55682962007-09-20 13:09:35 -040011276 return 0;
11277 err_out:
11278 genl_unregister_family(&nl80211_fam);
11279 return err;
11280}
11281
11282void nl80211_exit(void)
11283{
Jouni Malinen026331c2010-02-15 12:53:10 +020011284 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011285 genl_unregister_family(&nl80211_fam);
11286}