blob: a51269d2d48888834043fd0881e769cb5f623c44 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-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 Malinen36aedc92008-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 Malinen36aedc92008-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 Malinendc6382ce2009-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 Malinendc6382ce2009-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 Malinendc6382ce2009-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];
David Spinadelfc73f112013-07-31 18:04:15 +03006594 struct wireless_dev *wdev =
6595 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006596 int err;
6597
David Spinadelfc73f112013-07-31 18:04:15 +03006598 if (!rdev->ops->testmode_cmd)
6599 return -EOPNOTSUPP;
6600
6601 if (IS_ERR(wdev)) {
6602 err = PTR_ERR(wdev);
6603 if (err != -EINVAL)
6604 return err;
6605 wdev = NULL;
6606 } else if (wdev->wiphy != &rdev->wiphy) {
6607 return -EINVAL;
6608 }
6609
Johannes Bergaff89a92009-07-01 21:26:51 +02006610 if (!info->attrs[NL80211_ATTR_TESTDATA])
6611 return -EINVAL;
6612
David Spinadelfc73f112013-07-31 18:04:15 +03006613 rdev->testmode_info = info;
6614 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006615 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6616 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
David Spinadelfc73f112013-07-31 18:04:15 +03006617 rdev->testmode_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006618
Johannes Bergaff89a92009-07-01 21:26:51 +02006619 return err;
6620}
6621
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006622static int nl80211_testmode_dump(struct sk_buff *skb,
6623 struct netlink_callback *cb)
6624{
Johannes Berg00918d32011-12-13 17:22:05 +01006625 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006626 int err;
6627 long phy_idx;
6628 void *data = NULL;
6629 int data_len = 0;
6630
Johannes Berg5fe231e2013-05-08 21:45:15 +02006631 rtnl_lock();
6632
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006633 if (cb->args[0]) {
6634 /*
6635 * 0 is a valid index, but not valid for args[0],
6636 * so we need to offset by 1.
6637 */
6638 phy_idx = cb->args[0] - 1;
6639 } else {
6640 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6641 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6642 nl80211_policy);
6643 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006644 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006645
Johannes Berg2bd7e352012-06-15 14:23:16 +02006646 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6647 nl80211_fam.attrbuf);
6648 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006649 err = PTR_ERR(rdev);
6650 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006651 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006652 phy_idx = rdev->wiphy_idx;
6653 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006654
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006655 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6656 cb->args[1] =
6657 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6658 }
6659
6660 if (cb->args[1]) {
6661 data = nla_data((void *)cb->args[1]);
6662 data_len = nla_len((void *)cb->args[1]);
6663 }
6664
Johannes Berg00918d32011-12-13 17:22:05 +01006665 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6666 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006667 err = -ENOENT;
6668 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006669 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006670
Johannes Berg00918d32011-12-13 17:22:05 +01006671 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006672 err = -EOPNOTSUPP;
6673 goto out_err;
6674 }
6675
6676 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006677 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006678 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6679 NL80211_CMD_TESTMODE);
6680 struct nlattr *tmdata;
6681
David S. Miller9360ffd2012-03-29 04:41:26 -04006682 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006683 genlmsg_cancel(skb, hdr);
6684 break;
6685 }
6686
6687 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6688 if (!tmdata) {
6689 genlmsg_cancel(skb, hdr);
6690 break;
6691 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006692 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006693 nla_nest_end(skb, tmdata);
6694
6695 if (err == -ENOBUFS || err == -ENOENT) {
6696 genlmsg_cancel(skb, hdr);
6697 break;
6698 } else if (err) {
6699 genlmsg_cancel(skb, hdr);
6700 goto out_err;
6701 }
6702
6703 genlmsg_end(skb, hdr);
6704 }
6705
6706 err = skb->len;
6707 /* see above */
6708 cb->args[0] = phy_idx + 1;
6709 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006710 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006711 return err;
6712}
6713
Johannes Bergaff89a92009-07-01 21:26:51 +02006714static struct sk_buff *
6715__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006716 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006717{
6718 struct sk_buff *skb;
6719 void *hdr;
6720 struct nlattr *data;
6721
6722 skb = nlmsg_new(approxlen + 100, gfp);
6723 if (!skb)
6724 return NULL;
6725
Eric W. Biederman15e47302012-09-07 20:12:54 +00006726 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006727 if (!hdr) {
6728 kfree_skb(skb);
6729 return NULL;
6730 }
6731
David S. Miller9360ffd2012-03-29 04:41:26 -04006732 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6733 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006734 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6735
6736 ((void **)skb->cb)[0] = rdev;
6737 ((void **)skb->cb)[1] = hdr;
6738 ((void **)skb->cb)[2] = data;
6739
6740 return skb;
6741
6742 nla_put_failure:
6743 kfree_skb(skb);
6744 return NULL;
6745}
6746
6747struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6748 int approxlen)
6749{
6750 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6751
6752 if (WARN_ON(!rdev->testmode_info))
6753 return NULL;
6754
6755 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006756 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006757 rdev->testmode_info->snd_seq,
6758 GFP_KERNEL);
6759}
6760EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6761
6762int cfg80211_testmode_reply(struct sk_buff *skb)
6763{
6764 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6765 void *hdr = ((void **)skb->cb)[1];
6766 struct nlattr *data = ((void **)skb->cb)[2];
6767
6768 if (WARN_ON(!rdev->testmode_info)) {
6769 kfree_skb(skb);
6770 return -EINVAL;
6771 }
6772
6773 nla_nest_end(skb, data);
6774 genlmsg_end(skb, hdr);
6775 return genlmsg_reply(skb, rdev->testmode_info);
6776}
6777EXPORT_SYMBOL(cfg80211_testmode_reply);
6778
6779struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6780 int approxlen, gfp_t gfp)
6781{
6782 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6783
6784 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6785}
6786EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6787
6788void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6789{
6790 void *hdr = ((void **)skb->cb)[1];
6791 struct nlattr *data = ((void **)skb->cb)[2];
6792
6793 nla_nest_end(skb, data);
6794 genlmsg_end(skb, hdr);
6795 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6796}
6797EXPORT_SYMBOL(cfg80211_testmode_event);
6798#endif
6799
Samuel Ortizb23aa672009-07-01 21:26:54 +02006800static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6801{
Johannes Berg4c476992010-10-04 21:36:35 +02006802 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6803 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006804 struct cfg80211_connect_params connect;
6805 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006806 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006807 int err;
6808
6809 memset(&connect, 0, sizeof(connect));
6810
6811 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6812 return -EINVAL;
6813
6814 if (!info->attrs[NL80211_ATTR_SSID] ||
6815 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6816 return -EINVAL;
6817
6818 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6819 connect.auth_type =
6820 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006821 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6822 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006823 return -EINVAL;
6824 } else
6825 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6826
6827 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6828
Johannes Bergc0692b82010-08-27 14:26:53 +03006829 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006830 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006831 if (err)
6832 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006833
Johannes Berg074ac8d2010-09-16 14:58:22 +02006834 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006835 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6836 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006837
Johannes Berg79c97e92009-07-07 03:56:12 +02006838 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006839
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306840 connect.bg_scan_period = -1;
6841 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6842 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6843 connect.bg_scan_period =
6844 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6845 }
6846
Samuel Ortizb23aa672009-07-01 21:26:54 +02006847 if (info->attrs[NL80211_ATTR_MAC])
6848 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6849 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6850 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6851
6852 if (info->attrs[NL80211_ATTR_IE]) {
6853 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6854 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6855 }
6856
Jouni Malinencee00a92013-01-15 17:15:57 +02006857 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6858 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6859 if (connect.mfp != NL80211_MFP_REQUIRED &&
6860 connect.mfp != NL80211_MFP_NO)
6861 return -EINVAL;
6862 } else {
6863 connect.mfp = NL80211_MFP_NO;
6864 }
6865
Samuel Ortizb23aa672009-07-01 21:26:54 +02006866 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6867 connect.channel =
6868 ieee80211_get_channel(wiphy,
6869 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6870 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006871 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6872 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006873 }
6874
Johannes Bergfffd0932009-07-08 14:22:54 +02006875 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6876 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306877 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006878 if (IS_ERR(connkeys))
6879 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006880 }
6881
Ben Greear7e7c8922011-11-18 11:31:59 -08006882 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6883 connect.flags |= ASSOC_REQ_DISABLE_HT;
6884
6885 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6886 memcpy(&connect.ht_capa_mask,
6887 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6888 sizeof(connect.ht_capa_mask));
6889
6890 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006891 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6892 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006893 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006894 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006895 memcpy(&connect.ht_capa,
6896 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6897 sizeof(connect.ht_capa));
6898 }
6899
Johannes Bergee2aca32013-02-21 17:36:01 +01006900 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6901 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6902
6903 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6904 memcpy(&connect.vht_capa_mask,
6905 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6906 sizeof(connect.vht_capa_mask));
6907
6908 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6909 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6910 kfree(connkeys);
6911 return -EINVAL;
6912 }
6913 memcpy(&connect.vht_capa,
6914 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6915 sizeof(connect.vht_capa));
6916 }
6917
Johannes Berg83739b02013-05-15 17:44:01 +02006918 wdev_lock(dev->ieee80211_ptr);
6919 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6920 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006921 if (err)
6922 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006923 return err;
6924}
6925
6926static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6927{
Johannes Berg4c476992010-10-04 21:36:35 +02006928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6929 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006930 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006931 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006932
6933 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6934 reason = WLAN_REASON_DEAUTH_LEAVING;
6935 else
6936 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6937
6938 if (reason == 0)
6939 return -EINVAL;
6940
Johannes Berg074ac8d2010-09-16 14:58:22 +02006941 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006942 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6943 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006944
Johannes Berg83739b02013-05-15 17:44:01 +02006945 wdev_lock(dev->ieee80211_ptr);
6946 ret = cfg80211_disconnect(rdev, dev, reason, true);
6947 wdev_unlock(dev->ieee80211_ptr);
6948 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006949}
6950
Johannes Berg463d0182009-07-14 00:33:35 +02006951static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6952{
Johannes Berg4c476992010-10-04 21:36:35 +02006953 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006954 struct net *net;
6955 int err;
6956 u32 pid;
6957
6958 if (!info->attrs[NL80211_ATTR_PID])
6959 return -EINVAL;
6960
6961 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6962
Johannes Berg463d0182009-07-14 00:33:35 +02006963 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006964 if (IS_ERR(net))
6965 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006966
6967 err = 0;
6968
6969 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006970 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6971 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006972
Johannes Berg463d0182009-07-14 00:33:35 +02006973 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006974 return err;
6975}
6976
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006977static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6978{
Johannes Berg4c476992010-10-04 21:36:35 +02006979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006980 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6981 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006982 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006983 struct cfg80211_pmksa pmksa;
6984
6985 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6986
6987 if (!info->attrs[NL80211_ATTR_MAC])
6988 return -EINVAL;
6989
6990 if (!info->attrs[NL80211_ATTR_PMKID])
6991 return -EINVAL;
6992
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006993 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6994 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6995
Johannes Berg074ac8d2010-09-16 14:58:22 +02006996 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006997 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6998 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006999
7000 switch (info->genlhdr->cmd) {
7001 case NL80211_CMD_SET_PMKSA:
7002 rdev_ops = rdev->ops->set_pmksa;
7003 break;
7004 case NL80211_CMD_DEL_PMKSA:
7005 rdev_ops = rdev->ops->del_pmksa;
7006 break;
7007 default:
7008 WARN_ON(1);
7009 break;
7010 }
7011
Johannes Berg4c476992010-10-04 21:36:35 +02007012 if (!rdev_ops)
7013 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007014
Johannes Berg4c476992010-10-04 21:36:35 +02007015 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007016}
7017
7018static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7019{
Johannes Berg4c476992010-10-04 21:36:35 +02007020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7021 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007022
Johannes Berg074ac8d2010-09-16 14:58:22 +02007023 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007024 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7025 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007026
Johannes Berg4c476992010-10-04 21:36:35 +02007027 if (!rdev->ops->flush_pmksa)
7028 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007029
Hila Gonene35e4d22012-06-27 17:19:42 +03007030 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007031}
7032
Arik Nemtsov109086c2011-09-28 14:12:50 +03007033static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7034{
7035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7036 struct net_device *dev = info->user_ptr[1];
7037 u8 action_code, dialog_token;
7038 u16 status_code;
7039 u8 *peer;
7040
7041 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7042 !rdev->ops->tdls_mgmt)
7043 return -EOPNOTSUPP;
7044
7045 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7046 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7047 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7048 !info->attrs[NL80211_ATTR_IE] ||
7049 !info->attrs[NL80211_ATTR_MAC])
7050 return -EINVAL;
7051
7052 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7053 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7054 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7055 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7056
Hila Gonene35e4d22012-06-27 17:19:42 +03007057 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7058 dialog_token, status_code,
7059 nla_data(info->attrs[NL80211_ATTR_IE]),
7060 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007061}
7062
7063static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7064{
7065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7066 struct net_device *dev = info->user_ptr[1];
7067 enum nl80211_tdls_operation operation;
7068 u8 *peer;
7069
7070 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7071 !rdev->ops->tdls_oper)
7072 return -EOPNOTSUPP;
7073
7074 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7075 !info->attrs[NL80211_ATTR_MAC])
7076 return -EINVAL;
7077
7078 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7079 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7080
Hila Gonene35e4d22012-06-27 17:19:42 +03007081 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007082}
7083
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007084static int nl80211_remain_on_channel(struct sk_buff *skb,
7085 struct genl_info *info)
7086{
Johannes Berg4c476992010-10-04 21:36:35 +02007087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007088 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007089 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007090 struct sk_buff *msg;
7091 void *hdr;
7092 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007093 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007094 int err;
7095
7096 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7097 !info->attrs[NL80211_ATTR_DURATION])
7098 return -EINVAL;
7099
7100 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7101
Johannes Berg7c4ef712011-11-18 15:33:48 +01007102 if (!rdev->ops->remain_on_channel ||
7103 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007104 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007105
Johannes Bergebf348f2012-06-01 12:50:54 +02007106 /*
7107 * We should be on that channel for at least a minimum amount of
7108 * time (10ms) but no longer than the driver supports.
7109 */
7110 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7111 duration > rdev->wiphy.max_remain_on_channel_duration)
7112 return -EINVAL;
7113
Johannes Berg683b6d32012-11-08 21:25:48 +01007114 err = nl80211_parse_chandef(rdev, info, &chandef);
7115 if (err)
7116 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007117
7118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007119 if (!msg)
7120 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007121
Eric W. Biederman15e47302012-09-07 20:12:54 +00007122 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007123 NL80211_CMD_REMAIN_ON_CHANNEL);
7124
7125 if (IS_ERR(hdr)) {
7126 err = PTR_ERR(hdr);
7127 goto free_msg;
7128 }
7129
Johannes Berg683b6d32012-11-08 21:25:48 +01007130 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7131 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007132
7133 if (err)
7134 goto free_msg;
7135
David S. Miller9360ffd2012-03-29 04:41:26 -04007136 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7137 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007138
7139 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007140
7141 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007142
7143 nla_put_failure:
7144 err = -ENOBUFS;
7145 free_msg:
7146 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007147 return err;
7148}
7149
7150static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7151 struct genl_info *info)
7152{
Johannes Berg4c476992010-10-04 21:36:35 +02007153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007154 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007155 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007156
7157 if (!info->attrs[NL80211_ATTR_COOKIE])
7158 return -EINVAL;
7159
Johannes Berg4c476992010-10-04 21:36:35 +02007160 if (!rdev->ops->cancel_remain_on_channel)
7161 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007162
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007163 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7164
Hila Gonene35e4d22012-06-27 17:19:42 +03007165 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007166}
7167
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007168static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7169 u8 *rates, u8 rates_len)
7170{
7171 u8 i;
7172 u32 mask = 0;
7173
7174 for (i = 0; i < rates_len; i++) {
7175 int rate = (rates[i] & 0x7f) * 5;
7176 int ridx;
7177 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7178 struct ieee80211_rate *srate =
7179 &sband->bitrates[ridx];
7180 if (rate == srate->bitrate) {
7181 mask |= 1 << ridx;
7182 break;
7183 }
7184 }
7185 if (ridx == sband->n_bitrates)
7186 return 0; /* rate not found */
7187 }
7188
7189 return mask;
7190}
7191
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007192static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7193 u8 *rates, u8 rates_len,
7194 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7195{
7196 u8 i;
7197
7198 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7199
7200 for (i = 0; i < rates_len; i++) {
7201 int ridx, rbit;
7202
7203 ridx = rates[i] / 8;
7204 rbit = BIT(rates[i] % 8);
7205
7206 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007207 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007208 return false;
7209
7210 /* check availability */
7211 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7212 mcs[ridx] |= rbit;
7213 else
7214 return false;
7215 }
7216
7217 return true;
7218}
7219
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007220static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007221 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7222 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007223 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7224 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007225};
7226
7227static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7228 struct genl_info *info)
7229{
7230 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007232 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007233 int rem, i;
7234 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007235 struct nlattr *tx_rates;
7236 struct ieee80211_supported_band *sband;
7237
7238 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7239 return -EINVAL;
7240
Johannes Berg4c476992010-10-04 21:36:35 +02007241 if (!rdev->ops->set_bitrate_mask)
7242 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007243
7244 memset(&mask, 0, sizeof(mask));
7245 /* Default to all rates enabled */
7246 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7247 sband = rdev->wiphy.bands[i];
7248 mask.control[i].legacy =
7249 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007250 if (sband)
7251 memcpy(mask.control[i].mcs,
7252 sband->ht_cap.mcs.rx_mask,
7253 sizeof(mask.control[i].mcs));
7254 else
7255 memset(mask.control[i].mcs, 0,
7256 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007257 }
7258
7259 /*
7260 * The nested attribute uses enum nl80211_band as the index. This maps
7261 * directly to the enum ieee80211_band values used in cfg80211.
7262 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007263 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007264 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7265 {
7266 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007267 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7268 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007269 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007270 if (sband == NULL)
7271 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007272 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7273 nla_len(tx_rates), nl80211_txattr_policy);
7274 if (tb[NL80211_TXRATE_LEGACY]) {
7275 mask.control[band].legacy = rateset_to_mask(
7276 sband,
7277 nla_data(tb[NL80211_TXRATE_LEGACY]),
7278 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307279 if ((mask.control[band].legacy == 0) &&
7280 nla_len(tb[NL80211_TXRATE_LEGACY]))
7281 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007282 }
7283 if (tb[NL80211_TXRATE_MCS]) {
7284 if (!ht_rateset_to_mask(
7285 sband,
7286 nla_data(tb[NL80211_TXRATE_MCS]),
7287 nla_len(tb[NL80211_TXRATE_MCS]),
7288 mask.control[band].mcs))
7289 return -EINVAL;
7290 }
7291
7292 if (mask.control[band].legacy == 0) {
7293 /* don't allow empty legacy rates if HT
7294 * is not even supported. */
7295 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7296 return -EINVAL;
7297
7298 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7299 if (mask.control[band].mcs[i])
7300 break;
7301
7302 /* legacy and mcs rates may not be both empty */
7303 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007304 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007305 }
7306 }
7307
Hila Gonene35e4d22012-06-27 17:19:42 +03007308 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007309}
7310
Johannes Berg2e161f72010-08-12 15:38:38 +02007311static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007312{
Johannes Berg4c476992010-10-04 21:36:35 +02007313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007314 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007315 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007316
7317 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7318 return -EINVAL;
7319
Johannes Berg2e161f72010-08-12 15:38:38 +02007320 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7321 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007322
Johannes Berg71bbc992012-06-15 15:30:18 +02007323 switch (wdev->iftype) {
7324 case NL80211_IFTYPE_STATION:
7325 case NL80211_IFTYPE_ADHOC:
7326 case NL80211_IFTYPE_P2P_CLIENT:
7327 case NL80211_IFTYPE_AP:
7328 case NL80211_IFTYPE_AP_VLAN:
7329 case NL80211_IFTYPE_MESH_POINT:
7330 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007331 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007332 break;
7333 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007334 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007335 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007336
7337 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007338 if (!rdev->ops->mgmt_tx)
7339 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007340
Eric W. Biederman15e47302012-09-07 20:12:54 +00007341 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007342 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7343 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007344}
7345
Johannes Berg2e161f72010-08-12 15:38:38 +02007346static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007347{
Johannes Berg4c476992010-10-04 21:36:35 +02007348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007349 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007350 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007351 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007352 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007353 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007354 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007355 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007356 bool offchan, no_cck, dont_wait_for_ack;
7357
7358 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007359
Johannes Berg683b6d32012-11-08 21:25:48 +01007360 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007361 return -EINVAL;
7362
Johannes Berg4c476992010-10-04 21:36:35 +02007363 if (!rdev->ops->mgmt_tx)
7364 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007365
Johannes Berg71bbc992012-06-15 15:30:18 +02007366 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007367 case NL80211_IFTYPE_P2P_DEVICE:
7368 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7369 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007370 case NL80211_IFTYPE_STATION:
7371 case NL80211_IFTYPE_ADHOC:
7372 case NL80211_IFTYPE_P2P_CLIENT:
7373 case NL80211_IFTYPE_AP:
7374 case NL80211_IFTYPE_AP_VLAN:
7375 case NL80211_IFTYPE_MESH_POINT:
7376 case NL80211_IFTYPE_P2P_GO:
7377 break;
7378 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007379 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007380 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007381
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007382 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007383 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007384 return -EINVAL;
7385 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007386
7387 /*
7388 * We should wait on the channel for at least a minimum amount
7389 * of time (10ms) but no longer than the driver supports.
7390 */
7391 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7392 wait > rdev->wiphy.max_remain_on_channel_duration)
7393 return -EINVAL;
7394
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007395 }
7396
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007397 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7398
Johannes Berg7c4ef712011-11-18 15:33:48 +01007399 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7400 return -EINVAL;
7401
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307402 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7403
Antonio Quartulliea141b752013-06-11 14:20:03 +02007404 /* get the channel if any has been specified, otherwise pass NULL to
7405 * the driver. The latter will use the current one
7406 */
7407 chandef.chan = NULL;
7408 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7409 err = nl80211_parse_chandef(rdev, info, &chandef);
7410 if (err)
7411 return err;
7412 }
7413
7414 if (!chandef.chan && offchan)
7415 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007416
Johannes Berge247bd902011-11-04 11:18:21 +01007417 if (!dont_wait_for_ack) {
7418 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7419 if (!msg)
7420 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007421
Eric W. Biederman15e47302012-09-07 20:12:54 +00007422 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007423 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007424
Johannes Berge247bd902011-11-04 11:18:21 +01007425 if (IS_ERR(hdr)) {
7426 err = PTR_ERR(hdr);
7427 goto free_msg;
7428 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007429 }
Johannes Berge247bd902011-11-04 11:18:21 +01007430
Johannes Berg683b6d32012-11-08 21:25:48 +01007431 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007432 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7433 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007434 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007435 if (err)
7436 goto free_msg;
7437
Johannes Berge247bd902011-11-04 11:18:21 +01007438 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007439 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7440 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007441
Johannes Berge247bd902011-11-04 11:18:21 +01007442 genlmsg_end(msg, hdr);
7443 return genlmsg_reply(msg, info);
7444 }
7445
7446 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007447
7448 nla_put_failure:
7449 err = -ENOBUFS;
7450 free_msg:
7451 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007452 return err;
7453}
7454
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007455static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7456{
7457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007458 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007459 u64 cookie;
7460
7461 if (!info->attrs[NL80211_ATTR_COOKIE])
7462 return -EINVAL;
7463
7464 if (!rdev->ops->mgmt_tx_cancel_wait)
7465 return -EOPNOTSUPP;
7466
Johannes Berg71bbc992012-06-15 15:30:18 +02007467 switch (wdev->iftype) {
7468 case NL80211_IFTYPE_STATION:
7469 case NL80211_IFTYPE_ADHOC:
7470 case NL80211_IFTYPE_P2P_CLIENT:
7471 case NL80211_IFTYPE_AP:
7472 case NL80211_IFTYPE_AP_VLAN:
7473 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007474 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007475 break;
7476 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007477 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007478 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007479
7480 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7481
Hila Gonene35e4d22012-06-27 17:19:42 +03007482 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007483}
7484
Kalle Valoffb9eb32010-02-17 17:58:10 +02007485static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7486{
Johannes Berg4c476992010-10-04 21:36:35 +02007487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007488 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007489 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007490 u8 ps_state;
7491 bool state;
7492 int err;
7493
Johannes Berg4c476992010-10-04 21:36:35 +02007494 if (!info->attrs[NL80211_ATTR_PS_STATE])
7495 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007496
7497 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7498
Johannes Berg4c476992010-10-04 21:36:35 +02007499 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7500 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007501
7502 wdev = dev->ieee80211_ptr;
7503
Johannes Berg4c476992010-10-04 21:36:35 +02007504 if (!rdev->ops->set_power_mgmt)
7505 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007506
7507 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7508
7509 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007510 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007511
Hila Gonene35e4d22012-06-27 17:19:42 +03007512 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007513 if (!err)
7514 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007515 return err;
7516}
7517
7518static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7519{
Johannes Berg4c476992010-10-04 21:36:35 +02007520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007521 enum nl80211_ps_state ps_state;
7522 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007523 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007524 struct sk_buff *msg;
7525 void *hdr;
7526 int err;
7527
Kalle Valoffb9eb32010-02-17 17:58:10 +02007528 wdev = dev->ieee80211_ptr;
7529
Johannes Berg4c476992010-10-04 21:36:35 +02007530 if (!rdev->ops->set_power_mgmt)
7531 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007532
7533 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007534 if (!msg)
7535 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007536
Eric W. Biederman15e47302012-09-07 20:12:54 +00007537 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007538 NL80211_CMD_GET_POWER_SAVE);
7539 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007540 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007541 goto free_msg;
7542 }
7543
7544 if (wdev->ps)
7545 ps_state = NL80211_PS_ENABLED;
7546 else
7547 ps_state = NL80211_PS_DISABLED;
7548
David S. Miller9360ffd2012-03-29 04:41:26 -04007549 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7550 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007551
7552 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007553 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007554
Johannes Berg4c476992010-10-04 21:36:35 +02007555 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007556 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007557 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007558 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007559 return err;
7560}
7561
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007562static struct nla_policy
7563nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7564 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7565 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7566 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007567 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7568 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7569 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007570};
7571
Thomas Pedersen84f10702012-07-12 16:17:33 -07007572static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007573 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007574{
7575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007576 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007577 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007578
Johannes Bergd9d8b012012-11-26 12:51:52 +01007579 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007580 return -EINVAL;
7581
Thomas Pedersen84f10702012-07-12 16:17:33 -07007582 if (!rdev->ops->set_cqm_txe_config)
7583 return -EOPNOTSUPP;
7584
7585 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7586 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7587 return -EOPNOTSUPP;
7588
Hila Gonene35e4d22012-06-27 17:19:42 +03007589 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007590}
7591
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007592static int nl80211_set_cqm_rssi(struct genl_info *info,
7593 s32 threshold, u32 hysteresis)
7594{
Johannes Berg4c476992010-10-04 21:36:35 +02007595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007596 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007597 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007598
7599 if (threshold > 0)
7600 return -EINVAL;
7601
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007602 /* disabling - hysteresis should also be zero then */
7603 if (threshold == 0)
7604 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007605
Johannes Berg4c476992010-10-04 21:36:35 +02007606 if (!rdev->ops->set_cqm_rssi_config)
7607 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007608
Johannes Berg074ac8d2010-09-16 14:58:22 +02007609 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007610 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7611 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007612
Hila Gonene35e4d22012-06-27 17:19:42 +03007613 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007614}
7615
7616static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7617{
7618 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7619 struct nlattr *cqm;
7620 int err;
7621
7622 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007623 if (!cqm)
7624 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007625
7626 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7627 nl80211_attr_cqm_policy);
7628 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007629 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007630
7631 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7632 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007633 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7634 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007635
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007636 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7637 }
7638
7639 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7640 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7641 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7642 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7643 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7644 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7645
7646 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7647 }
7648
7649 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007650}
7651
Johannes Berg29cbe682010-12-03 09:20:44 +01007652static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7653{
7654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7655 struct net_device *dev = info->user_ptr[1];
7656 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007657 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007658 int err;
7659
7660 /* start with default */
7661 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007662 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007663
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007664 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007665 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007666 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007667 if (err)
7668 return err;
7669 }
7670
7671 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7672 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7673 return -EINVAL;
7674
Javier Cardonac80d5452010-12-16 17:37:49 -08007675 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7676 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7677
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007678 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7679 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7680 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7681 return -EINVAL;
7682
Marco Porsch9bdbf042013-01-07 16:04:51 +01007683 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7684 setup.beacon_interval =
7685 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7686 if (setup.beacon_interval < 10 ||
7687 setup.beacon_interval > 10000)
7688 return -EINVAL;
7689 }
7690
7691 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7692 setup.dtim_period =
7693 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7694 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7695 return -EINVAL;
7696 }
7697
Javier Cardonac80d5452010-12-16 17:37:49 -08007698 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7699 /* parse additional setup parameters if given */
7700 err = nl80211_parse_mesh_setup(info, &setup);
7701 if (err)
7702 return err;
7703 }
7704
Thomas Pedersend37bb182013-03-04 13:06:13 -08007705 if (setup.user_mpm)
7706 cfg.auto_open_plinks = false;
7707
Johannes Bergcc1d2802012-05-16 23:50:20 +02007708 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007709 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7710 if (err)
7711 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007712 } else {
7713 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007714 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007715 }
7716
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007717 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7718 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7719 int n_rates =
7720 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7721 struct ieee80211_supported_band *sband;
7722
7723 if (!setup.chandef.chan)
7724 return -EINVAL;
7725
7726 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7727
7728 err = ieee80211_get_ratemask(sband, rates, n_rates,
7729 &setup.basic_rates);
7730 if (err)
7731 return err;
7732 }
7733
Javier Cardonac80d5452010-12-16 17:37:49 -08007734 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007735}
7736
7737static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7738{
7739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7740 struct net_device *dev = info->user_ptr[1];
7741
7742 return cfg80211_leave_mesh(rdev, dev);
7743}
7744
Johannes Bergdfb89c52012-06-27 09:23:48 +02007745#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007746static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7747 struct cfg80211_registered_device *rdev)
7748{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007749 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007750 struct nlattr *nl_pats, *nl_pat;
7751 int i, pat_len;
7752
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007753 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007754 return 0;
7755
7756 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7757 if (!nl_pats)
7758 return -ENOBUFS;
7759
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007760 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007761 nl_pat = nla_nest_start(msg, i + 1);
7762 if (!nl_pat)
7763 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007764 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007765 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007766 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007767 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7768 wowlan->patterns[i].pattern) ||
7769 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007770 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007771 return -ENOBUFS;
7772 nla_nest_end(msg, nl_pat);
7773 }
7774 nla_nest_end(msg, nl_pats);
7775
7776 return 0;
7777}
7778
Johannes Berg2a0e0472013-01-23 22:57:40 +01007779static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7780 struct cfg80211_wowlan_tcp *tcp)
7781{
7782 struct nlattr *nl_tcp;
7783
7784 if (!tcp)
7785 return 0;
7786
7787 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7788 if (!nl_tcp)
7789 return -ENOBUFS;
7790
7791 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7792 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7793 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7794 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7795 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7796 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7797 tcp->payload_len, tcp->payload) ||
7798 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7799 tcp->data_interval) ||
7800 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7801 tcp->wake_len, tcp->wake_data) ||
7802 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7803 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7804 return -ENOBUFS;
7805
7806 if (tcp->payload_seq.len &&
7807 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7808 sizeof(tcp->payload_seq), &tcp->payload_seq))
7809 return -ENOBUFS;
7810
7811 if (tcp->payload_tok.len &&
7812 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7813 sizeof(tcp->payload_tok) + tcp->tokens_size,
7814 &tcp->payload_tok))
7815 return -ENOBUFS;
7816
Johannes Berge248ad32013-05-16 10:24:28 +02007817 nla_nest_end(msg, nl_tcp);
7818
Johannes Berg2a0e0472013-01-23 22:57:40 +01007819 return 0;
7820}
7821
Johannes Bergff1b6e62011-05-04 15:37:28 +02007822static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7823{
7824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7825 struct sk_buff *msg;
7826 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007827 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007828
Johannes Berg964dc9e2013-06-03 17:25:34 +02007829 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007830 return -EOPNOTSUPP;
7831
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007832 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007833 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007834 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7835 rdev->wiphy.wowlan_config->tcp->payload_len +
7836 rdev->wiphy.wowlan_config->tcp->wake_len +
7837 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007838 }
7839
7840 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007841 if (!msg)
7842 return -ENOMEM;
7843
Eric W. Biederman15e47302012-09-07 20:12:54 +00007844 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007845 NL80211_CMD_GET_WOWLAN);
7846 if (!hdr)
7847 goto nla_put_failure;
7848
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007849 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007850 struct nlattr *nl_wowlan;
7851
7852 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7853 if (!nl_wowlan)
7854 goto nla_put_failure;
7855
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007856 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007857 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007858 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007859 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007860 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007861 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007862 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007863 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007864 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007865 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007866 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007867 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007868 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007869 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7870 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007871
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007872 if (nl80211_send_wowlan_patterns(msg, rdev))
7873 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007874
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007875 if (nl80211_send_wowlan_tcp(msg,
7876 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007877 goto nla_put_failure;
7878
Johannes Bergff1b6e62011-05-04 15:37:28 +02007879 nla_nest_end(msg, nl_wowlan);
7880 }
7881
7882 genlmsg_end(msg, hdr);
7883 return genlmsg_reply(msg, info);
7884
7885nla_put_failure:
7886 nlmsg_free(msg);
7887 return -ENOBUFS;
7888}
7889
Johannes Berg2a0e0472013-01-23 22:57:40 +01007890static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7891 struct nlattr *attr,
7892 struct cfg80211_wowlan *trig)
7893{
7894 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7895 struct cfg80211_wowlan_tcp *cfg;
7896 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7897 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7898 u32 size;
7899 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7900 int err, port;
7901
Johannes Berg964dc9e2013-06-03 17:25:34 +02007902 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007903 return -EINVAL;
7904
7905 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7906 nla_data(attr), nla_len(attr),
7907 nl80211_wowlan_tcp_policy);
7908 if (err)
7909 return err;
7910
7911 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7912 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7913 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7914 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7915 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7916 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7917 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7918 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7919 return -EINVAL;
7920
7921 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007922 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007923 return -EINVAL;
7924
7925 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007926 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007927 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007928 return -EINVAL;
7929
7930 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007931 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007932 return -EINVAL;
7933
7934 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7935 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7936 return -EINVAL;
7937
7938 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7939 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7940
7941 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7942 tokens_size = tokln - sizeof(*tok);
7943
7944 if (!tok->len || tokens_size % tok->len)
7945 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007946 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007947 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007948 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007949 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007950 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007951 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007952 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007953 return -EINVAL;
7954 if (tok->offset + tok->len > data_size)
7955 return -EINVAL;
7956 }
7957
7958 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7959 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007960 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007961 return -EINVAL;
7962 if (seq->len == 0 || seq->len > 4)
7963 return -EINVAL;
7964 if (seq->len + seq->offset > data_size)
7965 return -EINVAL;
7966 }
7967
7968 size = sizeof(*cfg);
7969 size += data_size;
7970 size += wake_size + wake_mask_size;
7971 size += tokens_size;
7972
7973 cfg = kzalloc(size, GFP_KERNEL);
7974 if (!cfg)
7975 return -ENOMEM;
7976 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7977 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7978 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7979 ETH_ALEN);
7980 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7981 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7982 else
7983 port = 0;
7984#ifdef CONFIG_INET
7985 /* allocate a socket and port for it and use it */
7986 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7987 IPPROTO_TCP, &cfg->sock, 1);
7988 if (err) {
7989 kfree(cfg);
7990 return err;
7991 }
7992 if (inet_csk_get_port(cfg->sock->sk, port)) {
7993 sock_release(cfg->sock);
7994 kfree(cfg);
7995 return -EADDRINUSE;
7996 }
7997 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7998#else
7999 if (!port) {
8000 kfree(cfg);
8001 return -EINVAL;
8002 }
8003 cfg->src_port = port;
8004#endif
8005
8006 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8007 cfg->payload_len = data_size;
8008 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8009 memcpy((void *)cfg->payload,
8010 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8011 data_size);
8012 if (seq)
8013 cfg->payload_seq = *seq;
8014 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8015 cfg->wake_len = wake_size;
8016 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8017 memcpy((void *)cfg->wake_data,
8018 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8019 wake_size);
8020 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8021 data_size + wake_size;
8022 memcpy((void *)cfg->wake_mask,
8023 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8024 wake_mask_size);
8025 if (tok) {
8026 cfg->tokens_size = tokens_size;
8027 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8028 }
8029
8030 trig->tcp = cfg;
8031
8032 return 0;
8033}
8034
Johannes Bergff1b6e62011-05-04 15:37:28 +02008035static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8036{
8037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8038 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008039 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008040 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008041 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008042 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008043 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008044
Johannes Berg964dc9e2013-06-03 17:25:34 +02008045 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008046 return -EOPNOTSUPP;
8047
Johannes Bergae33bd82012-07-12 16:25:02 +02008048 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8049 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008050 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008051 goto set_wakeup;
8052 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008053
8054 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8055 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8056 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8057 nl80211_wowlan_policy);
8058 if (err)
8059 return err;
8060
8061 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8062 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8063 return -EINVAL;
8064 new_triggers.any = true;
8065 }
8066
8067 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8068 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8069 return -EINVAL;
8070 new_triggers.disconnect = true;
8071 }
8072
8073 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8074 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8075 return -EINVAL;
8076 new_triggers.magic_pkt = true;
8077 }
8078
Johannes Berg77dbbb12011-07-13 10:48:55 +02008079 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8080 return -EINVAL;
8081
8082 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8083 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8084 return -EINVAL;
8085 new_triggers.gtk_rekey_failure = true;
8086 }
8087
8088 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8089 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8090 return -EINVAL;
8091 new_triggers.eap_identity_req = true;
8092 }
8093
8094 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8095 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8096 return -EINVAL;
8097 new_triggers.four_way_handshake = true;
8098 }
8099
8100 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8101 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8102 return -EINVAL;
8103 new_triggers.rfkill_release = true;
8104 }
8105
Johannes Bergff1b6e62011-05-04 15:37:28 +02008106 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8107 struct nlattr *pat;
8108 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008109 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008110 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008111
8112 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8113 rem)
8114 n_patterns++;
8115 if (n_patterns > wowlan->n_patterns)
8116 return -EINVAL;
8117
8118 new_triggers.patterns = kcalloc(n_patterns,
8119 sizeof(new_triggers.patterns[0]),
8120 GFP_KERNEL);
8121 if (!new_triggers.patterns)
8122 return -ENOMEM;
8123
8124 new_triggers.n_patterns = n_patterns;
8125 i = 0;
8126
8127 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8128 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008129 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8130 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008131 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008132 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8133 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008134 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008135 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008136 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008137 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008138 goto error;
8139 if (pat_len > wowlan->pattern_max_len ||
8140 pat_len < wowlan->pattern_min_len)
8141 goto error;
8142
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008143 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008144 pkt_offset = 0;
8145 else
8146 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008147 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008148 if (pkt_offset > wowlan->max_pkt_offset)
8149 goto error;
8150 new_triggers.patterns[i].pkt_offset = pkt_offset;
8151
Johannes Bergff1b6e62011-05-04 15:37:28 +02008152 new_triggers.patterns[i].mask =
8153 kmalloc(mask_len + pat_len, GFP_KERNEL);
8154 if (!new_triggers.patterns[i].mask) {
8155 err = -ENOMEM;
8156 goto error;
8157 }
8158 new_triggers.patterns[i].pattern =
8159 new_triggers.patterns[i].mask + mask_len;
8160 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008161 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008162 mask_len);
8163 new_triggers.patterns[i].pattern_len = pat_len;
8164 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008165 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008166 pat_len);
8167 i++;
8168 }
8169 }
8170
Johannes Berg2a0e0472013-01-23 22:57:40 +01008171 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8172 err = nl80211_parse_wowlan_tcp(
8173 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8174 &new_triggers);
8175 if (err)
8176 goto error;
8177 }
8178
Johannes Bergae33bd82012-07-12 16:25:02 +02008179 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8180 if (!ntrig) {
8181 err = -ENOMEM;
8182 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008183 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008184 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008185 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008186
Johannes Bergae33bd82012-07-12 16:25:02 +02008187 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008188 if (rdev->ops->set_wakeup &&
8189 prev_enabled != !!rdev->wiphy.wowlan_config)
8190 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008191
Johannes Bergff1b6e62011-05-04 15:37:28 +02008192 return 0;
8193 error:
8194 for (i = 0; i < new_triggers.n_patterns; i++)
8195 kfree(new_triggers.patterns[i].mask);
8196 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008197 if (new_triggers.tcp && new_triggers.tcp->sock)
8198 sock_release(new_triggers.tcp->sock);
8199 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008200 return err;
8201}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008202#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008203
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008204static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8205 struct cfg80211_registered_device *rdev)
8206{
8207 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8208 int i, j, pat_len;
8209 struct cfg80211_coalesce_rules *rule;
8210
8211 if (!rdev->coalesce->n_rules)
8212 return 0;
8213
8214 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8215 if (!nl_rules)
8216 return -ENOBUFS;
8217
8218 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8219 nl_rule = nla_nest_start(msg, i + 1);
8220 if (!nl_rule)
8221 return -ENOBUFS;
8222
8223 rule = &rdev->coalesce->rules[i];
8224 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8225 rule->delay))
8226 return -ENOBUFS;
8227
8228 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8229 rule->condition))
8230 return -ENOBUFS;
8231
8232 nl_pats = nla_nest_start(msg,
8233 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8234 if (!nl_pats)
8235 return -ENOBUFS;
8236
8237 for (j = 0; j < rule->n_patterns; j++) {
8238 nl_pat = nla_nest_start(msg, j + 1);
8239 if (!nl_pat)
8240 return -ENOBUFS;
8241 pat_len = rule->patterns[j].pattern_len;
8242 if (nla_put(msg, NL80211_PKTPAT_MASK,
8243 DIV_ROUND_UP(pat_len, 8),
8244 rule->patterns[j].mask) ||
8245 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8246 rule->patterns[j].pattern) ||
8247 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8248 rule->patterns[j].pkt_offset))
8249 return -ENOBUFS;
8250 nla_nest_end(msg, nl_pat);
8251 }
8252 nla_nest_end(msg, nl_pats);
8253 nla_nest_end(msg, nl_rule);
8254 }
8255 nla_nest_end(msg, nl_rules);
8256
8257 return 0;
8258}
8259
8260static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8261{
8262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8263 struct sk_buff *msg;
8264 void *hdr;
8265
8266 if (!rdev->wiphy.coalesce)
8267 return -EOPNOTSUPP;
8268
8269 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8270 if (!msg)
8271 return -ENOMEM;
8272
8273 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8274 NL80211_CMD_GET_COALESCE);
8275 if (!hdr)
8276 goto nla_put_failure;
8277
8278 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8279 goto nla_put_failure;
8280
8281 genlmsg_end(msg, hdr);
8282 return genlmsg_reply(msg, info);
8283
8284nla_put_failure:
8285 nlmsg_free(msg);
8286 return -ENOBUFS;
8287}
8288
8289void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8290{
8291 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8292 int i, j;
8293 struct cfg80211_coalesce_rules *rule;
8294
8295 if (!coalesce)
8296 return;
8297
8298 for (i = 0; i < coalesce->n_rules; i++) {
8299 rule = &coalesce->rules[i];
8300 for (j = 0; j < rule->n_patterns; j++)
8301 kfree(rule->patterns[j].mask);
8302 kfree(rule->patterns);
8303 }
8304 kfree(coalesce->rules);
8305 kfree(coalesce);
8306 rdev->coalesce = NULL;
8307}
8308
8309static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8310 struct nlattr *rule,
8311 struct cfg80211_coalesce_rules *new_rule)
8312{
8313 int err, i;
8314 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8315 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8316 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8317 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8318
8319 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8320 nla_len(rule), nl80211_coalesce_policy);
8321 if (err)
8322 return err;
8323
8324 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8325 new_rule->delay =
8326 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8327 if (new_rule->delay > coalesce->max_delay)
8328 return -EINVAL;
8329
8330 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8331 new_rule->condition =
8332 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8333 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8334 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8335 return -EINVAL;
8336
8337 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8338 return -EINVAL;
8339
8340 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8341 rem)
8342 n_patterns++;
8343 if (n_patterns > coalesce->n_patterns)
8344 return -EINVAL;
8345
8346 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8347 GFP_KERNEL);
8348 if (!new_rule->patterns)
8349 return -ENOMEM;
8350
8351 new_rule->n_patterns = n_patterns;
8352 i = 0;
8353
8354 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8355 rem) {
8356 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8357 nla_len(pat), NULL);
8358 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8359 !pat_tb[NL80211_PKTPAT_PATTERN])
8360 return -EINVAL;
8361 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8362 mask_len = DIV_ROUND_UP(pat_len, 8);
8363 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8364 return -EINVAL;
8365 if (pat_len > coalesce->pattern_max_len ||
8366 pat_len < coalesce->pattern_min_len)
8367 return -EINVAL;
8368
8369 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8370 pkt_offset = 0;
8371 else
8372 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8373 if (pkt_offset > coalesce->max_pkt_offset)
8374 return -EINVAL;
8375 new_rule->patterns[i].pkt_offset = pkt_offset;
8376
8377 new_rule->patterns[i].mask =
8378 kmalloc(mask_len + pat_len, GFP_KERNEL);
8379 if (!new_rule->patterns[i].mask)
8380 return -ENOMEM;
8381 new_rule->patterns[i].pattern =
8382 new_rule->patterns[i].mask + mask_len;
8383 memcpy(new_rule->patterns[i].mask,
8384 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8385 new_rule->patterns[i].pattern_len = pat_len;
8386 memcpy(new_rule->patterns[i].pattern,
8387 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8388 i++;
8389 }
8390
8391 return 0;
8392}
8393
8394static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8395{
8396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8397 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8398 struct cfg80211_coalesce new_coalesce = {};
8399 struct cfg80211_coalesce *n_coalesce;
8400 int err, rem_rule, n_rules = 0, i, j;
8401 struct nlattr *rule;
8402 struct cfg80211_coalesce_rules *tmp_rule;
8403
8404 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8405 return -EOPNOTSUPP;
8406
8407 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8408 cfg80211_rdev_free_coalesce(rdev);
8409 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8410 return 0;
8411 }
8412
8413 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8414 rem_rule)
8415 n_rules++;
8416 if (n_rules > coalesce->n_rules)
8417 return -EINVAL;
8418
8419 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8420 GFP_KERNEL);
8421 if (!new_coalesce.rules)
8422 return -ENOMEM;
8423
8424 new_coalesce.n_rules = n_rules;
8425 i = 0;
8426
8427 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8428 rem_rule) {
8429 err = nl80211_parse_coalesce_rule(rdev, rule,
8430 &new_coalesce.rules[i]);
8431 if (err)
8432 goto error;
8433
8434 i++;
8435 }
8436
8437 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8438 if (err)
8439 goto error;
8440
8441 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8442 if (!n_coalesce) {
8443 err = -ENOMEM;
8444 goto error;
8445 }
8446 cfg80211_rdev_free_coalesce(rdev);
8447 rdev->coalesce = n_coalesce;
8448
8449 return 0;
8450error:
8451 for (i = 0; i < new_coalesce.n_rules; i++) {
8452 tmp_rule = &new_coalesce.rules[i];
8453 for (j = 0; j < tmp_rule->n_patterns; j++)
8454 kfree(tmp_rule->patterns[j].mask);
8455 kfree(tmp_rule->patterns);
8456 }
8457 kfree(new_coalesce.rules);
8458
8459 return err;
8460}
8461
Johannes Berge5497d72011-07-05 16:35:40 +02008462static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8463{
8464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8465 struct net_device *dev = info->user_ptr[1];
8466 struct wireless_dev *wdev = dev->ieee80211_ptr;
8467 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8468 struct cfg80211_gtk_rekey_data rekey_data;
8469 int err;
8470
8471 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8472 return -EINVAL;
8473
8474 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8475 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8476 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8477 nl80211_rekey_policy);
8478 if (err)
8479 return err;
8480
8481 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8482 return -ERANGE;
8483 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8484 return -ERANGE;
8485 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8486 return -ERANGE;
8487
8488 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8489 NL80211_KEK_LEN);
8490 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8491 NL80211_KCK_LEN);
8492 memcpy(rekey_data.replay_ctr,
8493 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8494 NL80211_REPLAY_CTR_LEN);
8495
8496 wdev_lock(wdev);
8497 if (!wdev->current_bss) {
8498 err = -ENOTCONN;
8499 goto out;
8500 }
8501
8502 if (!rdev->ops->set_rekey_data) {
8503 err = -EOPNOTSUPP;
8504 goto out;
8505 }
8506
Hila Gonene35e4d22012-06-27 17:19:42 +03008507 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008508 out:
8509 wdev_unlock(wdev);
8510 return err;
8511}
8512
Johannes Berg28946da2011-11-04 11:18:12 +01008513static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8514 struct genl_info *info)
8515{
8516 struct net_device *dev = info->user_ptr[1];
8517 struct wireless_dev *wdev = dev->ieee80211_ptr;
8518
8519 if (wdev->iftype != NL80211_IFTYPE_AP &&
8520 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8521 return -EINVAL;
8522
Eric W. Biederman15e47302012-09-07 20:12:54 +00008523 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008524 return -EBUSY;
8525
Eric W. Biederman15e47302012-09-07 20:12:54 +00008526 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008527 return 0;
8528}
8529
Johannes Berg7f6cf312011-11-04 11:18:15 +01008530static int nl80211_probe_client(struct sk_buff *skb,
8531 struct genl_info *info)
8532{
8533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8534 struct net_device *dev = info->user_ptr[1];
8535 struct wireless_dev *wdev = dev->ieee80211_ptr;
8536 struct sk_buff *msg;
8537 void *hdr;
8538 const u8 *addr;
8539 u64 cookie;
8540 int err;
8541
8542 if (wdev->iftype != NL80211_IFTYPE_AP &&
8543 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8544 return -EOPNOTSUPP;
8545
8546 if (!info->attrs[NL80211_ATTR_MAC])
8547 return -EINVAL;
8548
8549 if (!rdev->ops->probe_client)
8550 return -EOPNOTSUPP;
8551
8552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8553 if (!msg)
8554 return -ENOMEM;
8555
Eric W. Biederman15e47302012-09-07 20:12:54 +00008556 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008557 NL80211_CMD_PROBE_CLIENT);
8558
8559 if (IS_ERR(hdr)) {
8560 err = PTR_ERR(hdr);
8561 goto free_msg;
8562 }
8563
8564 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8565
Hila Gonene35e4d22012-06-27 17:19:42 +03008566 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008567 if (err)
8568 goto free_msg;
8569
David S. Miller9360ffd2012-03-29 04:41:26 -04008570 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8571 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008572
8573 genlmsg_end(msg, hdr);
8574
8575 return genlmsg_reply(msg, info);
8576
8577 nla_put_failure:
8578 err = -ENOBUFS;
8579 free_msg:
8580 nlmsg_free(msg);
8581 return err;
8582}
8583
Johannes Berg5e760232011-11-04 11:18:17 +01008584static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8585{
8586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008587 struct cfg80211_beacon_registration *reg, *nreg;
8588 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008589
8590 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8591 return -EOPNOTSUPP;
8592
Ben Greear37c73b52012-10-26 14:49:25 -07008593 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8594 if (!nreg)
8595 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008596
Ben Greear37c73b52012-10-26 14:49:25 -07008597 /* First, check if already registered. */
8598 spin_lock_bh(&rdev->beacon_registrations_lock);
8599 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8600 if (reg->nlportid == info->snd_portid) {
8601 rv = -EALREADY;
8602 goto out_err;
8603 }
8604 }
8605 /* Add it to the list */
8606 nreg->nlportid = info->snd_portid;
8607 list_add(&nreg->list, &rdev->beacon_registrations);
8608
8609 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008610
8611 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008612out_err:
8613 spin_unlock_bh(&rdev->beacon_registrations_lock);
8614 kfree(nreg);
8615 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008616}
8617
Johannes Berg98104fde2012-06-16 00:19:54 +02008618static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8619{
8620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8621 struct wireless_dev *wdev = info->user_ptr[1];
8622 int err;
8623
8624 if (!rdev->ops->start_p2p_device)
8625 return -EOPNOTSUPP;
8626
8627 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8628 return -EOPNOTSUPP;
8629
8630 if (wdev->p2p_started)
8631 return 0;
8632
Johannes Berg98104fde2012-06-16 00:19:54 +02008633 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008634 if (err)
8635 return err;
8636
Johannes Bergeeb126e2012-10-23 15:16:50 +02008637 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008638 if (err)
8639 return err;
8640
8641 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008642 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008643
8644 return 0;
8645}
8646
8647static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8648{
8649 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8650 struct wireless_dev *wdev = info->user_ptr[1];
8651
8652 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8653 return -EOPNOTSUPP;
8654
8655 if (!rdev->ops->stop_p2p_device)
8656 return -EOPNOTSUPP;
8657
Johannes Bergf9f47522013-03-19 15:04:07 +01008658 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008659
8660 return 0;
8661}
8662
Johannes Berg3713b4e2013-02-14 16:19:38 +01008663static int nl80211_get_protocol_features(struct sk_buff *skb,
8664 struct genl_info *info)
8665{
8666 void *hdr;
8667 struct sk_buff *msg;
8668
8669 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8670 if (!msg)
8671 return -ENOMEM;
8672
8673 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8674 NL80211_CMD_GET_PROTOCOL_FEATURES);
8675 if (!hdr)
8676 goto nla_put_failure;
8677
8678 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8679 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8680 goto nla_put_failure;
8681
8682 genlmsg_end(msg, hdr);
8683 return genlmsg_reply(msg, info);
8684
8685 nla_put_failure:
8686 kfree_skb(msg);
8687 return -ENOBUFS;
8688}
8689
Jouni Malinen355199e2013-02-27 17:14:27 +02008690static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8691{
8692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8693 struct cfg80211_update_ft_ies_params ft_params;
8694 struct net_device *dev = info->user_ptr[1];
8695
8696 if (!rdev->ops->update_ft_ies)
8697 return -EOPNOTSUPP;
8698
8699 if (!info->attrs[NL80211_ATTR_MDID] ||
8700 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8701 return -EINVAL;
8702
8703 memset(&ft_params, 0, sizeof(ft_params));
8704 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8705 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8706 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8707
8708 return rdev_update_ft_ies(rdev, dev, &ft_params);
8709}
8710
Arend van Spriel5de17982013-04-18 15:49:00 +02008711static int nl80211_crit_protocol_start(struct sk_buff *skb,
8712 struct genl_info *info)
8713{
8714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8715 struct wireless_dev *wdev = info->user_ptr[1];
8716 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8717 u16 duration;
8718 int ret;
8719
8720 if (!rdev->ops->crit_proto_start)
8721 return -EOPNOTSUPP;
8722
8723 if (WARN_ON(!rdev->ops->crit_proto_stop))
8724 return -EINVAL;
8725
8726 if (rdev->crit_proto_nlportid)
8727 return -EBUSY;
8728
8729 /* determine protocol if provided */
8730 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8731 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8732
8733 if (proto >= NUM_NL80211_CRIT_PROTO)
8734 return -EINVAL;
8735
8736 /* timeout must be provided */
8737 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8738 return -EINVAL;
8739
8740 duration =
8741 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8742
8743 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8744 return -ERANGE;
8745
8746 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8747 if (!ret)
8748 rdev->crit_proto_nlportid = info->snd_portid;
8749
8750 return ret;
8751}
8752
8753static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8754 struct genl_info *info)
8755{
8756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8757 struct wireless_dev *wdev = info->user_ptr[1];
8758
8759 if (!rdev->ops->crit_proto_stop)
8760 return -EOPNOTSUPP;
8761
8762 if (rdev->crit_proto_nlportid) {
8763 rdev->crit_proto_nlportid = 0;
8764 rdev_crit_proto_stop(rdev, wdev);
8765 }
8766 return 0;
8767}
8768
Johannes Berg4c476992010-10-04 21:36:35 +02008769#define NL80211_FLAG_NEED_WIPHY 0x01
8770#define NL80211_FLAG_NEED_NETDEV 0x02
8771#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008772#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8773#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8774 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008775#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008776/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008777#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8778 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008779
8780static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8781 struct genl_info *info)
8782{
8783 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008784 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008785 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008786 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8787
8788 if (rtnl)
8789 rtnl_lock();
8790
8791 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008792 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008793 if (IS_ERR(rdev)) {
8794 if (rtnl)
8795 rtnl_unlock();
8796 return PTR_ERR(rdev);
8797 }
8798 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008799 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8800 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008801 ASSERT_RTNL();
8802
Johannes Berg89a54e42012-06-15 14:33:17 +02008803 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8804 info->attrs);
8805 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008806 if (rtnl)
8807 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008808 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008809 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008810
Johannes Berg89a54e42012-06-15 14:33:17 +02008811 dev = wdev->netdev;
8812 rdev = wiphy_to_dev(wdev->wiphy);
8813
Johannes Berg1bf614e2012-06-15 15:23:36 +02008814 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8815 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008816 if (rtnl)
8817 rtnl_unlock();
8818 return -EINVAL;
8819 }
8820
8821 info->user_ptr[1] = dev;
8822 } else {
8823 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008824 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008825
Johannes Berg1bf614e2012-06-15 15:23:36 +02008826 if (dev) {
8827 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8828 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008829 if (rtnl)
8830 rtnl_unlock();
8831 return -ENETDOWN;
8832 }
8833
8834 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008835 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8836 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008837 if (rtnl)
8838 rtnl_unlock();
8839 return -ENETDOWN;
8840 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008841 }
8842
Johannes Berg4c476992010-10-04 21:36:35 +02008843 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008844 }
8845
8846 return 0;
8847}
8848
8849static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8850 struct genl_info *info)
8851{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008852 if (info->user_ptr[1]) {
8853 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8854 struct wireless_dev *wdev = info->user_ptr[1];
8855
8856 if (wdev->netdev)
8857 dev_put(wdev->netdev);
8858 } else {
8859 dev_put(info->user_ptr[1]);
8860 }
8861 }
Johannes Berg4c476992010-10-04 21:36:35 +02008862 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8863 rtnl_unlock();
8864}
8865
Johannes Berg55682962007-09-20 13:09:35 -04008866static struct genl_ops nl80211_ops[] = {
8867 {
8868 .cmd = NL80211_CMD_GET_WIPHY,
8869 .doit = nl80211_get_wiphy,
8870 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008871 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008872 .policy = nl80211_policy,
8873 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008874 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8875 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008876 },
8877 {
8878 .cmd = NL80211_CMD_SET_WIPHY,
8879 .doit = nl80211_set_wiphy,
8880 .policy = nl80211_policy,
8881 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008882 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008883 },
8884 {
8885 .cmd = NL80211_CMD_GET_INTERFACE,
8886 .doit = nl80211_get_interface,
8887 .dumpit = nl80211_dump_interface,
8888 .policy = nl80211_policy,
8889 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008890 .internal_flags = NL80211_FLAG_NEED_WDEV |
8891 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008892 },
8893 {
8894 .cmd = NL80211_CMD_SET_INTERFACE,
8895 .doit = nl80211_set_interface,
8896 .policy = nl80211_policy,
8897 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008898 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8899 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008900 },
8901 {
8902 .cmd = NL80211_CMD_NEW_INTERFACE,
8903 .doit = nl80211_new_interface,
8904 .policy = nl80211_policy,
8905 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008906 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8907 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008908 },
8909 {
8910 .cmd = NL80211_CMD_DEL_INTERFACE,
8911 .doit = nl80211_del_interface,
8912 .policy = nl80211_policy,
8913 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008914 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008915 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008916 },
Johannes Berg41ade002007-12-19 02:03:29 +01008917 {
8918 .cmd = NL80211_CMD_GET_KEY,
8919 .doit = nl80211_get_key,
8920 .policy = nl80211_policy,
8921 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +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_SET_KEY,
8927 .doit = nl80211_set_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_NEW_KEY,
8935 .doit = nl80211_new_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 },
8941 {
8942 .cmd = NL80211_CMD_DEL_KEY,
8943 .doit = nl80211_del_key,
8944 .policy = nl80211_policy,
8945 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008946 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008947 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008948 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008949 {
8950 .cmd = NL80211_CMD_SET_BEACON,
8951 .policy = nl80211_policy,
8952 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008953 .doit = nl80211_set_beacon,
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_START_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_start_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 },
8965 {
Johannes Berg88600202012-02-13 15:17:18 +01008966 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008967 .policy = nl80211_policy,
8968 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008969 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008971 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008972 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008973 {
8974 .cmd = NL80211_CMD_GET_STATION,
8975 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008976 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008977 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008978 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8979 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008980 },
8981 {
8982 .cmd = NL80211_CMD_SET_STATION,
8983 .doit = nl80211_set_station,
8984 .policy = nl80211_policy,
8985 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +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_NEW_STATION,
8991 .doit = nl80211_new_station,
8992 .policy = nl80211_policy,
8993 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +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 },
8997 {
8998 .cmd = NL80211_CMD_DEL_STATION,
8999 .doit = nl80211_del_station,
9000 .policy = nl80211_policy,
9001 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009003 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009004 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009005 {
9006 .cmd = NL80211_CMD_GET_MPATH,
9007 .doit = nl80211_get_mpath,
9008 .dumpit = nl80211_dump_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_SET_MPATH,
9016 .doit = nl80211_set_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_NEW_MPATH,
9024 .doit = nl80211_new_mpath,
9025 .policy = nl80211_policy,
9026 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +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 },
9030 {
9031 .cmd = NL80211_CMD_DEL_MPATH,
9032 .doit = nl80211_del_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009037 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009038 {
9039 .cmd = NL80211_CMD_SET_BSS,
9040 .doit = nl80211_set_bss,
9041 .policy = nl80211_policy,
9042 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009043 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009044 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009045 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009046 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009047 .cmd = NL80211_CMD_GET_REG,
9048 .doit = nl80211_get_reg,
9049 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009050 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009051 /* can be retrieved by unprivileged users */
9052 },
9053 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009054 .cmd = NL80211_CMD_SET_REG,
9055 .doit = nl80211_set_reg,
9056 .policy = nl80211_policy,
9057 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009058 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009059 },
9060 {
9061 .cmd = NL80211_CMD_REQ_SET_REG,
9062 .doit = nl80211_req_set_reg,
9063 .policy = nl80211_policy,
9064 .flags = GENL_ADMIN_PERM,
9065 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009066 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009067 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9068 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009069 .policy = nl80211_policy,
9070 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009072 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009073 },
9074 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009075 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9076 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009077 .policy = nl80211_policy,
9078 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009080 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009081 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009082 {
Johannes Berg2a519312009-02-10 21:25:55 +01009083 .cmd = NL80211_CMD_TRIGGER_SCAN,
9084 .doit = nl80211_trigger_scan,
9085 .policy = nl80211_policy,
9086 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009087 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009088 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009089 },
9090 {
9091 .cmd = NL80211_CMD_GET_SCAN,
9092 .policy = nl80211_policy,
9093 .dumpit = nl80211_dump_scan,
9094 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009095 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009096 .cmd = NL80211_CMD_START_SCHED_SCAN,
9097 .doit = nl80211_start_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 {
9104 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9105 .doit = nl80211_stop_sched_scan,
9106 .policy = nl80211_policy,
9107 .flags = GENL_ADMIN_PERM,
9108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9109 NL80211_FLAG_NEED_RTNL,
9110 },
9111 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009112 .cmd = NL80211_CMD_AUTHENTICATE,
9113 .doit = nl80211_authenticate,
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_ASSOCIATE,
9121 .doit = nl80211_associate,
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_DEAUTHENTICATE,
9129 .doit = nl80211_deauthenticate,
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 },
9135 {
9136 .cmd = NL80211_CMD_DISASSOCIATE,
9137 .doit = nl80211_disassociate,
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,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009142 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009143 {
9144 .cmd = NL80211_CMD_JOIN_IBSS,
9145 .doit = nl80211_join_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 },
9151 {
9152 .cmd = NL80211_CMD_LEAVE_IBSS,
9153 .doit = nl80211_leave_ibss,
9154 .policy = nl80211_policy,
9155 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009157 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009158 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009159#ifdef CONFIG_NL80211_TESTMODE
9160 {
9161 .cmd = NL80211_CMD_TESTMODE,
9162 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009163 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009164 .policy = nl80211_policy,
9165 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009166 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9167 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009168 },
9169#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009170 {
9171 .cmd = NL80211_CMD_CONNECT,
9172 .doit = nl80211_connect,
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 },
9178 {
9179 .cmd = NL80211_CMD_DISCONNECT,
9180 .doit = nl80211_disconnect,
9181 .policy = nl80211_policy,
9182 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009184 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009185 },
Johannes Berg463d0182009-07-14 00:33:35 +02009186 {
9187 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9188 .doit = nl80211_wiphy_netns,
9189 .policy = nl80211_policy,
9190 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009191 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9192 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009193 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009194 {
9195 .cmd = NL80211_CMD_GET_SURVEY,
9196 .policy = nl80211_policy,
9197 .dumpit = nl80211_dump_survey,
9198 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009199 {
9200 .cmd = NL80211_CMD_SET_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_DEL_PMKSA,
9209 .doit = nl80211_setdel_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 },
9215 {
9216 .cmd = NL80211_CMD_FLUSH_PMKSA,
9217 .doit = nl80211_flush_pmksa,
9218 .policy = nl80211_policy,
9219 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009220 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009221 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009222 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009223 {
9224 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9225 .doit = nl80211_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 },
9231 {
9232 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9233 .doit = nl80211_cancel_remain_on_channel,
9234 .policy = nl80211_policy,
9235 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009236 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009237 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009238 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009239 {
9240 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9241 .doit = nl80211_set_tx_bitrate_mask,
9242 .policy = nl80211_policy,
9243 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009244 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9245 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009246 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009247 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009248 .cmd = NL80211_CMD_REGISTER_FRAME,
9249 .doit = nl80211_register_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 |
Johannes Berg4c476992010-10-04 21:36:35 +02009253 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009254 },
9255 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009256 .cmd = NL80211_CMD_FRAME,
9257 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009258 .policy = nl80211_policy,
9259 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009260 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009261 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009262 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009263 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009264 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9265 .doit = nl80211_tx_mgmt_cancel_wait,
9266 .policy = nl80211_policy,
9267 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009268 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009269 NL80211_FLAG_NEED_RTNL,
9270 },
9271 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009272 .cmd = NL80211_CMD_SET_POWER_SAVE,
9273 .doit = nl80211_set_power_save,
9274 .policy = nl80211_policy,
9275 .flags = GENL_ADMIN_PERM,
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 },
9279 {
9280 .cmd = NL80211_CMD_GET_POWER_SAVE,
9281 .doit = nl80211_get_power_save,
9282 .policy = nl80211_policy,
9283 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009284 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9285 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009286 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009287 {
9288 .cmd = NL80211_CMD_SET_CQM,
9289 .doit = nl80211_set_cqm,
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,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009294 },
Johannes Bergf444de02010-05-05 15:25:02 +02009295 {
9296 .cmd = NL80211_CMD_SET_CHANNEL,
9297 .doit = nl80211_set_channel,
9298 .policy = nl80211_policy,
9299 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009300 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9301 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009302 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009303 {
9304 .cmd = NL80211_CMD_SET_WDS_PEER,
9305 .doit = nl80211_set_wds_peer,
9306 .policy = nl80211_policy,
9307 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009308 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9309 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009310 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009311 {
9312 .cmd = NL80211_CMD_JOIN_MESH,
9313 .doit = nl80211_join_mesh,
9314 .policy = nl80211_policy,
9315 .flags = GENL_ADMIN_PERM,
9316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9317 NL80211_FLAG_NEED_RTNL,
9318 },
9319 {
9320 .cmd = NL80211_CMD_LEAVE_MESH,
9321 .doit = nl80211_leave_mesh,
9322 .policy = nl80211_policy,
9323 .flags = GENL_ADMIN_PERM,
9324 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9325 NL80211_FLAG_NEED_RTNL,
9326 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009327#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009328 {
9329 .cmd = NL80211_CMD_GET_WOWLAN,
9330 .doit = nl80211_get_wowlan,
9331 .policy = nl80211_policy,
9332 /* can be retrieved by unprivileged users */
9333 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9334 NL80211_FLAG_NEED_RTNL,
9335 },
9336 {
9337 .cmd = NL80211_CMD_SET_WOWLAN,
9338 .doit = nl80211_set_wowlan,
9339 .policy = nl80211_policy,
9340 .flags = GENL_ADMIN_PERM,
9341 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9342 NL80211_FLAG_NEED_RTNL,
9343 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009344#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009345 {
9346 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9347 .doit = nl80211_set_rekey_data,
9348 .policy = nl80211_policy,
9349 .flags = GENL_ADMIN_PERM,
9350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9351 NL80211_FLAG_NEED_RTNL,
9352 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009353 {
9354 .cmd = NL80211_CMD_TDLS_MGMT,
9355 .doit = nl80211_tdls_mgmt,
9356 .policy = nl80211_policy,
9357 .flags = GENL_ADMIN_PERM,
9358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9359 NL80211_FLAG_NEED_RTNL,
9360 },
9361 {
9362 .cmd = NL80211_CMD_TDLS_OPER,
9363 .doit = nl80211_tdls_oper,
9364 .policy = nl80211_policy,
9365 .flags = GENL_ADMIN_PERM,
9366 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9367 NL80211_FLAG_NEED_RTNL,
9368 },
Johannes Berg28946da2011-11-04 11:18:12 +01009369 {
9370 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9371 .doit = nl80211_register_unexpected_frame,
9372 .policy = nl80211_policy,
9373 .flags = GENL_ADMIN_PERM,
9374 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9375 NL80211_FLAG_NEED_RTNL,
9376 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009377 {
9378 .cmd = NL80211_CMD_PROBE_CLIENT,
9379 .doit = nl80211_probe_client,
9380 .policy = nl80211_policy,
9381 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009382 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009383 NL80211_FLAG_NEED_RTNL,
9384 },
Johannes Berg5e760232011-11-04 11:18:17 +01009385 {
9386 .cmd = NL80211_CMD_REGISTER_BEACONS,
9387 .doit = nl80211_register_beacons,
9388 .policy = nl80211_policy,
9389 .flags = GENL_ADMIN_PERM,
9390 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9391 NL80211_FLAG_NEED_RTNL,
9392 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009393 {
9394 .cmd = NL80211_CMD_SET_NOACK_MAP,
9395 .doit = nl80211_set_noack_map,
9396 .policy = nl80211_policy,
9397 .flags = GENL_ADMIN_PERM,
9398 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9399 NL80211_FLAG_NEED_RTNL,
9400 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009401 {
9402 .cmd = NL80211_CMD_START_P2P_DEVICE,
9403 .doit = nl80211_start_p2p_device,
9404 .policy = nl80211_policy,
9405 .flags = GENL_ADMIN_PERM,
9406 .internal_flags = NL80211_FLAG_NEED_WDEV |
9407 NL80211_FLAG_NEED_RTNL,
9408 },
9409 {
9410 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9411 .doit = nl80211_stop_p2p_device,
9412 .policy = nl80211_policy,
9413 .flags = GENL_ADMIN_PERM,
9414 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9415 NL80211_FLAG_NEED_RTNL,
9416 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009417 {
9418 .cmd = NL80211_CMD_SET_MCAST_RATE,
9419 .doit = nl80211_set_mcast_rate,
9420 .policy = nl80211_policy,
9421 .flags = GENL_ADMIN_PERM,
9422 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9423 NL80211_FLAG_NEED_RTNL,
9424 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309425 {
9426 .cmd = NL80211_CMD_SET_MAC_ACL,
9427 .doit = nl80211_set_mac_acl,
9428 .policy = nl80211_policy,
9429 .flags = GENL_ADMIN_PERM,
9430 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9431 NL80211_FLAG_NEED_RTNL,
9432 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009433 {
9434 .cmd = NL80211_CMD_RADAR_DETECT,
9435 .doit = nl80211_start_radar_detection,
9436 .policy = nl80211_policy,
9437 .flags = GENL_ADMIN_PERM,
9438 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9439 NL80211_FLAG_NEED_RTNL,
9440 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009441 {
9442 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9443 .doit = nl80211_get_protocol_features,
9444 .policy = nl80211_policy,
9445 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009446 {
9447 .cmd = NL80211_CMD_UPDATE_FT_IES,
9448 .doit = nl80211_update_ft_ies,
9449 .policy = nl80211_policy,
9450 .flags = GENL_ADMIN_PERM,
9451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9452 NL80211_FLAG_NEED_RTNL,
9453 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009454 {
9455 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9456 .doit = nl80211_crit_protocol_start,
9457 .policy = nl80211_policy,
9458 .flags = GENL_ADMIN_PERM,
9459 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9460 NL80211_FLAG_NEED_RTNL,
9461 },
9462 {
9463 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9464 .doit = nl80211_crit_protocol_stop,
9465 .policy = nl80211_policy,
9466 .flags = GENL_ADMIN_PERM,
9467 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9468 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009469 },
9470 {
9471 .cmd = NL80211_CMD_GET_COALESCE,
9472 .doit = nl80211_get_coalesce,
9473 .policy = nl80211_policy,
9474 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9475 NL80211_FLAG_NEED_RTNL,
9476 },
9477 {
9478 .cmd = NL80211_CMD_SET_COALESCE,
9479 .doit = nl80211_set_coalesce,
9480 .policy = nl80211_policy,
9481 .flags = GENL_ADMIN_PERM,
9482 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9483 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009484 },
9485 {
9486 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9487 .doit = nl80211_channel_switch,
9488 .policy = nl80211_policy,
9489 .flags = GENL_ADMIN_PERM,
9490 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9491 NL80211_FLAG_NEED_RTNL,
9492 },
Johannes Berg55682962007-09-20 13:09:35 -04009493};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009494
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009495static struct genl_multicast_group nl80211_mlme_mcgrp = {
9496 .name = "mlme",
9497};
Johannes Berg55682962007-09-20 13:09:35 -04009498
9499/* multicast groups */
9500static struct genl_multicast_group nl80211_config_mcgrp = {
9501 .name = "config",
9502};
Johannes Berg2a519312009-02-10 21:25:55 +01009503static struct genl_multicast_group nl80211_scan_mcgrp = {
9504 .name = "scan",
9505};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009506static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9507 .name = "regulatory",
9508};
Johannes Berg55682962007-09-20 13:09:35 -04009509
9510/* notification functions */
9511
9512void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9513{
9514 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009515 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009516
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009517 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009518 if (!msg)
9519 return;
9520
Johannes Berg86e8cf92013-06-19 10:57:22 +02009521 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009522 nlmsg_free(msg);
9523 return;
9524 }
9525
Johannes Berg463d0182009-07-14 00:33:35 +02009526 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9527 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009528}
9529
Johannes Berg362a4152009-05-24 16:43:15 +02009530static int nl80211_add_scan_req(struct sk_buff *msg,
9531 struct cfg80211_registered_device *rdev)
9532{
9533 struct cfg80211_scan_request *req = rdev->scan_req;
9534 struct nlattr *nest;
9535 int i;
9536
9537 if (WARN_ON(!req))
9538 return 0;
9539
9540 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9541 if (!nest)
9542 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009543 for (i = 0; i < req->n_ssids; i++) {
9544 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9545 goto nla_put_failure;
9546 }
Johannes Berg362a4152009-05-24 16:43:15 +02009547 nla_nest_end(msg, nest);
9548
9549 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9550 if (!nest)
9551 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009552 for (i = 0; i < req->n_channels; i++) {
9553 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9554 goto nla_put_failure;
9555 }
Johannes Berg362a4152009-05-24 16:43:15 +02009556 nla_nest_end(msg, nest);
9557
David S. Miller9360ffd2012-03-29 04:41:26 -04009558 if (req->ie &&
9559 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9560 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009561
Sam Lefflered4737712012-10-11 21:03:31 -07009562 if (req->flags)
9563 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9564
Johannes Berg362a4152009-05-24 16:43:15 +02009565 return 0;
9566 nla_put_failure:
9567 return -ENOBUFS;
9568}
9569
Johannes Berga538e2d2009-06-16 19:56:42 +02009570static int nl80211_send_scan_msg(struct sk_buff *msg,
9571 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009572 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009573 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009574 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009575{
9576 void *hdr;
9577
Eric W. Biederman15e47302012-09-07 20:12:54 +00009578 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009579 if (!hdr)
9580 return -1;
9581
David S. Miller9360ffd2012-03-29 04:41:26 -04009582 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009583 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9584 wdev->netdev->ifindex)) ||
9585 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009586 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009587
Johannes Berg362a4152009-05-24 16:43:15 +02009588 /* ignore errors and send incomplete event anyway */
9589 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009590
9591 return genlmsg_end(msg, hdr);
9592
9593 nla_put_failure:
9594 genlmsg_cancel(msg, hdr);
9595 return -EMSGSIZE;
9596}
9597
Luciano Coelho807f8a82011-05-11 17:09:35 +03009598static int
9599nl80211_send_sched_scan_msg(struct sk_buff *msg,
9600 struct cfg80211_registered_device *rdev,
9601 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009602 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009603{
9604 void *hdr;
9605
Eric W. Biederman15e47302012-09-07 20:12:54 +00009606 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009607 if (!hdr)
9608 return -1;
9609
David S. Miller9360ffd2012-03-29 04:41:26 -04009610 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9611 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9612 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009613
9614 return genlmsg_end(msg, hdr);
9615
9616 nla_put_failure:
9617 genlmsg_cancel(msg, hdr);
9618 return -EMSGSIZE;
9619}
9620
Johannes Berga538e2d2009-06-16 19:56:42 +02009621void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009622 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009623{
9624 struct sk_buff *msg;
9625
Thomas Graf58050fc2012-06-28 03:57:45 +00009626 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009627 if (!msg)
9628 return;
9629
Johannes Bergfd014282012-06-18 19:17:03 +02009630 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009631 NL80211_CMD_TRIGGER_SCAN) < 0) {
9632 nlmsg_free(msg);
9633 return;
9634 }
9635
Johannes Berg463d0182009-07-14 00:33:35 +02009636 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9637 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009638}
9639
Johannes Berg2a519312009-02-10 21:25:55 +01009640void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009641 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009642{
9643 struct sk_buff *msg;
9644
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009646 if (!msg)
9647 return;
9648
Johannes Bergfd014282012-06-18 19:17:03 +02009649 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009650 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009651 nlmsg_free(msg);
9652 return;
9653 }
9654
Johannes Berg463d0182009-07-14 00:33:35 +02009655 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9656 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009657}
9658
9659void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009660 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009661{
9662 struct sk_buff *msg;
9663
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009665 if (!msg)
9666 return;
9667
Johannes Bergfd014282012-06-18 19:17:03 +02009668 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009669 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009670 nlmsg_free(msg);
9671 return;
9672 }
9673
Johannes Berg463d0182009-07-14 00:33:35 +02009674 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9675 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009676}
9677
Luciano Coelho807f8a82011-05-11 17:09:35 +03009678void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9679 struct net_device *netdev)
9680{
9681 struct sk_buff *msg;
9682
9683 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9684 if (!msg)
9685 return;
9686
9687 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9688 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9689 nlmsg_free(msg);
9690 return;
9691 }
9692
9693 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9694 nl80211_scan_mcgrp.id, GFP_KERNEL);
9695}
9696
9697void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9698 struct net_device *netdev, u32 cmd)
9699{
9700 struct sk_buff *msg;
9701
Thomas Graf58050fc2012-06-28 03:57:45 +00009702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009703 if (!msg)
9704 return;
9705
9706 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9707 nlmsg_free(msg);
9708 return;
9709 }
9710
9711 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9712 nl80211_scan_mcgrp.id, GFP_KERNEL);
9713}
9714
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009715/*
9716 * This can happen on global regulatory changes or device specific settings
9717 * based on custom world regulatory domains.
9718 */
9719void nl80211_send_reg_change_event(struct regulatory_request *request)
9720{
9721 struct sk_buff *msg;
9722 void *hdr;
9723
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009725 if (!msg)
9726 return;
9727
9728 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9729 if (!hdr) {
9730 nlmsg_free(msg);
9731 return;
9732 }
9733
9734 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009735 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9736 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009737
David S. Miller9360ffd2012-03-29 04:41:26 -04009738 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9739 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9740 NL80211_REGDOM_TYPE_WORLD))
9741 goto nla_put_failure;
9742 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9743 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9744 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9745 goto nla_put_failure;
9746 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9747 request->intersect) {
9748 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9749 NL80211_REGDOM_TYPE_INTERSECTION))
9750 goto nla_put_failure;
9751 } else {
9752 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9753 NL80211_REGDOM_TYPE_COUNTRY) ||
9754 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9755 request->alpha2))
9756 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009757 }
9758
Johannes Bergf4173762012-12-03 18:23:37 +01009759 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009760 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9761 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009762
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009763 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009764
Johannes Bergbc43b282009-07-25 10:54:13 +02009765 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009766 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009767 GFP_ATOMIC);
9768 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009769
9770 return;
9771
9772nla_put_failure:
9773 genlmsg_cancel(msg, hdr);
9774 nlmsg_free(msg);
9775}
9776
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009777static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9778 struct net_device *netdev,
9779 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009780 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009781{
9782 struct sk_buff *msg;
9783 void *hdr;
9784
Johannes Berge6d6e342009-07-01 21:26:47 +02009785 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009786 if (!msg)
9787 return;
9788
9789 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9790 if (!hdr) {
9791 nlmsg_free(msg);
9792 return;
9793 }
9794
David S. Miller9360ffd2012-03-29 04:41:26 -04009795 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9796 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9797 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9798 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009799
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009800 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009801
Johannes Berg463d0182009-07-14 00:33:35 +02009802 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9803 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009804 return;
9805
9806 nla_put_failure:
9807 genlmsg_cancel(msg, hdr);
9808 nlmsg_free(msg);
9809}
9810
9811void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009812 struct net_device *netdev, const u8 *buf,
9813 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009814{
9815 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009816 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009817}
9818
9819void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9820 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009821 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009822{
Johannes Berge6d6e342009-07-01 21:26:47 +02009823 nl80211_send_mlme_event(rdev, netdev, buf, len,
9824 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009825}
9826
Jouni Malinen53b46b82009-03-27 20:53:56 +02009827void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009828 struct net_device *netdev, const u8 *buf,
9829 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_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009833}
9834
Jouni Malinen53b46b82009-03-27 20:53:56 +02009835void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9836 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009837 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009838{
9839 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009840 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009841}
9842
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009843void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9844 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009845{
Johannes Berg947add32013-02-22 22:05:20 +01009846 struct wireless_dev *wdev = dev->ieee80211_ptr;
9847 struct wiphy *wiphy = wdev->wiphy;
9848 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009849 const struct ieee80211_mgmt *mgmt = (void *)buf;
9850 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009851
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009852 if (WARN_ON(len < 2))
9853 return;
9854
9855 if (ieee80211_is_deauth(mgmt->frame_control))
9856 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9857 else
9858 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9859
9860 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9861 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009862}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009863EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009864
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009865static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9866 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009867 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009868{
9869 struct sk_buff *msg;
9870 void *hdr;
9871
Johannes Berge6d6e342009-07-01 21:26:47 +02009872 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009873 if (!msg)
9874 return;
9875
9876 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9877 if (!hdr) {
9878 nlmsg_free(msg);
9879 return;
9880 }
9881
David S. Miller9360ffd2012-03-29 04:41:26 -04009882 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9883 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9884 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9885 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9886 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009887
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009888 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009889
Johannes Berg463d0182009-07-14 00:33:35 +02009890 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9891 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009892 return;
9893
9894 nla_put_failure:
9895 genlmsg_cancel(msg, hdr);
9896 nlmsg_free(msg);
9897}
9898
9899void nl80211_send_auth_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{
9903 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009904 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009905}
9906
9907void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009908 struct net_device *netdev, const u8 *addr,
9909 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009910{
Johannes Berge6d6e342009-07-01 21:26:47 +02009911 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9912 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009913}
9914
Samuel Ortizb23aa672009-07-01 21:26:54 +02009915void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9916 struct net_device *netdev, const u8 *bssid,
9917 const u8 *req_ie, size_t req_ie_len,
9918 const u8 *resp_ie, size_t resp_ie_len,
9919 u16 status, gfp_t gfp)
9920{
9921 struct sk_buff *msg;
9922 void *hdr;
9923
Thomas Graf58050fc2012-06-28 03:57:45 +00009924 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009925 if (!msg)
9926 return;
9927
9928 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9929 if (!hdr) {
9930 nlmsg_free(msg);
9931 return;
9932 }
9933
David S. Miller9360ffd2012-03-29 04:41:26 -04009934 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9935 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9936 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9937 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9938 (req_ie &&
9939 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9940 (resp_ie &&
9941 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9942 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009943
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009944 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009945
Johannes Berg463d0182009-07-14 00:33:35 +02009946 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9947 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009948 return;
9949
9950 nla_put_failure:
9951 genlmsg_cancel(msg, hdr);
9952 nlmsg_free(msg);
9953
9954}
9955
9956void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9957 struct net_device *netdev, const u8 *bssid,
9958 const u8 *req_ie, size_t req_ie_len,
9959 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9960{
9961 struct sk_buff *msg;
9962 void *hdr;
9963
Thomas Graf58050fc2012-06-28 03:57:45 +00009964 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009965 if (!msg)
9966 return;
9967
9968 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9969 if (!hdr) {
9970 nlmsg_free(msg);
9971 return;
9972 }
9973
David S. Miller9360ffd2012-03-29 04:41:26 -04009974 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9975 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9976 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9977 (req_ie &&
9978 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9979 (resp_ie &&
9980 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9981 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009982
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009983 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009984
Johannes Berg463d0182009-07-14 00:33:35 +02009985 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9986 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009987 return;
9988
9989 nla_put_failure:
9990 genlmsg_cancel(msg, hdr);
9991 nlmsg_free(msg);
9992
9993}
9994
9995void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9996 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009997 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009998{
9999 struct sk_buff *msg;
10000 void *hdr;
10001
Thomas Graf58050fc2012-06-28 03:57:45 +000010002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010003 if (!msg)
10004 return;
10005
10006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10007 if (!hdr) {
10008 nlmsg_free(msg);
10009 return;
10010 }
10011
David S. Miller9360ffd2012-03-29 04:41:26 -040010012 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10013 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10014 (from_ap && reason &&
10015 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10016 (from_ap &&
10017 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10018 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10019 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010020
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010021 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010022
Johannes Berg463d0182009-07-14 00:33:35 +020010023 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10024 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010025 return;
10026
10027 nla_put_failure:
10028 genlmsg_cancel(msg, hdr);
10029 nlmsg_free(msg);
10030
10031}
10032
Johannes Berg04a773a2009-04-19 21:24:32 +020010033void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10034 struct net_device *netdev, const u8 *bssid,
10035 gfp_t gfp)
10036{
10037 struct sk_buff *msg;
10038 void *hdr;
10039
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010041 if (!msg)
10042 return;
10043
10044 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10045 if (!hdr) {
10046 nlmsg_free(msg);
10047 return;
10048 }
10049
David S. Miller9360ffd2012-03-29 04:41:26 -040010050 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10052 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10053 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010054
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010055 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010056
Johannes Berg463d0182009-07-14 00:33:35 +020010057 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10058 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010059 return;
10060
10061 nla_put_failure:
10062 genlmsg_cancel(msg, hdr);
10063 nlmsg_free(msg);
10064}
10065
Johannes Berg947add32013-02-22 22:05:20 +010010066void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10067 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010068{
Johannes Berg947add32013-02-22 22:05:20 +010010069 struct wireless_dev *wdev = dev->ieee80211_ptr;
10070 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010071 struct sk_buff *msg;
10072 void *hdr;
10073
Johannes Berg947add32013-02-22 22:05:20 +010010074 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10075 return;
10076
10077 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10078
Javier Cardonac93b5e72011-04-07 15:08:34 -070010079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10080 if (!msg)
10081 return;
10082
10083 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10084 if (!hdr) {
10085 nlmsg_free(msg);
10086 return;
10087 }
10088
David S. Miller9360ffd2012-03-29 04:41:26 -040010089 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010090 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10091 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010092 (ie_len && ie &&
10093 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10094 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010095
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010096 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010097
10098 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10099 nl80211_mlme_mcgrp.id, gfp);
10100 return;
10101
10102 nla_put_failure:
10103 genlmsg_cancel(msg, hdr);
10104 nlmsg_free(msg);
10105}
Johannes Berg947add32013-02-22 22:05:20 +010010106EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010107
Jouni Malinena3b8b052009-03-27 21:59:49 +020010108void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10109 struct net_device *netdev, const u8 *addr,
10110 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010111 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010112{
10113 struct sk_buff *msg;
10114 void *hdr;
10115
Johannes Berge6d6e342009-07-01 21:26:47 +020010116 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010117 if (!msg)
10118 return;
10119
10120 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10121 if (!hdr) {
10122 nlmsg_free(msg);
10123 return;
10124 }
10125
David S. Miller9360ffd2012-03-29 04:41:26 -040010126 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10127 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10128 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10129 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10130 (key_id != -1 &&
10131 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10132 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10133 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010134
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010135 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010136
Johannes Berg463d0182009-07-14 00:33:35 +020010137 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10138 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010139 return;
10140
10141 nla_put_failure:
10142 genlmsg_cancel(msg, hdr);
10143 nlmsg_free(msg);
10144}
10145
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010146void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10147 struct ieee80211_channel *channel_before,
10148 struct ieee80211_channel *channel_after)
10149{
10150 struct sk_buff *msg;
10151 void *hdr;
10152 struct nlattr *nl_freq;
10153
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010155 if (!msg)
10156 return;
10157
10158 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10159 if (!hdr) {
10160 nlmsg_free(msg);
10161 return;
10162 }
10163
10164 /*
10165 * Since we are applying the beacon hint to a wiphy we know its
10166 * wiphy_idx is valid
10167 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10169 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010170
10171 /* Before */
10172 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10173 if (!nl_freq)
10174 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010175 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010176 goto nla_put_failure;
10177 nla_nest_end(msg, nl_freq);
10178
10179 /* After */
10180 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10181 if (!nl_freq)
10182 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010183 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010184 goto nla_put_failure;
10185 nla_nest_end(msg, nl_freq);
10186
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010187 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010188
Johannes Berg463d0182009-07-14 00:33:35 +020010189 rcu_read_lock();
10190 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10191 GFP_ATOMIC);
10192 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010193
10194 return;
10195
10196nla_put_failure:
10197 genlmsg_cancel(msg, hdr);
10198 nlmsg_free(msg);
10199}
10200
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010201static void nl80211_send_remain_on_chan_event(
10202 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010203 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010204 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010205 unsigned int duration, gfp_t gfp)
10206{
10207 struct sk_buff *msg;
10208 void *hdr;
10209
10210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10211 if (!msg)
10212 return;
10213
10214 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10215 if (!hdr) {
10216 nlmsg_free(msg);
10217 return;
10218 }
10219
David S. Miller9360ffd2012-03-29 04:41:26 -040010220 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010221 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10222 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010223 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010224 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010225 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10226 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010227 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10228 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010229
David S. Miller9360ffd2012-03-29 04:41:26 -040010230 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10231 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10232 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010233
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010234 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010235
10236 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10237 nl80211_mlme_mcgrp.id, gfp);
10238 return;
10239
10240 nla_put_failure:
10241 genlmsg_cancel(msg, hdr);
10242 nlmsg_free(msg);
10243}
10244
Johannes Berg947add32013-02-22 22:05:20 +010010245void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10246 struct ieee80211_channel *chan,
10247 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010248{
Johannes Berg947add32013-02-22 22:05:20 +010010249 struct wiphy *wiphy = wdev->wiphy;
10250 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10251
10252 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010253 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010254 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010255 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010256}
Johannes Berg947add32013-02-22 22:05:20 +010010257EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010258
Johannes Berg947add32013-02-22 22:05:20 +010010259void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10260 struct ieee80211_channel *chan,
10261 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010262{
Johannes Berg947add32013-02-22 22:05:20 +010010263 struct wiphy *wiphy = wdev->wiphy;
10264 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10265
10266 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010267 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010268 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010269}
Johannes Berg947add32013-02-22 22:05:20 +010010270EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010271
Johannes Berg947add32013-02-22 22:05:20 +010010272void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10273 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010274{
Johannes Berg947add32013-02-22 22:05:20 +010010275 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10276 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010277 struct sk_buff *msg;
10278
Johannes Berg947add32013-02-22 22:05:20 +010010279 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10280
Thomas Graf58050fc2012-06-28 03:57:45 +000010281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010282 if (!msg)
10283 return;
10284
John W. Linville66266b32012-03-15 13:25:41 -040010285 if (nl80211_send_station(msg, 0, 0, 0,
10286 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010287 nlmsg_free(msg);
10288 return;
10289 }
10290
10291 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10292 nl80211_mlme_mcgrp.id, gfp);
10293}
Johannes Berg947add32013-02-22 22:05:20 +010010294EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010295
Johannes Berg947add32013-02-22 22:05:20 +010010296void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010297{
Johannes Berg947add32013-02-22 22:05:20 +010010298 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10299 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010300 struct sk_buff *msg;
10301 void *hdr;
10302
Johannes Berg947add32013-02-22 22:05:20 +010010303 trace_cfg80211_del_sta(dev, mac_addr);
10304
Thomas Graf58050fc2012-06-28 03:57:45 +000010305 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010306 if (!msg)
10307 return;
10308
10309 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10310 if (!hdr) {
10311 nlmsg_free(msg);
10312 return;
10313 }
10314
David S. Miller9360ffd2012-03-29 04:41:26 -040010315 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10316 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10317 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010318
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010319 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010320
10321 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10322 nl80211_mlme_mcgrp.id, gfp);
10323 return;
10324
10325 nla_put_failure:
10326 genlmsg_cancel(msg, hdr);
10327 nlmsg_free(msg);
10328}
Johannes Berg947add32013-02-22 22:05:20 +010010329EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010330
Johannes Berg947add32013-02-22 22:05:20 +010010331void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10332 enum nl80211_connect_failed_reason reason,
10333 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010334{
Johannes Berg947add32013-02-22 22:05:20 +010010335 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10336 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010337 struct sk_buff *msg;
10338 void *hdr;
10339
10340 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10341 if (!msg)
10342 return;
10343
10344 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10345 if (!hdr) {
10346 nlmsg_free(msg);
10347 return;
10348 }
10349
10350 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10351 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10352 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10353 goto nla_put_failure;
10354
10355 genlmsg_end(msg, hdr);
10356
10357 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10358 nl80211_mlme_mcgrp.id, gfp);
10359 return;
10360
10361 nla_put_failure:
10362 genlmsg_cancel(msg, hdr);
10363 nlmsg_free(msg);
10364}
Johannes Berg947add32013-02-22 22:05:20 +010010365EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010366
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010367static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10368 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010369{
10370 struct wireless_dev *wdev = dev->ieee80211_ptr;
10371 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10372 struct sk_buff *msg;
10373 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010374 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010375
Eric W. Biederman15e47302012-09-07 20:12:54 +000010376 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010377 return false;
10378
10379 msg = nlmsg_new(100, gfp);
10380 if (!msg)
10381 return true;
10382
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010383 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010384 if (!hdr) {
10385 nlmsg_free(msg);
10386 return true;
10387 }
10388
David S. Miller9360ffd2012-03-29 04:41:26 -040010389 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10390 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10391 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10392 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010393
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010394 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010395 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010396 return true;
10397
10398 nla_put_failure:
10399 genlmsg_cancel(msg, hdr);
10400 nlmsg_free(msg);
10401 return true;
10402}
10403
Johannes Berg947add32013-02-22 22:05:20 +010010404bool cfg80211_rx_spurious_frame(struct net_device *dev,
10405 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010406{
Johannes Berg947add32013-02-22 22:05:20 +010010407 struct wireless_dev *wdev = dev->ieee80211_ptr;
10408 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010409
Johannes Berg947add32013-02-22 22:05:20 +010010410 trace_cfg80211_rx_spurious_frame(dev, addr);
10411
10412 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10413 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10414 trace_cfg80211_return_bool(false);
10415 return false;
10416 }
10417 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10418 addr, gfp);
10419 trace_cfg80211_return_bool(ret);
10420 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010421}
Johannes Berg947add32013-02-22 22:05:20 +010010422EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10423
10424bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10425 const u8 *addr, gfp_t gfp)
10426{
10427 struct wireless_dev *wdev = dev->ieee80211_ptr;
10428 bool ret;
10429
10430 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10431
10432 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10433 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10434 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10435 trace_cfg80211_return_bool(false);
10436 return false;
10437 }
10438 ret = __nl80211_unexpected_frame(dev,
10439 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10440 addr, gfp);
10441 trace_cfg80211_return_bool(ret);
10442 return ret;
10443}
10444EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010445
Johannes Berg2e161f72010-08-12 15:38:38 +020010446int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010447 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010448 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010449 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010450{
Johannes Berg71bbc992012-06-15 15:30:18 +020010451 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010452 struct sk_buff *msg;
10453 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010454
10455 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10456 if (!msg)
10457 return -ENOMEM;
10458
Johannes Berg2e161f72010-08-12 15:38:38 +020010459 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010460 if (!hdr) {
10461 nlmsg_free(msg);
10462 return -ENOMEM;
10463 }
10464
David S. Miller9360ffd2012-03-29 04:41:26 -040010465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010466 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10467 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010468 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010469 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10470 (sig_dbm &&
10471 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010472 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10473 (flags &&
10474 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010475 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010476
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010477 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010478
Eric W. Biederman15e47302012-09-07 20:12:54 +000010479 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010480
10481 nla_put_failure:
10482 genlmsg_cancel(msg, hdr);
10483 nlmsg_free(msg);
10484 return -ENOBUFS;
10485}
10486
Johannes Berg947add32013-02-22 22:05:20 +010010487void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10488 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010489{
Johannes Berg947add32013-02-22 22:05:20 +010010490 struct wiphy *wiphy = wdev->wiphy;
10491 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010492 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010493 struct sk_buff *msg;
10494 void *hdr;
10495
Johannes Berg947add32013-02-22 22:05:20 +010010496 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10497
Jouni Malinen026331c2010-02-15 12:53:10 +020010498 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10499 if (!msg)
10500 return;
10501
Johannes Berg2e161f72010-08-12 15:38:38 +020010502 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010503 if (!hdr) {
10504 nlmsg_free(msg);
10505 return;
10506 }
10507
David S. Miller9360ffd2012-03-29 04:41:26 -040010508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010509 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10510 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010511 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010512 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10513 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10514 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10515 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010516
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010517 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010518
10519 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10520 return;
10521
10522 nla_put_failure:
10523 genlmsg_cancel(msg, hdr);
10524 nlmsg_free(msg);
10525}
Johannes Berg947add32013-02-22 22:05:20 +010010526EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010527
Johannes Berg947add32013-02-22 22:05:20 +010010528void cfg80211_cqm_rssi_notify(struct net_device *dev,
10529 enum nl80211_cqm_rssi_threshold_event rssi_event,
10530 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010531{
Johannes Berg947add32013-02-22 22:05:20 +010010532 struct wireless_dev *wdev = dev->ieee80211_ptr;
10533 struct wiphy *wiphy = wdev->wiphy;
10534 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010535 struct sk_buff *msg;
10536 struct nlattr *pinfoattr;
10537 void *hdr;
10538
Johannes Berg947add32013-02-22 22:05:20 +010010539 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10540
Thomas Graf58050fc2012-06-28 03:57:45 +000010541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010542 if (!msg)
10543 return;
10544
10545 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10546 if (!hdr) {
10547 nlmsg_free(msg);
10548 return;
10549 }
10550
David S. Miller9360ffd2012-03-29 04:41:26 -040010551 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010552 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010553 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010554
10555 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10556 if (!pinfoattr)
10557 goto nla_put_failure;
10558
David S. Miller9360ffd2012-03-29 04:41:26 -040010559 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10560 rssi_event))
10561 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010562
10563 nla_nest_end(msg, pinfoattr);
10564
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010565 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010566
10567 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10568 nl80211_mlme_mcgrp.id, gfp);
10569 return;
10570
10571 nla_put_failure:
10572 genlmsg_cancel(msg, hdr);
10573 nlmsg_free(msg);
10574}
Johannes Berg947add32013-02-22 22:05:20 +010010575EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010576
Johannes Berg947add32013-02-22 22:05:20 +010010577static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10578 struct net_device *netdev, const u8 *bssid,
10579 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010580{
10581 struct sk_buff *msg;
10582 struct nlattr *rekey_attr;
10583 void *hdr;
10584
Thomas Graf58050fc2012-06-28 03:57:45 +000010585 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010586 if (!msg)
10587 return;
10588
10589 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10590 if (!hdr) {
10591 nlmsg_free(msg);
10592 return;
10593 }
10594
David S. Miller9360ffd2012-03-29 04:41:26 -040010595 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10596 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10597 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10598 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010599
10600 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10601 if (!rekey_attr)
10602 goto nla_put_failure;
10603
David S. Miller9360ffd2012-03-29 04:41:26 -040010604 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10605 NL80211_REPLAY_CTR_LEN, replay_ctr))
10606 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010607
10608 nla_nest_end(msg, rekey_attr);
10609
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010610 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010611
10612 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10613 nl80211_mlme_mcgrp.id, gfp);
10614 return;
10615
10616 nla_put_failure:
10617 genlmsg_cancel(msg, hdr);
10618 nlmsg_free(msg);
10619}
10620
Johannes Berg947add32013-02-22 22:05:20 +010010621void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10622 const u8 *replay_ctr, gfp_t gfp)
10623{
10624 struct wireless_dev *wdev = dev->ieee80211_ptr;
10625 struct wiphy *wiphy = wdev->wiphy;
10626 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10627
10628 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10629 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10630}
10631EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10632
10633static void
10634nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10635 struct net_device *netdev, int index,
10636 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010637{
10638 struct sk_buff *msg;
10639 struct nlattr *attr;
10640 void *hdr;
10641
Thomas Graf58050fc2012-06-28 03:57:45 +000010642 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010643 if (!msg)
10644 return;
10645
10646 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10647 if (!hdr) {
10648 nlmsg_free(msg);
10649 return;
10650 }
10651
David S. Miller9360ffd2012-03-29 04:41:26 -040010652 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10653 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10654 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010655
10656 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10657 if (!attr)
10658 goto nla_put_failure;
10659
David S. Miller9360ffd2012-03-29 04:41:26 -040010660 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10661 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10662 (preauth &&
10663 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10664 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010665
10666 nla_nest_end(msg, attr);
10667
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010668 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010669
10670 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10671 nl80211_mlme_mcgrp.id, gfp);
10672 return;
10673
10674 nla_put_failure:
10675 genlmsg_cancel(msg, hdr);
10676 nlmsg_free(msg);
10677}
10678
Johannes Berg947add32013-02-22 22:05:20 +010010679void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10680 const u8 *bssid, bool preauth, gfp_t gfp)
10681{
10682 struct wireless_dev *wdev = dev->ieee80211_ptr;
10683 struct wiphy *wiphy = wdev->wiphy;
10684 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10685
10686 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10687 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10688}
10689EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10690
10691static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10692 struct net_device *netdev,
10693 struct cfg80211_chan_def *chandef,
10694 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010695{
10696 struct sk_buff *msg;
10697 void *hdr;
10698
Thomas Graf58050fc2012-06-28 03:57:45 +000010699 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010700 if (!msg)
10701 return;
10702
10703 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10704 if (!hdr) {
10705 nlmsg_free(msg);
10706 return;
10707 }
10708
Johannes Berg683b6d32012-11-08 21:25:48 +010010709 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10710 goto nla_put_failure;
10711
10712 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010713 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010714
10715 genlmsg_end(msg, hdr);
10716
10717 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10718 nl80211_mlme_mcgrp.id, gfp);
10719 return;
10720
10721 nla_put_failure:
10722 genlmsg_cancel(msg, hdr);
10723 nlmsg_free(msg);
10724}
10725
Johannes Berg947add32013-02-22 22:05:20 +010010726void cfg80211_ch_switch_notify(struct net_device *dev,
10727 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010728{
Johannes Berg947add32013-02-22 22:05:20 +010010729 struct wireless_dev *wdev = dev->ieee80211_ptr;
10730 struct wiphy *wiphy = wdev->wiphy;
10731 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10732
10733 trace_cfg80211_ch_switch_notify(dev, chandef);
10734
10735 wdev_lock(wdev);
10736
10737 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10738 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10739 goto out;
10740
10741 wdev->channel = chandef->chan;
10742 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10743out:
10744 wdev_unlock(wdev);
10745 return;
10746}
10747EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10748
10749void cfg80211_cqm_txe_notify(struct net_device *dev,
10750 const u8 *peer, u32 num_packets,
10751 u32 rate, u32 intvl, gfp_t gfp)
10752{
10753 struct wireless_dev *wdev = dev->ieee80211_ptr;
10754 struct wiphy *wiphy = wdev->wiphy;
10755 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010756 struct sk_buff *msg;
10757 struct nlattr *pinfoattr;
10758 void *hdr;
10759
10760 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10761 if (!msg)
10762 return;
10763
10764 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10765 if (!hdr) {
10766 nlmsg_free(msg);
10767 return;
10768 }
10769
10770 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010771 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010772 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10773 goto nla_put_failure;
10774
10775 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10776 if (!pinfoattr)
10777 goto nla_put_failure;
10778
10779 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10780 goto nla_put_failure;
10781
10782 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10783 goto nla_put_failure;
10784
10785 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10786 goto nla_put_failure;
10787
10788 nla_nest_end(msg, pinfoattr);
10789
10790 genlmsg_end(msg, hdr);
10791
10792 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10793 nl80211_mlme_mcgrp.id, gfp);
10794 return;
10795
10796 nla_put_failure:
10797 genlmsg_cancel(msg, hdr);
10798 nlmsg_free(msg);
10799}
Johannes Berg947add32013-02-22 22:05:20 +010010800EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010801
10802void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010803nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10804 struct cfg80211_chan_def *chandef,
10805 enum nl80211_radar_event event,
10806 struct net_device *netdev, gfp_t gfp)
10807{
10808 struct sk_buff *msg;
10809 void *hdr;
10810
10811 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10812 if (!msg)
10813 return;
10814
10815 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10816 if (!hdr) {
10817 nlmsg_free(msg);
10818 return;
10819 }
10820
10821 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10822 goto nla_put_failure;
10823
10824 /* NOP and radar events don't need a netdev parameter */
10825 if (netdev) {
10826 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10827
10828 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10829 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10830 goto nla_put_failure;
10831 }
10832
10833 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10834 goto nla_put_failure;
10835
10836 if (nl80211_send_chandef(msg, chandef))
10837 goto nla_put_failure;
10838
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010839 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010840
10841 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10842 nl80211_mlme_mcgrp.id, gfp);
10843 return;
10844
10845 nla_put_failure:
10846 genlmsg_cancel(msg, hdr);
10847 nlmsg_free(msg);
10848}
10849
Johannes Berg947add32013-02-22 22:05:20 +010010850void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10851 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010852{
Johannes Berg947add32013-02-22 22:05:20 +010010853 struct wireless_dev *wdev = dev->ieee80211_ptr;
10854 struct wiphy *wiphy = wdev->wiphy;
10855 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010856 struct sk_buff *msg;
10857 struct nlattr *pinfoattr;
10858 void *hdr;
10859
Johannes Berg947add32013-02-22 22:05:20 +010010860 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10861
Thomas Graf58050fc2012-06-28 03:57:45 +000010862 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010863 if (!msg)
10864 return;
10865
10866 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10867 if (!hdr) {
10868 nlmsg_free(msg);
10869 return;
10870 }
10871
David S. Miller9360ffd2012-03-29 04:41:26 -040010872 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010873 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010874 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10875 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010876
10877 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10878 if (!pinfoattr)
10879 goto nla_put_failure;
10880
David S. Miller9360ffd2012-03-29 04:41:26 -040010881 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10882 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010883
10884 nla_nest_end(msg, pinfoattr);
10885
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010886 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010887
10888 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10889 nl80211_mlme_mcgrp.id, gfp);
10890 return;
10891
10892 nla_put_failure:
10893 genlmsg_cancel(msg, hdr);
10894 nlmsg_free(msg);
10895}
Johannes Berg947add32013-02-22 22:05:20 +010010896EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010897
Johannes Berg7f6cf312011-11-04 11:18:15 +010010898void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10899 u64 cookie, bool acked, gfp_t gfp)
10900{
10901 struct wireless_dev *wdev = dev->ieee80211_ptr;
10902 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10903 struct sk_buff *msg;
10904 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010905
Beni Lev4ee3e062012-08-27 12:49:39 +030010906 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10907
Thomas Graf58050fc2012-06-28 03:57:45 +000010908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010909
Johannes Berg7f6cf312011-11-04 11:18:15 +010010910 if (!msg)
10911 return;
10912
10913 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10914 if (!hdr) {
10915 nlmsg_free(msg);
10916 return;
10917 }
10918
David S. Miller9360ffd2012-03-29 04:41:26 -040010919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10920 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10921 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10922 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10923 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10924 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010925
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010926 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010927
10928 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10929 nl80211_mlme_mcgrp.id, gfp);
10930 return;
10931
10932 nla_put_failure:
10933 genlmsg_cancel(msg, hdr);
10934 nlmsg_free(msg);
10935}
10936EXPORT_SYMBOL(cfg80211_probe_status);
10937
Johannes Berg5e760232011-11-04 11:18:17 +010010938void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10939 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010940 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010941{
10942 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10943 struct sk_buff *msg;
10944 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010945 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010946
Beni Lev4ee3e062012-08-27 12:49:39 +030010947 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10948
Ben Greear37c73b52012-10-26 14:49:25 -070010949 spin_lock_bh(&rdev->beacon_registrations_lock);
10950 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10951 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10952 if (!msg) {
10953 spin_unlock_bh(&rdev->beacon_registrations_lock);
10954 return;
10955 }
Johannes Berg5e760232011-11-04 11:18:17 +010010956
Ben Greear37c73b52012-10-26 14:49:25 -070010957 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10958 if (!hdr)
10959 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010960
Ben Greear37c73b52012-10-26 14:49:25 -070010961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10962 (freq &&
10963 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10964 (sig_dbm &&
10965 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10966 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10967 goto nla_put_failure;
10968
10969 genlmsg_end(msg, hdr);
10970
10971 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010972 }
Ben Greear37c73b52012-10-26 14:49:25 -070010973 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010974 return;
10975
10976 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010977 spin_unlock_bh(&rdev->beacon_registrations_lock);
10978 if (hdr)
10979 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010980 nlmsg_free(msg);
10981}
10982EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10983
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010984#ifdef CONFIG_PM
10985void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10986 struct cfg80211_wowlan_wakeup *wakeup,
10987 gfp_t gfp)
10988{
10989 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10990 struct sk_buff *msg;
10991 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010992 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010993
10994 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10995
10996 if (wakeup)
10997 size += wakeup->packet_present_len;
10998
10999 msg = nlmsg_new(size, gfp);
11000 if (!msg)
11001 return;
11002
11003 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11004 if (!hdr)
11005 goto free_msg;
11006
11007 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11008 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11009 goto free_msg;
11010
11011 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11012 wdev->netdev->ifindex))
11013 goto free_msg;
11014
11015 if (wakeup) {
11016 struct nlattr *reasons;
11017
11018 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11019
11020 if (wakeup->disconnect &&
11021 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11022 goto free_msg;
11023 if (wakeup->magic_pkt &&
11024 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11025 goto free_msg;
11026 if (wakeup->gtk_rekey_failure &&
11027 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11028 goto free_msg;
11029 if (wakeup->eap_identity_req &&
11030 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11031 goto free_msg;
11032 if (wakeup->four_way_handshake &&
11033 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11034 goto free_msg;
11035 if (wakeup->rfkill_release &&
11036 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11037 goto free_msg;
11038
11039 if (wakeup->pattern_idx >= 0 &&
11040 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11041 wakeup->pattern_idx))
11042 goto free_msg;
11043
Johannes Berg2a0e0472013-01-23 22:57:40 +010011044 if (wakeup->tcp_match)
11045 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11046
11047 if (wakeup->tcp_connlost)
11048 nla_put_flag(msg,
11049 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11050
11051 if (wakeup->tcp_nomoretokens)
11052 nla_put_flag(msg,
11053 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11054
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011055 if (wakeup->packet) {
11056 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11057 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11058
11059 if (!wakeup->packet_80211) {
11060 pkt_attr =
11061 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11062 len_attr =
11063 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11064 }
11065
11066 if (wakeup->packet_len &&
11067 nla_put_u32(msg, len_attr, wakeup->packet_len))
11068 goto free_msg;
11069
11070 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11071 wakeup->packet))
11072 goto free_msg;
11073 }
11074
11075 nla_nest_end(msg, reasons);
11076 }
11077
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011078 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011079
11080 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11081 nl80211_mlme_mcgrp.id, gfp);
11082 return;
11083
11084 free_msg:
11085 nlmsg_free(msg);
11086}
11087EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11088#endif
11089
Jouni Malinen3475b092012-11-16 22:49:57 +020011090void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11091 enum nl80211_tdls_operation oper,
11092 u16 reason_code, gfp_t gfp)
11093{
11094 struct wireless_dev *wdev = dev->ieee80211_ptr;
11095 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11096 struct sk_buff *msg;
11097 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011098
11099 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11100 reason_code);
11101
11102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11103 if (!msg)
11104 return;
11105
11106 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11107 if (!hdr) {
11108 nlmsg_free(msg);
11109 return;
11110 }
11111
11112 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11113 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11114 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11115 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11116 (reason_code > 0 &&
11117 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11118 goto nla_put_failure;
11119
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011120 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011121
11122 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11123 nl80211_mlme_mcgrp.id, gfp);
11124 return;
11125
11126 nla_put_failure:
11127 genlmsg_cancel(msg, hdr);
11128 nlmsg_free(msg);
11129}
11130EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11131
Jouni Malinen026331c2010-02-15 12:53:10 +020011132static int nl80211_netlink_notify(struct notifier_block * nb,
11133 unsigned long state,
11134 void *_notify)
11135{
11136 struct netlink_notify *notify = _notify;
11137 struct cfg80211_registered_device *rdev;
11138 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011139 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011140
11141 if (state != NETLINK_URELEASE)
11142 return NOTIFY_DONE;
11143
11144 rcu_read_lock();
11145
Johannes Berg5e760232011-11-04 11:18:17 +010011146 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011147 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011148 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011149
11150 spin_lock_bh(&rdev->beacon_registrations_lock);
11151 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11152 list) {
11153 if (reg->nlportid == notify->portid) {
11154 list_del(&reg->list);
11155 kfree(reg);
11156 break;
11157 }
11158 }
11159 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011160 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011161
11162 rcu_read_unlock();
11163
11164 return NOTIFY_DONE;
11165}
11166
11167static struct notifier_block nl80211_netlink_notifier = {
11168 .notifier_call = nl80211_netlink_notify,
11169};
11170
Jouni Malinen355199e2013-02-27 17:14:27 +020011171void cfg80211_ft_event(struct net_device *netdev,
11172 struct cfg80211_ft_event_params *ft_event)
11173{
11174 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11175 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11176 struct sk_buff *msg;
11177 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011178
11179 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11180
11181 if (!ft_event->target_ap)
11182 return;
11183
11184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11185 if (!msg)
11186 return;
11187
11188 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11189 if (!hdr) {
11190 nlmsg_free(msg);
11191 return;
11192 }
11193
11194 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11195 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11196 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11197 if (ft_event->ies)
11198 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11199 if (ft_event->ric_ies)
11200 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11201 ft_event->ric_ies);
11202
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011203 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011204
11205 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11206 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11207}
11208EXPORT_SYMBOL(cfg80211_ft_event);
11209
Arend van Spriel5de17982013-04-18 15:49:00 +020011210void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11211{
11212 struct cfg80211_registered_device *rdev;
11213 struct sk_buff *msg;
11214 void *hdr;
11215 u32 nlportid;
11216
11217 rdev = wiphy_to_dev(wdev->wiphy);
11218 if (!rdev->crit_proto_nlportid)
11219 return;
11220
11221 nlportid = rdev->crit_proto_nlportid;
11222 rdev->crit_proto_nlportid = 0;
11223
11224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11225 if (!msg)
11226 return;
11227
11228 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11229 if (!hdr)
11230 goto nla_put_failure;
11231
11232 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11233 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11234 goto nla_put_failure;
11235
11236 genlmsg_end(msg, hdr);
11237
11238 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11239 return;
11240
11241 nla_put_failure:
11242 if (hdr)
11243 genlmsg_cancel(msg, hdr);
11244 nlmsg_free(msg);
11245
11246}
11247EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11248
Johannes Berg55682962007-09-20 13:09:35 -040011249/* initialisation/exit functions */
11250
11251int nl80211_init(void)
11252{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011253 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011254
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011255 err = genl_register_family_with_ops(&nl80211_fam,
11256 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011257 if (err)
11258 return err;
11259
Johannes Berg55682962007-09-20 13:09:35 -040011260 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11261 if (err)
11262 goto err_out;
11263
Johannes Berg2a519312009-02-10 21:25:55 +010011264 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11265 if (err)
11266 goto err_out;
11267
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011268 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11269 if (err)
11270 goto err_out;
11271
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011272 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11273 if (err)
11274 goto err_out;
11275
Johannes Bergaff89a92009-07-01 21:26:51 +020011276#ifdef CONFIG_NL80211_TESTMODE
11277 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11278 if (err)
11279 goto err_out;
11280#endif
11281
Jouni Malinen026331c2010-02-15 12:53:10 +020011282 err = netlink_register_notifier(&nl80211_netlink_notifier);
11283 if (err)
11284 goto err_out;
11285
Johannes Berg55682962007-09-20 13:09:35 -040011286 return 0;
11287 err_out:
11288 genl_unregister_family(&nl80211_fam);
11289 return err;
11290}
11291
11292void nl80211_exit(void)
11293{
Jouni Malinen026331c2010-02-15 12:53:10 +020011294 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011295 genl_unregister_family(&nl80211_fam);
11296}