blob: a09f36bb957c32977f08d52f4a3785921be1543e [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:
803 if (!wdev->current_bss)
804 return -ENOLINK;
805 break;
806 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200808 if (wdev->sme_state != CFG80211_SME_CONNECTED)
809 return -ENOLINK;
810 break;
811 default:
812 return -EINVAL;
813 }
814
815 return 0;
816}
817
Johannes Berg7527a782011-05-13 10:58:57 +0200818static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
819{
820 struct nlattr *nl_modes = nla_nest_start(msg, attr);
821 int i;
822
823 if (!nl_modes)
824 goto nla_put_failure;
825
826 i = 0;
827 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400828 if ((ifmodes & 1) && nla_put_flag(msg, i))
829 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200830 ifmodes >>= 1;
831 i++;
832 }
833
834 nla_nest_end(msg, nl_modes);
835 return 0;
836
837nla_put_failure:
838 return -ENOBUFS;
839}
840
841static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100842 struct sk_buff *msg,
843 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200844{
845 struct nlattr *nl_combis;
846 int i, j;
847
848 nl_combis = nla_nest_start(msg,
849 NL80211_ATTR_INTERFACE_COMBINATIONS);
850 if (!nl_combis)
851 goto nla_put_failure;
852
853 for (i = 0; i < wiphy->n_iface_combinations; i++) {
854 const struct ieee80211_iface_combination *c;
855 struct nlattr *nl_combi, *nl_limits;
856
857 c = &wiphy->iface_combinations[i];
858
859 nl_combi = nla_nest_start(msg, i + 1);
860 if (!nl_combi)
861 goto nla_put_failure;
862
863 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
864 if (!nl_limits)
865 goto nla_put_failure;
866
867 for (j = 0; j < c->n_limits; j++) {
868 struct nlattr *nl_limit;
869
870 nl_limit = nla_nest_start(msg, j + 1);
871 if (!nl_limit)
872 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400873 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
874 c->limits[j].max))
875 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200876 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
877 c->limits[j].types))
878 goto nla_put_failure;
879 nla_nest_end(msg, nl_limit);
880 }
881
882 nla_nest_end(msg, nl_limits);
883
David S. Miller9360ffd2012-03-29 04:41:26 -0400884 if (c->beacon_int_infra_match &&
885 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
886 goto nla_put_failure;
887 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
888 c->num_different_channels) ||
889 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
890 c->max_interfaces))
891 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100892 if (large &&
893 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
894 c->radar_detect_widths))
895 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200896
897 nla_nest_end(msg, nl_combi);
898 }
899
900 nla_nest_end(msg, nl_combis);
901
902 return 0;
903nla_put_failure:
904 return -ENOBUFS;
905}
906
Johannes Berg3713b4e2013-02-14 16:19:38 +0100907#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100908static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
909 struct sk_buff *msg)
910{
911 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
912 struct nlattr *nl_tcp;
913
914 if (!tcp)
915 return 0;
916
917 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
918 if (!nl_tcp)
919 return -ENOBUFS;
920
921 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
922 tcp->data_payload_max))
923 return -ENOBUFS;
924
925 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
926 tcp->data_payload_max))
927 return -ENOBUFS;
928
929 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
930 return -ENOBUFS;
931
932 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
933 sizeof(*tcp->tok), tcp->tok))
934 return -ENOBUFS;
935
936 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
937 tcp->data_interval_max))
938 return -ENOBUFS;
939
940 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
941 tcp->wake_payload_max))
942 return -ENOBUFS;
943
944 nla_nest_end(msg, nl_tcp);
945 return 0;
946}
947
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100949 struct cfg80211_registered_device *dev,
950 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100951{
952 struct nlattr *nl_wowlan;
953
954 if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns)
955 return 0;
956
957 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
958 if (!nl_wowlan)
959 return -ENOBUFS;
960
961 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
962 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
963 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
964 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
965 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
966 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
967 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
968 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
969 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
970 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
971 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
972 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
973 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
974 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
975 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
977 return -ENOBUFS;
978
979 if (dev->wiphy.wowlan.n_patterns) {
980 struct nl80211_wowlan_pattern_support pat = {
981 .max_patterns = dev->wiphy.wowlan.n_patterns,
982 .min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
983 .max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
984 .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset,
985 };
986
987 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
988 sizeof(pat), &pat))
989 return -ENOBUFS;
990 }
991
Johannes Bergb56cf722013-02-20 01:02:38 +0100992 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
993 return -ENOBUFS;
994
Johannes Berg3713b4e2013-02-14 16:19:38 +0100995 nla_nest_end(msg, nl_wowlan);
996
997 return 0;
998}
999#endif
1000
1001static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1002 struct ieee80211_supported_band *sband)
1003{
1004 struct nlattr *nl_rates, *nl_rate;
1005 struct ieee80211_rate *rate;
1006 int i;
1007
1008 /* add HT info */
1009 if (sband->ht_cap.ht_supported &&
1010 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1011 sizeof(sband->ht_cap.mcs),
1012 &sband->ht_cap.mcs) ||
1013 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1014 sband->ht_cap.cap) ||
1015 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1016 sband->ht_cap.ampdu_factor) ||
1017 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1018 sband->ht_cap.ampdu_density)))
1019 return -ENOBUFS;
1020
1021 /* add VHT info */
1022 if (sband->vht_cap.vht_supported &&
1023 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1024 sizeof(sband->vht_cap.vht_mcs),
1025 &sband->vht_cap.vht_mcs) ||
1026 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1027 sband->vht_cap.cap)))
1028 return -ENOBUFS;
1029
1030 /* add bitrates */
1031 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1032 if (!nl_rates)
1033 return -ENOBUFS;
1034
1035 for (i = 0; i < sband->n_bitrates; i++) {
1036 nl_rate = nla_nest_start(msg, i);
1037 if (!nl_rate)
1038 return -ENOBUFS;
1039
1040 rate = &sband->bitrates[i];
1041 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1042 rate->bitrate))
1043 return -ENOBUFS;
1044 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1045 nla_put_flag(msg,
1046 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1047 return -ENOBUFS;
1048
1049 nla_nest_end(msg, nl_rate);
1050 }
1051
1052 nla_nest_end(msg, nl_rates);
1053
1054 return 0;
1055}
1056
1057static int
1058nl80211_send_mgmt_stypes(struct sk_buff *msg,
1059 const struct ieee80211_txrx_stypes *mgmt_stypes)
1060{
1061 u16 stypes;
1062 struct nlattr *nl_ftypes, *nl_ifs;
1063 enum nl80211_iftype ift;
1064 int i;
1065
1066 if (!mgmt_stypes)
1067 return 0;
1068
1069 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1070 if (!nl_ifs)
1071 return -ENOBUFS;
1072
1073 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1074 nl_ftypes = nla_nest_start(msg, ift);
1075 if (!nl_ftypes)
1076 return -ENOBUFS;
1077 i = 0;
1078 stypes = mgmt_stypes[ift].tx;
1079 while (stypes) {
1080 if ((stypes & 1) &&
1081 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1082 (i << 4) | IEEE80211_FTYPE_MGMT))
1083 return -ENOBUFS;
1084 stypes >>= 1;
1085 i++;
1086 }
1087 nla_nest_end(msg, nl_ftypes);
1088 }
1089
1090 nla_nest_end(msg, nl_ifs);
1091
1092 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1093 if (!nl_ifs)
1094 return -ENOBUFS;
1095
1096 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1097 nl_ftypes = nla_nest_start(msg, ift);
1098 if (!nl_ftypes)
1099 return -ENOBUFS;
1100 i = 0;
1101 stypes = mgmt_stypes[ift].rx;
1102 while (stypes) {
1103 if ((stypes & 1) &&
1104 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1105 (i << 4) | IEEE80211_FTYPE_MGMT))
1106 return -ENOBUFS;
1107 stypes >>= 1;
1108 i++;
1109 }
1110 nla_nest_end(msg, nl_ftypes);
1111 }
1112 nla_nest_end(msg, nl_ifs);
1113
1114 return 0;
1115}
1116
1117static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1118 struct sk_buff *msg, u32 portid, u32 seq,
1119 int flags, bool split, long *split_start,
1120 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001121{
1122 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001123 struct nlattr *nl_bands, *nl_band;
1124 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001125 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001126 enum ieee80211_band band;
1127 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001128 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001129 const struct ieee80211_txrx_stypes *mgmt_stypes =
1130 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001131 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001132 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001133
Eric W. Biederman15e47302012-09-07 20:12:54 +00001134 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001135 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001136 return -ENOBUFS;
1137
1138 /* allow always using the variables */
1139 if (!split) {
1140 split_start = &start;
1141 band_start = &start_band;
1142 chan_start = &start_chan;
1143 }
Johannes Berg55682962007-09-20 13:09:35 -04001144
David S. Miller9360ffd2012-03-29 04:41:26 -04001145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1147 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001148 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001150 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001151
Johannes Berg3713b4e2013-02-14 16:19:38 +01001152 switch (*split_start) {
1153 case 0:
1154 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1155 dev->wiphy.retry_short) ||
1156 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1157 dev->wiphy.retry_long) ||
1158 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1159 dev->wiphy.frag_threshold) ||
1160 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1161 dev->wiphy.rts_threshold) ||
1162 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1163 dev->wiphy.coverage_class) ||
1164 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1165 dev->wiphy.max_scan_ssids) ||
1166 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1167 dev->wiphy.max_sched_scan_ssids) ||
1168 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1169 dev->wiphy.max_scan_ie_len) ||
1170 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1171 dev->wiphy.max_sched_scan_ie_len) ||
1172 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1173 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001174 goto nla_put_failure;
1175
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1178 goto nla_put_failure;
1179 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1180 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1181 goto nla_put_failure;
1182 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1183 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1184 goto nla_put_failure;
1185 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1186 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1187 goto nla_put_failure;
1188 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1189 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1190 goto nla_put_failure;
1191 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1192 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001193 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001194
Johannes Berg3713b4e2013-02-14 16:19:38 +01001195 (*split_start)++;
1196 if (split)
1197 break;
1198 case 1:
1199 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1200 sizeof(u32) * dev->wiphy.n_cipher_suites,
1201 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001202 goto nla_put_failure;
1203
Johannes Berg3713b4e2013-02-14 16:19:38 +01001204 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1205 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001206 goto nla_put_failure;
1207
Johannes Berg3713b4e2013-02-14 16:19:38 +01001208 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1209 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1210 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001211
Johannes Berg3713b4e2013-02-14 16:19:38 +01001212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1213 dev->wiphy.available_antennas_tx) ||
1214 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1215 dev->wiphy.available_antennas_rx))
1216 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001217
Johannes Berg3713b4e2013-02-14 16:19:38 +01001218 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1219 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1220 dev->wiphy.probe_resp_offload))
1221 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001222
Johannes Berg3713b4e2013-02-14 16:19:38 +01001223 if ((dev->wiphy.available_antennas_tx ||
1224 dev->wiphy.available_antennas_rx) &&
1225 dev->ops->get_antenna) {
1226 u32 tx_ant = 0, rx_ant = 0;
1227 int res;
1228 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1229 if (!res) {
1230 if (nla_put_u32(msg,
1231 NL80211_ATTR_WIPHY_ANTENNA_TX,
1232 tx_ant) ||
1233 nla_put_u32(msg,
1234 NL80211_ATTR_WIPHY_ANTENNA_RX,
1235 rx_ant))
1236 goto nla_put_failure;
1237 }
Johannes Bergee688b002008-01-24 19:38:39 +01001238 }
1239
Johannes Berg3713b4e2013-02-14 16:19:38 +01001240 (*split_start)++;
1241 if (split)
1242 break;
1243 case 2:
1244 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1245 dev->wiphy.interface_modes))
1246 goto nla_put_failure;
1247 (*split_start)++;
1248 if (split)
1249 break;
1250 case 3:
1251 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1252 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001253 goto nla_put_failure;
1254
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1256 struct ieee80211_supported_band *sband;
1257
1258 sband = dev->wiphy.bands[band];
1259
1260 if (!sband)
1261 continue;
1262
1263 nl_band = nla_nest_start(msg, band);
1264 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001265 goto nla_put_failure;
1266
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 switch (*chan_start) {
1268 case 0:
1269 if (nl80211_send_band_rateinfo(msg, sband))
1270 goto nla_put_failure;
1271 (*chan_start)++;
1272 if (split)
1273 break;
1274 default:
1275 /* add frequencies */
1276 nl_freqs = nla_nest_start(
1277 msg, NL80211_BAND_ATTR_FREQS);
1278 if (!nl_freqs)
1279 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001280
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 for (i = *chan_start - 1;
1282 i < sband->n_channels;
1283 i++) {
1284 nl_freq = nla_nest_start(msg, i);
1285 if (!nl_freq)
1286 goto nla_put_failure;
1287
1288 chan = &sband->channels[i];
1289
Johannes Bergcdc89b92013-02-18 23:54:36 +01001290 if (nl80211_msg_put_channel(msg, chan,
1291 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 goto nla_put_failure;
1293
1294 nla_nest_end(msg, nl_freq);
1295 if (split)
1296 break;
1297 }
1298 if (i < sband->n_channels)
1299 *chan_start = i + 2;
1300 else
1301 *chan_start = 0;
1302 nla_nest_end(msg, nl_freqs);
1303 }
1304
1305 nla_nest_end(msg, nl_band);
1306
1307 if (split) {
1308 /* start again here */
1309 if (*chan_start)
1310 band--;
1311 break;
1312 }
Johannes Bergee688b002008-01-24 19:38:39 +01001313 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001315
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 if (band < IEEE80211_NUM_BANDS)
1317 *band_start = band + 1;
1318 else
1319 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001320
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 /* if bands & channels are done, continue outside */
1322 if (*band_start == 0 && *chan_start == 0)
1323 (*split_start)++;
1324 if (split)
1325 break;
1326 case 4:
1327 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1328 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001329 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330
1331 i = 0;
1332#define CMD(op, n) \
1333 do { \
1334 if (dev->ops->op) { \
1335 i++; \
1336 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1337 goto nla_put_failure; \
1338 } \
1339 } while (0)
1340
1341 CMD(add_virtual_intf, NEW_INTERFACE);
1342 CMD(change_virtual_intf, SET_INTERFACE);
1343 CMD(add_key, NEW_KEY);
1344 CMD(start_ap, START_AP);
1345 CMD(add_station, NEW_STATION);
1346 CMD(add_mpath, NEW_MPATH);
1347 CMD(update_mesh_config, SET_MESH_CONFIG);
1348 CMD(change_bss, SET_BSS);
1349 CMD(auth, AUTHENTICATE);
1350 CMD(assoc, ASSOCIATE);
1351 CMD(deauth, DEAUTHENTICATE);
1352 CMD(disassoc, DISASSOCIATE);
1353 CMD(join_ibss, JOIN_IBSS);
1354 CMD(join_mesh, JOIN_MESH);
1355 CMD(set_pmksa, SET_PMKSA);
1356 CMD(del_pmksa, DEL_PMKSA);
1357 CMD(flush_pmksa, FLUSH_PMKSA);
1358 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1359 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1360 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1361 CMD(mgmt_tx, FRAME);
1362 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1363 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1364 i++;
1365 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1366 goto nla_put_failure;
1367 }
1368 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1369 dev->ops->join_mesh) {
1370 i++;
1371 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1372 goto nla_put_failure;
1373 }
1374 CMD(set_wds_peer, SET_WDS_PEER);
1375 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1376 CMD(tdls_mgmt, TDLS_MGMT);
1377 CMD(tdls_oper, TDLS_OPER);
1378 }
1379 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1380 CMD(sched_scan_start, START_SCHED_SCAN);
1381 CMD(probe_client, PROBE_CLIENT);
1382 CMD(set_noack_map, SET_NOACK_MAP);
1383 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1384 i++;
1385 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1386 goto nla_put_failure;
1387 }
1388 CMD(start_p2p_device, START_P2P_DEVICE);
1389 CMD(set_mcast_rate, SET_MCAST_RATE);
Arend van Spriel5de17982013-04-18 15:49:00 +02001390 if (split) {
1391 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1392 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1393 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001394
Kalle Valo4745fc02011-11-17 19:06:10 +02001395#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001396 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001397#endif
1398
Johannes Berg8fdc6212009-03-14 09:34:01 +01001399#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001400
Johannes Berg3713b4e2013-02-14 16:19:38 +01001401 if (dev->ops->connect || dev->ops->auth) {
1402 i++;
1403 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001404 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001405 }
1406
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 if (dev->ops->disconnect || dev->ops->deauth) {
1408 i++;
1409 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1410 goto nla_put_failure;
1411 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001412
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 nla_nest_end(msg, nl_cmds);
1414 (*split_start)++;
1415 if (split)
1416 break;
1417 case 5:
1418 if (dev->ops->remain_on_channel &&
1419 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1420 nla_put_u32(msg,
1421 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1422 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001423 goto nla_put_failure;
1424
Johannes Berg3713b4e2013-02-14 16:19:38 +01001425 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1426 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1427 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001428
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1430 goto nla_put_failure;
1431 (*split_start)++;
1432 if (split)
1433 break;
1434 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001435#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001436 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 goto nla_put_failure;
1438 (*split_start)++;
1439 if (split)
1440 break;
1441#else
1442 (*split_start)++;
1443#endif
1444 case 7:
1445 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1446 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001447 goto nla_put_failure;
1448
Johannes Bergcdc89b92013-02-18 23:54:36 +01001449 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001451
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 (*split_start)++;
1453 if (split)
1454 break;
1455 case 8:
1456 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1457 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1458 dev->wiphy.ap_sme_capa))
1459 goto nla_put_failure;
1460
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001461 features = dev->wiphy.features;
1462 /*
1463 * We can only add the per-channel limit information if the
1464 * dump is split, otherwise it makes it too big. Therefore
1465 * only advertise it in that case.
1466 */
1467 if (split)
1468 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1469 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 goto nla_put_failure;
1471
1472 if (dev->wiphy.ht_capa_mod_mask &&
1473 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1474 sizeof(*dev->wiphy.ht_capa_mod_mask),
1475 dev->wiphy.ht_capa_mod_mask))
1476 goto nla_put_failure;
1477
1478 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1479 dev->wiphy.max_acl_mac_addrs &&
1480 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1481 dev->wiphy.max_acl_mac_addrs))
1482 goto nla_put_failure;
1483
1484 /*
1485 * Any information below this point is only available to
1486 * applications that can deal with it being split. This
1487 * helps ensure that newly added capabilities don't break
1488 * older tools by overrunning their buffers.
1489 *
1490 * We still increment split_start so that in the split
1491 * case we'll continue with more data in the next round,
1492 * but break unconditionally so unsplit data stops here.
1493 */
1494 (*split_start)++;
1495 break;
1496 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001497 if (dev->wiphy.extended_capabilities &&
1498 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1499 dev->wiphy.extended_capabilities_len,
1500 dev->wiphy.extended_capabilities) ||
1501 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1502 dev->wiphy.extended_capabilities_len,
1503 dev->wiphy.extended_capabilities_mask)))
1504 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505
Johannes Bergee2aca32013-02-21 17:36:01 +01001506 if (dev->wiphy.vht_capa_mod_mask &&
1507 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1508 sizeof(*dev->wiphy.vht_capa_mod_mask),
1509 dev->wiphy.vht_capa_mod_mask))
1510 goto nla_put_failure;
1511
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 /* done */
1513 *split_start = 0;
1514 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001515 }
Johannes Berg55682962007-09-20 13:09:35 -04001516 return genlmsg_end(msg, hdr);
1517
1518 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001519 genlmsg_cancel(msg, hdr);
1520 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001521}
1522
1523static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1524{
Johannes Berg645e77d2013-03-01 14:03:49 +01001525 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001526 int start = cb->args[0];
1527 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 s64 filter_wiphy = -1;
1529 bool split = false;
1530 struct nlattr **tb = nl80211_fam.attrbuf;
1531 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001532
Johannes Berg5fe231e2013-05-08 21:45:15 +02001533 rtnl_lock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1535 tb, nl80211_fam.maxattr, nl80211_policy);
1536 if (res == 0) {
1537 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1538 if (tb[NL80211_ATTR_WIPHY])
1539 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1540 if (tb[NL80211_ATTR_WDEV])
1541 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1542 if (tb[NL80211_ATTR_IFINDEX]) {
1543 struct net_device *netdev;
1544 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1545
1546 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001547 if (!netdev)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 return -ENODEV;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 if (netdev->ieee80211_ptr) {
1550 dev = wiphy_to_dev(
1551 netdev->ieee80211_ptr->wiphy);
1552 filter_wiphy = dev->wiphy_idx;
1553 }
1554 dev_put(netdev);
1555 }
1556 }
1557
Johannes Berg79c97e92009-07-07 03:56:12 +02001558 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001559 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1560 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001561 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001562 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1564 continue;
1565 /* attempt to fit multiple wiphy data chunks into the skb */
1566 do {
1567 ret = nl80211_send_wiphy(dev, skb,
1568 NETLINK_CB(cb->skb).portid,
1569 cb->nlh->nlmsg_seq,
1570 NLM_F_MULTI,
1571 split, &cb->args[1],
1572 &cb->args[2],
1573 &cb->args[3]);
1574 if (ret < 0) {
1575 /*
1576 * If sending the wiphy data didn't fit (ENOBUFS
1577 * or EMSGSIZE returned), this SKB is still
1578 * empty (so it's not too big because another
1579 * wiphy dataset is already in the skb) and
1580 * we've not tried to adjust the dump allocation
1581 * yet ... then adjust the alloc size to be
1582 * bigger, and return 1 but with the empty skb.
1583 * This results in an empty message being RX'ed
1584 * in userspace, but that is ignored.
1585 *
1586 * We can then retry with the larger buffer.
1587 */
1588 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1589 !skb->len &&
1590 cb->min_dump_alloc < 4096) {
1591 cb->min_dump_alloc = 4096;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 return 1;
1593 }
1594 idx--;
1595 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001596 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 } while (cb->args[1] > 0);
1598 break;
Johannes Berg55682962007-09-20 13:09:35 -04001599 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001600 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001601
1602 cb->args[0] = idx;
1603
1604 return skb->len;
1605}
1606
1607static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1608{
1609 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001610 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001611
Johannes Berg645e77d2013-03-01 14:03:49 +01001612 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001613 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001614 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001615
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1617 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001618 nlmsg_free(msg);
1619 return -ENOBUFS;
1620 }
Johannes Berg55682962007-09-20 13:09:35 -04001621
Johannes Berg134e6372009-07-10 09:51:34 +00001622 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001623}
1624
Jouni Malinen31888482008-10-30 16:59:24 +02001625static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1626 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1627 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1628 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1629 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1630 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1631};
1632
1633static int parse_txq_params(struct nlattr *tb[],
1634 struct ieee80211_txq_params *txq_params)
1635{
Johannes Berga3304b02012-03-28 11:04:24 +02001636 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001637 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1638 !tb[NL80211_TXQ_ATTR_AIFS])
1639 return -EINVAL;
1640
Johannes Berga3304b02012-03-28 11:04:24 +02001641 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001642 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1643 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1644 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1645 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1646
Johannes Berga3304b02012-03-28 11:04:24 +02001647 if (txq_params->ac >= NL80211_NUM_ACS)
1648 return -EINVAL;
1649
Jouni Malinen31888482008-10-30 16:59:24 +02001650 return 0;
1651}
1652
Johannes Bergf444de02010-05-05 15:25:02 +02001653static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1654{
1655 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001656 * You can only set the channel explicitly for WDS interfaces,
1657 * all others have their channel managed via their respective
1658 * "establish a connection" command (connect, join, ...)
1659 *
1660 * For AP/GO and mesh mode, the channel can be set with the
1661 * channel userspace API, but is only stored and passed to the
1662 * low-level driver when the AP starts or the mesh is joined.
1663 * This is for backward compatibility, userspace can also give
1664 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001665 *
1666 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001667 * whatever else is going on, so they have their own special
1668 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001669 */
1670 return !wdev ||
1671 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001672 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001673 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1674 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001675}
1676
Johannes Berg683b6d32012-11-08 21:25:48 +01001677static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1678 struct genl_info *info,
1679 struct cfg80211_chan_def *chandef)
1680{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301681 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001682
1683 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1684 return -EINVAL;
1685
1686 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1687
1688 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001689 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1690 chandef->center_freq1 = control_freq;
1691 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001692
1693 /* Primary channel not allowed */
1694 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1695 return -EINVAL;
1696
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001697 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1698 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001699
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001700 chantype = nla_get_u32(
1701 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1702
1703 switch (chantype) {
1704 case NL80211_CHAN_NO_HT:
1705 case NL80211_CHAN_HT20:
1706 case NL80211_CHAN_HT40PLUS:
1707 case NL80211_CHAN_HT40MINUS:
1708 cfg80211_chandef_create(chandef, chandef->chan,
1709 chantype);
1710 break;
1711 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001712 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001713 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001714 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1715 chandef->width =
1716 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1717 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1718 chandef->center_freq1 =
1719 nla_get_u32(
1720 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1721 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1722 chandef->center_freq2 =
1723 nla_get_u32(
1724 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1725 }
1726
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001727 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001728 return -EINVAL;
1729
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001730 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1731 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001732 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001733
Johannes Berg683b6d32012-11-08 21:25:48 +01001734 return 0;
1735}
1736
Johannes Bergf444de02010-05-05 15:25:02 +02001737static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1738 struct wireless_dev *wdev,
1739 struct genl_info *info)
1740{
Johannes Berg683b6d32012-11-08 21:25:48 +01001741 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001742 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001743 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1744
1745 if (wdev)
1746 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001747
Johannes Bergf444de02010-05-05 15:25:02 +02001748 if (!nl80211_can_set_dev_channel(wdev))
1749 return -EOPNOTSUPP;
1750
Johannes Berg683b6d32012-11-08 21:25:48 +01001751 result = nl80211_parse_chandef(rdev, info, &chandef);
1752 if (result)
1753 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001754
Johannes Berge8c9bd52012-06-06 08:18:22 +02001755 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001756 case NL80211_IFTYPE_AP:
1757 case NL80211_IFTYPE_P2P_GO:
1758 if (wdev->beacon_interval) {
1759 result = -EBUSY;
1760 break;
1761 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001762 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001763 result = -EINVAL;
1764 break;
1765 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001766 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001767 result = 0;
1768 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001769 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001771 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001772 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001773 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001774 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001775 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001776 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001777 }
Johannes Bergf444de02010-05-05 15:25:02 +02001778
1779 return result;
1780}
1781
1782static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1783{
Johannes Berg4c476992010-10-04 21:36:35 +02001784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1785 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001786
Johannes Berg4c476992010-10-04 21:36:35 +02001787 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001788}
1789
Bill Jordane8347eb2010-10-01 13:54:28 -04001790static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1791{
Johannes Berg43b19952010-10-07 13:10:30 +02001792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1793 struct net_device *dev = info->user_ptr[1];
1794 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001795 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001796
1797 if (!info->attrs[NL80211_ATTR_MAC])
1798 return -EINVAL;
1799
Johannes Berg43b19952010-10-07 13:10:30 +02001800 if (netif_running(dev))
1801 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001802
Johannes Berg43b19952010-10-07 13:10:30 +02001803 if (!rdev->ops->set_wds_peer)
1804 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001805
Johannes Berg43b19952010-10-07 13:10:30 +02001806 if (wdev->iftype != NL80211_IFTYPE_WDS)
1807 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001808
1809 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001810 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001811}
1812
1813
Johannes Berg55682962007-09-20 13:09:35 -04001814static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1815{
1816 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001817 struct net_device *netdev = NULL;
1818 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001819 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001820 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001821 u32 changed;
1822 u8 retry_short = 0, retry_long = 0;
1823 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001824 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001825
Johannes Berg5fe231e2013-05-08 21:45:15 +02001826 ASSERT_RTNL();
1827
Johannes Bergf444de02010-05-05 15:25:02 +02001828 /*
1829 * Try to find the wiphy and netdev. Normally this
1830 * function shouldn't need the netdev, but this is
1831 * done for backward compatibility -- previously
1832 * setting the channel was done per wiphy, but now
1833 * it is per netdev. Previous userland like hostapd
1834 * also passed a netdev to set_wiphy, so that it is
1835 * possible to let that go to the right netdev!
1836 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001837
Johannes Bergf444de02010-05-05 15:25:02 +02001838 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1839 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1840
1841 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001842 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001843 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001844 else
Johannes Bergf444de02010-05-05 15:25:02 +02001845 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001846 }
1847
Johannes Bergf444de02010-05-05 15:25:02 +02001848 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001849 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1850 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001851 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001852 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001853 wdev = NULL;
1854 netdev = NULL;
1855 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001856 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001857 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001858
1859 /*
1860 * end workaround code, by now the rdev is available
1861 * and locked, and wdev may or may not be NULL.
1862 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001863
1864 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001865 result = cfg80211_dev_rename(
1866 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001867
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001868 if (result)
1869 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001870
Jouni Malinen31888482008-10-30 16:59:24 +02001871 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1872 struct ieee80211_txq_params txq_params;
1873 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1874
1875 if (!rdev->ops->set_txq_params) {
1876 result = -EOPNOTSUPP;
1877 goto bad_res;
1878 }
1879
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001880 if (!netdev) {
1881 result = -EINVAL;
1882 goto bad_res;
1883 }
1884
Johannes Berg133a3ff2011-11-03 14:50:13 +01001885 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1886 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1887 result = -EINVAL;
1888 goto bad_res;
1889 }
1890
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001891 if (!netif_running(netdev)) {
1892 result = -ENETDOWN;
1893 goto bad_res;
1894 }
1895
Jouni Malinen31888482008-10-30 16:59:24 +02001896 nla_for_each_nested(nl_txq_params,
1897 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1898 rem_txq_params) {
1899 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1900 nla_data(nl_txq_params),
1901 nla_len(nl_txq_params),
1902 txq_params_policy);
1903 result = parse_txq_params(tb, &txq_params);
1904 if (result)
1905 goto bad_res;
1906
Hila Gonene35e4d22012-06-27 17:19:42 +03001907 result = rdev_set_txq_params(rdev, netdev,
1908 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001909 if (result)
1910 goto bad_res;
1911 }
1912 }
1913
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001914 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001915 result = __nl80211_set_channel(rdev,
1916 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1917 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001918 if (result)
1919 goto bad_res;
1920 }
1921
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001922 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001923 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001924 enum nl80211_tx_power_setting type;
1925 int idx, mbm = 0;
1926
Johannes Bergc8442112012-10-24 10:17:18 +02001927 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1928 txp_wdev = NULL;
1929
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001930 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001931 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001932 goto bad_res;
1933 }
1934
1935 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1936 type = nla_get_u32(info->attrs[idx]);
1937
1938 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1939 (type != NL80211_TX_POWER_AUTOMATIC)) {
1940 result = -EINVAL;
1941 goto bad_res;
1942 }
1943
1944 if (type != NL80211_TX_POWER_AUTOMATIC) {
1945 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1946 mbm = nla_get_u32(info->attrs[idx]);
1947 }
1948
Johannes Bergc8442112012-10-24 10:17:18 +02001949 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001950 if (result)
1951 goto bad_res;
1952 }
1953
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001954 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1955 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1956 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001957 if ((!rdev->wiphy.available_antennas_tx &&
1958 !rdev->wiphy.available_antennas_rx) ||
1959 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001960 result = -EOPNOTSUPP;
1961 goto bad_res;
1962 }
1963
1964 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1965 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1966
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001967 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001968 * available antenna masks, except for the "all" mask */
1969 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1970 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001971 result = -EINVAL;
1972 goto bad_res;
1973 }
1974
Bruno Randolf7f531e02010-12-16 11:30:22 +09001975 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1976 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001977
Hila Gonene35e4d22012-06-27 17:19:42 +03001978 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001979 if (result)
1980 goto bad_res;
1981 }
1982
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001983 changed = 0;
1984
1985 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1986 retry_short = nla_get_u8(
1987 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1988 if (retry_short == 0) {
1989 result = -EINVAL;
1990 goto bad_res;
1991 }
1992 changed |= WIPHY_PARAM_RETRY_SHORT;
1993 }
1994
1995 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1996 retry_long = nla_get_u8(
1997 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1998 if (retry_long == 0) {
1999 result = -EINVAL;
2000 goto bad_res;
2001 }
2002 changed |= WIPHY_PARAM_RETRY_LONG;
2003 }
2004
2005 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2006 frag_threshold = nla_get_u32(
2007 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2008 if (frag_threshold < 256) {
2009 result = -EINVAL;
2010 goto bad_res;
2011 }
2012 if (frag_threshold != (u32) -1) {
2013 /*
2014 * Fragments (apart from the last one) are required to
2015 * have even length. Make the fragmentation code
2016 * simpler by stripping LSB should someone try to use
2017 * odd threshold value.
2018 */
2019 frag_threshold &= ~0x1;
2020 }
2021 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2022 }
2023
2024 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2025 rts_threshold = nla_get_u32(
2026 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2027 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2028 }
2029
Lukáš Turek81077e82009-12-21 22:50:47 +01002030 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2031 coverage_class = nla_get_u8(
2032 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2033 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2034 }
2035
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002036 if (changed) {
2037 u8 old_retry_short, old_retry_long;
2038 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002039 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002040
2041 if (!rdev->ops->set_wiphy_params) {
2042 result = -EOPNOTSUPP;
2043 goto bad_res;
2044 }
2045
2046 old_retry_short = rdev->wiphy.retry_short;
2047 old_retry_long = rdev->wiphy.retry_long;
2048 old_frag_threshold = rdev->wiphy.frag_threshold;
2049 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002050 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002051
2052 if (changed & WIPHY_PARAM_RETRY_SHORT)
2053 rdev->wiphy.retry_short = retry_short;
2054 if (changed & WIPHY_PARAM_RETRY_LONG)
2055 rdev->wiphy.retry_long = retry_long;
2056 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2057 rdev->wiphy.frag_threshold = frag_threshold;
2058 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2059 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002060 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2061 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002062
Hila Gonene35e4d22012-06-27 17:19:42 +03002063 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002064 if (result) {
2065 rdev->wiphy.retry_short = old_retry_short;
2066 rdev->wiphy.retry_long = old_retry_long;
2067 rdev->wiphy.frag_threshold = old_frag_threshold;
2068 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002069 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070 }
2071 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002072
Johannes Berg306d6112008-12-08 12:39:04 +01002073 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002074 if (netdev)
2075 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002076 return result;
2077}
2078
Johannes Berg71bbc992012-06-15 15:30:18 +02002079static inline u64 wdev_id(struct wireless_dev *wdev)
2080{
2081 return (u64)wdev->identifier |
2082 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2083}
Johannes Berg55682962007-09-20 13:09:35 -04002084
Johannes Berg683b6d32012-11-08 21:25:48 +01002085static int nl80211_send_chandef(struct sk_buff *msg,
2086 struct cfg80211_chan_def *chandef)
2087{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002088 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002089
Johannes Berg683b6d32012-11-08 21:25:48 +01002090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2091 chandef->chan->center_freq))
2092 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002093 switch (chandef->width) {
2094 case NL80211_CHAN_WIDTH_20_NOHT:
2095 case NL80211_CHAN_WIDTH_20:
2096 case NL80211_CHAN_WIDTH_40:
2097 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2098 cfg80211_get_chandef_type(chandef)))
2099 return -ENOBUFS;
2100 break;
2101 default:
2102 break;
2103 }
2104 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2105 return -ENOBUFS;
2106 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2107 return -ENOBUFS;
2108 if (chandef->center_freq2 &&
2109 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002110 return -ENOBUFS;
2111 return 0;
2112}
2113
Eric W. Biederman15e47302012-09-07 20:12:54 +00002114static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002115 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002116 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002117{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002118 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002119 void *hdr;
2120
Eric W. Biederman15e47302012-09-07 20:12:54 +00002121 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002122 if (!hdr)
2123 return -1;
2124
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002125 if (dev &&
2126 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002127 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002128 goto nla_put_failure;
2129
2130 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2131 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002132 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002133 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002134 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2135 rdev->devlist_generation ^
2136 (cfg80211_rdev_list_generation << 2)))
2137 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002138
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002139 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002140 int ret;
2141 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002142
Johannes Berg683b6d32012-11-08 21:25:48 +01002143 ret = rdev_get_channel(rdev, wdev, &chandef);
2144 if (ret == 0) {
2145 if (nl80211_send_chandef(msg, &chandef))
2146 goto nla_put_failure;
2147 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002148 }
2149
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002150 if (wdev->ssid_len) {
2151 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2152 goto nla_put_failure;
2153 }
2154
Johannes Berg55682962007-09-20 13:09:35 -04002155 return genlmsg_end(msg, hdr);
2156
2157 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002158 genlmsg_cancel(msg, hdr);
2159 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002160}
2161
2162static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2163{
2164 int wp_idx = 0;
2165 int if_idx = 0;
2166 int wp_start = cb->args[0];
2167 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002168 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002169 struct wireless_dev *wdev;
2170
Johannes Berg5fe231e2013-05-08 21:45:15 +02002171 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002172 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2173 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002174 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002175 if (wp_idx < wp_start) {
2176 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002177 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002178 }
Johannes Berg55682962007-09-20 13:09:35 -04002179 if_idx = 0;
2180
Johannes Berg89a54e42012-06-15 14:33:17 +02002181 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002182 if (if_idx < if_start) {
2183 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002184 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002185 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002186 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002187 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002188 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002189 goto out;
2190 }
2191 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002192 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193
2194 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002195 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002196 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002197 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002198
2199 cb->args[0] = wp_idx;
2200 cb->args[1] = if_idx;
2201
2202 return skb->len;
2203}
2204
2205static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2206{
2207 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002208 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002209 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002210
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002212 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002213 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002214
Eric W. Biederman15e47302012-09-07 20:12:54 +00002215 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002216 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002217 nlmsg_free(msg);
2218 return -ENOBUFS;
2219 }
Johannes Berg55682962007-09-20 13:09:35 -04002220
Johannes Berg134e6372009-07-10 09:51:34 +00002221 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002222}
2223
Michael Wu66f7ac52008-01-31 19:48:22 +01002224static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2225 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2226 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2227 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2228 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2229 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
2230};
2231
2232static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2233{
2234 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2235 int flag;
2236
2237 *mntrflags = 0;
2238
2239 if (!nla)
2240 return -EINVAL;
2241
2242 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2243 nla, mntr_flags_policy))
2244 return -EINVAL;
2245
2246 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2247 if (flags[flag])
2248 *mntrflags |= (1<<flag);
2249
2250 return 0;
2251}
2252
Johannes Berg9bc383d2009-11-19 11:55:19 +01002253static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002254 struct net_device *netdev, u8 use_4addr,
2255 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002256{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002257 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002258 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002259 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002260 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002261 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002262
2263 switch (iftype) {
2264 case NL80211_IFTYPE_AP_VLAN:
2265 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2266 return 0;
2267 break;
2268 case NL80211_IFTYPE_STATION:
2269 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2270 return 0;
2271 break;
2272 default:
2273 break;
2274 }
2275
2276 return -EOPNOTSUPP;
2277}
2278
Johannes Berg55682962007-09-20 13:09:35 -04002279static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2280{
Johannes Berg4c476992010-10-04 21:36:35 +02002281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002282 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002283 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002284 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002285 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002286 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002287 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002288
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002289 memset(&params, 0, sizeof(params));
2290
Johannes Berg04a773a2009-04-19 21:24:32 +02002291 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002292
Johannes Berg723b0382008-09-16 20:22:09 +02002293 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002294 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002295 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002296 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002297 if (ntype > NL80211_IFTYPE_MAX)
2298 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002299 }
2300
Johannes Berg92ffe052008-09-16 20:39:36 +02002301 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002302 struct wireless_dev *wdev = dev->ieee80211_ptr;
2303
Johannes Berg4c476992010-10-04 21:36:35 +02002304 if (ntype != NL80211_IFTYPE_MESH_POINT)
2305 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002306 if (netif_running(dev))
2307 return -EBUSY;
2308
2309 wdev_lock(wdev);
2310 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2311 IEEE80211_MAX_MESH_ID_LEN);
2312 wdev->mesh_id_up_len =
2313 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2314 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2315 wdev->mesh_id_up_len);
2316 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002317 }
2318
Felix Fietkau8b787642009-11-10 18:53:10 +01002319 if (info->attrs[NL80211_ATTR_4ADDR]) {
2320 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2321 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002322 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002323 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002324 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002325 } else {
2326 params.use_4addr = -1;
2327 }
2328
Johannes Berg92ffe052008-09-16 20:39:36 +02002329 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002330 if (ntype != NL80211_IFTYPE_MONITOR)
2331 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002332 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2333 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002334 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002335 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002336
2337 flags = &_flags;
2338 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002339 }
Johannes Berg3b858752009-03-12 09:55:09 +01002340
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002341 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002342 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002343 else
2344 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002345
Johannes Berg9bc383d2009-11-19 11:55:19 +01002346 if (!err && params.use_4addr != -1)
2347 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2348
Johannes Berg55682962007-09-20 13:09:35 -04002349 return err;
2350}
2351
2352static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2353{
Johannes Berg4c476992010-10-04 21:36:35 +02002354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002355 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002356 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002357 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002358 int err;
2359 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002360 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002361
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002362 memset(&params, 0, sizeof(params));
2363
Johannes Berg55682962007-09-20 13:09:35 -04002364 if (!info->attrs[NL80211_ATTR_IFNAME])
2365 return -EINVAL;
2366
2367 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2368 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2369 if (type > NL80211_IFTYPE_MAX)
2370 return -EINVAL;
2371 }
2372
Johannes Berg79c97e92009-07-07 03:56:12 +02002373 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002374 !(rdev->wiphy.interface_modes & (1 << type)))
2375 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002376
Arend van Spriel1c18f142013-01-08 10:17:27 +01002377 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2378 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2379 ETH_ALEN);
2380 if (!is_valid_ether_addr(params.macaddr))
2381 return -EADDRNOTAVAIL;
2382 }
2383
Johannes Berg9bc383d2009-11-19 11:55:19 +01002384 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002385 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002386 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002387 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002388 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002389 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002390
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002391 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2392 if (!msg)
2393 return -ENOMEM;
2394
Michael Wu66f7ac52008-01-31 19:48:22 +01002395 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2396 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2397 &flags);
Hila Gonene35e4d22012-06-27 17:19:42 +03002398 wdev = rdev_add_virtual_intf(rdev,
2399 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2400 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002401 if (IS_ERR(wdev)) {
2402 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002403 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002404 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002405
Johannes Berg98104fde2012-06-16 00:19:54 +02002406 switch (type) {
2407 case NL80211_IFTYPE_MESH_POINT:
2408 if (!info->attrs[NL80211_ATTR_MESH_ID])
2409 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002410 wdev_lock(wdev);
2411 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2412 IEEE80211_MAX_MESH_ID_LEN);
2413 wdev->mesh_id_up_len =
2414 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2415 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2416 wdev->mesh_id_up_len);
2417 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002418 break;
2419 case NL80211_IFTYPE_P2P_DEVICE:
2420 /*
2421 * P2P Device doesn't have a netdev, so doesn't go
2422 * through the netdev notifier and must be added here
2423 */
2424 mutex_init(&wdev->mtx);
2425 INIT_LIST_HEAD(&wdev->event_list);
2426 spin_lock_init(&wdev->event_lock);
2427 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2428 spin_lock_init(&wdev->mgmt_registrations_lock);
2429
Johannes Berg98104fde2012-06-16 00:19:54 +02002430 wdev->identifier = ++rdev->wdev_id;
2431 list_add_rcu(&wdev->list, &rdev->wdev_list);
2432 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002433 break;
2434 default:
2435 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002436 }
2437
Eric W. Biederman15e47302012-09-07 20:12:54 +00002438 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002439 rdev, wdev) < 0) {
2440 nlmsg_free(msg);
2441 return -ENOBUFS;
2442 }
2443
2444 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002445}
2446
2447static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2448{
Johannes Berg4c476992010-10-04 21:36:35 +02002449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002450 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002451
Johannes Berg4c476992010-10-04 21:36:35 +02002452 if (!rdev->ops->del_virtual_intf)
2453 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002454
Johannes Berg84efbb82012-06-16 00:00:26 +02002455 /*
2456 * If we remove a wireless device without a netdev then clear
2457 * user_ptr[1] so that nl80211_post_doit won't dereference it
2458 * to check if it needs to do dev_put(). Otherwise it crashes
2459 * since the wdev has been freed, unlike with a netdev where
2460 * we need the dev_put() for the netdev to really be freed.
2461 */
2462 if (!wdev->netdev)
2463 info->user_ptr[1] = NULL;
2464
Hila Gonene35e4d22012-06-27 17:19:42 +03002465 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002466}
2467
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002468static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2469{
2470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2471 struct net_device *dev = info->user_ptr[1];
2472 u16 noack_map;
2473
2474 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2475 return -EINVAL;
2476
2477 if (!rdev->ops->set_noack_map)
2478 return -EOPNOTSUPP;
2479
2480 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2481
Hila Gonene35e4d22012-06-27 17:19:42 +03002482 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002483}
2484
Johannes Berg41ade002007-12-19 02:03:29 +01002485struct get_key_cookie {
2486 struct sk_buff *msg;
2487 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002488 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002489};
2490
2491static void get_key_callback(void *c, struct key_params *params)
2492{
Johannes Bergb9454e82009-07-08 13:29:08 +02002493 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002494 struct get_key_cookie *cookie = c;
2495
David S. Miller9360ffd2012-03-29 04:41:26 -04002496 if ((params->key &&
2497 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2498 params->key_len, params->key)) ||
2499 (params->seq &&
2500 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2501 params->seq_len, params->seq)) ||
2502 (params->cipher &&
2503 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2504 params->cipher)))
2505 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002506
Johannes Bergb9454e82009-07-08 13:29:08 +02002507 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2508 if (!key)
2509 goto nla_put_failure;
2510
David S. Miller9360ffd2012-03-29 04:41:26 -04002511 if ((params->key &&
2512 nla_put(cookie->msg, NL80211_KEY_DATA,
2513 params->key_len, params->key)) ||
2514 (params->seq &&
2515 nla_put(cookie->msg, NL80211_KEY_SEQ,
2516 params->seq_len, params->seq)) ||
2517 (params->cipher &&
2518 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2519 params->cipher)))
2520 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002521
David S. Miller9360ffd2012-03-29 04:41:26 -04002522 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2523 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002524
2525 nla_nest_end(cookie->msg, key);
2526
Johannes Berg41ade002007-12-19 02:03:29 +01002527 return;
2528 nla_put_failure:
2529 cookie->error = 1;
2530}
2531
2532static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2533{
Johannes Berg4c476992010-10-04 21:36:35 +02002534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002535 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002536 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002537 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002538 const u8 *mac_addr = NULL;
2539 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002540 struct get_key_cookie cookie = {
2541 .error = 0,
2542 };
2543 void *hdr;
2544 struct sk_buff *msg;
2545
2546 if (info->attrs[NL80211_ATTR_KEY_IDX])
2547 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2548
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002549 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002550 return -EINVAL;
2551
2552 if (info->attrs[NL80211_ATTR_MAC])
2553 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2554
Johannes Berge31b8212010-10-05 19:39:30 +02002555 pairwise = !!mac_addr;
2556 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2557 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2558 if (kt >= NUM_NL80211_KEYTYPES)
2559 return -EINVAL;
2560 if (kt != NL80211_KEYTYPE_GROUP &&
2561 kt != NL80211_KEYTYPE_PAIRWISE)
2562 return -EINVAL;
2563 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2564 }
2565
Johannes Berg4c476992010-10-04 21:36:35 +02002566 if (!rdev->ops->get_key)
2567 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002568
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002570 if (!msg)
2571 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002572
Eric W. Biederman15e47302012-09-07 20:12:54 +00002573 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002574 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002575 if (IS_ERR(hdr))
2576 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002577
2578 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002579 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002580
David S. Miller9360ffd2012-03-29 04:41:26 -04002581 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2582 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2583 goto nla_put_failure;
2584 if (mac_addr &&
2585 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2586 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002587
Johannes Berge31b8212010-10-05 19:39:30 +02002588 if (pairwise && mac_addr &&
2589 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2590 return -ENOENT;
2591
Hila Gonene35e4d22012-06-27 17:19:42 +03002592 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2593 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002594
2595 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002596 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002597
2598 if (cookie.error)
2599 goto nla_put_failure;
2600
2601 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002602 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002603
2604 nla_put_failure:
2605 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002606 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002607 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002608 return err;
2609}
2610
2611static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2612{
Johannes Berg4c476992010-10-04 21:36:35 +02002613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002614 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002615 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002616 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002617
Johannes Bergb9454e82009-07-08 13:29:08 +02002618 err = nl80211_parse_key(info, &key);
2619 if (err)
2620 return err;
2621
2622 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002623 return -EINVAL;
2624
Johannes Bergb9454e82009-07-08 13:29:08 +02002625 /* only support setting default key */
2626 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002627 return -EINVAL;
2628
Johannes Bergfffd0932009-07-08 14:22:54 +02002629 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002630
2631 if (key.def) {
2632 if (!rdev->ops->set_default_key) {
2633 err = -EOPNOTSUPP;
2634 goto out;
2635 }
2636
2637 err = nl80211_key_allowed(dev->ieee80211_ptr);
2638 if (err)
2639 goto out;
2640
Hila Gonene35e4d22012-06-27 17:19:42 +03002641 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002642 key.def_uni, key.def_multi);
2643
2644 if (err)
2645 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002646
Johannes Berg3d23e342009-09-29 23:27:28 +02002647#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002648 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002649#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002650 } else {
2651 if (key.def_uni || !key.def_multi) {
2652 err = -EINVAL;
2653 goto out;
2654 }
2655
2656 if (!rdev->ops->set_default_mgmt_key) {
2657 err = -EOPNOTSUPP;
2658 goto out;
2659 }
2660
2661 err = nl80211_key_allowed(dev->ieee80211_ptr);
2662 if (err)
2663 goto out;
2664
Hila Gonene35e4d22012-06-27 17:19:42 +03002665 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002666 if (err)
2667 goto out;
2668
2669#ifdef CONFIG_CFG80211_WEXT
2670 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2671#endif
2672 }
2673
2674 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002675 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002676
Johannes Berg41ade002007-12-19 02:03:29 +01002677 return err;
2678}
2679
2680static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2681{
Johannes Berg4c476992010-10-04 21:36:35 +02002682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002683 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002684 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002685 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002686 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002687
Johannes Bergb9454e82009-07-08 13:29:08 +02002688 err = nl80211_parse_key(info, &key);
2689 if (err)
2690 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002691
Johannes Bergb9454e82009-07-08 13:29:08 +02002692 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002693 return -EINVAL;
2694
Johannes Berg41ade002007-12-19 02:03:29 +01002695 if (info->attrs[NL80211_ATTR_MAC])
2696 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2697
Johannes Berge31b8212010-10-05 19:39:30 +02002698 if (key.type == -1) {
2699 if (mac_addr)
2700 key.type = NL80211_KEYTYPE_PAIRWISE;
2701 else
2702 key.type = NL80211_KEYTYPE_GROUP;
2703 }
2704
2705 /* for now */
2706 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2707 key.type != NL80211_KEYTYPE_GROUP)
2708 return -EINVAL;
2709
Johannes Berg4c476992010-10-04 21:36:35 +02002710 if (!rdev->ops->add_key)
2711 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002712
Johannes Berge31b8212010-10-05 19:39:30 +02002713 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2714 key.type == NL80211_KEYTYPE_PAIRWISE,
2715 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002716 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002717
2718 wdev_lock(dev->ieee80211_ptr);
2719 err = nl80211_key_allowed(dev->ieee80211_ptr);
2720 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002721 err = rdev_add_key(rdev, dev, key.idx,
2722 key.type == NL80211_KEYTYPE_PAIRWISE,
2723 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002724 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002725
Johannes Berg41ade002007-12-19 02:03:29 +01002726 return err;
2727}
2728
2729static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2730{
Johannes Berg4c476992010-10-04 21:36:35 +02002731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002732 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002733 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002734 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002735 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002736
Johannes Bergb9454e82009-07-08 13:29:08 +02002737 err = nl80211_parse_key(info, &key);
2738 if (err)
2739 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002740
2741 if (info->attrs[NL80211_ATTR_MAC])
2742 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2743
Johannes Berge31b8212010-10-05 19:39:30 +02002744 if (key.type == -1) {
2745 if (mac_addr)
2746 key.type = NL80211_KEYTYPE_PAIRWISE;
2747 else
2748 key.type = NL80211_KEYTYPE_GROUP;
2749 }
2750
2751 /* for now */
2752 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2753 key.type != NL80211_KEYTYPE_GROUP)
2754 return -EINVAL;
2755
Johannes Berg4c476992010-10-04 21:36:35 +02002756 if (!rdev->ops->del_key)
2757 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002758
Johannes Bergfffd0932009-07-08 14:22:54 +02002759 wdev_lock(dev->ieee80211_ptr);
2760 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002761
2762 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2763 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2764 err = -ENOENT;
2765
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002767 err = rdev_del_key(rdev, dev, key.idx,
2768 key.type == NL80211_KEYTYPE_PAIRWISE,
2769 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Johannes Berg3d23e342009-09-29 23:27:28 +02002771#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002772 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002773 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002774 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002776 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2777 }
2778#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002779 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002780
Johannes Berg41ade002007-12-19 02:03:29 +01002781 return err;
2782}
2783
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302784/* This function returns an error or the number of nested attributes */
2785static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2786{
2787 struct nlattr *attr;
2788 int n_entries = 0, tmp;
2789
2790 nla_for_each_nested(attr, nl_attr, tmp) {
2791 if (nla_len(attr) != ETH_ALEN)
2792 return -EINVAL;
2793
2794 n_entries++;
2795 }
2796
2797 return n_entries;
2798}
2799
2800/*
2801 * This function parses ACL information and allocates memory for ACL data.
2802 * On successful return, the calling function is responsible to free the
2803 * ACL buffer returned by this function.
2804 */
2805static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2806 struct genl_info *info)
2807{
2808 enum nl80211_acl_policy acl_policy;
2809 struct nlattr *attr;
2810 struct cfg80211_acl_data *acl;
2811 int i = 0, n_entries, tmp;
2812
2813 if (!wiphy->max_acl_mac_addrs)
2814 return ERR_PTR(-EOPNOTSUPP);
2815
2816 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2817 return ERR_PTR(-EINVAL);
2818
2819 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2820 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2821 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2822 return ERR_PTR(-EINVAL);
2823
2824 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2825 return ERR_PTR(-EINVAL);
2826
2827 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2828 if (n_entries < 0)
2829 return ERR_PTR(n_entries);
2830
2831 if (n_entries > wiphy->max_acl_mac_addrs)
2832 return ERR_PTR(-ENOTSUPP);
2833
2834 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2835 GFP_KERNEL);
2836 if (!acl)
2837 return ERR_PTR(-ENOMEM);
2838
2839 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2840 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2841 i++;
2842 }
2843
2844 acl->n_acl_entries = n_entries;
2845 acl->acl_policy = acl_policy;
2846
2847 return acl;
2848}
2849
2850static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2851{
2852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2853 struct net_device *dev = info->user_ptr[1];
2854 struct cfg80211_acl_data *acl;
2855 int err;
2856
2857 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2858 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2859 return -EOPNOTSUPP;
2860
2861 if (!dev->ieee80211_ptr->beacon_interval)
2862 return -EINVAL;
2863
2864 acl = parse_acl_data(&rdev->wiphy, info);
2865 if (IS_ERR(acl))
2866 return PTR_ERR(acl);
2867
2868 err = rdev_set_mac_acl(rdev, dev, acl);
2869
2870 kfree(acl);
2871
2872 return err;
2873}
2874
Johannes Berg88600202012-02-13 15:17:18 +01002875static int nl80211_parse_beacon(struct genl_info *info,
2876 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002877{
Johannes Berg88600202012-02-13 15:17:18 +01002878 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002879
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002880 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2881 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2882 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2883 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002884 return -EINVAL;
2885
Johannes Berg88600202012-02-13 15:17:18 +01002886 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002887
Johannes Berged1b6cc2007-12-19 02:03:32 +01002888 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002889 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2890 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2891 if (!bcn->head_len)
2892 return -EINVAL;
2893 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002894 }
2895
2896 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002897 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2898 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002899 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002900 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002901 }
2902
Johannes Berg4c476992010-10-04 21:36:35 +02002903 if (!haveinfo)
2904 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002905
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002906 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002907 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2908 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002909 }
2910
2911 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002912 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002913 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002914 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002915 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2916 }
2917
2918 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002919 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002920 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002921 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002922 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2923 }
2924
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002925 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002926 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002927 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002928 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002929 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2930 }
2931
Johannes Berg88600202012-02-13 15:17:18 +01002932 return 0;
2933}
2934
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002935static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2936 struct cfg80211_ap_settings *params)
2937{
2938 struct wireless_dev *wdev;
2939 bool ret = false;
2940
Johannes Berg89a54e42012-06-15 14:33:17 +02002941 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002942 if (wdev->iftype != NL80211_IFTYPE_AP &&
2943 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2944 continue;
2945
Johannes Berg683b6d32012-11-08 21:25:48 +01002946 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002947 continue;
2948
Johannes Berg683b6d32012-11-08 21:25:48 +01002949 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002950 ret = true;
2951 break;
2952 }
2953
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002954 return ret;
2955}
2956
Jouni Malinene39e5b52012-09-30 19:29:39 +03002957static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2958 enum nl80211_auth_type auth_type,
2959 enum nl80211_commands cmd)
2960{
2961 if (auth_type > NL80211_AUTHTYPE_MAX)
2962 return false;
2963
2964 switch (cmd) {
2965 case NL80211_CMD_AUTHENTICATE:
2966 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2967 auth_type == NL80211_AUTHTYPE_SAE)
2968 return false;
2969 return true;
2970 case NL80211_CMD_CONNECT:
2971 case NL80211_CMD_START_AP:
2972 /* SAE not supported yet */
2973 if (auth_type == NL80211_AUTHTYPE_SAE)
2974 return false;
2975 return true;
2976 default:
2977 return false;
2978 }
2979}
2980
Johannes Berg88600202012-02-13 15:17:18 +01002981static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2982{
2983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2984 struct net_device *dev = info->user_ptr[1];
2985 struct wireless_dev *wdev = dev->ieee80211_ptr;
2986 struct cfg80211_ap_settings params;
2987 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01002988 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01002989
2990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2991 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2992 return -EOPNOTSUPP;
2993
2994 if (!rdev->ops->start_ap)
2995 return -EOPNOTSUPP;
2996
2997 if (wdev->beacon_interval)
2998 return -EALREADY;
2999
3000 memset(&params, 0, sizeof(params));
3001
3002 /* these are required for START_AP */
3003 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3004 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3005 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3006 return -EINVAL;
3007
3008 err = nl80211_parse_beacon(info, &params.beacon);
3009 if (err)
3010 return err;
3011
3012 params.beacon_interval =
3013 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3014 params.dtim_period =
3015 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3016
3017 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3018 if (err)
3019 return err;
3020
3021 /*
3022 * In theory, some of these attributes should be required here
3023 * but since they were not used when the command was originally
3024 * added, keep them optional for old user space programs to let
3025 * them continue to work with drivers that do not need the
3026 * additional information -- drivers must check!
3027 */
3028 if (info->attrs[NL80211_ATTR_SSID]) {
3029 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3030 params.ssid_len =
3031 nla_len(info->attrs[NL80211_ATTR_SSID]);
3032 if (params.ssid_len == 0 ||
3033 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3034 return -EINVAL;
3035 }
3036
3037 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3038 params.hidden_ssid = nla_get_u32(
3039 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3040 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3041 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3042 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3043 return -EINVAL;
3044 }
3045
3046 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3047
3048 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3049 params.auth_type = nla_get_u32(
3050 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003051 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3052 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003053 return -EINVAL;
3054 } else
3055 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3056
3057 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3058 NL80211_MAX_NR_CIPHER_SUITES);
3059 if (err)
3060 return err;
3061
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303062 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3063 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3064 return -EOPNOTSUPP;
3065 params.inactivity_timeout = nla_get_u16(
3066 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3067 }
3068
Johannes Berg53cabad2012-11-14 15:17:28 +01003069 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3070 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3071 return -EINVAL;
3072 params.p2p_ctwindow =
3073 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3074 if (params.p2p_ctwindow > 127)
3075 return -EINVAL;
3076 if (params.p2p_ctwindow != 0 &&
3077 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3078 return -EINVAL;
3079 }
3080
3081 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3082 u8 tmp;
3083
3084 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3085 return -EINVAL;
3086 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3087 if (tmp > 1)
3088 return -EINVAL;
3089 params.p2p_opp_ps = tmp;
3090 if (params.p2p_opp_ps != 0 &&
3091 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3092 return -EINVAL;
3093 }
3094
Johannes Bergaa430da2012-05-16 23:50:18 +02003095 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003096 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3097 if (err)
3098 return err;
3099 } else if (wdev->preset_chandef.chan) {
3100 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003101 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003102 return -EINVAL;
3103
Johannes Berg683b6d32012-11-08 21:25:48 +01003104 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003105 return -EINVAL;
3106
Simon Wunderlich04f39042013-02-08 18:16:19 +01003107 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3108 if (err < 0)
3109 return err;
3110 if (err) {
3111 radar_detect_width = BIT(params.chandef.width);
3112 params.radar_required = true;
3113 }
3114
Simon Wunderlich04f39042013-02-08 18:16:19 +01003115 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3116 params.chandef.chan,
3117 CHAN_MODE_SHARED,
3118 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003119 if (err)
3120 return err;
3121
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303122 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3123 params.acl = parse_acl_data(&rdev->wiphy, info);
3124 if (IS_ERR(params.acl))
3125 return PTR_ERR(params.acl);
3126 }
3127
Hila Gonene35e4d22012-06-27 17:19:42 +03003128 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003129 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003130 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003131 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003132 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003133 wdev->ssid_len = params.ssid_len;
3134 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003135 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303136
3137 kfree(params.acl);
3138
Johannes Berg56d18932011-05-09 18:41:15 +02003139 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003140}
3141
Johannes Berg88600202012-02-13 15:17:18 +01003142static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3143{
3144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3145 struct net_device *dev = info->user_ptr[1];
3146 struct wireless_dev *wdev = dev->ieee80211_ptr;
3147 struct cfg80211_beacon_data params;
3148 int err;
3149
3150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3151 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3152 return -EOPNOTSUPP;
3153
3154 if (!rdev->ops->change_beacon)
3155 return -EOPNOTSUPP;
3156
3157 if (!wdev->beacon_interval)
3158 return -EINVAL;
3159
3160 err = nl80211_parse_beacon(info, &params);
3161 if (err)
3162 return err;
3163
Hila Gonene35e4d22012-06-27 17:19:42 +03003164 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003165}
3166
3167static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003168{
Johannes Berg4c476992010-10-04 21:36:35 +02003169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3170 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003171
Michal Kazior60771782012-06-29 12:46:56 +02003172 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003173}
3174
Johannes Berg5727ef12007-12-19 02:03:34 +01003175static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3176 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3177 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3178 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003179 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003180 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003181 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003182};
3183
Johannes Bergeccb8e82009-05-11 21:57:56 +03003184static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003185 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003186 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003187{
3188 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003189 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003190 int flag;
3191
Johannes Bergeccb8e82009-05-11 21:57:56 +03003192 /*
3193 * Try parsing the new attribute first so userspace
3194 * can specify both for older kernels.
3195 */
3196 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3197 if (nla) {
3198 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003199
Johannes Bergeccb8e82009-05-11 21:57:56 +03003200 sta_flags = nla_data(nla);
3201 params->sta_flags_mask = sta_flags->mask;
3202 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003203 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003204 if ((params->sta_flags_mask |
3205 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3206 return -EINVAL;
3207 return 0;
3208 }
3209
3210 /* if present, parse the old attribute */
3211
3212 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003213 if (!nla)
3214 return 0;
3215
3216 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3217 nla, sta_flags_policy))
3218 return -EINVAL;
3219
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003220 /*
3221 * Only allow certain flags for interface types so that
3222 * other attributes are silently ignored. Remember that
3223 * this is backward compatibility code with old userspace
3224 * and shouldn't be hit in other cases anyway.
3225 */
3226 switch (iftype) {
3227 case NL80211_IFTYPE_AP:
3228 case NL80211_IFTYPE_AP_VLAN:
3229 case NL80211_IFTYPE_P2P_GO:
3230 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3231 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3232 BIT(NL80211_STA_FLAG_WME) |
3233 BIT(NL80211_STA_FLAG_MFP);
3234 break;
3235 case NL80211_IFTYPE_P2P_CLIENT:
3236 case NL80211_IFTYPE_STATION:
3237 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3238 BIT(NL80211_STA_FLAG_TDLS_PEER);
3239 break;
3240 case NL80211_IFTYPE_MESH_POINT:
3241 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3242 BIT(NL80211_STA_FLAG_MFP) |
3243 BIT(NL80211_STA_FLAG_AUTHORIZED);
3244 default:
3245 return -EINVAL;
3246 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003247
Johannes Berg3383b5a2012-05-10 20:14:43 +02003248 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3249 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003250 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003251
Johannes Berg3383b5a2012-05-10 20:14:43 +02003252 /* no longer support new API additions in old API */
3253 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3254 return -EINVAL;
3255 }
3256 }
3257
Johannes Berg5727ef12007-12-19 02:03:34 +01003258 return 0;
3259}
3260
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003261static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3262 int attr)
3263{
3264 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003265 u32 bitrate;
3266 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003267
3268 rate = nla_nest_start(msg, attr);
3269 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003270 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003271
3272 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3273 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003274 /* report 16-bit bitrate only if we can */
3275 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003276 if (bitrate > 0 &&
3277 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3278 return false;
3279 if (bitrate_compat > 0 &&
3280 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3281 return false;
3282
3283 if (info->flags & RATE_INFO_FLAGS_MCS) {
3284 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3285 return false;
3286 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3287 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3288 return false;
3289 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3290 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3291 return false;
3292 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3293 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3294 return false;
3295 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3296 return false;
3297 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3298 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3299 return false;
3300 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3301 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3302 return false;
3303 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3304 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3305 return false;
3306 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3307 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3308 return false;
3309 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3310 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3311 return false;
3312 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003313
3314 nla_nest_end(msg, rate);
3315 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003316}
3317
Felix Fietkau119363c2013-04-22 16:29:30 +02003318static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3319 int id)
3320{
3321 void *attr;
3322 int i = 0;
3323
3324 if (!mask)
3325 return true;
3326
3327 attr = nla_nest_start(msg, id);
3328 if (!attr)
3329 return false;
3330
3331 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3332 if (!(mask & BIT(i)))
3333 continue;
3334
3335 if (nla_put_u8(msg, i, signal[i]))
3336 return false;
3337 }
3338
3339 nla_nest_end(msg, attr);
3340
3341 return true;
3342}
3343
Eric W. Biederman15e47302012-09-07 20:12:54 +00003344static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003345 int flags,
3346 struct cfg80211_registered_device *rdev,
3347 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003348 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003349{
3350 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003351 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003352
Eric W. Biederman15e47302012-09-07 20:12:54 +00003353 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003354 if (!hdr)
3355 return -1;
3356
David S. Miller9360ffd2012-03-29 04:41:26 -04003357 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3358 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3359 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3360 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003361
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003362 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3363 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003364 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003365 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3366 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3367 sinfo->connected_time))
3368 goto nla_put_failure;
3369 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3370 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3371 sinfo->inactive_time))
3372 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003373 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3374 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003375 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003376 (u32)sinfo->rx_bytes))
3377 goto nla_put_failure;
3378 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003379 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003380 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3381 (u32)sinfo->tx_bytes))
3382 goto nla_put_failure;
3383 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3384 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003385 sinfo->rx_bytes))
3386 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003387 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3388 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003389 sinfo->tx_bytes))
3390 goto nla_put_failure;
3391 if ((sinfo->filled & STATION_INFO_LLID) &&
3392 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3393 goto nla_put_failure;
3394 if ((sinfo->filled & STATION_INFO_PLID) &&
3395 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3396 goto nla_put_failure;
3397 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3398 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3399 sinfo->plink_state))
3400 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003401 switch (rdev->wiphy.signal_type) {
3402 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003403 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3404 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3405 sinfo->signal))
3406 goto nla_put_failure;
3407 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3408 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3409 sinfo->signal_avg))
3410 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003411 break;
3412 default:
3413 break;
3414 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003415 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3416 if (!nl80211_put_signal(msg, sinfo->chains,
3417 sinfo->chain_signal,
3418 NL80211_STA_INFO_CHAIN_SIGNAL))
3419 goto nla_put_failure;
3420 }
3421 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3422 if (!nl80211_put_signal(msg, sinfo->chains,
3423 sinfo->chain_signal_avg,
3424 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3425 goto nla_put_failure;
3426 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003427 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003428 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3429 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003430 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003431 }
3432 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3433 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3434 NL80211_STA_INFO_RX_BITRATE))
3435 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003436 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003437 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3438 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3439 sinfo->rx_packets))
3440 goto nla_put_failure;
3441 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3442 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3443 sinfo->tx_packets))
3444 goto nla_put_failure;
3445 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3446 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3447 sinfo->tx_retries))
3448 goto nla_put_failure;
3449 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3451 sinfo->tx_failed))
3452 goto nla_put_failure;
3453 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3454 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3455 sinfo->beacon_loss_count))
3456 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003457 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3458 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3459 sinfo->local_pm))
3460 goto nla_put_failure;
3461 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3462 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3463 sinfo->peer_pm))
3464 goto nla_put_failure;
3465 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3466 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3467 sinfo->nonpeer_pm))
3468 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003469 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3470 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3471 if (!bss_param)
3472 goto nla_put_failure;
3473
David S. Miller9360ffd2012-03-29 04:41:26 -04003474 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3475 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3476 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3477 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3478 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3479 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3480 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3481 sinfo->bss_param.dtim_period) ||
3482 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3483 sinfo->bss_param.beacon_interval))
3484 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003485
3486 nla_nest_end(msg, bss_param);
3487 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003488 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3489 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3490 sizeof(struct nl80211_sta_flag_update),
3491 &sinfo->sta_flags))
3492 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003493 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3494 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3495 sinfo->t_offset))
3496 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003497 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003498
David S. Miller9360ffd2012-03-29 04:41:26 -04003499 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3500 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3501 sinfo->assoc_req_ies))
3502 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003503
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003504 return genlmsg_end(msg, hdr);
3505
3506 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003507 genlmsg_cancel(msg, hdr);
3508 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003509}
3510
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003511static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003512 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003513{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003514 struct station_info sinfo;
3515 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003516 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003517 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003518 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003519 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003520
Johannes Berg97990a02013-04-19 01:02:55 +02003521 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003522 if (err)
3523 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003524
Johannes Berg97990a02013-04-19 01:02:55 +02003525 if (!wdev->netdev) {
3526 err = -EINVAL;
3527 goto out_err;
3528 }
3529
Johannes Bergbba95fe2008-07-29 13:22:51 +02003530 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003531 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003532 goto out_err;
3533 }
3534
Johannes Bergbba95fe2008-07-29 13:22:51 +02003535 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003536 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003537 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003538 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 if (err == -ENOENT)
3540 break;
3541 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003542 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003543
3544 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003545 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003547 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003548 &sinfo) < 0)
3549 goto out;
3550
3551 sta_idx++;
3552 }
3553
3554
3555 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003556 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003557 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003558 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003559 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003560
3561 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003562}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003563
Johannes Berg5727ef12007-12-19 02:03:34 +01003564static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3565{
Johannes Berg4c476992010-10-04 21:36:35 +02003566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3567 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003568 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003569 struct sk_buff *msg;
3570 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003571 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003572
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003573 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003574
3575 if (!info->attrs[NL80211_ATTR_MAC])
3576 return -EINVAL;
3577
3578 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3579
Johannes Berg4c476992010-10-04 21:36:35 +02003580 if (!rdev->ops->get_station)
3581 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003582
Hila Gonene35e4d22012-06-27 17:19:42 +03003583 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003584 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003585 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003586
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003588 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003589 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003590
Eric W. Biederman15e47302012-09-07 20:12:54 +00003591 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003592 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003593 nlmsg_free(msg);
3594 return -ENOBUFS;
3595 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003596
Johannes Berg4c476992010-10-04 21:36:35 +02003597 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003598}
3599
Johannes Berg77ee7c82013-02-15 00:48:33 +01003600int cfg80211_check_station_change(struct wiphy *wiphy,
3601 struct station_parameters *params,
3602 enum cfg80211_station_type statype)
3603{
3604 if (params->listen_interval != -1)
3605 return -EINVAL;
3606 if (params->aid)
3607 return -EINVAL;
3608
3609 /* When you run into this, adjust the code below for the new flag */
3610 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3611
3612 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003613 case CFG80211_STA_MESH_PEER_KERNEL:
3614 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003615 /*
3616 * No ignoring the TDLS flag here -- the userspace mesh
3617 * code doesn't have the bug of including TDLS in the
3618 * mask everywhere.
3619 */
3620 if (params->sta_flags_mask &
3621 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3622 BIT(NL80211_STA_FLAG_MFP) |
3623 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3624 return -EINVAL;
3625 break;
3626 case CFG80211_STA_TDLS_PEER_SETUP:
3627 case CFG80211_STA_TDLS_PEER_ACTIVE:
3628 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3629 return -EINVAL;
3630 /* ignore since it can't change */
3631 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3632 break;
3633 default:
3634 /* disallow mesh-specific things */
3635 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3636 return -EINVAL;
3637 if (params->local_pm)
3638 return -EINVAL;
3639 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3640 return -EINVAL;
3641 }
3642
3643 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3644 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3645 /* TDLS can't be set, ... */
3646 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3647 return -EINVAL;
3648 /*
3649 * ... but don't bother the driver with it. This works around
3650 * a hostapd/wpa_supplicant issue -- it always includes the
3651 * TLDS_PEER flag in the mask even for AP mode.
3652 */
3653 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3654 }
3655
3656 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3657 /* reject other things that can't change */
3658 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3659 return -EINVAL;
3660 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3661 return -EINVAL;
3662 if (params->supported_rates)
3663 return -EINVAL;
3664 if (params->ext_capab || params->ht_capa || params->vht_capa)
3665 return -EINVAL;
3666 }
3667
3668 if (statype != CFG80211_STA_AP_CLIENT) {
3669 if (params->vlan)
3670 return -EINVAL;
3671 }
3672
3673 switch (statype) {
3674 case CFG80211_STA_AP_MLME_CLIENT:
3675 /* Use this only for authorizing/unauthorizing a station */
3676 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3677 return -EOPNOTSUPP;
3678 break;
3679 case CFG80211_STA_AP_CLIENT:
3680 /* accept only the listed bits */
3681 if (params->sta_flags_mask &
3682 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3683 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3684 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3685 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3686 BIT(NL80211_STA_FLAG_WME) |
3687 BIT(NL80211_STA_FLAG_MFP)))
3688 return -EINVAL;
3689
3690 /* but authenticated/associated only if driver handles it */
3691 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3692 params->sta_flags_mask &
3693 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3694 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3695 return -EINVAL;
3696 break;
3697 case CFG80211_STA_IBSS:
3698 case CFG80211_STA_AP_STA:
3699 /* reject any changes other than AUTHORIZED */
3700 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3701 return -EINVAL;
3702 break;
3703 case CFG80211_STA_TDLS_PEER_SETUP:
3704 /* reject any changes other than AUTHORIZED or WME */
3705 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3706 BIT(NL80211_STA_FLAG_WME)))
3707 return -EINVAL;
3708 /* force (at least) rates when authorizing */
3709 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3710 !params->supported_rates)
3711 return -EINVAL;
3712 break;
3713 case CFG80211_STA_TDLS_PEER_ACTIVE:
3714 /* reject any changes */
3715 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003716 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003717 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3718 return -EINVAL;
3719 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003720 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003721 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3722 return -EINVAL;
3723 break;
3724 }
3725
3726 return 0;
3727}
3728EXPORT_SYMBOL(cfg80211_check_station_change);
3729
Johannes Berg5727ef12007-12-19 02:03:34 +01003730/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003731 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003732 */
Johannes Berg80b99892011-11-18 16:23:01 +01003733static struct net_device *get_vlan(struct genl_info *info,
3734 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003735{
Johannes Berg463d0182009-07-14 00:33:35 +02003736 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003737 struct net_device *v;
3738 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003739
Johannes Berg80b99892011-11-18 16:23:01 +01003740 if (!vlanattr)
3741 return NULL;
3742
3743 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3744 if (!v)
3745 return ERR_PTR(-ENODEV);
3746
3747 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3748 ret = -EINVAL;
3749 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003750 }
Johannes Berg80b99892011-11-18 16:23:01 +01003751
Johannes Berg77ee7c82013-02-15 00:48:33 +01003752 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3753 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3754 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3755 ret = -EINVAL;
3756 goto error;
3757 }
3758
Johannes Berg80b99892011-11-18 16:23:01 +01003759 if (!netif_running(v)) {
3760 ret = -ENETDOWN;
3761 goto error;
3762 }
3763
3764 return v;
3765 error:
3766 dev_put(v);
3767 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003768}
3769
Jouni Malinendf881292013-02-14 21:10:54 +02003770static struct nla_policy
3771nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3772 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3773 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3774};
3775
Johannes Bergff276692013-02-15 00:09:01 +01003776static int nl80211_parse_sta_wme(struct genl_info *info,
3777 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003778{
Jouni Malinendf881292013-02-14 21:10:54 +02003779 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3780 struct nlattr *nla;
3781 int err;
3782
Jouni Malinendf881292013-02-14 21:10:54 +02003783 /* parse WME attributes if present */
3784 if (!info->attrs[NL80211_ATTR_STA_WME])
3785 return 0;
3786
3787 nla = info->attrs[NL80211_ATTR_STA_WME];
3788 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3789 nl80211_sta_wme_policy);
3790 if (err)
3791 return err;
3792
3793 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3794 params->uapsd_queues = nla_get_u8(
3795 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3796 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3797 return -EINVAL;
3798
3799 if (tb[NL80211_STA_WME_MAX_SP])
3800 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3801
3802 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3803 return -EINVAL;
3804
3805 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3806
3807 return 0;
3808}
3809
Johannes Bergff276692013-02-15 00:09:01 +01003810static int nl80211_set_station_tdls(struct genl_info *info,
3811 struct station_parameters *params)
3812{
3813 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003814 if (info->attrs[NL80211_ATTR_PEER_AID])
3815 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003816 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3817 params->ht_capa =
3818 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3819 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3820 params->vht_capa =
3821 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3822
3823 return nl80211_parse_sta_wme(info, params);
3824}
3825
Johannes Berg5727ef12007-12-19 02:03:34 +01003826static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3827{
Johannes Berg4c476992010-10-04 21:36:35 +02003828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003829 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003830 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003831 u8 *mac_addr;
3832 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003833
3834 memset(&params, 0, sizeof(params));
3835
3836 params.listen_interval = -1;
3837
Johannes Berg77ee7c82013-02-15 00:48:33 +01003838 if (!rdev->ops->change_station)
3839 return -EOPNOTSUPP;
3840
Johannes Berg5727ef12007-12-19 02:03:34 +01003841 if (info->attrs[NL80211_ATTR_STA_AID])
3842 return -EINVAL;
3843
3844 if (!info->attrs[NL80211_ATTR_MAC])
3845 return -EINVAL;
3846
3847 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3848
3849 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3850 params.supported_rates =
3851 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3852 params.supported_rates_len =
3853 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3854 }
3855
Jouni Malinen9d62a982013-02-14 21:10:13 +02003856 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3857 params.capability =
3858 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3859 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3860 }
3861
3862 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3863 params.ext_capab =
3864 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3865 params.ext_capab_len =
3866 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3867 }
3868
Jouni Malinendf881292013-02-14 21:10:54 +02003869 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003870 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003871
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003872 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003873 return -EINVAL;
3874
Johannes Bergf8bacc22013-02-14 23:27:01 +01003875 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003876 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003877 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3878 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3879 return -EINVAL;
3880 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003881
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003883 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003884 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3885 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3886 return -EINVAL;
3887 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3888 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003889
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003890 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3891 enum nl80211_mesh_power_mode pm = nla_get_u32(
3892 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3893
3894 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3895 pm > NL80211_MESH_POWER_MAX)
3896 return -EINVAL;
3897
3898 params.local_pm = pm;
3899 }
3900
Johannes Berg77ee7c82013-02-15 00:48:33 +01003901 /* Include parameters for TDLS peer (will check later) */
3902 err = nl80211_set_station_tdls(info, &params);
3903 if (err)
3904 return err;
3905
3906 params.vlan = get_vlan(info, rdev);
3907 if (IS_ERR(params.vlan))
3908 return PTR_ERR(params.vlan);
3909
Johannes Berga97f4422009-06-18 17:23:43 +02003910 switch (dev->ieee80211_ptr->iftype) {
3911 case NL80211_IFTYPE_AP:
3912 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003913 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003914 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003915 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003916 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003917 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003918 break;
3919 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003920 err = -EOPNOTSUPP;
3921 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003922 }
3923
Johannes Berg77ee7c82013-02-15 00:48:33 +01003924 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003925 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003926
Johannes Berg77ee7c82013-02-15 00:48:33 +01003927 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003928 if (params.vlan)
3929 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003930
Johannes Berg5727ef12007-12-19 02:03:34 +01003931 return err;
3932}
3933
3934static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3935{
Johannes Berg4c476992010-10-04 21:36:35 +02003936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003937 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003938 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003939 struct station_parameters params;
3940 u8 *mac_addr = NULL;
3941
3942 memset(&params, 0, sizeof(params));
3943
Johannes Berg984c3112013-02-14 23:43:25 +01003944 if (!rdev->ops->add_station)
3945 return -EOPNOTSUPP;
3946
Johannes Berg5727ef12007-12-19 02:03:34 +01003947 if (!info->attrs[NL80211_ATTR_MAC])
3948 return -EINVAL;
3949
Johannes Berg5727ef12007-12-19 02:03:34 +01003950 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3951 return -EINVAL;
3952
3953 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3954 return -EINVAL;
3955
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003956 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3957 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003958 return -EINVAL;
3959
Johannes Berg5727ef12007-12-19 02:03:34 +01003960 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3961 params.supported_rates =
3962 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3963 params.supported_rates_len =
3964 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3965 params.listen_interval =
3966 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003967
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003968 if (info->attrs[NL80211_ATTR_STA_AID])
3969 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3970 else
3971 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003972 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3973 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003974
Jouni Malinen9d62a982013-02-14 21:10:13 +02003975 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3976 params.capability =
3977 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3978 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3979 }
3980
3981 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3982 params.ext_capab =
3983 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3984 params.ext_capab_len =
3985 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3986 }
3987
Jouni Malinen36aedc92008-08-25 11:58:58 +03003988 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3989 params.ht_capa =
3990 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003991
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003992 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3993 params.vht_capa =
3994 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3995
Johannes Bergf8bacc22013-02-14 23:27:01 +01003996 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07003997 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003998 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3999 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4000 return -EINVAL;
4001 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004002
Johannes Bergff276692013-02-15 00:09:01 +01004003 err = nl80211_parse_sta_wme(info, &params);
4004 if (err)
4005 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004006
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004007 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004008 return -EINVAL;
4009
Johannes Berg77ee7c82013-02-15 00:48:33 +01004010 /* When you run into this, adjust the code below for the new flag */
4011 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4012
Johannes Bergbdd90d52011-12-14 12:20:27 +01004013 switch (dev->ieee80211_ptr->iftype) {
4014 case NL80211_IFTYPE_AP:
4015 case NL80211_IFTYPE_AP_VLAN:
4016 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004017 /* ignore WME attributes if iface/sta is not capable */
4018 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4019 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4020 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004021
Johannes Bergbdd90d52011-12-14 12:20:27 +01004022 /* TDLS peers cannot be added */
4023 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004024 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004025 /* but don't bother the driver with it */
4026 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004027
Johannes Bergd582cff2012-10-26 17:53:44 +02004028 /* allow authenticated/associated only if driver handles it */
4029 if (!(rdev->wiphy.features &
4030 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4031 params.sta_flags_mask &
4032 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4033 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4034 return -EINVAL;
4035
Johannes Bergbdd90d52011-12-14 12:20:27 +01004036 /* must be last in here for error handling */
4037 params.vlan = get_vlan(info, rdev);
4038 if (IS_ERR(params.vlan))
4039 return PTR_ERR(params.vlan);
4040 break;
4041 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004042 /* ignore uAPSD data */
4043 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4044
Johannes Bergd582cff2012-10-26 17:53:44 +02004045 /* associated is disallowed */
4046 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4047 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004048 /* TDLS peers cannot be added */
4049 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004050 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004051 break;
4052 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004053 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004054 /* ignore uAPSD data */
4055 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4056
Johannes Berg77ee7c82013-02-15 00:48:33 +01004057 /* these are disallowed */
4058 if (params.sta_flags_mask &
4059 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4060 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004061 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004062 /* Only TDLS peers can be added */
4063 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4064 return -EINVAL;
4065 /* Can only add if TDLS ... */
4066 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4067 return -EOPNOTSUPP;
4068 /* ... with external setup is supported */
4069 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4070 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004071 /*
4072 * Older wpa_supplicant versions always mark the TDLS peer
4073 * as authorized, but it shouldn't yet be.
4074 */
4075 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004076 break;
4077 default:
4078 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004079 }
4080
Johannes Bergbdd90d52011-12-14 12:20:27 +01004081 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004082
Hila Gonene35e4d22012-06-27 17:19:42 +03004083 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004084
Johannes Berg5727ef12007-12-19 02:03:34 +01004085 if (params.vlan)
4086 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004087 return err;
4088}
4089
4090static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4091{
Johannes Berg4c476992010-10-04 21:36:35 +02004092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4093 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 u8 *mac_addr = NULL;
4095
4096 if (info->attrs[NL80211_ATTR_MAC])
4097 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4098
Johannes Berge80cf852009-05-11 14:43:13 +02004099 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004100 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004101 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4103 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004104
Johannes Berg4c476992010-10-04 21:36:35 +02004105 if (!rdev->ops->del_station)
4106 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004107
Hila Gonene35e4d22012-06-27 17:19:42 +03004108 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004109}
4110
Eric W. Biederman15e47302012-09-07 20:12:54 +00004111static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004112 int flags, struct net_device *dev,
4113 u8 *dst, u8 *next_hop,
4114 struct mpath_info *pinfo)
4115{
4116 void *hdr;
4117 struct nlattr *pinfoattr;
4118
Eric W. Biederman15e47302012-09-07 20:12:54 +00004119 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004120 if (!hdr)
4121 return -1;
4122
David S. Miller9360ffd2012-03-29 04:41:26 -04004123 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4124 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4125 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4126 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4127 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004128
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004129 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4130 if (!pinfoattr)
4131 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004132 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4133 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4134 pinfo->frame_qlen))
4135 goto nla_put_failure;
4136 if (((pinfo->filled & MPATH_INFO_SN) &&
4137 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4138 ((pinfo->filled & MPATH_INFO_METRIC) &&
4139 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4140 pinfo->metric)) ||
4141 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4142 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4143 pinfo->exptime)) ||
4144 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4145 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4146 pinfo->flags)) ||
4147 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4148 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4149 pinfo->discovery_timeout)) ||
4150 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4151 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4152 pinfo->discovery_retries)))
4153 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004154
4155 nla_nest_end(msg, pinfoattr);
4156
4157 return genlmsg_end(msg, hdr);
4158
4159 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004160 genlmsg_cancel(msg, hdr);
4161 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004162}
4163
4164static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004165 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004166{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004167 struct mpath_info pinfo;
4168 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004169 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004170 u8 dst[ETH_ALEN];
4171 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004172 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004173 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174
Johannes Berg97990a02013-04-19 01:02:55 +02004175 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004176 if (err)
4177 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004178
4179 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004180 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004181 goto out_err;
4182 }
4183
Johannes Berg97990a02013-04-19 01:02:55 +02004184 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004185 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004186 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004187 }
4188
Johannes Bergbba95fe2008-07-29 13:22:51 +02004189 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004190 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4191 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004192 if (err == -ENOENT)
4193 break;
4194 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004195 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004196
Eric W. Biederman15e47302012-09-07 20:12:54 +00004197 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004198 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004199 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004200 &pinfo) < 0)
4201 goto out;
4202
4203 path_idx++;
4204 }
4205
4206
4207 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004208 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004209 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004210 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004211 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004212 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004213}
4214
4215static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4216{
Johannes Berg4c476992010-10-04 21:36:35 +02004217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004218 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004219 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004220 struct mpath_info pinfo;
4221 struct sk_buff *msg;
4222 u8 *dst = NULL;
4223 u8 next_hop[ETH_ALEN];
4224
4225 memset(&pinfo, 0, sizeof(pinfo));
4226
4227 if (!info->attrs[NL80211_ATTR_MAC])
4228 return -EINVAL;
4229
4230 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4231
Johannes Berg4c476992010-10-04 21:36:35 +02004232 if (!rdev->ops->get_mpath)
4233 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004234
Johannes Berg4c476992010-10-04 21:36:35 +02004235 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4236 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004237
Hila Gonene35e4d22012-06-27 17:19:42 +03004238 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004239 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004240 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004241
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004243 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004244 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004245
Eric W. Biederman15e47302012-09-07 20:12:54 +00004246 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004247 dev, dst, next_hop, &pinfo) < 0) {
4248 nlmsg_free(msg);
4249 return -ENOBUFS;
4250 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004251
Johannes Berg4c476992010-10-04 21:36:35 +02004252 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004253}
4254
4255static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4256{
Johannes Berg4c476992010-10-04 21:36:35 +02004257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4258 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004259 u8 *dst = NULL;
4260 u8 *next_hop = NULL;
4261
4262 if (!info->attrs[NL80211_ATTR_MAC])
4263 return -EINVAL;
4264
4265 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4266 return -EINVAL;
4267
4268 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4269 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4270
Johannes Berg4c476992010-10-04 21:36:35 +02004271 if (!rdev->ops->change_mpath)
4272 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004273
Johannes Berg4c476992010-10-04 21:36:35 +02004274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4275 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004276
Hila Gonene35e4d22012-06-27 17:19:42 +03004277 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004278}
Johannes Berg4c476992010-10-04 21:36:35 +02004279
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004280static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4281{
Johannes Berg4c476992010-10-04 21:36:35 +02004282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4283 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004284 u8 *dst = NULL;
4285 u8 *next_hop = NULL;
4286
4287 if (!info->attrs[NL80211_ATTR_MAC])
4288 return -EINVAL;
4289
4290 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4291 return -EINVAL;
4292
4293 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4294 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4295
Johannes Berg4c476992010-10-04 21:36:35 +02004296 if (!rdev->ops->add_mpath)
4297 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004298
Johannes Berg4c476992010-10-04 21:36:35 +02004299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4300 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004301
Hila Gonene35e4d22012-06-27 17:19:42 +03004302 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004303}
4304
4305static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4306{
Johannes Berg4c476992010-10-04 21:36:35 +02004307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4308 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004309 u8 *dst = NULL;
4310
4311 if (info->attrs[NL80211_ATTR_MAC])
4312 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4313
Johannes Berg4c476992010-10-04 21:36:35 +02004314 if (!rdev->ops->del_mpath)
4315 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004316
Hila Gonene35e4d22012-06-27 17:19:42 +03004317 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004318}
4319
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004320static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4321{
Johannes Berg4c476992010-10-04 21:36:35 +02004322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4323 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004324 struct bss_parameters params;
4325
4326 memset(&params, 0, sizeof(params));
4327 /* default to not changing parameters */
4328 params.use_cts_prot = -1;
4329 params.use_short_preamble = -1;
4330 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004331 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004332 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004333 params.p2p_ctwindow = -1;
4334 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004335
4336 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4337 params.use_cts_prot =
4338 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4339 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4340 params.use_short_preamble =
4341 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4342 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4343 params.use_short_slot_time =
4344 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004345 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4346 params.basic_rates =
4347 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4348 params.basic_rates_len =
4349 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4350 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004351 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4352 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004353 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4354 params.ht_opmode =
4355 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004356
Johannes Berg53cabad2012-11-14 15:17:28 +01004357 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4358 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4359 return -EINVAL;
4360 params.p2p_ctwindow =
4361 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4362 if (params.p2p_ctwindow < 0)
4363 return -EINVAL;
4364 if (params.p2p_ctwindow != 0 &&
4365 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4366 return -EINVAL;
4367 }
4368
4369 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4370 u8 tmp;
4371
4372 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4373 return -EINVAL;
4374 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4375 if (tmp > 1)
4376 return -EINVAL;
4377 params.p2p_opp_ps = tmp;
4378 if (params.p2p_opp_ps &&
4379 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4380 return -EINVAL;
4381 }
4382
Johannes Berg4c476992010-10-04 21:36:35 +02004383 if (!rdev->ops->change_bss)
4384 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004385
Johannes Berg074ac8d2010-09-16 14:58:22 +02004386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004387 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4388 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004389
Hila Gonene35e4d22012-06-27 17:19:42 +03004390 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004391}
4392
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004393static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004394 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4395 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4396 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4397 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4398 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4399 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4400};
4401
4402static int parse_reg_rule(struct nlattr *tb[],
4403 struct ieee80211_reg_rule *reg_rule)
4404{
4405 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4406 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4407
4408 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4409 return -EINVAL;
4410 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4411 return -EINVAL;
4412 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4413 return -EINVAL;
4414 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4415 return -EINVAL;
4416 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4417 return -EINVAL;
4418
4419 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4420
4421 freq_range->start_freq_khz =
4422 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4423 freq_range->end_freq_khz =
4424 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4425 freq_range->max_bandwidth_khz =
4426 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4427
4428 power_rule->max_eirp =
4429 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4430
4431 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4432 power_rule->max_antenna_gain =
4433 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4434
4435 return 0;
4436}
4437
4438static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4439{
4440 int r;
4441 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004442 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004443
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004444 /*
4445 * You should only get this when cfg80211 hasn't yet initialized
4446 * completely when built-in to the kernel right between the time
4447 * window between nl80211_init() and regulatory_init(), if that is
4448 * even possible.
4449 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004450 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004451 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004452
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004453 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4454 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004455
4456 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4457
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004458 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4459 user_reg_hint_type =
4460 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4461 else
4462 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4463
4464 switch (user_reg_hint_type) {
4465 case NL80211_USER_REG_HINT_USER:
4466 case NL80211_USER_REG_HINT_CELL_BASE:
4467 break;
4468 default:
4469 return -EINVAL;
4470 }
4471
4472 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004473
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004474 return r;
4475}
4476
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004477static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004478 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004479{
Johannes Berg4c476992010-10-04 21:36:35 +02004480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004481 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004482 struct wireless_dev *wdev = dev->ieee80211_ptr;
4483 struct mesh_config cur_params;
4484 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004485 void *hdr;
4486 struct nlattr *pinfoattr;
4487 struct sk_buff *msg;
4488
Johannes Berg29cbe682010-12-03 09:20:44 +01004489 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4490 return -EOPNOTSUPP;
4491
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004492 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004493 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004494
Johannes Berg29cbe682010-12-03 09:20:44 +01004495 wdev_lock(wdev);
4496 /* If not connected, get default parameters */
4497 if (!wdev->mesh_id_len)
4498 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4499 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004500 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004501 wdev_unlock(wdev);
4502
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004503 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004504 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004505
4506 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004508 if (!msg)
4509 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004510 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004511 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004512 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004513 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004514 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004515 if (!pinfoattr)
4516 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004517 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4518 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4519 cur_params.dot11MeshRetryTimeout) ||
4520 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4521 cur_params.dot11MeshConfirmTimeout) ||
4522 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4523 cur_params.dot11MeshHoldingTimeout) ||
4524 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4525 cur_params.dot11MeshMaxPeerLinks) ||
4526 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4527 cur_params.dot11MeshMaxRetries) ||
4528 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4529 cur_params.dot11MeshTTL) ||
4530 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4531 cur_params.element_ttl) ||
4532 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4533 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004534 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4535 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004536 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4537 cur_params.dot11MeshHWMPmaxPREQretries) ||
4538 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4539 cur_params.path_refresh_time) ||
4540 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4541 cur_params.min_discovery_timeout) ||
4542 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4543 cur_params.dot11MeshHWMPactivePathTimeout) ||
4544 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4545 cur_params.dot11MeshHWMPpreqMinInterval) ||
4546 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4547 cur_params.dot11MeshHWMPperrMinInterval) ||
4548 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4549 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4550 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4551 cur_params.dot11MeshHWMPRootMode) ||
4552 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4553 cur_params.dot11MeshHWMPRannInterval) ||
4554 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4555 cur_params.dot11MeshGateAnnouncementProtocol) ||
4556 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4557 cur_params.dot11MeshForwarding) ||
4558 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004559 cur_params.rssi_threshold) ||
4560 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004561 cur_params.ht_opmode) ||
4562 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4563 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4564 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004565 cur_params.dot11MeshHWMProotInterval) ||
4566 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004567 cur_params.dot11MeshHWMPconfirmationInterval) ||
4568 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4569 cur_params.power_mode) ||
4570 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4571 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004572 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004573 nla_nest_end(msg, pinfoattr);
4574 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004575 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004576
Johannes Berg3b858752009-03-12 09:55:09 +01004577 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004578 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004579 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004580 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004581 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004582}
4583
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004584static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4586 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4587 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4588 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4589 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4590 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004591 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004592 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004593 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4595 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4596 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4597 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4598 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004599 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004600 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004601 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004602 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004603 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004604 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004605 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4606 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004607 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4608 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004609 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004610 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4611 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004612};
4613
Javier Cardonac80d5452010-12-16 17:37:49 -08004614static const struct nla_policy
4615 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004616 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004617 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4618 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004619 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004620 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004621 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004622 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004623 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004624 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004625};
4626
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004627static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004628 struct mesh_config *cfg,
4629 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004630{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004631 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004632 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004633
Marco Porschea54fba2013-01-07 16:04:48 +01004634#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4635do { \
4636 if (tb[attr]) { \
4637 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4638 return -EINVAL; \
4639 cfg->param = fn(tb[attr]); \
4640 mask |= (1 << (attr - 1)); \
4641 } \
4642} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004643
4644
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004645 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004646 return -EINVAL;
4647 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004648 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004649 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004650 return -EINVAL;
4651
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004652 /* This makes sure that there aren't more than 32 mesh config
4653 * parameters (otherwise our bitfield scheme would not work.) */
4654 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4655
4656 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004657 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004658 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4659 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004660 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004661 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4662 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004664 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4665 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004666 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004667 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4668 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004669 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004670 mask, NL80211_MESHCONF_MAX_RETRIES,
4671 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004674 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004675 mask, NL80211_MESHCONF_ELEMENT_TTL,
4676 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004677 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004678 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4679 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004680 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4681 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4683 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4686 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004688 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4689 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004691 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4692 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004693 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4694 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004695 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4696 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004698 1, 65535, mask,
4699 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004700 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004702 1, 65535, mask,
4703 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004704 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004706 dot11MeshHWMPnetDiameterTraversalTime,
4707 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4709 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4711 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4712 nla_get_u8);
4713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4714 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004715 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004717 dot11MeshGateAnnouncementProtocol, 0, 1,
4718 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004719 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004721 mask, NL80211_MESHCONF_FORWARDING,
4722 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004724 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4725 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004726 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004727 mask, NL80211_MESHCONF_HT_OPMODE,
4728 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004729 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004730 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004731 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4732 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004734 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4735 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004737 dot11MeshHWMPconfirmationInterval,
4738 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004739 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4740 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4742 NL80211_MESH_POWER_ACTIVE,
4743 NL80211_MESH_POWER_MAX,
4744 mask, NL80211_MESHCONF_POWER_MODE,
4745 nla_get_u32);
4746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4747 0, 65535, mask,
4748 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004749 if (mask_out)
4750 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004751
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004752 return 0;
4753
4754#undef FILL_IN_MESH_PARAM_IF_SET
4755}
4756
Javier Cardonac80d5452010-12-16 17:37:49 -08004757static int nl80211_parse_mesh_setup(struct genl_info *info,
4758 struct mesh_setup *setup)
4759{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004761 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4762
4763 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4764 return -EINVAL;
4765 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4766 info->attrs[NL80211_ATTR_MESH_SETUP],
4767 nl80211_mesh_setup_params_policy))
4768 return -EINVAL;
4769
Javier Cardonad299a1f2012-03-31 11:31:33 -07004770 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4771 setup->sync_method =
4772 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4773 IEEE80211_SYNC_METHOD_VENDOR :
4774 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4775
Javier Cardonac80d5452010-12-16 17:37:49 -08004776 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4777 setup->path_sel_proto =
4778 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4779 IEEE80211_PATH_PROTOCOL_VENDOR :
4780 IEEE80211_PATH_PROTOCOL_HWMP;
4781
4782 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4783 setup->path_metric =
4784 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4785 IEEE80211_PATH_METRIC_VENDOR :
4786 IEEE80211_PATH_METRIC_AIRTIME;
4787
Javier Cardona581a8b02011-04-07 15:08:27 -07004788
4789 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004790 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004791 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004792 if (!is_valid_ie_attr(ieattr))
4793 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004794 setup->ie = nla_data(ieattr);
4795 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004796 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004797 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4798 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4799 return -EINVAL;
4800 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004801 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4802 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004803 if (setup->is_secure)
4804 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004805
Colleen Twitty6e16d902013-05-08 11:45:59 -07004806 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4807 if (!setup->user_mpm)
4808 return -EINVAL;
4809 setup->auth_id =
4810 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4811 }
4812
Javier Cardonac80d5452010-12-16 17:37:49 -08004813 return 0;
4814}
4815
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004816static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004817 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004818{
4819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4820 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004821 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004822 struct mesh_config cfg;
4823 u32 mask;
4824 int err;
4825
Johannes Berg29cbe682010-12-03 09:20:44 +01004826 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4827 return -EOPNOTSUPP;
4828
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004829 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004830 return -EOPNOTSUPP;
4831
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004832 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004833 if (err)
4834 return err;
4835
Johannes Berg29cbe682010-12-03 09:20:44 +01004836 wdev_lock(wdev);
4837 if (!wdev->mesh_id_len)
4838 err = -ENOLINK;
4839
4840 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004841 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004842
4843 wdev_unlock(wdev);
4844
4845 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004846}
4847
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004848static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4849{
Johannes Berg458f4f92012-12-06 15:47:38 +01004850 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004851 struct sk_buff *msg;
4852 void *hdr = NULL;
4853 struct nlattr *nl_reg_rules;
4854 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004855
4856 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004857 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004858
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004860 if (!msg)
4861 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004862
Eric W. Biederman15e47302012-09-07 20:12:54 +00004863 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004864 NL80211_CMD_GET_REG);
4865 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004866 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004867
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004868 if (reg_last_request_cell_base() &&
4869 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4870 NL80211_USER_REG_HINT_CELL_BASE))
4871 goto nla_put_failure;
4872
Johannes Berg458f4f92012-12-06 15:47:38 +01004873 rcu_read_lock();
4874 regdom = rcu_dereference(cfg80211_regdomain);
4875
4876 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4877 (regdom->dfs_region &&
4878 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4879 goto nla_put_failure_rcu;
4880
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004881 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4882 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004883 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004884
Johannes Berg458f4f92012-12-06 15:47:38 +01004885 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004886 struct nlattr *nl_reg_rule;
4887 const struct ieee80211_reg_rule *reg_rule;
4888 const struct ieee80211_freq_range *freq_range;
4889 const struct ieee80211_power_rule *power_rule;
4890
Johannes Berg458f4f92012-12-06 15:47:38 +01004891 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004892 freq_range = &reg_rule->freq_range;
4893 power_rule = &reg_rule->power_rule;
4894
4895 nl_reg_rule = nla_nest_start(msg, i);
4896 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004897 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004898
David S. Miller9360ffd2012-03-29 04:41:26 -04004899 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4900 reg_rule->flags) ||
4901 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4902 freq_range->start_freq_khz) ||
4903 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4904 freq_range->end_freq_khz) ||
4905 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4906 freq_range->max_bandwidth_khz) ||
4907 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4908 power_rule->max_antenna_gain) ||
4909 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4910 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004911 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004912
4913 nla_nest_end(msg, nl_reg_rule);
4914 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004915 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004916
4917 nla_nest_end(msg, nl_reg_rules);
4918
4919 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004920 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004921
Johannes Berg458f4f92012-12-06 15:47:38 +01004922nla_put_failure_rcu:
4923 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004924nla_put_failure:
4925 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004926put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004927 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004928 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004929}
4930
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004931static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4932{
4933 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4934 struct nlattr *nl_reg_rule;
4935 char *alpha2 = NULL;
4936 int rem_reg_rules = 0, r = 0;
4937 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004938 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004939 struct ieee80211_regdomain *rd = NULL;
4940
4941 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4942 return -EINVAL;
4943
4944 if (!info->attrs[NL80211_ATTR_REG_RULES])
4945 return -EINVAL;
4946
4947 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4948
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004949 if (info->attrs[NL80211_ATTR_DFS_REGION])
4950 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4951
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004952 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004953 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954 num_rules++;
4955 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004956 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004957 }
4958
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004960 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004961
4962 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004963 if (!rd)
4964 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004965
4966 rd->n_reg_rules = num_rules;
4967 rd->alpha2[0] = alpha2[0];
4968 rd->alpha2[1] = alpha2[1];
4969
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004970 /*
4971 * Disable DFS master mode if the DFS region was
4972 * not supported or known on this kernel.
4973 */
4974 if (reg_supported_dfs_region(dfs_region))
4975 rd->dfs_region = dfs_region;
4976
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004977 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004978 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004979 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004980 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4981 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4983 if (r)
4984 goto bad_reg;
4985
4986 rule_idx++;
4987
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004988 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4989 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004990 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004991 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992 }
4993
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004994 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01004995 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01004996 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004997
Johannes Bergd2372b32008-10-24 20:32:20 +02004998 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004999 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005000 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005001}
5002
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005003static int validate_scan_freqs(struct nlattr *freqs)
5004{
5005 struct nlattr *attr1, *attr2;
5006 int n_channels = 0, tmp1, tmp2;
5007
5008 nla_for_each_nested(attr1, freqs, tmp1) {
5009 n_channels++;
5010 /*
5011 * Some hardware has a limited channel list for
5012 * scanning, and it is pretty much nonsensical
5013 * to scan for a channel twice, so disallow that
5014 * and don't require drivers to check that the
5015 * channel list they get isn't longer than what
5016 * they can scan, as long as they can scan all
5017 * the channels they registered at once.
5018 */
5019 nla_for_each_nested(attr2, freqs, tmp2)
5020 if (attr1 != attr2 &&
5021 nla_get_u32(attr1) == nla_get_u32(attr2))
5022 return 0;
5023 }
5024
5025 return n_channels;
5026}
5027
Johannes Berg2a519312009-02-10 21:25:55 +01005028static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5029{
Johannes Berg4c476992010-10-04 21:36:35 +02005030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005031 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005032 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005033 struct nlattr *attr;
5034 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005035 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005036 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005037
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005038 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5039 return -EINVAL;
5040
Johannes Berg79c97e92009-07-07 03:56:12 +02005041 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005042
Johannes Berg4c476992010-10-04 21:36:35 +02005043 if (!rdev->ops->scan)
5044 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005045
Johannes Bergf9f47522013-03-19 15:04:07 +01005046 if (rdev->scan_req) {
5047 err = -EBUSY;
5048 goto unlock;
5049 }
Johannes Berg2a519312009-02-10 21:25:55 +01005050
5051 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005052 n_channels = validate_scan_freqs(
5053 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005054 if (!n_channels) {
5055 err = -EINVAL;
5056 goto unlock;
5057 }
Johannes Berg2a519312009-02-10 21:25:55 +01005058 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005059 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005060 n_channels = 0;
5061
Johannes Berg2a519312009-02-10 21:25:55 +01005062 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5063 if (wiphy->bands[band])
5064 n_channels += wiphy->bands[band]->n_channels;
5065 }
5066
5067 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5068 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5069 n_ssids++;
5070
Johannes Bergf9f47522013-03-19 15:04:07 +01005071 if (n_ssids > wiphy->max_scan_ssids) {
5072 err = -EINVAL;
5073 goto unlock;
5074 }
Johannes Berg2a519312009-02-10 21:25:55 +01005075
Jouni Malinen70692ad2009-02-16 19:39:13 +02005076 if (info->attrs[NL80211_ATTR_IE])
5077 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5078 else
5079 ie_len = 0;
5080
Johannes Bergf9f47522013-03-19 15:04:07 +01005081 if (ie_len > wiphy->max_scan_ie_len) {
5082 err = -EINVAL;
5083 goto unlock;
5084 }
Johannes Berg18a83652009-03-31 12:12:05 +02005085
Johannes Berg2a519312009-02-10 21:25:55 +01005086 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005087 + sizeof(*request->ssids) * n_ssids
5088 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005089 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005090 if (!request) {
5091 err = -ENOMEM;
5092 goto unlock;
5093 }
Johannes Berg2a519312009-02-10 21:25:55 +01005094
Johannes Berg2a519312009-02-10 21:25:55 +01005095 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005096 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005097 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005098 if (ie_len) {
5099 if (request->ssids)
5100 request->ie = (void *)(request->ssids + n_ssids);
5101 else
5102 request->ie = (void *)(request->channels + n_channels);
5103 }
Johannes Berg2a519312009-02-10 21:25:55 +01005104
Johannes Berg584991d2009-11-02 13:32:03 +01005105 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005106 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5107 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005108 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005109 struct ieee80211_channel *chan;
5110
5111 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5112
5113 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005114 err = -EINVAL;
5115 goto out_free;
5116 }
Johannes Berg584991d2009-11-02 13:32:03 +01005117
5118 /* ignore disabled channels */
5119 if (chan->flags & IEEE80211_CHAN_DISABLED)
5120 continue;
5121
5122 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005123 i++;
5124 }
5125 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005126 enum ieee80211_band band;
5127
Johannes Berg2a519312009-02-10 21:25:55 +01005128 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005129 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5130 int j;
5131 if (!wiphy->bands[band])
5132 continue;
5133 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005134 struct ieee80211_channel *chan;
5135
5136 chan = &wiphy->bands[band]->channels[j];
5137
5138 if (chan->flags & IEEE80211_CHAN_DISABLED)
5139 continue;
5140
5141 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005142 i++;
5143 }
5144 }
5145 }
5146
Johannes Berg584991d2009-11-02 13:32:03 +01005147 if (!i) {
5148 err = -EINVAL;
5149 goto out_free;
5150 }
5151
5152 request->n_channels = i;
5153
Johannes Berg2a519312009-02-10 21:25:55 +01005154 i = 0;
5155 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5156 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005157 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005158 err = -EINVAL;
5159 goto out_free;
5160 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005161 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005162 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005163 i++;
5164 }
5165 }
5166
Jouni Malinen70692ad2009-02-16 19:39:13 +02005167 if (info->attrs[NL80211_ATTR_IE]) {
5168 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005169 memcpy((void *)request->ie,
5170 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005171 request->ie_len);
5172 }
5173
Johannes Berg34850ab2011-07-18 18:08:35 +02005174 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005175 if (wiphy->bands[i])
5176 request->rates[i] =
5177 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005178
5179 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5180 nla_for_each_nested(attr,
5181 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5182 tmp) {
5183 enum ieee80211_band band = nla_type(attr);
5184
Dan Carpenter84404622011-07-29 11:52:18 +03005185 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005186 err = -EINVAL;
5187 goto out_free;
5188 }
5189 err = ieee80211_get_ratemask(wiphy->bands[band],
5190 nla_data(attr),
5191 nla_len(attr),
5192 &request->rates[band]);
5193 if (err)
5194 goto out_free;
5195 }
5196 }
5197
Sam Leffler46856bb2012-10-11 21:03:32 -07005198 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005199 request->flags = nla_get_u32(
5200 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005201 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5202 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5203 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5204 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005205 err = -EOPNOTSUPP;
5206 goto out_free;
5207 }
5208 }
Sam Lefflered4737712012-10-11 21:03:31 -07005209
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305210 request->no_cck =
5211 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5212
Johannes Bergfd014282012-06-18 19:17:03 +02005213 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005214 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005215 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005216
Johannes Berg79c97e92009-07-07 03:56:12 +02005217 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005218 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005219
Johannes Berg463d0182009-07-14 00:33:35 +02005220 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005221 nl80211_send_scan_start(rdev, wdev);
5222 if (wdev->netdev)
5223 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005224 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005225 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005226 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005227 kfree(request);
5228 }
Johannes Berg3b858752009-03-12 09:55:09 +01005229
Johannes Bergf9f47522013-03-19 15:04:07 +01005230 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005231 return err;
5232}
5233
Luciano Coelho807f8a82011-05-11 17:09:35 +03005234static int nl80211_start_sched_scan(struct sk_buff *skb,
5235 struct genl_info *info)
5236{
5237 struct cfg80211_sched_scan_request *request;
5238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5239 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005240 struct nlattr *attr;
5241 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005242 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005243 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005244 enum ieee80211_band band;
5245 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005246 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005247
5248 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5249 !rdev->ops->sched_scan_start)
5250 return -EOPNOTSUPP;
5251
5252 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5253 return -EINVAL;
5254
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005255 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5256 return -EINVAL;
5257
5258 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5259 if (interval == 0)
5260 return -EINVAL;
5261
Luciano Coelho807f8a82011-05-11 17:09:35 +03005262 wiphy = &rdev->wiphy;
5263
5264 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5265 n_channels = validate_scan_freqs(
5266 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5267 if (!n_channels)
5268 return -EINVAL;
5269 } else {
5270 n_channels = 0;
5271
5272 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5273 if (wiphy->bands[band])
5274 n_channels += wiphy->bands[band]->n_channels;
5275 }
5276
5277 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5278 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5279 tmp)
5280 n_ssids++;
5281
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005282 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005283 return -EINVAL;
5284
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005285 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5286 nla_for_each_nested(attr,
5287 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5288 tmp)
5289 n_match_sets++;
5290
5291 if (n_match_sets > wiphy->max_match_sets)
5292 return -EINVAL;
5293
Luciano Coelho807f8a82011-05-11 17:09:35 +03005294 if (info->attrs[NL80211_ATTR_IE])
5295 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5296 else
5297 ie_len = 0;
5298
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005299 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005300 return -EINVAL;
5301
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005302 if (rdev->sched_scan_req) {
5303 err = -EINPROGRESS;
5304 goto out;
5305 }
5306
Luciano Coelho807f8a82011-05-11 17:09:35 +03005307 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005308 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005309 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005310 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005311 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005312 if (!request) {
5313 err = -ENOMEM;
5314 goto out;
5315 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005316
5317 if (n_ssids)
5318 request->ssids = (void *)&request->channels[n_channels];
5319 request->n_ssids = n_ssids;
5320 if (ie_len) {
5321 if (request->ssids)
5322 request->ie = (void *)(request->ssids + n_ssids);
5323 else
5324 request->ie = (void *)(request->channels + n_channels);
5325 }
5326
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005327 if (n_match_sets) {
5328 if (request->ie)
5329 request->match_sets = (void *)(request->ie + ie_len);
5330 else if (request->ssids)
5331 request->match_sets =
5332 (void *)(request->ssids + n_ssids);
5333 else
5334 request->match_sets =
5335 (void *)(request->channels + n_channels);
5336 }
5337 request->n_match_sets = n_match_sets;
5338
Luciano Coelho807f8a82011-05-11 17:09:35 +03005339 i = 0;
5340 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5341 /* user specified, bail out if channel not found */
5342 nla_for_each_nested(attr,
5343 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5344 tmp) {
5345 struct ieee80211_channel *chan;
5346
5347 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5348
5349 if (!chan) {
5350 err = -EINVAL;
5351 goto out_free;
5352 }
5353
5354 /* ignore disabled channels */
5355 if (chan->flags & IEEE80211_CHAN_DISABLED)
5356 continue;
5357
5358 request->channels[i] = chan;
5359 i++;
5360 }
5361 } else {
5362 /* all channels */
5363 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5364 int j;
5365 if (!wiphy->bands[band])
5366 continue;
5367 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5368 struct ieee80211_channel *chan;
5369
5370 chan = &wiphy->bands[band]->channels[j];
5371
5372 if (chan->flags & IEEE80211_CHAN_DISABLED)
5373 continue;
5374
5375 request->channels[i] = chan;
5376 i++;
5377 }
5378 }
5379 }
5380
5381 if (!i) {
5382 err = -EINVAL;
5383 goto out_free;
5384 }
5385
5386 request->n_channels = i;
5387
5388 i = 0;
5389 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5390 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5391 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005392 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005393 err = -EINVAL;
5394 goto out_free;
5395 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005396 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005397 memcpy(request->ssids[i].ssid, nla_data(attr),
5398 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005399 i++;
5400 }
5401 }
5402
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005403 i = 0;
5404 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5405 nla_for_each_nested(attr,
5406 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5407 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005408 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005409
5410 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5411 nla_data(attr), nla_len(attr),
5412 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005413 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005414 if (ssid) {
5415 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5416 err = -EINVAL;
5417 goto out_free;
5418 }
5419 memcpy(request->match_sets[i].ssid.ssid,
5420 nla_data(ssid), nla_len(ssid));
5421 request->match_sets[i].ssid.ssid_len =
5422 nla_len(ssid);
5423 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005424 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5425 if (rssi)
5426 request->rssi_thold = nla_get_u32(rssi);
5427 else
5428 request->rssi_thold =
5429 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005430 i++;
5431 }
5432 }
5433
Luciano Coelho807f8a82011-05-11 17:09:35 +03005434 if (info->attrs[NL80211_ATTR_IE]) {
5435 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5436 memcpy((void *)request->ie,
5437 nla_data(info->attrs[NL80211_ATTR_IE]),
5438 request->ie_len);
5439 }
5440
Sam Leffler46856bb2012-10-11 21:03:32 -07005441 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005442 request->flags = nla_get_u32(
5443 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005444 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5445 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5446 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5447 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005448 err = -EOPNOTSUPP;
5449 goto out_free;
5450 }
5451 }
Sam Lefflered4737712012-10-11 21:03:31 -07005452
Luciano Coelho807f8a82011-05-11 17:09:35 +03005453 request->dev = dev;
5454 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005455 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005456 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005457
Hila Gonene35e4d22012-06-27 17:19:42 +03005458 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005459 if (!err) {
5460 rdev->sched_scan_req = request;
5461 nl80211_send_sched_scan(rdev, dev,
5462 NL80211_CMD_START_SCHED_SCAN);
5463 goto out;
5464 }
5465
5466out_free:
5467 kfree(request);
5468out:
5469 return err;
5470}
5471
5472static int nl80211_stop_sched_scan(struct sk_buff *skb,
5473 struct genl_info *info)
5474{
5475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5476
5477 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5478 !rdev->ops->sched_scan_stop)
5479 return -EOPNOTSUPP;
5480
Johannes Berg5fe231e2013-05-08 21:45:15 +02005481 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005482}
5483
Simon Wunderlich04f39042013-02-08 18:16:19 +01005484static int nl80211_start_radar_detection(struct sk_buff *skb,
5485 struct genl_info *info)
5486{
5487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5488 struct net_device *dev = info->user_ptr[1];
5489 struct wireless_dev *wdev = dev->ieee80211_ptr;
5490 struct cfg80211_chan_def chandef;
5491 int err;
5492
5493 err = nl80211_parse_chandef(rdev, info, &chandef);
5494 if (err)
5495 return err;
5496
5497 if (wdev->cac_started)
5498 return -EBUSY;
5499
5500 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5501 if (err < 0)
5502 return err;
5503
5504 if (err == 0)
5505 return -EINVAL;
5506
5507 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5508 return -EINVAL;
5509
5510 if (!rdev->ops->start_radar_detection)
5511 return -EOPNOTSUPP;
5512
Simon Wunderlich04f39042013-02-08 18:16:19 +01005513 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5514 chandef.chan, CHAN_MODE_SHARED,
5515 BIT(chandef.width));
5516 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005517 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005518
5519 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5520 if (!err) {
5521 wdev->channel = chandef.chan;
5522 wdev->cac_started = true;
5523 wdev->cac_start_time = jiffies;
5524 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005525 return err;
5526}
5527
Johannes Berg9720bb32011-06-21 09:45:33 +02005528static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5529 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005530 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005531 struct wireless_dev *wdev,
5532 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005533{
Johannes Berg48ab9052009-07-10 18:42:31 +02005534 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005535 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005536 void *hdr;
5537 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005538 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005539
5540 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005541
Eric W. Biederman15e47302012-09-07 20:12:54 +00005542 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005543 NL80211_CMD_NEW_SCAN_RESULTS);
5544 if (!hdr)
5545 return -1;
5546
Johannes Berg9720bb32011-06-21 09:45:33 +02005547 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5548
Johannes Berg97990a02013-04-19 01:02:55 +02005549 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5550 goto nla_put_failure;
5551 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005552 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5553 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005554 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5555 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005556
5557 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5558 if (!bss)
5559 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005560 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005561 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005562 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005563
5564 rcu_read_lock();
5565 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005566 if (ies) {
5567 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5568 goto fail_unlock_rcu;
5569 tsf = true;
5570 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5571 ies->len, ies->data))
5572 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005573 }
5574 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005575 if (ies) {
5576 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5577 goto fail_unlock_rcu;
5578 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5579 ies->len, ies->data))
5580 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005581 }
5582 rcu_read_unlock();
5583
David S. Miller9360ffd2012-03-29 04:41:26 -04005584 if (res->beacon_interval &&
5585 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5586 goto nla_put_failure;
5587 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5588 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5589 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5590 jiffies_to_msecs(jiffies - intbss->ts)))
5591 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005592
Johannes Berg77965c92009-02-18 18:45:06 +01005593 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005594 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005595 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5596 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005597 break;
5598 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005599 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5600 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005601 break;
5602 default:
5603 break;
5604 }
5605
Johannes Berg48ab9052009-07-10 18:42:31 +02005606 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005607 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005608 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005609 if (intbss == wdev->current_bss &&
5610 nla_put_u32(msg, NL80211_BSS_STATUS,
5611 NL80211_BSS_STATUS_ASSOCIATED))
5612 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005613 break;
5614 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005615 if (intbss == wdev->current_bss &&
5616 nla_put_u32(msg, NL80211_BSS_STATUS,
5617 NL80211_BSS_STATUS_IBSS_JOINED))
5618 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005619 break;
5620 default:
5621 break;
5622 }
5623
Johannes Berg2a519312009-02-10 21:25:55 +01005624 nla_nest_end(msg, bss);
5625
5626 return genlmsg_end(msg, hdr);
5627
Johannes Berg8cef2c92013-02-05 16:54:31 +01005628 fail_unlock_rcu:
5629 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005630 nla_put_failure:
5631 genlmsg_cancel(msg, hdr);
5632 return -EMSGSIZE;
5633}
5634
Johannes Berg97990a02013-04-19 01:02:55 +02005635static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005636{
Johannes Berg48ab9052009-07-10 18:42:31 +02005637 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005638 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005639 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005640 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005641 int err;
5642
Johannes Berg97990a02013-04-19 01:02:55 +02005643 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005644 if (err)
5645 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005646
Johannes Berg48ab9052009-07-10 18:42:31 +02005647 wdev_lock(wdev);
5648 spin_lock_bh(&rdev->bss_lock);
5649 cfg80211_bss_expire(rdev);
5650
Johannes Berg9720bb32011-06-21 09:45:33 +02005651 cb->seq = rdev->bss_generation;
5652
Johannes Berg48ab9052009-07-10 18:42:31 +02005653 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005654 if (++idx <= start)
5655 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005656 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005657 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005658 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005659 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005660 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005661 }
5662 }
5663
Johannes Berg48ab9052009-07-10 18:42:31 +02005664 spin_unlock_bh(&rdev->bss_lock);
5665 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005666
Johannes Berg97990a02013-04-19 01:02:55 +02005667 cb->args[2] = idx;
5668 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005669
Johannes Berg67748892010-10-04 21:14:06 +02005670 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005671}
5672
Eric W. Biederman15e47302012-09-07 20:12:54 +00005673static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005674 int flags, struct net_device *dev,
5675 struct survey_info *survey)
5676{
5677 void *hdr;
5678 struct nlattr *infoattr;
5679
Eric W. Biederman15e47302012-09-07 20:12:54 +00005680 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005681 NL80211_CMD_NEW_SURVEY_RESULTS);
5682 if (!hdr)
5683 return -ENOMEM;
5684
David S. Miller9360ffd2012-03-29 04:41:26 -04005685 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5686 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005687
5688 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5689 if (!infoattr)
5690 goto nla_put_failure;
5691
David S. Miller9360ffd2012-03-29 04:41:26 -04005692 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5693 survey->channel->center_freq))
5694 goto nla_put_failure;
5695
5696 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5697 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5698 goto nla_put_failure;
5699 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5700 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5701 goto nla_put_failure;
5702 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5703 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5704 survey->channel_time))
5705 goto nla_put_failure;
5706 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5707 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5708 survey->channel_time_busy))
5709 goto nla_put_failure;
5710 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5711 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5712 survey->channel_time_ext_busy))
5713 goto nla_put_failure;
5714 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5715 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5716 survey->channel_time_rx))
5717 goto nla_put_failure;
5718 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5719 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5720 survey->channel_time_tx))
5721 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005722
5723 nla_nest_end(msg, infoattr);
5724
5725 return genlmsg_end(msg, hdr);
5726
5727 nla_put_failure:
5728 genlmsg_cancel(msg, hdr);
5729 return -EMSGSIZE;
5730}
5731
5732static int nl80211_dump_survey(struct sk_buff *skb,
5733 struct netlink_callback *cb)
5734{
5735 struct survey_info survey;
5736 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005737 struct wireless_dev *wdev;
5738 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005739 int res;
5740
Johannes Berg97990a02013-04-19 01:02:55 +02005741 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005742 if (res)
5743 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005744
Johannes Berg97990a02013-04-19 01:02:55 +02005745 if (!wdev->netdev) {
5746 res = -EINVAL;
5747 goto out_err;
5748 }
5749
Holger Schurig61fa7132009-11-11 12:25:40 +01005750 if (!dev->ops->dump_survey) {
5751 res = -EOPNOTSUPP;
5752 goto out_err;
5753 }
5754
5755 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005756 struct ieee80211_channel *chan;
5757
Johannes Berg97990a02013-04-19 01:02:55 +02005758 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005759 if (res == -ENOENT)
5760 break;
5761 if (res)
5762 goto out_err;
5763
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005764 /* Survey without a channel doesn't make sense */
5765 if (!survey.channel) {
5766 res = -EINVAL;
5767 goto out;
5768 }
5769
5770 chan = ieee80211_get_channel(&dev->wiphy,
5771 survey.channel->center_freq);
5772 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5773 survey_idx++;
5774 continue;
5775 }
5776
Holger Schurig61fa7132009-11-11 12:25:40 +01005777 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005778 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005779 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005780 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005781 goto out;
5782 survey_idx++;
5783 }
5784
5785 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005786 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005787 res = skb->len;
5788 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005789 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005790 return res;
5791}
5792
Samuel Ortizb23aa672009-07-01 21:26:54 +02005793static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5794{
5795 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5796 NL80211_WPA_VERSION_2));
5797}
5798
Jouni Malinen636a5d32009-03-19 13:39:22 +02005799static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5800{
Johannes Berg4c476992010-10-04 21:36:35 +02005801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5802 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005803 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005804 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5805 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005806 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005807 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005808 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005809
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005810 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5811 return -EINVAL;
5812
5813 if (!info->attrs[NL80211_ATTR_MAC])
5814 return -EINVAL;
5815
Jouni Malinen17780922009-03-27 20:52:47 +02005816 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5817 return -EINVAL;
5818
Johannes Berg19957bb2009-07-02 17:20:43 +02005819 if (!info->attrs[NL80211_ATTR_SSID])
5820 return -EINVAL;
5821
5822 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5823 return -EINVAL;
5824
Johannes Bergfffd0932009-07-08 14:22:54 +02005825 err = nl80211_parse_key(info, &key);
5826 if (err)
5827 return err;
5828
5829 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005830 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5831 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005832 if (!key.p.key || !key.p.key_len)
5833 return -EINVAL;
5834 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5835 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5836 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5837 key.p.key_len != WLAN_KEY_LEN_WEP104))
5838 return -EINVAL;
5839 if (key.idx > 4)
5840 return -EINVAL;
5841 } else {
5842 key.p.key_len = 0;
5843 key.p.key = NULL;
5844 }
5845
Johannes Bergafea0b72010-08-10 09:46:42 +02005846 if (key.idx >= 0) {
5847 int i;
5848 bool ok = false;
5849 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5850 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5851 ok = true;
5852 break;
5853 }
5854 }
Johannes Berg4c476992010-10-04 21:36:35 +02005855 if (!ok)
5856 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005857 }
5858
Johannes Berg4c476992010-10-04 21:36:35 +02005859 if (!rdev->ops->auth)
5860 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005861
Johannes Berg074ac8d2010-09-16 14:58:22 +02005862 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005863 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5864 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005865
Johannes Berg19957bb2009-07-02 17:20:43 +02005866 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005867 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005868 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005869 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5870 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005871
Johannes Berg19957bb2009-07-02 17:20:43 +02005872 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5873 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5874
5875 if (info->attrs[NL80211_ATTR_IE]) {
5876 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5877 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5878 }
5879
5880 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005881 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005882 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005883
Jouni Malinene39e5b52012-09-30 19:29:39 +03005884 if (auth_type == NL80211_AUTHTYPE_SAE &&
5885 !info->attrs[NL80211_ATTR_SAE_DATA])
5886 return -EINVAL;
5887
5888 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5889 if (auth_type != NL80211_AUTHTYPE_SAE)
5890 return -EINVAL;
5891 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5892 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5893 /* need to include at least Auth Transaction and Status Code */
5894 if (sae_data_len < 4)
5895 return -EINVAL;
5896 }
5897
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005898 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5899
Johannes Berg95de8172012-01-20 13:55:25 +01005900 /*
5901 * Since we no longer track auth state, ignore
5902 * requests to only change local state.
5903 */
5904 if (local_state_change)
5905 return 0;
5906
Johannes Berg91bf9b22013-05-15 17:44:01 +02005907 wdev_lock(dev->ieee80211_ptr);
5908 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5909 ssid, ssid_len, ie, ie_len,
5910 key.p.key, key.p.key_len, key.idx,
5911 sae_data, sae_data_len);
5912 wdev_unlock(dev->ieee80211_ptr);
5913 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005914}
5915
Johannes Bergc0692b82010-08-27 14:26:53 +03005916static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5917 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005918 struct cfg80211_crypto_settings *settings,
5919 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005920{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005921 memset(settings, 0, sizeof(*settings));
5922
Samuel Ortizb23aa672009-07-01 21:26:54 +02005923 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5924
Johannes Bergc0692b82010-08-27 14:26:53 +03005925 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5926 u16 proto;
5927 proto = nla_get_u16(
5928 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5929 settings->control_port_ethertype = cpu_to_be16(proto);
5930 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5931 proto != ETH_P_PAE)
5932 return -EINVAL;
5933 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5934 settings->control_port_no_encrypt = true;
5935 } else
5936 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5937
Samuel Ortizb23aa672009-07-01 21:26:54 +02005938 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5939 void *data;
5940 int len, i;
5941
5942 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5943 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5944 settings->n_ciphers_pairwise = len / sizeof(u32);
5945
5946 if (len % sizeof(u32))
5947 return -EINVAL;
5948
Johannes Berg3dc27d22009-07-02 21:36:37 +02005949 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005950 return -EINVAL;
5951
5952 memcpy(settings->ciphers_pairwise, data, len);
5953
5954 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005955 if (!cfg80211_supported_cipher_suite(
5956 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005957 settings->ciphers_pairwise[i]))
5958 return -EINVAL;
5959 }
5960
5961 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5962 settings->cipher_group =
5963 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005964 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5965 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005966 return -EINVAL;
5967 }
5968
5969 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5970 settings->wpa_versions =
5971 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5972 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5973 return -EINVAL;
5974 }
5975
5976 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5977 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005978 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005979
5980 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5981 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5982 settings->n_akm_suites = len / sizeof(u32);
5983
5984 if (len % sizeof(u32))
5985 return -EINVAL;
5986
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005987 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5988 return -EINVAL;
5989
Samuel Ortizb23aa672009-07-01 21:26:54 +02005990 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005991 }
5992
5993 return 0;
5994}
5995
Jouni Malinen636a5d32009-03-19 13:39:22 +02005996static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5997{
Johannes Berg4c476992010-10-04 21:36:35 +02005998 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5999 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006000 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006001 struct cfg80211_assoc_request req = {};
6002 const u8 *bssid, *ssid;
6003 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006004
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006005 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6006 return -EINVAL;
6007
6008 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006009 !info->attrs[NL80211_ATTR_SSID] ||
6010 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006011 return -EINVAL;
6012
Johannes Berg4c476992010-10-04 21:36:35 +02006013 if (!rdev->ops->assoc)
6014 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006015
Johannes Berg074ac8d2010-09-16 14:58:22 +02006016 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006017 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6018 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006019
Johannes Berg19957bb2009-07-02 17:20:43 +02006020 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006021
Johannes Berg19957bb2009-07-02 17:20:43 +02006022 chan = ieee80211_get_channel(&rdev->wiphy,
6023 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006024 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6025 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006026
Johannes Berg19957bb2009-07-02 17:20:43 +02006027 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6028 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006029
6030 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006031 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6032 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006033 }
6034
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006035 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006036 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006037 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006038 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006039 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006040 else if (mfp != NL80211_MFP_NO)
6041 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006042 }
6043
Johannes Berg3e5d7642009-07-07 14:37:26 +02006044 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006045 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006046
Ben Greear7e7c8922011-11-18 11:31:59 -08006047 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006048 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006049
6050 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006051 memcpy(&req.ht_capa_mask,
6052 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6053 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006054
6055 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006056 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006057 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006058 memcpy(&req.ht_capa,
6059 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6060 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006061 }
6062
Johannes Bergee2aca32013-02-21 17:36:01 +01006063 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006064 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006065
6066 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006067 memcpy(&req.vht_capa_mask,
6068 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6069 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006070
6071 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006072 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006073 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006074 memcpy(&req.vht_capa,
6075 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6076 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006077 }
6078
Johannes Bergf62fab72013-02-21 20:09:09 +01006079 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006080 if (!err) {
6081 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006082 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6083 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006084 wdev_unlock(dev->ieee80211_ptr);
6085 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006086
Jouni Malinen636a5d32009-03-19 13:39:22 +02006087 return err;
6088}
6089
6090static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6091{
Johannes Berg4c476992010-10-04 21:36:35 +02006092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6093 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006094 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006095 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006096 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006097 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006098
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006099 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6100 return -EINVAL;
6101
6102 if (!info->attrs[NL80211_ATTR_MAC])
6103 return -EINVAL;
6104
6105 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6106 return -EINVAL;
6107
Johannes Berg4c476992010-10-04 21:36:35 +02006108 if (!rdev->ops->deauth)
6109 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006110
Johannes Berg074ac8d2010-09-16 14:58:22 +02006111 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006112 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6113 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006114
Johannes Berg19957bb2009-07-02 17:20:43 +02006115 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006116
Johannes Berg19957bb2009-07-02 17:20:43 +02006117 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6118 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006119 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006120 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006121 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006122
6123 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006124 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6125 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006126 }
6127
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006128 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6129
Johannes Berg91bf9b22013-05-15 17:44:01 +02006130 wdev_lock(dev->ieee80211_ptr);
6131 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6132 local_state_change);
6133 wdev_unlock(dev->ieee80211_ptr);
6134 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006135}
6136
6137static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6138{
Johannes Berg4c476992010-10-04 21:36:35 +02006139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6140 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006141 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006142 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006143 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006144 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006145
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006146 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6147 return -EINVAL;
6148
6149 if (!info->attrs[NL80211_ATTR_MAC])
6150 return -EINVAL;
6151
6152 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6153 return -EINVAL;
6154
Johannes Berg4c476992010-10-04 21:36:35 +02006155 if (!rdev->ops->disassoc)
6156 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006157
Johannes Berg074ac8d2010-09-16 14:58:22 +02006158 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006159 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6160 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006161
Johannes Berg19957bb2009-07-02 17:20:43 +02006162 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006163
Johannes Berg19957bb2009-07-02 17:20:43 +02006164 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6165 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006166 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006167 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006168 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006169
6170 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006171 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6172 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006173 }
6174
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006175 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6176
Johannes Berg91bf9b22013-05-15 17:44:01 +02006177 wdev_lock(dev->ieee80211_ptr);
6178 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6179 local_state_change);
6180 wdev_unlock(dev->ieee80211_ptr);
6181 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006182}
6183
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006184static bool
6185nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6186 int mcast_rate[IEEE80211_NUM_BANDS],
6187 int rateval)
6188{
6189 struct wiphy *wiphy = &rdev->wiphy;
6190 bool found = false;
6191 int band, i;
6192
6193 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6194 struct ieee80211_supported_band *sband;
6195
6196 sband = wiphy->bands[band];
6197 if (!sband)
6198 continue;
6199
6200 for (i = 0; i < sband->n_bitrates; i++) {
6201 if (sband->bitrates[i].bitrate == rateval) {
6202 mcast_rate[band] = i + 1;
6203 found = true;
6204 break;
6205 }
6206 }
6207 }
6208
6209 return found;
6210}
6211
Johannes Berg04a773a2009-04-19 21:24:32 +02006212static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6213{
Johannes Berg4c476992010-10-04 21:36:35 +02006214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6215 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006216 struct cfg80211_ibss_params ibss;
6217 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006218 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006219 int err;
6220
Johannes Berg8e30bc52009-04-22 17:45:38 +02006221 memset(&ibss, 0, sizeof(ibss));
6222
Johannes Berg04a773a2009-04-19 21:24:32 +02006223 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6224 return -EINVAL;
6225
Johannes Berg683b6d32012-11-08 21:25:48 +01006226 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006227 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6228 return -EINVAL;
6229
Johannes Berg8e30bc52009-04-22 17:45:38 +02006230 ibss.beacon_interval = 100;
6231
6232 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6233 ibss.beacon_interval =
6234 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6235 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6236 return -EINVAL;
6237 }
6238
Johannes Berg4c476992010-10-04 21:36:35 +02006239 if (!rdev->ops->join_ibss)
6240 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006241
Johannes Berg4c476992010-10-04 21:36:35 +02006242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6243 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006244
Johannes Berg79c97e92009-07-07 03:56:12 +02006245 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006246
Johannes Berg39193492011-09-16 13:45:25 +02006247 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006248 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006249
6250 if (!is_valid_ether_addr(ibss.bssid))
6251 return -EINVAL;
6252 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006253 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6254 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6255
6256 if (info->attrs[NL80211_ATTR_IE]) {
6257 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6258 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6259 }
6260
Johannes Berg683b6d32012-11-08 21:25:48 +01006261 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6262 if (err)
6263 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006264
Johannes Berg683b6d32012-11-08 21:25:48 +01006265 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006266 return -EINVAL;
6267
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006268 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6269 return -EINVAL;
6270 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6271 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006272 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006273
Johannes Berg04a773a2009-04-19 21:24:32 +02006274 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006275 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006276
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006277 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6278 u8 *rates =
6279 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6280 int n_rates =
6281 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6282 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006283 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006284
Johannes Berg34850ab2011-07-18 18:08:35 +02006285 err = ieee80211_get_ratemask(sband, rates, n_rates,
6286 &ibss.basic_rates);
6287 if (err)
6288 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006289 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006290
6291 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6292 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6293 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6294 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006295
Johannes Berg4c476992010-10-04 21:36:35 +02006296 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306297 bool no_ht = false;
6298
Johannes Berg4c476992010-10-04 21:36:35 +02006299 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306300 info->attrs[NL80211_ATTR_KEYS],
6301 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006302 if (IS_ERR(connkeys))
6303 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306304
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006305 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6306 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306307 kfree(connkeys);
6308 return -EINVAL;
6309 }
Johannes Berg4c476992010-10-04 21:36:35 +02006310 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006311
Antonio Quartulli267335d2012-01-31 20:25:47 +01006312 ibss.control_port =
6313 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6314
Johannes Berg4c476992010-10-04 21:36:35 +02006315 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006316 if (err)
6317 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006318 return err;
6319}
6320
6321static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6322{
Johannes Berg4c476992010-10-04 21:36:35 +02006323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6324 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006325
Johannes Berg4c476992010-10-04 21:36:35 +02006326 if (!rdev->ops->leave_ibss)
6327 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006328
Johannes Berg4c476992010-10-04 21:36:35 +02006329 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6330 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006331
Johannes Berg4c476992010-10-04 21:36:35 +02006332 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006333}
6334
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006335static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6336{
6337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6338 struct net_device *dev = info->user_ptr[1];
6339 int mcast_rate[IEEE80211_NUM_BANDS];
6340 u32 nla_rate;
6341 int err;
6342
6343 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6344 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6345 return -EOPNOTSUPP;
6346
6347 if (!rdev->ops->set_mcast_rate)
6348 return -EOPNOTSUPP;
6349
6350 memset(mcast_rate, 0, sizeof(mcast_rate));
6351
6352 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6353 return -EINVAL;
6354
6355 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6356 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6357 return -EINVAL;
6358
6359 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6360
6361 return err;
6362}
6363
6364
Johannes Bergaff89a92009-07-01 21:26:51 +02006365#ifdef CONFIG_NL80211_TESTMODE
6366static struct genl_multicast_group nl80211_testmode_mcgrp = {
6367 .name = "testmode",
6368};
6369
6370static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6371{
Johannes Berg4c476992010-10-04 21:36:35 +02006372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006373 int err;
6374
6375 if (!info->attrs[NL80211_ATTR_TESTDATA])
6376 return -EINVAL;
6377
Johannes Bergaff89a92009-07-01 21:26:51 +02006378 err = -EOPNOTSUPP;
6379 if (rdev->ops->testmode_cmd) {
6380 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006381 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006382 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6383 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6384 rdev->testmode_info = NULL;
6385 }
6386
Johannes Bergaff89a92009-07-01 21:26:51 +02006387 return err;
6388}
6389
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006390static int nl80211_testmode_dump(struct sk_buff *skb,
6391 struct netlink_callback *cb)
6392{
Johannes Berg00918d32011-12-13 17:22:05 +01006393 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006394 int err;
6395 long phy_idx;
6396 void *data = NULL;
6397 int data_len = 0;
6398
Johannes Berg5fe231e2013-05-08 21:45:15 +02006399 rtnl_lock();
6400
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006401 if (cb->args[0]) {
6402 /*
6403 * 0 is a valid index, but not valid for args[0],
6404 * so we need to offset by 1.
6405 */
6406 phy_idx = cb->args[0] - 1;
6407 } else {
6408 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6409 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6410 nl80211_policy);
6411 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006412 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006413
Johannes Berg2bd7e352012-06-15 14:23:16 +02006414 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6415 nl80211_fam.attrbuf);
6416 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006417 err = PTR_ERR(rdev);
6418 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006419 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006420 phy_idx = rdev->wiphy_idx;
6421 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006422
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006423 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6424 cb->args[1] =
6425 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6426 }
6427
6428 if (cb->args[1]) {
6429 data = nla_data((void *)cb->args[1]);
6430 data_len = nla_len((void *)cb->args[1]);
6431 }
6432
Johannes Berg00918d32011-12-13 17:22:05 +01006433 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6434 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006435 err = -ENOENT;
6436 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006437 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006438
Johannes Berg00918d32011-12-13 17:22:05 +01006439 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006440 err = -EOPNOTSUPP;
6441 goto out_err;
6442 }
6443
6444 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006445 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006446 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6447 NL80211_CMD_TESTMODE);
6448 struct nlattr *tmdata;
6449
David S. Miller9360ffd2012-03-29 04:41:26 -04006450 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006451 genlmsg_cancel(skb, hdr);
6452 break;
6453 }
6454
6455 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6456 if (!tmdata) {
6457 genlmsg_cancel(skb, hdr);
6458 break;
6459 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006460 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006461 nla_nest_end(skb, tmdata);
6462
6463 if (err == -ENOBUFS || err == -ENOENT) {
6464 genlmsg_cancel(skb, hdr);
6465 break;
6466 } else if (err) {
6467 genlmsg_cancel(skb, hdr);
6468 goto out_err;
6469 }
6470
6471 genlmsg_end(skb, hdr);
6472 }
6473
6474 err = skb->len;
6475 /* see above */
6476 cb->args[0] = phy_idx + 1;
6477 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006478 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006479 return err;
6480}
6481
Johannes Bergaff89a92009-07-01 21:26:51 +02006482static struct sk_buff *
6483__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006484 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006485{
6486 struct sk_buff *skb;
6487 void *hdr;
6488 struct nlattr *data;
6489
6490 skb = nlmsg_new(approxlen + 100, gfp);
6491 if (!skb)
6492 return NULL;
6493
Eric W. Biederman15e47302012-09-07 20:12:54 +00006494 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006495 if (!hdr) {
6496 kfree_skb(skb);
6497 return NULL;
6498 }
6499
David S. Miller9360ffd2012-03-29 04:41:26 -04006500 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6501 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006502 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6503
6504 ((void **)skb->cb)[0] = rdev;
6505 ((void **)skb->cb)[1] = hdr;
6506 ((void **)skb->cb)[2] = data;
6507
6508 return skb;
6509
6510 nla_put_failure:
6511 kfree_skb(skb);
6512 return NULL;
6513}
6514
6515struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6516 int approxlen)
6517{
6518 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6519
6520 if (WARN_ON(!rdev->testmode_info))
6521 return NULL;
6522
6523 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006524 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006525 rdev->testmode_info->snd_seq,
6526 GFP_KERNEL);
6527}
6528EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6529
6530int cfg80211_testmode_reply(struct sk_buff *skb)
6531{
6532 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6533 void *hdr = ((void **)skb->cb)[1];
6534 struct nlattr *data = ((void **)skb->cb)[2];
6535
6536 if (WARN_ON(!rdev->testmode_info)) {
6537 kfree_skb(skb);
6538 return -EINVAL;
6539 }
6540
6541 nla_nest_end(skb, data);
6542 genlmsg_end(skb, hdr);
6543 return genlmsg_reply(skb, rdev->testmode_info);
6544}
6545EXPORT_SYMBOL(cfg80211_testmode_reply);
6546
6547struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6548 int approxlen, gfp_t gfp)
6549{
6550 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6551
6552 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6553}
6554EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6555
6556void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6557{
6558 void *hdr = ((void **)skb->cb)[1];
6559 struct nlattr *data = ((void **)skb->cb)[2];
6560
6561 nla_nest_end(skb, data);
6562 genlmsg_end(skb, hdr);
6563 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6564}
6565EXPORT_SYMBOL(cfg80211_testmode_event);
6566#endif
6567
Samuel Ortizb23aa672009-07-01 21:26:54 +02006568static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6569{
Johannes Berg4c476992010-10-04 21:36:35 +02006570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6571 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006572 struct cfg80211_connect_params connect;
6573 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006574 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006575 int err;
6576
6577 memset(&connect, 0, sizeof(connect));
6578
6579 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6580 return -EINVAL;
6581
6582 if (!info->attrs[NL80211_ATTR_SSID] ||
6583 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6584 return -EINVAL;
6585
6586 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6587 connect.auth_type =
6588 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006589 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6590 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006591 return -EINVAL;
6592 } else
6593 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6594
6595 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6596
Johannes Bergc0692b82010-08-27 14:26:53 +03006597 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006598 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006599 if (err)
6600 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006601
Johannes Berg074ac8d2010-09-16 14:58:22 +02006602 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006603 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6604 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006605
Johannes Berg79c97e92009-07-07 03:56:12 +02006606 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006607
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306608 connect.bg_scan_period = -1;
6609 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6610 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6611 connect.bg_scan_period =
6612 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6613 }
6614
Samuel Ortizb23aa672009-07-01 21:26:54 +02006615 if (info->attrs[NL80211_ATTR_MAC])
6616 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6617 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6618 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6619
6620 if (info->attrs[NL80211_ATTR_IE]) {
6621 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6622 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6623 }
6624
Jouni Malinencee00a92013-01-15 17:15:57 +02006625 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6626 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6627 if (connect.mfp != NL80211_MFP_REQUIRED &&
6628 connect.mfp != NL80211_MFP_NO)
6629 return -EINVAL;
6630 } else {
6631 connect.mfp = NL80211_MFP_NO;
6632 }
6633
Samuel Ortizb23aa672009-07-01 21:26:54 +02006634 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6635 connect.channel =
6636 ieee80211_get_channel(wiphy,
6637 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6638 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006639 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6640 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006641 }
6642
Johannes Bergfffd0932009-07-08 14:22:54 +02006643 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6644 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306645 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006646 if (IS_ERR(connkeys))
6647 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006648 }
6649
Ben Greear7e7c8922011-11-18 11:31:59 -08006650 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6651 connect.flags |= ASSOC_REQ_DISABLE_HT;
6652
6653 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6654 memcpy(&connect.ht_capa_mask,
6655 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6656 sizeof(connect.ht_capa_mask));
6657
6658 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006659 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6660 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006661 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006662 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006663 memcpy(&connect.ht_capa,
6664 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6665 sizeof(connect.ht_capa));
6666 }
6667
Johannes Bergee2aca32013-02-21 17:36:01 +01006668 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6669 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6670
6671 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6672 memcpy(&connect.vht_capa_mask,
6673 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6674 sizeof(connect.vht_capa_mask));
6675
6676 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6677 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6678 kfree(connkeys);
6679 return -EINVAL;
6680 }
6681 memcpy(&connect.vht_capa,
6682 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6683 sizeof(connect.vht_capa));
6684 }
6685
Johannes Berg83739b02013-05-15 17:44:01 +02006686 wdev_lock(dev->ieee80211_ptr);
6687 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6688 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006689 if (err)
6690 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006691 return err;
6692}
6693
6694static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6695{
Johannes Berg4c476992010-10-04 21:36:35 +02006696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6697 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006698 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006699 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006700
6701 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6702 reason = WLAN_REASON_DEAUTH_LEAVING;
6703 else
6704 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6705
6706 if (reason == 0)
6707 return -EINVAL;
6708
Johannes Berg074ac8d2010-09-16 14:58:22 +02006709 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006710 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6711 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006712
Johannes Berg83739b02013-05-15 17:44:01 +02006713 wdev_lock(dev->ieee80211_ptr);
6714 ret = cfg80211_disconnect(rdev, dev, reason, true);
6715 wdev_unlock(dev->ieee80211_ptr);
6716 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006717}
6718
Johannes Berg463d0182009-07-14 00:33:35 +02006719static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6720{
Johannes Berg4c476992010-10-04 21:36:35 +02006721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006722 struct net *net;
6723 int err;
6724 u32 pid;
6725
6726 if (!info->attrs[NL80211_ATTR_PID])
6727 return -EINVAL;
6728
6729 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6730
Johannes Berg463d0182009-07-14 00:33:35 +02006731 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006732 if (IS_ERR(net))
6733 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006734
6735 err = 0;
6736
6737 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006738 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6739 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006740
Johannes Berg463d0182009-07-14 00:33:35 +02006741 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006742 return err;
6743}
6744
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006745static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6746{
Johannes Berg4c476992010-10-04 21:36:35 +02006747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006748 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6749 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006750 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006751 struct cfg80211_pmksa pmksa;
6752
6753 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6754
6755 if (!info->attrs[NL80211_ATTR_MAC])
6756 return -EINVAL;
6757
6758 if (!info->attrs[NL80211_ATTR_PMKID])
6759 return -EINVAL;
6760
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006761 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6762 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6763
Johannes Berg074ac8d2010-09-16 14:58:22 +02006764 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006765 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6766 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006767
6768 switch (info->genlhdr->cmd) {
6769 case NL80211_CMD_SET_PMKSA:
6770 rdev_ops = rdev->ops->set_pmksa;
6771 break;
6772 case NL80211_CMD_DEL_PMKSA:
6773 rdev_ops = rdev->ops->del_pmksa;
6774 break;
6775 default:
6776 WARN_ON(1);
6777 break;
6778 }
6779
Johannes Berg4c476992010-10-04 21:36:35 +02006780 if (!rdev_ops)
6781 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006782
Johannes Berg4c476992010-10-04 21:36:35 +02006783 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006784}
6785
6786static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6787{
Johannes Berg4c476992010-10-04 21:36:35 +02006788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6789 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006790
Johannes Berg074ac8d2010-09-16 14:58:22 +02006791 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006792 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6793 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006794
Johannes Berg4c476992010-10-04 21:36:35 +02006795 if (!rdev->ops->flush_pmksa)
6796 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006797
Hila Gonene35e4d22012-06-27 17:19:42 +03006798 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006799}
6800
Arik Nemtsov109086c2011-09-28 14:12:50 +03006801static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6802{
6803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6804 struct net_device *dev = info->user_ptr[1];
6805 u8 action_code, dialog_token;
6806 u16 status_code;
6807 u8 *peer;
6808
6809 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6810 !rdev->ops->tdls_mgmt)
6811 return -EOPNOTSUPP;
6812
6813 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6814 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6815 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6816 !info->attrs[NL80211_ATTR_IE] ||
6817 !info->attrs[NL80211_ATTR_MAC])
6818 return -EINVAL;
6819
6820 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6821 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6822 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6823 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6824
Hila Gonene35e4d22012-06-27 17:19:42 +03006825 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6826 dialog_token, status_code,
6827 nla_data(info->attrs[NL80211_ATTR_IE]),
6828 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006829}
6830
6831static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6832{
6833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6834 struct net_device *dev = info->user_ptr[1];
6835 enum nl80211_tdls_operation operation;
6836 u8 *peer;
6837
6838 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6839 !rdev->ops->tdls_oper)
6840 return -EOPNOTSUPP;
6841
6842 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6843 !info->attrs[NL80211_ATTR_MAC])
6844 return -EINVAL;
6845
6846 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6847 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6848
Hila Gonene35e4d22012-06-27 17:19:42 +03006849 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006850}
6851
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006852static int nl80211_remain_on_channel(struct sk_buff *skb,
6853 struct genl_info *info)
6854{
Johannes Berg4c476992010-10-04 21:36:35 +02006855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006856 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006857 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006858 struct sk_buff *msg;
6859 void *hdr;
6860 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006861 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006862 int err;
6863
6864 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6865 !info->attrs[NL80211_ATTR_DURATION])
6866 return -EINVAL;
6867
6868 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6869
Johannes Berg7c4ef712011-11-18 15:33:48 +01006870 if (!rdev->ops->remain_on_channel ||
6871 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006872 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006873
Johannes Bergebf348f2012-06-01 12:50:54 +02006874 /*
6875 * We should be on that channel for at least a minimum amount of
6876 * time (10ms) but no longer than the driver supports.
6877 */
6878 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6879 duration > rdev->wiphy.max_remain_on_channel_duration)
6880 return -EINVAL;
6881
Johannes Berg683b6d32012-11-08 21:25:48 +01006882 err = nl80211_parse_chandef(rdev, info, &chandef);
6883 if (err)
6884 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006885
6886 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006887 if (!msg)
6888 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006889
Eric W. Biederman15e47302012-09-07 20:12:54 +00006890 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006891 NL80211_CMD_REMAIN_ON_CHANNEL);
6892
6893 if (IS_ERR(hdr)) {
6894 err = PTR_ERR(hdr);
6895 goto free_msg;
6896 }
6897
Johannes Berg683b6d32012-11-08 21:25:48 +01006898 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6899 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006900
6901 if (err)
6902 goto free_msg;
6903
David S. Miller9360ffd2012-03-29 04:41:26 -04006904 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6905 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006906
6907 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006908
6909 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006910
6911 nla_put_failure:
6912 err = -ENOBUFS;
6913 free_msg:
6914 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006915 return err;
6916}
6917
6918static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6919 struct genl_info *info)
6920{
Johannes Berg4c476992010-10-04 21:36:35 +02006921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006922 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006923 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006924
6925 if (!info->attrs[NL80211_ATTR_COOKIE])
6926 return -EINVAL;
6927
Johannes Berg4c476992010-10-04 21:36:35 +02006928 if (!rdev->ops->cancel_remain_on_channel)
6929 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006930
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006931 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6932
Hila Gonene35e4d22012-06-27 17:19:42 +03006933 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006934}
6935
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006936static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6937 u8 *rates, u8 rates_len)
6938{
6939 u8 i;
6940 u32 mask = 0;
6941
6942 for (i = 0; i < rates_len; i++) {
6943 int rate = (rates[i] & 0x7f) * 5;
6944 int ridx;
6945 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6946 struct ieee80211_rate *srate =
6947 &sband->bitrates[ridx];
6948 if (rate == srate->bitrate) {
6949 mask |= 1 << ridx;
6950 break;
6951 }
6952 }
6953 if (ridx == sband->n_bitrates)
6954 return 0; /* rate not found */
6955 }
6956
6957 return mask;
6958}
6959
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006960static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6961 u8 *rates, u8 rates_len,
6962 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6963{
6964 u8 i;
6965
6966 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6967
6968 for (i = 0; i < rates_len; i++) {
6969 int ridx, rbit;
6970
6971 ridx = rates[i] / 8;
6972 rbit = BIT(rates[i] % 8);
6973
6974 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006975 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006976 return false;
6977
6978 /* check availability */
6979 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6980 mcs[ridx] |= rbit;
6981 else
6982 return false;
6983 }
6984
6985 return true;
6986}
6987
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006988static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006989 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6990 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006991 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6992 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006993};
6994
6995static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6996 struct genl_info *info)
6997{
6998 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007000 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007001 int rem, i;
7002 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007003 struct nlattr *tx_rates;
7004 struct ieee80211_supported_band *sband;
7005
7006 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7007 return -EINVAL;
7008
Johannes Berg4c476992010-10-04 21:36:35 +02007009 if (!rdev->ops->set_bitrate_mask)
7010 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007011
7012 memset(&mask, 0, sizeof(mask));
7013 /* Default to all rates enabled */
7014 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7015 sband = rdev->wiphy.bands[i];
7016 mask.control[i].legacy =
7017 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007018 if (sband)
7019 memcpy(mask.control[i].mcs,
7020 sband->ht_cap.mcs.rx_mask,
7021 sizeof(mask.control[i].mcs));
7022 else
7023 memset(mask.control[i].mcs, 0,
7024 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007025 }
7026
7027 /*
7028 * The nested attribute uses enum nl80211_band as the index. This maps
7029 * directly to the enum ieee80211_band values used in cfg80211.
7030 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007031 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007032 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7033 {
7034 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007035 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7036 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007037 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007038 if (sband == NULL)
7039 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007040 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7041 nla_len(tx_rates), nl80211_txattr_policy);
7042 if (tb[NL80211_TXRATE_LEGACY]) {
7043 mask.control[band].legacy = rateset_to_mask(
7044 sband,
7045 nla_data(tb[NL80211_TXRATE_LEGACY]),
7046 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307047 if ((mask.control[band].legacy == 0) &&
7048 nla_len(tb[NL80211_TXRATE_LEGACY]))
7049 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007050 }
7051 if (tb[NL80211_TXRATE_MCS]) {
7052 if (!ht_rateset_to_mask(
7053 sband,
7054 nla_data(tb[NL80211_TXRATE_MCS]),
7055 nla_len(tb[NL80211_TXRATE_MCS]),
7056 mask.control[band].mcs))
7057 return -EINVAL;
7058 }
7059
7060 if (mask.control[band].legacy == 0) {
7061 /* don't allow empty legacy rates if HT
7062 * is not even supported. */
7063 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7064 return -EINVAL;
7065
7066 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7067 if (mask.control[band].mcs[i])
7068 break;
7069
7070 /* legacy and mcs rates may not be both empty */
7071 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007072 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007073 }
7074 }
7075
Hila Gonene35e4d22012-06-27 17:19:42 +03007076 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007077}
7078
Johannes Berg2e161f72010-08-12 15:38:38 +02007079static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007080{
Johannes Berg4c476992010-10-04 21:36:35 +02007081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007082 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007083 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007084
7085 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7086 return -EINVAL;
7087
Johannes Berg2e161f72010-08-12 15:38:38 +02007088 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7089 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007090
Johannes Berg71bbc992012-06-15 15:30:18 +02007091 switch (wdev->iftype) {
7092 case NL80211_IFTYPE_STATION:
7093 case NL80211_IFTYPE_ADHOC:
7094 case NL80211_IFTYPE_P2P_CLIENT:
7095 case NL80211_IFTYPE_AP:
7096 case NL80211_IFTYPE_AP_VLAN:
7097 case NL80211_IFTYPE_MESH_POINT:
7098 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007099 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007100 break;
7101 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007102 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007103 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007104
7105 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007106 if (!rdev->ops->mgmt_tx)
7107 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007108
Eric W. Biederman15e47302012-09-07 20:12:54 +00007109 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007110 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7111 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007112}
7113
Johannes Berg2e161f72010-08-12 15:38:38 +02007114static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007115{
Johannes Berg4c476992010-10-04 21:36:35 +02007116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007117 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007118 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007119 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007120 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007121 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007122 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007123 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007124 bool offchan, no_cck, dont_wait_for_ack;
7125
7126 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007127
Johannes Berg683b6d32012-11-08 21:25:48 +01007128 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007129 return -EINVAL;
7130
Johannes Berg4c476992010-10-04 21:36:35 +02007131 if (!rdev->ops->mgmt_tx)
7132 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007133
Johannes Berg71bbc992012-06-15 15:30:18 +02007134 switch (wdev->iftype) {
7135 case NL80211_IFTYPE_STATION:
7136 case NL80211_IFTYPE_ADHOC:
7137 case NL80211_IFTYPE_P2P_CLIENT:
7138 case NL80211_IFTYPE_AP:
7139 case NL80211_IFTYPE_AP_VLAN:
7140 case NL80211_IFTYPE_MESH_POINT:
7141 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007142 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007143 break;
7144 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007145 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007146 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007147
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007148 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007149 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007150 return -EINVAL;
7151 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007152
7153 /*
7154 * We should wait on the channel for at least a minimum amount
7155 * of time (10ms) but no longer than the driver supports.
7156 */
7157 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7158 wait > rdev->wiphy.max_remain_on_channel_duration)
7159 return -EINVAL;
7160
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007161 }
7162
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007163 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7164
Johannes Berg7c4ef712011-11-18 15:33:48 +01007165 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7166 return -EINVAL;
7167
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307168 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7169
Johannes Berg683b6d32012-11-08 21:25:48 +01007170 err = nl80211_parse_chandef(rdev, info, &chandef);
7171 if (err)
7172 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007173
Johannes Berge247bd902011-11-04 11:18:21 +01007174 if (!dont_wait_for_ack) {
7175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7176 if (!msg)
7177 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007178
Eric W. Biederman15e47302012-09-07 20:12:54 +00007179 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007180 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007181
Johannes Berge247bd902011-11-04 11:18:21 +01007182 if (IS_ERR(hdr)) {
7183 err = PTR_ERR(hdr);
7184 goto free_msg;
7185 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007186 }
Johannes Berge247bd902011-11-04 11:18:21 +01007187
Johannes Berg683b6d32012-11-08 21:25:48 +01007188 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007189 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7190 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007191 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007192 if (err)
7193 goto free_msg;
7194
Johannes Berge247bd902011-11-04 11:18:21 +01007195 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007196 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7197 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007198
Johannes Berge247bd902011-11-04 11:18:21 +01007199 genlmsg_end(msg, hdr);
7200 return genlmsg_reply(msg, info);
7201 }
7202
7203 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007204
7205 nla_put_failure:
7206 err = -ENOBUFS;
7207 free_msg:
7208 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007209 return err;
7210}
7211
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007212static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7213{
7214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007215 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007216 u64 cookie;
7217
7218 if (!info->attrs[NL80211_ATTR_COOKIE])
7219 return -EINVAL;
7220
7221 if (!rdev->ops->mgmt_tx_cancel_wait)
7222 return -EOPNOTSUPP;
7223
Johannes Berg71bbc992012-06-15 15:30:18 +02007224 switch (wdev->iftype) {
7225 case NL80211_IFTYPE_STATION:
7226 case NL80211_IFTYPE_ADHOC:
7227 case NL80211_IFTYPE_P2P_CLIENT:
7228 case NL80211_IFTYPE_AP:
7229 case NL80211_IFTYPE_AP_VLAN:
7230 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007231 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007232 break;
7233 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007234 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007235 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007236
7237 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7238
Hila Gonene35e4d22012-06-27 17:19:42 +03007239 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007240}
7241
Kalle Valoffb9eb32010-02-17 17:58:10 +02007242static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7243{
Johannes Berg4c476992010-10-04 21:36:35 +02007244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007245 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007246 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007247 u8 ps_state;
7248 bool state;
7249 int err;
7250
Johannes Berg4c476992010-10-04 21:36:35 +02007251 if (!info->attrs[NL80211_ATTR_PS_STATE])
7252 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007253
7254 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7255
Johannes Berg4c476992010-10-04 21:36:35 +02007256 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7257 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007258
7259 wdev = dev->ieee80211_ptr;
7260
Johannes Berg4c476992010-10-04 21:36:35 +02007261 if (!rdev->ops->set_power_mgmt)
7262 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007263
7264 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7265
7266 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007267 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007268
Hila Gonene35e4d22012-06-27 17:19:42 +03007269 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007270 if (!err)
7271 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007272 return err;
7273}
7274
7275static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7276{
Johannes Berg4c476992010-10-04 21:36:35 +02007277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007278 enum nl80211_ps_state ps_state;
7279 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007280 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007281 struct sk_buff *msg;
7282 void *hdr;
7283 int err;
7284
Kalle Valoffb9eb32010-02-17 17:58:10 +02007285 wdev = dev->ieee80211_ptr;
7286
Johannes Berg4c476992010-10-04 21:36:35 +02007287 if (!rdev->ops->set_power_mgmt)
7288 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007289
7290 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007291 if (!msg)
7292 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007293
Eric W. Biederman15e47302012-09-07 20:12:54 +00007294 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007295 NL80211_CMD_GET_POWER_SAVE);
7296 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007297 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007298 goto free_msg;
7299 }
7300
7301 if (wdev->ps)
7302 ps_state = NL80211_PS_ENABLED;
7303 else
7304 ps_state = NL80211_PS_DISABLED;
7305
David S. Miller9360ffd2012-03-29 04:41:26 -04007306 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7307 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007308
7309 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007310 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007311
Johannes Berg4c476992010-10-04 21:36:35 +02007312 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007313 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007314 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007315 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007316 return err;
7317}
7318
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007319static struct nla_policy
7320nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7321 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7322 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7323 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007324 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7325 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7326 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007327};
7328
Thomas Pedersen84f10702012-07-12 16:17:33 -07007329static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007330 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007331{
7332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7333 struct wireless_dev *wdev;
7334 struct net_device *dev = info->user_ptr[1];
7335
Johannes Bergd9d8b012012-11-26 12:51:52 +01007336 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007337 return -EINVAL;
7338
7339 wdev = dev->ieee80211_ptr;
7340
7341 if (!rdev->ops->set_cqm_txe_config)
7342 return -EOPNOTSUPP;
7343
7344 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7345 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7346 return -EOPNOTSUPP;
7347
Hila Gonene35e4d22012-06-27 17:19:42 +03007348 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007349}
7350
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007351static int nl80211_set_cqm_rssi(struct genl_info *info,
7352 s32 threshold, u32 hysteresis)
7353{
Johannes Berg4c476992010-10-04 21:36:35 +02007354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007355 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007356 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007357
7358 if (threshold > 0)
7359 return -EINVAL;
7360
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007361 wdev = dev->ieee80211_ptr;
7362
Johannes Berg4c476992010-10-04 21:36:35 +02007363 if (!rdev->ops->set_cqm_rssi_config)
7364 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007365
Johannes Berg074ac8d2010-09-16 14:58:22 +02007366 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007367 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7368 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007369
Hila Gonene35e4d22012-06-27 17:19:42 +03007370 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007371}
7372
7373static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7374{
7375 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7376 struct nlattr *cqm;
7377 int err;
7378
7379 cqm = info->attrs[NL80211_ATTR_CQM];
7380 if (!cqm) {
7381 err = -EINVAL;
7382 goto out;
7383 }
7384
7385 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7386 nl80211_attr_cqm_policy);
7387 if (err)
7388 goto out;
7389
7390 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7391 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7392 s32 threshold;
7393 u32 hysteresis;
7394 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7395 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7396 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007397 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7398 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7399 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7400 u32 rate, pkts, intvl;
7401 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7402 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7403 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7404 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007405 } else
7406 err = -EINVAL;
7407
7408out:
7409 return err;
7410}
7411
Johannes Berg29cbe682010-12-03 09:20:44 +01007412static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7413{
7414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7415 struct net_device *dev = info->user_ptr[1];
7416 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007417 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007418 int err;
7419
7420 /* start with default */
7421 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007422 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007423
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007424 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007425 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007426 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007427 if (err)
7428 return err;
7429 }
7430
7431 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7432 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7433 return -EINVAL;
7434
Javier Cardonac80d5452010-12-16 17:37:49 -08007435 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7436 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7437
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007438 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7439 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7440 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7441 return -EINVAL;
7442
Marco Porsch9bdbf042013-01-07 16:04:51 +01007443 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7444 setup.beacon_interval =
7445 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7446 if (setup.beacon_interval < 10 ||
7447 setup.beacon_interval > 10000)
7448 return -EINVAL;
7449 }
7450
7451 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7452 setup.dtim_period =
7453 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7454 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7455 return -EINVAL;
7456 }
7457
Javier Cardonac80d5452010-12-16 17:37:49 -08007458 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7459 /* parse additional setup parameters if given */
7460 err = nl80211_parse_mesh_setup(info, &setup);
7461 if (err)
7462 return err;
7463 }
7464
Thomas Pedersend37bb182013-03-04 13:06:13 -08007465 if (setup.user_mpm)
7466 cfg.auto_open_plinks = false;
7467
Johannes Bergcc1d2802012-05-16 23:50:20 +02007468 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007469 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7470 if (err)
7471 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007472 } else {
7473 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007474 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007475 }
7476
Javier Cardonac80d5452010-12-16 17:37:49 -08007477 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007478}
7479
7480static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7481{
7482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7483 struct net_device *dev = info->user_ptr[1];
7484
7485 return cfg80211_leave_mesh(rdev, dev);
7486}
7487
Johannes Bergdfb89c52012-06-27 09:23:48 +02007488#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007489static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7490 struct cfg80211_registered_device *rdev)
7491{
7492 struct nlattr *nl_pats, *nl_pat;
7493 int i, pat_len;
7494
7495 if (!rdev->wowlan->n_patterns)
7496 return 0;
7497
7498 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7499 if (!nl_pats)
7500 return -ENOBUFS;
7501
7502 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
7503 nl_pat = nla_nest_start(msg, i + 1);
7504 if (!nl_pat)
7505 return -ENOBUFS;
7506 pat_len = rdev->wowlan->patterns[i].pattern_len;
7507 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7508 DIV_ROUND_UP(pat_len, 8),
7509 rdev->wowlan->patterns[i].mask) ||
7510 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
7511 pat_len, rdev->wowlan->patterns[i].pattern) ||
7512 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
7513 rdev->wowlan->patterns[i].pkt_offset))
7514 return -ENOBUFS;
7515 nla_nest_end(msg, nl_pat);
7516 }
7517 nla_nest_end(msg, nl_pats);
7518
7519 return 0;
7520}
7521
Johannes Berg2a0e0472013-01-23 22:57:40 +01007522static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7523 struct cfg80211_wowlan_tcp *tcp)
7524{
7525 struct nlattr *nl_tcp;
7526
7527 if (!tcp)
7528 return 0;
7529
7530 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7531 if (!nl_tcp)
7532 return -ENOBUFS;
7533
7534 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7535 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7536 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7537 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7538 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7539 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7540 tcp->payload_len, tcp->payload) ||
7541 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7542 tcp->data_interval) ||
7543 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7544 tcp->wake_len, tcp->wake_data) ||
7545 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7546 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7547 return -ENOBUFS;
7548
7549 if (tcp->payload_seq.len &&
7550 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7551 sizeof(tcp->payload_seq), &tcp->payload_seq))
7552 return -ENOBUFS;
7553
7554 if (tcp->payload_tok.len &&
7555 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7556 sizeof(tcp->payload_tok) + tcp->tokens_size,
7557 &tcp->payload_tok))
7558 return -ENOBUFS;
7559
Johannes Berge248ad32013-05-16 10:24:28 +02007560 nla_nest_end(msg, nl_tcp);
7561
Johannes Berg2a0e0472013-01-23 22:57:40 +01007562 return 0;
7563}
7564
Johannes Bergff1b6e62011-05-04 15:37:28 +02007565static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7566{
7567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7568 struct sk_buff *msg;
7569 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007570 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007571
Johannes Berg2a0e0472013-01-23 22:57:40 +01007572 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7573 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007574 return -EOPNOTSUPP;
7575
Johannes Berg2a0e0472013-01-23 22:57:40 +01007576 if (rdev->wowlan && rdev->wowlan->tcp) {
7577 /* adjust size to have room for all the data */
7578 size += rdev->wowlan->tcp->tokens_size +
7579 rdev->wowlan->tcp->payload_len +
7580 rdev->wowlan->tcp->wake_len +
7581 rdev->wowlan->tcp->wake_len / 8;
7582 }
7583
7584 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007585 if (!msg)
7586 return -ENOMEM;
7587
Eric W. Biederman15e47302012-09-07 20:12:54 +00007588 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007589 NL80211_CMD_GET_WOWLAN);
7590 if (!hdr)
7591 goto nla_put_failure;
7592
7593 if (rdev->wowlan) {
7594 struct nlattr *nl_wowlan;
7595
7596 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7597 if (!nl_wowlan)
7598 goto nla_put_failure;
7599
David S. Miller9360ffd2012-03-29 04:41:26 -04007600 if ((rdev->wowlan->any &&
7601 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7602 (rdev->wowlan->disconnect &&
7603 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7604 (rdev->wowlan->magic_pkt &&
7605 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7606 (rdev->wowlan->gtk_rekey_failure &&
7607 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7608 (rdev->wowlan->eap_identity_req &&
7609 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7610 (rdev->wowlan->four_way_handshake &&
7611 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7612 (rdev->wowlan->rfkill_release &&
7613 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7614 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007615
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007616 if (nl80211_send_wowlan_patterns(msg, rdev))
7617 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007618
7619 if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp))
7620 goto nla_put_failure;
7621
Johannes Bergff1b6e62011-05-04 15:37:28 +02007622 nla_nest_end(msg, nl_wowlan);
7623 }
7624
7625 genlmsg_end(msg, hdr);
7626 return genlmsg_reply(msg, info);
7627
7628nla_put_failure:
7629 nlmsg_free(msg);
7630 return -ENOBUFS;
7631}
7632
Johannes Berg2a0e0472013-01-23 22:57:40 +01007633static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7634 struct nlattr *attr,
7635 struct cfg80211_wowlan *trig)
7636{
7637 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7638 struct cfg80211_wowlan_tcp *cfg;
7639 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7640 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7641 u32 size;
7642 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7643 int err, port;
7644
7645 if (!rdev->wiphy.wowlan.tcp)
7646 return -EINVAL;
7647
7648 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7649 nla_data(attr), nla_len(attr),
7650 nl80211_wowlan_tcp_policy);
7651 if (err)
7652 return err;
7653
7654 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7655 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7656 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7657 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7658 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7659 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7660 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7661 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7662 return -EINVAL;
7663
7664 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
7665 if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max)
7666 return -EINVAL;
7667
7668 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg723d5682013-02-26 13:56:40 +01007669 rdev->wiphy.wowlan.tcp->data_interval_max ||
7670 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007671 return -EINVAL;
7672
7673 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
7674 if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max)
7675 return -EINVAL;
7676
7677 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7678 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7679 return -EINVAL;
7680
7681 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7682 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7683
7684 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7685 tokens_size = tokln - sizeof(*tok);
7686
7687 if (!tok->len || tokens_size % tok->len)
7688 return -EINVAL;
7689 if (!rdev->wiphy.wowlan.tcp->tok)
7690 return -EINVAL;
7691 if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len)
7692 return -EINVAL;
7693 if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len)
7694 return -EINVAL;
7695 if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize)
7696 return -EINVAL;
7697 if (tok->offset + tok->len > data_size)
7698 return -EINVAL;
7699 }
7700
7701 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7702 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
7703 if (!rdev->wiphy.wowlan.tcp->seq)
7704 return -EINVAL;
7705 if (seq->len == 0 || seq->len > 4)
7706 return -EINVAL;
7707 if (seq->len + seq->offset > data_size)
7708 return -EINVAL;
7709 }
7710
7711 size = sizeof(*cfg);
7712 size += data_size;
7713 size += wake_size + wake_mask_size;
7714 size += tokens_size;
7715
7716 cfg = kzalloc(size, GFP_KERNEL);
7717 if (!cfg)
7718 return -ENOMEM;
7719 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7720 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7721 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7722 ETH_ALEN);
7723 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7724 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7725 else
7726 port = 0;
7727#ifdef CONFIG_INET
7728 /* allocate a socket and port for it and use it */
7729 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7730 IPPROTO_TCP, &cfg->sock, 1);
7731 if (err) {
7732 kfree(cfg);
7733 return err;
7734 }
7735 if (inet_csk_get_port(cfg->sock->sk, port)) {
7736 sock_release(cfg->sock);
7737 kfree(cfg);
7738 return -EADDRINUSE;
7739 }
7740 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7741#else
7742 if (!port) {
7743 kfree(cfg);
7744 return -EINVAL;
7745 }
7746 cfg->src_port = port;
7747#endif
7748
7749 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7750 cfg->payload_len = data_size;
7751 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7752 memcpy((void *)cfg->payload,
7753 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7754 data_size);
7755 if (seq)
7756 cfg->payload_seq = *seq;
7757 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7758 cfg->wake_len = wake_size;
7759 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7760 memcpy((void *)cfg->wake_data,
7761 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7762 wake_size);
7763 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7764 data_size + wake_size;
7765 memcpy((void *)cfg->wake_mask,
7766 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7767 wake_mask_size);
7768 if (tok) {
7769 cfg->tokens_size = tokens_size;
7770 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7771 }
7772
7773 trig->tcp = cfg;
7774
7775 return 0;
7776}
7777
Johannes Bergff1b6e62011-05-04 15:37:28 +02007778static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7779{
7780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7781 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007782 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007783 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007784 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
7785 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02007786 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007787
Johannes Berg2a0e0472013-01-23 22:57:40 +01007788 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns &&
7789 !rdev->wiphy.wowlan.tcp)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007790 return -EOPNOTSUPP;
7791
Johannes Bergae33bd82012-07-12 16:25:02 +02007792 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7793 cfg80211_rdev_free_wowlan(rdev);
7794 rdev->wowlan = NULL;
7795 goto set_wakeup;
7796 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007797
7798 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7799 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7800 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7801 nl80211_wowlan_policy);
7802 if (err)
7803 return err;
7804
7805 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7806 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7807 return -EINVAL;
7808 new_triggers.any = true;
7809 }
7810
7811 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7812 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7813 return -EINVAL;
7814 new_triggers.disconnect = true;
7815 }
7816
7817 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7818 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7819 return -EINVAL;
7820 new_triggers.magic_pkt = true;
7821 }
7822
Johannes Berg77dbbb12011-07-13 10:48:55 +02007823 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7824 return -EINVAL;
7825
7826 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7827 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7828 return -EINVAL;
7829 new_triggers.gtk_rekey_failure = true;
7830 }
7831
7832 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7833 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7834 return -EINVAL;
7835 new_triggers.eap_identity_req = true;
7836 }
7837
7838 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7839 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7840 return -EINVAL;
7841 new_triggers.four_way_handshake = true;
7842 }
7843
7844 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7845 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7846 return -EINVAL;
7847 new_triggers.rfkill_release = true;
7848 }
7849
Johannes Bergff1b6e62011-05-04 15:37:28 +02007850 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7851 struct nlattr *pat;
7852 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007853 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007854 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7855
7856 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7857 rem)
7858 n_patterns++;
7859 if (n_patterns > wowlan->n_patterns)
7860 return -EINVAL;
7861
7862 new_triggers.patterns = kcalloc(n_patterns,
7863 sizeof(new_triggers.patterns[0]),
7864 GFP_KERNEL);
7865 if (!new_triggers.patterns)
7866 return -ENOMEM;
7867
7868 new_triggers.n_patterns = n_patterns;
7869 i = 0;
7870
7871 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7872 rem) {
7873 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7874 nla_data(pat), nla_len(pat), NULL);
7875 err = -EINVAL;
7876 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7877 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7878 goto error;
7879 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7880 mask_len = DIV_ROUND_UP(pat_len, 8);
7881 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7882 mask_len)
7883 goto error;
7884 if (pat_len > wowlan->pattern_max_len ||
7885 pat_len < wowlan->pattern_min_len)
7886 goto error;
7887
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007888 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7889 pkt_offset = 0;
7890 else
7891 pkt_offset = nla_get_u32(
7892 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7893 if (pkt_offset > wowlan->max_pkt_offset)
7894 goto error;
7895 new_triggers.patterns[i].pkt_offset = pkt_offset;
7896
Johannes Bergff1b6e62011-05-04 15:37:28 +02007897 new_triggers.patterns[i].mask =
7898 kmalloc(mask_len + pat_len, GFP_KERNEL);
7899 if (!new_triggers.patterns[i].mask) {
7900 err = -ENOMEM;
7901 goto error;
7902 }
7903 new_triggers.patterns[i].pattern =
7904 new_triggers.patterns[i].mask + mask_len;
7905 memcpy(new_triggers.patterns[i].mask,
7906 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7907 mask_len);
7908 new_triggers.patterns[i].pattern_len = pat_len;
7909 memcpy(new_triggers.patterns[i].pattern,
7910 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7911 pat_len);
7912 i++;
7913 }
7914 }
7915
Johannes Berg2a0e0472013-01-23 22:57:40 +01007916 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7917 err = nl80211_parse_wowlan_tcp(
7918 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7919 &new_triggers);
7920 if (err)
7921 goto error;
7922 }
7923
Johannes Bergae33bd82012-07-12 16:25:02 +02007924 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7925 if (!ntrig) {
7926 err = -ENOMEM;
7927 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007928 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007929 cfg80211_rdev_free_wowlan(rdev);
7930 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007931
Johannes Bergae33bd82012-07-12 16:25:02 +02007932 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02007933 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
Hila Gonene35e4d22012-06-27 17:19:42 +03007934 rdev_set_wakeup(rdev, rdev->wowlan);
Johannes Berg6d525632012-04-04 15:05:25 +02007935
Johannes Bergff1b6e62011-05-04 15:37:28 +02007936 return 0;
7937 error:
7938 for (i = 0; i < new_triggers.n_patterns; i++)
7939 kfree(new_triggers.patterns[i].mask);
7940 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007941 if (new_triggers.tcp && new_triggers.tcp->sock)
7942 sock_release(new_triggers.tcp->sock);
7943 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007944 return err;
7945}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007946#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007947
Johannes Berge5497d72011-07-05 16:35:40 +02007948static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7949{
7950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7951 struct net_device *dev = info->user_ptr[1];
7952 struct wireless_dev *wdev = dev->ieee80211_ptr;
7953 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7954 struct cfg80211_gtk_rekey_data rekey_data;
7955 int err;
7956
7957 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7958 return -EINVAL;
7959
7960 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7961 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7962 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7963 nl80211_rekey_policy);
7964 if (err)
7965 return err;
7966
7967 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7968 return -ERANGE;
7969 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7970 return -ERANGE;
7971 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7972 return -ERANGE;
7973
7974 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7975 NL80211_KEK_LEN);
7976 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7977 NL80211_KCK_LEN);
7978 memcpy(rekey_data.replay_ctr,
7979 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7980 NL80211_REPLAY_CTR_LEN);
7981
7982 wdev_lock(wdev);
7983 if (!wdev->current_bss) {
7984 err = -ENOTCONN;
7985 goto out;
7986 }
7987
7988 if (!rdev->ops->set_rekey_data) {
7989 err = -EOPNOTSUPP;
7990 goto out;
7991 }
7992
Hila Gonene35e4d22012-06-27 17:19:42 +03007993 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02007994 out:
7995 wdev_unlock(wdev);
7996 return err;
7997}
7998
Johannes Berg28946da2011-11-04 11:18:12 +01007999static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8000 struct genl_info *info)
8001{
8002 struct net_device *dev = info->user_ptr[1];
8003 struct wireless_dev *wdev = dev->ieee80211_ptr;
8004
8005 if (wdev->iftype != NL80211_IFTYPE_AP &&
8006 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8007 return -EINVAL;
8008
Eric W. Biederman15e47302012-09-07 20:12:54 +00008009 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008010 return -EBUSY;
8011
Eric W. Biederman15e47302012-09-07 20:12:54 +00008012 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008013 return 0;
8014}
8015
Johannes Berg7f6cf312011-11-04 11:18:15 +01008016static int nl80211_probe_client(struct sk_buff *skb,
8017 struct genl_info *info)
8018{
8019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8020 struct net_device *dev = info->user_ptr[1];
8021 struct wireless_dev *wdev = dev->ieee80211_ptr;
8022 struct sk_buff *msg;
8023 void *hdr;
8024 const u8 *addr;
8025 u64 cookie;
8026 int err;
8027
8028 if (wdev->iftype != NL80211_IFTYPE_AP &&
8029 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8030 return -EOPNOTSUPP;
8031
8032 if (!info->attrs[NL80211_ATTR_MAC])
8033 return -EINVAL;
8034
8035 if (!rdev->ops->probe_client)
8036 return -EOPNOTSUPP;
8037
8038 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8039 if (!msg)
8040 return -ENOMEM;
8041
Eric W. Biederman15e47302012-09-07 20:12:54 +00008042 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008043 NL80211_CMD_PROBE_CLIENT);
8044
8045 if (IS_ERR(hdr)) {
8046 err = PTR_ERR(hdr);
8047 goto free_msg;
8048 }
8049
8050 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8051
Hila Gonene35e4d22012-06-27 17:19:42 +03008052 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008053 if (err)
8054 goto free_msg;
8055
David S. Miller9360ffd2012-03-29 04:41:26 -04008056 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8057 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008058
8059 genlmsg_end(msg, hdr);
8060
8061 return genlmsg_reply(msg, info);
8062
8063 nla_put_failure:
8064 err = -ENOBUFS;
8065 free_msg:
8066 nlmsg_free(msg);
8067 return err;
8068}
8069
Johannes Berg5e760232011-11-04 11:18:17 +01008070static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8071{
8072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008073 struct cfg80211_beacon_registration *reg, *nreg;
8074 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008075
8076 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8077 return -EOPNOTSUPP;
8078
Ben Greear37c73b52012-10-26 14:49:25 -07008079 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8080 if (!nreg)
8081 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008082
Ben Greear37c73b52012-10-26 14:49:25 -07008083 /* First, check if already registered. */
8084 spin_lock_bh(&rdev->beacon_registrations_lock);
8085 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8086 if (reg->nlportid == info->snd_portid) {
8087 rv = -EALREADY;
8088 goto out_err;
8089 }
8090 }
8091 /* Add it to the list */
8092 nreg->nlportid = info->snd_portid;
8093 list_add(&nreg->list, &rdev->beacon_registrations);
8094
8095 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008096
8097 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008098out_err:
8099 spin_unlock_bh(&rdev->beacon_registrations_lock);
8100 kfree(nreg);
8101 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008102}
8103
Johannes Berg98104fde2012-06-16 00:19:54 +02008104static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8105{
8106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8107 struct wireless_dev *wdev = info->user_ptr[1];
8108 int err;
8109
8110 if (!rdev->ops->start_p2p_device)
8111 return -EOPNOTSUPP;
8112
8113 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8114 return -EOPNOTSUPP;
8115
8116 if (wdev->p2p_started)
8117 return 0;
8118
Johannes Berg98104fde2012-06-16 00:19:54 +02008119 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008120 if (err)
8121 return err;
8122
Johannes Bergeeb126e2012-10-23 15:16:50 +02008123 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008124 if (err)
8125 return err;
8126
8127 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008128 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008129
8130 return 0;
8131}
8132
8133static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8134{
8135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8136 struct wireless_dev *wdev = info->user_ptr[1];
8137
8138 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8139 return -EOPNOTSUPP;
8140
8141 if (!rdev->ops->stop_p2p_device)
8142 return -EOPNOTSUPP;
8143
Johannes Bergf9f47522013-03-19 15:04:07 +01008144 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008145
8146 return 0;
8147}
8148
Johannes Berg3713b4e2013-02-14 16:19:38 +01008149static int nl80211_get_protocol_features(struct sk_buff *skb,
8150 struct genl_info *info)
8151{
8152 void *hdr;
8153 struct sk_buff *msg;
8154
8155 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8156 if (!msg)
8157 return -ENOMEM;
8158
8159 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8160 NL80211_CMD_GET_PROTOCOL_FEATURES);
8161 if (!hdr)
8162 goto nla_put_failure;
8163
8164 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8165 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8166 goto nla_put_failure;
8167
8168 genlmsg_end(msg, hdr);
8169 return genlmsg_reply(msg, info);
8170
8171 nla_put_failure:
8172 kfree_skb(msg);
8173 return -ENOBUFS;
8174}
8175
Jouni Malinen355199e2013-02-27 17:14:27 +02008176static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8177{
8178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8179 struct cfg80211_update_ft_ies_params ft_params;
8180 struct net_device *dev = info->user_ptr[1];
8181
8182 if (!rdev->ops->update_ft_ies)
8183 return -EOPNOTSUPP;
8184
8185 if (!info->attrs[NL80211_ATTR_MDID] ||
8186 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8187 return -EINVAL;
8188
8189 memset(&ft_params, 0, sizeof(ft_params));
8190 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8191 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8192 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8193
8194 return rdev_update_ft_ies(rdev, dev, &ft_params);
8195}
8196
Arend van Spriel5de17982013-04-18 15:49:00 +02008197static int nl80211_crit_protocol_start(struct sk_buff *skb,
8198 struct genl_info *info)
8199{
8200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8201 struct wireless_dev *wdev = info->user_ptr[1];
8202 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8203 u16 duration;
8204 int ret;
8205
8206 if (!rdev->ops->crit_proto_start)
8207 return -EOPNOTSUPP;
8208
8209 if (WARN_ON(!rdev->ops->crit_proto_stop))
8210 return -EINVAL;
8211
8212 if (rdev->crit_proto_nlportid)
8213 return -EBUSY;
8214
8215 /* determine protocol if provided */
8216 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8217 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8218
8219 if (proto >= NUM_NL80211_CRIT_PROTO)
8220 return -EINVAL;
8221
8222 /* timeout must be provided */
8223 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8224 return -EINVAL;
8225
8226 duration =
8227 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8228
8229 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8230 return -ERANGE;
8231
8232 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8233 if (!ret)
8234 rdev->crit_proto_nlportid = info->snd_portid;
8235
8236 return ret;
8237}
8238
8239static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8240 struct genl_info *info)
8241{
8242 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8243 struct wireless_dev *wdev = info->user_ptr[1];
8244
8245 if (!rdev->ops->crit_proto_stop)
8246 return -EOPNOTSUPP;
8247
8248 if (rdev->crit_proto_nlportid) {
8249 rdev->crit_proto_nlportid = 0;
8250 rdev_crit_proto_stop(rdev, wdev);
8251 }
8252 return 0;
8253}
8254
Johannes Berg4c476992010-10-04 21:36:35 +02008255#define NL80211_FLAG_NEED_WIPHY 0x01
8256#define NL80211_FLAG_NEED_NETDEV 0x02
8257#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008258#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8259#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8260 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008261#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008262/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008263#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8264 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008265
8266static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8267 struct genl_info *info)
8268{
8269 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008270 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008271 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008272 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8273
8274 if (rtnl)
8275 rtnl_lock();
8276
8277 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008278 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008279 if (IS_ERR(rdev)) {
8280 if (rtnl)
8281 rtnl_unlock();
8282 return PTR_ERR(rdev);
8283 }
8284 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008285 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8286 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008287 ASSERT_RTNL();
8288
Johannes Berg89a54e42012-06-15 14:33:17 +02008289 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8290 info->attrs);
8291 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008292 if (rtnl)
8293 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008294 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008295 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008296
Johannes Berg89a54e42012-06-15 14:33:17 +02008297 dev = wdev->netdev;
8298 rdev = wiphy_to_dev(wdev->wiphy);
8299
Johannes Berg1bf614e2012-06-15 15:23:36 +02008300 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8301 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008302 if (rtnl)
8303 rtnl_unlock();
8304 return -EINVAL;
8305 }
8306
8307 info->user_ptr[1] = dev;
8308 } else {
8309 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008310 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008311
Johannes Berg1bf614e2012-06-15 15:23:36 +02008312 if (dev) {
8313 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8314 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008315 if (rtnl)
8316 rtnl_unlock();
8317 return -ENETDOWN;
8318 }
8319
8320 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008321 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8322 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008323 if (rtnl)
8324 rtnl_unlock();
8325 return -ENETDOWN;
8326 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008327 }
8328
Johannes Berg4c476992010-10-04 21:36:35 +02008329 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008330 }
8331
8332 return 0;
8333}
8334
8335static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8336 struct genl_info *info)
8337{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008338 if (info->user_ptr[1]) {
8339 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8340 struct wireless_dev *wdev = info->user_ptr[1];
8341
8342 if (wdev->netdev)
8343 dev_put(wdev->netdev);
8344 } else {
8345 dev_put(info->user_ptr[1]);
8346 }
8347 }
Johannes Berg4c476992010-10-04 21:36:35 +02008348 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8349 rtnl_unlock();
8350}
8351
Johannes Berg55682962007-09-20 13:09:35 -04008352static struct genl_ops nl80211_ops[] = {
8353 {
8354 .cmd = NL80211_CMD_GET_WIPHY,
8355 .doit = nl80211_get_wiphy,
8356 .dumpit = nl80211_dump_wiphy,
8357 .policy = nl80211_policy,
8358 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008359 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8360 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008361 },
8362 {
8363 .cmd = NL80211_CMD_SET_WIPHY,
8364 .doit = nl80211_set_wiphy,
8365 .policy = nl80211_policy,
8366 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008367 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008368 },
8369 {
8370 .cmd = NL80211_CMD_GET_INTERFACE,
8371 .doit = nl80211_get_interface,
8372 .dumpit = nl80211_dump_interface,
8373 .policy = nl80211_policy,
8374 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008375 .internal_flags = NL80211_FLAG_NEED_WDEV |
8376 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008377 },
8378 {
8379 .cmd = NL80211_CMD_SET_INTERFACE,
8380 .doit = nl80211_set_interface,
8381 .policy = nl80211_policy,
8382 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008383 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8384 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008385 },
8386 {
8387 .cmd = NL80211_CMD_NEW_INTERFACE,
8388 .doit = nl80211_new_interface,
8389 .policy = nl80211_policy,
8390 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008391 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8392 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008393 },
8394 {
8395 .cmd = NL80211_CMD_DEL_INTERFACE,
8396 .doit = nl80211_del_interface,
8397 .policy = nl80211_policy,
8398 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008399 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008400 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008401 },
Johannes Berg41ade002007-12-19 02:03:29 +01008402 {
8403 .cmd = NL80211_CMD_GET_KEY,
8404 .doit = nl80211_get_key,
8405 .policy = nl80211_policy,
8406 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008407 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008408 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008409 },
8410 {
8411 .cmd = NL80211_CMD_SET_KEY,
8412 .doit = nl80211_set_key,
8413 .policy = nl80211_policy,
8414 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008415 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008416 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008417 },
8418 {
8419 .cmd = NL80211_CMD_NEW_KEY,
8420 .doit = nl80211_new_key,
8421 .policy = nl80211_policy,
8422 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008423 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008424 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008425 },
8426 {
8427 .cmd = NL80211_CMD_DEL_KEY,
8428 .doit = nl80211_del_key,
8429 .policy = nl80211_policy,
8430 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008432 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008433 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008434 {
8435 .cmd = NL80211_CMD_SET_BEACON,
8436 .policy = nl80211_policy,
8437 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008438 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008440 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008441 },
8442 {
Johannes Berg88600202012-02-13 15:17:18 +01008443 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008444 .policy = nl80211_policy,
8445 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008446 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008448 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008449 },
8450 {
Johannes Berg88600202012-02-13 15:17:18 +01008451 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008452 .policy = nl80211_policy,
8453 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008454 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008456 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008457 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008458 {
8459 .cmd = NL80211_CMD_GET_STATION,
8460 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008461 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008462 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008463 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8464 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008465 },
8466 {
8467 .cmd = NL80211_CMD_SET_STATION,
8468 .doit = nl80211_set_station,
8469 .policy = nl80211_policy,
8470 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008472 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008473 },
8474 {
8475 .cmd = NL80211_CMD_NEW_STATION,
8476 .doit = nl80211_new_station,
8477 .policy = nl80211_policy,
8478 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008480 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008481 },
8482 {
8483 .cmd = NL80211_CMD_DEL_STATION,
8484 .doit = nl80211_del_station,
8485 .policy = nl80211_policy,
8486 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008487 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008488 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008489 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008490 {
8491 .cmd = NL80211_CMD_GET_MPATH,
8492 .doit = nl80211_get_mpath,
8493 .dumpit = nl80211_dump_mpath,
8494 .policy = nl80211_policy,
8495 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008497 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008498 },
8499 {
8500 .cmd = NL80211_CMD_SET_MPATH,
8501 .doit = nl80211_set_mpath,
8502 .policy = nl80211_policy,
8503 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008505 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008506 },
8507 {
8508 .cmd = NL80211_CMD_NEW_MPATH,
8509 .doit = nl80211_new_mpath,
8510 .policy = nl80211_policy,
8511 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008513 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008514 },
8515 {
8516 .cmd = NL80211_CMD_DEL_MPATH,
8517 .doit = nl80211_del_mpath,
8518 .policy = nl80211_policy,
8519 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008521 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008522 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008523 {
8524 .cmd = NL80211_CMD_SET_BSS,
8525 .doit = nl80211_set_bss,
8526 .policy = nl80211_policy,
8527 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008529 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008530 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008531 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008532 .cmd = NL80211_CMD_GET_REG,
8533 .doit = nl80211_get_reg,
8534 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008535 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008536 /* can be retrieved by unprivileged users */
8537 },
8538 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008539 .cmd = NL80211_CMD_SET_REG,
8540 .doit = nl80211_set_reg,
8541 .policy = nl80211_policy,
8542 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008543 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008544 },
8545 {
8546 .cmd = NL80211_CMD_REQ_SET_REG,
8547 .doit = nl80211_req_set_reg,
8548 .policy = nl80211_policy,
8549 .flags = GENL_ADMIN_PERM,
8550 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008551 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008552 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8553 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008554 .policy = nl80211_policy,
8555 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008556 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008557 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008558 },
8559 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008560 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8561 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008562 .policy = nl80211_policy,
8563 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008564 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008565 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008566 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008567 {
Johannes Berg2a519312009-02-10 21:25:55 +01008568 .cmd = NL80211_CMD_TRIGGER_SCAN,
8569 .doit = nl80211_trigger_scan,
8570 .policy = nl80211_policy,
8571 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008572 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008573 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008574 },
8575 {
8576 .cmd = NL80211_CMD_GET_SCAN,
8577 .policy = nl80211_policy,
8578 .dumpit = nl80211_dump_scan,
8579 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008580 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008581 .cmd = NL80211_CMD_START_SCHED_SCAN,
8582 .doit = nl80211_start_sched_scan,
8583 .policy = nl80211_policy,
8584 .flags = GENL_ADMIN_PERM,
8585 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8586 NL80211_FLAG_NEED_RTNL,
8587 },
8588 {
8589 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8590 .doit = nl80211_stop_sched_scan,
8591 .policy = nl80211_policy,
8592 .flags = GENL_ADMIN_PERM,
8593 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8594 NL80211_FLAG_NEED_RTNL,
8595 },
8596 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008597 .cmd = NL80211_CMD_AUTHENTICATE,
8598 .doit = nl80211_authenticate,
8599 .policy = nl80211_policy,
8600 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008601 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008602 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008603 },
8604 {
8605 .cmd = NL80211_CMD_ASSOCIATE,
8606 .doit = nl80211_associate,
8607 .policy = nl80211_policy,
8608 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008610 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008611 },
8612 {
8613 .cmd = NL80211_CMD_DEAUTHENTICATE,
8614 .doit = nl80211_deauthenticate,
8615 .policy = nl80211_policy,
8616 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008617 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008618 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008619 },
8620 {
8621 .cmd = NL80211_CMD_DISASSOCIATE,
8622 .doit = nl80211_disassociate,
8623 .policy = nl80211_policy,
8624 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008625 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008626 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008627 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008628 {
8629 .cmd = NL80211_CMD_JOIN_IBSS,
8630 .doit = nl80211_join_ibss,
8631 .policy = nl80211_policy,
8632 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008634 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008635 },
8636 {
8637 .cmd = NL80211_CMD_LEAVE_IBSS,
8638 .doit = nl80211_leave_ibss,
8639 .policy = nl80211_policy,
8640 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008642 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008643 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008644#ifdef CONFIG_NL80211_TESTMODE
8645 {
8646 .cmd = NL80211_CMD_TESTMODE,
8647 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008648 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008649 .policy = nl80211_policy,
8650 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008651 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8652 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008653 },
8654#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008655 {
8656 .cmd = NL80211_CMD_CONNECT,
8657 .doit = nl80211_connect,
8658 .policy = nl80211_policy,
8659 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008660 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008661 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008662 },
8663 {
8664 .cmd = NL80211_CMD_DISCONNECT,
8665 .doit = nl80211_disconnect,
8666 .policy = nl80211_policy,
8667 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008669 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008670 },
Johannes Berg463d0182009-07-14 00:33:35 +02008671 {
8672 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8673 .doit = nl80211_wiphy_netns,
8674 .policy = nl80211_policy,
8675 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008676 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8677 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008678 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008679 {
8680 .cmd = NL80211_CMD_GET_SURVEY,
8681 .policy = nl80211_policy,
8682 .dumpit = nl80211_dump_survey,
8683 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008684 {
8685 .cmd = NL80211_CMD_SET_PMKSA,
8686 .doit = nl80211_setdel_pmksa,
8687 .policy = nl80211_policy,
8688 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008689 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008690 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008691 },
8692 {
8693 .cmd = NL80211_CMD_DEL_PMKSA,
8694 .doit = nl80211_setdel_pmksa,
8695 .policy = nl80211_policy,
8696 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008697 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008698 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008699 },
8700 {
8701 .cmd = NL80211_CMD_FLUSH_PMKSA,
8702 .doit = nl80211_flush_pmksa,
8703 .policy = nl80211_policy,
8704 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008705 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008706 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008707 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008708 {
8709 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8710 .doit = nl80211_remain_on_channel,
8711 .policy = nl80211_policy,
8712 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008713 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008714 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008715 },
8716 {
8717 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8718 .doit = nl80211_cancel_remain_on_channel,
8719 .policy = nl80211_policy,
8720 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008721 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008722 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008723 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008724 {
8725 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8726 .doit = nl80211_set_tx_bitrate_mask,
8727 .policy = nl80211_policy,
8728 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008729 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8730 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008731 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008732 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008733 .cmd = NL80211_CMD_REGISTER_FRAME,
8734 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008735 .policy = nl80211_policy,
8736 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008737 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008738 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008739 },
8740 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008741 .cmd = NL80211_CMD_FRAME,
8742 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008743 .policy = nl80211_policy,
8744 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008745 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008746 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008747 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008748 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008749 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8750 .doit = nl80211_tx_mgmt_cancel_wait,
8751 .policy = nl80211_policy,
8752 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008753 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008754 NL80211_FLAG_NEED_RTNL,
8755 },
8756 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008757 .cmd = NL80211_CMD_SET_POWER_SAVE,
8758 .doit = nl80211_set_power_save,
8759 .policy = nl80211_policy,
8760 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008761 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8762 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008763 },
8764 {
8765 .cmd = NL80211_CMD_GET_POWER_SAVE,
8766 .doit = nl80211_get_power_save,
8767 .policy = nl80211_policy,
8768 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008769 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8770 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008771 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008772 {
8773 .cmd = NL80211_CMD_SET_CQM,
8774 .doit = nl80211_set_cqm,
8775 .policy = nl80211_policy,
8776 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008777 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8778 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008779 },
Johannes Bergf444de02010-05-05 15:25:02 +02008780 {
8781 .cmd = NL80211_CMD_SET_CHANNEL,
8782 .doit = nl80211_set_channel,
8783 .policy = nl80211_policy,
8784 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008785 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8786 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008787 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008788 {
8789 .cmd = NL80211_CMD_SET_WDS_PEER,
8790 .doit = nl80211_set_wds_peer,
8791 .policy = nl80211_policy,
8792 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008793 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8794 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008795 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008796 {
8797 .cmd = NL80211_CMD_JOIN_MESH,
8798 .doit = nl80211_join_mesh,
8799 .policy = nl80211_policy,
8800 .flags = GENL_ADMIN_PERM,
8801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8802 NL80211_FLAG_NEED_RTNL,
8803 },
8804 {
8805 .cmd = NL80211_CMD_LEAVE_MESH,
8806 .doit = nl80211_leave_mesh,
8807 .policy = nl80211_policy,
8808 .flags = GENL_ADMIN_PERM,
8809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8810 NL80211_FLAG_NEED_RTNL,
8811 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008812#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008813 {
8814 .cmd = NL80211_CMD_GET_WOWLAN,
8815 .doit = nl80211_get_wowlan,
8816 .policy = nl80211_policy,
8817 /* can be retrieved by unprivileged users */
8818 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8819 NL80211_FLAG_NEED_RTNL,
8820 },
8821 {
8822 .cmd = NL80211_CMD_SET_WOWLAN,
8823 .doit = nl80211_set_wowlan,
8824 .policy = nl80211_policy,
8825 .flags = GENL_ADMIN_PERM,
8826 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8827 NL80211_FLAG_NEED_RTNL,
8828 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008829#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008830 {
8831 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8832 .doit = nl80211_set_rekey_data,
8833 .policy = nl80211_policy,
8834 .flags = GENL_ADMIN_PERM,
8835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8836 NL80211_FLAG_NEED_RTNL,
8837 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008838 {
8839 .cmd = NL80211_CMD_TDLS_MGMT,
8840 .doit = nl80211_tdls_mgmt,
8841 .policy = nl80211_policy,
8842 .flags = GENL_ADMIN_PERM,
8843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8844 NL80211_FLAG_NEED_RTNL,
8845 },
8846 {
8847 .cmd = NL80211_CMD_TDLS_OPER,
8848 .doit = nl80211_tdls_oper,
8849 .policy = nl80211_policy,
8850 .flags = GENL_ADMIN_PERM,
8851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8852 NL80211_FLAG_NEED_RTNL,
8853 },
Johannes Berg28946da2011-11-04 11:18:12 +01008854 {
8855 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8856 .doit = nl80211_register_unexpected_frame,
8857 .policy = nl80211_policy,
8858 .flags = GENL_ADMIN_PERM,
8859 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8860 NL80211_FLAG_NEED_RTNL,
8861 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008862 {
8863 .cmd = NL80211_CMD_PROBE_CLIENT,
8864 .doit = nl80211_probe_client,
8865 .policy = nl80211_policy,
8866 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008868 NL80211_FLAG_NEED_RTNL,
8869 },
Johannes Berg5e760232011-11-04 11:18:17 +01008870 {
8871 .cmd = NL80211_CMD_REGISTER_BEACONS,
8872 .doit = nl80211_register_beacons,
8873 .policy = nl80211_policy,
8874 .flags = GENL_ADMIN_PERM,
8875 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8876 NL80211_FLAG_NEED_RTNL,
8877 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008878 {
8879 .cmd = NL80211_CMD_SET_NOACK_MAP,
8880 .doit = nl80211_set_noack_map,
8881 .policy = nl80211_policy,
8882 .flags = GENL_ADMIN_PERM,
8883 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8884 NL80211_FLAG_NEED_RTNL,
8885 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008886 {
8887 .cmd = NL80211_CMD_START_P2P_DEVICE,
8888 .doit = nl80211_start_p2p_device,
8889 .policy = nl80211_policy,
8890 .flags = GENL_ADMIN_PERM,
8891 .internal_flags = NL80211_FLAG_NEED_WDEV |
8892 NL80211_FLAG_NEED_RTNL,
8893 },
8894 {
8895 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8896 .doit = nl80211_stop_p2p_device,
8897 .policy = nl80211_policy,
8898 .flags = GENL_ADMIN_PERM,
8899 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8900 NL80211_FLAG_NEED_RTNL,
8901 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008902 {
8903 .cmd = NL80211_CMD_SET_MCAST_RATE,
8904 .doit = nl80211_set_mcast_rate,
8905 .policy = nl80211_policy,
8906 .flags = GENL_ADMIN_PERM,
8907 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8908 NL80211_FLAG_NEED_RTNL,
8909 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308910 {
8911 .cmd = NL80211_CMD_SET_MAC_ACL,
8912 .doit = nl80211_set_mac_acl,
8913 .policy = nl80211_policy,
8914 .flags = GENL_ADMIN_PERM,
8915 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8916 NL80211_FLAG_NEED_RTNL,
8917 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008918 {
8919 .cmd = NL80211_CMD_RADAR_DETECT,
8920 .doit = nl80211_start_radar_detection,
8921 .policy = nl80211_policy,
8922 .flags = GENL_ADMIN_PERM,
8923 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8924 NL80211_FLAG_NEED_RTNL,
8925 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008926 {
8927 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8928 .doit = nl80211_get_protocol_features,
8929 .policy = nl80211_policy,
8930 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008931 {
8932 .cmd = NL80211_CMD_UPDATE_FT_IES,
8933 .doit = nl80211_update_ft_ies,
8934 .policy = nl80211_policy,
8935 .flags = GENL_ADMIN_PERM,
8936 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8937 NL80211_FLAG_NEED_RTNL,
8938 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008939 {
8940 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8941 .doit = nl80211_crit_protocol_start,
8942 .policy = nl80211_policy,
8943 .flags = GENL_ADMIN_PERM,
8944 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8945 NL80211_FLAG_NEED_RTNL,
8946 },
8947 {
8948 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
8949 .doit = nl80211_crit_protocol_stop,
8950 .policy = nl80211_policy,
8951 .flags = GENL_ADMIN_PERM,
8952 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8953 NL80211_FLAG_NEED_RTNL,
8954 }
Johannes Berg55682962007-09-20 13:09:35 -04008955};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008956
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008957static struct genl_multicast_group nl80211_mlme_mcgrp = {
8958 .name = "mlme",
8959};
Johannes Berg55682962007-09-20 13:09:35 -04008960
8961/* multicast groups */
8962static struct genl_multicast_group nl80211_config_mcgrp = {
8963 .name = "config",
8964};
Johannes Berg2a519312009-02-10 21:25:55 +01008965static struct genl_multicast_group nl80211_scan_mcgrp = {
8966 .name = "scan",
8967};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008968static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8969 .name = "regulatory",
8970};
Johannes Berg55682962007-09-20 13:09:35 -04008971
8972/* notification functions */
8973
8974void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8975{
8976 struct sk_buff *msg;
8977
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008978 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008979 if (!msg)
8980 return;
8981
Johannes Berg3713b4e2013-02-14 16:19:38 +01008982 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8983 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008984 nlmsg_free(msg);
8985 return;
8986 }
8987
Johannes Berg463d0182009-07-14 00:33:35 +02008988 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8989 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008990}
8991
Johannes Berg362a4152009-05-24 16:43:15 +02008992static int nl80211_add_scan_req(struct sk_buff *msg,
8993 struct cfg80211_registered_device *rdev)
8994{
8995 struct cfg80211_scan_request *req = rdev->scan_req;
8996 struct nlattr *nest;
8997 int i;
8998
8999 if (WARN_ON(!req))
9000 return 0;
9001
9002 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9003 if (!nest)
9004 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009005 for (i = 0; i < req->n_ssids; i++) {
9006 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9007 goto nla_put_failure;
9008 }
Johannes Berg362a4152009-05-24 16:43:15 +02009009 nla_nest_end(msg, nest);
9010
9011 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9012 if (!nest)
9013 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009014 for (i = 0; i < req->n_channels; i++) {
9015 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9016 goto nla_put_failure;
9017 }
Johannes Berg362a4152009-05-24 16:43:15 +02009018 nla_nest_end(msg, nest);
9019
David S. Miller9360ffd2012-03-29 04:41:26 -04009020 if (req->ie &&
9021 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9022 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009023
Sam Lefflered4737712012-10-11 21:03:31 -07009024 if (req->flags)
9025 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9026
Johannes Berg362a4152009-05-24 16:43:15 +02009027 return 0;
9028 nla_put_failure:
9029 return -ENOBUFS;
9030}
9031
Johannes Berga538e2d2009-06-16 19:56:42 +02009032static int nl80211_send_scan_msg(struct sk_buff *msg,
9033 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009034 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009035 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009036 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009037{
9038 void *hdr;
9039
Eric W. Biederman15e47302012-09-07 20:12:54 +00009040 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009041 if (!hdr)
9042 return -1;
9043
David S. Miller9360ffd2012-03-29 04:41:26 -04009044 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009045 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9046 wdev->netdev->ifindex)) ||
9047 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009048 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009049
Johannes Berg362a4152009-05-24 16:43:15 +02009050 /* ignore errors and send incomplete event anyway */
9051 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009052
9053 return genlmsg_end(msg, hdr);
9054
9055 nla_put_failure:
9056 genlmsg_cancel(msg, hdr);
9057 return -EMSGSIZE;
9058}
9059
Luciano Coelho807f8a82011-05-11 17:09:35 +03009060static int
9061nl80211_send_sched_scan_msg(struct sk_buff *msg,
9062 struct cfg80211_registered_device *rdev,
9063 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009064 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009065{
9066 void *hdr;
9067
Eric W. Biederman15e47302012-09-07 20:12:54 +00009068 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009069 if (!hdr)
9070 return -1;
9071
David S. Miller9360ffd2012-03-29 04:41:26 -04009072 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9073 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9074 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009075
9076 return genlmsg_end(msg, hdr);
9077
9078 nla_put_failure:
9079 genlmsg_cancel(msg, hdr);
9080 return -EMSGSIZE;
9081}
9082
Johannes Berga538e2d2009-06-16 19:56:42 +02009083void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009084 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009085{
9086 struct sk_buff *msg;
9087
Thomas Graf58050fc2012-06-28 03:57:45 +00009088 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009089 if (!msg)
9090 return;
9091
Johannes Bergfd014282012-06-18 19:17:03 +02009092 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009093 NL80211_CMD_TRIGGER_SCAN) < 0) {
9094 nlmsg_free(msg);
9095 return;
9096 }
9097
Johannes Berg463d0182009-07-14 00:33:35 +02009098 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9099 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009100}
9101
Johannes Berg2a519312009-02-10 21:25:55 +01009102void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009103 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009104{
9105 struct sk_buff *msg;
9106
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009108 if (!msg)
9109 return;
9110
Johannes Bergfd014282012-06-18 19:17:03 +02009111 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009112 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009113 nlmsg_free(msg);
9114 return;
9115 }
9116
Johannes Berg463d0182009-07-14 00:33:35 +02009117 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9118 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009119}
9120
9121void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009122 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009123{
9124 struct sk_buff *msg;
9125
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009126 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009127 if (!msg)
9128 return;
9129
Johannes Bergfd014282012-06-18 19:17:03 +02009130 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009131 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009132 nlmsg_free(msg);
9133 return;
9134 }
9135
Johannes Berg463d0182009-07-14 00:33:35 +02009136 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9137 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009138}
9139
Luciano Coelho807f8a82011-05-11 17:09:35 +03009140void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9141 struct net_device *netdev)
9142{
9143 struct sk_buff *msg;
9144
9145 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9146 if (!msg)
9147 return;
9148
9149 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9150 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9151 nlmsg_free(msg);
9152 return;
9153 }
9154
9155 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9156 nl80211_scan_mcgrp.id, GFP_KERNEL);
9157}
9158
9159void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9160 struct net_device *netdev, u32 cmd)
9161{
9162 struct sk_buff *msg;
9163
Thomas Graf58050fc2012-06-28 03:57:45 +00009164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009165 if (!msg)
9166 return;
9167
9168 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9169 nlmsg_free(msg);
9170 return;
9171 }
9172
9173 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9174 nl80211_scan_mcgrp.id, GFP_KERNEL);
9175}
9176
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009177/*
9178 * This can happen on global regulatory changes or device specific settings
9179 * based on custom world regulatory domains.
9180 */
9181void nl80211_send_reg_change_event(struct regulatory_request *request)
9182{
9183 struct sk_buff *msg;
9184 void *hdr;
9185
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009187 if (!msg)
9188 return;
9189
9190 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9191 if (!hdr) {
9192 nlmsg_free(msg);
9193 return;
9194 }
9195
9196 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009197 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9198 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009199
David S. Miller9360ffd2012-03-29 04:41:26 -04009200 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9201 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9202 NL80211_REGDOM_TYPE_WORLD))
9203 goto nla_put_failure;
9204 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9205 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9206 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9207 goto nla_put_failure;
9208 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9209 request->intersect) {
9210 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9211 NL80211_REGDOM_TYPE_INTERSECTION))
9212 goto nla_put_failure;
9213 } else {
9214 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9215 NL80211_REGDOM_TYPE_COUNTRY) ||
9216 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9217 request->alpha2))
9218 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009219 }
9220
Johannes Bergf4173762012-12-03 18:23:37 +01009221 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009222 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9223 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009224
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009225 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009226
Johannes Bergbc43b282009-07-25 10:54:13 +02009227 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009228 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009229 GFP_ATOMIC);
9230 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009231
9232 return;
9233
9234nla_put_failure:
9235 genlmsg_cancel(msg, hdr);
9236 nlmsg_free(msg);
9237}
9238
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009239static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9240 struct net_device *netdev,
9241 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009242 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009243{
9244 struct sk_buff *msg;
9245 void *hdr;
9246
Johannes Berge6d6e342009-07-01 21:26:47 +02009247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009248 if (!msg)
9249 return;
9250
9251 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9252 if (!hdr) {
9253 nlmsg_free(msg);
9254 return;
9255 }
9256
David S. Miller9360ffd2012-03-29 04:41:26 -04009257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9258 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9259 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9260 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009261
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009262 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009263
Johannes Berg463d0182009-07-14 00:33:35 +02009264 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9265 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009266 return;
9267
9268 nla_put_failure:
9269 genlmsg_cancel(msg, hdr);
9270 nlmsg_free(msg);
9271}
9272
9273void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009274 struct net_device *netdev, const u8 *buf,
9275 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009276{
9277 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009278 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009279}
9280
9281void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9282 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009283 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009284{
Johannes Berge6d6e342009-07-01 21:26:47 +02009285 nl80211_send_mlme_event(rdev, netdev, buf, len,
9286 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009287}
9288
Jouni Malinen53b46b82009-03-27 20:53:56 +02009289void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009290 struct net_device *netdev, const u8 *buf,
9291 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009292{
9293 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009294 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009295}
9296
Jouni Malinen53b46b82009-03-27 20:53:56 +02009297void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9298 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009299 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009300{
9301 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009302 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009303}
9304
Johannes Berg947add32013-02-22 22:05:20 +01009305void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
9306 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009307{
Johannes Berg947add32013-02-22 22:05:20 +01009308 struct wireless_dev *wdev = dev->ieee80211_ptr;
9309 struct wiphy *wiphy = wdev->wiphy;
9310 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009311
Johannes Berg947add32013-02-22 22:05:20 +01009312 trace_cfg80211_send_unprot_deauth(dev);
9313 nl80211_send_mlme_event(rdev, dev, buf, len,
9314 NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009315}
Johannes Berg947add32013-02-22 22:05:20 +01009316EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
9317
9318void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
9319 size_t len)
9320{
9321 struct wireless_dev *wdev = dev->ieee80211_ptr;
9322 struct wiphy *wiphy = wdev->wiphy;
9323 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9324
9325 trace_cfg80211_send_unprot_disassoc(dev);
9326 nl80211_send_mlme_event(rdev, dev, buf, len,
9327 NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC);
9328}
9329EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009330
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009331static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9332 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009333 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009334{
9335 struct sk_buff *msg;
9336 void *hdr;
9337
Johannes Berge6d6e342009-07-01 21:26:47 +02009338 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009339 if (!msg)
9340 return;
9341
9342 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9343 if (!hdr) {
9344 nlmsg_free(msg);
9345 return;
9346 }
9347
David S. Miller9360ffd2012-03-29 04:41:26 -04009348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9349 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9350 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9351 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9352 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009353
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009354 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009355
Johannes Berg463d0182009-07-14 00:33:35 +02009356 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9357 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009358 return;
9359
9360 nla_put_failure:
9361 genlmsg_cancel(msg, hdr);
9362 nlmsg_free(msg);
9363}
9364
9365void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009366 struct net_device *netdev, const u8 *addr,
9367 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009368{
9369 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009370 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009371}
9372
9373void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009374 struct net_device *netdev, const u8 *addr,
9375 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009376{
Johannes Berge6d6e342009-07-01 21:26:47 +02009377 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9378 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009379}
9380
Samuel Ortizb23aa672009-07-01 21:26:54 +02009381void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9382 struct net_device *netdev, const u8 *bssid,
9383 const u8 *req_ie, size_t req_ie_len,
9384 const u8 *resp_ie, size_t resp_ie_len,
9385 u16 status, gfp_t gfp)
9386{
9387 struct sk_buff *msg;
9388 void *hdr;
9389
Thomas Graf58050fc2012-06-28 03:57:45 +00009390 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009391 if (!msg)
9392 return;
9393
9394 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9395 if (!hdr) {
9396 nlmsg_free(msg);
9397 return;
9398 }
9399
David S. Miller9360ffd2012-03-29 04:41:26 -04009400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9401 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9402 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9403 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9404 (req_ie &&
9405 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9406 (resp_ie &&
9407 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9408 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009409
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009410 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009411
Johannes Berg463d0182009-07-14 00:33:35 +02009412 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9413 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009414 return;
9415
9416 nla_put_failure:
9417 genlmsg_cancel(msg, hdr);
9418 nlmsg_free(msg);
9419
9420}
9421
9422void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9423 struct net_device *netdev, const u8 *bssid,
9424 const u8 *req_ie, size_t req_ie_len,
9425 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9426{
9427 struct sk_buff *msg;
9428 void *hdr;
9429
Thomas Graf58050fc2012-06-28 03:57:45 +00009430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009431 if (!msg)
9432 return;
9433
9434 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9435 if (!hdr) {
9436 nlmsg_free(msg);
9437 return;
9438 }
9439
David S. Miller9360ffd2012-03-29 04:41:26 -04009440 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9441 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9442 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9443 (req_ie &&
9444 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9445 (resp_ie &&
9446 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9447 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009448
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009449 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009450
Johannes Berg463d0182009-07-14 00:33:35 +02009451 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9452 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009453 return;
9454
9455 nla_put_failure:
9456 genlmsg_cancel(msg, hdr);
9457 nlmsg_free(msg);
9458
9459}
9460
9461void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9462 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009463 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009464{
9465 struct sk_buff *msg;
9466 void *hdr;
9467
Thomas Graf58050fc2012-06-28 03:57:45 +00009468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009469 if (!msg)
9470 return;
9471
9472 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9473 if (!hdr) {
9474 nlmsg_free(msg);
9475 return;
9476 }
9477
David S. Miller9360ffd2012-03-29 04:41:26 -04009478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9480 (from_ap && reason &&
9481 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9482 (from_ap &&
9483 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9484 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9485 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009486
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009487 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009488
Johannes Berg463d0182009-07-14 00:33:35 +02009489 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9490 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009491 return;
9492
9493 nla_put_failure:
9494 genlmsg_cancel(msg, hdr);
9495 nlmsg_free(msg);
9496
9497}
9498
Johannes Berg04a773a2009-04-19 21:24:32 +02009499void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9500 struct net_device *netdev, const u8 *bssid,
9501 gfp_t gfp)
9502{
9503 struct sk_buff *msg;
9504 void *hdr;
9505
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009506 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009507 if (!msg)
9508 return;
9509
9510 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9511 if (!hdr) {
9512 nlmsg_free(msg);
9513 return;
9514 }
9515
David S. Miller9360ffd2012-03-29 04:41:26 -04009516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9517 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9518 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9519 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009520
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009521 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009522
Johannes Berg463d0182009-07-14 00:33:35 +02009523 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9524 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009525 return;
9526
9527 nla_put_failure:
9528 genlmsg_cancel(msg, hdr);
9529 nlmsg_free(msg);
9530}
9531
Johannes Berg947add32013-02-22 22:05:20 +01009532void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9533 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009534{
Johannes Berg947add32013-02-22 22:05:20 +01009535 struct wireless_dev *wdev = dev->ieee80211_ptr;
9536 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009537 struct sk_buff *msg;
9538 void *hdr;
9539
Johannes Berg947add32013-02-22 22:05:20 +01009540 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9541 return;
9542
9543 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9544
Javier Cardonac93b5e72011-04-07 15:08:34 -07009545 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9546 if (!msg)
9547 return;
9548
9549 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9550 if (!hdr) {
9551 nlmsg_free(msg);
9552 return;
9553 }
9554
David S. Miller9360ffd2012-03-29 04:41:26 -04009555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009556 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9557 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009558 (ie_len && ie &&
9559 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9560 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009561
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009562 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009563
9564 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9565 nl80211_mlme_mcgrp.id, gfp);
9566 return;
9567
9568 nla_put_failure:
9569 genlmsg_cancel(msg, hdr);
9570 nlmsg_free(msg);
9571}
Johannes Berg947add32013-02-22 22:05:20 +01009572EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009573
Jouni Malinena3b8b052009-03-27 21:59:49 +02009574void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9575 struct net_device *netdev, const u8 *addr,
9576 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009577 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009578{
9579 struct sk_buff *msg;
9580 void *hdr;
9581
Johannes Berge6d6e342009-07-01 21:26:47 +02009582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009583 if (!msg)
9584 return;
9585
9586 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9587 if (!hdr) {
9588 nlmsg_free(msg);
9589 return;
9590 }
9591
David S. Miller9360ffd2012-03-29 04:41:26 -04009592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9593 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9594 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9595 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9596 (key_id != -1 &&
9597 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9598 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9599 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009600
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009601 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009602
Johannes Berg463d0182009-07-14 00:33:35 +02009603 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9604 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009605 return;
9606
9607 nla_put_failure:
9608 genlmsg_cancel(msg, hdr);
9609 nlmsg_free(msg);
9610}
9611
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009612void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9613 struct ieee80211_channel *channel_before,
9614 struct ieee80211_channel *channel_after)
9615{
9616 struct sk_buff *msg;
9617 void *hdr;
9618 struct nlattr *nl_freq;
9619
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009621 if (!msg)
9622 return;
9623
9624 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9625 if (!hdr) {
9626 nlmsg_free(msg);
9627 return;
9628 }
9629
9630 /*
9631 * Since we are applying the beacon hint to a wiphy we know its
9632 * wiphy_idx is valid
9633 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009634 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9635 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009636
9637 /* Before */
9638 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9639 if (!nl_freq)
9640 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009641 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009642 goto nla_put_failure;
9643 nla_nest_end(msg, nl_freq);
9644
9645 /* After */
9646 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9647 if (!nl_freq)
9648 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009649 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009650 goto nla_put_failure;
9651 nla_nest_end(msg, nl_freq);
9652
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009653 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009654
Johannes Berg463d0182009-07-14 00:33:35 +02009655 rcu_read_lock();
9656 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9657 GFP_ATOMIC);
9658 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009659
9660 return;
9661
9662nla_put_failure:
9663 genlmsg_cancel(msg, hdr);
9664 nlmsg_free(msg);
9665}
9666
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009667static void nl80211_send_remain_on_chan_event(
9668 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009669 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009670 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009671 unsigned int duration, gfp_t gfp)
9672{
9673 struct sk_buff *msg;
9674 void *hdr;
9675
9676 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9677 if (!msg)
9678 return;
9679
9680 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9681 if (!hdr) {
9682 nlmsg_free(msg);
9683 return;
9684 }
9685
David S. Miller9360ffd2012-03-29 04:41:26 -04009686 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009687 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9688 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009689 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009690 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009691 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9692 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009693 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9694 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009695
David S. Miller9360ffd2012-03-29 04:41:26 -04009696 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9697 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9698 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009699
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009700 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009701
9702 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9703 nl80211_mlme_mcgrp.id, gfp);
9704 return;
9705
9706 nla_put_failure:
9707 genlmsg_cancel(msg, hdr);
9708 nlmsg_free(msg);
9709}
9710
Johannes Berg947add32013-02-22 22:05:20 +01009711void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9712 struct ieee80211_channel *chan,
9713 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009714{
Johannes Berg947add32013-02-22 22:05:20 +01009715 struct wiphy *wiphy = wdev->wiphy;
9716 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9717
9718 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009719 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009720 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009721 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009722}
Johannes Berg947add32013-02-22 22:05:20 +01009723EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009724
Johannes Berg947add32013-02-22 22:05:20 +01009725void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9726 struct ieee80211_channel *chan,
9727 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009728{
Johannes Berg947add32013-02-22 22:05:20 +01009729 struct wiphy *wiphy = wdev->wiphy;
9730 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9731
9732 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009733 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009734 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009735}
Johannes Berg947add32013-02-22 22:05:20 +01009736EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009737
Johannes Berg947add32013-02-22 22:05:20 +01009738void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9739 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009740{
Johannes Berg947add32013-02-22 22:05:20 +01009741 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9742 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009743 struct sk_buff *msg;
9744
Johannes Berg947add32013-02-22 22:05:20 +01009745 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9746
Thomas Graf58050fc2012-06-28 03:57:45 +00009747 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009748 if (!msg)
9749 return;
9750
John W. Linville66266b32012-03-15 13:25:41 -04009751 if (nl80211_send_station(msg, 0, 0, 0,
9752 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009753 nlmsg_free(msg);
9754 return;
9755 }
9756
9757 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9758 nl80211_mlme_mcgrp.id, gfp);
9759}
Johannes Berg947add32013-02-22 22:05:20 +01009760EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009761
Johannes Berg947add32013-02-22 22:05:20 +01009762void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009763{
Johannes Berg947add32013-02-22 22:05:20 +01009764 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9765 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009766 struct sk_buff *msg;
9767 void *hdr;
9768
Johannes Berg947add32013-02-22 22:05:20 +01009769 trace_cfg80211_del_sta(dev, mac_addr);
9770
Thomas Graf58050fc2012-06-28 03:57:45 +00009771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009772 if (!msg)
9773 return;
9774
9775 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9776 if (!hdr) {
9777 nlmsg_free(msg);
9778 return;
9779 }
9780
David S. Miller9360ffd2012-03-29 04:41:26 -04009781 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9782 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9783 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009784
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009785 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009786
9787 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9788 nl80211_mlme_mcgrp.id, gfp);
9789 return;
9790
9791 nla_put_failure:
9792 genlmsg_cancel(msg, hdr);
9793 nlmsg_free(msg);
9794}
Johannes Berg947add32013-02-22 22:05:20 +01009795EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009796
Johannes Berg947add32013-02-22 22:05:20 +01009797void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9798 enum nl80211_connect_failed_reason reason,
9799 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309800{
Johannes Berg947add32013-02-22 22:05:20 +01009801 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9802 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309803 struct sk_buff *msg;
9804 void *hdr;
9805
9806 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9807 if (!msg)
9808 return;
9809
9810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9811 if (!hdr) {
9812 nlmsg_free(msg);
9813 return;
9814 }
9815
9816 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9817 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9818 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9819 goto nla_put_failure;
9820
9821 genlmsg_end(msg, hdr);
9822
9823 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9824 nl80211_mlme_mcgrp.id, gfp);
9825 return;
9826
9827 nla_put_failure:
9828 genlmsg_cancel(msg, hdr);
9829 nlmsg_free(msg);
9830}
Johannes Berg947add32013-02-22 22:05:20 +01009831EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309832
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009833static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9834 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009835{
9836 struct wireless_dev *wdev = dev->ieee80211_ptr;
9837 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9838 struct sk_buff *msg;
9839 void *hdr;
9840 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009841 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009842
Eric W. Biederman15e47302012-09-07 20:12:54 +00009843 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009844 return false;
9845
9846 msg = nlmsg_new(100, gfp);
9847 if (!msg)
9848 return true;
9849
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009850 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009851 if (!hdr) {
9852 nlmsg_free(msg);
9853 return true;
9854 }
9855
David S. Miller9360ffd2012-03-29 04:41:26 -04009856 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9857 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9858 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9859 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009860
9861 err = genlmsg_end(msg, hdr);
9862 if (err < 0) {
9863 nlmsg_free(msg);
9864 return true;
9865 }
9866
Eric W. Biederman15e47302012-09-07 20:12:54 +00009867 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009868 return true;
9869
9870 nla_put_failure:
9871 genlmsg_cancel(msg, hdr);
9872 nlmsg_free(msg);
9873 return true;
9874}
9875
Johannes Berg947add32013-02-22 22:05:20 +01009876bool cfg80211_rx_spurious_frame(struct net_device *dev,
9877 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009878{
Johannes Berg947add32013-02-22 22:05:20 +01009879 struct wireless_dev *wdev = dev->ieee80211_ptr;
9880 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009881
Johannes Berg947add32013-02-22 22:05:20 +01009882 trace_cfg80211_rx_spurious_frame(dev, addr);
9883
9884 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9885 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9886 trace_cfg80211_return_bool(false);
9887 return false;
9888 }
9889 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9890 addr, gfp);
9891 trace_cfg80211_return_bool(ret);
9892 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009893}
Johannes Berg947add32013-02-22 22:05:20 +01009894EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9895
9896bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9897 const u8 *addr, gfp_t gfp)
9898{
9899 struct wireless_dev *wdev = dev->ieee80211_ptr;
9900 bool ret;
9901
9902 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9903
9904 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9905 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9906 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9907 trace_cfg80211_return_bool(false);
9908 return false;
9909 }
9910 ret = __nl80211_unexpected_frame(dev,
9911 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9912 addr, gfp);
9913 trace_cfg80211_return_bool(ret);
9914 return ret;
9915}
9916EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009917
Johannes Berg2e161f72010-08-12 15:38:38 +02009918int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009919 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009920 int freq, int sig_dbm,
9921 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009922{
Johannes Berg71bbc992012-06-15 15:30:18 +02009923 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009924 struct sk_buff *msg;
9925 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009926
9927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9928 if (!msg)
9929 return -ENOMEM;
9930
Johannes Berg2e161f72010-08-12 15:38:38 +02009931 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009932 if (!hdr) {
9933 nlmsg_free(msg);
9934 return -ENOMEM;
9935 }
9936
David S. Miller9360ffd2012-03-29 04:41:26 -04009937 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009938 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9939 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009940 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009941 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9942 (sig_dbm &&
9943 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9944 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9945 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009946
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009947 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009948
Eric W. Biederman15e47302012-09-07 20:12:54 +00009949 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009950
9951 nla_put_failure:
9952 genlmsg_cancel(msg, hdr);
9953 nlmsg_free(msg);
9954 return -ENOBUFS;
9955}
9956
Johannes Berg947add32013-02-22 22:05:20 +01009957void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9958 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009959{
Johannes Berg947add32013-02-22 22:05:20 +01009960 struct wiphy *wiphy = wdev->wiphy;
9961 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009962 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009963 struct sk_buff *msg;
9964 void *hdr;
9965
Johannes Berg947add32013-02-22 22:05:20 +01009966 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9967
Jouni Malinen026331c2010-02-15 12:53:10 +02009968 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9969 if (!msg)
9970 return;
9971
Johannes Berg2e161f72010-08-12 15:38:38 +02009972 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009973 if (!hdr) {
9974 nlmsg_free(msg);
9975 return;
9976 }
9977
David S. Miller9360ffd2012-03-29 04:41:26 -04009978 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009979 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9980 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009981 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009982 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9983 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9984 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9985 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009986
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009987 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009988
9989 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9990 return;
9991
9992 nla_put_failure:
9993 genlmsg_cancel(msg, hdr);
9994 nlmsg_free(msg);
9995}
Johannes Berg947add32013-02-22 22:05:20 +01009996EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009997
Johannes Berg947add32013-02-22 22:05:20 +01009998void cfg80211_cqm_rssi_notify(struct net_device *dev,
9999 enum nl80211_cqm_rssi_threshold_event rssi_event,
10000 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010001{
Johannes Berg947add32013-02-22 22:05:20 +010010002 struct wireless_dev *wdev = dev->ieee80211_ptr;
10003 struct wiphy *wiphy = wdev->wiphy;
10004 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010005 struct sk_buff *msg;
10006 struct nlattr *pinfoattr;
10007 void *hdr;
10008
Johannes Berg947add32013-02-22 22:05:20 +010010009 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10010
Thomas Graf58050fc2012-06-28 03:57:45 +000010011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010012 if (!msg)
10013 return;
10014
10015 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10016 if (!hdr) {
10017 nlmsg_free(msg);
10018 return;
10019 }
10020
David S. Miller9360ffd2012-03-29 04:41:26 -040010021 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010022 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010023 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010024
10025 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10026 if (!pinfoattr)
10027 goto nla_put_failure;
10028
David S. Miller9360ffd2012-03-29 04:41:26 -040010029 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10030 rssi_event))
10031 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010032
10033 nla_nest_end(msg, pinfoattr);
10034
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010035 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010036
10037 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10038 nl80211_mlme_mcgrp.id, gfp);
10039 return;
10040
10041 nla_put_failure:
10042 genlmsg_cancel(msg, hdr);
10043 nlmsg_free(msg);
10044}
Johannes Berg947add32013-02-22 22:05:20 +010010045EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010046
Johannes Berg947add32013-02-22 22:05:20 +010010047static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10048 struct net_device *netdev, const u8 *bssid,
10049 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010050{
10051 struct sk_buff *msg;
10052 struct nlattr *rekey_attr;
10053 void *hdr;
10054
Thomas Graf58050fc2012-06-28 03:57:45 +000010055 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010056 if (!msg)
10057 return;
10058
10059 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10060 if (!hdr) {
10061 nlmsg_free(msg);
10062 return;
10063 }
10064
David S. Miller9360ffd2012-03-29 04:41:26 -040010065 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10066 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10067 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10068 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010069
10070 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10071 if (!rekey_attr)
10072 goto nla_put_failure;
10073
David S. Miller9360ffd2012-03-29 04:41:26 -040010074 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10075 NL80211_REPLAY_CTR_LEN, replay_ctr))
10076 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010077
10078 nla_nest_end(msg, rekey_attr);
10079
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010080 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010081
10082 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10083 nl80211_mlme_mcgrp.id, gfp);
10084 return;
10085
10086 nla_put_failure:
10087 genlmsg_cancel(msg, hdr);
10088 nlmsg_free(msg);
10089}
10090
Johannes Berg947add32013-02-22 22:05:20 +010010091void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10092 const u8 *replay_ctr, gfp_t gfp)
10093{
10094 struct wireless_dev *wdev = dev->ieee80211_ptr;
10095 struct wiphy *wiphy = wdev->wiphy;
10096 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10097
10098 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10099 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10100}
10101EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10102
10103static void
10104nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10105 struct net_device *netdev, int index,
10106 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010107{
10108 struct sk_buff *msg;
10109 struct nlattr *attr;
10110 void *hdr;
10111
Thomas Graf58050fc2012-06-28 03:57:45 +000010112 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010113 if (!msg)
10114 return;
10115
10116 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10117 if (!hdr) {
10118 nlmsg_free(msg);
10119 return;
10120 }
10121
David S. Miller9360ffd2012-03-29 04:41:26 -040010122 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10123 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10124 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010125
10126 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10127 if (!attr)
10128 goto nla_put_failure;
10129
David S. Miller9360ffd2012-03-29 04:41:26 -040010130 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10131 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10132 (preauth &&
10133 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10134 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010135
10136 nla_nest_end(msg, attr);
10137
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010138 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010139
10140 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10141 nl80211_mlme_mcgrp.id, gfp);
10142 return;
10143
10144 nla_put_failure:
10145 genlmsg_cancel(msg, hdr);
10146 nlmsg_free(msg);
10147}
10148
Johannes Berg947add32013-02-22 22:05:20 +010010149void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10150 const u8 *bssid, bool preauth, gfp_t gfp)
10151{
10152 struct wireless_dev *wdev = dev->ieee80211_ptr;
10153 struct wiphy *wiphy = wdev->wiphy;
10154 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10155
10156 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10157 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10158}
10159EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10160
10161static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10162 struct net_device *netdev,
10163 struct cfg80211_chan_def *chandef,
10164 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010165{
10166 struct sk_buff *msg;
10167 void *hdr;
10168
Thomas Graf58050fc2012-06-28 03:57:45 +000010169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010170 if (!msg)
10171 return;
10172
10173 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10174 if (!hdr) {
10175 nlmsg_free(msg);
10176 return;
10177 }
10178
Johannes Berg683b6d32012-11-08 21:25:48 +010010179 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10180 goto nla_put_failure;
10181
10182 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010183 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010184
10185 genlmsg_end(msg, hdr);
10186
10187 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10188 nl80211_mlme_mcgrp.id, gfp);
10189 return;
10190
10191 nla_put_failure:
10192 genlmsg_cancel(msg, hdr);
10193 nlmsg_free(msg);
10194}
10195
Johannes Berg947add32013-02-22 22:05:20 +010010196void cfg80211_ch_switch_notify(struct net_device *dev,
10197 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010198{
Johannes Berg947add32013-02-22 22:05:20 +010010199 struct wireless_dev *wdev = dev->ieee80211_ptr;
10200 struct wiphy *wiphy = wdev->wiphy;
10201 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10202
10203 trace_cfg80211_ch_switch_notify(dev, chandef);
10204
10205 wdev_lock(wdev);
10206
10207 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10208 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10209 goto out;
10210
10211 wdev->channel = chandef->chan;
10212 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10213out:
10214 wdev_unlock(wdev);
10215 return;
10216}
10217EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10218
10219void cfg80211_cqm_txe_notify(struct net_device *dev,
10220 const u8 *peer, u32 num_packets,
10221 u32 rate, u32 intvl, gfp_t gfp)
10222{
10223 struct wireless_dev *wdev = dev->ieee80211_ptr;
10224 struct wiphy *wiphy = wdev->wiphy;
10225 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010226 struct sk_buff *msg;
10227 struct nlattr *pinfoattr;
10228 void *hdr;
10229
10230 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10231 if (!msg)
10232 return;
10233
10234 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10235 if (!hdr) {
10236 nlmsg_free(msg);
10237 return;
10238 }
10239
10240 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010242 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10243 goto nla_put_failure;
10244
10245 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10246 if (!pinfoattr)
10247 goto nla_put_failure;
10248
10249 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10250 goto nla_put_failure;
10251
10252 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10253 goto nla_put_failure;
10254
10255 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10256 goto nla_put_failure;
10257
10258 nla_nest_end(msg, pinfoattr);
10259
10260 genlmsg_end(msg, hdr);
10261
10262 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10263 nl80211_mlme_mcgrp.id, gfp);
10264 return;
10265
10266 nla_put_failure:
10267 genlmsg_cancel(msg, hdr);
10268 nlmsg_free(msg);
10269}
Johannes Berg947add32013-02-22 22:05:20 +010010270EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010271
10272void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010273nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10274 struct cfg80211_chan_def *chandef,
10275 enum nl80211_radar_event event,
10276 struct net_device *netdev, gfp_t gfp)
10277{
10278 struct sk_buff *msg;
10279 void *hdr;
10280
10281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10282 if (!msg)
10283 return;
10284
10285 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10286 if (!hdr) {
10287 nlmsg_free(msg);
10288 return;
10289 }
10290
10291 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10292 goto nla_put_failure;
10293
10294 /* NOP and radar events don't need a netdev parameter */
10295 if (netdev) {
10296 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10297
10298 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10299 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10300 goto nla_put_failure;
10301 }
10302
10303 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10304 goto nla_put_failure;
10305
10306 if (nl80211_send_chandef(msg, chandef))
10307 goto nla_put_failure;
10308
10309 if (genlmsg_end(msg, hdr) < 0) {
10310 nlmsg_free(msg);
10311 return;
10312 }
10313
10314 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10315 nl80211_mlme_mcgrp.id, gfp);
10316 return;
10317
10318 nla_put_failure:
10319 genlmsg_cancel(msg, hdr);
10320 nlmsg_free(msg);
10321}
10322
Johannes Berg947add32013-02-22 22:05:20 +010010323void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10324 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010325{
Johannes Berg947add32013-02-22 22:05:20 +010010326 struct wireless_dev *wdev = dev->ieee80211_ptr;
10327 struct wiphy *wiphy = wdev->wiphy;
10328 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010329 struct sk_buff *msg;
10330 struct nlattr *pinfoattr;
10331 void *hdr;
10332
Johannes Berg947add32013-02-22 22:05:20 +010010333 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10334
Thomas Graf58050fc2012-06-28 03:57:45 +000010335 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010336 if (!msg)
10337 return;
10338
10339 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10340 if (!hdr) {
10341 nlmsg_free(msg);
10342 return;
10343 }
10344
David S. Miller9360ffd2012-03-29 04:41:26 -040010345 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010346 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010347 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10348 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010349
10350 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10351 if (!pinfoattr)
10352 goto nla_put_failure;
10353
David S. Miller9360ffd2012-03-29 04:41:26 -040010354 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10355 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010356
10357 nla_nest_end(msg, pinfoattr);
10358
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010359 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010360
10361 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10362 nl80211_mlme_mcgrp.id, gfp);
10363 return;
10364
10365 nla_put_failure:
10366 genlmsg_cancel(msg, hdr);
10367 nlmsg_free(msg);
10368}
Johannes Berg947add32013-02-22 22:05:20 +010010369EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010370
Johannes Berg7f6cf312011-11-04 11:18:15 +010010371void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10372 u64 cookie, bool acked, gfp_t gfp)
10373{
10374 struct wireless_dev *wdev = dev->ieee80211_ptr;
10375 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10376 struct sk_buff *msg;
10377 void *hdr;
10378 int err;
10379
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
10400 err = genlmsg_end(msg, hdr);
10401 if (err < 0) {
10402 nlmsg_free(msg);
10403 return;
10404 }
10405
10406 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10407 nl80211_mlme_mcgrp.id, gfp);
10408 return;
10409
10410 nla_put_failure:
10411 genlmsg_cancel(msg, hdr);
10412 nlmsg_free(msg);
10413}
10414EXPORT_SYMBOL(cfg80211_probe_status);
10415
Johannes Berg5e760232011-11-04 11:18:17 +010010416void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10417 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010418 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010419{
10420 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10421 struct sk_buff *msg;
10422 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010423 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010424
Beni Lev4ee3e062012-08-27 12:49:39 +030010425 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10426
Ben Greear37c73b52012-10-26 14:49:25 -070010427 spin_lock_bh(&rdev->beacon_registrations_lock);
10428 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10429 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10430 if (!msg) {
10431 spin_unlock_bh(&rdev->beacon_registrations_lock);
10432 return;
10433 }
Johannes Berg5e760232011-11-04 11:18:17 +010010434
Ben Greear37c73b52012-10-26 14:49:25 -070010435 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10436 if (!hdr)
10437 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010438
Ben Greear37c73b52012-10-26 14:49:25 -070010439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10440 (freq &&
10441 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10442 (sig_dbm &&
10443 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10444 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10445 goto nla_put_failure;
10446
10447 genlmsg_end(msg, hdr);
10448
10449 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010450 }
Ben Greear37c73b52012-10-26 14:49:25 -070010451 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010452 return;
10453
10454 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010455 spin_unlock_bh(&rdev->beacon_registrations_lock);
10456 if (hdr)
10457 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010458 nlmsg_free(msg);
10459}
10460EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10461
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010462#ifdef CONFIG_PM
10463void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10464 struct cfg80211_wowlan_wakeup *wakeup,
10465 gfp_t gfp)
10466{
10467 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10468 struct sk_buff *msg;
10469 void *hdr;
10470 int err, size = 200;
10471
10472 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10473
10474 if (wakeup)
10475 size += wakeup->packet_present_len;
10476
10477 msg = nlmsg_new(size, gfp);
10478 if (!msg)
10479 return;
10480
10481 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10482 if (!hdr)
10483 goto free_msg;
10484
10485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10486 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10487 goto free_msg;
10488
10489 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10490 wdev->netdev->ifindex))
10491 goto free_msg;
10492
10493 if (wakeup) {
10494 struct nlattr *reasons;
10495
10496 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10497
10498 if (wakeup->disconnect &&
10499 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10500 goto free_msg;
10501 if (wakeup->magic_pkt &&
10502 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10503 goto free_msg;
10504 if (wakeup->gtk_rekey_failure &&
10505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10506 goto free_msg;
10507 if (wakeup->eap_identity_req &&
10508 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10509 goto free_msg;
10510 if (wakeup->four_way_handshake &&
10511 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10512 goto free_msg;
10513 if (wakeup->rfkill_release &&
10514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10515 goto free_msg;
10516
10517 if (wakeup->pattern_idx >= 0 &&
10518 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10519 wakeup->pattern_idx))
10520 goto free_msg;
10521
Johannes Berg2a0e0472013-01-23 22:57:40 +010010522 if (wakeup->tcp_match)
10523 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10524
10525 if (wakeup->tcp_connlost)
10526 nla_put_flag(msg,
10527 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10528
10529 if (wakeup->tcp_nomoretokens)
10530 nla_put_flag(msg,
10531 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10532
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010533 if (wakeup->packet) {
10534 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10535 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10536
10537 if (!wakeup->packet_80211) {
10538 pkt_attr =
10539 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10540 len_attr =
10541 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10542 }
10543
10544 if (wakeup->packet_len &&
10545 nla_put_u32(msg, len_attr, wakeup->packet_len))
10546 goto free_msg;
10547
10548 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10549 wakeup->packet))
10550 goto free_msg;
10551 }
10552
10553 nla_nest_end(msg, reasons);
10554 }
10555
10556 err = genlmsg_end(msg, hdr);
10557 if (err < 0)
10558 goto free_msg;
10559
10560 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10561 nl80211_mlme_mcgrp.id, gfp);
10562 return;
10563
10564 free_msg:
10565 nlmsg_free(msg);
10566}
10567EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10568#endif
10569
Jouni Malinen3475b092012-11-16 22:49:57 +020010570void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10571 enum nl80211_tdls_operation oper,
10572 u16 reason_code, gfp_t gfp)
10573{
10574 struct wireless_dev *wdev = dev->ieee80211_ptr;
10575 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10576 struct sk_buff *msg;
10577 void *hdr;
10578 int err;
10579
10580 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10581 reason_code);
10582
10583 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10584 if (!msg)
10585 return;
10586
10587 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10588 if (!hdr) {
10589 nlmsg_free(msg);
10590 return;
10591 }
10592
10593 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10594 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10595 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10596 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10597 (reason_code > 0 &&
10598 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10599 goto nla_put_failure;
10600
10601 err = genlmsg_end(msg, hdr);
10602 if (err < 0) {
10603 nlmsg_free(msg);
10604 return;
10605 }
10606
10607 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10608 nl80211_mlme_mcgrp.id, gfp);
10609 return;
10610
10611 nla_put_failure:
10612 genlmsg_cancel(msg, hdr);
10613 nlmsg_free(msg);
10614}
10615EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10616
Jouni Malinen026331c2010-02-15 12:53:10 +020010617static int nl80211_netlink_notify(struct notifier_block * nb,
10618 unsigned long state,
10619 void *_notify)
10620{
10621 struct netlink_notify *notify = _notify;
10622 struct cfg80211_registered_device *rdev;
10623 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010624 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010625
10626 if (state != NETLINK_URELEASE)
10627 return NOTIFY_DONE;
10628
10629 rcu_read_lock();
10630
Johannes Berg5e760232011-11-04 11:18:17 +010010631 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010632 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010633 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010634
10635 spin_lock_bh(&rdev->beacon_registrations_lock);
10636 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10637 list) {
10638 if (reg->nlportid == notify->portid) {
10639 list_del(&reg->list);
10640 kfree(reg);
10641 break;
10642 }
10643 }
10644 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010645 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010646
10647 rcu_read_unlock();
10648
10649 return NOTIFY_DONE;
10650}
10651
10652static struct notifier_block nl80211_netlink_notifier = {
10653 .notifier_call = nl80211_netlink_notify,
10654};
10655
Jouni Malinen355199e2013-02-27 17:14:27 +020010656void cfg80211_ft_event(struct net_device *netdev,
10657 struct cfg80211_ft_event_params *ft_event)
10658{
10659 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10660 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10661 struct sk_buff *msg;
10662 void *hdr;
10663 int err;
10664
10665 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10666
10667 if (!ft_event->target_ap)
10668 return;
10669
10670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10671 if (!msg)
10672 return;
10673
10674 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10675 if (!hdr) {
10676 nlmsg_free(msg);
10677 return;
10678 }
10679
10680 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10681 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10682 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10683 if (ft_event->ies)
10684 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10685 if (ft_event->ric_ies)
10686 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10687 ft_event->ric_ies);
10688
10689 err = genlmsg_end(msg, hdr);
10690 if (err < 0) {
10691 nlmsg_free(msg);
10692 return;
10693 }
10694
10695 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10696 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10697}
10698EXPORT_SYMBOL(cfg80211_ft_event);
10699
Arend van Spriel5de17982013-04-18 15:49:00 +020010700void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10701{
10702 struct cfg80211_registered_device *rdev;
10703 struct sk_buff *msg;
10704 void *hdr;
10705 u32 nlportid;
10706
10707 rdev = wiphy_to_dev(wdev->wiphy);
10708 if (!rdev->crit_proto_nlportid)
10709 return;
10710
10711 nlportid = rdev->crit_proto_nlportid;
10712 rdev->crit_proto_nlportid = 0;
10713
10714 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10715 if (!msg)
10716 return;
10717
10718 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10719 if (!hdr)
10720 goto nla_put_failure;
10721
10722 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10723 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10724 goto nla_put_failure;
10725
10726 genlmsg_end(msg, hdr);
10727
10728 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10729 return;
10730
10731 nla_put_failure:
10732 if (hdr)
10733 genlmsg_cancel(msg, hdr);
10734 nlmsg_free(msg);
10735
10736}
10737EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10738
Johannes Berg55682962007-09-20 13:09:35 -040010739/* initialisation/exit functions */
10740
10741int nl80211_init(void)
10742{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010743 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010744
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010745 err = genl_register_family_with_ops(&nl80211_fam,
10746 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010747 if (err)
10748 return err;
10749
Johannes Berg55682962007-09-20 13:09:35 -040010750 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10751 if (err)
10752 goto err_out;
10753
Johannes Berg2a519312009-02-10 21:25:55 +010010754 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10755 if (err)
10756 goto err_out;
10757
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010758 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10759 if (err)
10760 goto err_out;
10761
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010762 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10763 if (err)
10764 goto err_out;
10765
Johannes Bergaff89a92009-07-01 21:26:51 +020010766#ifdef CONFIG_NL80211_TESTMODE
10767 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10768 if (err)
10769 goto err_out;
10770#endif
10771
Jouni Malinen026331c2010-02-15 12:53:10 +020010772 err = netlink_register_notifier(&nl80211_netlink_notifier);
10773 if (err)
10774 goto err_out;
10775
Johannes Berg55682962007-09-20 13:09:35 -040010776 return 0;
10777 err_out:
10778 genl_unregister_family(&nl80211_fam);
10779 return err;
10780}
10781
10782void nl80211_exit(void)
10783{
Jouni Malinen026331c2010-02-15 12:53:10 +020010784 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010785 genl_unregister_family(&nl80211_fam);
10786}