blob: 8aa83c04d4ebf68b5686e52f3ca35da585844043 [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 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Johannes Berge5497d72011-07-05 16:35:40 +0200406/* policy for GTK rekey offload attributes */
407static const struct nla_policy
408nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
409 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
410 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
411 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
412};
413
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300414static const struct nla_policy
415nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300417 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300419};
420
Johannes Berg97990a02013-04-19 01:02:55 +0200421static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
422 struct netlink_callback *cb,
423 struct cfg80211_registered_device **rdev,
424 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100425{
Johannes Berg67748892010-10-04 21:14:06 +0200426 int err;
427
Johannes Berg67748892010-10-04 21:14:06 +0200428 rtnl_lock();
429
Johannes Berg97990a02013-04-19 01:02:55 +0200430 if (!cb->args[0]) {
431 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
432 nl80211_fam.attrbuf, nl80211_fam.maxattr,
433 nl80211_policy);
434 if (err)
435 goto out_unlock;
436
437 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
438 nl80211_fam.attrbuf);
439 if (IS_ERR(*wdev)) {
440 err = PTR_ERR(*wdev);
441 goto out_unlock;
442 }
443 *rdev = wiphy_to_dev((*wdev)->wiphy);
444 cb->args[0] = (*rdev)->wiphy_idx;
445 cb->args[1] = (*wdev)->identifier;
446 } else {
447 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
448 struct wireless_dev *tmp;
449
450 if (!wiphy) {
451 err = -ENODEV;
452 goto out_unlock;
453 }
454 *rdev = wiphy_to_dev(wiphy);
455 *wdev = NULL;
456
Johannes Berg97990a02013-04-19 01:02:55 +0200457 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
458 if (tmp->identifier == cb->args[1]) {
459 *wdev = tmp;
460 break;
461 }
462 }
Johannes Berg97990a02013-04-19 01:02:55 +0200463
464 if (!*wdev) {
465 err = -ENODEV;
466 goto out_unlock;
467 }
Johannes Berg67748892010-10-04 21:14:06 +0200468 }
469
Johannes Berg67748892010-10-04 21:14:06 +0200470 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200471 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200472 rtnl_unlock();
473 return err;
474}
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200477{
Johannes Berg67748892010-10-04 21:14:06 +0200478 rtnl_unlock();
479}
480
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100481/* IE validation */
482static bool is_valid_ie_attr(const struct nlattr *attr)
483{
484 const u8 *pos;
485 int len;
486
487 if (!attr)
488 return true;
489
490 pos = nla_data(attr);
491 len = nla_len(attr);
492
493 while (len) {
494 u8 elemlen;
495
496 if (len < 2)
497 return false;
498 len -= 2;
499
500 elemlen = pos[1];
501 if (elemlen > len)
502 return false;
503
504 len -= elemlen;
505 pos += 2 + elemlen;
506 }
507
508 return true;
509}
510
Johannes Berg55682962007-09-20 13:09:35 -0400511/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000512static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400513 int flags, u8 cmd)
514{
515 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000516 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400517}
518
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400519static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100520 struct ieee80211_channel *chan,
521 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400522{
David S. Miller9360ffd2012-03-29 04:41:26 -0400523 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
524 chan->center_freq))
525 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400526
David S. Miller9360ffd2012-03-29 04:41:26 -0400527 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
528 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
529 goto nla_put_failure;
530 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
531 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
532 goto nla_put_failure;
533 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
534 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
535 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100536 if (chan->flags & IEEE80211_CHAN_RADAR) {
537 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
538 goto nla_put_failure;
539 if (large) {
540 u32 time;
541
542 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
543
544 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
545 chan->dfs_state))
546 goto nla_put_failure;
547 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
548 time))
549 goto nla_put_failure;
550 }
551 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100553 if (large) {
554 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
565 goto nla_put_failure;
566 }
567
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
569 DBM_TO_MBM(chan->max_power)))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
572 return 0;
573
574 nla_put_failure:
575 return -ENOBUFS;
576}
577
Johannes Berg55682962007-09-20 13:09:35 -0400578/* netlink command implementations */
579
Johannes Bergb9454e82009-07-08 13:29:08 +0200580struct key_parse {
581 struct key_params p;
582 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200583 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200584 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100585 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200586};
587
588static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
589{
590 struct nlattr *tb[NL80211_KEY_MAX + 1];
591 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
592 nl80211_key_policy);
593 if (err)
594 return err;
595
596 k->def = !!tb[NL80211_KEY_DEFAULT];
597 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
598
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100599 if (k->def) {
600 k->def_uni = true;
601 k->def_multi = true;
602 }
603 if (k->defmgmt)
604 k->def_multi = true;
605
Johannes Bergb9454e82009-07-08 13:29:08 +0200606 if (tb[NL80211_KEY_IDX])
607 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
608
609 if (tb[NL80211_KEY_DATA]) {
610 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
611 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
612 }
613
614 if (tb[NL80211_KEY_SEQ]) {
615 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
616 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
617 }
618
619 if (tb[NL80211_KEY_CIPHER])
620 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
621
Johannes Berge31b8212010-10-05 19:39:30 +0200622 if (tb[NL80211_KEY_TYPE]) {
623 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
624 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
625 return -EINVAL;
626 }
627
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100628 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
629 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100630 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
631 tb[NL80211_KEY_DEFAULT_TYPES],
632 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100633 if (err)
634 return err;
635
636 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
637 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
638 }
639
Johannes Bergb9454e82009-07-08 13:29:08 +0200640 return 0;
641}
642
643static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
644{
645 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
646 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
647 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
648 }
649
650 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
651 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
652 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
653 }
654
655 if (info->attrs[NL80211_ATTR_KEY_IDX])
656 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
657
658 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
659 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
660
661 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
662 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
663
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 if (k->def) {
665 k->def_uni = true;
666 k->def_multi = true;
667 }
668 if (k->defmgmt)
669 k->def_multi = true;
670
Johannes Berge31b8212010-10-05 19:39:30 +0200671 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
672 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
673 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
674 return -EINVAL;
675 }
676
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
678 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
679 int err = nla_parse_nested(
680 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
681 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
682 nl80211_key_default_policy);
683 if (err)
684 return err;
685
686 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
687 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
688 }
689
Johannes Bergb9454e82009-07-08 13:29:08 +0200690 return 0;
691}
692
693static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
694{
695 int err;
696
697 memset(k, 0, sizeof(*k));
698 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200699 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200700
701 if (info->attrs[NL80211_ATTR_KEY])
702 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
703 else
704 err = nl80211_parse_key_old(info, k);
705
706 if (err)
707 return err;
708
709 if (k->def && k->defmgmt)
710 return -EINVAL;
711
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (k->defmgmt) {
713 if (k->def_uni || !k->def_multi)
714 return -EINVAL;
715 }
716
Johannes Bergb9454e82009-07-08 13:29:08 +0200717 if (k->idx != -1) {
718 if (k->defmgmt) {
719 if (k->idx < 4 || k->idx > 5)
720 return -EINVAL;
721 } else if (k->def) {
722 if (k->idx < 0 || k->idx > 3)
723 return -EINVAL;
724 } else {
725 if (k->idx < 0 || k->idx > 5)
726 return -EINVAL;
727 }
728 }
729
730 return 0;
731}
732
Johannes Bergfffd0932009-07-08 14:22:54 +0200733static struct cfg80211_cached_keys *
734nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530735 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200736{
737 struct key_parse parse;
738 struct nlattr *key;
739 struct cfg80211_cached_keys *result;
740 int rem, err, def = 0;
741
742 result = kzalloc(sizeof(*result), GFP_KERNEL);
743 if (!result)
744 return ERR_PTR(-ENOMEM);
745
746 result->def = -1;
747 result->defmgmt = -1;
748
749 nla_for_each_nested(key, keys, rem) {
750 memset(&parse, 0, sizeof(parse));
751 parse.idx = -1;
752
753 err = nl80211_parse_key_new(key, &parse);
754 if (err)
755 goto error;
756 err = -EINVAL;
757 if (!parse.p.key)
758 goto error;
759 if (parse.idx < 0 || parse.idx > 4)
760 goto error;
761 if (parse.def) {
762 if (def)
763 goto error;
764 def = 1;
765 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100766 if (!parse.def_uni || !parse.def_multi)
767 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200768 } else if (parse.defmgmt)
769 goto error;
770 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200771 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (err)
773 goto error;
774 result->params[parse.idx].cipher = parse.p.cipher;
775 result->params[parse.idx].key_len = parse.p.key_len;
776 result->params[parse.idx].key = result->data[parse.idx];
777 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530778
779 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
780 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
781 if (no_ht)
782 *no_ht = true;
783 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200784 }
785
786 return result;
787 error:
788 kfree(result);
789 return ERR_PTR(err);
790}
791
792static int nl80211_key_allowed(struct wireless_dev *wdev)
793{
794 ASSERT_WDEV_LOCK(wdev);
795
Johannes Bergfffd0932009-07-08 14:22:54 +0200796 switch (wdev->iftype) {
797 case NL80211_IFTYPE_AP:
798 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200799 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700800 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200801 break;
802 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200803 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200804 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200805 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806 return -ENOLINK;
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 return 0;
813}
814
Johannes Berg7527a782011-05-13 10:58:57 +0200815static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
816{
817 struct nlattr *nl_modes = nla_nest_start(msg, attr);
818 int i;
819
820 if (!nl_modes)
821 goto nla_put_failure;
822
823 i = 0;
824 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400825 if ((ifmodes & 1) && nla_put_flag(msg, i))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 ifmodes >>= 1;
828 i++;
829 }
830
831 nla_nest_end(msg, nl_modes);
832 return 0;
833
834nla_put_failure:
835 return -ENOBUFS;
836}
837
838static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100839 struct sk_buff *msg,
840 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200841{
842 struct nlattr *nl_combis;
843 int i, j;
844
845 nl_combis = nla_nest_start(msg,
846 NL80211_ATTR_INTERFACE_COMBINATIONS);
847 if (!nl_combis)
848 goto nla_put_failure;
849
850 for (i = 0; i < wiphy->n_iface_combinations; i++) {
851 const struct ieee80211_iface_combination *c;
852 struct nlattr *nl_combi, *nl_limits;
853
854 c = &wiphy->iface_combinations[i];
855
856 nl_combi = nla_nest_start(msg, i + 1);
857 if (!nl_combi)
858 goto nla_put_failure;
859
860 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
861 if (!nl_limits)
862 goto nla_put_failure;
863
864 for (j = 0; j < c->n_limits; j++) {
865 struct nlattr *nl_limit;
866
867 nl_limit = nla_nest_start(msg, j + 1);
868 if (!nl_limit)
869 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
871 c->limits[j].max))
872 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200873 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
874 c->limits[j].types))
875 goto nla_put_failure;
876 nla_nest_end(msg, nl_limit);
877 }
878
879 nla_nest_end(msg, nl_limits);
880
David S. Miller9360ffd2012-03-29 04:41:26 -0400881 if (c->beacon_int_infra_match &&
882 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
883 goto nla_put_failure;
884 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
885 c->num_different_channels) ||
886 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
887 c->max_interfaces))
888 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100889 if (large &&
890 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
891 c->radar_detect_widths))
892 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200893
894 nla_nest_end(msg, nl_combi);
895 }
896
897 nla_nest_end(msg, nl_combis);
898
899 return 0;
900nla_put_failure:
901 return -ENOBUFS;
902}
903
Johannes Berg3713b4e2013-02-14 16:19:38 +0100904#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100905static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
906 struct sk_buff *msg)
907{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200908 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100909 struct nlattr *nl_tcp;
910
911 if (!tcp)
912 return 0;
913
914 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
915 if (!nl_tcp)
916 return -ENOBUFS;
917
918 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
919 tcp->data_payload_max))
920 return -ENOBUFS;
921
922 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
923 tcp->data_payload_max))
924 return -ENOBUFS;
925
926 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
927 return -ENOBUFS;
928
929 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
930 sizeof(*tcp->tok), tcp->tok))
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
934 tcp->data_interval_max))
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
938 tcp->wake_payload_max))
939 return -ENOBUFS;
940
941 nla_nest_end(msg, nl_tcp);
942 return 0;
943}
944
Johannes Berg3713b4e2013-02-14 16:19:38 +0100945static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100946 struct cfg80211_registered_device *dev,
947 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948{
949 struct nlattr *nl_wowlan;
950
Johannes Berg964dc9e2013-06-03 17:25:34 +0200951 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100952 return 0;
953
954 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
955 if (!nl_wowlan)
956 return -ENOBUFS;
957
Johannes Berg964dc9e2013-06-03 17:25:34 +0200958 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200960 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200962 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200964 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
974 return -ENOBUFS;
975
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 if (dev->wiphy.wowlan->n_patterns) {
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 struct nl80211_wowlan_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 .max_patterns = dev->wiphy.wowlan->n_patterns,
979 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
980 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
981 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 };
983
984 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
985 sizeof(pat), &pat))
986 return -ENOBUFS;
987 }
988
Johannes Bergb56cf722013-02-20 01:02:38 +0100989 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
990 return -ENOBUFS;
991
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992 nla_nest_end(msg, nl_wowlan);
993
994 return 0;
995}
996#endif
997
998static int nl80211_send_band_rateinfo(struct sk_buff *msg,
999 struct ieee80211_supported_band *sband)
1000{
1001 struct nlattr *nl_rates, *nl_rate;
1002 struct ieee80211_rate *rate;
1003 int i;
1004
1005 /* add HT info */
1006 if (sband->ht_cap.ht_supported &&
1007 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1008 sizeof(sband->ht_cap.mcs),
1009 &sband->ht_cap.mcs) ||
1010 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1011 sband->ht_cap.cap) ||
1012 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1013 sband->ht_cap.ampdu_factor) ||
1014 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1015 sband->ht_cap.ampdu_density)))
1016 return -ENOBUFS;
1017
1018 /* add VHT info */
1019 if (sband->vht_cap.vht_supported &&
1020 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1021 sizeof(sband->vht_cap.vht_mcs),
1022 &sband->vht_cap.vht_mcs) ||
1023 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1024 sband->vht_cap.cap)))
1025 return -ENOBUFS;
1026
1027 /* add bitrates */
1028 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1029 if (!nl_rates)
1030 return -ENOBUFS;
1031
1032 for (i = 0; i < sband->n_bitrates; i++) {
1033 nl_rate = nla_nest_start(msg, i);
1034 if (!nl_rate)
1035 return -ENOBUFS;
1036
1037 rate = &sband->bitrates[i];
1038 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1039 rate->bitrate))
1040 return -ENOBUFS;
1041 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1042 nla_put_flag(msg,
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_rate);
1047 }
1048
1049 nla_nest_end(msg, nl_rates);
1050
1051 return 0;
1052}
1053
1054static int
1055nl80211_send_mgmt_stypes(struct sk_buff *msg,
1056 const struct ieee80211_txrx_stypes *mgmt_stypes)
1057{
1058 u16 stypes;
1059 struct nlattr *nl_ftypes, *nl_ifs;
1060 enum nl80211_iftype ift;
1061 int i;
1062
1063 if (!mgmt_stypes)
1064 return 0;
1065
1066 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1067 if (!nl_ifs)
1068 return -ENOBUFS;
1069
1070 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1071 nl_ftypes = nla_nest_start(msg, ift);
1072 if (!nl_ftypes)
1073 return -ENOBUFS;
1074 i = 0;
1075 stypes = mgmt_stypes[ift].tx;
1076 while (stypes) {
1077 if ((stypes & 1) &&
1078 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1079 (i << 4) | IEEE80211_FTYPE_MGMT))
1080 return -ENOBUFS;
1081 stypes >>= 1;
1082 i++;
1083 }
1084 nla_nest_end(msg, nl_ftypes);
1085 }
1086
1087 nla_nest_end(msg, nl_ifs);
1088
1089 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1090 if (!nl_ifs)
1091 return -ENOBUFS;
1092
1093 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1094 nl_ftypes = nla_nest_start(msg, ift);
1095 if (!nl_ftypes)
1096 return -ENOBUFS;
1097 i = 0;
1098 stypes = mgmt_stypes[ift].rx;
1099 while (stypes) {
1100 if ((stypes & 1) &&
1101 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1102 (i << 4) | IEEE80211_FTYPE_MGMT))
1103 return -ENOBUFS;
1104 stypes >>= 1;
1105 i++;
1106 }
1107 nla_nest_end(msg, nl_ftypes);
1108 }
1109 nla_nest_end(msg, nl_ifs);
1110
1111 return 0;
1112}
1113
1114static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1115 struct sk_buff *msg, u32 portid, u32 seq,
1116 int flags, bool split, long *split_start,
1117 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001118{
1119 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001120 struct nlattr *nl_bands, *nl_band;
1121 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001122 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001123 enum ieee80211_band band;
1124 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001125 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001126 const struct ieee80211_txrx_stypes *mgmt_stypes =
1127 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001129 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001130
Eric W. Biederman15e47302012-09-07 20:12:54 +00001131 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001132 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133 return -ENOBUFS;
1134
1135 /* allow always using the variables */
1136 if (!split) {
1137 split_start = &start;
1138 band_start = &start_band;
1139 chan_start = &start_chan;
1140 }
Johannes Berg55682962007-09-20 13:09:35 -04001141
David S. Miller9360ffd2012-03-29 04:41:26 -04001142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1144 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001145 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001148
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 switch (*split_start) {
1150 case 0:
1151 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1152 dev->wiphy.retry_short) ||
1153 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1154 dev->wiphy.retry_long) ||
1155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1156 dev->wiphy.frag_threshold) ||
1157 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1158 dev->wiphy.rts_threshold) ||
1159 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1160 dev->wiphy.coverage_class) ||
1161 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1162 dev->wiphy.max_scan_ssids) ||
1163 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1164 dev->wiphy.max_sched_scan_ssids) ||
1165 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1166 dev->wiphy.max_scan_ie_len) ||
1167 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1168 dev->wiphy.max_sched_scan_ie_len) ||
1169 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1170 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001171 goto nla_put_failure;
1172
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1174 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1175 goto nla_put_failure;
1176 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1178 goto nla_put_failure;
1179 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1180 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1181 goto nla_put_failure;
1182 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1183 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1184 goto nla_put_failure;
1185 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1186 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1187 goto nla_put_failure;
1188 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1189 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001190 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001191
Johannes Berg3713b4e2013-02-14 16:19:38 +01001192 (*split_start)++;
1193 if (split)
1194 break;
1195 case 1:
1196 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1197 sizeof(u32) * dev->wiphy.n_cipher_suites,
1198 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001199 goto nla_put_failure;
1200
Johannes Berg3713b4e2013-02-14 16:19:38 +01001201 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1202 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001203 goto nla_put_failure;
1204
Johannes Berg3713b4e2013-02-14 16:19:38 +01001205 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1206 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1207 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001208
Johannes Berg3713b4e2013-02-14 16:19:38 +01001209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1210 dev->wiphy.available_antennas_tx) ||
1211 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1212 dev->wiphy.available_antennas_rx))
1213 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001214
Johannes Berg3713b4e2013-02-14 16:19:38 +01001215 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1216 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1217 dev->wiphy.probe_resp_offload))
1218 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001219
Johannes Berg3713b4e2013-02-14 16:19:38 +01001220 if ((dev->wiphy.available_antennas_tx ||
1221 dev->wiphy.available_antennas_rx) &&
1222 dev->ops->get_antenna) {
1223 u32 tx_ant = 0, rx_ant = 0;
1224 int res;
1225 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1226 if (!res) {
1227 if (nla_put_u32(msg,
1228 NL80211_ATTR_WIPHY_ANTENNA_TX,
1229 tx_ant) ||
1230 nla_put_u32(msg,
1231 NL80211_ATTR_WIPHY_ANTENNA_RX,
1232 rx_ant))
1233 goto nla_put_failure;
1234 }
Johannes Bergee688b002008-01-24 19:38:39 +01001235 }
1236
Johannes Berg3713b4e2013-02-14 16:19:38 +01001237 (*split_start)++;
1238 if (split)
1239 break;
1240 case 2:
1241 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1242 dev->wiphy.interface_modes))
1243 goto nla_put_failure;
1244 (*split_start)++;
1245 if (split)
1246 break;
1247 case 3:
1248 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1249 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001250 goto nla_put_failure;
1251
Johannes Berg3713b4e2013-02-14 16:19:38 +01001252 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1253 struct ieee80211_supported_band *sband;
1254
1255 sband = dev->wiphy.bands[band];
1256
1257 if (!sband)
1258 continue;
1259
1260 nl_band = nla_nest_start(msg, band);
1261 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001262 goto nla_put_failure;
1263
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 switch (*chan_start) {
1265 case 0:
1266 if (nl80211_send_band_rateinfo(msg, sband))
1267 goto nla_put_failure;
1268 (*chan_start)++;
1269 if (split)
1270 break;
1271 default:
1272 /* add frequencies */
1273 nl_freqs = nla_nest_start(
1274 msg, NL80211_BAND_ATTR_FREQS);
1275 if (!nl_freqs)
1276 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001277
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 for (i = *chan_start - 1;
1279 i < sband->n_channels;
1280 i++) {
1281 nl_freq = nla_nest_start(msg, i);
1282 if (!nl_freq)
1283 goto nla_put_failure;
1284
1285 chan = &sband->channels[i];
1286
Johannes Bergcdc89b92013-02-18 23:54:36 +01001287 if (nl80211_msg_put_channel(msg, chan,
1288 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 goto nla_put_failure;
1290
1291 nla_nest_end(msg, nl_freq);
1292 if (split)
1293 break;
1294 }
1295 if (i < sband->n_channels)
1296 *chan_start = i + 2;
1297 else
1298 *chan_start = 0;
1299 nla_nest_end(msg, nl_freqs);
1300 }
1301
1302 nla_nest_end(msg, nl_band);
1303
1304 if (split) {
1305 /* start again here */
1306 if (*chan_start)
1307 band--;
1308 break;
1309 }
Johannes Bergee688b002008-01-24 19:38:39 +01001310 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (band < IEEE80211_NUM_BANDS)
1314 *band_start = band + 1;
1315 else
1316 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001317
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 /* if bands & channels are done, continue outside */
1319 if (*band_start == 0 && *chan_start == 0)
1320 (*split_start)++;
1321 if (split)
1322 break;
1323 case 4:
1324 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1325 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327
1328 i = 0;
1329#define CMD(op, n) \
1330 do { \
1331 if (dev->ops->op) { \
1332 i++; \
1333 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1334 goto nla_put_failure; \
1335 } \
1336 } while (0)
1337
1338 CMD(add_virtual_intf, NEW_INTERFACE);
1339 CMD(change_virtual_intf, SET_INTERFACE);
1340 CMD(add_key, NEW_KEY);
1341 CMD(start_ap, START_AP);
1342 CMD(add_station, NEW_STATION);
1343 CMD(add_mpath, NEW_MPATH);
1344 CMD(update_mesh_config, SET_MESH_CONFIG);
1345 CMD(change_bss, SET_BSS);
1346 CMD(auth, AUTHENTICATE);
1347 CMD(assoc, ASSOCIATE);
1348 CMD(deauth, DEAUTHENTICATE);
1349 CMD(disassoc, DISASSOCIATE);
1350 CMD(join_ibss, JOIN_IBSS);
1351 CMD(join_mesh, JOIN_MESH);
1352 CMD(set_pmksa, SET_PMKSA);
1353 CMD(del_pmksa, DEL_PMKSA);
1354 CMD(flush_pmksa, FLUSH_PMKSA);
1355 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1356 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1357 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1358 CMD(mgmt_tx, FRAME);
1359 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1360 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1361 i++;
1362 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1363 goto nla_put_failure;
1364 }
1365 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1366 dev->ops->join_mesh) {
1367 i++;
1368 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1369 goto nla_put_failure;
1370 }
1371 CMD(set_wds_peer, SET_WDS_PEER);
1372 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1373 CMD(tdls_mgmt, TDLS_MGMT);
1374 CMD(tdls_oper, TDLS_OPER);
1375 }
1376 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1377 CMD(sched_scan_start, START_SCHED_SCAN);
1378 CMD(probe_client, PROBE_CLIENT);
1379 CMD(set_noack_map, SET_NOACK_MAP);
1380 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1381 i++;
1382 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1383 goto nla_put_failure;
1384 }
1385 CMD(start_p2p_device, START_P2P_DEVICE);
1386 CMD(set_mcast_rate, SET_MCAST_RATE);
Arend van Spriel5de17982013-04-18 15:49:00 +02001387 if (split) {
1388 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1389 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1390 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001391
Kalle Valo4745fc02011-11-17 19:06:10 +02001392#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001394#endif
1395
Johannes Berg8fdc6212009-03-14 09:34:01 +01001396#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001397
Johannes Berg3713b4e2013-02-14 16:19:38 +01001398 if (dev->ops->connect || dev->ops->auth) {
1399 i++;
1400 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001401 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001402 }
1403
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 if (dev->ops->disconnect || dev->ops->deauth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1407 goto nla_put_failure;
1408 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001409
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 nla_nest_end(msg, nl_cmds);
1411 (*split_start)++;
1412 if (split)
1413 break;
1414 case 5:
1415 if (dev->ops->remain_on_channel &&
1416 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1417 nla_put_u32(msg,
1418 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1419 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001420 goto nla_put_failure;
1421
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1423 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1424 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001425
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1427 goto nla_put_failure;
1428 (*split_start)++;
1429 if (split)
1430 break;
1431 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001432#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001433 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 goto nla_put_failure;
1435 (*split_start)++;
1436 if (split)
1437 break;
1438#else
1439 (*split_start)++;
1440#endif
1441 case 7:
1442 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1443 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001444 goto nla_put_failure;
1445
Johannes Bergcdc89b92013-02-18 23:54:36 +01001446 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001448
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 (*split_start)++;
1450 if (split)
1451 break;
1452 case 8:
1453 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1454 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1455 dev->wiphy.ap_sme_capa))
1456 goto nla_put_failure;
1457
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001458 features = dev->wiphy.features;
1459 /*
1460 * We can only add the per-channel limit information if the
1461 * dump is split, otherwise it makes it too big. Therefore
1462 * only advertise it in that case.
1463 */
1464 if (split)
1465 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1466 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 goto nla_put_failure;
1468
1469 if (dev->wiphy.ht_capa_mod_mask &&
1470 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1471 sizeof(*dev->wiphy.ht_capa_mod_mask),
1472 dev->wiphy.ht_capa_mod_mask))
1473 goto nla_put_failure;
1474
1475 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1476 dev->wiphy.max_acl_mac_addrs &&
1477 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1478 dev->wiphy.max_acl_mac_addrs))
1479 goto nla_put_failure;
1480
1481 /*
1482 * Any information below this point is only available to
1483 * applications that can deal with it being split. This
1484 * helps ensure that newly added capabilities don't break
1485 * older tools by overrunning their buffers.
1486 *
1487 * We still increment split_start so that in the split
1488 * case we'll continue with more data in the next round,
1489 * but break unconditionally so unsplit data stops here.
1490 */
1491 (*split_start)++;
1492 break;
1493 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001494 if (dev->wiphy.extended_capabilities &&
1495 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1496 dev->wiphy.extended_capabilities_len,
1497 dev->wiphy.extended_capabilities) ||
1498 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1499 dev->wiphy.extended_capabilities_len,
1500 dev->wiphy.extended_capabilities_mask)))
1501 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502
Johannes Bergee2aca32013-02-21 17:36:01 +01001503 if (dev->wiphy.vht_capa_mod_mask &&
1504 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1505 sizeof(*dev->wiphy.vht_capa_mod_mask),
1506 dev->wiphy.vht_capa_mod_mask))
1507 goto nla_put_failure;
1508
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509 /* done */
1510 *split_start = 0;
1511 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001512 }
Johannes Berg55682962007-09-20 13:09:35 -04001513 return genlmsg_end(msg, hdr);
1514
1515 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001516 genlmsg_cancel(msg, hdr);
1517 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001518}
1519
1520static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1521{
Johannes Berg645e77d2013-03-01 14:03:49 +01001522 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001523 int start = cb->args[0];
1524 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 s64 filter_wiphy = -1;
1526 bool split = false;
1527 struct nlattr **tb = nl80211_fam.attrbuf;
1528 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001529
Johannes Berg5fe231e2013-05-08 21:45:15 +02001530 rtnl_lock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1532 tb, nl80211_fam.maxattr, nl80211_policy);
1533 if (res == 0) {
1534 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1535 if (tb[NL80211_ATTR_WIPHY])
1536 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1537 if (tb[NL80211_ATTR_WDEV])
1538 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1539 if (tb[NL80211_ATTR_IFINDEX]) {
1540 struct net_device *netdev;
1541 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1542
1543 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001544 if (!netdev)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 return -ENODEV;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 if (netdev->ieee80211_ptr) {
1547 dev = wiphy_to_dev(
1548 netdev->ieee80211_ptr->wiphy);
1549 filter_wiphy = dev->wiphy_idx;
1550 }
1551 dev_put(netdev);
1552 }
1553 }
1554
Johannes Berg79c97e92009-07-07 03:56:12 +02001555 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001556 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1557 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001558 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001559 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1561 continue;
1562 /* attempt to fit multiple wiphy data chunks into the skb */
1563 do {
1564 ret = nl80211_send_wiphy(dev, skb,
1565 NETLINK_CB(cb->skb).portid,
1566 cb->nlh->nlmsg_seq,
1567 NLM_F_MULTI,
1568 split, &cb->args[1],
1569 &cb->args[2],
1570 &cb->args[3]);
1571 if (ret < 0) {
1572 /*
1573 * If sending the wiphy data didn't fit (ENOBUFS
1574 * or EMSGSIZE returned), this SKB is still
1575 * empty (so it's not too big because another
1576 * wiphy dataset is already in the skb) and
1577 * we've not tried to adjust the dump allocation
1578 * yet ... then adjust the alloc size to be
1579 * bigger, and return 1 but with the empty skb.
1580 * This results in an empty message being RX'ed
1581 * in userspace, but that is ignored.
1582 *
1583 * We can then retry with the larger buffer.
1584 */
1585 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1586 !skb->len &&
1587 cb->min_dump_alloc < 4096) {
1588 cb->min_dump_alloc = 4096;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 return 1;
1590 }
1591 idx--;
1592 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001593 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 } while (cb->args[1] > 0);
1595 break;
Johannes Berg55682962007-09-20 13:09:35 -04001596 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001597 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001598
1599 cb->args[0] = idx;
1600
1601 return skb->len;
1602}
1603
1604static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1605{
1606 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001607 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001608
Johannes Berg645e77d2013-03-01 14:03:49 +01001609 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001610 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001611 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001612
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1614 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001615 nlmsg_free(msg);
1616 return -ENOBUFS;
1617 }
Johannes Berg55682962007-09-20 13:09:35 -04001618
Johannes Berg134e6372009-07-10 09:51:34 +00001619 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001620}
1621
Jouni Malinen31888482008-10-30 16:59:24 +02001622static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1623 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1624 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1625 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1626 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1627 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1628};
1629
1630static int parse_txq_params(struct nlattr *tb[],
1631 struct ieee80211_txq_params *txq_params)
1632{
Johannes Berga3304b02012-03-28 11:04:24 +02001633 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001634 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1635 !tb[NL80211_TXQ_ATTR_AIFS])
1636 return -EINVAL;
1637
Johannes Berga3304b02012-03-28 11:04:24 +02001638 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001639 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1640 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1641 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1642 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1643
Johannes Berga3304b02012-03-28 11:04:24 +02001644 if (txq_params->ac >= NL80211_NUM_ACS)
1645 return -EINVAL;
1646
Jouni Malinen31888482008-10-30 16:59:24 +02001647 return 0;
1648}
1649
Johannes Bergf444de02010-05-05 15:25:02 +02001650static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1651{
1652 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001653 * You can only set the channel explicitly for WDS interfaces,
1654 * all others have their channel managed via their respective
1655 * "establish a connection" command (connect, join, ...)
1656 *
1657 * For AP/GO and mesh mode, the channel can be set with the
1658 * channel userspace API, but is only stored and passed to the
1659 * low-level driver when the AP starts or the mesh is joined.
1660 * This is for backward compatibility, userspace can also give
1661 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001662 *
1663 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001664 * whatever else is going on, so they have their own special
1665 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001666 */
1667 return !wdev ||
1668 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001669 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001670 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1671 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001672}
1673
Johannes Berg683b6d32012-11-08 21:25:48 +01001674static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1675 struct genl_info *info,
1676 struct cfg80211_chan_def *chandef)
1677{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301678 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001679
1680 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1681 return -EINVAL;
1682
1683 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1684
1685 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001686 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1687 chandef->center_freq1 = control_freq;
1688 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001689
1690 /* Primary channel not allowed */
1691 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1692 return -EINVAL;
1693
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001694 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1695 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001696
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001697 chantype = nla_get_u32(
1698 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1699
1700 switch (chantype) {
1701 case NL80211_CHAN_NO_HT:
1702 case NL80211_CHAN_HT20:
1703 case NL80211_CHAN_HT40PLUS:
1704 case NL80211_CHAN_HT40MINUS:
1705 cfg80211_chandef_create(chandef, chandef->chan,
1706 chantype);
1707 break;
1708 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001709 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001710 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001711 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1712 chandef->width =
1713 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1714 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1715 chandef->center_freq1 =
1716 nla_get_u32(
1717 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1718 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1719 chandef->center_freq2 =
1720 nla_get_u32(
1721 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1722 }
1723
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001724 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001725 return -EINVAL;
1726
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001727 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1728 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001729 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001730
Johannes Berg683b6d32012-11-08 21:25:48 +01001731 return 0;
1732}
1733
Johannes Bergf444de02010-05-05 15:25:02 +02001734static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1735 struct wireless_dev *wdev,
1736 struct genl_info *info)
1737{
Johannes Berg683b6d32012-11-08 21:25:48 +01001738 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001739 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001740 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1741
1742 if (wdev)
1743 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001744
Johannes Bergf444de02010-05-05 15:25:02 +02001745 if (!nl80211_can_set_dev_channel(wdev))
1746 return -EOPNOTSUPP;
1747
Johannes Berg683b6d32012-11-08 21:25:48 +01001748 result = nl80211_parse_chandef(rdev, info, &chandef);
1749 if (result)
1750 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001751
Johannes Berge8c9bd52012-06-06 08:18:22 +02001752 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001753 case NL80211_IFTYPE_AP:
1754 case NL80211_IFTYPE_P2P_GO:
1755 if (wdev->beacon_interval) {
1756 result = -EBUSY;
1757 break;
1758 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001759 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001760 result = -EINVAL;
1761 break;
1762 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001763 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001764 result = 0;
1765 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001766 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001767 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001768 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001769 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001771 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001772 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001773 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001774 }
Johannes Bergf444de02010-05-05 15:25:02 +02001775
1776 return result;
1777}
1778
1779static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1780{
Johannes Berg4c476992010-10-04 21:36:35 +02001781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1782 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001783
Johannes Berg4c476992010-10-04 21:36:35 +02001784 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001785}
1786
Bill Jordane8347eb2010-10-01 13:54:28 -04001787static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1788{
Johannes Berg43b19952010-10-07 13:10:30 +02001789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1790 struct net_device *dev = info->user_ptr[1];
1791 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001792 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001793
1794 if (!info->attrs[NL80211_ATTR_MAC])
1795 return -EINVAL;
1796
Johannes Berg43b19952010-10-07 13:10:30 +02001797 if (netif_running(dev))
1798 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001799
Johannes Berg43b19952010-10-07 13:10:30 +02001800 if (!rdev->ops->set_wds_peer)
1801 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001802
Johannes Berg43b19952010-10-07 13:10:30 +02001803 if (wdev->iftype != NL80211_IFTYPE_WDS)
1804 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001805
1806 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001807 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001808}
1809
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1812{
1813 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001814 struct net_device *netdev = NULL;
1815 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001816 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001817 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001818 u32 changed;
1819 u8 retry_short = 0, retry_long = 0;
1820 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001821 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001822
Johannes Berg5fe231e2013-05-08 21:45:15 +02001823 ASSERT_RTNL();
1824
Johannes Bergf444de02010-05-05 15:25:02 +02001825 /*
1826 * Try to find the wiphy and netdev. Normally this
1827 * function shouldn't need the netdev, but this is
1828 * done for backward compatibility -- previously
1829 * setting the channel was done per wiphy, but now
1830 * it is per netdev. Previous userland like hostapd
1831 * also passed a netdev to set_wiphy, so that it is
1832 * possible to let that go to the right netdev!
1833 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001834
Johannes Bergf444de02010-05-05 15:25:02 +02001835 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1836 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1837
1838 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001839 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001840 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001841 else
Johannes Bergf444de02010-05-05 15:25:02 +02001842 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001843 }
1844
Johannes Bergf444de02010-05-05 15:25:02 +02001845 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001846 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1847 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001848 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001849 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001850 wdev = NULL;
1851 netdev = NULL;
1852 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001853 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001854 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001855
1856 /*
1857 * end workaround code, by now the rdev is available
1858 * and locked, and wdev may or may not be NULL.
1859 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001860
1861 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001862 result = cfg80211_dev_rename(
1863 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001864
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001865 if (result)
1866 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001867
Jouni Malinen31888482008-10-30 16:59:24 +02001868 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1869 struct ieee80211_txq_params txq_params;
1870 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1871
1872 if (!rdev->ops->set_txq_params) {
1873 result = -EOPNOTSUPP;
1874 goto bad_res;
1875 }
1876
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001877 if (!netdev) {
1878 result = -EINVAL;
1879 goto bad_res;
1880 }
1881
Johannes Berg133a3ff2011-11-03 14:50:13 +01001882 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1883 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1884 result = -EINVAL;
1885 goto bad_res;
1886 }
1887
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001888 if (!netif_running(netdev)) {
1889 result = -ENETDOWN;
1890 goto bad_res;
1891 }
1892
Jouni Malinen31888482008-10-30 16:59:24 +02001893 nla_for_each_nested(nl_txq_params,
1894 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1895 rem_txq_params) {
1896 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1897 nla_data(nl_txq_params),
1898 nla_len(nl_txq_params),
1899 txq_params_policy);
1900 result = parse_txq_params(tb, &txq_params);
1901 if (result)
1902 goto bad_res;
1903
Hila Gonene35e4d22012-06-27 17:19:42 +03001904 result = rdev_set_txq_params(rdev, netdev,
1905 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001906 if (result)
1907 goto bad_res;
1908 }
1909 }
1910
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001911 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001912 result = __nl80211_set_channel(rdev,
1913 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1914 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001915 if (result)
1916 goto bad_res;
1917 }
1918
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001919 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001920 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001921 enum nl80211_tx_power_setting type;
1922 int idx, mbm = 0;
1923
Johannes Bergc8442112012-10-24 10:17:18 +02001924 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1925 txp_wdev = NULL;
1926
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001927 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001928 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001929 goto bad_res;
1930 }
1931
1932 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1933 type = nla_get_u32(info->attrs[idx]);
1934
1935 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1936 (type != NL80211_TX_POWER_AUTOMATIC)) {
1937 result = -EINVAL;
1938 goto bad_res;
1939 }
1940
1941 if (type != NL80211_TX_POWER_AUTOMATIC) {
1942 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1943 mbm = nla_get_u32(info->attrs[idx]);
1944 }
1945
Johannes Bergc8442112012-10-24 10:17:18 +02001946 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001947 if (result)
1948 goto bad_res;
1949 }
1950
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001951 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1952 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1953 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001954 if ((!rdev->wiphy.available_antennas_tx &&
1955 !rdev->wiphy.available_antennas_rx) ||
1956 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001957 result = -EOPNOTSUPP;
1958 goto bad_res;
1959 }
1960
1961 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1962 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1963
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001964 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001965 * available antenna masks, except for the "all" mask */
1966 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1967 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001968 result = -EINVAL;
1969 goto bad_res;
1970 }
1971
Bruno Randolf7f531e02010-12-16 11:30:22 +09001972 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1973 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001974
Hila Gonene35e4d22012-06-27 17:19:42 +03001975 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001976 if (result)
1977 goto bad_res;
1978 }
1979
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001980 changed = 0;
1981
1982 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1983 retry_short = nla_get_u8(
1984 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1985 if (retry_short == 0) {
1986 result = -EINVAL;
1987 goto bad_res;
1988 }
1989 changed |= WIPHY_PARAM_RETRY_SHORT;
1990 }
1991
1992 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1993 retry_long = nla_get_u8(
1994 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1995 if (retry_long == 0) {
1996 result = -EINVAL;
1997 goto bad_res;
1998 }
1999 changed |= WIPHY_PARAM_RETRY_LONG;
2000 }
2001
2002 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2003 frag_threshold = nla_get_u32(
2004 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2005 if (frag_threshold < 256) {
2006 result = -EINVAL;
2007 goto bad_res;
2008 }
2009 if (frag_threshold != (u32) -1) {
2010 /*
2011 * Fragments (apart from the last one) are required to
2012 * have even length. Make the fragmentation code
2013 * simpler by stripping LSB should someone try to use
2014 * odd threshold value.
2015 */
2016 frag_threshold &= ~0x1;
2017 }
2018 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2019 }
2020
2021 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2022 rts_threshold = nla_get_u32(
2023 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2024 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2025 }
2026
Lukáš Turek81077e82009-12-21 22:50:47 +01002027 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2028 coverage_class = nla_get_u8(
2029 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2030 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2031 }
2032
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002033 if (changed) {
2034 u8 old_retry_short, old_retry_long;
2035 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002036 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002037
2038 if (!rdev->ops->set_wiphy_params) {
2039 result = -EOPNOTSUPP;
2040 goto bad_res;
2041 }
2042
2043 old_retry_short = rdev->wiphy.retry_short;
2044 old_retry_long = rdev->wiphy.retry_long;
2045 old_frag_threshold = rdev->wiphy.frag_threshold;
2046 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002047 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002048
2049 if (changed & WIPHY_PARAM_RETRY_SHORT)
2050 rdev->wiphy.retry_short = retry_short;
2051 if (changed & WIPHY_PARAM_RETRY_LONG)
2052 rdev->wiphy.retry_long = retry_long;
2053 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2054 rdev->wiphy.frag_threshold = frag_threshold;
2055 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2056 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002057 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2058 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002059
Hila Gonene35e4d22012-06-27 17:19:42 +03002060 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002061 if (result) {
2062 rdev->wiphy.retry_short = old_retry_short;
2063 rdev->wiphy.retry_long = old_retry_long;
2064 rdev->wiphy.frag_threshold = old_frag_threshold;
2065 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002066 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002067 }
2068 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002069
Johannes Berg306d6112008-12-08 12:39:04 +01002070 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002071 if (netdev)
2072 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002073 return result;
2074}
2075
Johannes Berg71bbc992012-06-15 15:30:18 +02002076static inline u64 wdev_id(struct wireless_dev *wdev)
2077{
2078 return (u64)wdev->identifier |
2079 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2080}
Johannes Berg55682962007-09-20 13:09:35 -04002081
Johannes Berg683b6d32012-11-08 21:25:48 +01002082static int nl80211_send_chandef(struct sk_buff *msg,
2083 struct cfg80211_chan_def *chandef)
2084{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002085 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002086
Johannes Berg683b6d32012-11-08 21:25:48 +01002087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2088 chandef->chan->center_freq))
2089 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002090 switch (chandef->width) {
2091 case NL80211_CHAN_WIDTH_20_NOHT:
2092 case NL80211_CHAN_WIDTH_20:
2093 case NL80211_CHAN_WIDTH_40:
2094 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2095 cfg80211_get_chandef_type(chandef)))
2096 return -ENOBUFS;
2097 break;
2098 default:
2099 break;
2100 }
2101 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2102 return -ENOBUFS;
2103 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2104 return -ENOBUFS;
2105 if (chandef->center_freq2 &&
2106 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002107 return -ENOBUFS;
2108 return 0;
2109}
2110
Eric W. Biederman15e47302012-09-07 20:12:54 +00002111static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002112 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002113 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002114{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002115 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002116 void *hdr;
2117
Eric W. Biederman15e47302012-09-07 20:12:54 +00002118 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002119 if (!hdr)
2120 return -1;
2121
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002122 if (dev &&
2123 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002124 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002125 goto nla_put_failure;
2126
2127 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2128 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002129 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002130 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002131 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2132 rdev->devlist_generation ^
2133 (cfg80211_rdev_list_generation << 2)))
2134 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002135
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002136 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002137 int ret;
2138 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002139
Johannes Berg683b6d32012-11-08 21:25:48 +01002140 ret = rdev_get_channel(rdev, wdev, &chandef);
2141 if (ret == 0) {
2142 if (nl80211_send_chandef(msg, &chandef))
2143 goto nla_put_failure;
2144 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002145 }
2146
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002147 if (wdev->ssid_len) {
2148 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2149 goto nla_put_failure;
2150 }
2151
Johannes Berg55682962007-09-20 13:09:35 -04002152 return genlmsg_end(msg, hdr);
2153
2154 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002155 genlmsg_cancel(msg, hdr);
2156 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002157}
2158
2159static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2160{
2161 int wp_idx = 0;
2162 int if_idx = 0;
2163 int wp_start = cb->args[0];
2164 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002165 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002166 struct wireless_dev *wdev;
2167
Johannes Berg5fe231e2013-05-08 21:45:15 +02002168 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002169 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2170 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002171 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002172 if (wp_idx < wp_start) {
2173 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002174 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002175 }
Johannes Berg55682962007-09-20 13:09:35 -04002176 if_idx = 0;
2177
Johannes Berg89a54e42012-06-15 14:33:17 +02002178 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002179 if (if_idx < if_start) {
2180 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002181 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002182 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002183 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002184 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002185 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002186 goto out;
2187 }
2188 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002189 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002190
2191 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002192 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002194 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002195
2196 cb->args[0] = wp_idx;
2197 cb->args[1] = if_idx;
2198
2199 return skb->len;
2200}
2201
2202static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2203{
2204 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002205 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002206 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002207
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002209 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002210 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002211
Eric W. Biederman15e47302012-09-07 20:12:54 +00002212 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002213 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002214 nlmsg_free(msg);
2215 return -ENOBUFS;
2216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217
Johannes Berg134e6372009-07-10 09:51:34 +00002218 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002219}
2220
Michael Wu66f7ac52008-01-31 19:48:22 +01002221static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2222 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2223 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2224 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2225 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2226 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002227 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002228};
2229
2230static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2231{
2232 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2233 int flag;
2234
2235 *mntrflags = 0;
2236
2237 if (!nla)
2238 return -EINVAL;
2239
2240 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2241 nla, mntr_flags_policy))
2242 return -EINVAL;
2243
2244 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2245 if (flags[flag])
2246 *mntrflags |= (1<<flag);
2247
2248 return 0;
2249}
2250
Johannes Berg9bc383d2009-11-19 11:55:19 +01002251static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002252 struct net_device *netdev, u8 use_4addr,
2253 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002254{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002255 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002256 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002257 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002258 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002259 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002260
2261 switch (iftype) {
2262 case NL80211_IFTYPE_AP_VLAN:
2263 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2264 return 0;
2265 break;
2266 case NL80211_IFTYPE_STATION:
2267 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2268 return 0;
2269 break;
2270 default:
2271 break;
2272 }
2273
2274 return -EOPNOTSUPP;
2275}
2276
Johannes Berg55682962007-09-20 13:09:35 -04002277static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2278{
Johannes Berg4c476992010-10-04 21:36:35 +02002279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002280 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002281 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002282 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002283 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002284 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002285 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002286
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002287 memset(&params, 0, sizeof(params));
2288
Johannes Berg04a773a2009-04-19 21:24:32 +02002289 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002290
Johannes Berg723b0382008-09-16 20:22:09 +02002291 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002292 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002293 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002294 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002295 if (ntype > NL80211_IFTYPE_MAX)
2296 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002297 }
2298
Johannes Berg92ffe052008-09-16 20:39:36 +02002299 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002300 struct wireless_dev *wdev = dev->ieee80211_ptr;
2301
Johannes Berg4c476992010-10-04 21:36:35 +02002302 if (ntype != NL80211_IFTYPE_MESH_POINT)
2303 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002304 if (netif_running(dev))
2305 return -EBUSY;
2306
2307 wdev_lock(wdev);
2308 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2309 IEEE80211_MAX_MESH_ID_LEN);
2310 wdev->mesh_id_up_len =
2311 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2312 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2313 wdev->mesh_id_up_len);
2314 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002315 }
2316
Felix Fietkau8b787642009-11-10 18:53:10 +01002317 if (info->attrs[NL80211_ATTR_4ADDR]) {
2318 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2319 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002320 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002322 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002323 } else {
2324 params.use_4addr = -1;
2325 }
2326
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002328 if (ntype != NL80211_IFTYPE_MONITOR)
2329 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002330 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2331 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002332 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002333 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002334
2335 flags = &_flags;
2336 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002337 }
Johannes Berg3b858752009-03-12 09:55:09 +01002338
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002339 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2340 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2341 return -EOPNOTSUPP;
2342
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002343 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002344 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002345 else
2346 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002347
Johannes Berg9bc383d2009-11-19 11:55:19 +01002348 if (!err && params.use_4addr != -1)
2349 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2350
Johannes Berg55682962007-09-20 13:09:35 -04002351 return err;
2352}
2353
2354static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2355{
Johannes Berg4c476992010-10-04 21:36:35 +02002356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002357 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002358 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002359 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002360 int err;
2361 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002362 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002363
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002364 memset(&params, 0, sizeof(params));
2365
Johannes Berg55682962007-09-20 13:09:35 -04002366 if (!info->attrs[NL80211_ATTR_IFNAME])
2367 return -EINVAL;
2368
2369 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2370 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2371 if (type > NL80211_IFTYPE_MAX)
2372 return -EINVAL;
2373 }
2374
Johannes Berg79c97e92009-07-07 03:56:12 +02002375 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002376 !(rdev->wiphy.interface_modes & (1 << type)))
2377 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002378
Arend van Spriel1c18f142013-01-08 10:17:27 +01002379 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2380 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2381 ETH_ALEN);
2382 if (!is_valid_ether_addr(params.macaddr))
2383 return -EADDRNOTAVAIL;
2384 }
2385
Johannes Berg9bc383d2009-11-19 11:55:19 +01002386 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002387 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002388 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002389 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002390 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002391 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002392
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2394 if (!msg)
2395 return -ENOMEM;
2396
Michael Wu66f7ac52008-01-31 19:48:22 +01002397 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2398 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2399 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002400
2401 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2402 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2403 return -EOPNOTSUPP;
2404
Hila Gonene35e4d22012-06-27 17:19:42 +03002405 wdev = rdev_add_virtual_intf(rdev,
2406 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2407 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002408 if (IS_ERR(wdev)) {
2409 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002410 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002411 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002412
Johannes Berg98104fde2012-06-16 00:19:54 +02002413 switch (type) {
2414 case NL80211_IFTYPE_MESH_POINT:
2415 if (!info->attrs[NL80211_ATTR_MESH_ID])
2416 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002417 wdev_lock(wdev);
2418 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2419 IEEE80211_MAX_MESH_ID_LEN);
2420 wdev->mesh_id_up_len =
2421 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2422 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2423 wdev->mesh_id_up_len);
2424 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002425 break;
2426 case NL80211_IFTYPE_P2P_DEVICE:
2427 /*
2428 * P2P Device doesn't have a netdev, so doesn't go
2429 * through the netdev notifier and must be added here
2430 */
2431 mutex_init(&wdev->mtx);
2432 INIT_LIST_HEAD(&wdev->event_list);
2433 spin_lock_init(&wdev->event_lock);
2434 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2435 spin_lock_init(&wdev->mgmt_registrations_lock);
2436
Johannes Berg98104fde2012-06-16 00:19:54 +02002437 wdev->identifier = ++rdev->wdev_id;
2438 list_add_rcu(&wdev->list, &rdev->wdev_list);
2439 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002440 break;
2441 default:
2442 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002443 }
2444
Eric W. Biederman15e47302012-09-07 20:12:54 +00002445 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002446 rdev, wdev) < 0) {
2447 nlmsg_free(msg);
2448 return -ENOBUFS;
2449 }
2450
2451 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002452}
2453
2454static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2455{
Johannes Berg4c476992010-10-04 21:36:35 +02002456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002457 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002458
Johannes Berg4c476992010-10-04 21:36:35 +02002459 if (!rdev->ops->del_virtual_intf)
2460 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002461
Johannes Berg84efbb82012-06-16 00:00:26 +02002462 /*
2463 * If we remove a wireless device without a netdev then clear
2464 * user_ptr[1] so that nl80211_post_doit won't dereference it
2465 * to check if it needs to do dev_put(). Otherwise it crashes
2466 * since the wdev has been freed, unlike with a netdev where
2467 * we need the dev_put() for the netdev to really be freed.
2468 */
2469 if (!wdev->netdev)
2470 info->user_ptr[1] = NULL;
2471
Hila Gonene35e4d22012-06-27 17:19:42 +03002472 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002473}
2474
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002475static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2476{
2477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2478 struct net_device *dev = info->user_ptr[1];
2479 u16 noack_map;
2480
2481 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2482 return -EINVAL;
2483
2484 if (!rdev->ops->set_noack_map)
2485 return -EOPNOTSUPP;
2486
2487 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2488
Hila Gonene35e4d22012-06-27 17:19:42 +03002489 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002490}
2491
Johannes Berg41ade002007-12-19 02:03:29 +01002492struct get_key_cookie {
2493 struct sk_buff *msg;
2494 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002495 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002496};
2497
2498static void get_key_callback(void *c, struct key_params *params)
2499{
Johannes Bergb9454e82009-07-08 13:29:08 +02002500 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002501 struct get_key_cookie *cookie = c;
2502
David S. Miller9360ffd2012-03-29 04:41:26 -04002503 if ((params->key &&
2504 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2505 params->key_len, params->key)) ||
2506 (params->seq &&
2507 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2508 params->seq_len, params->seq)) ||
2509 (params->cipher &&
2510 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2511 params->cipher)))
2512 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002513
Johannes Bergb9454e82009-07-08 13:29:08 +02002514 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2515 if (!key)
2516 goto nla_put_failure;
2517
David S. Miller9360ffd2012-03-29 04:41:26 -04002518 if ((params->key &&
2519 nla_put(cookie->msg, NL80211_KEY_DATA,
2520 params->key_len, params->key)) ||
2521 (params->seq &&
2522 nla_put(cookie->msg, NL80211_KEY_SEQ,
2523 params->seq_len, params->seq)) ||
2524 (params->cipher &&
2525 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2526 params->cipher)))
2527 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002528
David S. Miller9360ffd2012-03-29 04:41:26 -04002529 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2530 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531
2532 nla_nest_end(cookie->msg, key);
2533
Johannes Berg41ade002007-12-19 02:03:29 +01002534 return;
2535 nla_put_failure:
2536 cookie->error = 1;
2537}
2538
2539static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2540{
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002542 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002543 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002544 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002545 const u8 *mac_addr = NULL;
2546 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002547 struct get_key_cookie cookie = {
2548 .error = 0,
2549 };
2550 void *hdr;
2551 struct sk_buff *msg;
2552
2553 if (info->attrs[NL80211_ATTR_KEY_IDX])
2554 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2555
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002556 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002557 return -EINVAL;
2558
2559 if (info->attrs[NL80211_ATTR_MAC])
2560 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2561
Johannes Berge31b8212010-10-05 19:39:30 +02002562 pairwise = !!mac_addr;
2563 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2564 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2565 if (kt >= NUM_NL80211_KEYTYPES)
2566 return -EINVAL;
2567 if (kt != NL80211_KEYTYPE_GROUP &&
2568 kt != NL80211_KEYTYPE_PAIRWISE)
2569 return -EINVAL;
2570 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2571 }
2572
Johannes Berg4c476992010-10-04 21:36:35 +02002573 if (!rdev->ops->get_key)
2574 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002575
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002577 if (!msg)
2578 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002579
Eric W. Biederman15e47302012-09-07 20:12:54 +00002580 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002581 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002582 if (IS_ERR(hdr))
2583 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002584
2585 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002586 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002587
David S. Miller9360ffd2012-03-29 04:41:26 -04002588 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2589 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2590 goto nla_put_failure;
2591 if (mac_addr &&
2592 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2593 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002594
Johannes Berge31b8212010-10-05 19:39:30 +02002595 if (pairwise && mac_addr &&
2596 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2597 return -ENOENT;
2598
Hila Gonene35e4d22012-06-27 17:19:42 +03002599 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2600 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002601
2602 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002603 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002604
2605 if (cookie.error)
2606 goto nla_put_failure;
2607
2608 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002609 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002610
2611 nla_put_failure:
2612 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002613 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002614 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002615 return err;
2616}
2617
2618static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2619{
Johannes Berg4c476992010-10-04 21:36:35 +02002620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002621 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002622 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002623 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002624
Johannes Bergb9454e82009-07-08 13:29:08 +02002625 err = nl80211_parse_key(info, &key);
2626 if (err)
2627 return err;
2628
2629 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002630 return -EINVAL;
2631
Johannes Bergb9454e82009-07-08 13:29:08 +02002632 /* only support setting default key */
2633 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002634 return -EINVAL;
2635
Johannes Bergfffd0932009-07-08 14:22:54 +02002636 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002637
2638 if (key.def) {
2639 if (!rdev->ops->set_default_key) {
2640 err = -EOPNOTSUPP;
2641 goto out;
2642 }
2643
2644 err = nl80211_key_allowed(dev->ieee80211_ptr);
2645 if (err)
2646 goto out;
2647
Hila Gonene35e4d22012-06-27 17:19:42 +03002648 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002649 key.def_uni, key.def_multi);
2650
2651 if (err)
2652 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002653
Johannes Berg3d23e342009-09-29 23:27:28 +02002654#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002655 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002656#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002657 } else {
2658 if (key.def_uni || !key.def_multi) {
2659 err = -EINVAL;
2660 goto out;
2661 }
2662
2663 if (!rdev->ops->set_default_mgmt_key) {
2664 err = -EOPNOTSUPP;
2665 goto out;
2666 }
2667
2668 err = nl80211_key_allowed(dev->ieee80211_ptr);
2669 if (err)
2670 goto out;
2671
Hila Gonene35e4d22012-06-27 17:19:42 +03002672 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002673 if (err)
2674 goto out;
2675
2676#ifdef CONFIG_CFG80211_WEXT
2677 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2678#endif
2679 }
2680
2681 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002682 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002683
Johannes Berg41ade002007-12-19 02:03:29 +01002684 return err;
2685}
2686
2687static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2688{
Johannes Berg4c476992010-10-04 21:36:35 +02002689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002690 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002691 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002692 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002693 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002694
Johannes Bergb9454e82009-07-08 13:29:08 +02002695 err = nl80211_parse_key(info, &key);
2696 if (err)
2697 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002698
Johannes Bergb9454e82009-07-08 13:29:08 +02002699 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002700 return -EINVAL;
2701
Johannes Berg41ade002007-12-19 02:03:29 +01002702 if (info->attrs[NL80211_ATTR_MAC])
2703 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2704
Johannes Berge31b8212010-10-05 19:39:30 +02002705 if (key.type == -1) {
2706 if (mac_addr)
2707 key.type = NL80211_KEYTYPE_PAIRWISE;
2708 else
2709 key.type = NL80211_KEYTYPE_GROUP;
2710 }
2711
2712 /* for now */
2713 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2714 key.type != NL80211_KEYTYPE_GROUP)
2715 return -EINVAL;
2716
Johannes Berg4c476992010-10-04 21:36:35 +02002717 if (!rdev->ops->add_key)
2718 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002719
Johannes Berge31b8212010-10-05 19:39:30 +02002720 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2721 key.type == NL80211_KEYTYPE_PAIRWISE,
2722 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002723 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002724
2725 wdev_lock(dev->ieee80211_ptr);
2726 err = nl80211_key_allowed(dev->ieee80211_ptr);
2727 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002728 err = rdev_add_key(rdev, dev, key.idx,
2729 key.type == NL80211_KEYTYPE_PAIRWISE,
2730 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002731 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002732
Johannes Berg41ade002007-12-19 02:03:29 +01002733 return err;
2734}
2735
2736static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2737{
Johannes Berg4c476992010-10-04 21:36:35 +02002738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002739 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002740 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002741 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002742 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002743
Johannes Bergb9454e82009-07-08 13:29:08 +02002744 err = nl80211_parse_key(info, &key);
2745 if (err)
2746 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002747
2748 if (info->attrs[NL80211_ATTR_MAC])
2749 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2750
Johannes Berge31b8212010-10-05 19:39:30 +02002751 if (key.type == -1) {
2752 if (mac_addr)
2753 key.type = NL80211_KEYTYPE_PAIRWISE;
2754 else
2755 key.type = NL80211_KEYTYPE_GROUP;
2756 }
2757
2758 /* for now */
2759 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2760 key.type != NL80211_KEYTYPE_GROUP)
2761 return -EINVAL;
2762
Johannes Berg4c476992010-10-04 21:36:35 +02002763 if (!rdev->ops->del_key)
2764 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002765
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 wdev_lock(dev->ieee80211_ptr);
2767 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002768
2769 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2770 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2771 err = -ENOENT;
2772
Johannes Bergfffd0932009-07-08 14:22:54 +02002773 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002774 err = rdev_del_key(rdev, dev, key.idx,
2775 key.type == NL80211_KEYTYPE_PAIRWISE,
2776 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002777
Johannes Berg3d23e342009-09-29 23:27:28 +02002778#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002779 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002781 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002782 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002783 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2784 }
2785#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002786 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002787
Johannes Berg41ade002007-12-19 02:03:29 +01002788 return err;
2789}
2790
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302791/* This function returns an error or the number of nested attributes */
2792static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2793{
2794 struct nlattr *attr;
2795 int n_entries = 0, tmp;
2796
2797 nla_for_each_nested(attr, nl_attr, tmp) {
2798 if (nla_len(attr) != ETH_ALEN)
2799 return -EINVAL;
2800
2801 n_entries++;
2802 }
2803
2804 return n_entries;
2805}
2806
2807/*
2808 * This function parses ACL information and allocates memory for ACL data.
2809 * On successful return, the calling function is responsible to free the
2810 * ACL buffer returned by this function.
2811 */
2812static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2813 struct genl_info *info)
2814{
2815 enum nl80211_acl_policy acl_policy;
2816 struct nlattr *attr;
2817 struct cfg80211_acl_data *acl;
2818 int i = 0, n_entries, tmp;
2819
2820 if (!wiphy->max_acl_mac_addrs)
2821 return ERR_PTR(-EOPNOTSUPP);
2822
2823 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2824 return ERR_PTR(-EINVAL);
2825
2826 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2827 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2828 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2829 return ERR_PTR(-EINVAL);
2830
2831 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2832 return ERR_PTR(-EINVAL);
2833
2834 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2835 if (n_entries < 0)
2836 return ERR_PTR(n_entries);
2837
2838 if (n_entries > wiphy->max_acl_mac_addrs)
2839 return ERR_PTR(-ENOTSUPP);
2840
2841 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2842 GFP_KERNEL);
2843 if (!acl)
2844 return ERR_PTR(-ENOMEM);
2845
2846 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2847 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2848 i++;
2849 }
2850
2851 acl->n_acl_entries = n_entries;
2852 acl->acl_policy = acl_policy;
2853
2854 return acl;
2855}
2856
2857static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2858{
2859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2860 struct net_device *dev = info->user_ptr[1];
2861 struct cfg80211_acl_data *acl;
2862 int err;
2863
2864 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2865 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2866 return -EOPNOTSUPP;
2867
2868 if (!dev->ieee80211_ptr->beacon_interval)
2869 return -EINVAL;
2870
2871 acl = parse_acl_data(&rdev->wiphy, info);
2872 if (IS_ERR(acl))
2873 return PTR_ERR(acl);
2874
2875 err = rdev_set_mac_acl(rdev, dev, acl);
2876
2877 kfree(acl);
2878
2879 return err;
2880}
2881
Johannes Berg88600202012-02-13 15:17:18 +01002882static int nl80211_parse_beacon(struct genl_info *info,
2883 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002884{
Johannes Berg88600202012-02-13 15:17:18 +01002885 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002886
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002887 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2888 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2889 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2890 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002891 return -EINVAL;
2892
Johannes Berg88600202012-02-13 15:17:18 +01002893 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002894
Johannes Berged1b6cc2007-12-19 02:03:32 +01002895 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002896 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2897 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2898 if (!bcn->head_len)
2899 return -EINVAL;
2900 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002901 }
2902
2903 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002904 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2905 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002906 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002907 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002908 }
2909
Johannes Berg4c476992010-10-04 21:36:35 +02002910 if (!haveinfo)
2911 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002912
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002913 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002914 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2915 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002916 }
2917
2918 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002919 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002920 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002921 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002922 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2923 }
2924
2925 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002926 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002927 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002928 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002929 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2930 }
2931
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002932 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002933 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002934 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002935 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002936 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2937 }
2938
Johannes Berg88600202012-02-13 15:17:18 +01002939 return 0;
2940}
2941
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002942static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2943 struct cfg80211_ap_settings *params)
2944{
2945 struct wireless_dev *wdev;
2946 bool ret = false;
2947
Johannes Berg89a54e42012-06-15 14:33:17 +02002948 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002949 if (wdev->iftype != NL80211_IFTYPE_AP &&
2950 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2951 continue;
2952
Johannes Berg683b6d32012-11-08 21:25:48 +01002953 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002954 continue;
2955
Johannes Berg683b6d32012-11-08 21:25:48 +01002956 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002957 ret = true;
2958 break;
2959 }
2960
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002961 return ret;
2962}
2963
Jouni Malinene39e5b52012-09-30 19:29:39 +03002964static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2965 enum nl80211_auth_type auth_type,
2966 enum nl80211_commands cmd)
2967{
2968 if (auth_type > NL80211_AUTHTYPE_MAX)
2969 return false;
2970
2971 switch (cmd) {
2972 case NL80211_CMD_AUTHENTICATE:
2973 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2974 auth_type == NL80211_AUTHTYPE_SAE)
2975 return false;
2976 return true;
2977 case NL80211_CMD_CONNECT:
2978 case NL80211_CMD_START_AP:
2979 /* SAE not supported yet */
2980 if (auth_type == NL80211_AUTHTYPE_SAE)
2981 return false;
2982 return true;
2983 default:
2984 return false;
2985 }
2986}
2987
Johannes Berg88600202012-02-13 15:17:18 +01002988static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2989{
2990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2991 struct net_device *dev = info->user_ptr[1];
2992 struct wireless_dev *wdev = dev->ieee80211_ptr;
2993 struct cfg80211_ap_settings params;
2994 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01002995 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01002996
2997 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2998 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2999 return -EOPNOTSUPP;
3000
3001 if (!rdev->ops->start_ap)
3002 return -EOPNOTSUPP;
3003
3004 if (wdev->beacon_interval)
3005 return -EALREADY;
3006
3007 memset(&params, 0, sizeof(params));
3008
3009 /* these are required for START_AP */
3010 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3011 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3012 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3013 return -EINVAL;
3014
3015 err = nl80211_parse_beacon(info, &params.beacon);
3016 if (err)
3017 return err;
3018
3019 params.beacon_interval =
3020 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3021 params.dtim_period =
3022 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3023
3024 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3025 if (err)
3026 return err;
3027
3028 /*
3029 * In theory, some of these attributes should be required here
3030 * but since they were not used when the command was originally
3031 * added, keep them optional for old user space programs to let
3032 * them continue to work with drivers that do not need the
3033 * additional information -- drivers must check!
3034 */
3035 if (info->attrs[NL80211_ATTR_SSID]) {
3036 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3037 params.ssid_len =
3038 nla_len(info->attrs[NL80211_ATTR_SSID]);
3039 if (params.ssid_len == 0 ||
3040 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3041 return -EINVAL;
3042 }
3043
3044 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3045 params.hidden_ssid = nla_get_u32(
3046 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3047 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3048 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3049 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3050 return -EINVAL;
3051 }
3052
3053 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3054
3055 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3056 params.auth_type = nla_get_u32(
3057 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003058 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3059 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003060 return -EINVAL;
3061 } else
3062 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3063
3064 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3065 NL80211_MAX_NR_CIPHER_SUITES);
3066 if (err)
3067 return err;
3068
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303069 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3070 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3071 return -EOPNOTSUPP;
3072 params.inactivity_timeout = nla_get_u16(
3073 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3074 }
3075
Johannes Berg53cabad2012-11-14 15:17:28 +01003076 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3078 return -EINVAL;
3079 params.p2p_ctwindow =
3080 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3081 if (params.p2p_ctwindow > 127)
3082 return -EINVAL;
3083 if (params.p2p_ctwindow != 0 &&
3084 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3085 return -EINVAL;
3086 }
3087
3088 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3089 u8 tmp;
3090
3091 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3092 return -EINVAL;
3093 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3094 if (tmp > 1)
3095 return -EINVAL;
3096 params.p2p_opp_ps = tmp;
3097 if (params.p2p_opp_ps != 0 &&
3098 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3099 return -EINVAL;
3100 }
3101
Johannes Bergaa430da2012-05-16 23:50:18 +02003102 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003103 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3104 if (err)
3105 return err;
3106 } else if (wdev->preset_chandef.chan) {
3107 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003108 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003109 return -EINVAL;
3110
Johannes Berg683b6d32012-11-08 21:25:48 +01003111 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003112 return -EINVAL;
3113
Simon Wunderlich04f39042013-02-08 18:16:19 +01003114 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3115 if (err < 0)
3116 return err;
3117 if (err) {
3118 radar_detect_width = BIT(params.chandef.width);
3119 params.radar_required = true;
3120 }
3121
Simon Wunderlich04f39042013-02-08 18:16:19 +01003122 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3123 params.chandef.chan,
3124 CHAN_MODE_SHARED,
3125 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003126 if (err)
3127 return err;
3128
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303129 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3130 params.acl = parse_acl_data(&rdev->wiphy, info);
3131 if (IS_ERR(params.acl))
3132 return PTR_ERR(params.acl);
3133 }
3134
Hila Gonene35e4d22012-06-27 17:19:42 +03003135 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003136 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003137 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003138 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003139 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003140 wdev->ssid_len = params.ssid_len;
3141 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003142 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303143
3144 kfree(params.acl);
3145
Johannes Berg56d18932011-05-09 18:41:15 +02003146 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003147}
3148
Johannes Berg88600202012-02-13 15:17:18 +01003149static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3150{
3151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3152 struct net_device *dev = info->user_ptr[1];
3153 struct wireless_dev *wdev = dev->ieee80211_ptr;
3154 struct cfg80211_beacon_data params;
3155 int err;
3156
3157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3158 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3159 return -EOPNOTSUPP;
3160
3161 if (!rdev->ops->change_beacon)
3162 return -EOPNOTSUPP;
3163
3164 if (!wdev->beacon_interval)
3165 return -EINVAL;
3166
3167 err = nl80211_parse_beacon(info, &params);
3168 if (err)
3169 return err;
3170
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003172}
3173
3174static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003175{
Johannes Berg4c476992010-10-04 21:36:35 +02003176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3177 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003178
Michal Kazior60771782012-06-29 12:46:56 +02003179 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003180}
3181
Johannes Berg5727ef12007-12-19 02:03:34 +01003182static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3183 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3184 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3185 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003186 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003187 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003188 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003189};
3190
Johannes Bergeccb8e82009-05-11 21:57:56 +03003191static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003192 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003193 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003194{
3195 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003196 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003197 int flag;
3198
Johannes Bergeccb8e82009-05-11 21:57:56 +03003199 /*
3200 * Try parsing the new attribute first so userspace
3201 * can specify both for older kernels.
3202 */
3203 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3204 if (nla) {
3205 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003206
Johannes Bergeccb8e82009-05-11 21:57:56 +03003207 sta_flags = nla_data(nla);
3208 params->sta_flags_mask = sta_flags->mask;
3209 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003210 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003211 if ((params->sta_flags_mask |
3212 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3213 return -EINVAL;
3214 return 0;
3215 }
3216
3217 /* if present, parse the old attribute */
3218
3219 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003220 if (!nla)
3221 return 0;
3222
3223 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3224 nla, sta_flags_policy))
3225 return -EINVAL;
3226
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003227 /*
3228 * Only allow certain flags for interface types so that
3229 * other attributes are silently ignored. Remember that
3230 * this is backward compatibility code with old userspace
3231 * and shouldn't be hit in other cases anyway.
3232 */
3233 switch (iftype) {
3234 case NL80211_IFTYPE_AP:
3235 case NL80211_IFTYPE_AP_VLAN:
3236 case NL80211_IFTYPE_P2P_GO:
3237 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3238 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3239 BIT(NL80211_STA_FLAG_WME) |
3240 BIT(NL80211_STA_FLAG_MFP);
3241 break;
3242 case NL80211_IFTYPE_P2P_CLIENT:
3243 case NL80211_IFTYPE_STATION:
3244 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3245 BIT(NL80211_STA_FLAG_TDLS_PEER);
3246 break;
3247 case NL80211_IFTYPE_MESH_POINT:
3248 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3249 BIT(NL80211_STA_FLAG_MFP) |
3250 BIT(NL80211_STA_FLAG_AUTHORIZED);
3251 default:
3252 return -EINVAL;
3253 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003254
Johannes Berg3383b5a2012-05-10 20:14:43 +02003255 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3256 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003257 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003258
Johannes Berg3383b5a2012-05-10 20:14:43 +02003259 /* no longer support new API additions in old API */
3260 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3261 return -EINVAL;
3262 }
3263 }
3264
Johannes Berg5727ef12007-12-19 02:03:34 +01003265 return 0;
3266}
3267
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003268static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3269 int attr)
3270{
3271 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003272 u32 bitrate;
3273 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003274
3275 rate = nla_nest_start(msg, attr);
3276 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003277 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003278
3279 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3280 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003281 /* report 16-bit bitrate only if we can */
3282 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003283 if (bitrate > 0 &&
3284 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3285 return false;
3286 if (bitrate_compat > 0 &&
3287 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3288 return false;
3289
3290 if (info->flags & RATE_INFO_FLAGS_MCS) {
3291 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3292 return false;
3293 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3294 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3295 return false;
3296 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3297 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3298 return false;
3299 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3300 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3301 return false;
3302 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3303 return false;
3304 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3305 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3306 return false;
3307 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3308 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3309 return false;
3310 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3311 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3312 return false;
3313 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3314 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3315 return false;
3316 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3317 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3318 return false;
3319 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003320
3321 nla_nest_end(msg, rate);
3322 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003323}
3324
Felix Fietkau119363c2013-04-22 16:29:30 +02003325static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3326 int id)
3327{
3328 void *attr;
3329 int i = 0;
3330
3331 if (!mask)
3332 return true;
3333
3334 attr = nla_nest_start(msg, id);
3335 if (!attr)
3336 return false;
3337
3338 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3339 if (!(mask & BIT(i)))
3340 continue;
3341
3342 if (nla_put_u8(msg, i, signal[i]))
3343 return false;
3344 }
3345
3346 nla_nest_end(msg, attr);
3347
3348 return true;
3349}
3350
Eric W. Biederman15e47302012-09-07 20:12:54 +00003351static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003352 int flags,
3353 struct cfg80211_registered_device *rdev,
3354 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003355 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003356{
3357 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003358 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003359
Eric W. Biederman15e47302012-09-07 20:12:54 +00003360 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003361 if (!hdr)
3362 return -1;
3363
David S. Miller9360ffd2012-03-29 04:41:26 -04003364 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3366 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3367 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003368
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003369 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3370 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003371 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003372 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3373 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3374 sinfo->connected_time))
3375 goto nla_put_failure;
3376 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3377 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3378 sinfo->inactive_time))
3379 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003380 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3381 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003382 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003383 (u32)sinfo->rx_bytes))
3384 goto nla_put_failure;
3385 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003386 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003387 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3388 (u32)sinfo->tx_bytes))
3389 goto nla_put_failure;
3390 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3391 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003392 sinfo->rx_bytes))
3393 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003394 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3395 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003396 sinfo->tx_bytes))
3397 goto nla_put_failure;
3398 if ((sinfo->filled & STATION_INFO_LLID) &&
3399 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3400 goto nla_put_failure;
3401 if ((sinfo->filled & STATION_INFO_PLID) &&
3402 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3403 goto nla_put_failure;
3404 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3405 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3406 sinfo->plink_state))
3407 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003408 switch (rdev->wiphy.signal_type) {
3409 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3411 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3412 sinfo->signal))
3413 goto nla_put_failure;
3414 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3415 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3416 sinfo->signal_avg))
3417 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003418 break;
3419 default:
3420 break;
3421 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003422 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3423 if (!nl80211_put_signal(msg, sinfo->chains,
3424 sinfo->chain_signal,
3425 NL80211_STA_INFO_CHAIN_SIGNAL))
3426 goto nla_put_failure;
3427 }
3428 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3429 if (!nl80211_put_signal(msg, sinfo->chains,
3430 sinfo->chain_signal_avg,
3431 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3432 goto nla_put_failure;
3433 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003434 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003435 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3436 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003437 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003438 }
3439 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3440 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3441 NL80211_STA_INFO_RX_BITRATE))
3442 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003443 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003444 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3445 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3446 sinfo->rx_packets))
3447 goto nla_put_failure;
3448 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3449 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3450 sinfo->tx_packets))
3451 goto nla_put_failure;
3452 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3453 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3454 sinfo->tx_retries))
3455 goto nla_put_failure;
3456 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3458 sinfo->tx_failed))
3459 goto nla_put_failure;
3460 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3461 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3462 sinfo->beacon_loss_count))
3463 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003464 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3465 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3466 sinfo->local_pm))
3467 goto nla_put_failure;
3468 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3469 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3470 sinfo->peer_pm))
3471 goto nla_put_failure;
3472 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3473 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3474 sinfo->nonpeer_pm))
3475 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003476 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3477 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3478 if (!bss_param)
3479 goto nla_put_failure;
3480
David S. Miller9360ffd2012-03-29 04:41:26 -04003481 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3482 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3483 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3484 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3485 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3486 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3487 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3488 sinfo->bss_param.dtim_period) ||
3489 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3490 sinfo->bss_param.beacon_interval))
3491 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003492
3493 nla_nest_end(msg, bss_param);
3494 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003495 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3496 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3497 sizeof(struct nl80211_sta_flag_update),
3498 &sinfo->sta_flags))
3499 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003500 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3501 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3502 sinfo->t_offset))
3503 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003505
David S. Miller9360ffd2012-03-29 04:41:26 -04003506 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3507 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3508 sinfo->assoc_req_ies))
3509 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003510
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003511 return genlmsg_end(msg, hdr);
3512
3513 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003514 genlmsg_cancel(msg, hdr);
3515 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516}
3517
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003518static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003519 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003520{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003521 struct station_info sinfo;
3522 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003523 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003524 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003525 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003527
Johannes Berg97990a02013-04-19 01:02:55 +02003528 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003529 if (err)
3530 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003531
Johannes Berg97990a02013-04-19 01:02:55 +02003532 if (!wdev->netdev) {
3533 err = -EINVAL;
3534 goto out_err;
3535 }
3536
Johannes Bergbba95fe2008-07-29 13:22:51 +02003537 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 goto out_err;
3540 }
3541
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003543 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003544 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 if (err == -ENOENT)
3547 break;
3548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550
3551 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003554 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003555 &sinfo) < 0)
3556 goto out;
3557
3558 sta_idx++;
3559 }
3560
3561
3562 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003563 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003565 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003566 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567
3568 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570
Johannes Berg5727ef12007-12-19 02:03:34 +01003571static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3572{
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003575 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003578 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003581
3582 if (!info->attrs[NL80211_ATTR_MAC])
3583 return -EINVAL;
3584
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 if (!rdev->ops->get_station)
3588 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003592 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003596 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Eric W. Biederman15e47302012-09-07 20:12:54 +00003598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003600 nlmsg_free(msg);
3601 return -ENOBUFS;
3602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003605}
3606
Johannes Berg77ee7c82013-02-15 00:48:33 +01003607int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3610{
3611 if (params->listen_interval != -1)
3612 return -EINVAL;
3613 if (params->aid)
3614 return -EINVAL;
3615
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3618
3619 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003620 case CFG80211_STA_MESH_PEER_KERNEL:
3621 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003622 /*
3623 * No ignoring the TDLS flag here -- the userspace mesh
3624 * code doesn't have the bug of including TDLS in the
3625 * mask everywhere.
3626 */
3627 if (params->sta_flags_mask &
3628 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3629 BIT(NL80211_STA_FLAG_MFP) |
3630 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3631 return -EINVAL;
3632 break;
3633 case CFG80211_STA_TDLS_PEER_SETUP:
3634 case CFG80211_STA_TDLS_PEER_ACTIVE:
3635 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3636 return -EINVAL;
3637 /* ignore since it can't change */
3638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3639 break;
3640 default:
3641 /* disallow mesh-specific things */
3642 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3643 return -EINVAL;
3644 if (params->local_pm)
3645 return -EINVAL;
3646 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3647 return -EINVAL;
3648 }
3649
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3651 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3652 /* TDLS can't be set, ... */
3653 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3654 return -EINVAL;
3655 /*
3656 * ... but don't bother the driver with it. This works around
3657 * a hostapd/wpa_supplicant issue -- it always includes the
3658 * TLDS_PEER flag in the mask even for AP mode.
3659 */
3660 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3661 }
3662
3663 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3664 /* reject other things that can't change */
3665 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3666 return -EINVAL;
3667 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3668 return -EINVAL;
3669 if (params->supported_rates)
3670 return -EINVAL;
3671 if (params->ext_capab || params->ht_capa || params->vht_capa)
3672 return -EINVAL;
3673 }
3674
3675 if (statype != CFG80211_STA_AP_CLIENT) {
3676 if (params->vlan)
3677 return -EINVAL;
3678 }
3679
3680 switch (statype) {
3681 case CFG80211_STA_AP_MLME_CLIENT:
3682 /* Use this only for authorizing/unauthorizing a station */
3683 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3684 return -EOPNOTSUPP;
3685 break;
3686 case CFG80211_STA_AP_CLIENT:
3687 /* accept only the listed bits */
3688 if (params->sta_flags_mask &
3689 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3691 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3692 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3693 BIT(NL80211_STA_FLAG_WME) |
3694 BIT(NL80211_STA_FLAG_MFP)))
3695 return -EINVAL;
3696
3697 /* but authenticated/associated only if driver handles it */
3698 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3699 params->sta_flags_mask &
3700 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3702 return -EINVAL;
3703 break;
3704 case CFG80211_STA_IBSS:
3705 case CFG80211_STA_AP_STA:
3706 /* reject any changes other than AUTHORIZED */
3707 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3708 return -EINVAL;
3709 break;
3710 case CFG80211_STA_TDLS_PEER_SETUP:
3711 /* reject any changes other than AUTHORIZED or WME */
3712 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3713 BIT(NL80211_STA_FLAG_WME)))
3714 return -EINVAL;
3715 /* force (at least) rates when authorizing */
3716 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3717 !params->supported_rates)
3718 return -EINVAL;
3719 break;
3720 case CFG80211_STA_TDLS_PEER_ACTIVE:
3721 /* reject any changes */
3722 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003723 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3725 return -EINVAL;
3726 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003727 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3729 return -EINVAL;
3730 break;
3731 }
3732
3733 return 0;
3734}
3735EXPORT_SYMBOL(cfg80211_check_station_change);
3736
Johannes Berg5727ef12007-12-19 02:03:34 +01003737/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003738 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003739 */
Johannes Berg80b99892011-11-18 16:23:01 +01003740static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003742{
Johannes Berg463d0182009-07-14 00:33:35 +02003743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003744 struct net_device *v;
3745 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003746
Johannes Berg80b99892011-11-18 16:23:01 +01003747 if (!vlanattr)
3748 return NULL;
3749
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3751 if (!v)
3752 return ERR_PTR(-ENODEV);
3753
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3755 ret = -EINVAL;
3756 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003757 }
Johannes Berg80b99892011-11-18 16:23:01 +01003758
Johannes Berg77ee7c82013-02-15 00:48:33 +01003759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3762 ret = -EINVAL;
3763 goto error;
3764 }
3765
Johannes Berg80b99892011-11-18 16:23:01 +01003766 if (!netif_running(v)) {
3767 ret = -ENETDOWN;
3768 goto error;
3769 }
3770
3771 return v;
3772 error:
3773 dev_put(v);
3774 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003775}
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777static struct nla_policy
3778nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3781};
3782
Johannes Bergff276692013-02-15 00:09:01 +01003783static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003785{
Jouni Malinendf881292013-02-14 21:10:54 +02003786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3787 struct nlattr *nla;
3788 int err;
3789
Jouni Malinendf881292013-02-14 21:10:54 +02003790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3792 return 0;
3793
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3797 if (err)
3798 return err;
3799
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3804 return -EINVAL;
3805
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3808
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3810 return -EINVAL;
3811
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3813
3814 return 0;
3815}
3816
Johannes Bergff276692013-02-15 00:09:01 +01003817static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3819{
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003821 if (info->attrs[NL80211_ATTR_PEER_AID])
3822 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003823 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3824 params->ht_capa =
3825 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3826 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3827 params->vht_capa =
3828 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3829
3830 return nl80211_parse_sta_wme(info, params);
3831}
3832
Johannes Berg5727ef12007-12-19 02:03:34 +01003833static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3834{
Johannes Berg4c476992010-10-04 21:36:35 +02003835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003836 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003837 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003838 u8 *mac_addr;
3839 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003840
3841 memset(&params, 0, sizeof(params));
3842
3843 params.listen_interval = -1;
3844
Johannes Berg77ee7c82013-02-15 00:48:33 +01003845 if (!rdev->ops->change_station)
3846 return -EOPNOTSUPP;
3847
Johannes Berg5727ef12007-12-19 02:03:34 +01003848 if (info->attrs[NL80211_ATTR_STA_AID])
3849 return -EINVAL;
3850
3851 if (!info->attrs[NL80211_ATTR_MAC])
3852 return -EINVAL;
3853
3854 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3855
3856 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3857 params.supported_rates =
3858 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3859 params.supported_rates_len =
3860 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3861 }
3862
Jouni Malinen9d62a982013-02-14 21:10:13 +02003863 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3864 params.capability =
3865 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3866 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3867 }
3868
3869 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3870 params.ext_capab =
3871 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3872 params.ext_capab_len =
3873 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3874 }
3875
Jouni Malinendf881292013-02-14 21:10:54 +02003876 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003877 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003878
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003879 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003880 return -EINVAL;
3881
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003883 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003884 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3885 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3886 return -EINVAL;
3887 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003888
Johannes Bergf8bacc22013-02-14 23:27:01 +01003889 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003890 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003891 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3892 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3893 return -EINVAL;
3894 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3895 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003896
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003897 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3898 enum nl80211_mesh_power_mode pm = nla_get_u32(
3899 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3900
3901 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3902 pm > NL80211_MESH_POWER_MAX)
3903 return -EINVAL;
3904
3905 params.local_pm = pm;
3906 }
3907
Johannes Berg77ee7c82013-02-15 00:48:33 +01003908 /* Include parameters for TDLS peer (will check later) */
3909 err = nl80211_set_station_tdls(info, &params);
3910 if (err)
3911 return err;
3912
3913 params.vlan = get_vlan(info, rdev);
3914 if (IS_ERR(params.vlan))
3915 return PTR_ERR(params.vlan);
3916
Johannes Berga97f4422009-06-18 17:23:43 +02003917 switch (dev->ieee80211_ptr->iftype) {
3918 case NL80211_IFTYPE_AP:
3919 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003920 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003921 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003922 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003923 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003924 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003925 break;
3926 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003927 err = -EOPNOTSUPP;
3928 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003929 }
3930
Johannes Berg77ee7c82013-02-15 00:48:33 +01003931 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003932 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003933
Johannes Berg77ee7c82013-02-15 00:48:33 +01003934 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003935 if (params.vlan)
3936 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003937
Johannes Berg5727ef12007-12-19 02:03:34 +01003938 return err;
3939}
3940
3941static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3942{
Johannes Berg4c476992010-10-04 21:36:35 +02003943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003945 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003946 struct station_parameters params;
3947 u8 *mac_addr = NULL;
3948
3949 memset(&params, 0, sizeof(params));
3950
Johannes Berg984c3112013-02-14 23:43:25 +01003951 if (!rdev->ops->add_station)
3952 return -EOPNOTSUPP;
3953
Johannes Berg5727ef12007-12-19 02:03:34 +01003954 if (!info->attrs[NL80211_ATTR_MAC])
3955 return -EINVAL;
3956
Johannes Berg5727ef12007-12-19 02:03:34 +01003957 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3958 return -EINVAL;
3959
3960 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3961 return -EINVAL;
3962
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003963 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3964 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003965 return -EINVAL;
3966
Johannes Berg5727ef12007-12-19 02:03:34 +01003967 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3968 params.supported_rates =
3969 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3970 params.supported_rates_len =
3971 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3972 params.listen_interval =
3973 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003974
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003975 if (info->attrs[NL80211_ATTR_STA_AID])
3976 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3977 else
3978 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003979 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3980 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003981
Jouni Malinen9d62a982013-02-14 21:10:13 +02003982 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3983 params.capability =
3984 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3985 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3986 }
3987
3988 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3989 params.ext_capab =
3990 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3991 params.ext_capab_len =
3992 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3993 }
3994
Jouni Malinen36aedc92008-08-25 11:58:58 +03003995 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3996 params.ht_capa =
3997 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003998
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003999 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4000 params.vht_capa =
4001 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4002
Johannes Bergf8bacc22013-02-14 23:27:01 +01004003 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004004 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004005 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4006 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4007 return -EINVAL;
4008 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004009
Johannes Bergff276692013-02-15 00:09:01 +01004010 err = nl80211_parse_sta_wme(info, &params);
4011 if (err)
4012 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004013
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004014 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004015 return -EINVAL;
4016
Johannes Berg77ee7c82013-02-15 00:48:33 +01004017 /* When you run into this, adjust the code below for the new flag */
4018 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4019
Johannes Bergbdd90d52011-12-14 12:20:27 +01004020 switch (dev->ieee80211_ptr->iftype) {
4021 case NL80211_IFTYPE_AP:
4022 case NL80211_IFTYPE_AP_VLAN:
4023 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004024 /* ignore WME attributes if iface/sta is not capable */
4025 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4026 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4027 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004028
Johannes Bergbdd90d52011-12-14 12:20:27 +01004029 /* TDLS peers cannot be added */
4030 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004031 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004032 /* but don't bother the driver with it */
4033 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004034
Johannes Bergd582cff2012-10-26 17:53:44 +02004035 /* allow authenticated/associated only if driver handles it */
4036 if (!(rdev->wiphy.features &
4037 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4038 params.sta_flags_mask &
4039 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4040 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4041 return -EINVAL;
4042
Johannes Bergbdd90d52011-12-14 12:20:27 +01004043 /* must be last in here for error handling */
4044 params.vlan = get_vlan(info, rdev);
4045 if (IS_ERR(params.vlan))
4046 return PTR_ERR(params.vlan);
4047 break;
4048 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004049 /* ignore uAPSD data */
4050 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4051
Johannes Bergd582cff2012-10-26 17:53:44 +02004052 /* associated is disallowed */
4053 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4054 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004055 /* TDLS peers cannot be added */
4056 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004057 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004058 break;
4059 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004060 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004061 /* ignore uAPSD data */
4062 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4063
Johannes Berg77ee7c82013-02-15 00:48:33 +01004064 /* these are disallowed */
4065 if (params.sta_flags_mask &
4066 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4067 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004068 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004069 /* Only TDLS peers can be added */
4070 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4071 return -EINVAL;
4072 /* Can only add if TDLS ... */
4073 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4074 return -EOPNOTSUPP;
4075 /* ... with external setup is supported */
4076 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4077 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004078 /*
4079 * Older wpa_supplicant versions always mark the TDLS peer
4080 * as authorized, but it shouldn't yet be.
4081 */
4082 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004083 break;
4084 default:
4085 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004086 }
4087
Johannes Bergbdd90d52011-12-14 12:20:27 +01004088 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004089
Hila Gonene35e4d22012-06-27 17:19:42 +03004090 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004091
Johannes Berg5727ef12007-12-19 02:03:34 +01004092 if (params.vlan)
4093 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 return err;
4095}
4096
4097static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4098{
Johannes Berg4c476992010-10-04 21:36:35 +02004099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4100 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004101 u8 *mac_addr = NULL;
4102
4103 if (info->attrs[NL80211_ATTR_MAC])
4104 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4105
Johannes Berge80cf852009-05-11 14:43:13 +02004106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004107 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004108 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004109 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4110 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004111
Johannes Berg4c476992010-10-04 21:36:35 +02004112 if (!rdev->ops->del_station)
4113 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004114
Hila Gonene35e4d22012-06-27 17:19:42 +03004115 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004116}
4117
Eric W. Biederman15e47302012-09-07 20:12:54 +00004118static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004119 int flags, struct net_device *dev,
4120 u8 *dst, u8 *next_hop,
4121 struct mpath_info *pinfo)
4122{
4123 void *hdr;
4124 struct nlattr *pinfoattr;
4125
Eric W. Biederman15e47302012-09-07 20:12:54 +00004126 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004127 if (!hdr)
4128 return -1;
4129
David S. Miller9360ffd2012-03-29 04:41:26 -04004130 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4131 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4132 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4133 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4134 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004135
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004136 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4137 if (!pinfoattr)
4138 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004139 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4140 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4141 pinfo->frame_qlen))
4142 goto nla_put_failure;
4143 if (((pinfo->filled & MPATH_INFO_SN) &&
4144 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4145 ((pinfo->filled & MPATH_INFO_METRIC) &&
4146 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4147 pinfo->metric)) ||
4148 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4149 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4150 pinfo->exptime)) ||
4151 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4152 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4153 pinfo->flags)) ||
4154 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4155 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4156 pinfo->discovery_timeout)) ||
4157 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4158 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4159 pinfo->discovery_retries)))
4160 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004161
4162 nla_nest_end(msg, pinfoattr);
4163
4164 return genlmsg_end(msg, hdr);
4165
4166 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004167 genlmsg_cancel(msg, hdr);
4168 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004169}
4170
4171static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004172 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004173{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174 struct mpath_info pinfo;
4175 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004176 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004177 u8 dst[ETH_ALEN];
4178 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004179 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004180 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004181
Johannes Berg97990a02013-04-19 01:02:55 +02004182 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004183 if (err)
4184 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004185
4186 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004187 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004188 goto out_err;
4189 }
4190
Johannes Berg97990a02013-04-19 01:02:55 +02004191 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004192 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004193 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004194 }
4195
Johannes Bergbba95fe2008-07-29 13:22:51 +02004196 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004197 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4198 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004199 if (err == -ENOENT)
4200 break;
4201 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004202 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004203
Eric W. Biederman15e47302012-09-07 20:12:54 +00004204 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004205 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004206 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004207 &pinfo) < 0)
4208 goto out;
4209
4210 path_idx++;
4211 }
4212
4213
4214 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004215 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004216 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004217 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004218 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004219 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004220}
4221
4222static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4223{
Johannes Berg4c476992010-10-04 21:36:35 +02004224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004225 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004226 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004227 struct mpath_info pinfo;
4228 struct sk_buff *msg;
4229 u8 *dst = NULL;
4230 u8 next_hop[ETH_ALEN];
4231
4232 memset(&pinfo, 0, sizeof(pinfo));
4233
4234 if (!info->attrs[NL80211_ATTR_MAC])
4235 return -EINVAL;
4236
4237 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4238
Johannes Berg4c476992010-10-04 21:36:35 +02004239 if (!rdev->ops->get_mpath)
4240 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004241
Johannes Berg4c476992010-10-04 21:36:35 +02004242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4243 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004244
Hila Gonene35e4d22012-06-27 17:19:42 +03004245 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004246 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004247 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004250 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004251 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252
Eric W. Biederman15e47302012-09-07 20:12:54 +00004253 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004254 dev, dst, next_hop, &pinfo) < 0) {
4255 nlmsg_free(msg);
4256 return -ENOBUFS;
4257 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258
Johannes Berg4c476992010-10-04 21:36:35 +02004259 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260}
4261
4262static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4263{
Johannes Berg4c476992010-10-04 21:36:35 +02004264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4265 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004266 u8 *dst = NULL;
4267 u8 *next_hop = NULL;
4268
4269 if (!info->attrs[NL80211_ATTR_MAC])
4270 return -EINVAL;
4271
4272 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4273 return -EINVAL;
4274
4275 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4276 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4277
Johannes Berg4c476992010-10-04 21:36:35 +02004278 if (!rdev->ops->change_mpath)
4279 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004280
Johannes Berg4c476992010-10-04 21:36:35 +02004281 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4282 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004283
Hila Gonene35e4d22012-06-27 17:19:42 +03004284 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004285}
Johannes Berg4c476992010-10-04 21:36:35 +02004286
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004287static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4288{
Johannes Berg4c476992010-10-04 21:36:35 +02004289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4290 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004291 u8 *dst = NULL;
4292 u8 *next_hop = NULL;
4293
4294 if (!info->attrs[NL80211_ATTR_MAC])
4295 return -EINVAL;
4296
4297 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4298 return -EINVAL;
4299
4300 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4301 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4302
Johannes Berg4c476992010-10-04 21:36:35 +02004303 if (!rdev->ops->add_mpath)
4304 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004305
Johannes Berg4c476992010-10-04 21:36:35 +02004306 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4307 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004308
Hila Gonene35e4d22012-06-27 17:19:42 +03004309 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004310}
4311
4312static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4313{
Johannes Berg4c476992010-10-04 21:36:35 +02004314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4315 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004316 u8 *dst = NULL;
4317
4318 if (info->attrs[NL80211_ATTR_MAC])
4319 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4320
Johannes Berg4c476992010-10-04 21:36:35 +02004321 if (!rdev->ops->del_mpath)
4322 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004323
Hila Gonene35e4d22012-06-27 17:19:42 +03004324 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325}
4326
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004327static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4328{
Johannes Berg4c476992010-10-04 21:36:35 +02004329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4330 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004331 struct bss_parameters params;
4332
4333 memset(&params, 0, sizeof(params));
4334 /* default to not changing parameters */
4335 params.use_cts_prot = -1;
4336 params.use_short_preamble = -1;
4337 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004338 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004339 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004340 params.p2p_ctwindow = -1;
4341 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004342
4343 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4344 params.use_cts_prot =
4345 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4346 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4347 params.use_short_preamble =
4348 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4349 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4350 params.use_short_slot_time =
4351 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004352 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4353 params.basic_rates =
4354 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4355 params.basic_rates_len =
4356 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4357 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004358 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4359 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004360 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4361 params.ht_opmode =
4362 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004363
Johannes Berg53cabad2012-11-14 15:17:28 +01004364 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4366 return -EINVAL;
4367 params.p2p_ctwindow =
4368 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4369 if (params.p2p_ctwindow < 0)
4370 return -EINVAL;
4371 if (params.p2p_ctwindow != 0 &&
4372 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4373 return -EINVAL;
4374 }
4375
4376 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4377 u8 tmp;
4378
4379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4380 return -EINVAL;
4381 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4382 if (tmp > 1)
4383 return -EINVAL;
4384 params.p2p_opp_ps = tmp;
4385 if (params.p2p_opp_ps &&
4386 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4387 return -EINVAL;
4388 }
4389
Johannes Berg4c476992010-10-04 21:36:35 +02004390 if (!rdev->ops->change_bss)
4391 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004392
Johannes Berg074ac8d2010-09-16 14:58:22 +02004393 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004394 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4395 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004396
Hila Gonene35e4d22012-06-27 17:19:42 +03004397 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004398}
4399
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004400static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004401 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4402 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4403 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4404 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4405 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4406 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4407};
4408
4409static int parse_reg_rule(struct nlattr *tb[],
4410 struct ieee80211_reg_rule *reg_rule)
4411{
4412 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4413 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4414
4415 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4416 return -EINVAL;
4417 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4418 return -EINVAL;
4419 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4420 return -EINVAL;
4421 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4422 return -EINVAL;
4423 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4424 return -EINVAL;
4425
4426 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4427
4428 freq_range->start_freq_khz =
4429 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4430 freq_range->end_freq_khz =
4431 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4432 freq_range->max_bandwidth_khz =
4433 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4434
4435 power_rule->max_eirp =
4436 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4437
4438 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4439 power_rule->max_antenna_gain =
4440 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4441
4442 return 0;
4443}
4444
4445static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4446{
4447 int r;
4448 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004449 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004450
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004451 /*
4452 * You should only get this when cfg80211 hasn't yet initialized
4453 * completely when built-in to the kernel right between the time
4454 * window between nl80211_init() and regulatory_init(), if that is
4455 * even possible.
4456 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004457 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004458 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004459
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004460 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4461 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004462
4463 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4464
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004465 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4466 user_reg_hint_type =
4467 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4468 else
4469 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4470
4471 switch (user_reg_hint_type) {
4472 case NL80211_USER_REG_HINT_USER:
4473 case NL80211_USER_REG_HINT_CELL_BASE:
4474 break;
4475 default:
4476 return -EINVAL;
4477 }
4478
4479 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004480
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004481 return r;
4482}
4483
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004484static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004485 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004486{
Johannes Berg4c476992010-10-04 21:36:35 +02004487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004488 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004489 struct wireless_dev *wdev = dev->ieee80211_ptr;
4490 struct mesh_config cur_params;
4491 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004492 void *hdr;
4493 struct nlattr *pinfoattr;
4494 struct sk_buff *msg;
4495
Johannes Berg29cbe682010-12-03 09:20:44 +01004496 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4497 return -EOPNOTSUPP;
4498
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004499 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004500 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004501
Johannes Berg29cbe682010-12-03 09:20:44 +01004502 wdev_lock(wdev);
4503 /* If not connected, get default parameters */
4504 if (!wdev->mesh_id_len)
4505 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4506 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004507 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004508 wdev_unlock(wdev);
4509
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004510 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004511 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004512
4513 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004515 if (!msg)
4516 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004517 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004518 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004519 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004520 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004521 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004522 if (!pinfoattr)
4523 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004524 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4525 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4526 cur_params.dot11MeshRetryTimeout) ||
4527 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4528 cur_params.dot11MeshConfirmTimeout) ||
4529 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4530 cur_params.dot11MeshHoldingTimeout) ||
4531 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4532 cur_params.dot11MeshMaxPeerLinks) ||
4533 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4534 cur_params.dot11MeshMaxRetries) ||
4535 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4536 cur_params.dot11MeshTTL) ||
4537 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4538 cur_params.element_ttl) ||
4539 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4540 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004541 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4542 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004543 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4544 cur_params.dot11MeshHWMPmaxPREQretries) ||
4545 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4546 cur_params.path_refresh_time) ||
4547 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4548 cur_params.min_discovery_timeout) ||
4549 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4550 cur_params.dot11MeshHWMPactivePathTimeout) ||
4551 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4552 cur_params.dot11MeshHWMPpreqMinInterval) ||
4553 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4554 cur_params.dot11MeshHWMPperrMinInterval) ||
4555 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4556 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4557 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4558 cur_params.dot11MeshHWMPRootMode) ||
4559 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4560 cur_params.dot11MeshHWMPRannInterval) ||
4561 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4562 cur_params.dot11MeshGateAnnouncementProtocol) ||
4563 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4564 cur_params.dot11MeshForwarding) ||
4565 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004566 cur_params.rssi_threshold) ||
4567 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004568 cur_params.ht_opmode) ||
4569 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4570 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4571 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004572 cur_params.dot11MeshHWMProotInterval) ||
4573 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004574 cur_params.dot11MeshHWMPconfirmationInterval) ||
4575 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4576 cur_params.power_mode) ||
4577 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004578 cur_params.dot11MeshAwakeWindowDuration) ||
4579 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4580 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004581 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004582 nla_nest_end(msg, pinfoattr);
4583 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004584 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585
Johannes Berg3b858752009-03-12 09:55:09 +01004586 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004588 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004589 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004590 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004591}
4592
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004593static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4595 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4596 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4597 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4598 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4599 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004600 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004602 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004603 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4604 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4605 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4606 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4607 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004608 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004609 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004610 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004611 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004612 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004613 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004614 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4615 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004616 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4617 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004618 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004619 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4620 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004621 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004622};
4623
Javier Cardonac80d5452010-12-16 17:37:49 -08004624static const struct nla_policy
4625 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004626 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004627 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4628 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004629 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004630 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004631 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004632 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004633 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004634 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004635};
4636
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004637static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004638 struct mesh_config *cfg,
4639 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004640{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004641 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004642 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004643
Marco Porschea54fba2013-01-07 16:04:48 +01004644#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4645do { \
4646 if (tb[attr]) { \
4647 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4648 return -EINVAL; \
4649 cfg->param = fn(tb[attr]); \
4650 mask |= (1 << (attr - 1)); \
4651 } \
4652} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004653
4654
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004655 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004656 return -EINVAL;
4657 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004658 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004659 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004660 return -EINVAL;
4661
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662 /* This makes sure that there aren't more than 32 mesh config
4663 * parameters (otherwise our bitfield scheme would not work.) */
4664 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4665
4666 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004668 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4669 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004671 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4672 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004674 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4675 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004677 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4678 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004680 mask, NL80211_MESHCONF_MAX_RETRIES,
4681 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004682 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004683 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_ELEMENT_TTL,
4686 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004688 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4689 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4691 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004692 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4693 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004694 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004695 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4696 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004698 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4699 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004701 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4702 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4704 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004705 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4706 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004708 1, 65535, mask,
4709 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004710 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004711 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004712 1, 65535, mask,
4713 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004714 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004715 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004716 dot11MeshHWMPnetDiameterTraversalTime,
4717 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004718 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4719 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4721 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4722 nla_get_u8);
4723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4724 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004725 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004726 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004727 dot11MeshGateAnnouncementProtocol, 0, 1,
4728 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004729 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004731 mask, NL80211_MESHCONF_FORWARDING,
4732 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004734 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4735 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004737 mask, NL80211_MESHCONF_HT_OPMODE,
4738 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004739 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004740 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004741 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4742 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004744 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4745 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004747 dot11MeshHWMPconfirmationInterval,
4748 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004749 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4750 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4752 NL80211_MESH_POWER_ACTIVE,
4753 NL80211_MESH_POWER_MAX,
4754 mask, NL80211_MESHCONF_POWER_MODE,
4755 nla_get_u32);
4756 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4757 0, 65535, mask,
4758 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4760 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4761 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004762 if (mask_out)
4763 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004764
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004765 return 0;
4766
4767#undef FILL_IN_MESH_PARAM_IF_SET
4768}
4769
Javier Cardonac80d5452010-12-16 17:37:49 -08004770static int nl80211_parse_mesh_setup(struct genl_info *info,
4771 struct mesh_setup *setup)
4772{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004774 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4775
4776 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4777 return -EINVAL;
4778 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4779 info->attrs[NL80211_ATTR_MESH_SETUP],
4780 nl80211_mesh_setup_params_policy))
4781 return -EINVAL;
4782
Javier Cardonad299a1f2012-03-31 11:31:33 -07004783 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4784 setup->sync_method =
4785 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4786 IEEE80211_SYNC_METHOD_VENDOR :
4787 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4788
Javier Cardonac80d5452010-12-16 17:37:49 -08004789 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4790 setup->path_sel_proto =
4791 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4792 IEEE80211_PATH_PROTOCOL_VENDOR :
4793 IEEE80211_PATH_PROTOCOL_HWMP;
4794
4795 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4796 setup->path_metric =
4797 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4798 IEEE80211_PATH_METRIC_VENDOR :
4799 IEEE80211_PATH_METRIC_AIRTIME;
4800
Javier Cardona581a8b02011-04-07 15:08:27 -07004801
4802 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004803 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004804 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004805 if (!is_valid_ie_attr(ieattr))
4806 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004807 setup->ie = nla_data(ieattr);
4808 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004809 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004810 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4811 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4812 return -EINVAL;
4813 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004814 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4815 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004816 if (setup->is_secure)
4817 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004818
Colleen Twitty6e16d902013-05-08 11:45:59 -07004819 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4820 if (!setup->user_mpm)
4821 return -EINVAL;
4822 setup->auth_id =
4823 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4824 }
4825
Javier Cardonac80d5452010-12-16 17:37:49 -08004826 return 0;
4827}
4828
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004829static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004830 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004831{
4832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4833 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004834 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004835 struct mesh_config cfg;
4836 u32 mask;
4837 int err;
4838
Johannes Berg29cbe682010-12-03 09:20:44 +01004839 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4840 return -EOPNOTSUPP;
4841
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004842 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004843 return -EOPNOTSUPP;
4844
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004845 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004846 if (err)
4847 return err;
4848
Johannes Berg29cbe682010-12-03 09:20:44 +01004849 wdev_lock(wdev);
4850 if (!wdev->mesh_id_len)
4851 err = -ENOLINK;
4852
4853 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004854 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004855
4856 wdev_unlock(wdev);
4857
4858 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004859}
4860
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004861static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4862{
Johannes Berg458f4f92012-12-06 15:47:38 +01004863 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004864 struct sk_buff *msg;
4865 void *hdr = NULL;
4866 struct nlattr *nl_reg_rules;
4867 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004868
4869 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004870 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004871
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004872 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004873 if (!msg)
4874 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004875
Eric W. Biederman15e47302012-09-07 20:12:54 +00004876 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004877 NL80211_CMD_GET_REG);
4878 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004879 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004880
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004881 if (reg_last_request_cell_base() &&
4882 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4883 NL80211_USER_REG_HINT_CELL_BASE))
4884 goto nla_put_failure;
4885
Johannes Berg458f4f92012-12-06 15:47:38 +01004886 rcu_read_lock();
4887 regdom = rcu_dereference(cfg80211_regdomain);
4888
4889 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4890 (regdom->dfs_region &&
4891 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4892 goto nla_put_failure_rcu;
4893
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004894 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4895 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004896 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004897
Johannes Berg458f4f92012-12-06 15:47:38 +01004898 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004899 struct nlattr *nl_reg_rule;
4900 const struct ieee80211_reg_rule *reg_rule;
4901 const struct ieee80211_freq_range *freq_range;
4902 const struct ieee80211_power_rule *power_rule;
4903
Johannes Berg458f4f92012-12-06 15:47:38 +01004904 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004905 freq_range = &reg_rule->freq_range;
4906 power_rule = &reg_rule->power_rule;
4907
4908 nl_reg_rule = nla_nest_start(msg, i);
4909 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004910 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004911
David S. Miller9360ffd2012-03-29 04:41:26 -04004912 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4913 reg_rule->flags) ||
4914 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4915 freq_range->start_freq_khz) ||
4916 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4917 freq_range->end_freq_khz) ||
4918 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4919 freq_range->max_bandwidth_khz) ||
4920 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4921 power_rule->max_antenna_gain) ||
4922 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4923 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004924 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004925
4926 nla_nest_end(msg, nl_reg_rule);
4927 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004928 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004929
4930 nla_nest_end(msg, nl_reg_rules);
4931
4932 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004933 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004934
Johannes Berg458f4f92012-12-06 15:47:38 +01004935nla_put_failure_rcu:
4936 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004937nla_put_failure:
4938 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004939put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004940 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004941 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004942}
4943
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004944static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4945{
4946 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4947 struct nlattr *nl_reg_rule;
4948 char *alpha2 = NULL;
4949 int rem_reg_rules = 0, r = 0;
4950 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004951 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004952 struct ieee80211_regdomain *rd = NULL;
4953
4954 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4955 return -EINVAL;
4956
4957 if (!info->attrs[NL80211_ATTR_REG_RULES])
4958 return -EINVAL;
4959
4960 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4961
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004962 if (info->attrs[NL80211_ATTR_DFS_REGION])
4963 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4964
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004965 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004966 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004967 num_rules++;
4968 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004969 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004970 }
4971
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004973 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004974
4975 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004976 if (!rd)
4977 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004978
4979 rd->n_reg_rules = num_rules;
4980 rd->alpha2[0] = alpha2[0];
4981 rd->alpha2[1] = alpha2[1];
4982
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004983 /*
4984 * Disable DFS master mode if the DFS region was
4985 * not supported or known on this kernel.
4986 */
4987 if (reg_supported_dfs_region(dfs_region))
4988 rd->dfs_region = dfs_region;
4989
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004990 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004991 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004993 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4994 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004995 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4996 if (r)
4997 goto bad_reg;
4998
4999 rule_idx++;
5000
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005001 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5002 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005003 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005004 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005005 }
5006
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005007 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005008 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005009 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005010
Johannes Bergd2372b32008-10-24 20:32:20 +02005011 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005012 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005013 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005014}
5015
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005016static int validate_scan_freqs(struct nlattr *freqs)
5017{
5018 struct nlattr *attr1, *attr2;
5019 int n_channels = 0, tmp1, tmp2;
5020
5021 nla_for_each_nested(attr1, freqs, tmp1) {
5022 n_channels++;
5023 /*
5024 * Some hardware has a limited channel list for
5025 * scanning, and it is pretty much nonsensical
5026 * to scan for a channel twice, so disallow that
5027 * and don't require drivers to check that the
5028 * channel list they get isn't longer than what
5029 * they can scan, as long as they can scan all
5030 * the channels they registered at once.
5031 */
5032 nla_for_each_nested(attr2, freqs, tmp2)
5033 if (attr1 != attr2 &&
5034 nla_get_u32(attr1) == nla_get_u32(attr2))
5035 return 0;
5036 }
5037
5038 return n_channels;
5039}
5040
Johannes Berg2a519312009-02-10 21:25:55 +01005041static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5042{
Johannes Berg4c476992010-10-04 21:36:35 +02005043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005044 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005045 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005046 struct nlattr *attr;
5047 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005048 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005049 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005050
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005051 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5052 return -EINVAL;
5053
Johannes Berg79c97e92009-07-07 03:56:12 +02005054 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005055
Johannes Berg4c476992010-10-04 21:36:35 +02005056 if (!rdev->ops->scan)
5057 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005058
Johannes Bergf9f47522013-03-19 15:04:07 +01005059 if (rdev->scan_req) {
5060 err = -EBUSY;
5061 goto unlock;
5062 }
Johannes Berg2a519312009-02-10 21:25:55 +01005063
5064 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005065 n_channels = validate_scan_freqs(
5066 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005067 if (!n_channels) {
5068 err = -EINVAL;
5069 goto unlock;
5070 }
Johannes Berg2a519312009-02-10 21:25:55 +01005071 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005072 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005073 n_channels = 0;
5074
Johannes Berg2a519312009-02-10 21:25:55 +01005075 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5076 if (wiphy->bands[band])
5077 n_channels += wiphy->bands[band]->n_channels;
5078 }
5079
5080 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5081 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5082 n_ssids++;
5083
Johannes Bergf9f47522013-03-19 15:04:07 +01005084 if (n_ssids > wiphy->max_scan_ssids) {
5085 err = -EINVAL;
5086 goto unlock;
5087 }
Johannes Berg2a519312009-02-10 21:25:55 +01005088
Jouni Malinen70692ad2009-02-16 19:39:13 +02005089 if (info->attrs[NL80211_ATTR_IE])
5090 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5091 else
5092 ie_len = 0;
5093
Johannes Bergf9f47522013-03-19 15:04:07 +01005094 if (ie_len > wiphy->max_scan_ie_len) {
5095 err = -EINVAL;
5096 goto unlock;
5097 }
Johannes Berg18a83652009-03-31 12:12:05 +02005098
Johannes Berg2a519312009-02-10 21:25:55 +01005099 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005100 + sizeof(*request->ssids) * n_ssids
5101 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005102 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005103 if (!request) {
5104 err = -ENOMEM;
5105 goto unlock;
5106 }
Johannes Berg2a519312009-02-10 21:25:55 +01005107
Johannes Berg2a519312009-02-10 21:25:55 +01005108 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005109 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005110 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005111 if (ie_len) {
5112 if (request->ssids)
5113 request->ie = (void *)(request->ssids + n_ssids);
5114 else
5115 request->ie = (void *)(request->channels + n_channels);
5116 }
Johannes Berg2a519312009-02-10 21:25:55 +01005117
Johannes Berg584991d2009-11-02 13:32:03 +01005118 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005119 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5120 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005121 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005122 struct ieee80211_channel *chan;
5123
5124 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5125
5126 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005127 err = -EINVAL;
5128 goto out_free;
5129 }
Johannes Berg584991d2009-11-02 13:32:03 +01005130
5131 /* ignore disabled channels */
5132 if (chan->flags & IEEE80211_CHAN_DISABLED)
5133 continue;
5134
5135 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005136 i++;
5137 }
5138 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005139 enum ieee80211_band band;
5140
Johannes Berg2a519312009-02-10 21:25:55 +01005141 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005142 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5143 int j;
5144 if (!wiphy->bands[band])
5145 continue;
5146 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005147 struct ieee80211_channel *chan;
5148
5149 chan = &wiphy->bands[band]->channels[j];
5150
5151 if (chan->flags & IEEE80211_CHAN_DISABLED)
5152 continue;
5153
5154 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005155 i++;
5156 }
5157 }
5158 }
5159
Johannes Berg584991d2009-11-02 13:32:03 +01005160 if (!i) {
5161 err = -EINVAL;
5162 goto out_free;
5163 }
5164
5165 request->n_channels = i;
5166
Johannes Berg2a519312009-02-10 21:25:55 +01005167 i = 0;
5168 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5169 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005170 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005171 err = -EINVAL;
5172 goto out_free;
5173 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005174 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005175 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005176 i++;
5177 }
5178 }
5179
Jouni Malinen70692ad2009-02-16 19:39:13 +02005180 if (info->attrs[NL80211_ATTR_IE]) {
5181 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005182 memcpy((void *)request->ie,
5183 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005184 request->ie_len);
5185 }
5186
Johannes Berg34850ab2011-07-18 18:08:35 +02005187 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005188 if (wiphy->bands[i])
5189 request->rates[i] =
5190 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005191
5192 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5193 nla_for_each_nested(attr,
5194 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5195 tmp) {
5196 enum ieee80211_band band = nla_type(attr);
5197
Dan Carpenter84404622011-07-29 11:52:18 +03005198 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005199 err = -EINVAL;
5200 goto out_free;
5201 }
5202 err = ieee80211_get_ratemask(wiphy->bands[band],
5203 nla_data(attr),
5204 nla_len(attr),
5205 &request->rates[band]);
5206 if (err)
5207 goto out_free;
5208 }
5209 }
5210
Sam Leffler46856bb2012-10-11 21:03:32 -07005211 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005212 request->flags = nla_get_u32(
5213 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005214 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5215 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5216 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5217 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005218 err = -EOPNOTSUPP;
5219 goto out_free;
5220 }
5221 }
Sam Lefflered4737712012-10-11 21:03:31 -07005222
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305223 request->no_cck =
5224 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5225
Johannes Bergfd014282012-06-18 19:17:03 +02005226 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005227 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005228 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005229
Johannes Berg79c97e92009-07-07 03:56:12 +02005230 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005231 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005232
Johannes Berg463d0182009-07-14 00:33:35 +02005233 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005234 nl80211_send_scan_start(rdev, wdev);
5235 if (wdev->netdev)
5236 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005237 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005238 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005239 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005240 kfree(request);
5241 }
Johannes Berg3b858752009-03-12 09:55:09 +01005242
Johannes Bergf9f47522013-03-19 15:04:07 +01005243 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005244 return err;
5245}
5246
Luciano Coelho807f8a82011-05-11 17:09:35 +03005247static int nl80211_start_sched_scan(struct sk_buff *skb,
5248 struct genl_info *info)
5249{
5250 struct cfg80211_sched_scan_request *request;
5251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5252 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005253 struct nlattr *attr;
5254 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005255 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005256 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005257 enum ieee80211_band band;
5258 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005259 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005260
5261 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5262 !rdev->ops->sched_scan_start)
5263 return -EOPNOTSUPP;
5264
5265 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5266 return -EINVAL;
5267
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005268 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5269 return -EINVAL;
5270
5271 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5272 if (interval == 0)
5273 return -EINVAL;
5274
Luciano Coelho807f8a82011-05-11 17:09:35 +03005275 wiphy = &rdev->wiphy;
5276
5277 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5278 n_channels = validate_scan_freqs(
5279 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5280 if (!n_channels)
5281 return -EINVAL;
5282 } else {
5283 n_channels = 0;
5284
5285 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5286 if (wiphy->bands[band])
5287 n_channels += wiphy->bands[band]->n_channels;
5288 }
5289
5290 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5291 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5292 tmp)
5293 n_ssids++;
5294
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005295 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005296 return -EINVAL;
5297
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005298 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5299 nla_for_each_nested(attr,
5300 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5301 tmp)
5302 n_match_sets++;
5303
5304 if (n_match_sets > wiphy->max_match_sets)
5305 return -EINVAL;
5306
Luciano Coelho807f8a82011-05-11 17:09:35 +03005307 if (info->attrs[NL80211_ATTR_IE])
5308 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5309 else
5310 ie_len = 0;
5311
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005312 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005313 return -EINVAL;
5314
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005315 if (rdev->sched_scan_req) {
5316 err = -EINPROGRESS;
5317 goto out;
5318 }
5319
Luciano Coelho807f8a82011-05-11 17:09:35 +03005320 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005321 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005322 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005323 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005324 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005325 if (!request) {
5326 err = -ENOMEM;
5327 goto out;
5328 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005329
5330 if (n_ssids)
5331 request->ssids = (void *)&request->channels[n_channels];
5332 request->n_ssids = n_ssids;
5333 if (ie_len) {
5334 if (request->ssids)
5335 request->ie = (void *)(request->ssids + n_ssids);
5336 else
5337 request->ie = (void *)(request->channels + n_channels);
5338 }
5339
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005340 if (n_match_sets) {
5341 if (request->ie)
5342 request->match_sets = (void *)(request->ie + ie_len);
5343 else if (request->ssids)
5344 request->match_sets =
5345 (void *)(request->ssids + n_ssids);
5346 else
5347 request->match_sets =
5348 (void *)(request->channels + n_channels);
5349 }
5350 request->n_match_sets = n_match_sets;
5351
Luciano Coelho807f8a82011-05-11 17:09:35 +03005352 i = 0;
5353 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5354 /* user specified, bail out if channel not found */
5355 nla_for_each_nested(attr,
5356 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5357 tmp) {
5358 struct ieee80211_channel *chan;
5359
5360 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5361
5362 if (!chan) {
5363 err = -EINVAL;
5364 goto out_free;
5365 }
5366
5367 /* ignore disabled channels */
5368 if (chan->flags & IEEE80211_CHAN_DISABLED)
5369 continue;
5370
5371 request->channels[i] = chan;
5372 i++;
5373 }
5374 } else {
5375 /* all channels */
5376 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5377 int j;
5378 if (!wiphy->bands[band])
5379 continue;
5380 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5381 struct ieee80211_channel *chan;
5382
5383 chan = &wiphy->bands[band]->channels[j];
5384
5385 if (chan->flags & IEEE80211_CHAN_DISABLED)
5386 continue;
5387
5388 request->channels[i] = chan;
5389 i++;
5390 }
5391 }
5392 }
5393
5394 if (!i) {
5395 err = -EINVAL;
5396 goto out_free;
5397 }
5398
5399 request->n_channels = i;
5400
5401 i = 0;
5402 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5403 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5404 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005405 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005406 err = -EINVAL;
5407 goto out_free;
5408 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005409 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005410 memcpy(request->ssids[i].ssid, nla_data(attr),
5411 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005412 i++;
5413 }
5414 }
5415
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005416 i = 0;
5417 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5418 nla_for_each_nested(attr,
5419 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5420 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005421 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005422
5423 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5424 nla_data(attr), nla_len(attr),
5425 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005426 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005427 if (ssid) {
5428 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5429 err = -EINVAL;
5430 goto out_free;
5431 }
5432 memcpy(request->match_sets[i].ssid.ssid,
5433 nla_data(ssid), nla_len(ssid));
5434 request->match_sets[i].ssid.ssid_len =
5435 nla_len(ssid);
5436 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005437 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5438 if (rssi)
5439 request->rssi_thold = nla_get_u32(rssi);
5440 else
5441 request->rssi_thold =
5442 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005443 i++;
5444 }
5445 }
5446
Luciano Coelho807f8a82011-05-11 17:09:35 +03005447 if (info->attrs[NL80211_ATTR_IE]) {
5448 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5449 memcpy((void *)request->ie,
5450 nla_data(info->attrs[NL80211_ATTR_IE]),
5451 request->ie_len);
5452 }
5453
Sam Leffler46856bb2012-10-11 21:03:32 -07005454 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005455 request->flags = nla_get_u32(
5456 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005457 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5458 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5459 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5460 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005461 err = -EOPNOTSUPP;
5462 goto out_free;
5463 }
5464 }
Sam Lefflered4737712012-10-11 21:03:31 -07005465
Luciano Coelho807f8a82011-05-11 17:09:35 +03005466 request->dev = dev;
5467 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005468 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005469 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005470
Hila Gonene35e4d22012-06-27 17:19:42 +03005471 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005472 if (!err) {
5473 rdev->sched_scan_req = request;
5474 nl80211_send_sched_scan(rdev, dev,
5475 NL80211_CMD_START_SCHED_SCAN);
5476 goto out;
5477 }
5478
5479out_free:
5480 kfree(request);
5481out:
5482 return err;
5483}
5484
5485static int nl80211_stop_sched_scan(struct sk_buff *skb,
5486 struct genl_info *info)
5487{
5488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5489
5490 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5491 !rdev->ops->sched_scan_stop)
5492 return -EOPNOTSUPP;
5493
Johannes Berg5fe231e2013-05-08 21:45:15 +02005494 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005495}
5496
Simon Wunderlich04f39042013-02-08 18:16:19 +01005497static int nl80211_start_radar_detection(struct sk_buff *skb,
5498 struct genl_info *info)
5499{
5500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5501 struct net_device *dev = info->user_ptr[1];
5502 struct wireless_dev *wdev = dev->ieee80211_ptr;
5503 struct cfg80211_chan_def chandef;
5504 int err;
5505
5506 err = nl80211_parse_chandef(rdev, info, &chandef);
5507 if (err)
5508 return err;
5509
5510 if (wdev->cac_started)
5511 return -EBUSY;
5512
5513 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5514 if (err < 0)
5515 return err;
5516
5517 if (err == 0)
5518 return -EINVAL;
5519
5520 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5521 return -EINVAL;
5522
5523 if (!rdev->ops->start_radar_detection)
5524 return -EOPNOTSUPP;
5525
Simon Wunderlich04f39042013-02-08 18:16:19 +01005526 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5527 chandef.chan, CHAN_MODE_SHARED,
5528 BIT(chandef.width));
5529 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005530 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005531
5532 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5533 if (!err) {
5534 wdev->channel = chandef.chan;
5535 wdev->cac_started = true;
5536 wdev->cac_start_time = jiffies;
5537 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005538 return err;
5539}
5540
Johannes Berg9720bb32011-06-21 09:45:33 +02005541static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5542 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005543 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005544 struct wireless_dev *wdev,
5545 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005546{
Johannes Berg48ab9052009-07-10 18:42:31 +02005547 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005548 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005549 void *hdr;
5550 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005551 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005552
5553 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005554
Eric W. Biederman15e47302012-09-07 20:12:54 +00005555 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005556 NL80211_CMD_NEW_SCAN_RESULTS);
5557 if (!hdr)
5558 return -1;
5559
Johannes Berg9720bb32011-06-21 09:45:33 +02005560 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5561
Johannes Berg97990a02013-04-19 01:02:55 +02005562 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5563 goto nla_put_failure;
5564 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005565 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5566 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005567 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5568 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005569
5570 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5571 if (!bss)
5572 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005573 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005574 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005575 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005576
5577 rcu_read_lock();
5578 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005579 if (ies) {
5580 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5581 goto fail_unlock_rcu;
5582 tsf = true;
5583 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5584 ies->len, ies->data))
5585 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005586 }
5587 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005588 if (ies) {
5589 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5590 goto fail_unlock_rcu;
5591 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5592 ies->len, ies->data))
5593 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005594 }
5595 rcu_read_unlock();
5596
David S. Miller9360ffd2012-03-29 04:41:26 -04005597 if (res->beacon_interval &&
5598 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5599 goto nla_put_failure;
5600 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5601 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5602 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5603 jiffies_to_msecs(jiffies - intbss->ts)))
5604 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005605
Johannes Berg77965c92009-02-18 18:45:06 +01005606 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005607 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005608 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5609 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005610 break;
5611 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005612 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5613 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005614 break;
5615 default:
5616 break;
5617 }
5618
Johannes Berg48ab9052009-07-10 18:42:31 +02005619 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005620 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005621 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005622 if (intbss == wdev->current_bss &&
5623 nla_put_u32(msg, NL80211_BSS_STATUS,
5624 NL80211_BSS_STATUS_ASSOCIATED))
5625 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005626 break;
5627 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005628 if (intbss == wdev->current_bss &&
5629 nla_put_u32(msg, NL80211_BSS_STATUS,
5630 NL80211_BSS_STATUS_IBSS_JOINED))
5631 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005632 break;
5633 default:
5634 break;
5635 }
5636
Johannes Berg2a519312009-02-10 21:25:55 +01005637 nla_nest_end(msg, bss);
5638
5639 return genlmsg_end(msg, hdr);
5640
Johannes Berg8cef2c92013-02-05 16:54:31 +01005641 fail_unlock_rcu:
5642 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005643 nla_put_failure:
5644 genlmsg_cancel(msg, hdr);
5645 return -EMSGSIZE;
5646}
5647
Johannes Berg97990a02013-04-19 01:02:55 +02005648static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005649{
Johannes Berg48ab9052009-07-10 18:42:31 +02005650 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005651 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005652 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005653 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005654 int err;
5655
Johannes Berg97990a02013-04-19 01:02:55 +02005656 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005657 if (err)
5658 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005659
Johannes Berg48ab9052009-07-10 18:42:31 +02005660 wdev_lock(wdev);
5661 spin_lock_bh(&rdev->bss_lock);
5662 cfg80211_bss_expire(rdev);
5663
Johannes Berg9720bb32011-06-21 09:45:33 +02005664 cb->seq = rdev->bss_generation;
5665
Johannes Berg48ab9052009-07-10 18:42:31 +02005666 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005667 if (++idx <= start)
5668 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005669 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005670 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005671 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005672 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005673 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005674 }
5675 }
5676
Johannes Berg48ab9052009-07-10 18:42:31 +02005677 spin_unlock_bh(&rdev->bss_lock);
5678 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005679
Johannes Berg97990a02013-04-19 01:02:55 +02005680 cb->args[2] = idx;
5681 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005682
Johannes Berg67748892010-10-04 21:14:06 +02005683 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005684}
5685
Eric W. Biederman15e47302012-09-07 20:12:54 +00005686static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005687 int flags, struct net_device *dev,
5688 struct survey_info *survey)
5689{
5690 void *hdr;
5691 struct nlattr *infoattr;
5692
Eric W. Biederman15e47302012-09-07 20:12:54 +00005693 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005694 NL80211_CMD_NEW_SURVEY_RESULTS);
5695 if (!hdr)
5696 return -ENOMEM;
5697
David S. Miller9360ffd2012-03-29 04:41:26 -04005698 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5699 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005700
5701 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5702 if (!infoattr)
5703 goto nla_put_failure;
5704
David S. Miller9360ffd2012-03-29 04:41:26 -04005705 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5706 survey->channel->center_freq))
5707 goto nla_put_failure;
5708
5709 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5710 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5711 goto nla_put_failure;
5712 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5713 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5714 goto nla_put_failure;
5715 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5716 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5717 survey->channel_time))
5718 goto nla_put_failure;
5719 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5720 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5721 survey->channel_time_busy))
5722 goto nla_put_failure;
5723 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5724 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5725 survey->channel_time_ext_busy))
5726 goto nla_put_failure;
5727 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5728 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5729 survey->channel_time_rx))
5730 goto nla_put_failure;
5731 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5732 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5733 survey->channel_time_tx))
5734 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005735
5736 nla_nest_end(msg, infoattr);
5737
5738 return genlmsg_end(msg, hdr);
5739
5740 nla_put_failure:
5741 genlmsg_cancel(msg, hdr);
5742 return -EMSGSIZE;
5743}
5744
5745static int nl80211_dump_survey(struct sk_buff *skb,
5746 struct netlink_callback *cb)
5747{
5748 struct survey_info survey;
5749 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005750 struct wireless_dev *wdev;
5751 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005752 int res;
5753
Johannes Berg97990a02013-04-19 01:02:55 +02005754 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005755 if (res)
5756 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005757
Johannes Berg97990a02013-04-19 01:02:55 +02005758 if (!wdev->netdev) {
5759 res = -EINVAL;
5760 goto out_err;
5761 }
5762
Holger Schurig61fa7132009-11-11 12:25:40 +01005763 if (!dev->ops->dump_survey) {
5764 res = -EOPNOTSUPP;
5765 goto out_err;
5766 }
5767
5768 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005769 struct ieee80211_channel *chan;
5770
Johannes Berg97990a02013-04-19 01:02:55 +02005771 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005772 if (res == -ENOENT)
5773 break;
5774 if (res)
5775 goto out_err;
5776
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005777 /* Survey without a channel doesn't make sense */
5778 if (!survey.channel) {
5779 res = -EINVAL;
5780 goto out;
5781 }
5782
5783 chan = ieee80211_get_channel(&dev->wiphy,
5784 survey.channel->center_freq);
5785 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5786 survey_idx++;
5787 continue;
5788 }
5789
Holger Schurig61fa7132009-11-11 12:25:40 +01005790 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005791 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005792 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005793 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005794 goto out;
5795 survey_idx++;
5796 }
5797
5798 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005799 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005800 res = skb->len;
5801 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005802 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005803 return res;
5804}
5805
Samuel Ortizb23aa672009-07-01 21:26:54 +02005806static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5807{
5808 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5809 NL80211_WPA_VERSION_2));
5810}
5811
Jouni Malinen636a5d32009-03-19 13:39:22 +02005812static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5813{
Johannes Berg4c476992010-10-04 21:36:35 +02005814 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5815 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005816 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005817 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5818 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005819 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005820 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005821 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005822
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005823 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5824 return -EINVAL;
5825
5826 if (!info->attrs[NL80211_ATTR_MAC])
5827 return -EINVAL;
5828
Jouni Malinen17780922009-03-27 20:52:47 +02005829 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5830 return -EINVAL;
5831
Johannes Berg19957bb2009-07-02 17:20:43 +02005832 if (!info->attrs[NL80211_ATTR_SSID])
5833 return -EINVAL;
5834
5835 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5836 return -EINVAL;
5837
Johannes Bergfffd0932009-07-08 14:22:54 +02005838 err = nl80211_parse_key(info, &key);
5839 if (err)
5840 return err;
5841
5842 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005843 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5844 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005845 if (!key.p.key || !key.p.key_len)
5846 return -EINVAL;
5847 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5848 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5849 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5850 key.p.key_len != WLAN_KEY_LEN_WEP104))
5851 return -EINVAL;
5852 if (key.idx > 4)
5853 return -EINVAL;
5854 } else {
5855 key.p.key_len = 0;
5856 key.p.key = NULL;
5857 }
5858
Johannes Bergafea0b72010-08-10 09:46:42 +02005859 if (key.idx >= 0) {
5860 int i;
5861 bool ok = false;
5862 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5863 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5864 ok = true;
5865 break;
5866 }
5867 }
Johannes Berg4c476992010-10-04 21:36:35 +02005868 if (!ok)
5869 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005870 }
5871
Johannes Berg4c476992010-10-04 21:36:35 +02005872 if (!rdev->ops->auth)
5873 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005874
Johannes Berg074ac8d2010-09-16 14:58:22 +02005875 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005876 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5877 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005878
Johannes Berg19957bb2009-07-02 17:20:43 +02005879 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005880 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005881 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005882 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5883 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005884
Johannes Berg19957bb2009-07-02 17:20:43 +02005885 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5886 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5887
5888 if (info->attrs[NL80211_ATTR_IE]) {
5889 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5890 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5891 }
5892
5893 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005894 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005895 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005896
Jouni Malinene39e5b52012-09-30 19:29:39 +03005897 if (auth_type == NL80211_AUTHTYPE_SAE &&
5898 !info->attrs[NL80211_ATTR_SAE_DATA])
5899 return -EINVAL;
5900
5901 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5902 if (auth_type != NL80211_AUTHTYPE_SAE)
5903 return -EINVAL;
5904 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5905 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5906 /* need to include at least Auth Transaction and Status Code */
5907 if (sae_data_len < 4)
5908 return -EINVAL;
5909 }
5910
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005911 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5912
Johannes Berg95de8172012-01-20 13:55:25 +01005913 /*
5914 * Since we no longer track auth state, ignore
5915 * requests to only change local state.
5916 */
5917 if (local_state_change)
5918 return 0;
5919
Johannes Berg91bf9b22013-05-15 17:44:01 +02005920 wdev_lock(dev->ieee80211_ptr);
5921 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5922 ssid, ssid_len, ie, ie_len,
5923 key.p.key, key.p.key_len, key.idx,
5924 sae_data, sae_data_len);
5925 wdev_unlock(dev->ieee80211_ptr);
5926 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005927}
5928
Johannes Bergc0692b82010-08-27 14:26:53 +03005929static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5930 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005931 struct cfg80211_crypto_settings *settings,
5932 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005933{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005934 memset(settings, 0, sizeof(*settings));
5935
Samuel Ortizb23aa672009-07-01 21:26:54 +02005936 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5937
Johannes Bergc0692b82010-08-27 14:26:53 +03005938 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5939 u16 proto;
5940 proto = nla_get_u16(
5941 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5942 settings->control_port_ethertype = cpu_to_be16(proto);
5943 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5944 proto != ETH_P_PAE)
5945 return -EINVAL;
5946 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5947 settings->control_port_no_encrypt = true;
5948 } else
5949 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5950
Samuel Ortizb23aa672009-07-01 21:26:54 +02005951 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5952 void *data;
5953 int len, i;
5954
5955 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5956 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5957 settings->n_ciphers_pairwise = len / sizeof(u32);
5958
5959 if (len % sizeof(u32))
5960 return -EINVAL;
5961
Johannes Berg3dc27d22009-07-02 21:36:37 +02005962 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005963 return -EINVAL;
5964
5965 memcpy(settings->ciphers_pairwise, data, len);
5966
5967 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005968 if (!cfg80211_supported_cipher_suite(
5969 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005970 settings->ciphers_pairwise[i]))
5971 return -EINVAL;
5972 }
5973
5974 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5975 settings->cipher_group =
5976 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005977 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5978 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005979 return -EINVAL;
5980 }
5981
5982 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5983 settings->wpa_versions =
5984 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5985 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5986 return -EINVAL;
5987 }
5988
5989 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5990 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005991 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005992
5993 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5994 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5995 settings->n_akm_suites = len / sizeof(u32);
5996
5997 if (len % sizeof(u32))
5998 return -EINVAL;
5999
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006000 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6001 return -EINVAL;
6002
Samuel Ortizb23aa672009-07-01 21:26:54 +02006003 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006004 }
6005
6006 return 0;
6007}
6008
Jouni Malinen636a5d32009-03-19 13:39:22 +02006009static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6010{
Johannes Berg4c476992010-10-04 21:36:35 +02006011 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6012 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006013 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006014 struct cfg80211_assoc_request req = {};
6015 const u8 *bssid, *ssid;
6016 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006017
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006018 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6019 return -EINVAL;
6020
6021 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006022 !info->attrs[NL80211_ATTR_SSID] ||
6023 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006024 return -EINVAL;
6025
Johannes Berg4c476992010-10-04 21:36:35 +02006026 if (!rdev->ops->assoc)
6027 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006028
Johannes Berg074ac8d2010-09-16 14:58:22 +02006029 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006030 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6031 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006032
Johannes Berg19957bb2009-07-02 17:20:43 +02006033 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006034
Johannes Berg19957bb2009-07-02 17:20:43 +02006035 chan = ieee80211_get_channel(&rdev->wiphy,
6036 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006037 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6038 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006039
Johannes Berg19957bb2009-07-02 17:20:43 +02006040 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6041 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006042
6043 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006044 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6045 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006046 }
6047
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006048 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006049 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006050 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006051 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006052 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006053 else if (mfp != NL80211_MFP_NO)
6054 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006055 }
6056
Johannes Berg3e5d7642009-07-07 14:37:26 +02006057 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006058 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006059
Ben Greear7e7c8922011-11-18 11:31:59 -08006060 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006061 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006062
6063 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006064 memcpy(&req.ht_capa_mask,
6065 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6066 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006067
6068 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006069 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006070 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006071 memcpy(&req.ht_capa,
6072 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6073 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006074 }
6075
Johannes Bergee2aca32013-02-21 17:36:01 +01006076 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006077 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006078
6079 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006080 memcpy(&req.vht_capa_mask,
6081 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6082 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006083
6084 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006085 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006086 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006087 memcpy(&req.vht_capa,
6088 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6089 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006090 }
6091
Johannes Bergf62fab72013-02-21 20:09:09 +01006092 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006093 if (!err) {
6094 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006095 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6096 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006097 wdev_unlock(dev->ieee80211_ptr);
6098 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006099
Jouni Malinen636a5d32009-03-19 13:39:22 +02006100 return err;
6101}
6102
6103static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6104{
Johannes Berg4c476992010-10-04 21:36:35 +02006105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6106 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006107 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006108 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006109 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006110 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006111
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006112 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6113 return -EINVAL;
6114
6115 if (!info->attrs[NL80211_ATTR_MAC])
6116 return -EINVAL;
6117
6118 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6119 return -EINVAL;
6120
Johannes Berg4c476992010-10-04 21:36:35 +02006121 if (!rdev->ops->deauth)
6122 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006123
Johannes Berg074ac8d2010-09-16 14:58:22 +02006124 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006125 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6126 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006127
Johannes Berg19957bb2009-07-02 17:20:43 +02006128 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006129
Johannes Berg19957bb2009-07-02 17:20:43 +02006130 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6131 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006132 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006133 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006134 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006135
6136 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006137 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6138 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006139 }
6140
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006141 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6142
Johannes Berg91bf9b22013-05-15 17:44:01 +02006143 wdev_lock(dev->ieee80211_ptr);
6144 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6145 local_state_change);
6146 wdev_unlock(dev->ieee80211_ptr);
6147 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006148}
6149
6150static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6151{
Johannes Berg4c476992010-10-04 21:36:35 +02006152 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6153 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006154 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006155 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006156 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006157 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006158
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006159 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6160 return -EINVAL;
6161
6162 if (!info->attrs[NL80211_ATTR_MAC])
6163 return -EINVAL;
6164
6165 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6166 return -EINVAL;
6167
Johannes Berg4c476992010-10-04 21:36:35 +02006168 if (!rdev->ops->disassoc)
6169 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006170
Johannes Berg074ac8d2010-09-16 14:58:22 +02006171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006172 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6173 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006174
Johannes Berg19957bb2009-07-02 17:20:43 +02006175 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006176
Johannes Berg19957bb2009-07-02 17:20:43 +02006177 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6178 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006179 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006180 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006181 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006182
6183 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006184 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6185 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006186 }
6187
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006188 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6189
Johannes Berg91bf9b22013-05-15 17:44:01 +02006190 wdev_lock(dev->ieee80211_ptr);
6191 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6192 local_state_change);
6193 wdev_unlock(dev->ieee80211_ptr);
6194 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006195}
6196
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006197static bool
6198nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6199 int mcast_rate[IEEE80211_NUM_BANDS],
6200 int rateval)
6201{
6202 struct wiphy *wiphy = &rdev->wiphy;
6203 bool found = false;
6204 int band, i;
6205
6206 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6207 struct ieee80211_supported_band *sband;
6208
6209 sband = wiphy->bands[band];
6210 if (!sband)
6211 continue;
6212
6213 for (i = 0; i < sband->n_bitrates; i++) {
6214 if (sband->bitrates[i].bitrate == rateval) {
6215 mcast_rate[band] = i + 1;
6216 found = true;
6217 break;
6218 }
6219 }
6220 }
6221
6222 return found;
6223}
6224
Johannes Berg04a773a2009-04-19 21:24:32 +02006225static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6226{
Johannes Berg4c476992010-10-04 21:36:35 +02006227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6228 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006229 struct cfg80211_ibss_params ibss;
6230 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006231 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006232 int err;
6233
Johannes Berg8e30bc52009-04-22 17:45:38 +02006234 memset(&ibss, 0, sizeof(ibss));
6235
Johannes Berg04a773a2009-04-19 21:24:32 +02006236 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6237 return -EINVAL;
6238
Johannes Berg683b6d32012-11-08 21:25:48 +01006239 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006240 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6241 return -EINVAL;
6242
Johannes Berg8e30bc52009-04-22 17:45:38 +02006243 ibss.beacon_interval = 100;
6244
6245 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6246 ibss.beacon_interval =
6247 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6248 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6249 return -EINVAL;
6250 }
6251
Johannes Berg4c476992010-10-04 21:36:35 +02006252 if (!rdev->ops->join_ibss)
6253 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006254
Johannes Berg4c476992010-10-04 21:36:35 +02006255 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6256 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006257
Johannes Berg79c97e92009-07-07 03:56:12 +02006258 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006259
Johannes Berg39193492011-09-16 13:45:25 +02006260 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006261 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006262
6263 if (!is_valid_ether_addr(ibss.bssid))
6264 return -EINVAL;
6265 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006266 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6267 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6268
6269 if (info->attrs[NL80211_ATTR_IE]) {
6270 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6271 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6272 }
6273
Johannes Berg683b6d32012-11-08 21:25:48 +01006274 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6275 if (err)
6276 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006277
Johannes Berg683b6d32012-11-08 21:25:48 +01006278 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006279 return -EINVAL;
6280
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006281 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6282 return -EINVAL;
6283 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6284 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006285 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006286
Johannes Berg04a773a2009-04-19 21:24:32 +02006287 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006288 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006289
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006290 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6291 u8 *rates =
6292 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6293 int n_rates =
6294 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6295 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006296 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006297
Johannes Berg34850ab2011-07-18 18:08:35 +02006298 err = ieee80211_get_ratemask(sband, rates, n_rates,
6299 &ibss.basic_rates);
6300 if (err)
6301 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006302 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006303
6304 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6305 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6306 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6307 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006308
Johannes Berg4c476992010-10-04 21:36:35 +02006309 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306310 bool no_ht = false;
6311
Johannes Berg4c476992010-10-04 21:36:35 +02006312 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306313 info->attrs[NL80211_ATTR_KEYS],
6314 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006315 if (IS_ERR(connkeys))
6316 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306317
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006318 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6319 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306320 kfree(connkeys);
6321 return -EINVAL;
6322 }
Johannes Berg4c476992010-10-04 21:36:35 +02006323 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006324
Antonio Quartulli267335d2012-01-31 20:25:47 +01006325 ibss.control_port =
6326 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6327
Johannes Berg4c476992010-10-04 21:36:35 +02006328 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006329 if (err)
6330 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006331 return err;
6332}
6333
6334static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6335{
Johannes Berg4c476992010-10-04 21:36:35 +02006336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6337 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006338
Johannes Berg4c476992010-10-04 21:36:35 +02006339 if (!rdev->ops->leave_ibss)
6340 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006341
Johannes Berg4c476992010-10-04 21:36:35 +02006342 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6343 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006344
Johannes Berg4c476992010-10-04 21:36:35 +02006345 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006346}
6347
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006348static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6349{
6350 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6351 struct net_device *dev = info->user_ptr[1];
6352 int mcast_rate[IEEE80211_NUM_BANDS];
6353 u32 nla_rate;
6354 int err;
6355
6356 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6357 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6358 return -EOPNOTSUPP;
6359
6360 if (!rdev->ops->set_mcast_rate)
6361 return -EOPNOTSUPP;
6362
6363 memset(mcast_rate, 0, sizeof(mcast_rate));
6364
6365 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6366 return -EINVAL;
6367
6368 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6369 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6370 return -EINVAL;
6371
6372 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6373
6374 return err;
6375}
6376
6377
Johannes Bergaff89a92009-07-01 21:26:51 +02006378#ifdef CONFIG_NL80211_TESTMODE
6379static struct genl_multicast_group nl80211_testmode_mcgrp = {
6380 .name = "testmode",
6381};
6382
6383static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6384{
Johannes Berg4c476992010-10-04 21:36:35 +02006385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006386 int err;
6387
6388 if (!info->attrs[NL80211_ATTR_TESTDATA])
6389 return -EINVAL;
6390
Johannes Bergaff89a92009-07-01 21:26:51 +02006391 err = -EOPNOTSUPP;
6392 if (rdev->ops->testmode_cmd) {
6393 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006394 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006395 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6396 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6397 rdev->testmode_info = NULL;
6398 }
6399
Johannes Bergaff89a92009-07-01 21:26:51 +02006400 return err;
6401}
6402
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006403static int nl80211_testmode_dump(struct sk_buff *skb,
6404 struct netlink_callback *cb)
6405{
Johannes Berg00918d32011-12-13 17:22:05 +01006406 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006407 int err;
6408 long phy_idx;
6409 void *data = NULL;
6410 int data_len = 0;
6411
Johannes Berg5fe231e2013-05-08 21:45:15 +02006412 rtnl_lock();
6413
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006414 if (cb->args[0]) {
6415 /*
6416 * 0 is a valid index, but not valid for args[0],
6417 * so we need to offset by 1.
6418 */
6419 phy_idx = cb->args[0] - 1;
6420 } else {
6421 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6422 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6423 nl80211_policy);
6424 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006425 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006426
Johannes Berg2bd7e352012-06-15 14:23:16 +02006427 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6428 nl80211_fam.attrbuf);
6429 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006430 err = PTR_ERR(rdev);
6431 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006432 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006433 phy_idx = rdev->wiphy_idx;
6434 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006435
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006436 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6437 cb->args[1] =
6438 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6439 }
6440
6441 if (cb->args[1]) {
6442 data = nla_data((void *)cb->args[1]);
6443 data_len = nla_len((void *)cb->args[1]);
6444 }
6445
Johannes Berg00918d32011-12-13 17:22:05 +01006446 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6447 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006448 err = -ENOENT;
6449 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006450 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006451
Johannes Berg00918d32011-12-13 17:22:05 +01006452 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006453 err = -EOPNOTSUPP;
6454 goto out_err;
6455 }
6456
6457 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006458 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006459 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6460 NL80211_CMD_TESTMODE);
6461 struct nlattr *tmdata;
6462
David S. Miller9360ffd2012-03-29 04:41:26 -04006463 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006464 genlmsg_cancel(skb, hdr);
6465 break;
6466 }
6467
6468 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6469 if (!tmdata) {
6470 genlmsg_cancel(skb, hdr);
6471 break;
6472 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006473 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006474 nla_nest_end(skb, tmdata);
6475
6476 if (err == -ENOBUFS || err == -ENOENT) {
6477 genlmsg_cancel(skb, hdr);
6478 break;
6479 } else if (err) {
6480 genlmsg_cancel(skb, hdr);
6481 goto out_err;
6482 }
6483
6484 genlmsg_end(skb, hdr);
6485 }
6486
6487 err = skb->len;
6488 /* see above */
6489 cb->args[0] = phy_idx + 1;
6490 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006491 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006492 return err;
6493}
6494
Johannes Bergaff89a92009-07-01 21:26:51 +02006495static struct sk_buff *
6496__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006497 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006498{
6499 struct sk_buff *skb;
6500 void *hdr;
6501 struct nlattr *data;
6502
6503 skb = nlmsg_new(approxlen + 100, gfp);
6504 if (!skb)
6505 return NULL;
6506
Eric W. Biederman15e47302012-09-07 20:12:54 +00006507 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006508 if (!hdr) {
6509 kfree_skb(skb);
6510 return NULL;
6511 }
6512
David S. Miller9360ffd2012-03-29 04:41:26 -04006513 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6514 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006515 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6516
6517 ((void **)skb->cb)[0] = rdev;
6518 ((void **)skb->cb)[1] = hdr;
6519 ((void **)skb->cb)[2] = data;
6520
6521 return skb;
6522
6523 nla_put_failure:
6524 kfree_skb(skb);
6525 return NULL;
6526}
6527
6528struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6529 int approxlen)
6530{
6531 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6532
6533 if (WARN_ON(!rdev->testmode_info))
6534 return NULL;
6535
6536 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006537 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006538 rdev->testmode_info->snd_seq,
6539 GFP_KERNEL);
6540}
6541EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6542
6543int cfg80211_testmode_reply(struct sk_buff *skb)
6544{
6545 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6546 void *hdr = ((void **)skb->cb)[1];
6547 struct nlattr *data = ((void **)skb->cb)[2];
6548
6549 if (WARN_ON(!rdev->testmode_info)) {
6550 kfree_skb(skb);
6551 return -EINVAL;
6552 }
6553
6554 nla_nest_end(skb, data);
6555 genlmsg_end(skb, hdr);
6556 return genlmsg_reply(skb, rdev->testmode_info);
6557}
6558EXPORT_SYMBOL(cfg80211_testmode_reply);
6559
6560struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6561 int approxlen, gfp_t gfp)
6562{
6563 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6564
6565 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6566}
6567EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6568
6569void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6570{
6571 void *hdr = ((void **)skb->cb)[1];
6572 struct nlattr *data = ((void **)skb->cb)[2];
6573
6574 nla_nest_end(skb, data);
6575 genlmsg_end(skb, hdr);
6576 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6577}
6578EXPORT_SYMBOL(cfg80211_testmode_event);
6579#endif
6580
Samuel Ortizb23aa672009-07-01 21:26:54 +02006581static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6582{
Johannes Berg4c476992010-10-04 21:36:35 +02006583 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6584 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006585 struct cfg80211_connect_params connect;
6586 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006587 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006588 int err;
6589
6590 memset(&connect, 0, sizeof(connect));
6591
6592 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6593 return -EINVAL;
6594
6595 if (!info->attrs[NL80211_ATTR_SSID] ||
6596 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6597 return -EINVAL;
6598
6599 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6600 connect.auth_type =
6601 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006602 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6603 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006604 return -EINVAL;
6605 } else
6606 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6607
6608 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6609
Johannes Bergc0692b82010-08-27 14:26:53 +03006610 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006611 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006612 if (err)
6613 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006614
Johannes Berg074ac8d2010-09-16 14:58:22 +02006615 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006616 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6617 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006618
Johannes Berg79c97e92009-07-07 03:56:12 +02006619 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006620
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306621 connect.bg_scan_period = -1;
6622 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6623 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6624 connect.bg_scan_period =
6625 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6626 }
6627
Samuel Ortizb23aa672009-07-01 21:26:54 +02006628 if (info->attrs[NL80211_ATTR_MAC])
6629 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6630 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6631 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6632
6633 if (info->attrs[NL80211_ATTR_IE]) {
6634 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6635 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6636 }
6637
Jouni Malinencee00a92013-01-15 17:15:57 +02006638 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6639 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6640 if (connect.mfp != NL80211_MFP_REQUIRED &&
6641 connect.mfp != NL80211_MFP_NO)
6642 return -EINVAL;
6643 } else {
6644 connect.mfp = NL80211_MFP_NO;
6645 }
6646
Samuel Ortizb23aa672009-07-01 21:26:54 +02006647 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6648 connect.channel =
6649 ieee80211_get_channel(wiphy,
6650 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6651 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006652 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6653 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006654 }
6655
Johannes Bergfffd0932009-07-08 14:22:54 +02006656 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6657 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306658 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006659 if (IS_ERR(connkeys))
6660 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006661 }
6662
Ben Greear7e7c8922011-11-18 11:31:59 -08006663 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6664 connect.flags |= ASSOC_REQ_DISABLE_HT;
6665
6666 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6667 memcpy(&connect.ht_capa_mask,
6668 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6669 sizeof(connect.ht_capa_mask));
6670
6671 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006672 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6673 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006674 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006675 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006676 memcpy(&connect.ht_capa,
6677 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6678 sizeof(connect.ht_capa));
6679 }
6680
Johannes Bergee2aca32013-02-21 17:36:01 +01006681 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6682 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6683
6684 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6685 memcpy(&connect.vht_capa_mask,
6686 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6687 sizeof(connect.vht_capa_mask));
6688
6689 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6690 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6691 kfree(connkeys);
6692 return -EINVAL;
6693 }
6694 memcpy(&connect.vht_capa,
6695 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6696 sizeof(connect.vht_capa));
6697 }
6698
Johannes Berg83739b02013-05-15 17:44:01 +02006699 wdev_lock(dev->ieee80211_ptr);
6700 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6701 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006702 if (err)
6703 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006704 return err;
6705}
6706
6707static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6708{
Johannes Berg4c476992010-10-04 21:36:35 +02006709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6710 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006711 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006712 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006713
6714 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6715 reason = WLAN_REASON_DEAUTH_LEAVING;
6716 else
6717 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6718
6719 if (reason == 0)
6720 return -EINVAL;
6721
Johannes Berg074ac8d2010-09-16 14:58:22 +02006722 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006723 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6724 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006725
Johannes Berg83739b02013-05-15 17:44:01 +02006726 wdev_lock(dev->ieee80211_ptr);
6727 ret = cfg80211_disconnect(rdev, dev, reason, true);
6728 wdev_unlock(dev->ieee80211_ptr);
6729 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006730}
6731
Johannes Berg463d0182009-07-14 00:33:35 +02006732static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6733{
Johannes Berg4c476992010-10-04 21:36:35 +02006734 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006735 struct net *net;
6736 int err;
6737 u32 pid;
6738
6739 if (!info->attrs[NL80211_ATTR_PID])
6740 return -EINVAL;
6741
6742 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6743
Johannes Berg463d0182009-07-14 00:33:35 +02006744 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006745 if (IS_ERR(net))
6746 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006747
6748 err = 0;
6749
6750 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006751 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6752 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006753
Johannes Berg463d0182009-07-14 00:33:35 +02006754 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006755 return err;
6756}
6757
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006758static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6759{
Johannes Berg4c476992010-10-04 21:36:35 +02006760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006761 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6762 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006763 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006764 struct cfg80211_pmksa pmksa;
6765
6766 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6767
6768 if (!info->attrs[NL80211_ATTR_MAC])
6769 return -EINVAL;
6770
6771 if (!info->attrs[NL80211_ATTR_PMKID])
6772 return -EINVAL;
6773
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006774 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6775 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6776
Johannes Berg074ac8d2010-09-16 14:58:22 +02006777 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006778 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6779 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006780
6781 switch (info->genlhdr->cmd) {
6782 case NL80211_CMD_SET_PMKSA:
6783 rdev_ops = rdev->ops->set_pmksa;
6784 break;
6785 case NL80211_CMD_DEL_PMKSA:
6786 rdev_ops = rdev->ops->del_pmksa;
6787 break;
6788 default:
6789 WARN_ON(1);
6790 break;
6791 }
6792
Johannes Berg4c476992010-10-04 21:36:35 +02006793 if (!rdev_ops)
6794 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006795
Johannes Berg4c476992010-10-04 21:36:35 +02006796 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006797}
6798
6799static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6800{
Johannes Berg4c476992010-10-04 21:36:35 +02006801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6802 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006803
Johannes Berg074ac8d2010-09-16 14:58:22 +02006804 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006805 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6806 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006807
Johannes Berg4c476992010-10-04 21:36:35 +02006808 if (!rdev->ops->flush_pmksa)
6809 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006810
Hila Gonene35e4d22012-06-27 17:19:42 +03006811 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006812}
6813
Arik Nemtsov109086c2011-09-28 14:12:50 +03006814static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6815{
6816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6817 struct net_device *dev = info->user_ptr[1];
6818 u8 action_code, dialog_token;
6819 u16 status_code;
6820 u8 *peer;
6821
6822 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6823 !rdev->ops->tdls_mgmt)
6824 return -EOPNOTSUPP;
6825
6826 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6827 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6828 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6829 !info->attrs[NL80211_ATTR_IE] ||
6830 !info->attrs[NL80211_ATTR_MAC])
6831 return -EINVAL;
6832
6833 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6834 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6835 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6836 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6837
Hila Gonene35e4d22012-06-27 17:19:42 +03006838 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6839 dialog_token, status_code,
6840 nla_data(info->attrs[NL80211_ATTR_IE]),
6841 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006842}
6843
6844static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6845{
6846 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6847 struct net_device *dev = info->user_ptr[1];
6848 enum nl80211_tdls_operation operation;
6849 u8 *peer;
6850
6851 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6852 !rdev->ops->tdls_oper)
6853 return -EOPNOTSUPP;
6854
6855 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6856 !info->attrs[NL80211_ATTR_MAC])
6857 return -EINVAL;
6858
6859 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6860 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6861
Hila Gonene35e4d22012-06-27 17:19:42 +03006862 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006863}
6864
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006865static int nl80211_remain_on_channel(struct sk_buff *skb,
6866 struct genl_info *info)
6867{
Johannes Berg4c476992010-10-04 21:36:35 +02006868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006869 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006870 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006871 struct sk_buff *msg;
6872 void *hdr;
6873 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006874 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006875 int err;
6876
6877 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6878 !info->attrs[NL80211_ATTR_DURATION])
6879 return -EINVAL;
6880
6881 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6882
Johannes Berg7c4ef712011-11-18 15:33:48 +01006883 if (!rdev->ops->remain_on_channel ||
6884 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006885 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006886
Johannes Bergebf348f2012-06-01 12:50:54 +02006887 /*
6888 * We should be on that channel for at least a minimum amount of
6889 * time (10ms) but no longer than the driver supports.
6890 */
6891 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6892 duration > rdev->wiphy.max_remain_on_channel_duration)
6893 return -EINVAL;
6894
Johannes Berg683b6d32012-11-08 21:25:48 +01006895 err = nl80211_parse_chandef(rdev, info, &chandef);
6896 if (err)
6897 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006898
6899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006900 if (!msg)
6901 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006902
Eric W. Biederman15e47302012-09-07 20:12:54 +00006903 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006904 NL80211_CMD_REMAIN_ON_CHANNEL);
6905
6906 if (IS_ERR(hdr)) {
6907 err = PTR_ERR(hdr);
6908 goto free_msg;
6909 }
6910
Johannes Berg683b6d32012-11-08 21:25:48 +01006911 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6912 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006913
6914 if (err)
6915 goto free_msg;
6916
David S. Miller9360ffd2012-03-29 04:41:26 -04006917 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6918 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006919
6920 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006921
6922 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006923
6924 nla_put_failure:
6925 err = -ENOBUFS;
6926 free_msg:
6927 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006928 return err;
6929}
6930
6931static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6932 struct genl_info *info)
6933{
Johannes Berg4c476992010-10-04 21:36:35 +02006934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006935 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006936 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006937
6938 if (!info->attrs[NL80211_ATTR_COOKIE])
6939 return -EINVAL;
6940
Johannes Berg4c476992010-10-04 21:36:35 +02006941 if (!rdev->ops->cancel_remain_on_channel)
6942 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006943
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006944 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6945
Hila Gonene35e4d22012-06-27 17:19:42 +03006946 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006947}
6948
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006949static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6950 u8 *rates, u8 rates_len)
6951{
6952 u8 i;
6953 u32 mask = 0;
6954
6955 for (i = 0; i < rates_len; i++) {
6956 int rate = (rates[i] & 0x7f) * 5;
6957 int ridx;
6958 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6959 struct ieee80211_rate *srate =
6960 &sband->bitrates[ridx];
6961 if (rate == srate->bitrate) {
6962 mask |= 1 << ridx;
6963 break;
6964 }
6965 }
6966 if (ridx == sband->n_bitrates)
6967 return 0; /* rate not found */
6968 }
6969
6970 return mask;
6971}
6972
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006973static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6974 u8 *rates, u8 rates_len,
6975 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6976{
6977 u8 i;
6978
6979 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6980
6981 for (i = 0; i < rates_len; i++) {
6982 int ridx, rbit;
6983
6984 ridx = rates[i] / 8;
6985 rbit = BIT(rates[i] % 8);
6986
6987 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006988 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006989 return false;
6990
6991 /* check availability */
6992 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6993 mcs[ridx] |= rbit;
6994 else
6995 return false;
6996 }
6997
6998 return true;
6999}
7000
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007001static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007002 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7003 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007004 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7005 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007006};
7007
7008static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7009 struct genl_info *info)
7010{
7011 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007012 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007013 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007014 int rem, i;
7015 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007016 struct nlattr *tx_rates;
7017 struct ieee80211_supported_band *sband;
7018
7019 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7020 return -EINVAL;
7021
Johannes Berg4c476992010-10-04 21:36:35 +02007022 if (!rdev->ops->set_bitrate_mask)
7023 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007024
7025 memset(&mask, 0, sizeof(mask));
7026 /* Default to all rates enabled */
7027 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7028 sband = rdev->wiphy.bands[i];
7029 mask.control[i].legacy =
7030 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007031 if (sband)
7032 memcpy(mask.control[i].mcs,
7033 sband->ht_cap.mcs.rx_mask,
7034 sizeof(mask.control[i].mcs));
7035 else
7036 memset(mask.control[i].mcs, 0,
7037 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007038 }
7039
7040 /*
7041 * The nested attribute uses enum nl80211_band as the index. This maps
7042 * directly to the enum ieee80211_band values used in cfg80211.
7043 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007044 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007045 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7046 {
7047 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007048 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7049 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007050 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007051 if (sband == NULL)
7052 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007053 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7054 nla_len(tx_rates), nl80211_txattr_policy);
7055 if (tb[NL80211_TXRATE_LEGACY]) {
7056 mask.control[band].legacy = rateset_to_mask(
7057 sband,
7058 nla_data(tb[NL80211_TXRATE_LEGACY]),
7059 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307060 if ((mask.control[band].legacy == 0) &&
7061 nla_len(tb[NL80211_TXRATE_LEGACY]))
7062 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007063 }
7064 if (tb[NL80211_TXRATE_MCS]) {
7065 if (!ht_rateset_to_mask(
7066 sband,
7067 nla_data(tb[NL80211_TXRATE_MCS]),
7068 nla_len(tb[NL80211_TXRATE_MCS]),
7069 mask.control[band].mcs))
7070 return -EINVAL;
7071 }
7072
7073 if (mask.control[band].legacy == 0) {
7074 /* don't allow empty legacy rates if HT
7075 * is not even supported. */
7076 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7077 return -EINVAL;
7078
7079 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7080 if (mask.control[band].mcs[i])
7081 break;
7082
7083 /* legacy and mcs rates may not be both empty */
7084 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007085 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007086 }
7087 }
7088
Hila Gonene35e4d22012-06-27 17:19:42 +03007089 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007090}
7091
Johannes Berg2e161f72010-08-12 15:38:38 +02007092static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007093{
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007095 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007096 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007097
7098 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7099 return -EINVAL;
7100
Johannes Berg2e161f72010-08-12 15:38:38 +02007101 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7102 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007103
Johannes Berg71bbc992012-06-15 15:30:18 +02007104 switch (wdev->iftype) {
7105 case NL80211_IFTYPE_STATION:
7106 case NL80211_IFTYPE_ADHOC:
7107 case NL80211_IFTYPE_P2P_CLIENT:
7108 case NL80211_IFTYPE_AP:
7109 case NL80211_IFTYPE_AP_VLAN:
7110 case NL80211_IFTYPE_MESH_POINT:
7111 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007112 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007113 break;
7114 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007115 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007116 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007117
7118 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007119 if (!rdev->ops->mgmt_tx)
7120 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007121
Eric W. Biederman15e47302012-09-07 20:12:54 +00007122 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007123 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7124 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007125}
7126
Johannes Berg2e161f72010-08-12 15:38:38 +02007127static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007128{
Johannes Berg4c476992010-10-04 21:36:35 +02007129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007130 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007131 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007132 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007133 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007134 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007135 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007136 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007137 bool offchan, no_cck, dont_wait_for_ack;
7138
7139 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007140
Johannes Berg683b6d32012-11-08 21:25:48 +01007141 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007142 return -EINVAL;
7143
Johannes Berg4c476992010-10-04 21:36:35 +02007144 if (!rdev->ops->mgmt_tx)
7145 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007146
Johannes Berg71bbc992012-06-15 15:30:18 +02007147 switch (wdev->iftype) {
7148 case NL80211_IFTYPE_STATION:
7149 case NL80211_IFTYPE_ADHOC:
7150 case NL80211_IFTYPE_P2P_CLIENT:
7151 case NL80211_IFTYPE_AP:
7152 case NL80211_IFTYPE_AP_VLAN:
7153 case NL80211_IFTYPE_MESH_POINT:
7154 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007155 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007156 break;
7157 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007158 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007159 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007160
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007161 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007162 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007163 return -EINVAL;
7164 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007165
7166 /*
7167 * We should wait on the channel for at least a minimum amount
7168 * of time (10ms) but no longer than the driver supports.
7169 */
7170 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7171 wait > rdev->wiphy.max_remain_on_channel_duration)
7172 return -EINVAL;
7173
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007174 }
7175
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007176 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7177
Johannes Berg7c4ef712011-11-18 15:33:48 +01007178 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7179 return -EINVAL;
7180
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307181 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7182
Johannes Berg683b6d32012-11-08 21:25:48 +01007183 err = nl80211_parse_chandef(rdev, info, &chandef);
7184 if (err)
7185 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007186
Johannes Berge247bd902011-11-04 11:18:21 +01007187 if (!dont_wait_for_ack) {
7188 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7189 if (!msg)
7190 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007191
Eric W. Biederman15e47302012-09-07 20:12:54 +00007192 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007193 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007194
Johannes Berge247bd902011-11-04 11:18:21 +01007195 if (IS_ERR(hdr)) {
7196 err = PTR_ERR(hdr);
7197 goto free_msg;
7198 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007199 }
Johannes Berge247bd902011-11-04 11:18:21 +01007200
Johannes Berg683b6d32012-11-08 21:25:48 +01007201 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007202 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7203 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007204 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007205 if (err)
7206 goto free_msg;
7207
Johannes Berge247bd902011-11-04 11:18:21 +01007208 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007209 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7210 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007211
Johannes Berge247bd902011-11-04 11:18:21 +01007212 genlmsg_end(msg, hdr);
7213 return genlmsg_reply(msg, info);
7214 }
7215
7216 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007217
7218 nla_put_failure:
7219 err = -ENOBUFS;
7220 free_msg:
7221 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007222 return err;
7223}
7224
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007225static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7226{
7227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007228 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007229 u64 cookie;
7230
7231 if (!info->attrs[NL80211_ATTR_COOKIE])
7232 return -EINVAL;
7233
7234 if (!rdev->ops->mgmt_tx_cancel_wait)
7235 return -EOPNOTSUPP;
7236
Johannes Berg71bbc992012-06-15 15:30:18 +02007237 switch (wdev->iftype) {
7238 case NL80211_IFTYPE_STATION:
7239 case NL80211_IFTYPE_ADHOC:
7240 case NL80211_IFTYPE_P2P_CLIENT:
7241 case NL80211_IFTYPE_AP:
7242 case NL80211_IFTYPE_AP_VLAN:
7243 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007244 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007245 break;
7246 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007247 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007248 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007249
7250 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7251
Hila Gonene35e4d22012-06-27 17:19:42 +03007252 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007253}
7254
Kalle Valoffb9eb32010-02-17 17:58:10 +02007255static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7256{
Johannes Berg4c476992010-10-04 21:36:35 +02007257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007258 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007259 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007260 u8 ps_state;
7261 bool state;
7262 int err;
7263
Johannes Berg4c476992010-10-04 21:36:35 +02007264 if (!info->attrs[NL80211_ATTR_PS_STATE])
7265 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007266
7267 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7268
Johannes Berg4c476992010-10-04 21:36:35 +02007269 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7270 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007271
7272 wdev = dev->ieee80211_ptr;
7273
Johannes Berg4c476992010-10-04 21:36:35 +02007274 if (!rdev->ops->set_power_mgmt)
7275 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007276
7277 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7278
7279 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007280 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007281
Hila Gonene35e4d22012-06-27 17:19:42 +03007282 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007283 if (!err)
7284 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007285 return err;
7286}
7287
7288static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7289{
Johannes Berg4c476992010-10-04 21:36:35 +02007290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007291 enum nl80211_ps_state ps_state;
7292 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007293 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007294 struct sk_buff *msg;
7295 void *hdr;
7296 int err;
7297
Kalle Valoffb9eb32010-02-17 17:58:10 +02007298 wdev = dev->ieee80211_ptr;
7299
Johannes Berg4c476992010-10-04 21:36:35 +02007300 if (!rdev->ops->set_power_mgmt)
7301 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007302
7303 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007304 if (!msg)
7305 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007306
Eric W. Biederman15e47302012-09-07 20:12:54 +00007307 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007308 NL80211_CMD_GET_POWER_SAVE);
7309 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007310 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007311 goto free_msg;
7312 }
7313
7314 if (wdev->ps)
7315 ps_state = NL80211_PS_ENABLED;
7316 else
7317 ps_state = NL80211_PS_DISABLED;
7318
David S. Miller9360ffd2012-03-29 04:41:26 -04007319 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7320 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007321
7322 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007323 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007324
Johannes Berg4c476992010-10-04 21:36:35 +02007325 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007326 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007327 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007328 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007329 return err;
7330}
7331
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007332static struct nla_policy
7333nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7334 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7335 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7336 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007337 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7338 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7339 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007340};
7341
Thomas Pedersen84f10702012-07-12 16:17:33 -07007342static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007343 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007344{
7345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7346 struct wireless_dev *wdev;
7347 struct net_device *dev = info->user_ptr[1];
7348
Johannes Bergd9d8b012012-11-26 12:51:52 +01007349 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007350 return -EINVAL;
7351
7352 wdev = dev->ieee80211_ptr;
7353
7354 if (!rdev->ops->set_cqm_txe_config)
7355 return -EOPNOTSUPP;
7356
7357 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7358 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7359 return -EOPNOTSUPP;
7360
Hila Gonene35e4d22012-06-27 17:19:42 +03007361 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007362}
7363
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007364static int nl80211_set_cqm_rssi(struct genl_info *info,
7365 s32 threshold, u32 hysteresis)
7366{
Johannes Berg4c476992010-10-04 21:36:35 +02007367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007368 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007369 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007370
7371 if (threshold > 0)
7372 return -EINVAL;
7373
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007374 wdev = dev->ieee80211_ptr;
7375
Johannes Berg4c476992010-10-04 21:36:35 +02007376 if (!rdev->ops->set_cqm_rssi_config)
7377 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007378
Johannes Berg074ac8d2010-09-16 14:58:22 +02007379 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007380 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7381 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007382
Hila Gonene35e4d22012-06-27 17:19:42 +03007383 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007384}
7385
7386static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7387{
7388 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7389 struct nlattr *cqm;
7390 int err;
7391
7392 cqm = info->attrs[NL80211_ATTR_CQM];
7393 if (!cqm) {
7394 err = -EINVAL;
7395 goto out;
7396 }
7397
7398 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7399 nl80211_attr_cqm_policy);
7400 if (err)
7401 goto out;
7402
7403 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7404 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7405 s32 threshold;
7406 u32 hysteresis;
7407 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7408 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7409 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007410 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7411 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7412 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7413 u32 rate, pkts, intvl;
7414 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7415 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7416 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7417 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007418 } else
7419 err = -EINVAL;
7420
7421out:
7422 return err;
7423}
7424
Johannes Berg29cbe682010-12-03 09:20:44 +01007425static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7426{
7427 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7428 struct net_device *dev = info->user_ptr[1];
7429 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007430 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007431 int err;
7432
7433 /* start with default */
7434 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007435 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007436
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007437 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007438 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007439 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007440 if (err)
7441 return err;
7442 }
7443
7444 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7445 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7446 return -EINVAL;
7447
Javier Cardonac80d5452010-12-16 17:37:49 -08007448 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7449 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7450
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007451 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7452 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7453 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7454 return -EINVAL;
7455
Marco Porsch9bdbf042013-01-07 16:04:51 +01007456 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7457 setup.beacon_interval =
7458 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7459 if (setup.beacon_interval < 10 ||
7460 setup.beacon_interval > 10000)
7461 return -EINVAL;
7462 }
7463
7464 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7465 setup.dtim_period =
7466 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7467 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7468 return -EINVAL;
7469 }
7470
Javier Cardonac80d5452010-12-16 17:37:49 -08007471 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7472 /* parse additional setup parameters if given */
7473 err = nl80211_parse_mesh_setup(info, &setup);
7474 if (err)
7475 return err;
7476 }
7477
Thomas Pedersend37bb182013-03-04 13:06:13 -08007478 if (setup.user_mpm)
7479 cfg.auto_open_plinks = false;
7480
Johannes Bergcc1d2802012-05-16 23:50:20 +02007481 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007482 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7483 if (err)
7484 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007485 } else {
7486 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007487 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007488 }
7489
Javier Cardonac80d5452010-12-16 17:37:49 -08007490 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007491}
7492
7493static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7494{
7495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7496 struct net_device *dev = info->user_ptr[1];
7497
7498 return cfg80211_leave_mesh(rdev, dev);
7499}
7500
Johannes Bergdfb89c52012-06-27 09:23:48 +02007501#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007502static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7503 struct cfg80211_registered_device *rdev)
7504{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007505 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007506 struct nlattr *nl_pats, *nl_pat;
7507 int i, pat_len;
7508
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007509 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007510 return 0;
7511
7512 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7513 if (!nl_pats)
7514 return -ENOBUFS;
7515
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007516 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007517 nl_pat = nla_nest_start(msg, i + 1);
7518 if (!nl_pat)
7519 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007520 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007521 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7522 DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007523 wowlan->patterns[i].mask) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007524 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007525 pat_len, wowlan->patterns[i].pattern) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007526 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007527 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007528 return -ENOBUFS;
7529 nla_nest_end(msg, nl_pat);
7530 }
7531 nla_nest_end(msg, nl_pats);
7532
7533 return 0;
7534}
7535
Johannes Berg2a0e0472013-01-23 22:57:40 +01007536static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7537 struct cfg80211_wowlan_tcp *tcp)
7538{
7539 struct nlattr *nl_tcp;
7540
7541 if (!tcp)
7542 return 0;
7543
7544 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7545 if (!nl_tcp)
7546 return -ENOBUFS;
7547
7548 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7549 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7550 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7551 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7552 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7553 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7554 tcp->payload_len, tcp->payload) ||
7555 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7556 tcp->data_interval) ||
7557 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7558 tcp->wake_len, tcp->wake_data) ||
7559 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7560 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7561 return -ENOBUFS;
7562
7563 if (tcp->payload_seq.len &&
7564 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7565 sizeof(tcp->payload_seq), &tcp->payload_seq))
7566 return -ENOBUFS;
7567
7568 if (tcp->payload_tok.len &&
7569 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7570 sizeof(tcp->payload_tok) + tcp->tokens_size,
7571 &tcp->payload_tok))
7572 return -ENOBUFS;
7573
Johannes Berge248ad32013-05-16 10:24:28 +02007574 nla_nest_end(msg, nl_tcp);
7575
Johannes Berg2a0e0472013-01-23 22:57:40 +01007576 return 0;
7577}
7578
Johannes Bergff1b6e62011-05-04 15:37:28 +02007579static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7580{
7581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7582 struct sk_buff *msg;
7583 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007584 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007585
Johannes Berg964dc9e2013-06-03 17:25:34 +02007586 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007587 return -EOPNOTSUPP;
7588
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007589 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007590 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007591 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7592 rdev->wiphy.wowlan_config->tcp->payload_len +
7593 rdev->wiphy.wowlan_config->tcp->wake_len +
7594 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007595 }
7596
7597 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007598 if (!msg)
7599 return -ENOMEM;
7600
Eric W. Biederman15e47302012-09-07 20:12:54 +00007601 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007602 NL80211_CMD_GET_WOWLAN);
7603 if (!hdr)
7604 goto nla_put_failure;
7605
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007606 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007607 struct nlattr *nl_wowlan;
7608
7609 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7610 if (!nl_wowlan)
7611 goto nla_put_failure;
7612
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007613 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007614 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007615 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007616 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007617 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007618 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007619 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007620 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007621 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007622 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007623 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007624 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007625 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007626 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7627 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007628
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007629 if (nl80211_send_wowlan_patterns(msg, rdev))
7630 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007631
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007632 if (nl80211_send_wowlan_tcp(msg,
7633 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007634 goto nla_put_failure;
7635
Johannes Bergff1b6e62011-05-04 15:37:28 +02007636 nla_nest_end(msg, nl_wowlan);
7637 }
7638
7639 genlmsg_end(msg, hdr);
7640 return genlmsg_reply(msg, info);
7641
7642nla_put_failure:
7643 nlmsg_free(msg);
7644 return -ENOBUFS;
7645}
7646
Johannes Berg2a0e0472013-01-23 22:57:40 +01007647static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7648 struct nlattr *attr,
7649 struct cfg80211_wowlan *trig)
7650{
7651 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7652 struct cfg80211_wowlan_tcp *cfg;
7653 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7654 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7655 u32 size;
7656 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7657 int err, port;
7658
Johannes Berg964dc9e2013-06-03 17:25:34 +02007659 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007660 return -EINVAL;
7661
7662 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7663 nla_data(attr), nla_len(attr),
7664 nl80211_wowlan_tcp_policy);
7665 if (err)
7666 return err;
7667
7668 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7669 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7670 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7671 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7672 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7673 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7674 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7675 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7676 return -EINVAL;
7677
7678 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007679 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007680 return -EINVAL;
7681
7682 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007683 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007684 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007685 return -EINVAL;
7686
7687 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007688 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007689 return -EINVAL;
7690
7691 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7692 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7693 return -EINVAL;
7694
7695 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7696 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7697
7698 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7699 tokens_size = tokln - sizeof(*tok);
7700
7701 if (!tok->len || tokens_size % tok->len)
7702 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007703 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007704 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007705 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007706 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007707 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007708 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007709 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007710 return -EINVAL;
7711 if (tok->offset + tok->len > data_size)
7712 return -EINVAL;
7713 }
7714
7715 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7716 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007717 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007718 return -EINVAL;
7719 if (seq->len == 0 || seq->len > 4)
7720 return -EINVAL;
7721 if (seq->len + seq->offset > data_size)
7722 return -EINVAL;
7723 }
7724
7725 size = sizeof(*cfg);
7726 size += data_size;
7727 size += wake_size + wake_mask_size;
7728 size += tokens_size;
7729
7730 cfg = kzalloc(size, GFP_KERNEL);
7731 if (!cfg)
7732 return -ENOMEM;
7733 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7734 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7735 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7736 ETH_ALEN);
7737 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7738 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7739 else
7740 port = 0;
7741#ifdef CONFIG_INET
7742 /* allocate a socket and port for it and use it */
7743 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7744 IPPROTO_TCP, &cfg->sock, 1);
7745 if (err) {
7746 kfree(cfg);
7747 return err;
7748 }
7749 if (inet_csk_get_port(cfg->sock->sk, port)) {
7750 sock_release(cfg->sock);
7751 kfree(cfg);
7752 return -EADDRINUSE;
7753 }
7754 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7755#else
7756 if (!port) {
7757 kfree(cfg);
7758 return -EINVAL;
7759 }
7760 cfg->src_port = port;
7761#endif
7762
7763 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7764 cfg->payload_len = data_size;
7765 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7766 memcpy((void *)cfg->payload,
7767 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7768 data_size);
7769 if (seq)
7770 cfg->payload_seq = *seq;
7771 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7772 cfg->wake_len = wake_size;
7773 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7774 memcpy((void *)cfg->wake_data,
7775 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7776 wake_size);
7777 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7778 data_size + wake_size;
7779 memcpy((void *)cfg->wake_mask,
7780 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7781 wake_mask_size);
7782 if (tok) {
7783 cfg->tokens_size = tokens_size;
7784 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7785 }
7786
7787 trig->tcp = cfg;
7788
7789 return 0;
7790}
7791
Johannes Bergff1b6e62011-05-04 15:37:28 +02007792static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7793{
7794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7795 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007796 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007797 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007798 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007799 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007800 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007801
Johannes Berg964dc9e2013-06-03 17:25:34 +02007802 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007803 return -EOPNOTSUPP;
7804
Johannes Bergae33bd82012-07-12 16:25:02 +02007805 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7806 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007807 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007808 goto set_wakeup;
7809 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007810
7811 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7812 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7813 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7814 nl80211_wowlan_policy);
7815 if (err)
7816 return err;
7817
7818 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7819 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7820 return -EINVAL;
7821 new_triggers.any = true;
7822 }
7823
7824 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7825 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7826 return -EINVAL;
7827 new_triggers.disconnect = true;
7828 }
7829
7830 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7831 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7832 return -EINVAL;
7833 new_triggers.magic_pkt = true;
7834 }
7835
Johannes Berg77dbbb12011-07-13 10:48:55 +02007836 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7837 return -EINVAL;
7838
7839 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7840 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7841 return -EINVAL;
7842 new_triggers.gtk_rekey_failure = true;
7843 }
7844
7845 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7846 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7847 return -EINVAL;
7848 new_triggers.eap_identity_req = true;
7849 }
7850
7851 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7852 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7853 return -EINVAL;
7854 new_triggers.four_way_handshake = true;
7855 }
7856
7857 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7858 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7859 return -EINVAL;
7860 new_triggers.rfkill_release = true;
7861 }
7862
Johannes Bergff1b6e62011-05-04 15:37:28 +02007863 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7864 struct nlattr *pat;
7865 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007866 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007867 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7868
7869 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7870 rem)
7871 n_patterns++;
7872 if (n_patterns > wowlan->n_patterns)
7873 return -EINVAL;
7874
7875 new_triggers.patterns = kcalloc(n_patterns,
7876 sizeof(new_triggers.patterns[0]),
7877 GFP_KERNEL);
7878 if (!new_triggers.patterns)
7879 return -ENOMEM;
7880
7881 new_triggers.n_patterns = n_patterns;
7882 i = 0;
7883
7884 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7885 rem) {
7886 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7887 nla_data(pat), nla_len(pat), NULL);
7888 err = -EINVAL;
7889 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7890 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7891 goto error;
7892 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7893 mask_len = DIV_ROUND_UP(pat_len, 8);
7894 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7895 mask_len)
7896 goto error;
7897 if (pat_len > wowlan->pattern_max_len ||
7898 pat_len < wowlan->pattern_min_len)
7899 goto error;
7900
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007901 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7902 pkt_offset = 0;
7903 else
7904 pkt_offset = nla_get_u32(
7905 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7906 if (pkt_offset > wowlan->max_pkt_offset)
7907 goto error;
7908 new_triggers.patterns[i].pkt_offset = pkt_offset;
7909
Johannes Bergff1b6e62011-05-04 15:37:28 +02007910 new_triggers.patterns[i].mask =
7911 kmalloc(mask_len + pat_len, GFP_KERNEL);
7912 if (!new_triggers.patterns[i].mask) {
7913 err = -ENOMEM;
7914 goto error;
7915 }
7916 new_triggers.patterns[i].pattern =
7917 new_triggers.patterns[i].mask + mask_len;
7918 memcpy(new_triggers.patterns[i].mask,
7919 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7920 mask_len);
7921 new_triggers.patterns[i].pattern_len = pat_len;
7922 memcpy(new_triggers.patterns[i].pattern,
7923 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7924 pat_len);
7925 i++;
7926 }
7927 }
7928
Johannes Berg2a0e0472013-01-23 22:57:40 +01007929 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7930 err = nl80211_parse_wowlan_tcp(
7931 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7932 &new_triggers);
7933 if (err)
7934 goto error;
7935 }
7936
Johannes Bergae33bd82012-07-12 16:25:02 +02007937 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7938 if (!ntrig) {
7939 err = -ENOMEM;
7940 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007941 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007942 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007943 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007944
Johannes Bergae33bd82012-07-12 16:25:02 +02007945 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007946 if (rdev->ops->set_wakeup &&
7947 prev_enabled != !!rdev->wiphy.wowlan_config)
7948 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02007949
Johannes Bergff1b6e62011-05-04 15:37:28 +02007950 return 0;
7951 error:
7952 for (i = 0; i < new_triggers.n_patterns; i++)
7953 kfree(new_triggers.patterns[i].mask);
7954 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007955 if (new_triggers.tcp && new_triggers.tcp->sock)
7956 sock_release(new_triggers.tcp->sock);
7957 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007958 return err;
7959}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007960#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007961
Johannes Berge5497d72011-07-05 16:35:40 +02007962static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7963{
7964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7965 struct net_device *dev = info->user_ptr[1];
7966 struct wireless_dev *wdev = dev->ieee80211_ptr;
7967 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7968 struct cfg80211_gtk_rekey_data rekey_data;
7969 int err;
7970
7971 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7972 return -EINVAL;
7973
7974 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7975 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7976 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7977 nl80211_rekey_policy);
7978 if (err)
7979 return err;
7980
7981 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7982 return -ERANGE;
7983 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7984 return -ERANGE;
7985 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7986 return -ERANGE;
7987
7988 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7989 NL80211_KEK_LEN);
7990 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7991 NL80211_KCK_LEN);
7992 memcpy(rekey_data.replay_ctr,
7993 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7994 NL80211_REPLAY_CTR_LEN);
7995
7996 wdev_lock(wdev);
7997 if (!wdev->current_bss) {
7998 err = -ENOTCONN;
7999 goto out;
8000 }
8001
8002 if (!rdev->ops->set_rekey_data) {
8003 err = -EOPNOTSUPP;
8004 goto out;
8005 }
8006
Hila Gonene35e4d22012-06-27 17:19:42 +03008007 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008008 out:
8009 wdev_unlock(wdev);
8010 return err;
8011}
8012
Johannes Berg28946da2011-11-04 11:18:12 +01008013static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8014 struct genl_info *info)
8015{
8016 struct net_device *dev = info->user_ptr[1];
8017 struct wireless_dev *wdev = dev->ieee80211_ptr;
8018
8019 if (wdev->iftype != NL80211_IFTYPE_AP &&
8020 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8021 return -EINVAL;
8022
Eric W. Biederman15e47302012-09-07 20:12:54 +00008023 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008024 return -EBUSY;
8025
Eric W. Biederman15e47302012-09-07 20:12:54 +00008026 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008027 return 0;
8028}
8029
Johannes Berg7f6cf312011-11-04 11:18:15 +01008030static int nl80211_probe_client(struct sk_buff *skb,
8031 struct genl_info *info)
8032{
8033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8034 struct net_device *dev = info->user_ptr[1];
8035 struct wireless_dev *wdev = dev->ieee80211_ptr;
8036 struct sk_buff *msg;
8037 void *hdr;
8038 const u8 *addr;
8039 u64 cookie;
8040 int err;
8041
8042 if (wdev->iftype != NL80211_IFTYPE_AP &&
8043 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8044 return -EOPNOTSUPP;
8045
8046 if (!info->attrs[NL80211_ATTR_MAC])
8047 return -EINVAL;
8048
8049 if (!rdev->ops->probe_client)
8050 return -EOPNOTSUPP;
8051
8052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8053 if (!msg)
8054 return -ENOMEM;
8055
Eric W. Biederman15e47302012-09-07 20:12:54 +00008056 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008057 NL80211_CMD_PROBE_CLIENT);
8058
8059 if (IS_ERR(hdr)) {
8060 err = PTR_ERR(hdr);
8061 goto free_msg;
8062 }
8063
8064 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8065
Hila Gonene35e4d22012-06-27 17:19:42 +03008066 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008067 if (err)
8068 goto free_msg;
8069
David S. Miller9360ffd2012-03-29 04:41:26 -04008070 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8071 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008072
8073 genlmsg_end(msg, hdr);
8074
8075 return genlmsg_reply(msg, info);
8076
8077 nla_put_failure:
8078 err = -ENOBUFS;
8079 free_msg:
8080 nlmsg_free(msg);
8081 return err;
8082}
8083
Johannes Berg5e760232011-11-04 11:18:17 +01008084static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8085{
8086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008087 struct cfg80211_beacon_registration *reg, *nreg;
8088 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008089
8090 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8091 return -EOPNOTSUPP;
8092
Ben Greear37c73b52012-10-26 14:49:25 -07008093 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8094 if (!nreg)
8095 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008096
Ben Greear37c73b52012-10-26 14:49:25 -07008097 /* First, check if already registered. */
8098 spin_lock_bh(&rdev->beacon_registrations_lock);
8099 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8100 if (reg->nlportid == info->snd_portid) {
8101 rv = -EALREADY;
8102 goto out_err;
8103 }
8104 }
8105 /* Add it to the list */
8106 nreg->nlportid = info->snd_portid;
8107 list_add(&nreg->list, &rdev->beacon_registrations);
8108
8109 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008110
8111 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008112out_err:
8113 spin_unlock_bh(&rdev->beacon_registrations_lock);
8114 kfree(nreg);
8115 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008116}
8117
Johannes Berg98104fde2012-06-16 00:19:54 +02008118static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8119{
8120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8121 struct wireless_dev *wdev = info->user_ptr[1];
8122 int err;
8123
8124 if (!rdev->ops->start_p2p_device)
8125 return -EOPNOTSUPP;
8126
8127 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8128 return -EOPNOTSUPP;
8129
8130 if (wdev->p2p_started)
8131 return 0;
8132
Johannes Berg98104fde2012-06-16 00:19:54 +02008133 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008134 if (err)
8135 return err;
8136
Johannes Bergeeb126e2012-10-23 15:16:50 +02008137 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008138 if (err)
8139 return err;
8140
8141 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008142 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008143
8144 return 0;
8145}
8146
8147static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8148{
8149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8150 struct wireless_dev *wdev = info->user_ptr[1];
8151
8152 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8153 return -EOPNOTSUPP;
8154
8155 if (!rdev->ops->stop_p2p_device)
8156 return -EOPNOTSUPP;
8157
Johannes Bergf9f47522013-03-19 15:04:07 +01008158 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008159
8160 return 0;
8161}
8162
Johannes Berg3713b4e2013-02-14 16:19:38 +01008163static int nl80211_get_protocol_features(struct sk_buff *skb,
8164 struct genl_info *info)
8165{
8166 void *hdr;
8167 struct sk_buff *msg;
8168
8169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8170 if (!msg)
8171 return -ENOMEM;
8172
8173 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8174 NL80211_CMD_GET_PROTOCOL_FEATURES);
8175 if (!hdr)
8176 goto nla_put_failure;
8177
8178 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8179 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8180 goto nla_put_failure;
8181
8182 genlmsg_end(msg, hdr);
8183 return genlmsg_reply(msg, info);
8184
8185 nla_put_failure:
8186 kfree_skb(msg);
8187 return -ENOBUFS;
8188}
8189
Jouni Malinen355199e2013-02-27 17:14:27 +02008190static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8191{
8192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8193 struct cfg80211_update_ft_ies_params ft_params;
8194 struct net_device *dev = info->user_ptr[1];
8195
8196 if (!rdev->ops->update_ft_ies)
8197 return -EOPNOTSUPP;
8198
8199 if (!info->attrs[NL80211_ATTR_MDID] ||
8200 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8201 return -EINVAL;
8202
8203 memset(&ft_params, 0, sizeof(ft_params));
8204 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8205 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8206 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8207
8208 return rdev_update_ft_ies(rdev, dev, &ft_params);
8209}
8210
Arend van Spriel5de17982013-04-18 15:49:00 +02008211static int nl80211_crit_protocol_start(struct sk_buff *skb,
8212 struct genl_info *info)
8213{
8214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8215 struct wireless_dev *wdev = info->user_ptr[1];
8216 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8217 u16 duration;
8218 int ret;
8219
8220 if (!rdev->ops->crit_proto_start)
8221 return -EOPNOTSUPP;
8222
8223 if (WARN_ON(!rdev->ops->crit_proto_stop))
8224 return -EINVAL;
8225
8226 if (rdev->crit_proto_nlportid)
8227 return -EBUSY;
8228
8229 /* determine protocol if provided */
8230 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8231 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8232
8233 if (proto >= NUM_NL80211_CRIT_PROTO)
8234 return -EINVAL;
8235
8236 /* timeout must be provided */
8237 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8238 return -EINVAL;
8239
8240 duration =
8241 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8242
8243 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8244 return -ERANGE;
8245
8246 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8247 if (!ret)
8248 rdev->crit_proto_nlportid = info->snd_portid;
8249
8250 return ret;
8251}
8252
8253static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8254 struct genl_info *info)
8255{
8256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8257 struct wireless_dev *wdev = info->user_ptr[1];
8258
8259 if (!rdev->ops->crit_proto_stop)
8260 return -EOPNOTSUPP;
8261
8262 if (rdev->crit_proto_nlportid) {
8263 rdev->crit_proto_nlportid = 0;
8264 rdev_crit_proto_stop(rdev, wdev);
8265 }
8266 return 0;
8267}
8268
Johannes Berg4c476992010-10-04 21:36:35 +02008269#define NL80211_FLAG_NEED_WIPHY 0x01
8270#define NL80211_FLAG_NEED_NETDEV 0x02
8271#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008272#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8273#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8274 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008275#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008276/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008277#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8278 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008279
8280static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8281 struct genl_info *info)
8282{
8283 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008284 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008285 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008286 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8287
8288 if (rtnl)
8289 rtnl_lock();
8290
8291 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008292 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008293 if (IS_ERR(rdev)) {
8294 if (rtnl)
8295 rtnl_unlock();
8296 return PTR_ERR(rdev);
8297 }
8298 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008299 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8300 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008301 ASSERT_RTNL();
8302
Johannes Berg89a54e42012-06-15 14:33:17 +02008303 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8304 info->attrs);
8305 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008306 if (rtnl)
8307 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008308 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008309 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008310
Johannes Berg89a54e42012-06-15 14:33:17 +02008311 dev = wdev->netdev;
8312 rdev = wiphy_to_dev(wdev->wiphy);
8313
Johannes Berg1bf614e2012-06-15 15:23:36 +02008314 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8315 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008316 if (rtnl)
8317 rtnl_unlock();
8318 return -EINVAL;
8319 }
8320
8321 info->user_ptr[1] = dev;
8322 } else {
8323 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008324 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008325
Johannes Berg1bf614e2012-06-15 15:23:36 +02008326 if (dev) {
8327 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8328 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008329 if (rtnl)
8330 rtnl_unlock();
8331 return -ENETDOWN;
8332 }
8333
8334 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008335 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8336 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008337 if (rtnl)
8338 rtnl_unlock();
8339 return -ENETDOWN;
8340 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008341 }
8342
Johannes Berg4c476992010-10-04 21:36:35 +02008343 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008344 }
8345
8346 return 0;
8347}
8348
8349static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8350 struct genl_info *info)
8351{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008352 if (info->user_ptr[1]) {
8353 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8354 struct wireless_dev *wdev = info->user_ptr[1];
8355
8356 if (wdev->netdev)
8357 dev_put(wdev->netdev);
8358 } else {
8359 dev_put(info->user_ptr[1]);
8360 }
8361 }
Johannes Berg4c476992010-10-04 21:36:35 +02008362 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8363 rtnl_unlock();
8364}
8365
Johannes Berg55682962007-09-20 13:09:35 -04008366static struct genl_ops nl80211_ops[] = {
8367 {
8368 .cmd = NL80211_CMD_GET_WIPHY,
8369 .doit = nl80211_get_wiphy,
8370 .dumpit = nl80211_dump_wiphy,
8371 .policy = nl80211_policy,
8372 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008373 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8374 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008375 },
8376 {
8377 .cmd = NL80211_CMD_SET_WIPHY,
8378 .doit = nl80211_set_wiphy,
8379 .policy = nl80211_policy,
8380 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008381 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008382 },
8383 {
8384 .cmd = NL80211_CMD_GET_INTERFACE,
8385 .doit = nl80211_get_interface,
8386 .dumpit = nl80211_dump_interface,
8387 .policy = nl80211_policy,
8388 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008389 .internal_flags = NL80211_FLAG_NEED_WDEV |
8390 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008391 },
8392 {
8393 .cmd = NL80211_CMD_SET_INTERFACE,
8394 .doit = nl80211_set_interface,
8395 .policy = nl80211_policy,
8396 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008397 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8398 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008399 },
8400 {
8401 .cmd = NL80211_CMD_NEW_INTERFACE,
8402 .doit = nl80211_new_interface,
8403 .policy = nl80211_policy,
8404 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008405 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8406 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008407 },
8408 {
8409 .cmd = NL80211_CMD_DEL_INTERFACE,
8410 .doit = nl80211_del_interface,
8411 .policy = nl80211_policy,
8412 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008413 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008414 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008415 },
Johannes Berg41ade002007-12-19 02:03:29 +01008416 {
8417 .cmd = NL80211_CMD_GET_KEY,
8418 .doit = nl80211_get_key,
8419 .policy = nl80211_policy,
8420 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008422 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008423 },
8424 {
8425 .cmd = NL80211_CMD_SET_KEY,
8426 .doit = nl80211_set_key,
8427 .policy = nl80211_policy,
8428 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008429 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008430 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008431 },
8432 {
8433 .cmd = NL80211_CMD_NEW_KEY,
8434 .doit = nl80211_new_key,
8435 .policy = nl80211_policy,
8436 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008438 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008439 },
8440 {
8441 .cmd = NL80211_CMD_DEL_KEY,
8442 .doit = nl80211_del_key,
8443 .policy = nl80211_policy,
8444 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008446 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008447 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008448 {
8449 .cmd = NL80211_CMD_SET_BEACON,
8450 .policy = nl80211_policy,
8451 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008452 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008454 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008455 },
8456 {
Johannes Berg88600202012-02-13 15:17:18 +01008457 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008458 .policy = nl80211_policy,
8459 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008460 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008461 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008462 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008463 },
8464 {
Johannes Berg88600202012-02-13 15:17:18 +01008465 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008466 .policy = nl80211_policy,
8467 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008468 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008470 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008471 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008472 {
8473 .cmd = NL80211_CMD_GET_STATION,
8474 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008475 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008476 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008477 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8478 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008479 },
8480 {
8481 .cmd = NL80211_CMD_SET_STATION,
8482 .doit = nl80211_set_station,
8483 .policy = nl80211_policy,
8484 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008485 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008486 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008487 },
8488 {
8489 .cmd = NL80211_CMD_NEW_STATION,
8490 .doit = nl80211_new_station,
8491 .policy = nl80211_policy,
8492 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008494 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008495 },
8496 {
8497 .cmd = NL80211_CMD_DEL_STATION,
8498 .doit = nl80211_del_station,
8499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008502 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008503 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008504 {
8505 .cmd = NL80211_CMD_GET_MPATH,
8506 .doit = nl80211_get_mpath,
8507 .dumpit = nl80211_dump_mpath,
8508 .policy = nl80211_policy,
8509 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008510 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008511 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008512 },
8513 {
8514 .cmd = NL80211_CMD_SET_MPATH,
8515 .doit = nl80211_set_mpath,
8516 .policy = nl80211_policy,
8517 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008518 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008519 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008520 },
8521 {
8522 .cmd = NL80211_CMD_NEW_MPATH,
8523 .doit = nl80211_new_mpath,
8524 .policy = nl80211_policy,
8525 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008526 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008527 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008528 },
8529 {
8530 .cmd = NL80211_CMD_DEL_MPATH,
8531 .doit = nl80211_del_mpath,
8532 .policy = nl80211_policy,
8533 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008534 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008535 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008536 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008537 {
8538 .cmd = NL80211_CMD_SET_BSS,
8539 .doit = nl80211_set_bss,
8540 .policy = nl80211_policy,
8541 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008542 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008543 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008544 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008545 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008546 .cmd = NL80211_CMD_GET_REG,
8547 .doit = nl80211_get_reg,
8548 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008549 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008550 /* can be retrieved by unprivileged users */
8551 },
8552 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008553 .cmd = NL80211_CMD_SET_REG,
8554 .doit = nl80211_set_reg,
8555 .policy = nl80211_policy,
8556 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008557 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008558 },
8559 {
8560 .cmd = NL80211_CMD_REQ_SET_REG,
8561 .doit = nl80211_req_set_reg,
8562 .policy = nl80211_policy,
8563 .flags = GENL_ADMIN_PERM,
8564 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008565 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008566 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8567 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008568 .policy = nl80211_policy,
8569 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008570 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008571 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008572 },
8573 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008574 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8575 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008576 .policy = nl80211_policy,
8577 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008579 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008580 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008581 {
Johannes Berg2a519312009-02-10 21:25:55 +01008582 .cmd = NL80211_CMD_TRIGGER_SCAN,
8583 .doit = nl80211_trigger_scan,
8584 .policy = nl80211_policy,
8585 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008586 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008587 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008588 },
8589 {
8590 .cmd = NL80211_CMD_GET_SCAN,
8591 .policy = nl80211_policy,
8592 .dumpit = nl80211_dump_scan,
8593 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008594 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008595 .cmd = NL80211_CMD_START_SCHED_SCAN,
8596 .doit = nl80211_start_sched_scan,
8597 .policy = nl80211_policy,
8598 .flags = GENL_ADMIN_PERM,
8599 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8600 NL80211_FLAG_NEED_RTNL,
8601 },
8602 {
8603 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8604 .doit = nl80211_stop_sched_scan,
8605 .policy = nl80211_policy,
8606 .flags = GENL_ADMIN_PERM,
8607 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8608 NL80211_FLAG_NEED_RTNL,
8609 },
8610 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008611 .cmd = NL80211_CMD_AUTHENTICATE,
8612 .doit = nl80211_authenticate,
8613 .policy = nl80211_policy,
8614 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008615 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008616 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008617 },
8618 {
8619 .cmd = NL80211_CMD_ASSOCIATE,
8620 .doit = nl80211_associate,
8621 .policy = nl80211_policy,
8622 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008623 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008624 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008625 },
8626 {
8627 .cmd = NL80211_CMD_DEAUTHENTICATE,
8628 .doit = nl80211_deauthenticate,
8629 .policy = nl80211_policy,
8630 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008631 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008632 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008633 },
8634 {
8635 .cmd = NL80211_CMD_DISASSOCIATE,
8636 .doit = nl80211_disassociate,
8637 .policy = nl80211_policy,
8638 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008640 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008641 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008642 {
8643 .cmd = NL80211_CMD_JOIN_IBSS,
8644 .doit = nl80211_join_ibss,
8645 .policy = nl80211_policy,
8646 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008648 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008649 },
8650 {
8651 .cmd = NL80211_CMD_LEAVE_IBSS,
8652 .doit = nl80211_leave_ibss,
8653 .policy = nl80211_policy,
8654 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008656 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008657 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008658#ifdef CONFIG_NL80211_TESTMODE
8659 {
8660 .cmd = NL80211_CMD_TESTMODE,
8661 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008662 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008663 .policy = nl80211_policy,
8664 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008665 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8666 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008667 },
8668#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008669 {
8670 .cmd = NL80211_CMD_CONNECT,
8671 .doit = nl80211_connect,
8672 .policy = nl80211_policy,
8673 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008674 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008675 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008676 },
8677 {
8678 .cmd = NL80211_CMD_DISCONNECT,
8679 .doit = nl80211_disconnect,
8680 .policy = nl80211_policy,
8681 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008682 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008683 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008684 },
Johannes Berg463d0182009-07-14 00:33:35 +02008685 {
8686 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8687 .doit = nl80211_wiphy_netns,
8688 .policy = nl80211_policy,
8689 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008690 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8691 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008692 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008693 {
8694 .cmd = NL80211_CMD_GET_SURVEY,
8695 .policy = nl80211_policy,
8696 .dumpit = nl80211_dump_survey,
8697 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008698 {
8699 .cmd = NL80211_CMD_SET_PMKSA,
8700 .doit = nl80211_setdel_pmksa,
8701 .policy = nl80211_policy,
8702 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008703 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008704 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008705 },
8706 {
8707 .cmd = NL80211_CMD_DEL_PMKSA,
8708 .doit = nl80211_setdel_pmksa,
8709 .policy = nl80211_policy,
8710 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008712 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008713 },
8714 {
8715 .cmd = NL80211_CMD_FLUSH_PMKSA,
8716 .doit = nl80211_flush_pmksa,
8717 .policy = nl80211_policy,
8718 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008720 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008721 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008722 {
8723 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8724 .doit = nl80211_remain_on_channel,
8725 .policy = nl80211_policy,
8726 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008727 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008728 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008729 },
8730 {
8731 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8732 .doit = nl80211_cancel_remain_on_channel,
8733 .policy = nl80211_policy,
8734 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008735 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008736 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008737 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008738 {
8739 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8740 .doit = nl80211_set_tx_bitrate_mask,
8741 .policy = nl80211_policy,
8742 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008743 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8744 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008745 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008746 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008747 .cmd = NL80211_CMD_REGISTER_FRAME,
8748 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008749 .policy = nl80211_policy,
8750 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008751 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008752 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008753 },
8754 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008755 .cmd = NL80211_CMD_FRAME,
8756 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008757 .policy = nl80211_policy,
8758 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008759 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008760 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008761 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008762 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008763 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8764 .doit = nl80211_tx_mgmt_cancel_wait,
8765 .policy = nl80211_policy,
8766 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008767 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008768 NL80211_FLAG_NEED_RTNL,
8769 },
8770 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008771 .cmd = NL80211_CMD_SET_POWER_SAVE,
8772 .doit = nl80211_set_power_save,
8773 .policy = nl80211_policy,
8774 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008775 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8776 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008777 },
8778 {
8779 .cmd = NL80211_CMD_GET_POWER_SAVE,
8780 .doit = nl80211_get_power_save,
8781 .policy = nl80211_policy,
8782 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008783 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8784 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008785 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008786 {
8787 .cmd = NL80211_CMD_SET_CQM,
8788 .doit = nl80211_set_cqm,
8789 .policy = nl80211_policy,
8790 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008791 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8792 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008793 },
Johannes Bergf444de02010-05-05 15:25:02 +02008794 {
8795 .cmd = NL80211_CMD_SET_CHANNEL,
8796 .doit = nl80211_set_channel,
8797 .policy = nl80211_policy,
8798 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008799 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8800 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008801 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008802 {
8803 .cmd = NL80211_CMD_SET_WDS_PEER,
8804 .doit = nl80211_set_wds_peer,
8805 .policy = nl80211_policy,
8806 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8808 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008809 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008810 {
8811 .cmd = NL80211_CMD_JOIN_MESH,
8812 .doit = nl80211_join_mesh,
8813 .policy = nl80211_policy,
8814 .flags = GENL_ADMIN_PERM,
8815 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8816 NL80211_FLAG_NEED_RTNL,
8817 },
8818 {
8819 .cmd = NL80211_CMD_LEAVE_MESH,
8820 .doit = nl80211_leave_mesh,
8821 .policy = nl80211_policy,
8822 .flags = GENL_ADMIN_PERM,
8823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8824 NL80211_FLAG_NEED_RTNL,
8825 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008826#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008827 {
8828 .cmd = NL80211_CMD_GET_WOWLAN,
8829 .doit = nl80211_get_wowlan,
8830 .policy = nl80211_policy,
8831 /* can be retrieved by unprivileged users */
8832 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8833 NL80211_FLAG_NEED_RTNL,
8834 },
8835 {
8836 .cmd = NL80211_CMD_SET_WOWLAN,
8837 .doit = nl80211_set_wowlan,
8838 .policy = nl80211_policy,
8839 .flags = GENL_ADMIN_PERM,
8840 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8841 NL80211_FLAG_NEED_RTNL,
8842 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008843#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008844 {
8845 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8846 .doit = nl80211_set_rekey_data,
8847 .policy = nl80211_policy,
8848 .flags = GENL_ADMIN_PERM,
8849 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8850 NL80211_FLAG_NEED_RTNL,
8851 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008852 {
8853 .cmd = NL80211_CMD_TDLS_MGMT,
8854 .doit = nl80211_tdls_mgmt,
8855 .policy = nl80211_policy,
8856 .flags = GENL_ADMIN_PERM,
8857 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8858 NL80211_FLAG_NEED_RTNL,
8859 },
8860 {
8861 .cmd = NL80211_CMD_TDLS_OPER,
8862 .doit = nl80211_tdls_oper,
8863 .policy = nl80211_policy,
8864 .flags = GENL_ADMIN_PERM,
8865 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8866 NL80211_FLAG_NEED_RTNL,
8867 },
Johannes Berg28946da2011-11-04 11:18:12 +01008868 {
8869 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8870 .doit = nl80211_register_unexpected_frame,
8871 .policy = nl80211_policy,
8872 .flags = GENL_ADMIN_PERM,
8873 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8874 NL80211_FLAG_NEED_RTNL,
8875 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008876 {
8877 .cmd = NL80211_CMD_PROBE_CLIENT,
8878 .doit = nl80211_probe_client,
8879 .policy = nl80211_policy,
8880 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008881 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008882 NL80211_FLAG_NEED_RTNL,
8883 },
Johannes Berg5e760232011-11-04 11:18:17 +01008884 {
8885 .cmd = NL80211_CMD_REGISTER_BEACONS,
8886 .doit = nl80211_register_beacons,
8887 .policy = nl80211_policy,
8888 .flags = GENL_ADMIN_PERM,
8889 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8890 NL80211_FLAG_NEED_RTNL,
8891 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008892 {
8893 .cmd = NL80211_CMD_SET_NOACK_MAP,
8894 .doit = nl80211_set_noack_map,
8895 .policy = nl80211_policy,
8896 .flags = GENL_ADMIN_PERM,
8897 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8898 NL80211_FLAG_NEED_RTNL,
8899 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008900 {
8901 .cmd = NL80211_CMD_START_P2P_DEVICE,
8902 .doit = nl80211_start_p2p_device,
8903 .policy = nl80211_policy,
8904 .flags = GENL_ADMIN_PERM,
8905 .internal_flags = NL80211_FLAG_NEED_WDEV |
8906 NL80211_FLAG_NEED_RTNL,
8907 },
8908 {
8909 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8910 .doit = nl80211_stop_p2p_device,
8911 .policy = nl80211_policy,
8912 .flags = GENL_ADMIN_PERM,
8913 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8914 NL80211_FLAG_NEED_RTNL,
8915 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008916 {
8917 .cmd = NL80211_CMD_SET_MCAST_RATE,
8918 .doit = nl80211_set_mcast_rate,
8919 .policy = nl80211_policy,
8920 .flags = GENL_ADMIN_PERM,
8921 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8922 NL80211_FLAG_NEED_RTNL,
8923 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308924 {
8925 .cmd = NL80211_CMD_SET_MAC_ACL,
8926 .doit = nl80211_set_mac_acl,
8927 .policy = nl80211_policy,
8928 .flags = GENL_ADMIN_PERM,
8929 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8930 NL80211_FLAG_NEED_RTNL,
8931 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008932 {
8933 .cmd = NL80211_CMD_RADAR_DETECT,
8934 .doit = nl80211_start_radar_detection,
8935 .policy = nl80211_policy,
8936 .flags = GENL_ADMIN_PERM,
8937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8938 NL80211_FLAG_NEED_RTNL,
8939 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008940 {
8941 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8942 .doit = nl80211_get_protocol_features,
8943 .policy = nl80211_policy,
8944 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008945 {
8946 .cmd = NL80211_CMD_UPDATE_FT_IES,
8947 .doit = nl80211_update_ft_ies,
8948 .policy = nl80211_policy,
8949 .flags = GENL_ADMIN_PERM,
8950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8951 NL80211_FLAG_NEED_RTNL,
8952 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008953 {
8954 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8955 .doit = nl80211_crit_protocol_start,
8956 .policy = nl80211_policy,
8957 .flags = GENL_ADMIN_PERM,
8958 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8959 NL80211_FLAG_NEED_RTNL,
8960 },
8961 {
8962 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
8963 .doit = nl80211_crit_protocol_stop,
8964 .policy = nl80211_policy,
8965 .flags = GENL_ADMIN_PERM,
8966 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8967 NL80211_FLAG_NEED_RTNL,
8968 }
Johannes Berg55682962007-09-20 13:09:35 -04008969};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008970
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008971static struct genl_multicast_group nl80211_mlme_mcgrp = {
8972 .name = "mlme",
8973};
Johannes Berg55682962007-09-20 13:09:35 -04008974
8975/* multicast groups */
8976static struct genl_multicast_group nl80211_config_mcgrp = {
8977 .name = "config",
8978};
Johannes Berg2a519312009-02-10 21:25:55 +01008979static struct genl_multicast_group nl80211_scan_mcgrp = {
8980 .name = "scan",
8981};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008982static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8983 .name = "regulatory",
8984};
Johannes Berg55682962007-09-20 13:09:35 -04008985
8986/* notification functions */
8987
8988void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8989{
8990 struct sk_buff *msg;
8991
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008992 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008993 if (!msg)
8994 return;
8995
Johannes Berg3713b4e2013-02-14 16:19:38 +01008996 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8997 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008998 nlmsg_free(msg);
8999 return;
9000 }
9001
Johannes Berg463d0182009-07-14 00:33:35 +02009002 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9003 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009004}
9005
Johannes Berg362a4152009-05-24 16:43:15 +02009006static int nl80211_add_scan_req(struct sk_buff *msg,
9007 struct cfg80211_registered_device *rdev)
9008{
9009 struct cfg80211_scan_request *req = rdev->scan_req;
9010 struct nlattr *nest;
9011 int i;
9012
9013 if (WARN_ON(!req))
9014 return 0;
9015
9016 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9017 if (!nest)
9018 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009019 for (i = 0; i < req->n_ssids; i++) {
9020 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9021 goto nla_put_failure;
9022 }
Johannes Berg362a4152009-05-24 16:43:15 +02009023 nla_nest_end(msg, nest);
9024
9025 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9026 if (!nest)
9027 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009028 for (i = 0; i < req->n_channels; i++) {
9029 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9030 goto nla_put_failure;
9031 }
Johannes Berg362a4152009-05-24 16:43:15 +02009032 nla_nest_end(msg, nest);
9033
David S. Miller9360ffd2012-03-29 04:41:26 -04009034 if (req->ie &&
9035 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9036 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009037
Sam Lefflered4737712012-10-11 21:03:31 -07009038 if (req->flags)
9039 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9040
Johannes Berg362a4152009-05-24 16:43:15 +02009041 return 0;
9042 nla_put_failure:
9043 return -ENOBUFS;
9044}
9045
Johannes Berga538e2d2009-06-16 19:56:42 +02009046static int nl80211_send_scan_msg(struct sk_buff *msg,
9047 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009048 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009049 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009050 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009051{
9052 void *hdr;
9053
Eric W. Biederman15e47302012-09-07 20:12:54 +00009054 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009055 if (!hdr)
9056 return -1;
9057
David S. Miller9360ffd2012-03-29 04:41:26 -04009058 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009059 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9060 wdev->netdev->ifindex)) ||
9061 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009062 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009063
Johannes Berg362a4152009-05-24 16:43:15 +02009064 /* ignore errors and send incomplete event anyway */
9065 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009066
9067 return genlmsg_end(msg, hdr);
9068
9069 nla_put_failure:
9070 genlmsg_cancel(msg, hdr);
9071 return -EMSGSIZE;
9072}
9073
Luciano Coelho807f8a82011-05-11 17:09:35 +03009074static int
9075nl80211_send_sched_scan_msg(struct sk_buff *msg,
9076 struct cfg80211_registered_device *rdev,
9077 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009078 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009079{
9080 void *hdr;
9081
Eric W. Biederman15e47302012-09-07 20:12:54 +00009082 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009083 if (!hdr)
9084 return -1;
9085
David S. Miller9360ffd2012-03-29 04:41:26 -04009086 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9088 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009089
9090 return genlmsg_end(msg, hdr);
9091
9092 nla_put_failure:
9093 genlmsg_cancel(msg, hdr);
9094 return -EMSGSIZE;
9095}
9096
Johannes Berga538e2d2009-06-16 19:56:42 +02009097void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009098 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009099{
9100 struct sk_buff *msg;
9101
Thomas Graf58050fc2012-06-28 03:57:45 +00009102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009103 if (!msg)
9104 return;
9105
Johannes Bergfd014282012-06-18 19:17:03 +02009106 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009107 NL80211_CMD_TRIGGER_SCAN) < 0) {
9108 nlmsg_free(msg);
9109 return;
9110 }
9111
Johannes Berg463d0182009-07-14 00:33:35 +02009112 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9113 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009114}
9115
Johannes Berg2a519312009-02-10 21:25:55 +01009116void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009117 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009118{
9119 struct sk_buff *msg;
9120
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009122 if (!msg)
9123 return;
9124
Johannes Bergfd014282012-06-18 19:17:03 +02009125 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009126 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009127 nlmsg_free(msg);
9128 return;
9129 }
9130
Johannes Berg463d0182009-07-14 00:33:35 +02009131 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9132 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009133}
9134
9135void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009136 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009137{
9138 struct sk_buff *msg;
9139
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009140 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009141 if (!msg)
9142 return;
9143
Johannes Bergfd014282012-06-18 19:17:03 +02009144 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009145 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009146 nlmsg_free(msg);
9147 return;
9148 }
9149
Johannes Berg463d0182009-07-14 00:33:35 +02009150 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9151 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009152}
9153
Luciano Coelho807f8a82011-05-11 17:09:35 +03009154void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9155 struct net_device *netdev)
9156{
9157 struct sk_buff *msg;
9158
9159 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9160 if (!msg)
9161 return;
9162
9163 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9164 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9165 nlmsg_free(msg);
9166 return;
9167 }
9168
9169 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9170 nl80211_scan_mcgrp.id, GFP_KERNEL);
9171}
9172
9173void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9174 struct net_device *netdev, u32 cmd)
9175{
9176 struct sk_buff *msg;
9177
Thomas Graf58050fc2012-06-28 03:57:45 +00009178 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009179 if (!msg)
9180 return;
9181
9182 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9183 nlmsg_free(msg);
9184 return;
9185 }
9186
9187 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9188 nl80211_scan_mcgrp.id, GFP_KERNEL);
9189}
9190
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009191/*
9192 * This can happen on global regulatory changes or device specific settings
9193 * based on custom world regulatory domains.
9194 */
9195void nl80211_send_reg_change_event(struct regulatory_request *request)
9196{
9197 struct sk_buff *msg;
9198 void *hdr;
9199
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009201 if (!msg)
9202 return;
9203
9204 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9205 if (!hdr) {
9206 nlmsg_free(msg);
9207 return;
9208 }
9209
9210 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009211 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9212 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009213
David S. Miller9360ffd2012-03-29 04:41:26 -04009214 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9215 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9216 NL80211_REGDOM_TYPE_WORLD))
9217 goto nla_put_failure;
9218 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9219 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9220 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9221 goto nla_put_failure;
9222 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9223 request->intersect) {
9224 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9225 NL80211_REGDOM_TYPE_INTERSECTION))
9226 goto nla_put_failure;
9227 } else {
9228 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9229 NL80211_REGDOM_TYPE_COUNTRY) ||
9230 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9231 request->alpha2))
9232 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009233 }
9234
Johannes Bergf4173762012-12-03 18:23:37 +01009235 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009236 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9237 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009238
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009239 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009240
Johannes Bergbc43b282009-07-25 10:54:13 +02009241 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009242 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009243 GFP_ATOMIC);
9244 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009245
9246 return;
9247
9248nla_put_failure:
9249 genlmsg_cancel(msg, hdr);
9250 nlmsg_free(msg);
9251}
9252
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009253static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9254 struct net_device *netdev,
9255 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009256 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009257{
9258 struct sk_buff *msg;
9259 void *hdr;
9260
Johannes Berge6d6e342009-07-01 21:26:47 +02009261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009262 if (!msg)
9263 return;
9264
9265 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9266 if (!hdr) {
9267 nlmsg_free(msg);
9268 return;
9269 }
9270
David S. Miller9360ffd2012-03-29 04:41:26 -04009271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9272 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9273 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9274 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009275
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009276 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009277
Johannes Berg463d0182009-07-14 00:33:35 +02009278 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9279 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009280 return;
9281
9282 nla_put_failure:
9283 genlmsg_cancel(msg, hdr);
9284 nlmsg_free(msg);
9285}
9286
9287void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009288 struct net_device *netdev, const u8 *buf,
9289 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009290{
9291 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009292 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009293}
9294
9295void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9296 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009297 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009298{
Johannes Berge6d6e342009-07-01 21:26:47 +02009299 nl80211_send_mlme_event(rdev, netdev, buf, len,
9300 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009301}
9302
Jouni Malinen53b46b82009-03-27 20:53:56 +02009303void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009304 struct net_device *netdev, const u8 *buf,
9305 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009306{
9307 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009308 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009309}
9310
Jouni Malinen53b46b82009-03-27 20:53:56 +02009311void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9312 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009313 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009314{
9315 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009316 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009317}
9318
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009319void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9320 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009321{
Johannes Berg947add32013-02-22 22:05:20 +01009322 struct wireless_dev *wdev = dev->ieee80211_ptr;
9323 struct wiphy *wiphy = wdev->wiphy;
9324 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009325 const struct ieee80211_mgmt *mgmt = (void *)buf;
9326 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009327
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009328 if (WARN_ON(len < 2))
9329 return;
9330
9331 if (ieee80211_is_deauth(mgmt->frame_control))
9332 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9333 else
9334 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9335
9336 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9337 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009338}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009339EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009340
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009341static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9342 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009343 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009344{
9345 struct sk_buff *msg;
9346 void *hdr;
9347
Johannes Berge6d6e342009-07-01 21:26:47 +02009348 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009349 if (!msg)
9350 return;
9351
9352 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9353 if (!hdr) {
9354 nlmsg_free(msg);
9355 return;
9356 }
9357
David S. Miller9360ffd2012-03-29 04:41:26 -04009358 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9359 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9360 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9361 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9362 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009363
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009364 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009365
Johannes Berg463d0182009-07-14 00:33:35 +02009366 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9367 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009368 return;
9369
9370 nla_put_failure:
9371 genlmsg_cancel(msg, hdr);
9372 nlmsg_free(msg);
9373}
9374
9375void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009376 struct net_device *netdev, const u8 *addr,
9377 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009378{
9379 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009380 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009381}
9382
9383void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009384 struct net_device *netdev, const u8 *addr,
9385 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009386{
Johannes Berge6d6e342009-07-01 21:26:47 +02009387 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9388 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009389}
9390
Samuel Ortizb23aa672009-07-01 21:26:54 +02009391void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9392 struct net_device *netdev, const u8 *bssid,
9393 const u8 *req_ie, size_t req_ie_len,
9394 const u8 *resp_ie, size_t resp_ie_len,
9395 u16 status, gfp_t gfp)
9396{
9397 struct sk_buff *msg;
9398 void *hdr;
9399
Thomas Graf58050fc2012-06-28 03:57:45 +00009400 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009401 if (!msg)
9402 return;
9403
9404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9405 if (!hdr) {
9406 nlmsg_free(msg);
9407 return;
9408 }
9409
David S. Miller9360ffd2012-03-29 04:41:26 -04009410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9411 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9412 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9413 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9414 (req_ie &&
9415 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9416 (resp_ie &&
9417 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9418 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009419
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009420 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009421
Johannes Berg463d0182009-07-14 00:33:35 +02009422 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9423 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009424 return;
9425
9426 nla_put_failure:
9427 genlmsg_cancel(msg, hdr);
9428 nlmsg_free(msg);
9429
9430}
9431
9432void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9433 struct net_device *netdev, const u8 *bssid,
9434 const u8 *req_ie, size_t req_ie_len,
9435 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9436{
9437 struct sk_buff *msg;
9438 void *hdr;
9439
Thomas Graf58050fc2012-06-28 03:57:45 +00009440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009441 if (!msg)
9442 return;
9443
9444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9445 if (!hdr) {
9446 nlmsg_free(msg);
9447 return;
9448 }
9449
David S. Miller9360ffd2012-03-29 04:41:26 -04009450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9451 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9452 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9453 (req_ie &&
9454 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9455 (resp_ie &&
9456 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9457 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009458
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009459 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009460
Johannes Berg463d0182009-07-14 00:33:35 +02009461 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9462 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009463 return;
9464
9465 nla_put_failure:
9466 genlmsg_cancel(msg, hdr);
9467 nlmsg_free(msg);
9468
9469}
9470
9471void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9472 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009473 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009474{
9475 struct sk_buff *msg;
9476 void *hdr;
9477
Thomas Graf58050fc2012-06-28 03:57:45 +00009478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009479 if (!msg)
9480 return;
9481
9482 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9483 if (!hdr) {
9484 nlmsg_free(msg);
9485 return;
9486 }
9487
David S. Miller9360ffd2012-03-29 04:41:26 -04009488 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9489 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9490 (from_ap && reason &&
9491 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9492 (from_ap &&
9493 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9494 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9495 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009496
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009497 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009498
Johannes Berg463d0182009-07-14 00:33:35 +02009499 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9500 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009501 return;
9502
9503 nla_put_failure:
9504 genlmsg_cancel(msg, hdr);
9505 nlmsg_free(msg);
9506
9507}
9508
Johannes Berg04a773a2009-04-19 21:24:32 +02009509void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9510 struct net_device *netdev, const u8 *bssid,
9511 gfp_t gfp)
9512{
9513 struct sk_buff *msg;
9514 void *hdr;
9515
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009516 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009517 if (!msg)
9518 return;
9519
9520 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9521 if (!hdr) {
9522 nlmsg_free(msg);
9523 return;
9524 }
9525
David S. Miller9360ffd2012-03-29 04:41:26 -04009526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9527 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9528 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9529 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009530
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009531 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009532
Johannes Berg463d0182009-07-14 00:33:35 +02009533 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9534 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009535 return;
9536
9537 nla_put_failure:
9538 genlmsg_cancel(msg, hdr);
9539 nlmsg_free(msg);
9540}
9541
Johannes Berg947add32013-02-22 22:05:20 +01009542void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9543 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009544{
Johannes Berg947add32013-02-22 22:05:20 +01009545 struct wireless_dev *wdev = dev->ieee80211_ptr;
9546 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009547 struct sk_buff *msg;
9548 void *hdr;
9549
Johannes Berg947add32013-02-22 22:05:20 +01009550 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9551 return;
9552
9553 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9554
Javier Cardonac93b5e72011-04-07 15:08:34 -07009555 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9556 if (!msg)
9557 return;
9558
9559 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9560 if (!hdr) {
9561 nlmsg_free(msg);
9562 return;
9563 }
9564
David S. Miller9360ffd2012-03-29 04:41:26 -04009565 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009566 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9567 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009568 (ie_len && ie &&
9569 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9570 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009571
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009572 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009573
9574 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9575 nl80211_mlme_mcgrp.id, gfp);
9576 return;
9577
9578 nla_put_failure:
9579 genlmsg_cancel(msg, hdr);
9580 nlmsg_free(msg);
9581}
Johannes Berg947add32013-02-22 22:05:20 +01009582EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009583
Jouni Malinena3b8b052009-03-27 21:59:49 +02009584void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9585 struct net_device *netdev, const u8 *addr,
9586 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009587 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009588{
9589 struct sk_buff *msg;
9590 void *hdr;
9591
Johannes Berge6d6e342009-07-01 21:26:47 +02009592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009593 if (!msg)
9594 return;
9595
9596 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9597 if (!hdr) {
9598 nlmsg_free(msg);
9599 return;
9600 }
9601
David S. Miller9360ffd2012-03-29 04:41:26 -04009602 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9603 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9604 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9605 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9606 (key_id != -1 &&
9607 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9608 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9609 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009610
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009611 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009612
Johannes Berg463d0182009-07-14 00:33:35 +02009613 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9614 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009615 return;
9616
9617 nla_put_failure:
9618 genlmsg_cancel(msg, hdr);
9619 nlmsg_free(msg);
9620}
9621
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009622void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9623 struct ieee80211_channel *channel_before,
9624 struct ieee80211_channel *channel_after)
9625{
9626 struct sk_buff *msg;
9627 void *hdr;
9628 struct nlattr *nl_freq;
9629
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009631 if (!msg)
9632 return;
9633
9634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9635 if (!hdr) {
9636 nlmsg_free(msg);
9637 return;
9638 }
9639
9640 /*
9641 * Since we are applying the beacon hint to a wiphy we know its
9642 * wiphy_idx is valid
9643 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009644 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9645 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009646
9647 /* Before */
9648 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9649 if (!nl_freq)
9650 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009651 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009652 goto nla_put_failure;
9653 nla_nest_end(msg, nl_freq);
9654
9655 /* After */
9656 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9657 if (!nl_freq)
9658 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009659 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009660 goto nla_put_failure;
9661 nla_nest_end(msg, nl_freq);
9662
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009663 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009664
Johannes Berg463d0182009-07-14 00:33:35 +02009665 rcu_read_lock();
9666 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9667 GFP_ATOMIC);
9668 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009669
9670 return;
9671
9672nla_put_failure:
9673 genlmsg_cancel(msg, hdr);
9674 nlmsg_free(msg);
9675}
9676
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009677static void nl80211_send_remain_on_chan_event(
9678 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009679 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009680 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009681 unsigned int duration, gfp_t gfp)
9682{
9683 struct sk_buff *msg;
9684 void *hdr;
9685
9686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9687 if (!msg)
9688 return;
9689
9690 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9691 if (!hdr) {
9692 nlmsg_free(msg);
9693 return;
9694 }
9695
David S. Miller9360ffd2012-03-29 04:41:26 -04009696 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009697 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9698 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009699 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009700 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009701 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9702 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009703 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9704 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009705
David S. Miller9360ffd2012-03-29 04:41:26 -04009706 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9707 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9708 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009709
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009710 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009711
9712 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9713 nl80211_mlme_mcgrp.id, gfp);
9714 return;
9715
9716 nla_put_failure:
9717 genlmsg_cancel(msg, hdr);
9718 nlmsg_free(msg);
9719}
9720
Johannes Berg947add32013-02-22 22:05:20 +01009721void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9722 struct ieee80211_channel *chan,
9723 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009724{
Johannes Berg947add32013-02-22 22:05:20 +01009725 struct wiphy *wiphy = wdev->wiphy;
9726 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9727
9728 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009729 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009730 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009731 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009732}
Johannes Berg947add32013-02-22 22:05:20 +01009733EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009734
Johannes Berg947add32013-02-22 22:05:20 +01009735void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9736 struct ieee80211_channel *chan,
9737 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009738{
Johannes Berg947add32013-02-22 22:05:20 +01009739 struct wiphy *wiphy = wdev->wiphy;
9740 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9741
9742 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009743 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009744 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009745}
Johannes Berg947add32013-02-22 22:05:20 +01009746EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009747
Johannes Berg947add32013-02-22 22:05:20 +01009748void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9749 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009750{
Johannes Berg947add32013-02-22 22:05:20 +01009751 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9752 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009753 struct sk_buff *msg;
9754
Johannes Berg947add32013-02-22 22:05:20 +01009755 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9756
Thomas Graf58050fc2012-06-28 03:57:45 +00009757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009758 if (!msg)
9759 return;
9760
John W. Linville66266b32012-03-15 13:25:41 -04009761 if (nl80211_send_station(msg, 0, 0, 0,
9762 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009763 nlmsg_free(msg);
9764 return;
9765 }
9766
9767 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9768 nl80211_mlme_mcgrp.id, gfp);
9769}
Johannes Berg947add32013-02-22 22:05:20 +01009770EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009771
Johannes Berg947add32013-02-22 22:05:20 +01009772void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009773{
Johannes Berg947add32013-02-22 22:05:20 +01009774 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9775 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009776 struct sk_buff *msg;
9777 void *hdr;
9778
Johannes Berg947add32013-02-22 22:05:20 +01009779 trace_cfg80211_del_sta(dev, mac_addr);
9780
Thomas Graf58050fc2012-06-28 03:57:45 +00009781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009782 if (!msg)
9783 return;
9784
9785 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9786 if (!hdr) {
9787 nlmsg_free(msg);
9788 return;
9789 }
9790
David S. Miller9360ffd2012-03-29 04:41:26 -04009791 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9792 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9793 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009794
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009795 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009796
9797 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9798 nl80211_mlme_mcgrp.id, gfp);
9799 return;
9800
9801 nla_put_failure:
9802 genlmsg_cancel(msg, hdr);
9803 nlmsg_free(msg);
9804}
Johannes Berg947add32013-02-22 22:05:20 +01009805EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009806
Johannes Berg947add32013-02-22 22:05:20 +01009807void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9808 enum nl80211_connect_failed_reason reason,
9809 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309810{
Johannes Berg947add32013-02-22 22:05:20 +01009811 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9812 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309813 struct sk_buff *msg;
9814 void *hdr;
9815
9816 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9817 if (!msg)
9818 return;
9819
9820 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9821 if (!hdr) {
9822 nlmsg_free(msg);
9823 return;
9824 }
9825
9826 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9827 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9828 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9829 goto nla_put_failure;
9830
9831 genlmsg_end(msg, hdr);
9832
9833 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9834 nl80211_mlme_mcgrp.id, gfp);
9835 return;
9836
9837 nla_put_failure:
9838 genlmsg_cancel(msg, hdr);
9839 nlmsg_free(msg);
9840}
Johannes Berg947add32013-02-22 22:05:20 +01009841EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309842
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009843static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9844 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009845{
9846 struct wireless_dev *wdev = dev->ieee80211_ptr;
9847 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9848 struct sk_buff *msg;
9849 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009850 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009851
Eric W. Biederman15e47302012-09-07 20:12:54 +00009852 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009853 return false;
9854
9855 msg = nlmsg_new(100, gfp);
9856 if (!msg)
9857 return true;
9858
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009859 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009860 if (!hdr) {
9861 nlmsg_free(msg);
9862 return true;
9863 }
9864
David S. Miller9360ffd2012-03-29 04:41:26 -04009865 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9866 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9867 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9868 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009869
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009870 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009871 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009872 return true;
9873
9874 nla_put_failure:
9875 genlmsg_cancel(msg, hdr);
9876 nlmsg_free(msg);
9877 return true;
9878}
9879
Johannes Berg947add32013-02-22 22:05:20 +01009880bool cfg80211_rx_spurious_frame(struct net_device *dev,
9881 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009882{
Johannes Berg947add32013-02-22 22:05:20 +01009883 struct wireless_dev *wdev = dev->ieee80211_ptr;
9884 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009885
Johannes Berg947add32013-02-22 22:05:20 +01009886 trace_cfg80211_rx_spurious_frame(dev, addr);
9887
9888 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9889 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9890 trace_cfg80211_return_bool(false);
9891 return false;
9892 }
9893 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9894 addr, gfp);
9895 trace_cfg80211_return_bool(ret);
9896 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009897}
Johannes Berg947add32013-02-22 22:05:20 +01009898EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9899
9900bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9901 const u8 *addr, gfp_t gfp)
9902{
9903 struct wireless_dev *wdev = dev->ieee80211_ptr;
9904 bool ret;
9905
9906 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9907
9908 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9909 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9910 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9911 trace_cfg80211_return_bool(false);
9912 return false;
9913 }
9914 ret = __nl80211_unexpected_frame(dev,
9915 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9916 addr, gfp);
9917 trace_cfg80211_return_bool(ret);
9918 return ret;
9919}
9920EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009921
Johannes Berg2e161f72010-08-12 15:38:38 +02009922int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009923 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009924 int freq, int sig_dbm,
9925 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009926{
Johannes Berg71bbc992012-06-15 15:30:18 +02009927 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009928 struct sk_buff *msg;
9929 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009930
9931 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9932 if (!msg)
9933 return -ENOMEM;
9934
Johannes Berg2e161f72010-08-12 15:38:38 +02009935 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009936 if (!hdr) {
9937 nlmsg_free(msg);
9938 return -ENOMEM;
9939 }
9940
David S. Miller9360ffd2012-03-29 04:41:26 -04009941 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009942 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9943 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009944 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009945 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9946 (sig_dbm &&
9947 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9948 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9949 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009950
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009951 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009952
Eric W. Biederman15e47302012-09-07 20:12:54 +00009953 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009954
9955 nla_put_failure:
9956 genlmsg_cancel(msg, hdr);
9957 nlmsg_free(msg);
9958 return -ENOBUFS;
9959}
9960
Johannes Berg947add32013-02-22 22:05:20 +01009961void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9962 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009963{
Johannes Berg947add32013-02-22 22:05:20 +01009964 struct wiphy *wiphy = wdev->wiphy;
9965 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009966 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009967 struct sk_buff *msg;
9968 void *hdr;
9969
Johannes Berg947add32013-02-22 22:05:20 +01009970 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9971
Jouni Malinen026331c2010-02-15 12:53:10 +02009972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9973 if (!msg)
9974 return;
9975
Johannes Berg2e161f72010-08-12 15:38:38 +02009976 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009977 if (!hdr) {
9978 nlmsg_free(msg);
9979 return;
9980 }
9981
David S. Miller9360ffd2012-03-29 04:41:26 -04009982 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009983 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9984 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009985 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009986 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9987 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9988 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9989 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009990
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009991 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009992
9993 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9994 return;
9995
9996 nla_put_failure:
9997 genlmsg_cancel(msg, hdr);
9998 nlmsg_free(msg);
9999}
Johannes Berg947add32013-02-22 22:05:20 +010010000EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010001
Johannes Berg947add32013-02-22 22:05:20 +010010002void cfg80211_cqm_rssi_notify(struct net_device *dev,
10003 enum nl80211_cqm_rssi_threshold_event rssi_event,
10004 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010005{
Johannes Berg947add32013-02-22 22:05:20 +010010006 struct wireless_dev *wdev = dev->ieee80211_ptr;
10007 struct wiphy *wiphy = wdev->wiphy;
10008 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010009 struct sk_buff *msg;
10010 struct nlattr *pinfoattr;
10011 void *hdr;
10012
Johannes Berg947add32013-02-22 22:05:20 +010010013 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10014
Thomas Graf58050fc2012-06-28 03:57:45 +000010015 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010016 if (!msg)
10017 return;
10018
10019 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10020 if (!hdr) {
10021 nlmsg_free(msg);
10022 return;
10023 }
10024
David S. Miller9360ffd2012-03-29 04:41:26 -040010025 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010026 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010027 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010028
10029 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10030 if (!pinfoattr)
10031 goto nla_put_failure;
10032
David S. Miller9360ffd2012-03-29 04:41:26 -040010033 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10034 rssi_event))
10035 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010036
10037 nla_nest_end(msg, pinfoattr);
10038
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010039 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010040
10041 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10042 nl80211_mlme_mcgrp.id, gfp);
10043 return;
10044
10045 nla_put_failure:
10046 genlmsg_cancel(msg, hdr);
10047 nlmsg_free(msg);
10048}
Johannes Berg947add32013-02-22 22:05:20 +010010049EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010050
Johannes Berg947add32013-02-22 22:05:20 +010010051static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10052 struct net_device *netdev, const u8 *bssid,
10053 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010054{
10055 struct sk_buff *msg;
10056 struct nlattr *rekey_attr;
10057 void *hdr;
10058
Thomas Graf58050fc2012-06-28 03:57:45 +000010059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010060 if (!msg)
10061 return;
10062
10063 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10064 if (!hdr) {
10065 nlmsg_free(msg);
10066 return;
10067 }
10068
David S. Miller9360ffd2012-03-29 04:41:26 -040010069 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10070 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10071 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10072 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010073
10074 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10075 if (!rekey_attr)
10076 goto nla_put_failure;
10077
David S. Miller9360ffd2012-03-29 04:41:26 -040010078 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10079 NL80211_REPLAY_CTR_LEN, replay_ctr))
10080 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010081
10082 nla_nest_end(msg, rekey_attr);
10083
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010084 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010085
10086 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10087 nl80211_mlme_mcgrp.id, gfp);
10088 return;
10089
10090 nla_put_failure:
10091 genlmsg_cancel(msg, hdr);
10092 nlmsg_free(msg);
10093}
10094
Johannes Berg947add32013-02-22 22:05:20 +010010095void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10096 const u8 *replay_ctr, gfp_t gfp)
10097{
10098 struct wireless_dev *wdev = dev->ieee80211_ptr;
10099 struct wiphy *wiphy = wdev->wiphy;
10100 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10101
10102 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10103 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10104}
10105EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10106
10107static void
10108nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10109 struct net_device *netdev, int index,
10110 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010111{
10112 struct sk_buff *msg;
10113 struct nlattr *attr;
10114 void *hdr;
10115
Thomas Graf58050fc2012-06-28 03:57:45 +000010116 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010117 if (!msg)
10118 return;
10119
10120 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
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 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010129
10130 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10131 if (!attr)
10132 goto nla_put_failure;
10133
David S. Miller9360ffd2012-03-29 04:41:26 -040010134 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10135 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10136 (preauth &&
10137 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10138 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010139
10140 nla_nest_end(msg, attr);
10141
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010142 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010143
10144 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10145 nl80211_mlme_mcgrp.id, gfp);
10146 return;
10147
10148 nla_put_failure:
10149 genlmsg_cancel(msg, hdr);
10150 nlmsg_free(msg);
10151}
10152
Johannes Berg947add32013-02-22 22:05:20 +010010153void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10154 const u8 *bssid, bool preauth, gfp_t gfp)
10155{
10156 struct wireless_dev *wdev = dev->ieee80211_ptr;
10157 struct wiphy *wiphy = wdev->wiphy;
10158 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10159
10160 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10161 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10162}
10163EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10164
10165static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10166 struct net_device *netdev,
10167 struct cfg80211_chan_def *chandef,
10168 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010169{
10170 struct sk_buff *msg;
10171 void *hdr;
10172
Thomas Graf58050fc2012-06-28 03:57:45 +000010173 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010174 if (!msg)
10175 return;
10176
10177 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10178 if (!hdr) {
10179 nlmsg_free(msg);
10180 return;
10181 }
10182
Johannes Berg683b6d32012-11-08 21:25:48 +010010183 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10184 goto nla_put_failure;
10185
10186 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010187 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010188
10189 genlmsg_end(msg, hdr);
10190
10191 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10192 nl80211_mlme_mcgrp.id, gfp);
10193 return;
10194
10195 nla_put_failure:
10196 genlmsg_cancel(msg, hdr);
10197 nlmsg_free(msg);
10198}
10199
Johannes Berg947add32013-02-22 22:05:20 +010010200void cfg80211_ch_switch_notify(struct net_device *dev,
10201 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010202{
Johannes Berg947add32013-02-22 22:05:20 +010010203 struct wireless_dev *wdev = dev->ieee80211_ptr;
10204 struct wiphy *wiphy = wdev->wiphy;
10205 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10206
10207 trace_cfg80211_ch_switch_notify(dev, chandef);
10208
10209 wdev_lock(wdev);
10210
10211 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10212 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10213 goto out;
10214
10215 wdev->channel = chandef->chan;
10216 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10217out:
10218 wdev_unlock(wdev);
10219 return;
10220}
10221EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10222
10223void cfg80211_cqm_txe_notify(struct net_device *dev,
10224 const u8 *peer, u32 num_packets,
10225 u32 rate, u32 intvl, gfp_t gfp)
10226{
10227 struct wireless_dev *wdev = dev->ieee80211_ptr;
10228 struct wiphy *wiphy = wdev->wiphy;
10229 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010230 struct sk_buff *msg;
10231 struct nlattr *pinfoattr;
10232 void *hdr;
10233
10234 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10235 if (!msg)
10236 return;
10237
10238 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10239 if (!hdr) {
10240 nlmsg_free(msg);
10241 return;
10242 }
10243
10244 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010245 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010246 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10247 goto nla_put_failure;
10248
10249 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10250 if (!pinfoattr)
10251 goto nla_put_failure;
10252
10253 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10254 goto nla_put_failure;
10255
10256 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10257 goto nla_put_failure;
10258
10259 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10260 goto nla_put_failure;
10261
10262 nla_nest_end(msg, pinfoattr);
10263
10264 genlmsg_end(msg, hdr);
10265
10266 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10267 nl80211_mlme_mcgrp.id, gfp);
10268 return;
10269
10270 nla_put_failure:
10271 genlmsg_cancel(msg, hdr);
10272 nlmsg_free(msg);
10273}
Johannes Berg947add32013-02-22 22:05:20 +010010274EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010275
10276void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010277nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10278 struct cfg80211_chan_def *chandef,
10279 enum nl80211_radar_event event,
10280 struct net_device *netdev, gfp_t gfp)
10281{
10282 struct sk_buff *msg;
10283 void *hdr;
10284
10285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10286 if (!msg)
10287 return;
10288
10289 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10290 if (!hdr) {
10291 nlmsg_free(msg);
10292 return;
10293 }
10294
10295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10296 goto nla_put_failure;
10297
10298 /* NOP and radar events don't need a netdev parameter */
10299 if (netdev) {
10300 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10301
10302 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10303 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10304 goto nla_put_failure;
10305 }
10306
10307 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10308 goto nla_put_failure;
10309
10310 if (nl80211_send_chandef(msg, chandef))
10311 goto nla_put_failure;
10312
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010313 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010314
10315 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10316 nl80211_mlme_mcgrp.id, gfp);
10317 return;
10318
10319 nla_put_failure:
10320 genlmsg_cancel(msg, hdr);
10321 nlmsg_free(msg);
10322}
10323
Johannes Berg947add32013-02-22 22:05:20 +010010324void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10325 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010326{
Johannes Berg947add32013-02-22 22:05:20 +010010327 struct wireless_dev *wdev = dev->ieee80211_ptr;
10328 struct wiphy *wiphy = wdev->wiphy;
10329 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010330 struct sk_buff *msg;
10331 struct nlattr *pinfoattr;
10332 void *hdr;
10333
Johannes Berg947add32013-02-22 22:05:20 +010010334 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10335
Thomas Graf58050fc2012-06-28 03:57:45 +000010336 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010337 if (!msg)
10338 return;
10339
10340 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10341 if (!hdr) {
10342 nlmsg_free(msg);
10343 return;
10344 }
10345
David S. Miller9360ffd2012-03-29 04:41:26 -040010346 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010347 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010348 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10349 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010350
10351 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10352 if (!pinfoattr)
10353 goto nla_put_failure;
10354
David S. Miller9360ffd2012-03-29 04:41:26 -040010355 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10356 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010357
10358 nla_nest_end(msg, pinfoattr);
10359
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010360 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010361
10362 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10363 nl80211_mlme_mcgrp.id, gfp);
10364 return;
10365
10366 nla_put_failure:
10367 genlmsg_cancel(msg, hdr);
10368 nlmsg_free(msg);
10369}
Johannes Berg947add32013-02-22 22:05:20 +010010370EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010371
Johannes Berg7f6cf312011-11-04 11:18:15 +010010372void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10373 u64 cookie, bool acked, gfp_t gfp)
10374{
10375 struct wireless_dev *wdev = dev->ieee80211_ptr;
10376 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10377 struct sk_buff *msg;
10378 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010379
Beni Lev4ee3e062012-08-27 12:49:39 +030010380 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10381
Thomas Graf58050fc2012-06-28 03:57:45 +000010382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010383
Johannes Berg7f6cf312011-11-04 11:18:15 +010010384 if (!msg)
10385 return;
10386
10387 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10388 if (!hdr) {
10389 nlmsg_free(msg);
10390 return;
10391 }
10392
David S. Miller9360ffd2012-03-29 04:41:26 -040010393 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10394 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10395 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10396 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10397 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10398 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010399
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010400 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010401
10402 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10403 nl80211_mlme_mcgrp.id, gfp);
10404 return;
10405
10406 nla_put_failure:
10407 genlmsg_cancel(msg, hdr);
10408 nlmsg_free(msg);
10409}
10410EXPORT_SYMBOL(cfg80211_probe_status);
10411
Johannes Berg5e760232011-11-04 11:18:17 +010010412void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10413 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010414 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010415{
10416 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10417 struct sk_buff *msg;
10418 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010419 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010420
Beni Lev4ee3e062012-08-27 12:49:39 +030010421 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10422
Ben Greear37c73b52012-10-26 14:49:25 -070010423 spin_lock_bh(&rdev->beacon_registrations_lock);
10424 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10425 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10426 if (!msg) {
10427 spin_unlock_bh(&rdev->beacon_registrations_lock);
10428 return;
10429 }
Johannes Berg5e760232011-11-04 11:18:17 +010010430
Ben Greear37c73b52012-10-26 14:49:25 -070010431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10432 if (!hdr)
10433 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010434
Ben Greear37c73b52012-10-26 14:49:25 -070010435 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10436 (freq &&
10437 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10438 (sig_dbm &&
10439 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10440 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10441 goto nla_put_failure;
10442
10443 genlmsg_end(msg, hdr);
10444
10445 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010446 }
Ben Greear37c73b52012-10-26 14:49:25 -070010447 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010448 return;
10449
10450 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010451 spin_unlock_bh(&rdev->beacon_registrations_lock);
10452 if (hdr)
10453 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010454 nlmsg_free(msg);
10455}
10456EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10457
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010458#ifdef CONFIG_PM
10459void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10460 struct cfg80211_wowlan_wakeup *wakeup,
10461 gfp_t gfp)
10462{
10463 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10464 struct sk_buff *msg;
10465 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010466 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010467
10468 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10469
10470 if (wakeup)
10471 size += wakeup->packet_present_len;
10472
10473 msg = nlmsg_new(size, gfp);
10474 if (!msg)
10475 return;
10476
10477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10478 if (!hdr)
10479 goto free_msg;
10480
10481 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10482 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10483 goto free_msg;
10484
10485 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10486 wdev->netdev->ifindex))
10487 goto free_msg;
10488
10489 if (wakeup) {
10490 struct nlattr *reasons;
10491
10492 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10493
10494 if (wakeup->disconnect &&
10495 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10496 goto free_msg;
10497 if (wakeup->magic_pkt &&
10498 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10499 goto free_msg;
10500 if (wakeup->gtk_rekey_failure &&
10501 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10502 goto free_msg;
10503 if (wakeup->eap_identity_req &&
10504 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10505 goto free_msg;
10506 if (wakeup->four_way_handshake &&
10507 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10508 goto free_msg;
10509 if (wakeup->rfkill_release &&
10510 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10511 goto free_msg;
10512
10513 if (wakeup->pattern_idx >= 0 &&
10514 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10515 wakeup->pattern_idx))
10516 goto free_msg;
10517
Johannes Berg2a0e0472013-01-23 22:57:40 +010010518 if (wakeup->tcp_match)
10519 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10520
10521 if (wakeup->tcp_connlost)
10522 nla_put_flag(msg,
10523 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10524
10525 if (wakeup->tcp_nomoretokens)
10526 nla_put_flag(msg,
10527 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10528
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010529 if (wakeup->packet) {
10530 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10531 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10532
10533 if (!wakeup->packet_80211) {
10534 pkt_attr =
10535 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10536 len_attr =
10537 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10538 }
10539
10540 if (wakeup->packet_len &&
10541 nla_put_u32(msg, len_attr, wakeup->packet_len))
10542 goto free_msg;
10543
10544 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10545 wakeup->packet))
10546 goto free_msg;
10547 }
10548
10549 nla_nest_end(msg, reasons);
10550 }
10551
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010552 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010553
10554 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10555 nl80211_mlme_mcgrp.id, gfp);
10556 return;
10557
10558 free_msg:
10559 nlmsg_free(msg);
10560}
10561EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10562#endif
10563
Jouni Malinen3475b092012-11-16 22:49:57 +020010564void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10565 enum nl80211_tdls_operation oper,
10566 u16 reason_code, gfp_t gfp)
10567{
10568 struct wireless_dev *wdev = dev->ieee80211_ptr;
10569 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10570 struct sk_buff *msg;
10571 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010572
10573 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10574 reason_code);
10575
10576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10577 if (!msg)
10578 return;
10579
10580 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10581 if (!hdr) {
10582 nlmsg_free(msg);
10583 return;
10584 }
10585
10586 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10587 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10588 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10589 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10590 (reason_code > 0 &&
10591 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10592 goto nla_put_failure;
10593
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010594 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010595
10596 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10597 nl80211_mlme_mcgrp.id, gfp);
10598 return;
10599
10600 nla_put_failure:
10601 genlmsg_cancel(msg, hdr);
10602 nlmsg_free(msg);
10603}
10604EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10605
Jouni Malinen026331c2010-02-15 12:53:10 +020010606static int nl80211_netlink_notify(struct notifier_block * nb,
10607 unsigned long state,
10608 void *_notify)
10609{
10610 struct netlink_notify *notify = _notify;
10611 struct cfg80211_registered_device *rdev;
10612 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010613 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010614
10615 if (state != NETLINK_URELEASE)
10616 return NOTIFY_DONE;
10617
10618 rcu_read_lock();
10619
Johannes Berg5e760232011-11-04 11:18:17 +010010620 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010621 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010622 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010623
10624 spin_lock_bh(&rdev->beacon_registrations_lock);
10625 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10626 list) {
10627 if (reg->nlportid == notify->portid) {
10628 list_del(&reg->list);
10629 kfree(reg);
10630 break;
10631 }
10632 }
10633 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010634 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010635
10636 rcu_read_unlock();
10637
10638 return NOTIFY_DONE;
10639}
10640
10641static struct notifier_block nl80211_netlink_notifier = {
10642 .notifier_call = nl80211_netlink_notify,
10643};
10644
Jouni Malinen355199e2013-02-27 17:14:27 +020010645void cfg80211_ft_event(struct net_device *netdev,
10646 struct cfg80211_ft_event_params *ft_event)
10647{
10648 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10649 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10650 struct sk_buff *msg;
10651 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010652
10653 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10654
10655 if (!ft_event->target_ap)
10656 return;
10657
10658 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10659 if (!msg)
10660 return;
10661
10662 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10663 if (!hdr) {
10664 nlmsg_free(msg);
10665 return;
10666 }
10667
10668 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10669 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10670 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10671 if (ft_event->ies)
10672 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10673 if (ft_event->ric_ies)
10674 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10675 ft_event->ric_ies);
10676
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010677 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010678
10679 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10680 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10681}
10682EXPORT_SYMBOL(cfg80211_ft_event);
10683
Arend van Spriel5de17982013-04-18 15:49:00 +020010684void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10685{
10686 struct cfg80211_registered_device *rdev;
10687 struct sk_buff *msg;
10688 void *hdr;
10689 u32 nlportid;
10690
10691 rdev = wiphy_to_dev(wdev->wiphy);
10692 if (!rdev->crit_proto_nlportid)
10693 return;
10694
10695 nlportid = rdev->crit_proto_nlportid;
10696 rdev->crit_proto_nlportid = 0;
10697
10698 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10699 if (!msg)
10700 return;
10701
10702 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10703 if (!hdr)
10704 goto nla_put_failure;
10705
10706 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10707 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10708 goto nla_put_failure;
10709
10710 genlmsg_end(msg, hdr);
10711
10712 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10713 return;
10714
10715 nla_put_failure:
10716 if (hdr)
10717 genlmsg_cancel(msg, hdr);
10718 nlmsg_free(msg);
10719
10720}
10721EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10722
Johannes Berg55682962007-09-20 13:09:35 -040010723/* initialisation/exit functions */
10724
10725int nl80211_init(void)
10726{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010727 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010728
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010729 err = genl_register_family_with_ops(&nl80211_fam,
10730 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010731 if (err)
10732 return err;
10733
Johannes Berg55682962007-09-20 13:09:35 -040010734 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10735 if (err)
10736 goto err_out;
10737
Johannes Berg2a519312009-02-10 21:25:55 +010010738 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10739 if (err)
10740 goto err_out;
10741
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010742 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10743 if (err)
10744 goto err_out;
10745
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010746 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10747 if (err)
10748 goto err_out;
10749
Johannes Bergaff89a92009-07-01 21:26:51 +020010750#ifdef CONFIG_NL80211_TESTMODE
10751 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10752 if (err)
10753 goto err_out;
10754#endif
10755
Jouni Malinen026331c2010-02-15 12:53:10 +020010756 err = netlink_register_notifier(&nl80211_netlink_notifier);
10757 if (err)
10758 goto err_out;
10759
Johannes Berg55682962007-09-20 13:09:35 -040010760 return 0;
10761 err_out:
10762 genl_unregister_family(&nl80211_fam);
10763 return err;
10764}
10765
10766void nl80211_exit(void)
10767{
Jouni Malinen026331c2010-02-15 12:53:10 +020010768 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010769 genl_unregister_family(&nl80211_fam);
10770}