blob: f1047aea868a19cce81f36f79cadcfae5b2772b6 [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 Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Jouni Malinen5fb628e2011-08-10 23:54:35 +030026static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
30 int cipher_limit);
31
Johannes Berg4c476992010-10-04 21:36:35 +020032static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
36
Johannes Berg55682962007-09-20 13:09:35 -040037/* the netlink family */
38static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020044 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020045 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040047};
48
Johannes Berg89a54e42012-06-15 14:33:17 +020049/* returns ERR_PTR values */
50static struct wireless_dev *
51__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040052{
Johannes Berg89a54e42012-06-15 14:33:17 +020053 struct cfg80211_registered_device *rdev;
54 struct wireless_dev *result = NULL;
55 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
56 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
57 u64 wdev_id;
58 int wiphy_idx = -1;
59 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040060
Johannes Berg89a54e42012-06-15 14:33:17 +020061 assert_cfg80211_lock();
Johannes Berg55682962007-09-20 13:09:35 -040062
Johannes Berg89a54e42012-06-15 14:33:17 +020063 if (!have_ifidx && !have_wdev_id)
64 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040065
Johannes Berg89a54e42012-06-15 14:33:17 +020066 if (have_ifidx)
67 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
68 if (have_wdev_id) {
69 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
70 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040071 }
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
74 struct wireless_dev *wdev;
75
76 if (wiphy_net(&rdev->wiphy) != netns)
77 continue;
78
79 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
80 continue;
81
82 mutex_lock(&rdev->devlist_mtx);
83 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 }
94 mutex_unlock(&rdev->devlist_mtx);
95
96 if (result)
97 break;
98 }
99
100 if (result)
101 return result;
102 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400103}
104
Johannes Berga9455402012-06-15 13:32:49 +0200105static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200106__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200107{
Johannes Berg7fee4772012-06-15 14:09:58 +0200108 struct cfg80211_registered_device *rdev = NULL, *tmp;
109 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200110
111 assert_cfg80211_lock();
112
Johannes Berg878d9ec2012-06-15 14:18:32 +0200113 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200114 !attrs[NL80211_ATTR_IFINDEX] &&
115 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200116 return ERR_PTR(-EINVAL);
117
Johannes Berg878d9ec2012-06-15 14:18:32 +0200118 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200119 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200120 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200121
Johannes Berg89a54e42012-06-15 14:33:17 +0200122 if (attrs[NL80211_ATTR_WDEV]) {
123 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
124 struct wireless_dev *wdev;
125 bool found = false;
126
127 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
128 if (tmp) {
129 /* make sure wdev exists */
130 mutex_lock(&tmp->devlist_mtx);
131 list_for_each_entry(wdev, &tmp->wdev_list, list) {
132 if (wdev->identifier != (u32)wdev_id)
133 continue;
134 found = true;
135 break;
136 }
137 mutex_unlock(&tmp->devlist_mtx);
138
139 if (!found)
140 tmp = NULL;
141
142 if (rdev && tmp != rdev)
143 return ERR_PTR(-EINVAL);
144 rdev = tmp;
145 }
146 }
147
Johannes Berg878d9ec2012-06-15 14:18:32 +0200148 if (attrs[NL80211_ATTR_IFINDEX]) {
149 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200150 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200151 if (netdev) {
152 if (netdev->ieee80211_ptr)
153 tmp = wiphy_to_dev(
154 netdev->ieee80211_ptr->wiphy);
155 else
156 tmp = NULL;
157
158 dev_put(netdev);
159
160 /* not wireless device -- return error */
161 if (!tmp)
162 return ERR_PTR(-EINVAL);
163
164 /* mismatch -- return error */
165 if (rdev && tmp != rdev)
166 return ERR_PTR(-EINVAL);
167
168 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200169 }
Johannes Berga9455402012-06-15 13:32:49 +0200170 }
171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (!rdev)
173 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200174
Johannes Berg4f7eff12012-06-15 14:14:22 +0200175 if (netns != wiphy_net(&rdev->wiphy))
176 return ERR_PTR(-ENODEV);
177
178 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200179}
180
181/*
182 * This function returns a pointer to the driver
183 * that the genl_info item that is passed refers to.
184 * If successful, it returns non-NULL and also locks
185 * the driver's mutex!
186 *
187 * This means that you need to call cfg80211_unlock_rdev()
188 * before being allowed to acquire &cfg80211_mutex!
189 *
190 * This is necessary because we need to lock the global
191 * mutex to get an item off the list safely, and then
192 * we lock the rdev mutex so it doesn't go away under us.
193 *
194 * We don't want to keep cfg80211_mutex locked
195 * for all the time in order to allow requests on
196 * other interfaces to go through at the same time.
197 *
198 * The result of this can be a PTR_ERR and hence must
199 * be checked with IS_ERR() for errors.
200 */
201static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200202cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200203{
204 struct cfg80211_registered_device *rdev;
205
206 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200207 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208
209 /* if it is not an error we grab the lock on
210 * it to assure it won't be going away while
211 * we operate on it */
212 if (!IS_ERR(rdev))
213 mutex_lock(&rdev->mtx);
214
215 mutex_unlock(&cfg80211_mutex);
216
217 return rdev;
218}
219
Johannes Berg55682962007-09-20 13:09:35 -0400220/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000221static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400222 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
223 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700224 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200225 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200226 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530227 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200228 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
229 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400233
234 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
235 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
236 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Eliad Pellere007b852011-11-24 18:13:56 +0200238 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
239 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100240
Johannes Bergb9454e82009-07-08 13:29:08 +0200241 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100242 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
243 .len = WLAN_MAX_KEY_LEN },
244 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
245 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
246 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200247 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200248 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100249
250 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
251 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
252 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
254 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
255 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100256 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
258 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
259 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
260 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100262 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200263 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800265 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100266 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300267
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700268 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
269 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
270
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300271 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
272 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
273 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200274 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
275 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100276 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300277
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800278 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700279 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700280
Johannes Berg6c739412011-11-03 09:27:01 +0100281 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200282
283 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
284 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100286 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
287 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200288
289 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
290 .len = IEEE80211_MAX_SSID_LEN },
291 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
292 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200293 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300294 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300295 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300296 [NL80211_ATTR_STA_FLAGS2] = {
297 .len = sizeof(struct nl80211_sta_flag_update),
298 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300299 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300300 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
301 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200302 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
303 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
304 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200305 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100306 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100307 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
308 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100309 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
310 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200311 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200312 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
313 .len = IEEE80211_MAX_DATA_LEN },
314 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200315 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200316 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300317 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200318 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300319 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200321 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900322 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
323 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100324 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100325 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100326 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200327 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700328 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300329 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200330 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200331 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300332 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300333 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
335 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
336 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530337 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300338 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530339 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300340 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
343 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
344 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100345 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200346 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
347 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700348 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800349 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
350 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
351 .len = NL80211_HT_CAPABILITY_LEN
352 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100353 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530354 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530355 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200356 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700357 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400358};
359
Johannes Berge31b8212010-10-05 19:39:30 +0200360/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000361static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200362 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200363 [NL80211_KEY_IDX] = { .type = NLA_U8 },
364 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200365 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200366 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
367 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200368 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100369 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
370};
371
372/* policy for the key default flags */
373static const struct nla_policy
374nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
375 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
376 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200377};
378
Johannes Bergff1b6e62011-05-04 15:37:28 +0200379/* policy for WoWLAN attributes */
380static const struct nla_policy
381nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
382 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
385 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200386 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
389 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200390};
391
Johannes Berge5497d72011-07-05 16:35:40 +0200392/* policy for GTK rekey offload attributes */
393static const struct nla_policy
394nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
395 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
396 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
397 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
398};
399
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300400static const struct nla_policy
401nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200402 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300403 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700404 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300405};
406
Holger Schuriga0438972009-11-11 11:30:02 +0100407/* ifidx get helper */
408static int nl80211_get_ifidx(struct netlink_callback *cb)
409{
410 int res;
411
412 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
413 nl80211_fam.attrbuf, nl80211_fam.maxattr,
414 nl80211_policy);
415 if (res)
416 return res;
417
418 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
419 return -EINVAL;
420
421 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
422 if (!res)
423 return -EINVAL;
424 return res;
425}
426
Johannes Berg67748892010-10-04 21:14:06 +0200427static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
428 struct netlink_callback *cb,
429 struct cfg80211_registered_device **rdev,
430 struct net_device **dev)
431{
432 int ifidx = cb->args[0];
433 int err;
434
435 if (!ifidx)
436 ifidx = nl80211_get_ifidx(cb);
437 if (ifidx < 0)
438 return ifidx;
439
440 cb->args[0] = ifidx;
441
442 rtnl_lock();
443
444 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
445 if (!*dev) {
446 err = -ENODEV;
447 goto out_rtnl;
448 }
449
450 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100451 if (IS_ERR(*rdev)) {
452 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200453 goto out_rtnl;
454 }
455
456 return 0;
457 out_rtnl:
458 rtnl_unlock();
459 return err;
460}
461
462static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
463{
464 cfg80211_unlock_rdev(rdev);
465 rtnl_unlock();
466}
467
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100468/* IE validation */
469static bool is_valid_ie_attr(const struct nlattr *attr)
470{
471 const u8 *pos;
472 int len;
473
474 if (!attr)
475 return true;
476
477 pos = nla_data(attr);
478 len = nla_len(attr);
479
480 while (len) {
481 u8 elemlen;
482
483 if (len < 2)
484 return false;
485 len -= 2;
486
487 elemlen = pos[1];
488 if (elemlen > len)
489 return false;
490
491 len -= elemlen;
492 pos += 2 + elemlen;
493 }
494
495 return true;
496}
497
Johannes Berg55682962007-09-20 13:09:35 -0400498/* message building helper */
499static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
500 int flags, u8 cmd)
501{
502 /* since there is no private header just add the generic one */
503 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
504}
505
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400506static int nl80211_msg_put_channel(struct sk_buff *msg,
507 struct ieee80211_channel *chan)
508{
David S. Miller9360ffd2012-03-29 04:41:26 -0400509 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
510 chan->center_freq))
511 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400512
David S. Miller9360ffd2012-03-29 04:41:26 -0400513 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
514 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
515 goto nla_put_failure;
516 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
517 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
518 goto nla_put_failure;
519 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
520 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
521 goto nla_put_failure;
522 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
523 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
524 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400525
David S. Miller9360ffd2012-03-29 04:41:26 -0400526 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
527 DBM_TO_MBM(chan->max_power)))
528 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400529
530 return 0;
531
532 nla_put_failure:
533 return -ENOBUFS;
534}
535
Johannes Berg55682962007-09-20 13:09:35 -0400536/* netlink command implementations */
537
Johannes Bergb9454e82009-07-08 13:29:08 +0200538struct key_parse {
539 struct key_params p;
540 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200541 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200542 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100543 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200544};
545
546static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
547{
548 struct nlattr *tb[NL80211_KEY_MAX + 1];
549 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
550 nl80211_key_policy);
551 if (err)
552 return err;
553
554 k->def = !!tb[NL80211_KEY_DEFAULT];
555 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
556
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100557 if (k->def) {
558 k->def_uni = true;
559 k->def_multi = true;
560 }
561 if (k->defmgmt)
562 k->def_multi = true;
563
Johannes Bergb9454e82009-07-08 13:29:08 +0200564 if (tb[NL80211_KEY_IDX])
565 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
566
567 if (tb[NL80211_KEY_DATA]) {
568 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
569 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
570 }
571
572 if (tb[NL80211_KEY_SEQ]) {
573 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
574 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
575 }
576
577 if (tb[NL80211_KEY_CIPHER])
578 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
579
Johannes Berge31b8212010-10-05 19:39:30 +0200580 if (tb[NL80211_KEY_TYPE]) {
581 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
582 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
583 return -EINVAL;
584 }
585
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100586 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
587 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100588 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
589 tb[NL80211_KEY_DEFAULT_TYPES],
590 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100591 if (err)
592 return err;
593
594 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
595 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
596 }
597
Johannes Bergb9454e82009-07-08 13:29:08 +0200598 return 0;
599}
600
601static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
602{
603 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
604 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
605 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
606 }
607
608 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
609 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
610 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
611 }
612
613 if (info->attrs[NL80211_ATTR_KEY_IDX])
614 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
615
616 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
617 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
618
619 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
620 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
621
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100622 if (k->def) {
623 k->def_uni = true;
624 k->def_multi = true;
625 }
626 if (k->defmgmt)
627 k->def_multi = true;
628
Johannes Berge31b8212010-10-05 19:39:30 +0200629 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
630 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
631 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
632 return -EINVAL;
633 }
634
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100635 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
636 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
637 int err = nla_parse_nested(
638 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
639 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
640 nl80211_key_default_policy);
641 if (err)
642 return err;
643
644 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
645 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
646 }
647
Johannes Bergb9454e82009-07-08 13:29:08 +0200648 return 0;
649}
650
651static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
652{
653 int err;
654
655 memset(k, 0, sizeof(*k));
656 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200657 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200658
659 if (info->attrs[NL80211_ATTR_KEY])
660 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
661 else
662 err = nl80211_parse_key_old(info, k);
663
664 if (err)
665 return err;
666
667 if (k->def && k->defmgmt)
668 return -EINVAL;
669
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 if (k->defmgmt) {
671 if (k->def_uni || !k->def_multi)
672 return -EINVAL;
673 }
674
Johannes Bergb9454e82009-07-08 13:29:08 +0200675 if (k->idx != -1) {
676 if (k->defmgmt) {
677 if (k->idx < 4 || k->idx > 5)
678 return -EINVAL;
679 } else if (k->def) {
680 if (k->idx < 0 || k->idx > 3)
681 return -EINVAL;
682 } else {
683 if (k->idx < 0 || k->idx > 5)
684 return -EINVAL;
685 }
686 }
687
688 return 0;
689}
690
Johannes Bergfffd0932009-07-08 14:22:54 +0200691static struct cfg80211_cached_keys *
692nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
693 struct nlattr *keys)
694{
695 struct key_parse parse;
696 struct nlattr *key;
697 struct cfg80211_cached_keys *result;
698 int rem, err, def = 0;
699
700 result = kzalloc(sizeof(*result), GFP_KERNEL);
701 if (!result)
702 return ERR_PTR(-ENOMEM);
703
704 result->def = -1;
705 result->defmgmt = -1;
706
707 nla_for_each_nested(key, keys, rem) {
708 memset(&parse, 0, sizeof(parse));
709 parse.idx = -1;
710
711 err = nl80211_parse_key_new(key, &parse);
712 if (err)
713 goto error;
714 err = -EINVAL;
715 if (!parse.p.key)
716 goto error;
717 if (parse.idx < 0 || parse.idx > 4)
718 goto error;
719 if (parse.def) {
720 if (def)
721 goto error;
722 def = 1;
723 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100724 if (!parse.def_uni || !parse.def_multi)
725 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200726 } else if (parse.defmgmt)
727 goto error;
728 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200729 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200730 if (err)
731 goto error;
732 result->params[parse.idx].cipher = parse.p.cipher;
733 result->params[parse.idx].key_len = parse.p.key_len;
734 result->params[parse.idx].key = result->data[parse.idx];
735 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
736 }
737
738 return result;
739 error:
740 kfree(result);
741 return ERR_PTR(err);
742}
743
744static int nl80211_key_allowed(struct wireless_dev *wdev)
745{
746 ASSERT_WDEV_LOCK(wdev);
747
Johannes Bergfffd0932009-07-08 14:22:54 +0200748 switch (wdev->iftype) {
749 case NL80211_IFTYPE_AP:
750 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200751 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700752 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200753 break;
754 case NL80211_IFTYPE_ADHOC:
755 if (!wdev->current_bss)
756 return -ENOLINK;
757 break;
758 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200759 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200760 if (wdev->sme_state != CFG80211_SME_CONNECTED)
761 return -ENOLINK;
762 break;
763 default:
764 return -EINVAL;
765 }
766
767 return 0;
768}
769
Johannes Berg7527a782011-05-13 10:58:57 +0200770static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
771{
772 struct nlattr *nl_modes = nla_nest_start(msg, attr);
773 int i;
774
775 if (!nl_modes)
776 goto nla_put_failure;
777
778 i = 0;
779 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400780 if ((ifmodes & 1) && nla_put_flag(msg, i))
781 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200782 ifmodes >>= 1;
783 i++;
784 }
785
786 nla_nest_end(msg, nl_modes);
787 return 0;
788
789nla_put_failure:
790 return -ENOBUFS;
791}
792
793static int nl80211_put_iface_combinations(struct wiphy *wiphy,
794 struct sk_buff *msg)
795{
796 struct nlattr *nl_combis;
797 int i, j;
798
799 nl_combis = nla_nest_start(msg,
800 NL80211_ATTR_INTERFACE_COMBINATIONS);
801 if (!nl_combis)
802 goto nla_put_failure;
803
804 for (i = 0; i < wiphy->n_iface_combinations; i++) {
805 const struct ieee80211_iface_combination *c;
806 struct nlattr *nl_combi, *nl_limits;
807
808 c = &wiphy->iface_combinations[i];
809
810 nl_combi = nla_nest_start(msg, i + 1);
811 if (!nl_combi)
812 goto nla_put_failure;
813
814 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
815 if (!nl_limits)
816 goto nla_put_failure;
817
818 for (j = 0; j < c->n_limits; j++) {
819 struct nlattr *nl_limit;
820
821 nl_limit = nla_nest_start(msg, j + 1);
822 if (!nl_limit)
823 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400824 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
825 c->limits[j].max))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
828 c->limits[j].types))
829 goto nla_put_failure;
830 nla_nest_end(msg, nl_limit);
831 }
832
833 nla_nest_end(msg, nl_limits);
834
David S. Miller9360ffd2012-03-29 04:41:26 -0400835 if (c->beacon_int_infra_match &&
836 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
837 goto nla_put_failure;
838 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
839 c->num_different_channels) ||
840 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
841 c->max_interfaces))
842 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200843
844 nla_nest_end(msg, nl_combi);
845 }
846
847 nla_nest_end(msg, nl_combis);
848
849 return 0;
850nla_put_failure:
851 return -ENOBUFS;
852}
853
Johannes Berg55682962007-09-20 13:09:35 -0400854static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
855 struct cfg80211_registered_device *dev)
856{
857 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100858 struct nlattr *nl_bands, *nl_band;
859 struct nlattr *nl_freqs, *nl_freq;
860 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100861 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100862 enum ieee80211_band band;
863 struct ieee80211_channel *chan;
864 struct ieee80211_rate *rate;
865 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200866 const struct ieee80211_txrx_stypes *mgmt_stypes =
867 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400868
869 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
870 if (!hdr)
871 return -1;
872
David S. Miller9360ffd2012-03-29 04:41:26 -0400873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
874 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
875 nla_put_u32(msg, NL80211_ATTR_GENERATION,
876 cfg80211_rdev_list_generation) ||
877 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
878 dev->wiphy.retry_short) ||
879 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
880 dev->wiphy.retry_long) ||
881 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
882 dev->wiphy.frag_threshold) ||
883 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
884 dev->wiphy.rts_threshold) ||
885 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
886 dev->wiphy.coverage_class) ||
887 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
888 dev->wiphy.max_scan_ssids) ||
889 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
890 dev->wiphy.max_sched_scan_ssids) ||
891 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
892 dev->wiphy.max_scan_ie_len) ||
893 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
894 dev->wiphy.max_sched_scan_ie_len) ||
895 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
896 dev->wiphy.max_match_sets))
897 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200898
David S. Miller9360ffd2012-03-29 04:41:26 -0400899 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
900 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
901 goto nla_put_failure;
902 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
903 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
904 goto nla_put_failure;
905 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
906 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
907 goto nla_put_failure;
908 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
909 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
910 goto nla_put_failure;
911 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
912 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
913 goto nla_put_failure;
914 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
915 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
916 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200917
David S. Miller9360ffd2012-03-29 04:41:26 -0400918 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
919 sizeof(u32) * dev->wiphy.n_cipher_suites,
920 dev->wiphy.cipher_suites))
921 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100922
David S. Miller9360ffd2012-03-29 04:41:26 -0400923 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
924 dev->wiphy.max_num_pmkids))
925 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530926
David S. Miller9360ffd2012-03-29 04:41:26 -0400927 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
928 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
929 goto nla_put_failure;
Johannes Berg25e47c182009-04-02 20:14:06 +0200930
David S. Miller9360ffd2012-03-29 04:41:26 -0400931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
932 dev->wiphy.available_antennas_tx) ||
933 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
934 dev->wiphy.available_antennas_rx))
935 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100936
David S. Miller9360ffd2012-03-29 04:41:26 -0400937 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
938 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
939 dev->wiphy.probe_resp_offload))
940 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200941
Bruno Randolf7f531e02010-12-16 11:30:22 +0900942 if ((dev->wiphy.available_antennas_tx ||
943 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900944 u32 tx_ant = 0, rx_ant = 0;
945 int res;
946 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
947 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400948 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
949 tx_ant) ||
950 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
951 rx_ant))
952 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900953 }
954 }
955
Johannes Berg7527a782011-05-13 10:58:57 +0200956 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
957 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700958 goto nla_put_failure;
959
Johannes Bergee688b002008-01-24 19:38:39 +0100960 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
961 if (!nl_bands)
962 goto nla_put_failure;
963
964 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
965 if (!dev->wiphy.bands[band])
966 continue;
967
968 nl_band = nla_nest_start(msg, band);
969 if (!nl_band)
970 goto nla_put_failure;
971
Johannes Bergd51626d2008-10-09 12:20:13 +0200972 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
974 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
975 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
976 &dev->wiphy.bands[band]->ht_cap.mcs) ||
977 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
978 dev->wiphy.bands[band]->ht_cap.cap) ||
979 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
980 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
981 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
982 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
983 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200984
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000985 /* add VHT info */
986 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
987 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
988 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
989 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
990 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
991 dev->wiphy.bands[band]->vht_cap.cap)))
992 goto nla_put_failure;
993
Johannes Bergee688b002008-01-24 19:38:39 +0100994 /* add frequencies */
995 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
996 if (!nl_freqs)
997 goto nla_put_failure;
998
999 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1000 nl_freq = nla_nest_start(msg, i);
1001 if (!nl_freq)
1002 goto nla_put_failure;
1003
1004 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +01001005
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001006 if (nl80211_msg_put_channel(msg, chan))
1007 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001008
Johannes Bergee688b002008-01-24 19:38:39 +01001009 nla_nest_end(msg, nl_freq);
1010 }
1011
1012 nla_nest_end(msg, nl_freqs);
1013
1014 /* add bitrates */
1015 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1016 if (!nl_rates)
1017 goto nla_put_failure;
1018
1019 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1020 nl_rate = nla_nest_start(msg, i);
1021 if (!nl_rate)
1022 goto nla_put_failure;
1023
1024 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -04001025 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1026 rate->bitrate))
1027 goto nla_put_failure;
1028 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1029 nla_put_flag(msg,
1030 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1031 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001032
1033 nla_nest_end(msg, nl_rate);
1034 }
1035
1036 nla_nest_end(msg, nl_rates);
1037
1038 nla_nest_end(msg, nl_band);
1039 }
1040 nla_nest_end(msg, nl_bands);
1041
Johannes Berg8fdc6212009-03-14 09:34:01 +01001042 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1043 if (!nl_cmds)
1044 goto nla_put_failure;
1045
1046 i = 0;
1047#define CMD(op, n) \
1048 do { \
1049 if (dev->ops->op) { \
1050 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1052 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +01001053 } \
1054 } while (0)
1055
1056 CMD(add_virtual_intf, NEW_INTERFACE);
1057 CMD(change_virtual_intf, SET_INTERFACE);
1058 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +01001059 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001060 CMD(add_station, NEW_STATION);
1061 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001062 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001063 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001064 CMD(auth, AUTHENTICATE);
1065 CMD(assoc, ASSOCIATE);
1066 CMD(deauth, DEAUTHENTICATE);
1067 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001068 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001069 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001070 CMD(set_pmksa, SET_PMKSA);
1071 CMD(del_pmksa, DEL_PMKSA);
1072 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001073 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1074 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001075 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001076 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001077 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001078 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001079 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001080 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1081 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001082 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001083 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001084 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001085 i++;
1086 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1087 goto nla_put_failure;
1088 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001089 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001090 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1091 CMD(tdls_mgmt, TDLS_MGMT);
1092 CMD(tdls_oper, TDLS_OPER);
1093 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001094 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1095 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001096 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001097 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001098 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1099 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001100 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1101 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001102 }
Johannes Berg98104fde2012-06-16 00:19:54 +02001103 CMD(start_p2p_device, START_P2P_DEVICE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001104
Kalle Valo4745fc02011-11-17 19:06:10 +02001105#ifdef CONFIG_NL80211_TESTMODE
1106 CMD(testmode_cmd, TESTMODE);
1107#endif
1108
Johannes Berg8fdc6212009-03-14 09:34:01 +01001109#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001110
Johannes Berg6829c8782009-07-02 09:13:27 +02001111 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001112 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001113 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1114 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001115 }
1116
Johannes Berg6829c8782009-07-02 09:13:27 +02001117 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001118 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001119 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1120 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001121 }
1122
Johannes Berg8fdc6212009-03-14 09:34:01 +01001123 nla_nest_end(msg, nl_cmds);
1124
Johannes Berg7c4ef712011-11-18 15:33:48 +01001125 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001126 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1127 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1128 dev->wiphy.max_remain_on_channel_duration))
1129 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001130
David S. Miller9360ffd2012-03-29 04:41:26 -04001131 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1132 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1133 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001134
Johannes Berg2e161f72010-08-12 15:38:38 +02001135 if (mgmt_stypes) {
1136 u16 stypes;
1137 struct nlattr *nl_ftypes, *nl_ifs;
1138 enum nl80211_iftype ift;
1139
1140 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1141 if (!nl_ifs)
1142 goto nla_put_failure;
1143
1144 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1145 nl_ftypes = nla_nest_start(msg, ift);
1146 if (!nl_ftypes)
1147 goto nla_put_failure;
1148 i = 0;
1149 stypes = mgmt_stypes[ift].tx;
1150 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001151 if ((stypes & 1) &&
1152 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1153 (i << 4) | IEEE80211_FTYPE_MGMT))
1154 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001155 stypes >>= 1;
1156 i++;
1157 }
1158 nla_nest_end(msg, nl_ftypes);
1159 }
1160
Johannes Berg74b70a42010-08-24 12:15:53 +02001161 nla_nest_end(msg, nl_ifs);
1162
Johannes Berg2e161f72010-08-12 15:38:38 +02001163 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1164 if (!nl_ifs)
1165 goto nla_put_failure;
1166
1167 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1168 nl_ftypes = nla_nest_start(msg, ift);
1169 if (!nl_ftypes)
1170 goto nla_put_failure;
1171 i = 0;
1172 stypes = mgmt_stypes[ift].rx;
1173 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001174 if ((stypes & 1) &&
1175 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1176 (i << 4) | IEEE80211_FTYPE_MGMT))
1177 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001178 stypes >>= 1;
1179 i++;
1180 }
1181 nla_nest_end(msg, nl_ftypes);
1182 }
1183 nla_nest_end(msg, nl_ifs);
1184 }
1185
Johannes Bergdfb89c52012-06-27 09:23:48 +02001186#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001187 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1188 struct nlattr *nl_wowlan;
1189
1190 nl_wowlan = nla_nest_start(msg,
1191 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1192 if (!nl_wowlan)
1193 goto nla_put_failure;
1194
David S. Miller9360ffd2012-03-29 04:41:26 -04001195 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1196 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1197 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1198 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1199 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1200 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1201 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1202 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1203 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1204 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1205 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1206 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1207 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1208 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1209 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1210 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1211 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001212 if (dev->wiphy.wowlan.n_patterns) {
1213 struct nl80211_wowlan_pattern_support pat = {
1214 .max_patterns = dev->wiphy.wowlan.n_patterns,
1215 .min_pattern_len =
1216 dev->wiphy.wowlan.pattern_min_len,
1217 .max_pattern_len =
1218 dev->wiphy.wowlan.pattern_max_len,
1219 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001220 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1221 sizeof(pat), &pat))
1222 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001223 }
1224
1225 nla_nest_end(msg, nl_wowlan);
1226 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001227#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001228
Johannes Berg7527a782011-05-13 10:58:57 +02001229 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1230 dev->wiphy.software_iftypes))
1231 goto nla_put_failure;
1232
1233 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1234 goto nla_put_failure;
1235
David S. Miller9360ffd2012-03-29 04:41:26 -04001236 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1237 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1238 dev->wiphy.ap_sme_capa))
1239 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001240
David S. Miller9360ffd2012-03-29 04:41:26 -04001241 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1242 dev->wiphy.features))
1243 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001244
David S. Miller9360ffd2012-03-29 04:41:26 -04001245 if (dev->wiphy.ht_capa_mod_mask &&
1246 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1247 sizeof(*dev->wiphy.ht_capa_mod_mask),
1248 dev->wiphy.ht_capa_mod_mask))
1249 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001250
Johannes Berg55682962007-09-20 13:09:35 -04001251 return genlmsg_end(msg, hdr);
1252
1253 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001254 genlmsg_cancel(msg, hdr);
1255 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001256}
1257
1258static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1259{
1260 int idx = 0;
1261 int start = cb->args[0];
1262 struct cfg80211_registered_device *dev;
1263
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001264 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001265 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001266 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1267 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001268 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001269 continue;
1270 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1271 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001272 dev) < 0) {
1273 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001274 break;
Julius Volzb4637272008-07-08 14:02:19 +02001275 }
Johannes Berg55682962007-09-20 13:09:35 -04001276 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001277 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001278
1279 cb->args[0] = idx;
1280
1281 return skb->len;
1282}
1283
1284static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1285{
1286 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001287 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001288
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001290 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001291 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001292
Johannes Berg4c476992010-10-04 21:36:35 +02001293 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1294 nlmsg_free(msg);
1295 return -ENOBUFS;
1296 }
Johannes Berg55682962007-09-20 13:09:35 -04001297
Johannes Berg134e6372009-07-10 09:51:34 +00001298 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001299}
1300
Jouni Malinen31888482008-10-30 16:59:24 +02001301static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1302 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1303 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1304 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1305 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1306 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1307};
1308
1309static int parse_txq_params(struct nlattr *tb[],
1310 struct ieee80211_txq_params *txq_params)
1311{
Johannes Berga3304b02012-03-28 11:04:24 +02001312 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001313 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1314 !tb[NL80211_TXQ_ATTR_AIFS])
1315 return -EINVAL;
1316
Johannes Berga3304b02012-03-28 11:04:24 +02001317 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001318 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1319 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1320 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1321 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1322
Johannes Berga3304b02012-03-28 11:04:24 +02001323 if (txq_params->ac >= NL80211_NUM_ACS)
1324 return -EINVAL;
1325
Jouni Malinen31888482008-10-30 16:59:24 +02001326 return 0;
1327}
1328
Johannes Bergf444de02010-05-05 15:25:02 +02001329static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1330{
1331 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001332 * You can only set the channel explicitly for WDS interfaces,
1333 * all others have their channel managed via their respective
1334 * "establish a connection" command (connect, join, ...)
1335 *
1336 * For AP/GO and mesh mode, the channel can be set with the
1337 * channel userspace API, but is only stored and passed to the
1338 * low-level driver when the AP starts or the mesh is joined.
1339 * This is for backward compatibility, userspace can also give
1340 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001341 *
1342 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001343 * whatever else is going on, so they have their own special
1344 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001345 */
1346 return !wdev ||
1347 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001348 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001349 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1350 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001351}
1352
Johannes Bergcd6c6592012-05-10 21:27:18 +02001353static bool nl80211_valid_channel_type(struct genl_info *info,
1354 enum nl80211_channel_type *channel_type)
1355{
1356 enum nl80211_channel_type tmp;
1357
1358 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1359 return false;
1360
1361 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1362 if (tmp != NL80211_CHAN_NO_HT &&
1363 tmp != NL80211_CHAN_HT20 &&
1364 tmp != NL80211_CHAN_HT40PLUS &&
1365 tmp != NL80211_CHAN_HT40MINUS)
1366 return false;
1367
1368 if (channel_type)
1369 *channel_type = tmp;
1370
1371 return true;
1372}
1373
Johannes Bergf444de02010-05-05 15:25:02 +02001374static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1375 struct wireless_dev *wdev,
1376 struct genl_info *info)
1377{
Johannes Bergaa430da2012-05-16 23:50:18 +02001378 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001379 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1380 u32 freq;
1381 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001382 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1383
1384 if (wdev)
1385 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001386
1387 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1388 return -EINVAL;
1389
1390 if (!nl80211_can_set_dev_channel(wdev))
1391 return -EOPNOTSUPP;
1392
Johannes Bergcd6c6592012-05-10 21:27:18 +02001393 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1394 !nl80211_valid_channel_type(info, &channel_type))
1395 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001396
1397 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1398
1399 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001400 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001401 case NL80211_IFTYPE_AP:
1402 case NL80211_IFTYPE_P2P_GO:
1403 if (wdev->beacon_interval) {
1404 result = -EBUSY;
1405 break;
1406 }
1407 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1408 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1409 channel,
1410 channel_type)) {
1411 result = -EINVAL;
1412 break;
1413 }
1414 wdev->preset_chan = channel;
1415 wdev->preset_chantype = channel_type;
1416 result = 0;
1417 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001418 case NL80211_IFTYPE_MESH_POINT:
1419 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1420 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001421 case NL80211_IFTYPE_MONITOR:
1422 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1423 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001424 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001425 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001426 }
1427 mutex_unlock(&rdev->devlist_mtx);
1428
1429 return result;
1430}
1431
1432static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1433{
Johannes Berg4c476992010-10-04 21:36:35 +02001434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1435 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001436
Johannes Berg4c476992010-10-04 21:36:35 +02001437 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001438}
1439
Bill Jordane8347eb2010-10-01 13:54:28 -04001440static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1441{
Johannes Berg43b19952010-10-07 13:10:30 +02001442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1443 struct net_device *dev = info->user_ptr[1];
1444 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001445 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001446
1447 if (!info->attrs[NL80211_ATTR_MAC])
1448 return -EINVAL;
1449
Johannes Berg43b19952010-10-07 13:10:30 +02001450 if (netif_running(dev))
1451 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001452
Johannes Berg43b19952010-10-07 13:10:30 +02001453 if (!rdev->ops->set_wds_peer)
1454 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001455
Johannes Berg43b19952010-10-07 13:10:30 +02001456 if (wdev->iftype != NL80211_IFTYPE_WDS)
1457 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001458
1459 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001460 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001461}
1462
1463
Johannes Berg55682962007-09-20 13:09:35 -04001464static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1465{
1466 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001467 struct net_device *netdev = NULL;
1468 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001469 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001470 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001471 u32 changed;
1472 u8 retry_short = 0, retry_long = 0;
1473 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001474 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001475
Johannes Bergf444de02010-05-05 15:25:02 +02001476 /*
1477 * Try to find the wiphy and netdev. Normally this
1478 * function shouldn't need the netdev, but this is
1479 * done for backward compatibility -- previously
1480 * setting the channel was done per wiphy, but now
1481 * it is per netdev. Previous userland like hostapd
1482 * also passed a netdev to set_wiphy, so that it is
1483 * possible to let that go to the right netdev!
1484 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001485 mutex_lock(&cfg80211_mutex);
1486
Johannes Bergf444de02010-05-05 15:25:02 +02001487 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1488 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1489
1490 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1491 if (netdev && netdev->ieee80211_ptr) {
1492 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1493 mutex_lock(&rdev->mtx);
1494 } else
1495 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001496 }
1497
Johannes Bergf444de02010-05-05 15:25:02 +02001498 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001499 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1500 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001501 if (IS_ERR(rdev)) {
1502 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001503 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001504 }
1505 wdev = NULL;
1506 netdev = NULL;
1507 result = 0;
1508
1509 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001510 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001511 wdev = netdev->ieee80211_ptr;
1512 else
1513 wdev = NULL;
1514
1515 /*
1516 * end workaround code, by now the rdev is available
1517 * and locked, and wdev may or may not be NULL.
1518 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001519
1520 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001521 result = cfg80211_dev_rename(
1522 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001523
1524 mutex_unlock(&cfg80211_mutex);
1525
1526 if (result)
1527 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001528
Jouni Malinen31888482008-10-30 16:59:24 +02001529 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1530 struct ieee80211_txq_params txq_params;
1531 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1532
1533 if (!rdev->ops->set_txq_params) {
1534 result = -EOPNOTSUPP;
1535 goto bad_res;
1536 }
1537
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001538 if (!netdev) {
1539 result = -EINVAL;
1540 goto bad_res;
1541 }
1542
Johannes Berg133a3ff2011-11-03 14:50:13 +01001543 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1544 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1545 result = -EINVAL;
1546 goto bad_res;
1547 }
1548
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001549 if (!netif_running(netdev)) {
1550 result = -ENETDOWN;
1551 goto bad_res;
1552 }
1553
Jouni Malinen31888482008-10-30 16:59:24 +02001554 nla_for_each_nested(nl_txq_params,
1555 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1556 rem_txq_params) {
1557 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1558 nla_data(nl_txq_params),
1559 nla_len(nl_txq_params),
1560 txq_params_policy);
1561 result = parse_txq_params(tb, &txq_params);
1562 if (result)
1563 goto bad_res;
1564
1565 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001566 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001567 &txq_params);
1568 if (result)
1569 goto bad_res;
1570 }
1571 }
1572
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001573 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001574 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001575 if (result)
1576 goto bad_res;
1577 }
1578
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001579 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1580 enum nl80211_tx_power_setting type;
1581 int idx, mbm = 0;
1582
1583 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001584 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001585 goto bad_res;
1586 }
1587
1588 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1589 type = nla_get_u32(info->attrs[idx]);
1590
1591 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1592 (type != NL80211_TX_POWER_AUTOMATIC)) {
1593 result = -EINVAL;
1594 goto bad_res;
1595 }
1596
1597 if (type != NL80211_TX_POWER_AUTOMATIC) {
1598 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1599 mbm = nla_get_u32(info->attrs[idx]);
1600 }
1601
1602 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1603 if (result)
1604 goto bad_res;
1605 }
1606
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001607 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1608 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1609 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001610 if ((!rdev->wiphy.available_antennas_tx &&
1611 !rdev->wiphy.available_antennas_rx) ||
1612 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001613 result = -EOPNOTSUPP;
1614 goto bad_res;
1615 }
1616
1617 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1618 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1619
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001620 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001621 * available antenna masks, except for the "all" mask */
1622 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1623 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001624 result = -EINVAL;
1625 goto bad_res;
1626 }
1627
Bruno Randolf7f531e02010-12-16 11:30:22 +09001628 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1629 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001630
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001631 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1632 if (result)
1633 goto bad_res;
1634 }
1635
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001636 changed = 0;
1637
1638 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1639 retry_short = nla_get_u8(
1640 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1641 if (retry_short == 0) {
1642 result = -EINVAL;
1643 goto bad_res;
1644 }
1645 changed |= WIPHY_PARAM_RETRY_SHORT;
1646 }
1647
1648 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1649 retry_long = nla_get_u8(
1650 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1651 if (retry_long == 0) {
1652 result = -EINVAL;
1653 goto bad_res;
1654 }
1655 changed |= WIPHY_PARAM_RETRY_LONG;
1656 }
1657
1658 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1659 frag_threshold = nla_get_u32(
1660 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1661 if (frag_threshold < 256) {
1662 result = -EINVAL;
1663 goto bad_res;
1664 }
1665 if (frag_threshold != (u32) -1) {
1666 /*
1667 * Fragments (apart from the last one) are required to
1668 * have even length. Make the fragmentation code
1669 * simpler by stripping LSB should someone try to use
1670 * odd threshold value.
1671 */
1672 frag_threshold &= ~0x1;
1673 }
1674 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1675 }
1676
1677 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1678 rts_threshold = nla_get_u32(
1679 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1680 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1681 }
1682
Lukáš Turek81077e82009-12-21 22:50:47 +01001683 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1684 coverage_class = nla_get_u8(
1685 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1686 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1687 }
1688
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001689 if (changed) {
1690 u8 old_retry_short, old_retry_long;
1691 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001692 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001693
1694 if (!rdev->ops->set_wiphy_params) {
1695 result = -EOPNOTSUPP;
1696 goto bad_res;
1697 }
1698
1699 old_retry_short = rdev->wiphy.retry_short;
1700 old_retry_long = rdev->wiphy.retry_long;
1701 old_frag_threshold = rdev->wiphy.frag_threshold;
1702 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001703 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001704
1705 if (changed & WIPHY_PARAM_RETRY_SHORT)
1706 rdev->wiphy.retry_short = retry_short;
1707 if (changed & WIPHY_PARAM_RETRY_LONG)
1708 rdev->wiphy.retry_long = retry_long;
1709 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1710 rdev->wiphy.frag_threshold = frag_threshold;
1711 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1712 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001713 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1714 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001715
1716 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1717 if (result) {
1718 rdev->wiphy.retry_short = old_retry_short;
1719 rdev->wiphy.retry_long = old_retry_long;
1720 rdev->wiphy.frag_threshold = old_frag_threshold;
1721 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001722 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001723 }
1724 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001725
Johannes Berg306d6112008-12-08 12:39:04 +01001726 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001727 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001728 if (netdev)
1729 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001730 return result;
1731}
1732
Johannes Berg71bbc992012-06-15 15:30:18 +02001733static inline u64 wdev_id(struct wireless_dev *wdev)
1734{
1735 return (u64)wdev->identifier |
1736 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1737}
Johannes Berg55682962007-09-20 13:09:35 -04001738
1739static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001740 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001741 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04001742{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001743 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04001744 void *hdr;
1745
1746 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1747 if (!hdr)
1748 return -1;
1749
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001750 if (dev &&
1751 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001752 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001753 goto nla_put_failure;
1754
1755 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1756 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02001757 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001758 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001759 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1760 rdev->devlist_generation ^
1761 (cfg80211_rdev_list_generation << 2)))
1762 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001763
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02001764 if (rdev->ops->get_channel) {
1765 struct ieee80211_channel *chan;
1766 enum nl80211_channel_type channel_type;
1767
1768 chan = rdev->ops->get_channel(&rdev->wiphy, wdev,
1769 &channel_type);
1770 if (chan &&
1771 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1772 chan->center_freq) ||
1773 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1774 channel_type)))
John W. Linville59ef43e2012-04-18 14:17:13 -04001775 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001776 }
1777
Johannes Berg55682962007-09-20 13:09:35 -04001778 return genlmsg_end(msg, hdr);
1779
1780 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001781 genlmsg_cancel(msg, hdr);
1782 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001783}
1784
1785static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1786{
1787 int wp_idx = 0;
1788 int if_idx = 0;
1789 int wp_start = cb->args[0];
1790 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001791 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001792 struct wireless_dev *wdev;
1793
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001794 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001795 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1796 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001797 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001798 if (wp_idx < wp_start) {
1799 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001800 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001801 }
Johannes Berg55682962007-09-20 13:09:35 -04001802 if_idx = 0;
1803
Johannes Bergf5ea9122009-08-07 16:17:38 +02001804 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02001805 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001806 if (if_idx < if_start) {
1807 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001808 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001809 }
Johannes Berg55682962007-09-20 13:09:35 -04001810 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1811 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001812 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02001813 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001814 goto out;
1815 }
1816 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001817 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001818 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001819
1820 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001821 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001822 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001823 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001824
1825 cb->args[0] = wp_idx;
1826 cb->args[1] = if_idx;
1827
1828 return skb->len;
1829}
1830
1831static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1832{
1833 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001834 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001835 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001836
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001838 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001839 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001840
Johannes Bergd7264052009-04-19 16:23:20 +02001841 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001842 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001843 nlmsg_free(msg);
1844 return -ENOBUFS;
1845 }
Johannes Berg55682962007-09-20 13:09:35 -04001846
Johannes Berg134e6372009-07-10 09:51:34 +00001847 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001848}
1849
Michael Wu66f7ac52008-01-31 19:48:22 +01001850static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1851 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1852 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1853 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1854 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1855 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1856};
1857
1858static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1859{
1860 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1861 int flag;
1862
1863 *mntrflags = 0;
1864
1865 if (!nla)
1866 return -EINVAL;
1867
1868 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1869 nla, mntr_flags_policy))
1870 return -EINVAL;
1871
1872 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1873 if (flags[flag])
1874 *mntrflags |= (1<<flag);
1875
1876 return 0;
1877}
1878
Johannes Berg9bc383d2009-11-19 11:55:19 +01001879static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001880 struct net_device *netdev, u8 use_4addr,
1881 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001882{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001883 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001884 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001885 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001886 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001887 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001888
1889 switch (iftype) {
1890 case NL80211_IFTYPE_AP_VLAN:
1891 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1892 return 0;
1893 break;
1894 case NL80211_IFTYPE_STATION:
1895 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1896 return 0;
1897 break;
1898 default:
1899 break;
1900 }
1901
1902 return -EOPNOTSUPP;
1903}
1904
Johannes Berg55682962007-09-20 13:09:35 -04001905static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1906{
Johannes Berg4c476992010-10-04 21:36:35 +02001907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001908 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001909 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001910 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001911 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001912 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001913 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001914
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001915 memset(&params, 0, sizeof(params));
1916
Johannes Berg04a773a2009-04-19 21:24:32 +02001917 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001918
Johannes Berg723b0382008-09-16 20:22:09 +02001919 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001920 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001921 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001922 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001923 if (ntype > NL80211_IFTYPE_MAX)
1924 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001925 }
1926
Johannes Berg92ffe052008-09-16 20:39:36 +02001927 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001928 struct wireless_dev *wdev = dev->ieee80211_ptr;
1929
Johannes Berg4c476992010-10-04 21:36:35 +02001930 if (ntype != NL80211_IFTYPE_MESH_POINT)
1931 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001932 if (netif_running(dev))
1933 return -EBUSY;
1934
1935 wdev_lock(wdev);
1936 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1937 IEEE80211_MAX_MESH_ID_LEN);
1938 wdev->mesh_id_up_len =
1939 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1940 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1941 wdev->mesh_id_up_len);
1942 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001943 }
1944
Felix Fietkau8b787642009-11-10 18:53:10 +01001945 if (info->attrs[NL80211_ATTR_4ADDR]) {
1946 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1947 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001948 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001949 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001950 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001951 } else {
1952 params.use_4addr = -1;
1953 }
1954
Johannes Berg92ffe052008-09-16 20:39:36 +02001955 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001956 if (ntype != NL80211_IFTYPE_MONITOR)
1957 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001958 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1959 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001960 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001961 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001962
1963 flags = &_flags;
1964 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001965 }
Johannes Berg3b858752009-03-12 09:55:09 +01001966
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001967 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001968 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001969 else
1970 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001971
Johannes Berg9bc383d2009-11-19 11:55:19 +01001972 if (!err && params.use_4addr != -1)
1973 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1974
Johannes Berg55682962007-09-20 13:09:35 -04001975 return err;
1976}
1977
1978static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1979{
Johannes Berg4c476992010-10-04 21:36:35 +02001980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001981 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02001982 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02001983 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04001984 int err;
1985 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001986 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001987
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001988 memset(&params, 0, sizeof(params));
1989
Johannes Berg55682962007-09-20 13:09:35 -04001990 if (!info->attrs[NL80211_ATTR_IFNAME])
1991 return -EINVAL;
1992
1993 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1994 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1995 if (type > NL80211_IFTYPE_MAX)
1996 return -EINVAL;
1997 }
1998
Johannes Berg79c97e92009-07-07 03:56:12 +02001999 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002000 !(rdev->wiphy.interface_modes & (1 << type)))
2001 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002002
Johannes Berg9bc383d2009-11-19 11:55:19 +01002003 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002004 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002005 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002006 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002007 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002008 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002009
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002010 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2011 if (!msg)
2012 return -ENOMEM;
2013
Michael Wu66f7ac52008-01-31 19:48:22 +01002014 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2015 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2016 &flags);
Johannes Berg84efbb82012-06-16 00:00:26 +02002017 wdev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01002018 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002019 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002020 if (IS_ERR(wdev)) {
2021 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002022 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002023 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002024
Johannes Berg98104fde2012-06-16 00:19:54 +02002025 switch (type) {
2026 case NL80211_IFTYPE_MESH_POINT:
2027 if (!info->attrs[NL80211_ATTR_MESH_ID])
2028 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002029 wdev_lock(wdev);
2030 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2031 IEEE80211_MAX_MESH_ID_LEN);
2032 wdev->mesh_id_up_len =
2033 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2034 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2035 wdev->mesh_id_up_len);
2036 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002037 break;
2038 case NL80211_IFTYPE_P2P_DEVICE:
2039 /*
2040 * P2P Device doesn't have a netdev, so doesn't go
2041 * through the netdev notifier and must be added here
2042 */
2043 mutex_init(&wdev->mtx);
2044 INIT_LIST_HEAD(&wdev->event_list);
2045 spin_lock_init(&wdev->event_lock);
2046 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2047 spin_lock_init(&wdev->mgmt_registrations_lock);
2048
2049 mutex_lock(&rdev->devlist_mtx);
2050 wdev->identifier = ++rdev->wdev_id;
2051 list_add_rcu(&wdev->list, &rdev->wdev_list);
2052 rdev->devlist_generation++;
2053 mutex_unlock(&rdev->devlist_mtx);
2054 break;
2055 default:
2056 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002057 }
2058
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002059 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
2060 rdev, wdev) < 0) {
2061 nlmsg_free(msg);
2062 return -ENOBUFS;
2063 }
2064
2065 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002066}
2067
2068static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2069{
Johannes Berg4c476992010-10-04 21:36:35 +02002070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002071 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002072
Johannes Berg4c476992010-10-04 21:36:35 +02002073 if (!rdev->ops->del_virtual_intf)
2074 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002075
Johannes Berg84efbb82012-06-16 00:00:26 +02002076 /*
2077 * If we remove a wireless device without a netdev then clear
2078 * user_ptr[1] so that nl80211_post_doit won't dereference it
2079 * to check if it needs to do dev_put(). Otherwise it crashes
2080 * since the wdev has been freed, unlike with a netdev where
2081 * we need the dev_put() for the netdev to really be freed.
2082 */
2083 if (!wdev->netdev)
2084 info->user_ptr[1] = NULL;
2085
2086 return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002087}
2088
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002089static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2090{
2091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2092 struct net_device *dev = info->user_ptr[1];
2093 u16 noack_map;
2094
2095 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2096 return -EINVAL;
2097
2098 if (!rdev->ops->set_noack_map)
2099 return -EOPNOTSUPP;
2100
2101 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2102
2103 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
2104}
2105
Johannes Berg41ade002007-12-19 02:03:29 +01002106struct get_key_cookie {
2107 struct sk_buff *msg;
2108 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002109 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002110};
2111
2112static void get_key_callback(void *c, struct key_params *params)
2113{
Johannes Bergb9454e82009-07-08 13:29:08 +02002114 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002115 struct get_key_cookie *cookie = c;
2116
David S. Miller9360ffd2012-03-29 04:41:26 -04002117 if ((params->key &&
2118 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2119 params->key_len, params->key)) ||
2120 (params->seq &&
2121 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2122 params->seq_len, params->seq)) ||
2123 (params->cipher &&
2124 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2125 params->cipher)))
2126 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002127
Johannes Bergb9454e82009-07-08 13:29:08 +02002128 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2129 if (!key)
2130 goto nla_put_failure;
2131
David S. Miller9360ffd2012-03-29 04:41:26 -04002132 if ((params->key &&
2133 nla_put(cookie->msg, NL80211_KEY_DATA,
2134 params->key_len, params->key)) ||
2135 (params->seq &&
2136 nla_put(cookie->msg, NL80211_KEY_SEQ,
2137 params->seq_len, params->seq)) ||
2138 (params->cipher &&
2139 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2140 params->cipher)))
2141 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002142
David S. Miller9360ffd2012-03-29 04:41:26 -04002143 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2144 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002145
2146 nla_nest_end(cookie->msg, key);
2147
Johannes Berg41ade002007-12-19 02:03:29 +01002148 return;
2149 nla_put_failure:
2150 cookie->error = 1;
2151}
2152
2153static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2154{
Johannes Berg4c476992010-10-04 21:36:35 +02002155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002156 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002157 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002158 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002159 const u8 *mac_addr = NULL;
2160 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002161 struct get_key_cookie cookie = {
2162 .error = 0,
2163 };
2164 void *hdr;
2165 struct sk_buff *msg;
2166
2167 if (info->attrs[NL80211_ATTR_KEY_IDX])
2168 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2169
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002170 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002171 return -EINVAL;
2172
2173 if (info->attrs[NL80211_ATTR_MAC])
2174 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2175
Johannes Berge31b8212010-10-05 19:39:30 +02002176 pairwise = !!mac_addr;
2177 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2178 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2179 if (kt >= NUM_NL80211_KEYTYPES)
2180 return -EINVAL;
2181 if (kt != NL80211_KEYTYPE_GROUP &&
2182 kt != NL80211_KEYTYPE_PAIRWISE)
2183 return -EINVAL;
2184 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2185 }
2186
Johannes Berg4c476992010-10-04 21:36:35 +02002187 if (!rdev->ops->get_key)
2188 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002189
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002190 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002191 if (!msg)
2192 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002193
2194 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2195 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002196 if (IS_ERR(hdr))
2197 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002198
2199 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002200 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002201
David S. Miller9360ffd2012-03-29 04:41:26 -04002202 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2203 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2204 goto nla_put_failure;
2205 if (mac_addr &&
2206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2207 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002208
Johannes Berge31b8212010-10-05 19:39:30 +02002209 if (pairwise && mac_addr &&
2210 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2211 return -ENOENT;
2212
2213 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2214 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002215
2216 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002217 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002218
2219 if (cookie.error)
2220 goto nla_put_failure;
2221
2222 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002223 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002224
2225 nla_put_failure:
2226 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002227 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002228 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002229 return err;
2230}
2231
2232static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2233{
Johannes Berg4c476992010-10-04 21:36:35 +02002234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002235 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002236 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002237 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002238
Johannes Bergb9454e82009-07-08 13:29:08 +02002239 err = nl80211_parse_key(info, &key);
2240 if (err)
2241 return err;
2242
2243 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002244 return -EINVAL;
2245
Johannes Bergb9454e82009-07-08 13:29:08 +02002246 /* only support setting default key */
2247 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002248 return -EINVAL;
2249
Johannes Bergfffd0932009-07-08 14:22:54 +02002250 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002251
2252 if (key.def) {
2253 if (!rdev->ops->set_default_key) {
2254 err = -EOPNOTSUPP;
2255 goto out;
2256 }
2257
2258 err = nl80211_key_allowed(dev->ieee80211_ptr);
2259 if (err)
2260 goto out;
2261
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002262 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2263 key.def_uni, key.def_multi);
2264
2265 if (err)
2266 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002267
Johannes Berg3d23e342009-09-29 23:27:28 +02002268#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002269 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002270#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002271 } else {
2272 if (key.def_uni || !key.def_multi) {
2273 err = -EINVAL;
2274 goto out;
2275 }
2276
2277 if (!rdev->ops->set_default_mgmt_key) {
2278 err = -EOPNOTSUPP;
2279 goto out;
2280 }
2281
2282 err = nl80211_key_allowed(dev->ieee80211_ptr);
2283 if (err)
2284 goto out;
2285
2286 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2287 dev, key.idx);
2288 if (err)
2289 goto out;
2290
2291#ifdef CONFIG_CFG80211_WEXT
2292 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2293#endif
2294 }
2295
2296 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002297 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002298
Johannes Berg41ade002007-12-19 02:03:29 +01002299 return err;
2300}
2301
2302static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2303{
Johannes Berg4c476992010-10-04 21:36:35 +02002304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002305 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002306 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002307 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002308 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002309
Johannes Bergb9454e82009-07-08 13:29:08 +02002310 err = nl80211_parse_key(info, &key);
2311 if (err)
2312 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002313
Johannes Bergb9454e82009-07-08 13:29:08 +02002314 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002315 return -EINVAL;
2316
Johannes Berg41ade002007-12-19 02:03:29 +01002317 if (info->attrs[NL80211_ATTR_MAC])
2318 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2319
Johannes Berge31b8212010-10-05 19:39:30 +02002320 if (key.type == -1) {
2321 if (mac_addr)
2322 key.type = NL80211_KEYTYPE_PAIRWISE;
2323 else
2324 key.type = NL80211_KEYTYPE_GROUP;
2325 }
2326
2327 /* for now */
2328 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2329 key.type != NL80211_KEYTYPE_GROUP)
2330 return -EINVAL;
2331
Johannes Berg4c476992010-10-04 21:36:35 +02002332 if (!rdev->ops->add_key)
2333 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002334
Johannes Berge31b8212010-10-05 19:39:30 +02002335 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2336 key.type == NL80211_KEYTYPE_PAIRWISE,
2337 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002338 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002339
2340 wdev_lock(dev->ieee80211_ptr);
2341 err = nl80211_key_allowed(dev->ieee80211_ptr);
2342 if (!err)
2343 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002344 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002345 mac_addr, &key.p);
2346 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002347
Johannes Berg41ade002007-12-19 02:03:29 +01002348 return err;
2349}
2350
2351static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2352{
Johannes Berg4c476992010-10-04 21:36:35 +02002353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002354 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002355 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002356 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002357 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002358
Johannes Bergb9454e82009-07-08 13:29:08 +02002359 err = nl80211_parse_key(info, &key);
2360 if (err)
2361 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002362
2363 if (info->attrs[NL80211_ATTR_MAC])
2364 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2365
Johannes Berge31b8212010-10-05 19:39:30 +02002366 if (key.type == -1) {
2367 if (mac_addr)
2368 key.type = NL80211_KEYTYPE_PAIRWISE;
2369 else
2370 key.type = NL80211_KEYTYPE_GROUP;
2371 }
2372
2373 /* for now */
2374 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2375 key.type != NL80211_KEYTYPE_GROUP)
2376 return -EINVAL;
2377
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (!rdev->ops->del_key)
2379 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002380
Johannes Bergfffd0932009-07-08 14:22:54 +02002381 wdev_lock(dev->ieee80211_ptr);
2382 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002383
2384 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2385 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2386 err = -ENOENT;
2387
Johannes Bergfffd0932009-07-08 14:22:54 +02002388 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002389 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2390 key.type == NL80211_KEYTYPE_PAIRWISE,
2391 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002392
Johannes Berg3d23e342009-09-29 23:27:28 +02002393#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002394 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002395 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002396 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002397 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002398 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2399 }
2400#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002401 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002402
Johannes Berg41ade002007-12-19 02:03:29 +01002403 return err;
2404}
2405
Johannes Berg88600202012-02-13 15:17:18 +01002406static int nl80211_parse_beacon(struct genl_info *info,
2407 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002408{
Johannes Berg88600202012-02-13 15:17:18 +01002409 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002410
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002411 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2412 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2413 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2414 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002415 return -EINVAL;
2416
Johannes Berg88600202012-02-13 15:17:18 +01002417 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002418
Johannes Berged1b6cc2007-12-19 02:03:32 +01002419 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002420 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2421 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2422 if (!bcn->head_len)
2423 return -EINVAL;
2424 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002425 }
2426
2427 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002428 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2429 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002430 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002431 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002432 }
2433
Johannes Berg4c476992010-10-04 21:36:35 +02002434 if (!haveinfo)
2435 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002436
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002437 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002438 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2439 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002440 }
2441
2442 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002443 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002444 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002445 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002446 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2447 }
2448
2449 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002450 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002451 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002452 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002453 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2454 }
2455
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002456 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002457 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002458 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002459 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002460 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2461 }
2462
Johannes Berg88600202012-02-13 15:17:18 +01002463 return 0;
2464}
2465
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002466static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2467 struct cfg80211_ap_settings *params)
2468{
2469 struct wireless_dev *wdev;
2470 bool ret = false;
2471
2472 mutex_lock(&rdev->devlist_mtx);
2473
Johannes Berg89a54e42012-06-15 14:33:17 +02002474 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002475 if (wdev->iftype != NL80211_IFTYPE_AP &&
2476 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2477 continue;
2478
2479 if (!wdev->preset_chan)
2480 continue;
2481
2482 params->channel = wdev->preset_chan;
2483 params->channel_type = wdev->preset_chantype;
2484 ret = true;
2485 break;
2486 }
2487
2488 mutex_unlock(&rdev->devlist_mtx);
2489
2490 return ret;
2491}
2492
Johannes Berg88600202012-02-13 15:17:18 +01002493static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2494{
2495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2496 struct net_device *dev = info->user_ptr[1];
2497 struct wireless_dev *wdev = dev->ieee80211_ptr;
2498 struct cfg80211_ap_settings params;
2499 int err;
2500
2501 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2502 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2503 return -EOPNOTSUPP;
2504
2505 if (!rdev->ops->start_ap)
2506 return -EOPNOTSUPP;
2507
2508 if (wdev->beacon_interval)
2509 return -EALREADY;
2510
2511 memset(&params, 0, sizeof(params));
2512
2513 /* these are required for START_AP */
2514 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2515 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2516 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2517 return -EINVAL;
2518
2519 err = nl80211_parse_beacon(info, &params.beacon);
2520 if (err)
2521 return err;
2522
2523 params.beacon_interval =
2524 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2525 params.dtim_period =
2526 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2527
2528 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2529 if (err)
2530 return err;
2531
2532 /*
2533 * In theory, some of these attributes should be required here
2534 * but since they were not used when the command was originally
2535 * added, keep them optional for old user space programs to let
2536 * them continue to work with drivers that do not need the
2537 * additional information -- drivers must check!
2538 */
2539 if (info->attrs[NL80211_ATTR_SSID]) {
2540 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2541 params.ssid_len =
2542 nla_len(info->attrs[NL80211_ATTR_SSID]);
2543 if (params.ssid_len == 0 ||
2544 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2545 return -EINVAL;
2546 }
2547
2548 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2549 params.hidden_ssid = nla_get_u32(
2550 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2551 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2552 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2553 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2554 return -EINVAL;
2555 }
2556
2557 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2558
2559 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2560 params.auth_type = nla_get_u32(
2561 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2562 if (!nl80211_valid_auth_type(params.auth_type))
2563 return -EINVAL;
2564 } else
2565 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2566
2567 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2568 NL80211_MAX_NR_CIPHER_SUITES);
2569 if (err)
2570 return err;
2571
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302572 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2573 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2574 return -EOPNOTSUPP;
2575 params.inactivity_timeout = nla_get_u16(
2576 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2577 }
2578
Johannes Bergaa430da2012-05-16 23:50:18 +02002579 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2580 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2581
2582 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2583 !nl80211_valid_channel_type(info, &channel_type))
2584 return -EINVAL;
2585
2586 params.channel = rdev_freq_to_chan(rdev,
2587 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2588 channel_type);
2589 if (!params.channel)
2590 return -EINVAL;
2591 params.channel_type = channel_type;
2592 } else if (wdev->preset_chan) {
2593 params.channel = wdev->preset_chan;
2594 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002595 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002596 return -EINVAL;
2597
2598 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2599 params.channel_type))
2600 return -EINVAL;
2601
Michal Kaziore4e32452012-06-29 12:47:08 +02002602 mutex_lock(&rdev->devlist_mtx);
2603 err = cfg80211_can_use_chan(rdev, wdev, params.channel,
2604 CHAN_MODE_SHARED);
2605 mutex_unlock(&rdev->devlist_mtx);
2606
2607 if (err)
2608 return err;
2609
Johannes Berg88600202012-02-13 15:17:18 +01002610 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002611 if (!err) {
2612 wdev->preset_chan = params.channel;
2613 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002614 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002615 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002616 }
Johannes Berg56d18932011-05-09 18:41:15 +02002617 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002618}
2619
Johannes Berg88600202012-02-13 15:17:18 +01002620static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2621{
2622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2623 struct net_device *dev = info->user_ptr[1];
2624 struct wireless_dev *wdev = dev->ieee80211_ptr;
2625 struct cfg80211_beacon_data params;
2626 int err;
2627
2628 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2629 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2630 return -EOPNOTSUPP;
2631
2632 if (!rdev->ops->change_beacon)
2633 return -EOPNOTSUPP;
2634
2635 if (!wdev->beacon_interval)
2636 return -EINVAL;
2637
2638 err = nl80211_parse_beacon(info, &params);
2639 if (err)
2640 return err;
2641
2642 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2643}
2644
2645static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002646{
Johannes Berg4c476992010-10-04 21:36:35 +02002647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2648 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002649
Michal Kazior60771782012-06-29 12:46:56 +02002650 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002651}
2652
Johannes Berg5727ef12007-12-19 02:03:34 +01002653static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2654 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2655 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2656 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002657 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002658 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002659 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002660};
2661
Johannes Bergeccb8e82009-05-11 21:57:56 +03002662static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002663 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002664 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002665{
2666 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002667 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002668 int flag;
2669
Johannes Bergeccb8e82009-05-11 21:57:56 +03002670 /*
2671 * Try parsing the new attribute first so userspace
2672 * can specify both for older kernels.
2673 */
2674 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2675 if (nla) {
2676 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002677
Johannes Bergeccb8e82009-05-11 21:57:56 +03002678 sta_flags = nla_data(nla);
2679 params->sta_flags_mask = sta_flags->mask;
2680 params->sta_flags_set = sta_flags->set;
2681 if ((params->sta_flags_mask |
2682 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2683 return -EINVAL;
2684 return 0;
2685 }
2686
2687 /* if present, parse the old attribute */
2688
2689 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002690 if (!nla)
2691 return 0;
2692
2693 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2694 nla, sta_flags_policy))
2695 return -EINVAL;
2696
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002697 /*
2698 * Only allow certain flags for interface types so that
2699 * other attributes are silently ignored. Remember that
2700 * this is backward compatibility code with old userspace
2701 * and shouldn't be hit in other cases anyway.
2702 */
2703 switch (iftype) {
2704 case NL80211_IFTYPE_AP:
2705 case NL80211_IFTYPE_AP_VLAN:
2706 case NL80211_IFTYPE_P2P_GO:
2707 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2708 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2709 BIT(NL80211_STA_FLAG_WME) |
2710 BIT(NL80211_STA_FLAG_MFP);
2711 break;
2712 case NL80211_IFTYPE_P2P_CLIENT:
2713 case NL80211_IFTYPE_STATION:
2714 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2715 BIT(NL80211_STA_FLAG_TDLS_PEER);
2716 break;
2717 case NL80211_IFTYPE_MESH_POINT:
2718 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2719 BIT(NL80211_STA_FLAG_MFP) |
2720 BIT(NL80211_STA_FLAG_AUTHORIZED);
2721 default:
2722 return -EINVAL;
2723 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002724
Johannes Berg3383b5a2012-05-10 20:14:43 +02002725 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2726 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002727 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002728
Johannes Berg3383b5a2012-05-10 20:14:43 +02002729 /* no longer support new API additions in old API */
2730 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2731 return -EINVAL;
2732 }
2733 }
2734
Johannes Berg5727ef12007-12-19 02:03:34 +01002735 return 0;
2736}
2737
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002738static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2739 int attr)
2740{
2741 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002742 u32 bitrate;
2743 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002744
2745 rate = nla_nest_start(msg, attr);
2746 if (!rate)
2747 goto nla_put_failure;
2748
2749 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2750 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002751 /* report 16-bit bitrate only if we can */
2752 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
David S. Miller9360ffd2012-03-29 04:41:26 -04002753 if ((bitrate > 0 &&
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002754 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
2755 (bitrate_compat > 0 &&
2756 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002757 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2758 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2759 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2760 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2761 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2762 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2763 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002764
2765 nla_nest_end(msg, rate);
2766 return true;
2767
2768nla_put_failure:
2769 return false;
2770}
2771
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002772static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002773 int flags,
2774 struct cfg80211_registered_device *rdev,
2775 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002776 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002777{
2778 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002779 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002780
2781 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2782 if (!hdr)
2783 return -1;
2784
David S. Miller9360ffd2012-03-29 04:41:26 -04002785 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2786 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2787 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2788 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002789
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002790 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2791 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002792 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002793 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2794 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2795 sinfo->connected_time))
2796 goto nla_put_failure;
2797 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2798 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2799 sinfo->inactive_time))
2800 goto nla_put_failure;
2801 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2802 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2803 sinfo->rx_bytes))
2804 goto nla_put_failure;
2805 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2806 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2807 sinfo->tx_bytes))
2808 goto nla_put_failure;
2809 if ((sinfo->filled & STATION_INFO_LLID) &&
2810 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2811 goto nla_put_failure;
2812 if ((sinfo->filled & STATION_INFO_PLID) &&
2813 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2814 goto nla_put_failure;
2815 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2816 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2817 sinfo->plink_state))
2818 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002819 switch (rdev->wiphy.signal_type) {
2820 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002821 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2822 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2823 sinfo->signal))
2824 goto nla_put_failure;
2825 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2826 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2827 sinfo->signal_avg))
2828 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002829 break;
2830 default:
2831 break;
2832 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002833 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002834 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2835 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002836 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002837 }
2838 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2839 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2840 NL80211_STA_INFO_RX_BITRATE))
2841 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002842 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002843 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2844 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2845 sinfo->rx_packets))
2846 goto nla_put_failure;
2847 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2848 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2849 sinfo->tx_packets))
2850 goto nla_put_failure;
2851 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2852 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2853 sinfo->tx_retries))
2854 goto nla_put_failure;
2855 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2856 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2857 sinfo->tx_failed))
2858 goto nla_put_failure;
2859 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2860 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2861 sinfo->beacon_loss_count))
2862 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002863 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2864 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2865 if (!bss_param)
2866 goto nla_put_failure;
2867
David S. Miller9360ffd2012-03-29 04:41:26 -04002868 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2869 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2870 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2871 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2872 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2873 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2874 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2875 sinfo->bss_param.dtim_period) ||
2876 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2877 sinfo->bss_param.beacon_interval))
2878 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002879
2880 nla_nest_end(msg, bss_param);
2881 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002882 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2883 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2884 sizeof(struct nl80211_sta_flag_update),
2885 &sinfo->sta_flags))
2886 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002887 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2888 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2889 sinfo->t_offset))
2890 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002891 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002892
David S. Miller9360ffd2012-03-29 04:41:26 -04002893 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2894 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2895 sinfo->assoc_req_ies))
2896 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002897
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002898 return genlmsg_end(msg, hdr);
2899
2900 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002901 genlmsg_cancel(msg, hdr);
2902 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002903}
2904
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002905static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002906 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002907{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002908 struct station_info sinfo;
2909 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002910 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002911 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002912 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002913 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002914
Johannes Berg67748892010-10-04 21:14:06 +02002915 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2916 if (err)
2917 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002918
2919 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002920 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002921 goto out_err;
2922 }
2923
Johannes Bergbba95fe2008-07-29 13:22:51 +02002924 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002925 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002926 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2927 mac_addr, &sinfo);
2928 if (err == -ENOENT)
2929 break;
2930 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002931 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002932
2933 if (nl80211_send_station(skb,
2934 NETLINK_CB(cb->skb).pid,
2935 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002936 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002937 &sinfo) < 0)
2938 goto out;
2939
2940 sta_idx++;
2941 }
2942
2943
2944 out:
2945 cb->args[1] = sta_idx;
2946 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002947 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002948 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002949
2950 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002951}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002952
Johannes Berg5727ef12007-12-19 02:03:34 +01002953static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2954{
Johannes Berg4c476992010-10-04 21:36:35 +02002955 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2956 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002957 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002958 struct sk_buff *msg;
2959 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002960 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002961
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002962 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002963
2964 if (!info->attrs[NL80211_ATTR_MAC])
2965 return -EINVAL;
2966
2967 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2968
Johannes Berg4c476992010-10-04 21:36:35 +02002969 if (!rdev->ops->get_station)
2970 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002971
Johannes Berg79c97e92009-07-07 03:56:12 +02002972 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002973 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002974 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002975
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002977 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002978 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002979
2980 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002981 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002982 nlmsg_free(msg);
2983 return -ENOBUFS;
2984 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002985
Johannes Berg4c476992010-10-04 21:36:35 +02002986 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002987}
2988
2989/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002990 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002991 */
Johannes Berg80b99892011-11-18 16:23:01 +01002992static struct net_device *get_vlan(struct genl_info *info,
2993 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002994{
Johannes Berg463d0182009-07-14 00:33:35 +02002995 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002996 struct net_device *v;
2997 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002998
Johannes Berg80b99892011-11-18 16:23:01 +01002999 if (!vlanattr)
3000 return NULL;
3001
3002 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3003 if (!v)
3004 return ERR_PTR(-ENODEV);
3005
3006 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3007 ret = -EINVAL;
3008 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003009 }
Johannes Berg80b99892011-11-18 16:23:01 +01003010
3011 if (!netif_running(v)) {
3012 ret = -ENETDOWN;
3013 goto error;
3014 }
3015
3016 return v;
3017 error:
3018 dev_put(v);
3019 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003020}
3021
3022static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3023{
Johannes Berg4c476992010-10-04 21:36:35 +02003024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003025 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003026 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003027 struct station_parameters params;
3028 u8 *mac_addr = NULL;
3029
3030 memset(&params, 0, sizeof(params));
3031
3032 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07003033 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01003034
3035 if (info->attrs[NL80211_ATTR_STA_AID])
3036 return -EINVAL;
3037
3038 if (!info->attrs[NL80211_ATTR_MAC])
3039 return -EINVAL;
3040
3041 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3042
3043 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3044 params.supported_rates =
3045 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3046 params.supported_rates_len =
3047 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3048 }
3049
3050 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3051 params.listen_interval =
3052 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3053
Jouni Malinen36aedc92008-08-25 11:58:58 +03003054 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3055 params.ht_capa =
3056 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3057
Johannes Bergbdd90d52011-12-14 12:20:27 +01003058 if (!rdev->ops->change_station)
3059 return -EOPNOTSUPP;
3060
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003061 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003062 return -EINVAL;
3063
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003064 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3065 params.plink_action =
3066 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3067
Javier Cardona9c3990a2011-05-03 16:57:11 -07003068 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
3069 params.plink_state =
3070 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3071
Johannes Berga97f4422009-06-18 17:23:43 +02003072 switch (dev->ieee80211_ptr->iftype) {
3073 case NL80211_IFTYPE_AP:
3074 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003075 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02003076 /* disallow mesh-specific things */
3077 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003078 return -EINVAL;
3079
3080 /* TDLS can't be set, ... */
3081 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3082 return -EINVAL;
3083 /*
3084 * ... but don't bother the driver with it. This works around
3085 * a hostapd/wpa_supplicant issue -- it always includes the
3086 * TLDS_PEER flag in the mask even for AP mode.
3087 */
3088 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3089
3090 /* accept only the listed bits */
3091 if (params.sta_flags_mask &
3092 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3093 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3094 BIT(NL80211_STA_FLAG_WME) |
3095 BIT(NL80211_STA_FLAG_MFP)))
3096 return -EINVAL;
3097
3098 /* must be last in here for error handling */
3099 params.vlan = get_vlan(info, rdev);
3100 if (IS_ERR(params.vlan))
3101 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02003102 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02003103 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003104 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003105 /*
3106 * Don't allow userspace to change the TDLS_PEER flag,
3107 * but silently ignore attempts to change it since we
3108 * don't have state here to verify that it doesn't try
3109 * to change the flag.
3110 */
3111 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01003112 /* fall through */
3113 case NL80211_IFTYPE_ADHOC:
3114 /* disallow things sta doesn't support */
3115 if (params.plink_action)
3116 return -EINVAL;
3117 if (params.ht_capa)
3118 return -EINVAL;
3119 if (params.listen_interval >= 0)
3120 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003121 /* reject any changes other than AUTHORIZED */
3122 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3123 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003124 break;
3125 case NL80211_IFTYPE_MESH_POINT:
3126 /* disallow things mesh doesn't support */
3127 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003128 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003129 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003130 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003131 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003132 return -EINVAL;
3133 /*
3134 * No special handling for TDLS here -- the userspace
3135 * mesh code doesn't have this bug.
3136 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003137 if (params.sta_flags_mask &
3138 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003139 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003140 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003141 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003142 break;
3143 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003144 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003145 }
3146
Johannes Bergbdd90d52011-12-14 12:20:27 +01003147 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003148
Johannes Berg79c97e92009-07-07 03:56:12 +02003149 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003150
Johannes Berg5727ef12007-12-19 02:03:34 +01003151 if (params.vlan)
3152 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003153
Johannes Berg5727ef12007-12-19 02:03:34 +01003154 return err;
3155}
3156
Eliad Pellerc75786c2011-08-23 14:37:46 +03003157static struct nla_policy
3158nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3159 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3160 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3161};
3162
Johannes Berg5727ef12007-12-19 02:03:34 +01003163static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3164{
Johannes Berg4c476992010-10-04 21:36:35 +02003165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003166 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003167 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003168 struct station_parameters params;
3169 u8 *mac_addr = NULL;
3170
3171 memset(&params, 0, sizeof(params));
3172
3173 if (!info->attrs[NL80211_ATTR_MAC])
3174 return -EINVAL;
3175
Johannes Berg5727ef12007-12-19 02:03:34 +01003176 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3177 return -EINVAL;
3178
3179 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3180 return -EINVAL;
3181
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003182 if (!info->attrs[NL80211_ATTR_STA_AID])
3183 return -EINVAL;
3184
Johannes Berg5727ef12007-12-19 02:03:34 +01003185 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3186 params.supported_rates =
3187 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3188 params.supported_rates_len =
3189 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3190 params.listen_interval =
3191 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003192
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003193 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3194 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3195 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003196
Jouni Malinen36aedc92008-08-25 11:58:58 +03003197 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3198 params.ht_capa =
3199 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003200
Javier Cardona96b78df2011-04-07 15:08:33 -07003201 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3202 params.plink_action =
3203 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3204
Johannes Bergbdd90d52011-12-14 12:20:27 +01003205 if (!rdev->ops->add_station)
3206 return -EOPNOTSUPP;
3207
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003208 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003209 return -EINVAL;
3210
Johannes Bergbdd90d52011-12-14 12:20:27 +01003211 switch (dev->ieee80211_ptr->iftype) {
3212 case NL80211_IFTYPE_AP:
3213 case NL80211_IFTYPE_AP_VLAN:
3214 case NL80211_IFTYPE_P2P_GO:
3215 /* parse WME attributes if sta is WME capable */
3216 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3217 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3218 info->attrs[NL80211_ATTR_STA_WME]) {
3219 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3220 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003221
Johannes Bergbdd90d52011-12-14 12:20:27 +01003222 nla = info->attrs[NL80211_ATTR_STA_WME];
3223 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3224 nl80211_sta_wme_policy);
3225 if (err)
3226 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003227
Johannes Bergbdd90d52011-12-14 12:20:27 +01003228 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3229 params.uapsd_queues =
3230 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3231 if (params.uapsd_queues &
3232 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3233 return -EINVAL;
3234
3235 if (tb[NL80211_STA_WME_MAX_SP])
3236 params.max_sp =
3237 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3238
3239 if (params.max_sp &
3240 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3241 return -EINVAL;
3242
3243 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3244 }
3245 /* TDLS peers cannot be added */
3246 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003247 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003248 /* but don't bother the driver with it */
3249 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003250
Johannes Bergbdd90d52011-12-14 12:20:27 +01003251 /* must be last in here for error handling */
3252 params.vlan = get_vlan(info, rdev);
3253 if (IS_ERR(params.vlan))
3254 return PTR_ERR(params.vlan);
3255 break;
3256 case NL80211_IFTYPE_MESH_POINT:
3257 /* TDLS peers cannot be added */
3258 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003259 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003260 break;
3261 case NL80211_IFTYPE_STATION:
3262 /* Only TDLS peers can be added */
3263 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3264 return -EINVAL;
3265 /* Can only add if TDLS ... */
3266 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3267 return -EOPNOTSUPP;
3268 /* ... with external setup is supported */
3269 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3270 return -EOPNOTSUPP;
3271 break;
3272 default:
3273 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003274 }
3275
Johannes Bergbdd90d52011-12-14 12:20:27 +01003276 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003277
Johannes Berg79c97e92009-07-07 03:56:12 +02003278 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003279
Johannes Berg5727ef12007-12-19 02:03:34 +01003280 if (params.vlan)
3281 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003282 return err;
3283}
3284
3285static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3286{
Johannes Berg4c476992010-10-04 21:36:35 +02003287 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3288 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003289 u8 *mac_addr = NULL;
3290
3291 if (info->attrs[NL80211_ATTR_MAC])
3292 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3293
Johannes Berge80cf852009-05-11 14:43:13 +02003294 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003295 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003297 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3298 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003299
Johannes Berg4c476992010-10-04 21:36:35 +02003300 if (!rdev->ops->del_station)
3301 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003302
Johannes Berg4c476992010-10-04 21:36:35 +02003303 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003304}
3305
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003306static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3307 int flags, struct net_device *dev,
3308 u8 *dst, u8 *next_hop,
3309 struct mpath_info *pinfo)
3310{
3311 void *hdr;
3312 struct nlattr *pinfoattr;
3313
3314 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3315 if (!hdr)
3316 return -1;
3317
David S. Miller9360ffd2012-03-29 04:41:26 -04003318 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3319 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3320 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3321 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3322 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003323
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003324 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3325 if (!pinfoattr)
3326 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003327 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3328 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3329 pinfo->frame_qlen))
3330 goto nla_put_failure;
3331 if (((pinfo->filled & MPATH_INFO_SN) &&
3332 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3333 ((pinfo->filled & MPATH_INFO_METRIC) &&
3334 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3335 pinfo->metric)) ||
3336 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3337 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3338 pinfo->exptime)) ||
3339 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3340 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3341 pinfo->flags)) ||
3342 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3343 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3344 pinfo->discovery_timeout)) ||
3345 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3346 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3347 pinfo->discovery_retries)))
3348 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003349
3350 nla_nest_end(msg, pinfoattr);
3351
3352 return genlmsg_end(msg, hdr);
3353
3354 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003355 genlmsg_cancel(msg, hdr);
3356 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003357}
3358
3359static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003360 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003361{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003362 struct mpath_info pinfo;
3363 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003364 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003365 u8 dst[ETH_ALEN];
3366 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003367 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003368 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003369
Johannes Berg67748892010-10-04 21:14:06 +02003370 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3371 if (err)
3372 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003373
3374 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003375 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003376 goto out_err;
3377 }
3378
Jouni Malineneec60b02009-03-20 21:21:19 +02003379 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3380 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003381 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003382 }
3383
Johannes Bergbba95fe2008-07-29 13:22:51 +02003384 while (1) {
3385 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3386 dst, next_hop, &pinfo);
3387 if (err == -ENOENT)
3388 break;
3389 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003390 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003391
3392 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3393 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3394 netdev, dst, next_hop,
3395 &pinfo) < 0)
3396 goto out;
3397
3398 path_idx++;
3399 }
3400
3401
3402 out:
3403 cb->args[1] = path_idx;
3404 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003405 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003406 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003407 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003408}
3409
3410static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3411{
Johannes Berg4c476992010-10-04 21:36:35 +02003412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003413 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003414 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003415 struct mpath_info pinfo;
3416 struct sk_buff *msg;
3417 u8 *dst = NULL;
3418 u8 next_hop[ETH_ALEN];
3419
3420 memset(&pinfo, 0, sizeof(pinfo));
3421
3422 if (!info->attrs[NL80211_ATTR_MAC])
3423 return -EINVAL;
3424
3425 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3426
Johannes Berg4c476992010-10-04 21:36:35 +02003427 if (!rdev->ops->get_mpath)
3428 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003429
Johannes Berg4c476992010-10-04 21:36:35 +02003430 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3431 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003432
Johannes Berg79c97e92009-07-07 03:56:12 +02003433 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003434 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003435 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003436
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003438 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003439 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003440
3441 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003442 dev, dst, next_hop, &pinfo) < 0) {
3443 nlmsg_free(msg);
3444 return -ENOBUFS;
3445 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003446
Johannes Berg4c476992010-10-04 21:36:35 +02003447 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003448}
3449
3450static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3451{
Johannes Berg4c476992010-10-04 21:36:35 +02003452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3453 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003454 u8 *dst = NULL;
3455 u8 *next_hop = NULL;
3456
3457 if (!info->attrs[NL80211_ATTR_MAC])
3458 return -EINVAL;
3459
3460 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3461 return -EINVAL;
3462
3463 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3464 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3465
Johannes Berg4c476992010-10-04 21:36:35 +02003466 if (!rdev->ops->change_mpath)
3467 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003468
Johannes Berg4c476992010-10-04 21:36:35 +02003469 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3470 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003471
Johannes Berg4c476992010-10-04 21:36:35 +02003472 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003473}
Johannes Berg4c476992010-10-04 21:36:35 +02003474
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003475static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3476{
Johannes Berg4c476992010-10-04 21:36:35 +02003477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3478 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003479 u8 *dst = NULL;
3480 u8 *next_hop = NULL;
3481
3482 if (!info->attrs[NL80211_ATTR_MAC])
3483 return -EINVAL;
3484
3485 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3486 return -EINVAL;
3487
3488 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3489 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3490
Johannes Berg4c476992010-10-04 21:36:35 +02003491 if (!rdev->ops->add_mpath)
3492 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003493
Johannes Berg4c476992010-10-04 21:36:35 +02003494 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3495 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003496
Johannes Berg4c476992010-10-04 21:36:35 +02003497 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003498}
3499
3500static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3501{
Johannes Berg4c476992010-10-04 21:36:35 +02003502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3503 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504 u8 *dst = NULL;
3505
3506 if (info->attrs[NL80211_ATTR_MAC])
3507 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3508
Johannes Berg4c476992010-10-04 21:36:35 +02003509 if (!rdev->ops->del_mpath)
3510 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003511
Johannes Berg4c476992010-10-04 21:36:35 +02003512 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003513}
3514
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003515static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3516{
Johannes Berg4c476992010-10-04 21:36:35 +02003517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3518 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003519 struct bss_parameters params;
3520
3521 memset(&params, 0, sizeof(params));
3522 /* default to not changing parameters */
3523 params.use_cts_prot = -1;
3524 params.use_short_preamble = -1;
3525 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003526 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003527 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003528
3529 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3530 params.use_cts_prot =
3531 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3532 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3533 params.use_short_preamble =
3534 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3535 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3536 params.use_short_slot_time =
3537 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003538 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3539 params.basic_rates =
3540 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3541 params.basic_rates_len =
3542 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3543 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003544 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3545 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003546 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3547 params.ht_opmode =
3548 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003549
Johannes Berg4c476992010-10-04 21:36:35 +02003550 if (!rdev->ops->change_bss)
3551 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003552
Johannes Berg074ac8d2010-09-16 14:58:22 +02003553 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003554 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3555 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003556
Johannes Berg4c476992010-10-04 21:36:35 +02003557 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003558}
3559
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003560static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003561 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3562 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3563 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3564 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3565 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3566 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3567};
3568
3569static int parse_reg_rule(struct nlattr *tb[],
3570 struct ieee80211_reg_rule *reg_rule)
3571{
3572 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3573 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3574
3575 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3576 return -EINVAL;
3577 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3578 return -EINVAL;
3579 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3580 return -EINVAL;
3581 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3582 return -EINVAL;
3583 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3584 return -EINVAL;
3585
3586 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3587
3588 freq_range->start_freq_khz =
3589 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3590 freq_range->end_freq_khz =
3591 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3592 freq_range->max_bandwidth_khz =
3593 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3594
3595 power_rule->max_eirp =
3596 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3597
3598 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3599 power_rule->max_antenna_gain =
3600 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3601
3602 return 0;
3603}
3604
3605static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3606{
3607 int r;
3608 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003609 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003610
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003611 /*
3612 * You should only get this when cfg80211 hasn't yet initialized
3613 * completely when built-in to the kernel right between the time
3614 * window between nl80211_init() and regulatory_init(), if that is
3615 * even possible.
3616 */
3617 mutex_lock(&cfg80211_mutex);
3618 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003619 mutex_unlock(&cfg80211_mutex);
3620 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003621 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003622 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003623
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003624 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3625 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003626
3627 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3628
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003629 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
3630 user_reg_hint_type =
3631 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
3632 else
3633 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
3634
3635 switch (user_reg_hint_type) {
3636 case NL80211_USER_REG_HINT_USER:
3637 case NL80211_USER_REG_HINT_CELL_BASE:
3638 break;
3639 default:
3640 return -EINVAL;
3641 }
3642
3643 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003644
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003645 return r;
3646}
3647
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003648static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003649 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003650{
Johannes Berg4c476992010-10-04 21:36:35 +02003651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003652 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003653 struct wireless_dev *wdev = dev->ieee80211_ptr;
3654 struct mesh_config cur_params;
3655 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003656 void *hdr;
3657 struct nlattr *pinfoattr;
3658 struct sk_buff *msg;
3659
Johannes Berg29cbe682010-12-03 09:20:44 +01003660 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3661 return -EOPNOTSUPP;
3662
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003663 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003664 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003665
Johannes Berg29cbe682010-12-03 09:20:44 +01003666 wdev_lock(wdev);
3667 /* If not connected, get default parameters */
3668 if (!wdev->mesh_id_len)
3669 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3670 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003671 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003672 &cur_params);
3673 wdev_unlock(wdev);
3674
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003675 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003676 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003677
3678 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003680 if (!msg)
3681 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003682 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003683 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003684 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003685 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003686 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003687 if (!pinfoattr)
3688 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003689 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3690 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3691 cur_params.dot11MeshRetryTimeout) ||
3692 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3693 cur_params.dot11MeshConfirmTimeout) ||
3694 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3695 cur_params.dot11MeshHoldingTimeout) ||
3696 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3697 cur_params.dot11MeshMaxPeerLinks) ||
3698 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3699 cur_params.dot11MeshMaxRetries) ||
3700 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3701 cur_params.dot11MeshTTL) ||
3702 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3703 cur_params.element_ttl) ||
3704 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3705 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003706 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3707 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003708 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3709 cur_params.dot11MeshHWMPmaxPREQretries) ||
3710 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3711 cur_params.path_refresh_time) ||
3712 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3713 cur_params.min_discovery_timeout) ||
3714 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3715 cur_params.dot11MeshHWMPactivePathTimeout) ||
3716 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3717 cur_params.dot11MeshHWMPpreqMinInterval) ||
3718 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3719 cur_params.dot11MeshHWMPperrMinInterval) ||
3720 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3721 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3722 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3723 cur_params.dot11MeshHWMPRootMode) ||
3724 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3725 cur_params.dot11MeshHWMPRannInterval) ||
3726 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3727 cur_params.dot11MeshGateAnnouncementProtocol) ||
3728 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3729 cur_params.dot11MeshForwarding) ||
3730 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003731 cur_params.rssi_threshold) ||
3732 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003733 cur_params.ht_opmode) ||
3734 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3735 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3736 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003737 cur_params.dot11MeshHWMProotInterval) ||
3738 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3739 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003740 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003741 nla_nest_end(msg, pinfoattr);
3742 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003743 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003744
Johannes Berg3b858752009-03-12 09:55:09 +01003745 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003746 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003747 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003748 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003749 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003750}
3751
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003752static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003753 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3754 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3755 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3756 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3757 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3758 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003759 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003760 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003761 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003762 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3763 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3764 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3765 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3766 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003767 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003768 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003769 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003770 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003771 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003772 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003773 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3774 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003775 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3776 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003777 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003778};
3779
Javier Cardonac80d5452010-12-16 17:37:49 -08003780static const struct nla_policy
3781 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003782 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003783 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3784 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003785 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003786 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003787 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003788 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003789};
3790
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003791static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003792 struct mesh_config *cfg,
3793 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003794{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003795 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003796 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003797
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003798#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3799do {\
3800 if (table[attr_num]) {\
3801 cfg->param = nla_fn(table[attr_num]); \
3802 mask |= (1 << (attr_num - 1)); \
3803 } \
3804} while (0);\
3805
3806
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003807 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003808 return -EINVAL;
3809 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003810 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003811 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003812 return -EINVAL;
3813
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003814 /* This makes sure that there aren't more than 32 mesh config
3815 * parameters (otherwise our bitfield scheme would not work.) */
3816 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3817
3818 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003819 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003820 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3821 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003822 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003823 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3824 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003825 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003826 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3827 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003828 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003829 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3830 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003832 mask, NL80211_MESHCONF_MAX_RETRIES,
3833 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003835 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003836 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003837 mask, NL80211_MESHCONF_ELEMENT_TTL,
3838 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003840 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3841 nla_get_u8);
3842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3843 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3844 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003845 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003846 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3847 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003848 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003849 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3850 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003851 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003852 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3853 nla_get_u16);
3854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3855 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3856 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003858 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3859 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003860 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003861 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3862 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003863 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003864 dot11MeshHWMPnetDiameterTraversalTime, mask,
3865 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3866 nla_get_u16);
3867 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3868 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3869 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3870 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3871 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003872 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003873 dot11MeshGateAnnouncementProtocol, mask,
3874 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3875 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003877 mask, NL80211_MESHCONF_FORWARDING,
3878 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003879 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003880 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3881 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003882 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003883 mask, NL80211_MESHCONF_HT_OPMODE,
3884 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003885 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3886 mask,
3887 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3888 nla_get_u32);
3889 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3890 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3891 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3893 dot11MeshHWMPconfirmationInterval, mask,
3894 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3895 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003896 if (mask_out)
3897 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003898
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003899 return 0;
3900
3901#undef FILL_IN_MESH_PARAM_IF_SET
3902}
3903
Javier Cardonac80d5452010-12-16 17:37:49 -08003904static int nl80211_parse_mesh_setup(struct genl_info *info,
3905 struct mesh_setup *setup)
3906{
3907 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3908
3909 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3910 return -EINVAL;
3911 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3912 info->attrs[NL80211_ATTR_MESH_SETUP],
3913 nl80211_mesh_setup_params_policy))
3914 return -EINVAL;
3915
Javier Cardonad299a1f2012-03-31 11:31:33 -07003916 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3917 setup->sync_method =
3918 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3919 IEEE80211_SYNC_METHOD_VENDOR :
3920 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3921
Javier Cardonac80d5452010-12-16 17:37:49 -08003922 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3923 setup->path_sel_proto =
3924 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3925 IEEE80211_PATH_PROTOCOL_VENDOR :
3926 IEEE80211_PATH_PROTOCOL_HWMP;
3927
3928 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3929 setup->path_metric =
3930 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3931 IEEE80211_PATH_METRIC_VENDOR :
3932 IEEE80211_PATH_METRIC_AIRTIME;
3933
Javier Cardona581a8b02011-04-07 15:08:27 -07003934
3935 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003936 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003937 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003938 if (!is_valid_ie_attr(ieattr))
3939 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003940 setup->ie = nla_data(ieattr);
3941 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003942 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003943 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3944 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003945
3946 return 0;
3947}
3948
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003949static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003950 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003951{
3952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3953 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003954 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003955 struct mesh_config cfg;
3956 u32 mask;
3957 int err;
3958
Johannes Berg29cbe682010-12-03 09:20:44 +01003959 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3960 return -EOPNOTSUPP;
3961
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003962 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003963 return -EOPNOTSUPP;
3964
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003965 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003966 if (err)
3967 return err;
3968
Johannes Berg29cbe682010-12-03 09:20:44 +01003969 wdev_lock(wdev);
3970 if (!wdev->mesh_id_len)
3971 err = -ENOLINK;
3972
3973 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003974 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003975 mask, &cfg);
3976
3977 wdev_unlock(wdev);
3978
3979 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003980}
3981
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003982static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3983{
3984 struct sk_buff *msg;
3985 void *hdr = NULL;
3986 struct nlattr *nl_reg_rules;
3987 unsigned int i;
3988 int err = -EINVAL;
3989
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003990 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003991
3992 if (!cfg80211_regdomain)
3993 goto out;
3994
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003996 if (!msg) {
3997 err = -ENOBUFS;
3998 goto out;
3999 }
4000
4001 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4002 NL80211_CMD_GET_REG);
4003 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004004 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004005
David S. Miller9360ffd2012-03-29 04:41:26 -04004006 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
4007 cfg80211_regdomain->alpha2) ||
4008 (cfg80211_regdomain->dfs_region &&
4009 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
4010 cfg80211_regdomain->dfs_region)))
4011 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004012
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004013 if (reg_last_request_cell_base() &&
4014 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4015 NL80211_USER_REG_HINT_CELL_BASE))
4016 goto nla_put_failure;
4017
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004018 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4019 if (!nl_reg_rules)
4020 goto nla_put_failure;
4021
4022 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
4023 struct nlattr *nl_reg_rule;
4024 const struct ieee80211_reg_rule *reg_rule;
4025 const struct ieee80211_freq_range *freq_range;
4026 const struct ieee80211_power_rule *power_rule;
4027
4028 reg_rule = &cfg80211_regdomain->reg_rules[i];
4029 freq_range = &reg_rule->freq_range;
4030 power_rule = &reg_rule->power_rule;
4031
4032 nl_reg_rule = nla_nest_start(msg, i);
4033 if (!nl_reg_rule)
4034 goto nla_put_failure;
4035
David S. Miller9360ffd2012-03-29 04:41:26 -04004036 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4037 reg_rule->flags) ||
4038 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4039 freq_range->start_freq_khz) ||
4040 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4041 freq_range->end_freq_khz) ||
4042 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4043 freq_range->max_bandwidth_khz) ||
4044 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4045 power_rule->max_antenna_gain) ||
4046 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4047 power_rule->max_eirp))
4048 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004049
4050 nla_nest_end(msg, nl_reg_rule);
4051 }
4052
4053 nla_nest_end(msg, nl_reg_rules);
4054
4055 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004056 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004057 goto out;
4058
4059nla_put_failure:
4060 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004061put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004062 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004063 err = -EMSGSIZE;
4064out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004065 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004066 return err;
4067}
4068
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004069static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4070{
4071 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4072 struct nlattr *nl_reg_rule;
4073 char *alpha2 = NULL;
4074 int rem_reg_rules = 0, r = 0;
4075 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004076 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004077 struct ieee80211_regdomain *rd = NULL;
4078
4079 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4080 return -EINVAL;
4081
4082 if (!info->attrs[NL80211_ATTR_REG_RULES])
4083 return -EINVAL;
4084
4085 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4086
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004087 if (info->attrs[NL80211_ATTR_DFS_REGION])
4088 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4089
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004090 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4091 rem_reg_rules) {
4092 num_rules++;
4093 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004094 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004095 }
4096
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004097 mutex_lock(&cfg80211_mutex);
4098
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004099 if (!reg_is_valid_request(alpha2)) {
4100 r = -EINVAL;
4101 goto bad_reg;
4102 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004103
4104 size_of_regd = sizeof(struct ieee80211_regdomain) +
4105 (num_rules * sizeof(struct ieee80211_reg_rule));
4106
4107 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004108 if (!rd) {
4109 r = -ENOMEM;
4110 goto bad_reg;
4111 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004112
4113 rd->n_reg_rules = num_rules;
4114 rd->alpha2[0] = alpha2[0];
4115 rd->alpha2[1] = alpha2[1];
4116
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004117 /*
4118 * Disable DFS master mode if the DFS region was
4119 * not supported or known on this kernel.
4120 */
4121 if (reg_supported_dfs_region(dfs_region))
4122 rd->dfs_region = dfs_region;
4123
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004124 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4125 rem_reg_rules) {
4126 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4127 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4128 reg_rule_policy);
4129 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4130 if (r)
4131 goto bad_reg;
4132
4133 rule_idx++;
4134
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004135 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4136 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004137 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004138 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004139 }
4140
4141 BUG_ON(rule_idx != num_rules);
4142
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004143 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004144
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004145 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004146
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004147 return r;
4148
Johannes Bergd2372b32008-10-24 20:32:20 +02004149 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004150 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004151 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004152 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004153}
4154
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004155static int validate_scan_freqs(struct nlattr *freqs)
4156{
4157 struct nlattr *attr1, *attr2;
4158 int n_channels = 0, tmp1, tmp2;
4159
4160 nla_for_each_nested(attr1, freqs, tmp1) {
4161 n_channels++;
4162 /*
4163 * Some hardware has a limited channel list for
4164 * scanning, and it is pretty much nonsensical
4165 * to scan for a channel twice, so disallow that
4166 * and don't require drivers to check that the
4167 * channel list they get isn't longer than what
4168 * they can scan, as long as they can scan all
4169 * the channels they registered at once.
4170 */
4171 nla_for_each_nested(attr2, freqs, tmp2)
4172 if (attr1 != attr2 &&
4173 nla_get_u32(attr1) == nla_get_u32(attr2))
4174 return 0;
4175 }
4176
4177 return n_channels;
4178}
4179
Johannes Berg2a519312009-02-10 21:25:55 +01004180static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4181{
Johannes Berg4c476992010-10-04 21:36:35 +02004182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02004183 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004184 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004185 struct nlattr *attr;
4186 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004187 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004188 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004189
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004190 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4191 return -EINVAL;
4192
Johannes Berg79c97e92009-07-07 03:56:12 +02004193 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004194
Johannes Berg4c476992010-10-04 21:36:35 +02004195 if (!rdev->ops->scan)
4196 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004197
Johannes Berg4c476992010-10-04 21:36:35 +02004198 if (rdev->scan_req)
4199 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004200
4201 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004202 n_channels = validate_scan_freqs(
4203 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004204 if (!n_channels)
4205 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004206 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004207 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004208 n_channels = 0;
4209
Johannes Berg2a519312009-02-10 21:25:55 +01004210 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4211 if (wiphy->bands[band])
4212 n_channels += wiphy->bands[band]->n_channels;
4213 }
4214
4215 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4216 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4217 n_ssids++;
4218
Johannes Berg4c476992010-10-04 21:36:35 +02004219 if (n_ssids > wiphy->max_scan_ssids)
4220 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004221
Jouni Malinen70692ad2009-02-16 19:39:13 +02004222 if (info->attrs[NL80211_ATTR_IE])
4223 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4224 else
4225 ie_len = 0;
4226
Johannes Berg4c476992010-10-04 21:36:35 +02004227 if (ie_len > wiphy->max_scan_ie_len)
4228 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004229
Johannes Berg2a519312009-02-10 21:25:55 +01004230 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004231 + sizeof(*request->ssids) * n_ssids
4232 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004233 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004234 if (!request)
4235 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004236
Johannes Berg2a519312009-02-10 21:25:55 +01004237 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004238 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004239 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004240 if (ie_len) {
4241 if (request->ssids)
4242 request->ie = (void *)(request->ssids + n_ssids);
4243 else
4244 request->ie = (void *)(request->channels + n_channels);
4245 }
Johannes Berg2a519312009-02-10 21:25:55 +01004246
Johannes Berg584991d2009-11-02 13:32:03 +01004247 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004248 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4249 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004250 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004251 struct ieee80211_channel *chan;
4252
4253 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4254
4255 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004256 err = -EINVAL;
4257 goto out_free;
4258 }
Johannes Berg584991d2009-11-02 13:32:03 +01004259
4260 /* ignore disabled channels */
4261 if (chan->flags & IEEE80211_CHAN_DISABLED)
4262 continue;
4263
4264 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004265 i++;
4266 }
4267 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004268 enum ieee80211_band band;
4269
Johannes Berg2a519312009-02-10 21:25:55 +01004270 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004271 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4272 int j;
4273 if (!wiphy->bands[band])
4274 continue;
4275 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004276 struct ieee80211_channel *chan;
4277
4278 chan = &wiphy->bands[band]->channels[j];
4279
4280 if (chan->flags & IEEE80211_CHAN_DISABLED)
4281 continue;
4282
4283 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004284 i++;
4285 }
4286 }
4287 }
4288
Johannes Berg584991d2009-11-02 13:32:03 +01004289 if (!i) {
4290 err = -EINVAL;
4291 goto out_free;
4292 }
4293
4294 request->n_channels = i;
4295
Johannes Berg2a519312009-02-10 21:25:55 +01004296 i = 0;
4297 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4298 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004299 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004300 err = -EINVAL;
4301 goto out_free;
4302 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004303 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004304 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004305 i++;
4306 }
4307 }
4308
Jouni Malinen70692ad2009-02-16 19:39:13 +02004309 if (info->attrs[NL80211_ATTR_IE]) {
4310 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004311 memcpy((void *)request->ie,
4312 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004313 request->ie_len);
4314 }
4315
Johannes Berg34850ab2011-07-18 18:08:35 +02004316 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004317 if (wiphy->bands[i])
4318 request->rates[i] =
4319 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004320
4321 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4322 nla_for_each_nested(attr,
4323 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4324 tmp) {
4325 enum ieee80211_band band = nla_type(attr);
4326
Dan Carpenter84404622011-07-29 11:52:18 +03004327 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004328 err = -EINVAL;
4329 goto out_free;
4330 }
4331 err = ieee80211_get_ratemask(wiphy->bands[band],
4332 nla_data(attr),
4333 nla_len(attr),
4334 &request->rates[band]);
4335 if (err)
4336 goto out_free;
4337 }
4338 }
4339
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304340 request->no_cck =
4341 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4342
Johannes Bergfd014282012-06-18 19:17:03 +02004343 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004344 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004345
Johannes Berg79c97e92009-07-07 03:56:12 +02004346 rdev->scan_req = request;
Johannes Bergfd014282012-06-18 19:17:03 +02004347 err = rdev->ops->scan(&rdev->wiphy, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004348
Johannes Berg463d0182009-07-14 00:33:35 +02004349 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02004350 nl80211_send_scan_start(rdev, wdev);
4351 if (wdev->netdev)
4352 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02004353 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004354 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004355 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004356 kfree(request);
4357 }
Johannes Berg3b858752009-03-12 09:55:09 +01004358
Johannes Berg2a519312009-02-10 21:25:55 +01004359 return err;
4360}
4361
Luciano Coelho807f8a82011-05-11 17:09:35 +03004362static int nl80211_start_sched_scan(struct sk_buff *skb,
4363 struct genl_info *info)
4364{
4365 struct cfg80211_sched_scan_request *request;
4366 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4367 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004368 struct nlattr *attr;
4369 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004370 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004371 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004372 enum ieee80211_band band;
4373 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004374 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004375
4376 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4377 !rdev->ops->sched_scan_start)
4378 return -EOPNOTSUPP;
4379
4380 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4381 return -EINVAL;
4382
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004383 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4384 return -EINVAL;
4385
4386 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4387 if (interval == 0)
4388 return -EINVAL;
4389
Luciano Coelho807f8a82011-05-11 17:09:35 +03004390 wiphy = &rdev->wiphy;
4391
4392 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4393 n_channels = validate_scan_freqs(
4394 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4395 if (!n_channels)
4396 return -EINVAL;
4397 } else {
4398 n_channels = 0;
4399
4400 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4401 if (wiphy->bands[band])
4402 n_channels += wiphy->bands[band]->n_channels;
4403 }
4404
4405 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4406 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4407 tmp)
4408 n_ssids++;
4409
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004410 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004411 return -EINVAL;
4412
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004413 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4414 nla_for_each_nested(attr,
4415 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4416 tmp)
4417 n_match_sets++;
4418
4419 if (n_match_sets > wiphy->max_match_sets)
4420 return -EINVAL;
4421
Luciano Coelho807f8a82011-05-11 17:09:35 +03004422 if (info->attrs[NL80211_ATTR_IE])
4423 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4424 else
4425 ie_len = 0;
4426
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004427 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004428 return -EINVAL;
4429
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004430 mutex_lock(&rdev->sched_scan_mtx);
4431
4432 if (rdev->sched_scan_req) {
4433 err = -EINPROGRESS;
4434 goto out;
4435 }
4436
Luciano Coelho807f8a82011-05-11 17:09:35 +03004437 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004438 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004439 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004440 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004441 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004442 if (!request) {
4443 err = -ENOMEM;
4444 goto out;
4445 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004446
4447 if (n_ssids)
4448 request->ssids = (void *)&request->channels[n_channels];
4449 request->n_ssids = n_ssids;
4450 if (ie_len) {
4451 if (request->ssids)
4452 request->ie = (void *)(request->ssids + n_ssids);
4453 else
4454 request->ie = (void *)(request->channels + n_channels);
4455 }
4456
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004457 if (n_match_sets) {
4458 if (request->ie)
4459 request->match_sets = (void *)(request->ie + ie_len);
4460 else if (request->ssids)
4461 request->match_sets =
4462 (void *)(request->ssids + n_ssids);
4463 else
4464 request->match_sets =
4465 (void *)(request->channels + n_channels);
4466 }
4467 request->n_match_sets = n_match_sets;
4468
Luciano Coelho807f8a82011-05-11 17:09:35 +03004469 i = 0;
4470 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4471 /* user specified, bail out if channel not found */
4472 nla_for_each_nested(attr,
4473 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4474 tmp) {
4475 struct ieee80211_channel *chan;
4476
4477 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4478
4479 if (!chan) {
4480 err = -EINVAL;
4481 goto out_free;
4482 }
4483
4484 /* ignore disabled channels */
4485 if (chan->flags & IEEE80211_CHAN_DISABLED)
4486 continue;
4487
4488 request->channels[i] = chan;
4489 i++;
4490 }
4491 } else {
4492 /* all channels */
4493 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4494 int j;
4495 if (!wiphy->bands[band])
4496 continue;
4497 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4498 struct ieee80211_channel *chan;
4499
4500 chan = &wiphy->bands[band]->channels[j];
4501
4502 if (chan->flags & IEEE80211_CHAN_DISABLED)
4503 continue;
4504
4505 request->channels[i] = chan;
4506 i++;
4507 }
4508 }
4509 }
4510
4511 if (!i) {
4512 err = -EINVAL;
4513 goto out_free;
4514 }
4515
4516 request->n_channels = i;
4517
4518 i = 0;
4519 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4520 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4521 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004522 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004523 err = -EINVAL;
4524 goto out_free;
4525 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004526 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004527 memcpy(request->ssids[i].ssid, nla_data(attr),
4528 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004529 i++;
4530 }
4531 }
4532
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004533 i = 0;
4534 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4535 nla_for_each_nested(attr,
4536 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4537 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004538 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004539
4540 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4541 nla_data(attr), nla_len(attr),
4542 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004543 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004544 if (ssid) {
4545 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4546 err = -EINVAL;
4547 goto out_free;
4548 }
4549 memcpy(request->match_sets[i].ssid.ssid,
4550 nla_data(ssid), nla_len(ssid));
4551 request->match_sets[i].ssid.ssid_len =
4552 nla_len(ssid);
4553 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004554 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4555 if (rssi)
4556 request->rssi_thold = nla_get_u32(rssi);
4557 else
4558 request->rssi_thold =
4559 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004560 i++;
4561 }
4562 }
4563
Luciano Coelho807f8a82011-05-11 17:09:35 +03004564 if (info->attrs[NL80211_ATTR_IE]) {
4565 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4566 memcpy((void *)request->ie,
4567 nla_data(info->attrs[NL80211_ATTR_IE]),
4568 request->ie_len);
4569 }
4570
4571 request->dev = dev;
4572 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004573 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004574
4575 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4576 if (!err) {
4577 rdev->sched_scan_req = request;
4578 nl80211_send_sched_scan(rdev, dev,
4579 NL80211_CMD_START_SCHED_SCAN);
4580 goto out;
4581 }
4582
4583out_free:
4584 kfree(request);
4585out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004586 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004587 return err;
4588}
4589
4590static int nl80211_stop_sched_scan(struct sk_buff *skb,
4591 struct genl_info *info)
4592{
4593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004594 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004595
4596 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4597 !rdev->ops->sched_scan_stop)
4598 return -EOPNOTSUPP;
4599
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004600 mutex_lock(&rdev->sched_scan_mtx);
4601 err = __cfg80211_stop_sched_scan(rdev, false);
4602 mutex_unlock(&rdev->sched_scan_mtx);
4603
4604 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004605}
4606
Johannes Berg9720bb32011-06-21 09:45:33 +02004607static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4608 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004609 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004610 struct wireless_dev *wdev,
4611 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004612{
Johannes Berg48ab9052009-07-10 18:42:31 +02004613 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004614 void *hdr;
4615 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004616
4617 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004618
Johannes Berg9720bb32011-06-21 09:45:33 +02004619 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004620 NL80211_CMD_NEW_SCAN_RESULTS);
4621 if (!hdr)
4622 return -1;
4623
Johannes Berg9720bb32011-06-21 09:45:33 +02004624 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4625
David S. Miller9360ffd2012-03-29 04:41:26 -04004626 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4628 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004629
4630 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4631 if (!bss)
4632 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004633 if ((!is_zero_ether_addr(res->bssid) &&
4634 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4635 (res->information_elements && res->len_information_elements &&
4636 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4637 res->len_information_elements,
4638 res->information_elements)) ||
4639 (res->beacon_ies && res->len_beacon_ies &&
4640 res->beacon_ies != res->information_elements &&
4641 nla_put(msg, NL80211_BSS_BEACON_IES,
4642 res->len_beacon_ies, res->beacon_ies)))
4643 goto nla_put_failure;
4644 if (res->tsf &&
4645 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4646 goto nla_put_failure;
4647 if (res->beacon_interval &&
4648 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4649 goto nla_put_failure;
4650 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4651 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4652 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4653 jiffies_to_msecs(jiffies - intbss->ts)))
4654 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004655
Johannes Berg77965c92009-02-18 18:45:06 +01004656 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004657 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004658 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4659 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004660 break;
4661 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004662 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4663 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004664 break;
4665 default:
4666 break;
4667 }
4668
Johannes Berg48ab9052009-07-10 18:42:31 +02004669 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004670 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004671 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004672 if (intbss == wdev->current_bss &&
4673 nla_put_u32(msg, NL80211_BSS_STATUS,
4674 NL80211_BSS_STATUS_ASSOCIATED))
4675 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004676 break;
4677 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004678 if (intbss == wdev->current_bss &&
4679 nla_put_u32(msg, NL80211_BSS_STATUS,
4680 NL80211_BSS_STATUS_IBSS_JOINED))
4681 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004682 break;
4683 default:
4684 break;
4685 }
4686
Johannes Berg2a519312009-02-10 21:25:55 +01004687 nla_nest_end(msg, bss);
4688
4689 return genlmsg_end(msg, hdr);
4690
4691 nla_put_failure:
4692 genlmsg_cancel(msg, hdr);
4693 return -EMSGSIZE;
4694}
4695
4696static int nl80211_dump_scan(struct sk_buff *skb,
4697 struct netlink_callback *cb)
4698{
Johannes Berg48ab9052009-07-10 18:42:31 +02004699 struct cfg80211_registered_device *rdev;
4700 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004701 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004702 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004703 int start = cb->args[1], idx = 0;
4704 int err;
4705
Johannes Berg67748892010-10-04 21:14:06 +02004706 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4707 if (err)
4708 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004709
Johannes Berg48ab9052009-07-10 18:42:31 +02004710 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004711
Johannes Berg48ab9052009-07-10 18:42:31 +02004712 wdev_lock(wdev);
4713 spin_lock_bh(&rdev->bss_lock);
4714 cfg80211_bss_expire(rdev);
4715
Johannes Berg9720bb32011-06-21 09:45:33 +02004716 cb->seq = rdev->bss_generation;
4717
Johannes Berg48ab9052009-07-10 18:42:31 +02004718 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004719 if (++idx <= start)
4720 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004721 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004722 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004723 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004724 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004725 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004726 }
4727 }
4728
Johannes Berg48ab9052009-07-10 18:42:31 +02004729 spin_unlock_bh(&rdev->bss_lock);
4730 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004731
4732 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004733 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004734
Johannes Berg67748892010-10-04 21:14:06 +02004735 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004736}
4737
Holger Schurig61fa7132009-11-11 12:25:40 +01004738static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4739 int flags, struct net_device *dev,
4740 struct survey_info *survey)
4741{
4742 void *hdr;
4743 struct nlattr *infoattr;
4744
Holger Schurig61fa7132009-11-11 12:25:40 +01004745 hdr = nl80211hdr_put(msg, pid, seq, flags,
4746 NL80211_CMD_NEW_SURVEY_RESULTS);
4747 if (!hdr)
4748 return -ENOMEM;
4749
David S. Miller9360ffd2012-03-29 04:41:26 -04004750 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4751 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004752
4753 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4754 if (!infoattr)
4755 goto nla_put_failure;
4756
David S. Miller9360ffd2012-03-29 04:41:26 -04004757 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4758 survey->channel->center_freq))
4759 goto nla_put_failure;
4760
4761 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4762 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4763 goto nla_put_failure;
4764 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4765 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4766 goto nla_put_failure;
4767 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4768 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4769 survey->channel_time))
4770 goto nla_put_failure;
4771 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4772 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4773 survey->channel_time_busy))
4774 goto nla_put_failure;
4775 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4776 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4777 survey->channel_time_ext_busy))
4778 goto nla_put_failure;
4779 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4780 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4781 survey->channel_time_rx))
4782 goto nla_put_failure;
4783 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4784 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4785 survey->channel_time_tx))
4786 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004787
4788 nla_nest_end(msg, infoattr);
4789
4790 return genlmsg_end(msg, hdr);
4791
4792 nla_put_failure:
4793 genlmsg_cancel(msg, hdr);
4794 return -EMSGSIZE;
4795}
4796
4797static int nl80211_dump_survey(struct sk_buff *skb,
4798 struct netlink_callback *cb)
4799{
4800 struct survey_info survey;
4801 struct cfg80211_registered_device *dev;
4802 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004803 int survey_idx = cb->args[1];
4804 int res;
4805
Johannes Berg67748892010-10-04 21:14:06 +02004806 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4807 if (res)
4808 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004809
4810 if (!dev->ops->dump_survey) {
4811 res = -EOPNOTSUPP;
4812 goto out_err;
4813 }
4814
4815 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004816 struct ieee80211_channel *chan;
4817
Holger Schurig61fa7132009-11-11 12:25:40 +01004818 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4819 &survey);
4820 if (res == -ENOENT)
4821 break;
4822 if (res)
4823 goto out_err;
4824
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004825 /* Survey without a channel doesn't make sense */
4826 if (!survey.channel) {
4827 res = -EINVAL;
4828 goto out;
4829 }
4830
4831 chan = ieee80211_get_channel(&dev->wiphy,
4832 survey.channel->center_freq);
4833 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4834 survey_idx++;
4835 continue;
4836 }
4837
Holger Schurig61fa7132009-11-11 12:25:40 +01004838 if (nl80211_send_survey(skb,
4839 NETLINK_CB(cb->skb).pid,
4840 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4841 netdev,
4842 &survey) < 0)
4843 goto out;
4844 survey_idx++;
4845 }
4846
4847 out:
4848 cb->args[1] = survey_idx;
4849 res = skb->len;
4850 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004851 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004852 return res;
4853}
4854
Jouni Malinen255e7372009-03-20 21:21:17 +02004855static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4856{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004857 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004858}
4859
Samuel Ortizb23aa672009-07-01 21:26:54 +02004860static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4861{
4862 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4863 NL80211_WPA_VERSION_2));
4864}
4865
Jouni Malinen636a5d32009-03-19 13:39:22 +02004866static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4867{
Johannes Berg4c476992010-10-04 21:36:35 +02004868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4869 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004870 struct ieee80211_channel *chan;
4871 const u8 *bssid, *ssid, *ie = NULL;
4872 int err, ssid_len, ie_len = 0;
4873 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004874 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004875 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004876
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004877 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4878 return -EINVAL;
4879
4880 if (!info->attrs[NL80211_ATTR_MAC])
4881 return -EINVAL;
4882
Jouni Malinen17780922009-03-27 20:52:47 +02004883 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4884 return -EINVAL;
4885
Johannes Berg19957bb2009-07-02 17:20:43 +02004886 if (!info->attrs[NL80211_ATTR_SSID])
4887 return -EINVAL;
4888
4889 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4890 return -EINVAL;
4891
Johannes Bergfffd0932009-07-08 14:22:54 +02004892 err = nl80211_parse_key(info, &key);
4893 if (err)
4894 return err;
4895
4896 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004897 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4898 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004899 if (!key.p.key || !key.p.key_len)
4900 return -EINVAL;
4901 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4902 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4903 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4904 key.p.key_len != WLAN_KEY_LEN_WEP104))
4905 return -EINVAL;
4906 if (key.idx > 4)
4907 return -EINVAL;
4908 } else {
4909 key.p.key_len = 0;
4910 key.p.key = NULL;
4911 }
4912
Johannes Bergafea0b72010-08-10 09:46:42 +02004913 if (key.idx >= 0) {
4914 int i;
4915 bool ok = false;
4916 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4917 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4918 ok = true;
4919 break;
4920 }
4921 }
Johannes Berg4c476992010-10-04 21:36:35 +02004922 if (!ok)
4923 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004924 }
4925
Johannes Berg4c476992010-10-04 21:36:35 +02004926 if (!rdev->ops->auth)
4927 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004928
Johannes Berg074ac8d2010-09-16 14:58:22 +02004929 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004930 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4931 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004932
Johannes Berg19957bb2009-07-02 17:20:43 +02004933 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004934 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004935 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004936 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4937 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004938
Johannes Berg19957bb2009-07-02 17:20:43 +02004939 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4940 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4941
4942 if (info->attrs[NL80211_ATTR_IE]) {
4943 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4944 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4945 }
4946
4947 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004948 if (!nl80211_valid_auth_type(auth_type))
4949 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004950
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004951 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4952
Johannes Berg95de8172012-01-20 13:55:25 +01004953 /*
4954 * Since we no longer track auth state, ignore
4955 * requests to only change local state.
4956 */
4957 if (local_state_change)
4958 return 0;
4959
Johannes Berg4c476992010-10-04 21:36:35 +02004960 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4961 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004962 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004963}
4964
Johannes Bergc0692b82010-08-27 14:26:53 +03004965static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4966 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004967 struct cfg80211_crypto_settings *settings,
4968 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004969{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004970 memset(settings, 0, sizeof(*settings));
4971
Samuel Ortizb23aa672009-07-01 21:26:54 +02004972 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4973
Johannes Bergc0692b82010-08-27 14:26:53 +03004974 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4975 u16 proto;
4976 proto = nla_get_u16(
4977 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4978 settings->control_port_ethertype = cpu_to_be16(proto);
4979 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4980 proto != ETH_P_PAE)
4981 return -EINVAL;
4982 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4983 settings->control_port_no_encrypt = true;
4984 } else
4985 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4986
Samuel Ortizb23aa672009-07-01 21:26:54 +02004987 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4988 void *data;
4989 int len, i;
4990
4991 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4992 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4993 settings->n_ciphers_pairwise = len / sizeof(u32);
4994
4995 if (len % sizeof(u32))
4996 return -EINVAL;
4997
Johannes Berg3dc27d22009-07-02 21:36:37 +02004998 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004999 return -EINVAL;
5000
5001 memcpy(settings->ciphers_pairwise, data, len);
5002
5003 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005004 if (!cfg80211_supported_cipher_suite(
5005 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005006 settings->ciphers_pairwise[i]))
5007 return -EINVAL;
5008 }
5009
5010 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5011 settings->cipher_group =
5012 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005013 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5014 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005015 return -EINVAL;
5016 }
5017
5018 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5019 settings->wpa_versions =
5020 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5021 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5022 return -EINVAL;
5023 }
5024
5025 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5026 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005027 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005028
5029 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5030 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5031 settings->n_akm_suites = len / sizeof(u32);
5032
5033 if (len % sizeof(u32))
5034 return -EINVAL;
5035
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005036 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5037 return -EINVAL;
5038
Samuel Ortizb23aa672009-07-01 21:26:54 +02005039 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005040 }
5041
5042 return 0;
5043}
5044
Jouni Malinen636a5d32009-03-19 13:39:22 +02005045static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5046{
Johannes Berg4c476992010-10-04 21:36:35 +02005047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5048 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005049 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005050 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005051 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005052 int err, ssid_len, ie_len = 0;
5053 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005054 u32 flags = 0;
5055 struct ieee80211_ht_cap *ht_capa = NULL;
5056 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005057
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005058 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5059 return -EINVAL;
5060
5061 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005062 !info->attrs[NL80211_ATTR_SSID] ||
5063 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005064 return -EINVAL;
5065
Johannes Berg4c476992010-10-04 21:36:35 +02005066 if (!rdev->ops->assoc)
5067 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005068
Johannes Berg074ac8d2010-09-16 14:58:22 +02005069 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005070 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5071 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005072
Johannes Berg19957bb2009-07-02 17:20:43 +02005073 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005074
Johannes Berg19957bb2009-07-02 17:20:43 +02005075 chan = ieee80211_get_channel(&rdev->wiphy,
5076 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005077 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5078 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005079
Johannes Berg19957bb2009-07-02 17:20:43 +02005080 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5081 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005082
5083 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005084 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5085 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005086 }
5087
Jouni Malinendc6382ce2009-05-06 22:09:37 +03005088 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005089 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03005090 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005091 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02005092 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02005093 else if (mfp != NL80211_MFP_NO)
5094 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03005095 }
5096
Johannes Berg3e5d7642009-07-07 14:37:26 +02005097 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5098 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5099
Ben Greear7e7c8922011-11-18 11:31:59 -08005100 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5101 flags |= ASSOC_REQ_DISABLE_HT;
5102
5103 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5104 ht_capa_mask =
5105 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5106
5107 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5108 if (!ht_capa_mask)
5109 return -EINVAL;
5110 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5111 }
5112
Johannes Bergc0692b82010-08-27 14:26:53 +03005113 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005114 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02005115 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5116 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08005117 &crypto, flags, ht_capa,
5118 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005119
Jouni Malinen636a5d32009-03-19 13:39:22 +02005120 return err;
5121}
5122
5123static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5124{
Johannes Berg4c476992010-10-04 21:36:35 +02005125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5126 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005127 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005128 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005129 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005130 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005131
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005132 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5133 return -EINVAL;
5134
5135 if (!info->attrs[NL80211_ATTR_MAC])
5136 return -EINVAL;
5137
5138 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5139 return -EINVAL;
5140
Johannes Berg4c476992010-10-04 21:36:35 +02005141 if (!rdev->ops->deauth)
5142 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005143
Johannes Berg074ac8d2010-09-16 14:58:22 +02005144 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005145 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5146 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005147
Johannes Berg19957bb2009-07-02 17:20:43 +02005148 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005149
Johannes Berg19957bb2009-07-02 17:20:43 +02005150 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5151 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005152 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005153 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005154 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005155
5156 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005157 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5158 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005159 }
5160
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005161 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5162
Johannes Berg4c476992010-10-04 21:36:35 +02005163 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5164 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005165}
5166
5167static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5168{
Johannes Berg4c476992010-10-04 21:36:35 +02005169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5170 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005171 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005172 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005173 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005174 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005175
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005176 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5177 return -EINVAL;
5178
5179 if (!info->attrs[NL80211_ATTR_MAC])
5180 return -EINVAL;
5181
5182 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5183 return -EINVAL;
5184
Johannes Berg4c476992010-10-04 21:36:35 +02005185 if (!rdev->ops->disassoc)
5186 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005187
Johannes Berg074ac8d2010-09-16 14:58:22 +02005188 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005189 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5190 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005191
Johannes Berg19957bb2009-07-02 17:20:43 +02005192 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005193
Johannes Berg19957bb2009-07-02 17:20:43 +02005194 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5195 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005196 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005197 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005198 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005199
5200 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005201 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5202 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005203 }
5204
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005205 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5206
Johannes Berg4c476992010-10-04 21:36:35 +02005207 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5208 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005209}
5210
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005211static bool
5212nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5213 int mcast_rate[IEEE80211_NUM_BANDS],
5214 int rateval)
5215{
5216 struct wiphy *wiphy = &rdev->wiphy;
5217 bool found = false;
5218 int band, i;
5219
5220 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5221 struct ieee80211_supported_band *sband;
5222
5223 sband = wiphy->bands[band];
5224 if (!sband)
5225 continue;
5226
5227 for (i = 0; i < sband->n_bitrates; i++) {
5228 if (sband->bitrates[i].bitrate == rateval) {
5229 mcast_rate[band] = i + 1;
5230 found = true;
5231 break;
5232 }
5233 }
5234 }
5235
5236 return found;
5237}
5238
Johannes Berg04a773a2009-04-19 21:24:32 +02005239static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5240{
Johannes Berg4c476992010-10-04 21:36:35 +02005241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5242 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005243 struct cfg80211_ibss_params ibss;
5244 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005245 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005246 int err;
5247
Johannes Berg8e30bc52009-04-22 17:45:38 +02005248 memset(&ibss, 0, sizeof(ibss));
5249
Johannes Berg04a773a2009-04-19 21:24:32 +02005250 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5251 return -EINVAL;
5252
5253 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5254 !info->attrs[NL80211_ATTR_SSID] ||
5255 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5256 return -EINVAL;
5257
Johannes Berg8e30bc52009-04-22 17:45:38 +02005258 ibss.beacon_interval = 100;
5259
5260 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5261 ibss.beacon_interval =
5262 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5263 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5264 return -EINVAL;
5265 }
5266
Johannes Berg4c476992010-10-04 21:36:35 +02005267 if (!rdev->ops->join_ibss)
5268 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005269
Johannes Berg4c476992010-10-04 21:36:35 +02005270 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5271 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005272
Johannes Berg79c97e92009-07-07 03:56:12 +02005273 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005274
Johannes Berg39193492011-09-16 13:45:25 +02005275 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005276 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005277
5278 if (!is_valid_ether_addr(ibss.bssid))
5279 return -EINVAL;
5280 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005281 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5282 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5283
5284 if (info->attrs[NL80211_ATTR_IE]) {
5285 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5286 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5287 }
5288
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005289 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5290 enum nl80211_channel_type channel_type;
5291
Johannes Bergcd6c6592012-05-10 21:27:18 +02005292 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005293 return -EINVAL;
5294
5295 if (channel_type != NL80211_CHAN_NO_HT &&
5296 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5297 return -EINVAL;
5298
5299 ibss.channel_type = channel_type;
5300 } else {
5301 ibss.channel_type = NL80211_CHAN_NO_HT;
5302 }
5303
5304 ibss.channel = rdev_freq_to_chan(rdev,
5305 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5306 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005307 if (!ibss.channel ||
5308 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005309 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5310 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005311
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005312 /* Both channels should be able to initiate communication */
5313 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5314 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5315 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5316 ibss.channel_type))
5317 return -EINVAL;
5318
Johannes Berg04a773a2009-04-19 21:24:32 +02005319 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005320 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005321
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005322 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5323 u8 *rates =
5324 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5325 int n_rates =
5326 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5327 struct ieee80211_supported_band *sband =
5328 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005329
Johannes Berg34850ab2011-07-18 18:08:35 +02005330 err = ieee80211_get_ratemask(sband, rates, n_rates,
5331 &ibss.basic_rates);
5332 if (err)
5333 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005334 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005335
5336 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5337 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5338 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5339 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005340
Johannes Berg4c476992010-10-04 21:36:35 +02005341 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5342 connkeys = nl80211_parse_connkeys(rdev,
5343 info->attrs[NL80211_ATTR_KEYS]);
5344 if (IS_ERR(connkeys))
5345 return PTR_ERR(connkeys);
5346 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005347
Antonio Quartulli267335d2012-01-31 20:25:47 +01005348 ibss.control_port =
5349 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5350
Johannes Berg4c476992010-10-04 21:36:35 +02005351 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005352 if (err)
5353 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005354 return err;
5355}
5356
5357static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5358{
Johannes Berg4c476992010-10-04 21:36:35 +02005359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5360 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005361
Johannes Berg4c476992010-10-04 21:36:35 +02005362 if (!rdev->ops->leave_ibss)
5363 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005364
Johannes Berg4c476992010-10-04 21:36:35 +02005365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5366 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005367
Johannes Berg4c476992010-10-04 21:36:35 +02005368 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005369}
5370
Johannes Bergaff89a92009-07-01 21:26:51 +02005371#ifdef CONFIG_NL80211_TESTMODE
5372static struct genl_multicast_group nl80211_testmode_mcgrp = {
5373 .name = "testmode",
5374};
5375
5376static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5377{
Johannes Berg4c476992010-10-04 21:36:35 +02005378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005379 int err;
5380
5381 if (!info->attrs[NL80211_ATTR_TESTDATA])
5382 return -EINVAL;
5383
Johannes Bergaff89a92009-07-01 21:26:51 +02005384 err = -EOPNOTSUPP;
5385 if (rdev->ops->testmode_cmd) {
5386 rdev->testmode_info = info;
5387 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5388 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5389 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5390 rdev->testmode_info = NULL;
5391 }
5392
Johannes Bergaff89a92009-07-01 21:26:51 +02005393 return err;
5394}
5395
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005396static int nl80211_testmode_dump(struct sk_buff *skb,
5397 struct netlink_callback *cb)
5398{
Johannes Berg00918d32011-12-13 17:22:05 +01005399 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005400 int err;
5401 long phy_idx;
5402 void *data = NULL;
5403 int data_len = 0;
5404
5405 if (cb->args[0]) {
5406 /*
5407 * 0 is a valid index, but not valid for args[0],
5408 * so we need to offset by 1.
5409 */
5410 phy_idx = cb->args[0] - 1;
5411 } else {
5412 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5413 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5414 nl80211_policy);
5415 if (err)
5416 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005417
Johannes Berg2bd7e352012-06-15 14:23:16 +02005418 mutex_lock(&cfg80211_mutex);
5419 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5420 nl80211_fam.attrbuf);
5421 if (IS_ERR(rdev)) {
5422 mutex_unlock(&cfg80211_mutex);
5423 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005424 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005425 phy_idx = rdev->wiphy_idx;
5426 rdev = NULL;
5427 mutex_unlock(&cfg80211_mutex);
5428
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005429 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5430 cb->args[1] =
5431 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5432 }
5433
5434 if (cb->args[1]) {
5435 data = nla_data((void *)cb->args[1]);
5436 data_len = nla_len((void *)cb->args[1]);
5437 }
5438
5439 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005440 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5441 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005442 mutex_unlock(&cfg80211_mutex);
5443 return -ENOENT;
5444 }
Johannes Berg00918d32011-12-13 17:22:05 +01005445 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005446 mutex_unlock(&cfg80211_mutex);
5447
Johannes Berg00918d32011-12-13 17:22:05 +01005448 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005449 err = -EOPNOTSUPP;
5450 goto out_err;
5451 }
5452
5453 while (1) {
5454 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5455 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5456 NL80211_CMD_TESTMODE);
5457 struct nlattr *tmdata;
5458
David S. Miller9360ffd2012-03-29 04:41:26 -04005459 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005460 genlmsg_cancel(skb, hdr);
5461 break;
5462 }
5463
5464 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5465 if (!tmdata) {
5466 genlmsg_cancel(skb, hdr);
5467 break;
5468 }
Johannes Berg00918d32011-12-13 17:22:05 +01005469 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5470 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005471 nla_nest_end(skb, tmdata);
5472
5473 if (err == -ENOBUFS || err == -ENOENT) {
5474 genlmsg_cancel(skb, hdr);
5475 break;
5476 } else if (err) {
5477 genlmsg_cancel(skb, hdr);
5478 goto out_err;
5479 }
5480
5481 genlmsg_end(skb, hdr);
5482 }
5483
5484 err = skb->len;
5485 /* see above */
5486 cb->args[0] = phy_idx + 1;
5487 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005488 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005489 return err;
5490}
5491
Johannes Bergaff89a92009-07-01 21:26:51 +02005492static struct sk_buff *
5493__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5494 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5495{
5496 struct sk_buff *skb;
5497 void *hdr;
5498 struct nlattr *data;
5499
5500 skb = nlmsg_new(approxlen + 100, gfp);
5501 if (!skb)
5502 return NULL;
5503
5504 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5505 if (!hdr) {
5506 kfree_skb(skb);
5507 return NULL;
5508 }
5509
David S. Miller9360ffd2012-03-29 04:41:26 -04005510 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5511 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005512 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5513
5514 ((void **)skb->cb)[0] = rdev;
5515 ((void **)skb->cb)[1] = hdr;
5516 ((void **)skb->cb)[2] = data;
5517
5518 return skb;
5519
5520 nla_put_failure:
5521 kfree_skb(skb);
5522 return NULL;
5523}
5524
5525struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5526 int approxlen)
5527{
5528 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5529
5530 if (WARN_ON(!rdev->testmode_info))
5531 return NULL;
5532
5533 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5534 rdev->testmode_info->snd_pid,
5535 rdev->testmode_info->snd_seq,
5536 GFP_KERNEL);
5537}
5538EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5539
5540int cfg80211_testmode_reply(struct sk_buff *skb)
5541{
5542 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5543 void *hdr = ((void **)skb->cb)[1];
5544 struct nlattr *data = ((void **)skb->cb)[2];
5545
5546 if (WARN_ON(!rdev->testmode_info)) {
5547 kfree_skb(skb);
5548 return -EINVAL;
5549 }
5550
5551 nla_nest_end(skb, data);
5552 genlmsg_end(skb, hdr);
5553 return genlmsg_reply(skb, rdev->testmode_info);
5554}
5555EXPORT_SYMBOL(cfg80211_testmode_reply);
5556
5557struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5558 int approxlen, gfp_t gfp)
5559{
5560 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5561
5562 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5563}
5564EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5565
5566void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5567{
5568 void *hdr = ((void **)skb->cb)[1];
5569 struct nlattr *data = ((void **)skb->cb)[2];
5570
5571 nla_nest_end(skb, data);
5572 genlmsg_end(skb, hdr);
5573 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5574}
5575EXPORT_SYMBOL(cfg80211_testmode_event);
5576#endif
5577
Samuel Ortizb23aa672009-07-01 21:26:54 +02005578static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5579{
Johannes Berg4c476992010-10-04 21:36:35 +02005580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5581 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005582 struct cfg80211_connect_params connect;
5583 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005584 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005585 int err;
5586
5587 memset(&connect, 0, sizeof(connect));
5588
5589 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5590 return -EINVAL;
5591
5592 if (!info->attrs[NL80211_ATTR_SSID] ||
5593 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5594 return -EINVAL;
5595
5596 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5597 connect.auth_type =
5598 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5599 if (!nl80211_valid_auth_type(connect.auth_type))
5600 return -EINVAL;
5601 } else
5602 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5603
5604 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5605
Johannes Bergc0692b82010-08-27 14:26:53 +03005606 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005607 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005608 if (err)
5609 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005610
Johannes Berg074ac8d2010-09-16 14:58:22 +02005611 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005612 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5613 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005614
Johannes Berg79c97e92009-07-07 03:56:12 +02005615 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005616
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305617 connect.bg_scan_period = -1;
5618 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5619 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5620 connect.bg_scan_period =
5621 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5622 }
5623
Samuel Ortizb23aa672009-07-01 21:26:54 +02005624 if (info->attrs[NL80211_ATTR_MAC])
5625 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5626 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5627 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5628
5629 if (info->attrs[NL80211_ATTR_IE]) {
5630 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5631 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5632 }
5633
5634 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5635 connect.channel =
5636 ieee80211_get_channel(wiphy,
5637 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5638 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005639 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5640 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005641 }
5642
Johannes Bergfffd0932009-07-08 14:22:54 +02005643 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5644 connkeys = nl80211_parse_connkeys(rdev,
5645 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005646 if (IS_ERR(connkeys))
5647 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005648 }
5649
Ben Greear7e7c8922011-11-18 11:31:59 -08005650 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5651 connect.flags |= ASSOC_REQ_DISABLE_HT;
5652
5653 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5654 memcpy(&connect.ht_capa_mask,
5655 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5656 sizeof(connect.ht_capa_mask));
5657
5658 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005659 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
5660 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08005661 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005662 }
Ben Greear7e7c8922011-11-18 11:31:59 -08005663 memcpy(&connect.ht_capa,
5664 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5665 sizeof(connect.ht_capa));
5666 }
5667
Johannes Bergfffd0932009-07-08 14:22:54 +02005668 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005669 if (err)
5670 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005671 return err;
5672}
5673
5674static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5675{
Johannes Berg4c476992010-10-04 21:36:35 +02005676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5677 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005678 u16 reason;
5679
5680 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5681 reason = WLAN_REASON_DEAUTH_LEAVING;
5682 else
5683 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5684
5685 if (reason == 0)
5686 return -EINVAL;
5687
Johannes Berg074ac8d2010-09-16 14:58:22 +02005688 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005689 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5690 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005691
Johannes Berg4c476992010-10-04 21:36:35 +02005692 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005693}
5694
Johannes Berg463d0182009-07-14 00:33:35 +02005695static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5696{
Johannes Berg4c476992010-10-04 21:36:35 +02005697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005698 struct net *net;
5699 int err;
5700 u32 pid;
5701
5702 if (!info->attrs[NL80211_ATTR_PID])
5703 return -EINVAL;
5704
5705 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5706
Johannes Berg463d0182009-07-14 00:33:35 +02005707 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005708 if (IS_ERR(net))
5709 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005710
5711 err = 0;
5712
5713 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005714 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5715 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005716
Johannes Berg463d0182009-07-14 00:33:35 +02005717 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005718 return err;
5719}
5720
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005721static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5722{
Johannes Berg4c476992010-10-04 21:36:35 +02005723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005724 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5725 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005726 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005727 struct cfg80211_pmksa pmksa;
5728
5729 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5730
5731 if (!info->attrs[NL80211_ATTR_MAC])
5732 return -EINVAL;
5733
5734 if (!info->attrs[NL80211_ATTR_PMKID])
5735 return -EINVAL;
5736
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005737 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5738 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5739
Johannes Berg074ac8d2010-09-16 14:58:22 +02005740 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005741 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5742 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005743
5744 switch (info->genlhdr->cmd) {
5745 case NL80211_CMD_SET_PMKSA:
5746 rdev_ops = rdev->ops->set_pmksa;
5747 break;
5748 case NL80211_CMD_DEL_PMKSA:
5749 rdev_ops = rdev->ops->del_pmksa;
5750 break;
5751 default:
5752 WARN_ON(1);
5753 break;
5754 }
5755
Johannes Berg4c476992010-10-04 21:36:35 +02005756 if (!rdev_ops)
5757 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005758
Johannes Berg4c476992010-10-04 21:36:35 +02005759 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005760}
5761
5762static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5763{
Johannes Berg4c476992010-10-04 21:36:35 +02005764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5765 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005766
Johannes Berg074ac8d2010-09-16 14:58:22 +02005767 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005768 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5769 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005770
Johannes Berg4c476992010-10-04 21:36:35 +02005771 if (!rdev->ops->flush_pmksa)
5772 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005773
Johannes Berg4c476992010-10-04 21:36:35 +02005774 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005775}
5776
Arik Nemtsov109086c2011-09-28 14:12:50 +03005777static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5778{
5779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5780 struct net_device *dev = info->user_ptr[1];
5781 u8 action_code, dialog_token;
5782 u16 status_code;
5783 u8 *peer;
5784
5785 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5786 !rdev->ops->tdls_mgmt)
5787 return -EOPNOTSUPP;
5788
5789 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5790 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5791 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5792 !info->attrs[NL80211_ATTR_IE] ||
5793 !info->attrs[NL80211_ATTR_MAC])
5794 return -EINVAL;
5795
5796 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5797 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5798 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5799 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5800
5801 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5802 dialog_token, status_code,
5803 nla_data(info->attrs[NL80211_ATTR_IE]),
5804 nla_len(info->attrs[NL80211_ATTR_IE]));
5805}
5806
5807static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5808{
5809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5810 struct net_device *dev = info->user_ptr[1];
5811 enum nl80211_tdls_operation operation;
5812 u8 *peer;
5813
5814 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5815 !rdev->ops->tdls_oper)
5816 return -EOPNOTSUPP;
5817
5818 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5819 !info->attrs[NL80211_ATTR_MAC])
5820 return -EINVAL;
5821
5822 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5823 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5824
5825 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5826}
5827
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005828static int nl80211_remain_on_channel(struct sk_buff *skb,
5829 struct genl_info *info)
5830{
Johannes Berg4c476992010-10-04 21:36:35 +02005831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005832 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005833 struct ieee80211_channel *chan;
5834 struct sk_buff *msg;
5835 void *hdr;
5836 u64 cookie;
5837 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5838 u32 freq, duration;
5839 int err;
5840
5841 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5842 !info->attrs[NL80211_ATTR_DURATION])
5843 return -EINVAL;
5844
5845 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5846
Johannes Berg7c4ef712011-11-18 15:33:48 +01005847 if (!rdev->ops->remain_on_channel ||
5848 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005849 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005850
Johannes Bergebf348f2012-06-01 12:50:54 +02005851 /*
5852 * We should be on that channel for at least a minimum amount of
5853 * time (10ms) but no longer than the driver supports.
5854 */
5855 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5856 duration > rdev->wiphy.max_remain_on_channel_duration)
5857 return -EINVAL;
5858
Johannes Bergcd6c6592012-05-10 21:27:18 +02005859 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5860 !nl80211_valid_channel_type(info, &channel_type))
5861 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005862
5863 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5864 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005865 if (chan == NULL)
5866 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005867
5868 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005869 if (!msg)
5870 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005871
5872 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5873 NL80211_CMD_REMAIN_ON_CHANNEL);
5874
5875 if (IS_ERR(hdr)) {
5876 err = PTR_ERR(hdr);
5877 goto free_msg;
5878 }
5879
Johannes Berg71bbc992012-06-15 15:30:18 +02005880 err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005881 channel_type, duration, &cookie);
5882
5883 if (err)
5884 goto free_msg;
5885
David S. Miller9360ffd2012-03-29 04:41:26 -04005886 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5887 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005888
5889 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005890
5891 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005892
5893 nla_put_failure:
5894 err = -ENOBUFS;
5895 free_msg:
5896 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005897 return err;
5898}
5899
5900static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5901 struct genl_info *info)
5902{
Johannes Berg4c476992010-10-04 21:36:35 +02005903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005904 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005905 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005906
5907 if (!info->attrs[NL80211_ATTR_COOKIE])
5908 return -EINVAL;
5909
Johannes Berg4c476992010-10-04 21:36:35 +02005910 if (!rdev->ops->cancel_remain_on_channel)
5911 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005912
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005913 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5914
Johannes Berg71bbc992012-06-15 15:30:18 +02005915 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005916}
5917
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005918static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5919 u8 *rates, u8 rates_len)
5920{
5921 u8 i;
5922 u32 mask = 0;
5923
5924 for (i = 0; i < rates_len; i++) {
5925 int rate = (rates[i] & 0x7f) * 5;
5926 int ridx;
5927 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5928 struct ieee80211_rate *srate =
5929 &sband->bitrates[ridx];
5930 if (rate == srate->bitrate) {
5931 mask |= 1 << ridx;
5932 break;
5933 }
5934 }
5935 if (ridx == sband->n_bitrates)
5936 return 0; /* rate not found */
5937 }
5938
5939 return mask;
5940}
5941
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005942static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5943 u8 *rates, u8 rates_len,
5944 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5945{
5946 u8 i;
5947
5948 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5949
5950 for (i = 0; i < rates_len; i++) {
5951 int ridx, rbit;
5952
5953 ridx = rates[i] / 8;
5954 rbit = BIT(rates[i] % 8);
5955
5956 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005957 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005958 return false;
5959
5960 /* check availability */
5961 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5962 mcs[ridx] |= rbit;
5963 else
5964 return false;
5965 }
5966
5967 return true;
5968}
5969
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005970static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005971 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5972 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005973 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5974 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005975};
5976
5977static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5978 struct genl_info *info)
5979{
5980 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005982 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005983 int rem, i;
5984 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005985 struct nlattr *tx_rates;
5986 struct ieee80211_supported_band *sband;
5987
5988 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5989 return -EINVAL;
5990
Johannes Berg4c476992010-10-04 21:36:35 +02005991 if (!rdev->ops->set_bitrate_mask)
5992 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005993
5994 memset(&mask, 0, sizeof(mask));
5995 /* Default to all rates enabled */
5996 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5997 sband = rdev->wiphy.bands[i];
5998 mask.control[i].legacy =
5999 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006000 if (sband)
6001 memcpy(mask.control[i].mcs,
6002 sband->ht_cap.mcs.rx_mask,
6003 sizeof(mask.control[i].mcs));
6004 else
6005 memset(mask.control[i].mcs, 0,
6006 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006007 }
6008
6009 /*
6010 * The nested attribute uses enum nl80211_band as the index. This maps
6011 * directly to the enum ieee80211_band values used in cfg80211.
6012 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006013 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006014 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6015 {
6016 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006017 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6018 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006019 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006020 if (sband == NULL)
6021 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006022 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6023 nla_len(tx_rates), nl80211_txattr_policy);
6024 if (tb[NL80211_TXRATE_LEGACY]) {
6025 mask.control[band].legacy = rateset_to_mask(
6026 sband,
6027 nla_data(tb[NL80211_TXRATE_LEGACY]),
6028 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306029 if ((mask.control[band].legacy == 0) &&
6030 nla_len(tb[NL80211_TXRATE_LEGACY]))
6031 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006032 }
6033 if (tb[NL80211_TXRATE_MCS]) {
6034 if (!ht_rateset_to_mask(
6035 sband,
6036 nla_data(tb[NL80211_TXRATE_MCS]),
6037 nla_len(tb[NL80211_TXRATE_MCS]),
6038 mask.control[band].mcs))
6039 return -EINVAL;
6040 }
6041
6042 if (mask.control[band].legacy == 0) {
6043 /* don't allow empty legacy rates if HT
6044 * is not even supported. */
6045 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6046 return -EINVAL;
6047
6048 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6049 if (mask.control[band].mcs[i])
6050 break;
6051
6052 /* legacy and mcs rates may not be both empty */
6053 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02006054 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006055 }
6056 }
6057
Johannes Berg4c476992010-10-04 21:36:35 +02006058 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006059}
6060
Johannes Berg2e161f72010-08-12 15:38:38 +02006061static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006062{
Johannes Berg4c476992010-10-04 21:36:35 +02006063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006064 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02006065 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02006066
6067 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6068 return -EINVAL;
6069
Johannes Berg2e161f72010-08-12 15:38:38 +02006070 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6071 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02006072
Johannes Berg71bbc992012-06-15 15:30:18 +02006073 switch (wdev->iftype) {
6074 case NL80211_IFTYPE_STATION:
6075 case NL80211_IFTYPE_ADHOC:
6076 case NL80211_IFTYPE_P2P_CLIENT:
6077 case NL80211_IFTYPE_AP:
6078 case NL80211_IFTYPE_AP_VLAN:
6079 case NL80211_IFTYPE_MESH_POINT:
6080 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006081 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006082 break;
6083 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006084 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006085 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006086
6087 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02006088 if (!rdev->ops->mgmt_tx)
6089 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006090
Johannes Berg71bbc992012-06-15 15:30:18 +02006091 return cfg80211_mlme_register_mgmt(wdev, info->snd_pid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02006092 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6093 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02006094}
6095
Johannes Berg2e161f72010-08-12 15:38:38 +02006096static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006097{
Johannes Berg4c476992010-10-04 21:36:35 +02006098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006099 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02006100 struct ieee80211_channel *chan;
6101 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02006102 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02006103 u32 freq;
6104 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01006105 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006106 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01006107 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006108 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01006109 bool offchan, no_cck, dont_wait_for_ack;
6110
6111 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02006112
6113 if (!info->attrs[NL80211_ATTR_FRAME] ||
6114 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6115 return -EINVAL;
6116
Johannes Berg4c476992010-10-04 21:36:35 +02006117 if (!rdev->ops->mgmt_tx)
6118 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006119
Johannes Berg71bbc992012-06-15 15:30:18 +02006120 switch (wdev->iftype) {
6121 case NL80211_IFTYPE_STATION:
6122 case NL80211_IFTYPE_ADHOC:
6123 case NL80211_IFTYPE_P2P_CLIENT:
6124 case NL80211_IFTYPE_AP:
6125 case NL80211_IFTYPE_AP_VLAN:
6126 case NL80211_IFTYPE_MESH_POINT:
6127 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006128 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006129 break;
6130 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006131 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006132 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006133
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006134 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01006135 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006136 return -EINVAL;
6137 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02006138
6139 /*
6140 * We should wait on the channel for at least a minimum amount
6141 * of time (10ms) but no longer than the driver supports.
6142 */
6143 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6144 wait > rdev->wiphy.max_remain_on_channel_duration)
6145 return -EINVAL;
6146
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006147 }
6148
Jouni Malinen026331c2010-02-15 12:53:10 +02006149 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02006150 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02006151 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02006152 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02006153 }
6154
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006155 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6156
Johannes Berg7c4ef712011-11-18 15:33:48 +01006157 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6158 return -EINVAL;
6159
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306160 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6161
Jouni Malinen026331c2010-02-15 12:53:10 +02006162 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6163 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006164 if (chan == NULL)
6165 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006166
Johannes Berge247bd902011-11-04 11:18:21 +01006167 if (!dont_wait_for_ack) {
6168 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6169 if (!msg)
6170 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006171
Johannes Berge247bd902011-11-04 11:18:21 +01006172 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6173 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006174
Johannes Berge247bd902011-11-04 11:18:21 +01006175 if (IS_ERR(hdr)) {
6176 err = PTR_ERR(hdr);
6177 goto free_msg;
6178 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006179 }
Johannes Berge247bd902011-11-04 11:18:21 +01006180
Johannes Berg71bbc992012-06-15 15:30:18 +02006181 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006182 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006183 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6184 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006185 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006186 if (err)
6187 goto free_msg;
6188
Johannes Berge247bd902011-11-04 11:18:21 +01006189 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006190 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6191 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006192
Johannes Berge247bd902011-11-04 11:18:21 +01006193 genlmsg_end(msg, hdr);
6194 return genlmsg_reply(msg, info);
6195 }
6196
6197 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006198
6199 nla_put_failure:
6200 err = -ENOBUFS;
6201 free_msg:
6202 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006203 return err;
6204}
6205
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006206static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6207{
6208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006209 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006210 u64 cookie;
6211
6212 if (!info->attrs[NL80211_ATTR_COOKIE])
6213 return -EINVAL;
6214
6215 if (!rdev->ops->mgmt_tx_cancel_wait)
6216 return -EOPNOTSUPP;
6217
Johannes Berg71bbc992012-06-15 15:30:18 +02006218 switch (wdev->iftype) {
6219 case NL80211_IFTYPE_STATION:
6220 case NL80211_IFTYPE_ADHOC:
6221 case NL80211_IFTYPE_P2P_CLIENT:
6222 case NL80211_IFTYPE_AP:
6223 case NL80211_IFTYPE_AP_VLAN:
6224 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006225 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006226 break;
6227 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006228 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006229 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006230
6231 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6232
Johannes Berg71bbc992012-06-15 15:30:18 +02006233 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006234}
6235
Kalle Valoffb9eb32010-02-17 17:58:10 +02006236static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6237{
Johannes Berg4c476992010-10-04 21:36:35 +02006238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006239 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006240 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006241 u8 ps_state;
6242 bool state;
6243 int err;
6244
Johannes Berg4c476992010-10-04 21:36:35 +02006245 if (!info->attrs[NL80211_ATTR_PS_STATE])
6246 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006247
6248 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6249
Johannes Berg4c476992010-10-04 21:36:35 +02006250 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6251 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006252
6253 wdev = dev->ieee80211_ptr;
6254
Johannes Berg4c476992010-10-04 21:36:35 +02006255 if (!rdev->ops->set_power_mgmt)
6256 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006257
6258 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6259
6260 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006261 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006262
Johannes Berg4c476992010-10-04 21:36:35 +02006263 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6264 wdev->ps_timeout);
6265 if (!err)
6266 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006267 return err;
6268}
6269
6270static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6271{
Johannes Berg4c476992010-10-04 21:36:35 +02006272 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006273 enum nl80211_ps_state ps_state;
6274 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006275 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006276 struct sk_buff *msg;
6277 void *hdr;
6278 int err;
6279
Kalle Valoffb9eb32010-02-17 17:58:10 +02006280 wdev = dev->ieee80211_ptr;
6281
Johannes Berg4c476992010-10-04 21:36:35 +02006282 if (!rdev->ops->set_power_mgmt)
6283 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006284
6285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006286 if (!msg)
6287 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006288
6289 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6290 NL80211_CMD_GET_POWER_SAVE);
6291 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006292 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006293 goto free_msg;
6294 }
6295
6296 if (wdev->ps)
6297 ps_state = NL80211_PS_ENABLED;
6298 else
6299 ps_state = NL80211_PS_DISABLED;
6300
David S. Miller9360ffd2012-03-29 04:41:26 -04006301 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6302 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006303
6304 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006305 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006306
Johannes Berg4c476992010-10-04 21:36:35 +02006307 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006308 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006309 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006310 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006311 return err;
6312}
6313
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006314static struct nla_policy
6315nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6316 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6317 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6318 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07006319 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6320 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6321 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006322};
6323
Thomas Pedersen84f10702012-07-12 16:17:33 -07006324static int nl80211_set_cqm_txe(struct genl_info *info,
6325 u32 rate, u32 pkts, u32 intvl)
6326{
6327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6328 struct wireless_dev *wdev;
6329 struct net_device *dev = info->user_ptr[1];
6330
6331 if ((rate < 0 || rate > 100) ||
6332 (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL))
6333 return -EINVAL;
6334
6335 wdev = dev->ieee80211_ptr;
6336
6337 if (!rdev->ops->set_cqm_txe_config)
6338 return -EOPNOTSUPP;
6339
6340 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6341 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6342 return -EOPNOTSUPP;
6343
6344 return rdev->ops->set_cqm_txe_config(wdev->wiphy, dev,
6345 rate, pkts, intvl);
6346}
6347
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006348static int nl80211_set_cqm_rssi(struct genl_info *info,
6349 s32 threshold, u32 hysteresis)
6350{
Johannes Berg4c476992010-10-04 21:36:35 +02006351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006352 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006353 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006354
6355 if (threshold > 0)
6356 return -EINVAL;
6357
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006358 wdev = dev->ieee80211_ptr;
6359
Johannes Berg4c476992010-10-04 21:36:35 +02006360 if (!rdev->ops->set_cqm_rssi_config)
6361 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006362
Johannes Berg074ac8d2010-09-16 14:58:22 +02006363 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006364 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6365 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006366
Johannes Berg4c476992010-10-04 21:36:35 +02006367 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6368 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006369}
6370
6371static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6372{
6373 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6374 struct nlattr *cqm;
6375 int err;
6376
6377 cqm = info->attrs[NL80211_ATTR_CQM];
6378 if (!cqm) {
6379 err = -EINVAL;
6380 goto out;
6381 }
6382
6383 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6384 nl80211_attr_cqm_policy);
6385 if (err)
6386 goto out;
6387
6388 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6389 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6390 s32 threshold;
6391 u32 hysteresis;
6392 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6393 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6394 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07006395 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
6396 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
6397 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
6398 u32 rate, pkts, intvl;
6399 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
6400 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
6401 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6402 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006403 } else
6404 err = -EINVAL;
6405
6406out:
6407 return err;
6408}
6409
Johannes Berg29cbe682010-12-03 09:20:44 +01006410static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6411{
6412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6413 struct net_device *dev = info->user_ptr[1];
6414 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006415 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006416 int err;
6417
6418 /* start with default */
6419 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006420 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006421
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006422 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006423 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006424 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006425 if (err)
6426 return err;
6427 }
6428
6429 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6430 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6431 return -EINVAL;
6432
Javier Cardonac80d5452010-12-16 17:37:49 -08006433 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6434 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6435
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006436 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6437 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6438 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6439 return -EINVAL;
6440
Javier Cardonac80d5452010-12-16 17:37:49 -08006441 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6442 /* parse additional setup parameters if given */
6443 err = nl80211_parse_mesh_setup(info, &setup);
6444 if (err)
6445 return err;
6446 }
6447
Johannes Bergcc1d2802012-05-16 23:50:20 +02006448 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6449 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6450
6451 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6452 !nl80211_valid_channel_type(info, &channel_type))
6453 return -EINVAL;
6454
6455 setup.channel = rdev_freq_to_chan(rdev,
6456 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6457 channel_type);
6458 if (!setup.channel)
6459 return -EINVAL;
6460 setup.channel_type = channel_type;
6461 } else {
6462 /* cfg80211_join_mesh() will sort it out */
6463 setup.channel = NULL;
6464 }
6465
Javier Cardonac80d5452010-12-16 17:37:49 -08006466 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006467}
6468
6469static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6470{
6471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6472 struct net_device *dev = info->user_ptr[1];
6473
6474 return cfg80211_leave_mesh(rdev, dev);
6475}
6476
Johannes Bergdfb89c52012-06-27 09:23:48 +02006477#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006478static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6479{
6480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6481 struct sk_buff *msg;
6482 void *hdr;
6483
6484 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6485 return -EOPNOTSUPP;
6486
6487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6488 if (!msg)
6489 return -ENOMEM;
6490
6491 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6492 NL80211_CMD_GET_WOWLAN);
6493 if (!hdr)
6494 goto nla_put_failure;
6495
6496 if (rdev->wowlan) {
6497 struct nlattr *nl_wowlan;
6498
6499 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6500 if (!nl_wowlan)
6501 goto nla_put_failure;
6502
David S. Miller9360ffd2012-03-29 04:41:26 -04006503 if ((rdev->wowlan->any &&
6504 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6505 (rdev->wowlan->disconnect &&
6506 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6507 (rdev->wowlan->magic_pkt &&
6508 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6509 (rdev->wowlan->gtk_rekey_failure &&
6510 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6511 (rdev->wowlan->eap_identity_req &&
6512 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6513 (rdev->wowlan->four_way_handshake &&
6514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6515 (rdev->wowlan->rfkill_release &&
6516 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6517 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006518 if (rdev->wowlan->n_patterns) {
6519 struct nlattr *nl_pats, *nl_pat;
6520 int i, pat_len;
6521
6522 nl_pats = nla_nest_start(msg,
6523 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6524 if (!nl_pats)
6525 goto nla_put_failure;
6526
6527 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6528 nl_pat = nla_nest_start(msg, i + 1);
6529 if (!nl_pat)
6530 goto nla_put_failure;
6531 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006532 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6533 DIV_ROUND_UP(pat_len, 8),
6534 rdev->wowlan->patterns[i].mask) ||
6535 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6536 pat_len,
6537 rdev->wowlan->patterns[i].pattern))
6538 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006539 nla_nest_end(msg, nl_pat);
6540 }
6541 nla_nest_end(msg, nl_pats);
6542 }
6543
6544 nla_nest_end(msg, nl_wowlan);
6545 }
6546
6547 genlmsg_end(msg, hdr);
6548 return genlmsg_reply(msg, info);
6549
6550nla_put_failure:
6551 nlmsg_free(msg);
6552 return -ENOBUFS;
6553}
6554
6555static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6556{
6557 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6558 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02006559 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02006560 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006561 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6562 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006563 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006564
6565 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6566 return -EOPNOTSUPP;
6567
Johannes Bergae33bd82012-07-12 16:25:02 +02006568 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
6569 cfg80211_rdev_free_wowlan(rdev);
6570 rdev->wowlan = NULL;
6571 goto set_wakeup;
6572 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02006573
6574 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6575 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6576 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6577 nl80211_wowlan_policy);
6578 if (err)
6579 return err;
6580
6581 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6582 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6583 return -EINVAL;
6584 new_triggers.any = true;
6585 }
6586
6587 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6588 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6589 return -EINVAL;
6590 new_triggers.disconnect = true;
6591 }
6592
6593 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6594 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6595 return -EINVAL;
6596 new_triggers.magic_pkt = true;
6597 }
6598
Johannes Berg77dbbb12011-07-13 10:48:55 +02006599 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6600 return -EINVAL;
6601
6602 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6603 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6604 return -EINVAL;
6605 new_triggers.gtk_rekey_failure = true;
6606 }
6607
6608 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6609 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6610 return -EINVAL;
6611 new_triggers.eap_identity_req = true;
6612 }
6613
6614 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6615 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6616 return -EINVAL;
6617 new_triggers.four_way_handshake = true;
6618 }
6619
6620 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6621 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6622 return -EINVAL;
6623 new_triggers.rfkill_release = true;
6624 }
6625
Johannes Bergff1b6e62011-05-04 15:37:28 +02006626 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6627 struct nlattr *pat;
6628 int n_patterns = 0;
6629 int rem, pat_len, mask_len;
6630 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6631
6632 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6633 rem)
6634 n_patterns++;
6635 if (n_patterns > wowlan->n_patterns)
6636 return -EINVAL;
6637
6638 new_triggers.patterns = kcalloc(n_patterns,
6639 sizeof(new_triggers.patterns[0]),
6640 GFP_KERNEL);
6641 if (!new_triggers.patterns)
6642 return -ENOMEM;
6643
6644 new_triggers.n_patterns = n_patterns;
6645 i = 0;
6646
6647 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6648 rem) {
6649 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6650 nla_data(pat), nla_len(pat), NULL);
6651 err = -EINVAL;
6652 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6653 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6654 goto error;
6655 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6656 mask_len = DIV_ROUND_UP(pat_len, 8);
6657 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6658 mask_len)
6659 goto error;
6660 if (pat_len > wowlan->pattern_max_len ||
6661 pat_len < wowlan->pattern_min_len)
6662 goto error;
6663
6664 new_triggers.patterns[i].mask =
6665 kmalloc(mask_len + pat_len, GFP_KERNEL);
6666 if (!new_triggers.patterns[i].mask) {
6667 err = -ENOMEM;
6668 goto error;
6669 }
6670 new_triggers.patterns[i].pattern =
6671 new_triggers.patterns[i].mask + mask_len;
6672 memcpy(new_triggers.patterns[i].mask,
6673 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6674 mask_len);
6675 new_triggers.patterns[i].pattern_len = pat_len;
6676 memcpy(new_triggers.patterns[i].pattern,
6677 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6678 pat_len);
6679 i++;
6680 }
6681 }
6682
Johannes Bergae33bd82012-07-12 16:25:02 +02006683 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
6684 if (!ntrig) {
6685 err = -ENOMEM;
6686 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006687 }
Johannes Bergae33bd82012-07-12 16:25:02 +02006688 cfg80211_rdev_free_wowlan(rdev);
6689 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006690
Johannes Bergae33bd82012-07-12 16:25:02 +02006691 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02006692 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6693 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6694
Johannes Bergff1b6e62011-05-04 15:37:28 +02006695 return 0;
6696 error:
6697 for (i = 0; i < new_triggers.n_patterns; i++)
6698 kfree(new_triggers.patterns[i].mask);
6699 kfree(new_triggers.patterns);
6700 return err;
6701}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006702#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006703
Johannes Berge5497d72011-07-05 16:35:40 +02006704static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6705{
6706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6707 struct net_device *dev = info->user_ptr[1];
6708 struct wireless_dev *wdev = dev->ieee80211_ptr;
6709 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6710 struct cfg80211_gtk_rekey_data rekey_data;
6711 int err;
6712
6713 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6714 return -EINVAL;
6715
6716 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6717 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6718 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6719 nl80211_rekey_policy);
6720 if (err)
6721 return err;
6722
6723 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6724 return -ERANGE;
6725 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6726 return -ERANGE;
6727 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6728 return -ERANGE;
6729
6730 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6731 NL80211_KEK_LEN);
6732 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6733 NL80211_KCK_LEN);
6734 memcpy(rekey_data.replay_ctr,
6735 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6736 NL80211_REPLAY_CTR_LEN);
6737
6738 wdev_lock(wdev);
6739 if (!wdev->current_bss) {
6740 err = -ENOTCONN;
6741 goto out;
6742 }
6743
6744 if (!rdev->ops->set_rekey_data) {
6745 err = -EOPNOTSUPP;
6746 goto out;
6747 }
6748
6749 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6750 out:
6751 wdev_unlock(wdev);
6752 return err;
6753}
6754
Johannes Berg28946da2011-11-04 11:18:12 +01006755static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6756 struct genl_info *info)
6757{
6758 struct net_device *dev = info->user_ptr[1];
6759 struct wireless_dev *wdev = dev->ieee80211_ptr;
6760
6761 if (wdev->iftype != NL80211_IFTYPE_AP &&
6762 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6763 return -EINVAL;
6764
6765 if (wdev->ap_unexpected_nlpid)
6766 return -EBUSY;
6767
6768 wdev->ap_unexpected_nlpid = info->snd_pid;
6769 return 0;
6770}
6771
Johannes Berg7f6cf312011-11-04 11:18:15 +01006772static int nl80211_probe_client(struct sk_buff *skb,
6773 struct genl_info *info)
6774{
6775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6776 struct net_device *dev = info->user_ptr[1];
6777 struct wireless_dev *wdev = dev->ieee80211_ptr;
6778 struct sk_buff *msg;
6779 void *hdr;
6780 const u8 *addr;
6781 u64 cookie;
6782 int err;
6783
6784 if (wdev->iftype != NL80211_IFTYPE_AP &&
6785 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6786 return -EOPNOTSUPP;
6787
6788 if (!info->attrs[NL80211_ATTR_MAC])
6789 return -EINVAL;
6790
6791 if (!rdev->ops->probe_client)
6792 return -EOPNOTSUPP;
6793
6794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6795 if (!msg)
6796 return -ENOMEM;
6797
6798 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6799 NL80211_CMD_PROBE_CLIENT);
6800
6801 if (IS_ERR(hdr)) {
6802 err = PTR_ERR(hdr);
6803 goto free_msg;
6804 }
6805
6806 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6807
6808 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6809 if (err)
6810 goto free_msg;
6811
David S. Miller9360ffd2012-03-29 04:41:26 -04006812 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6813 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006814
6815 genlmsg_end(msg, hdr);
6816
6817 return genlmsg_reply(msg, info);
6818
6819 nla_put_failure:
6820 err = -ENOBUFS;
6821 free_msg:
6822 nlmsg_free(msg);
6823 return err;
6824}
6825
Johannes Berg5e760232011-11-04 11:18:17 +01006826static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6827{
6828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6829
6830 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6831 return -EOPNOTSUPP;
6832
6833 if (rdev->ap_beacons_nlpid)
6834 return -EBUSY;
6835
6836 rdev->ap_beacons_nlpid = info->snd_pid;
6837
6838 return 0;
6839}
6840
Johannes Berg98104fde2012-06-16 00:19:54 +02006841static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
6842{
6843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6844 struct wireless_dev *wdev = info->user_ptr[1];
6845 int err;
6846
6847 if (!rdev->ops->start_p2p_device)
6848 return -EOPNOTSUPP;
6849
6850 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6851 return -EOPNOTSUPP;
6852
6853 if (wdev->p2p_started)
6854 return 0;
6855
6856 mutex_lock(&rdev->devlist_mtx);
6857 err = cfg80211_can_add_interface(rdev, wdev->iftype);
6858 mutex_unlock(&rdev->devlist_mtx);
6859 if (err)
6860 return err;
6861
6862 err = rdev->ops->start_p2p_device(&rdev->wiphy, wdev);
6863 if (err)
6864 return err;
6865
6866 wdev->p2p_started = true;
6867 mutex_lock(&rdev->devlist_mtx);
6868 rdev->opencount++;
6869 mutex_unlock(&rdev->devlist_mtx);
6870
6871 return 0;
6872}
6873
6874static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
6875{
6876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6877 struct wireless_dev *wdev = info->user_ptr[1];
6878
6879 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6880 return -EOPNOTSUPP;
6881
6882 if (!rdev->ops->stop_p2p_device)
6883 return -EOPNOTSUPP;
6884
6885 if (!wdev->p2p_started)
6886 return 0;
6887
6888 rdev->ops->stop_p2p_device(&rdev->wiphy, wdev);
6889 wdev->p2p_started = false;
6890
6891 mutex_lock(&rdev->devlist_mtx);
6892 rdev->opencount--;
6893 mutex_unlock(&rdev->devlist_mtx);
6894
6895 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
6896 rdev->scan_req->aborted = true;
6897 ___cfg80211_scan_done(rdev, true);
6898 }
6899
6900 return 0;
6901}
6902
Johannes Berg4c476992010-10-04 21:36:35 +02006903#define NL80211_FLAG_NEED_WIPHY 0x01
6904#define NL80211_FLAG_NEED_NETDEV 0x02
6905#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006906#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6907#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6908 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02006909#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02006910/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02006911#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6912 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006913
6914static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6915 struct genl_info *info)
6916{
6917 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02006918 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006919 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02006920 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6921
6922 if (rtnl)
6923 rtnl_lock();
6924
6925 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006926 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006927 if (IS_ERR(rdev)) {
6928 if (rtnl)
6929 rtnl_unlock();
6930 return PTR_ERR(rdev);
6931 }
6932 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02006933 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
6934 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02006935 mutex_lock(&cfg80211_mutex);
6936 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
6937 info->attrs);
6938 if (IS_ERR(wdev)) {
6939 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02006940 if (rtnl)
6941 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02006942 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006943 }
Johannes Berg89a54e42012-06-15 14:33:17 +02006944
Johannes Berg89a54e42012-06-15 14:33:17 +02006945 dev = wdev->netdev;
6946 rdev = wiphy_to_dev(wdev->wiphy);
6947
Johannes Berg1bf614e2012-06-15 15:23:36 +02006948 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
6949 if (!dev) {
6950 mutex_unlock(&cfg80211_mutex);
6951 if (rtnl)
6952 rtnl_unlock();
6953 return -EINVAL;
6954 }
6955
6956 info->user_ptr[1] = dev;
6957 } else {
6958 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02006959 }
Johannes Berg89a54e42012-06-15 14:33:17 +02006960
Johannes Berg1bf614e2012-06-15 15:23:36 +02006961 if (dev) {
6962 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6963 !netif_running(dev)) {
6964 mutex_unlock(&cfg80211_mutex);
6965 if (rtnl)
6966 rtnl_unlock();
6967 return -ENETDOWN;
6968 }
6969
6970 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02006971 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
6972 if (!wdev->p2p_started) {
6973 mutex_unlock(&cfg80211_mutex);
6974 if (rtnl)
6975 rtnl_unlock();
6976 return -ENETDOWN;
6977 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02006978 }
6979
Johannes Berg89a54e42012-06-15 14:33:17 +02006980 cfg80211_lock_rdev(rdev);
6981
6982 mutex_unlock(&cfg80211_mutex);
6983
Johannes Berg4c476992010-10-04 21:36:35 +02006984 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006985 }
6986
6987 return 0;
6988}
6989
6990static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6991 struct genl_info *info)
6992{
6993 if (info->user_ptr[0])
6994 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02006995 if (info->user_ptr[1]) {
6996 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
6997 struct wireless_dev *wdev = info->user_ptr[1];
6998
6999 if (wdev->netdev)
7000 dev_put(wdev->netdev);
7001 } else {
7002 dev_put(info->user_ptr[1]);
7003 }
7004 }
Johannes Berg4c476992010-10-04 21:36:35 +02007005 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7006 rtnl_unlock();
7007}
7008
Johannes Berg55682962007-09-20 13:09:35 -04007009static struct genl_ops nl80211_ops[] = {
7010 {
7011 .cmd = NL80211_CMD_GET_WIPHY,
7012 .doit = nl80211_get_wiphy,
7013 .dumpit = nl80211_dump_wiphy,
7014 .policy = nl80211_policy,
7015 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007016 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04007017 },
7018 {
7019 .cmd = NL80211_CMD_SET_WIPHY,
7020 .doit = nl80211_set_wiphy,
7021 .policy = nl80211_policy,
7022 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007023 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007024 },
7025 {
7026 .cmd = NL80211_CMD_GET_INTERFACE,
7027 .doit = nl80211_get_interface,
7028 .dumpit = nl80211_dump_interface,
7029 .policy = nl80211_policy,
7030 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02007031 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04007032 },
7033 {
7034 .cmd = NL80211_CMD_SET_INTERFACE,
7035 .doit = nl80211_set_interface,
7036 .policy = nl80211_policy,
7037 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007038 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7039 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007040 },
7041 {
7042 .cmd = NL80211_CMD_NEW_INTERFACE,
7043 .doit = nl80211_new_interface,
7044 .policy = nl80211_policy,
7045 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007046 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7047 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007048 },
7049 {
7050 .cmd = NL80211_CMD_DEL_INTERFACE,
7051 .doit = nl80211_del_interface,
7052 .policy = nl80211_policy,
7053 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02007054 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007055 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007056 },
Johannes Berg41ade002007-12-19 02:03:29 +01007057 {
7058 .cmd = NL80211_CMD_GET_KEY,
7059 .doit = nl80211_get_key,
7060 .policy = nl80211_policy,
7061 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007062 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007063 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007064 },
7065 {
7066 .cmd = NL80211_CMD_SET_KEY,
7067 .doit = nl80211_set_key,
7068 .policy = nl80211_policy,
7069 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007070 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007071 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007072 },
7073 {
7074 .cmd = NL80211_CMD_NEW_KEY,
7075 .doit = nl80211_new_key,
7076 .policy = nl80211_policy,
7077 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007078 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007079 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007080 },
7081 {
7082 .cmd = NL80211_CMD_DEL_KEY,
7083 .doit = nl80211_del_key,
7084 .policy = nl80211_policy,
7085 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007086 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007087 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007088 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01007089 {
7090 .cmd = NL80211_CMD_SET_BEACON,
7091 .policy = nl80211_policy,
7092 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007093 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007094 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007095 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007096 },
7097 {
Johannes Berg88600202012-02-13 15:17:18 +01007098 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007099 .policy = nl80211_policy,
7100 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007101 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007102 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007103 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007104 },
7105 {
Johannes Berg88600202012-02-13 15:17:18 +01007106 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007107 .policy = nl80211_policy,
7108 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007109 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007110 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007111 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007112 },
Johannes Berg5727ef12007-12-19 02:03:34 +01007113 {
7114 .cmd = NL80211_CMD_GET_STATION,
7115 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007116 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01007117 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02007118 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7119 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007120 },
7121 {
7122 .cmd = NL80211_CMD_SET_STATION,
7123 .doit = nl80211_set_station,
7124 .policy = nl80211_policy,
7125 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007126 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007127 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007128 },
7129 {
7130 .cmd = NL80211_CMD_NEW_STATION,
7131 .doit = nl80211_new_station,
7132 .policy = nl80211_policy,
7133 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007134 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007135 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007136 },
7137 {
7138 .cmd = NL80211_CMD_DEL_STATION,
7139 .doit = nl80211_del_station,
7140 .policy = nl80211_policy,
7141 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007142 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007143 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007144 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007145 {
7146 .cmd = NL80211_CMD_GET_MPATH,
7147 .doit = nl80211_get_mpath,
7148 .dumpit = nl80211_dump_mpath,
7149 .policy = nl80211_policy,
7150 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007152 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007153 },
7154 {
7155 .cmd = NL80211_CMD_SET_MPATH,
7156 .doit = nl80211_set_mpath,
7157 .policy = nl80211_policy,
7158 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007159 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007160 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007161 },
7162 {
7163 .cmd = NL80211_CMD_NEW_MPATH,
7164 .doit = nl80211_new_mpath,
7165 .policy = nl80211_policy,
7166 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007167 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007168 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007169 },
7170 {
7171 .cmd = NL80211_CMD_DEL_MPATH,
7172 .doit = nl80211_del_mpath,
7173 .policy = nl80211_policy,
7174 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007175 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007176 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007177 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007178 {
7179 .cmd = NL80211_CMD_SET_BSS,
7180 .doit = nl80211_set_bss,
7181 .policy = nl80211_policy,
7182 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007184 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007185 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007186 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007187 .cmd = NL80211_CMD_GET_REG,
7188 .doit = nl80211_get_reg,
7189 .policy = nl80211_policy,
7190 /* can be retrieved by unprivileged users */
7191 },
7192 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007193 .cmd = NL80211_CMD_SET_REG,
7194 .doit = nl80211_set_reg,
7195 .policy = nl80211_policy,
7196 .flags = GENL_ADMIN_PERM,
7197 },
7198 {
7199 .cmd = NL80211_CMD_REQ_SET_REG,
7200 .doit = nl80211_req_set_reg,
7201 .policy = nl80211_policy,
7202 .flags = GENL_ADMIN_PERM,
7203 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007204 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007205 .cmd = NL80211_CMD_GET_MESH_CONFIG,
7206 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007207 .policy = nl80211_policy,
7208 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007209 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007210 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007211 },
7212 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007213 .cmd = NL80211_CMD_SET_MESH_CONFIG,
7214 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007215 .policy = nl80211_policy,
7216 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01007217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007218 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007219 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02007220 {
Johannes Berg2a519312009-02-10 21:25:55 +01007221 .cmd = NL80211_CMD_TRIGGER_SCAN,
7222 .doit = nl80211_trigger_scan,
7223 .policy = nl80211_policy,
7224 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02007225 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007226 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01007227 },
7228 {
7229 .cmd = NL80211_CMD_GET_SCAN,
7230 .policy = nl80211_policy,
7231 .dumpit = nl80211_dump_scan,
7232 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02007233 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007234 .cmd = NL80211_CMD_START_SCHED_SCAN,
7235 .doit = nl80211_start_sched_scan,
7236 .policy = nl80211_policy,
7237 .flags = GENL_ADMIN_PERM,
7238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7239 NL80211_FLAG_NEED_RTNL,
7240 },
7241 {
7242 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
7243 .doit = nl80211_stop_sched_scan,
7244 .policy = nl80211_policy,
7245 .flags = GENL_ADMIN_PERM,
7246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7247 NL80211_FLAG_NEED_RTNL,
7248 },
7249 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02007250 .cmd = NL80211_CMD_AUTHENTICATE,
7251 .doit = nl80211_authenticate,
7252 .policy = nl80211_policy,
7253 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007254 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007255 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007256 },
7257 {
7258 .cmd = NL80211_CMD_ASSOCIATE,
7259 .doit = nl80211_associate,
7260 .policy = nl80211_policy,
7261 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007262 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007263 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007264 },
7265 {
7266 .cmd = NL80211_CMD_DEAUTHENTICATE,
7267 .doit = nl80211_deauthenticate,
7268 .policy = nl80211_policy,
7269 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007270 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007271 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007272 },
7273 {
7274 .cmd = NL80211_CMD_DISASSOCIATE,
7275 .doit = nl80211_disassociate,
7276 .policy = nl80211_policy,
7277 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007278 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007279 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007280 },
Johannes Berg04a773a2009-04-19 21:24:32 +02007281 {
7282 .cmd = NL80211_CMD_JOIN_IBSS,
7283 .doit = nl80211_join_ibss,
7284 .policy = nl80211_policy,
7285 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007286 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007287 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007288 },
7289 {
7290 .cmd = NL80211_CMD_LEAVE_IBSS,
7291 .doit = nl80211_leave_ibss,
7292 .policy = nl80211_policy,
7293 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007295 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007296 },
Johannes Bergaff89a92009-07-01 21:26:51 +02007297#ifdef CONFIG_NL80211_TESTMODE
7298 {
7299 .cmd = NL80211_CMD_TESTMODE,
7300 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007301 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02007302 .policy = nl80211_policy,
7303 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007304 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7305 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007306 },
7307#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007308 {
7309 .cmd = NL80211_CMD_CONNECT,
7310 .doit = nl80211_connect,
7311 .policy = nl80211_policy,
7312 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007313 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007314 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007315 },
7316 {
7317 .cmd = NL80211_CMD_DISCONNECT,
7318 .doit = nl80211_disconnect,
7319 .policy = nl80211_policy,
7320 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007321 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007322 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007323 },
Johannes Berg463d0182009-07-14 00:33:35 +02007324 {
7325 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7326 .doit = nl80211_wiphy_netns,
7327 .policy = nl80211_policy,
7328 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007329 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7330 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007331 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007332 {
7333 .cmd = NL80211_CMD_GET_SURVEY,
7334 .policy = nl80211_policy,
7335 .dumpit = nl80211_dump_survey,
7336 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007337 {
7338 .cmd = NL80211_CMD_SET_PMKSA,
7339 .doit = nl80211_setdel_pmksa,
7340 .policy = nl80211_policy,
7341 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007342 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007343 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007344 },
7345 {
7346 .cmd = NL80211_CMD_DEL_PMKSA,
7347 .doit = nl80211_setdel_pmksa,
7348 .policy = nl80211_policy,
7349 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007351 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007352 },
7353 {
7354 .cmd = NL80211_CMD_FLUSH_PMKSA,
7355 .doit = nl80211_flush_pmksa,
7356 .policy = nl80211_policy,
7357 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007359 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007360 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007361 {
7362 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7363 .doit = nl80211_remain_on_channel,
7364 .policy = nl80211_policy,
7365 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007366 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007367 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007368 },
7369 {
7370 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7371 .doit = nl80211_cancel_remain_on_channel,
7372 .policy = nl80211_policy,
7373 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007374 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007375 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007376 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007377 {
7378 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7379 .doit = nl80211_set_tx_bitrate_mask,
7380 .policy = nl80211_policy,
7381 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007382 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7383 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007384 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007385 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007386 .cmd = NL80211_CMD_REGISTER_FRAME,
7387 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007388 .policy = nl80211_policy,
7389 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007390 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007391 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007392 },
7393 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007394 .cmd = NL80211_CMD_FRAME,
7395 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007396 .policy = nl80211_policy,
7397 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007398 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007399 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007400 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007401 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007402 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7403 .doit = nl80211_tx_mgmt_cancel_wait,
7404 .policy = nl80211_policy,
7405 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007406 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007407 NL80211_FLAG_NEED_RTNL,
7408 },
7409 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007410 .cmd = NL80211_CMD_SET_POWER_SAVE,
7411 .doit = nl80211_set_power_save,
7412 .policy = nl80211_policy,
7413 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007414 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7415 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007416 },
7417 {
7418 .cmd = NL80211_CMD_GET_POWER_SAVE,
7419 .doit = nl80211_get_power_save,
7420 .policy = nl80211_policy,
7421 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007422 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7423 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007424 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007425 {
7426 .cmd = NL80211_CMD_SET_CQM,
7427 .doit = nl80211_set_cqm,
7428 .policy = nl80211_policy,
7429 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007430 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7431 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007432 },
Johannes Bergf444de02010-05-05 15:25:02 +02007433 {
7434 .cmd = NL80211_CMD_SET_CHANNEL,
7435 .doit = nl80211_set_channel,
7436 .policy = nl80211_policy,
7437 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007438 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7439 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007440 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007441 {
7442 .cmd = NL80211_CMD_SET_WDS_PEER,
7443 .doit = nl80211_set_wds_peer,
7444 .policy = nl80211_policy,
7445 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007446 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7447 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007448 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007449 {
7450 .cmd = NL80211_CMD_JOIN_MESH,
7451 .doit = nl80211_join_mesh,
7452 .policy = nl80211_policy,
7453 .flags = GENL_ADMIN_PERM,
7454 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7455 NL80211_FLAG_NEED_RTNL,
7456 },
7457 {
7458 .cmd = NL80211_CMD_LEAVE_MESH,
7459 .doit = nl80211_leave_mesh,
7460 .policy = nl80211_policy,
7461 .flags = GENL_ADMIN_PERM,
7462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7463 NL80211_FLAG_NEED_RTNL,
7464 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007465#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007466 {
7467 .cmd = NL80211_CMD_GET_WOWLAN,
7468 .doit = nl80211_get_wowlan,
7469 .policy = nl80211_policy,
7470 /* can be retrieved by unprivileged users */
7471 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7472 NL80211_FLAG_NEED_RTNL,
7473 },
7474 {
7475 .cmd = NL80211_CMD_SET_WOWLAN,
7476 .doit = nl80211_set_wowlan,
7477 .policy = nl80211_policy,
7478 .flags = GENL_ADMIN_PERM,
7479 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7480 NL80211_FLAG_NEED_RTNL,
7481 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007482#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007483 {
7484 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7485 .doit = nl80211_set_rekey_data,
7486 .policy = nl80211_policy,
7487 .flags = GENL_ADMIN_PERM,
7488 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7489 NL80211_FLAG_NEED_RTNL,
7490 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007491 {
7492 .cmd = NL80211_CMD_TDLS_MGMT,
7493 .doit = nl80211_tdls_mgmt,
7494 .policy = nl80211_policy,
7495 .flags = GENL_ADMIN_PERM,
7496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7497 NL80211_FLAG_NEED_RTNL,
7498 },
7499 {
7500 .cmd = NL80211_CMD_TDLS_OPER,
7501 .doit = nl80211_tdls_oper,
7502 .policy = nl80211_policy,
7503 .flags = GENL_ADMIN_PERM,
7504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7505 NL80211_FLAG_NEED_RTNL,
7506 },
Johannes Berg28946da2011-11-04 11:18:12 +01007507 {
7508 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7509 .doit = nl80211_register_unexpected_frame,
7510 .policy = nl80211_policy,
7511 .flags = GENL_ADMIN_PERM,
7512 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7513 NL80211_FLAG_NEED_RTNL,
7514 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007515 {
7516 .cmd = NL80211_CMD_PROBE_CLIENT,
7517 .doit = nl80211_probe_client,
7518 .policy = nl80211_policy,
7519 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007521 NL80211_FLAG_NEED_RTNL,
7522 },
Johannes Berg5e760232011-11-04 11:18:17 +01007523 {
7524 .cmd = NL80211_CMD_REGISTER_BEACONS,
7525 .doit = nl80211_register_beacons,
7526 .policy = nl80211_policy,
7527 .flags = GENL_ADMIN_PERM,
7528 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7529 NL80211_FLAG_NEED_RTNL,
7530 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007531 {
7532 .cmd = NL80211_CMD_SET_NOACK_MAP,
7533 .doit = nl80211_set_noack_map,
7534 .policy = nl80211_policy,
7535 .flags = GENL_ADMIN_PERM,
7536 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7537 NL80211_FLAG_NEED_RTNL,
7538 },
Johannes Berg98104fde2012-06-16 00:19:54 +02007539 {
7540 .cmd = NL80211_CMD_START_P2P_DEVICE,
7541 .doit = nl80211_start_p2p_device,
7542 .policy = nl80211_policy,
7543 .flags = GENL_ADMIN_PERM,
7544 .internal_flags = NL80211_FLAG_NEED_WDEV |
7545 NL80211_FLAG_NEED_RTNL,
7546 },
7547 {
7548 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
7549 .doit = nl80211_stop_p2p_device,
7550 .policy = nl80211_policy,
7551 .flags = GENL_ADMIN_PERM,
7552 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7553 NL80211_FLAG_NEED_RTNL,
7554 },
Johannes Berg55682962007-09-20 13:09:35 -04007555};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007556
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007557static struct genl_multicast_group nl80211_mlme_mcgrp = {
7558 .name = "mlme",
7559};
Johannes Berg55682962007-09-20 13:09:35 -04007560
7561/* multicast groups */
7562static struct genl_multicast_group nl80211_config_mcgrp = {
7563 .name = "config",
7564};
Johannes Berg2a519312009-02-10 21:25:55 +01007565static struct genl_multicast_group nl80211_scan_mcgrp = {
7566 .name = "scan",
7567};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007568static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7569 .name = "regulatory",
7570};
Johannes Berg55682962007-09-20 13:09:35 -04007571
7572/* notification functions */
7573
7574void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7575{
7576 struct sk_buff *msg;
7577
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007579 if (!msg)
7580 return;
7581
7582 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7583 nlmsg_free(msg);
7584 return;
7585 }
7586
Johannes Berg463d0182009-07-14 00:33:35 +02007587 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7588 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007589}
7590
Johannes Berg362a4152009-05-24 16:43:15 +02007591static int nl80211_add_scan_req(struct sk_buff *msg,
7592 struct cfg80211_registered_device *rdev)
7593{
7594 struct cfg80211_scan_request *req = rdev->scan_req;
7595 struct nlattr *nest;
7596 int i;
7597
Johannes Berg667503d2009-07-07 03:56:11 +02007598 ASSERT_RDEV_LOCK(rdev);
7599
Johannes Berg362a4152009-05-24 16:43:15 +02007600 if (WARN_ON(!req))
7601 return 0;
7602
7603 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7604 if (!nest)
7605 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007606 for (i = 0; i < req->n_ssids; i++) {
7607 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7608 goto nla_put_failure;
7609 }
Johannes Berg362a4152009-05-24 16:43:15 +02007610 nla_nest_end(msg, nest);
7611
7612 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7613 if (!nest)
7614 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007615 for (i = 0; i < req->n_channels; i++) {
7616 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7617 goto nla_put_failure;
7618 }
Johannes Berg362a4152009-05-24 16:43:15 +02007619 nla_nest_end(msg, nest);
7620
David S. Miller9360ffd2012-03-29 04:41:26 -04007621 if (req->ie &&
7622 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7623 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007624
7625 return 0;
7626 nla_put_failure:
7627 return -ENOBUFS;
7628}
7629
Johannes Berga538e2d2009-06-16 19:56:42 +02007630static int nl80211_send_scan_msg(struct sk_buff *msg,
7631 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007632 struct wireless_dev *wdev,
Johannes Berga538e2d2009-06-16 19:56:42 +02007633 u32 pid, u32 seq, int flags,
7634 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007635{
7636 void *hdr;
7637
7638 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7639 if (!hdr)
7640 return -1;
7641
David S. Miller9360ffd2012-03-29 04:41:26 -04007642 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02007643 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
7644 wdev->netdev->ifindex)) ||
7645 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007646 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007647
Johannes Berg362a4152009-05-24 16:43:15 +02007648 /* ignore errors and send incomplete event anyway */
7649 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007650
7651 return genlmsg_end(msg, hdr);
7652
7653 nla_put_failure:
7654 genlmsg_cancel(msg, hdr);
7655 return -EMSGSIZE;
7656}
7657
Luciano Coelho807f8a82011-05-11 17:09:35 +03007658static int
7659nl80211_send_sched_scan_msg(struct sk_buff *msg,
7660 struct cfg80211_registered_device *rdev,
7661 struct net_device *netdev,
7662 u32 pid, u32 seq, int flags, u32 cmd)
7663{
7664 void *hdr;
7665
7666 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7667 if (!hdr)
7668 return -1;
7669
David S. Miller9360ffd2012-03-29 04:41:26 -04007670 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7671 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7672 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007673
7674 return genlmsg_end(msg, hdr);
7675
7676 nla_put_failure:
7677 genlmsg_cancel(msg, hdr);
7678 return -EMSGSIZE;
7679}
7680
Johannes Berga538e2d2009-06-16 19:56:42 +02007681void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007682 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02007683{
7684 struct sk_buff *msg;
7685
Thomas Graf58050fc2012-06-28 03:57:45 +00007686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007687 if (!msg)
7688 return;
7689
Johannes Bergfd014282012-06-18 19:17:03 +02007690 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007691 NL80211_CMD_TRIGGER_SCAN) < 0) {
7692 nlmsg_free(msg);
7693 return;
7694 }
7695
Johannes Berg463d0182009-07-14 00:33:35 +02007696 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7697 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007698}
7699
Johannes Berg2a519312009-02-10 21:25:55 +01007700void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007701 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007702{
7703 struct sk_buff *msg;
7704
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007705 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007706 if (!msg)
7707 return;
7708
Johannes Bergfd014282012-06-18 19:17:03 +02007709 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007710 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007711 nlmsg_free(msg);
7712 return;
7713 }
7714
Johannes Berg463d0182009-07-14 00:33:35 +02007715 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7716 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007717}
7718
7719void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007720 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007721{
7722 struct sk_buff *msg;
7723
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007725 if (!msg)
7726 return;
7727
Johannes Bergfd014282012-06-18 19:17:03 +02007728 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007729 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007730 nlmsg_free(msg);
7731 return;
7732 }
7733
Johannes Berg463d0182009-07-14 00:33:35 +02007734 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7735 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007736}
7737
Luciano Coelho807f8a82011-05-11 17:09:35 +03007738void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7739 struct net_device *netdev)
7740{
7741 struct sk_buff *msg;
7742
7743 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7744 if (!msg)
7745 return;
7746
7747 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7748 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7749 nlmsg_free(msg);
7750 return;
7751 }
7752
7753 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7754 nl80211_scan_mcgrp.id, GFP_KERNEL);
7755}
7756
7757void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7758 struct net_device *netdev, u32 cmd)
7759{
7760 struct sk_buff *msg;
7761
Thomas Graf58050fc2012-06-28 03:57:45 +00007762 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007763 if (!msg)
7764 return;
7765
7766 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7767 nlmsg_free(msg);
7768 return;
7769 }
7770
7771 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7772 nl80211_scan_mcgrp.id, GFP_KERNEL);
7773}
7774
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007775/*
7776 * This can happen on global regulatory changes or device specific settings
7777 * based on custom world regulatory domains.
7778 */
7779void nl80211_send_reg_change_event(struct regulatory_request *request)
7780{
7781 struct sk_buff *msg;
7782 void *hdr;
7783
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007784 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007785 if (!msg)
7786 return;
7787
7788 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7789 if (!hdr) {
7790 nlmsg_free(msg);
7791 return;
7792 }
7793
7794 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007795 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7796 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007797
David S. Miller9360ffd2012-03-29 04:41:26 -04007798 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7799 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7800 NL80211_REGDOM_TYPE_WORLD))
7801 goto nla_put_failure;
7802 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7803 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7804 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7805 goto nla_put_failure;
7806 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7807 request->intersect) {
7808 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7809 NL80211_REGDOM_TYPE_INTERSECTION))
7810 goto nla_put_failure;
7811 } else {
7812 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7813 NL80211_REGDOM_TYPE_COUNTRY) ||
7814 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7815 request->alpha2))
7816 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007817 }
7818
David S. Miller9360ffd2012-03-29 04:41:26 -04007819 if (wiphy_idx_valid(request->wiphy_idx) &&
7820 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7821 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007822
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007823 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007824
Johannes Bergbc43b282009-07-25 10:54:13 +02007825 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007826 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007827 GFP_ATOMIC);
7828 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007829
7830 return;
7831
7832nla_put_failure:
7833 genlmsg_cancel(msg, hdr);
7834 nlmsg_free(msg);
7835}
7836
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007837static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7838 struct net_device *netdev,
7839 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007840 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007841{
7842 struct sk_buff *msg;
7843 void *hdr;
7844
Johannes Berge6d6e342009-07-01 21:26:47 +02007845 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007846 if (!msg)
7847 return;
7848
7849 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7850 if (!hdr) {
7851 nlmsg_free(msg);
7852 return;
7853 }
7854
David S. Miller9360ffd2012-03-29 04:41:26 -04007855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7857 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7858 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007859
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007860 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007861
Johannes Berg463d0182009-07-14 00:33:35 +02007862 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7863 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007864 return;
7865
7866 nla_put_failure:
7867 genlmsg_cancel(msg, hdr);
7868 nlmsg_free(msg);
7869}
7870
7871void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007872 struct net_device *netdev, const u8 *buf,
7873 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007874{
7875 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007876 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007877}
7878
7879void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7880 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007881 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007882{
Johannes Berge6d6e342009-07-01 21:26:47 +02007883 nl80211_send_mlme_event(rdev, netdev, buf, len,
7884 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007885}
7886
Jouni Malinen53b46b82009-03-27 20:53:56 +02007887void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007888 struct net_device *netdev, const u8 *buf,
7889 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007890{
7891 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007892 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007893}
7894
Jouni Malinen53b46b82009-03-27 20:53:56 +02007895void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7896 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007897 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007898{
7899 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007900 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007901}
7902
Jouni Malinencf4e5942010-12-16 00:52:40 +02007903void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7904 struct net_device *netdev, const u8 *buf,
7905 size_t len, gfp_t gfp)
7906{
7907 nl80211_send_mlme_event(rdev, netdev, buf, len,
7908 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7909}
7910
7911void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7912 struct net_device *netdev, const u8 *buf,
7913 size_t len, gfp_t gfp)
7914{
7915 nl80211_send_mlme_event(rdev, netdev, buf, len,
7916 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7917}
7918
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007919static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7920 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007921 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007922{
7923 struct sk_buff *msg;
7924 void *hdr;
7925
Johannes Berge6d6e342009-07-01 21:26:47 +02007926 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007927 if (!msg)
7928 return;
7929
7930 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7931 if (!hdr) {
7932 nlmsg_free(msg);
7933 return;
7934 }
7935
David S. Miller9360ffd2012-03-29 04:41:26 -04007936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7937 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7938 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7939 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7940 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007941
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007942 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007943
Johannes Berg463d0182009-07-14 00:33:35 +02007944 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7945 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007946 return;
7947
7948 nla_put_failure:
7949 genlmsg_cancel(msg, hdr);
7950 nlmsg_free(msg);
7951}
7952
7953void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007954 struct net_device *netdev, const u8 *addr,
7955 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007956{
7957 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007958 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007959}
7960
7961void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007962 struct net_device *netdev, const u8 *addr,
7963 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007964{
Johannes Berge6d6e342009-07-01 21:26:47 +02007965 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7966 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007967}
7968
Samuel Ortizb23aa672009-07-01 21:26:54 +02007969void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7970 struct net_device *netdev, const u8 *bssid,
7971 const u8 *req_ie, size_t req_ie_len,
7972 const u8 *resp_ie, size_t resp_ie_len,
7973 u16 status, gfp_t gfp)
7974{
7975 struct sk_buff *msg;
7976 void *hdr;
7977
Thomas Graf58050fc2012-06-28 03:57:45 +00007978 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007979 if (!msg)
7980 return;
7981
7982 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7983 if (!hdr) {
7984 nlmsg_free(msg);
7985 return;
7986 }
7987
David S. Miller9360ffd2012-03-29 04:41:26 -04007988 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7989 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7990 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7991 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7992 (req_ie &&
7993 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7994 (resp_ie &&
7995 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7996 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007997
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007998 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007999
Johannes Berg463d0182009-07-14 00:33:35 +02008000 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8001 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008002 return;
8003
8004 nla_put_failure:
8005 genlmsg_cancel(msg, hdr);
8006 nlmsg_free(msg);
8007
8008}
8009
8010void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8011 struct net_device *netdev, const u8 *bssid,
8012 const u8 *req_ie, size_t req_ie_len,
8013 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8014{
8015 struct sk_buff *msg;
8016 void *hdr;
8017
Thomas Graf58050fc2012-06-28 03:57:45 +00008018 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008019 if (!msg)
8020 return;
8021
8022 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8023 if (!hdr) {
8024 nlmsg_free(msg);
8025 return;
8026 }
8027
David S. Miller9360ffd2012-03-29 04:41:26 -04008028 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8029 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8030 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8031 (req_ie &&
8032 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8033 (resp_ie &&
8034 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8035 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008036
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008037 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008038
Johannes Berg463d0182009-07-14 00:33:35 +02008039 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8040 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008041 return;
8042
8043 nla_put_failure:
8044 genlmsg_cancel(msg, hdr);
8045 nlmsg_free(msg);
8046
8047}
8048
8049void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8050 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02008051 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008052{
8053 struct sk_buff *msg;
8054 void *hdr;
8055
Thomas Graf58050fc2012-06-28 03:57:45 +00008056 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008057 if (!msg)
8058 return;
8059
8060 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8061 if (!hdr) {
8062 nlmsg_free(msg);
8063 return;
8064 }
8065
David S. Miller9360ffd2012-03-29 04:41:26 -04008066 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8067 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8068 (from_ap && reason &&
8069 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8070 (from_ap &&
8071 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8072 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8073 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008074
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008075 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008076
Johannes Berg463d0182009-07-14 00:33:35 +02008077 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8078 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008079 return;
8080
8081 nla_put_failure:
8082 genlmsg_cancel(msg, hdr);
8083 nlmsg_free(msg);
8084
8085}
8086
Johannes Berg04a773a2009-04-19 21:24:32 +02008087void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8088 struct net_device *netdev, const u8 *bssid,
8089 gfp_t gfp)
8090{
8091 struct sk_buff *msg;
8092 void *hdr;
8093
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008094 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008095 if (!msg)
8096 return;
8097
8098 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
8099 if (!hdr) {
8100 nlmsg_free(msg);
8101 return;
8102 }
8103
David S. Miller9360ffd2012-03-29 04:41:26 -04008104 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8105 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8106 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8107 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02008108
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008109 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02008110
Johannes Berg463d0182009-07-14 00:33:35 +02008111 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8112 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008113 return;
8114
8115 nla_put_failure:
8116 genlmsg_cancel(msg, hdr);
8117 nlmsg_free(msg);
8118}
8119
Javier Cardonac93b5e72011-04-07 15:08:34 -07008120void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
8121 struct net_device *netdev,
8122 const u8 *macaddr, const u8* ie, u8 ie_len,
8123 gfp_t gfp)
8124{
8125 struct sk_buff *msg;
8126 void *hdr;
8127
8128 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8129 if (!msg)
8130 return;
8131
8132 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
8133 if (!hdr) {
8134 nlmsg_free(msg);
8135 return;
8136 }
8137
David S. Miller9360ffd2012-03-29 04:41:26 -04008138 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8139 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8140 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
8141 (ie_len && ie &&
8142 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8143 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07008144
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008145 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07008146
8147 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8148 nl80211_mlme_mcgrp.id, gfp);
8149 return;
8150
8151 nla_put_failure:
8152 genlmsg_cancel(msg, hdr);
8153 nlmsg_free(msg);
8154}
8155
Jouni Malinena3b8b052009-03-27 21:59:49 +02008156void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
8157 struct net_device *netdev, const u8 *addr,
8158 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02008159 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02008160{
8161 struct sk_buff *msg;
8162 void *hdr;
8163
Johannes Berge6d6e342009-07-01 21:26:47 +02008164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008165 if (!msg)
8166 return;
8167
8168 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
8169 if (!hdr) {
8170 nlmsg_free(msg);
8171 return;
8172 }
8173
David S. Miller9360ffd2012-03-29 04:41:26 -04008174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8176 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
8177 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
8178 (key_id != -1 &&
8179 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
8180 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
8181 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02008182
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008183 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008184
Johannes Berg463d0182009-07-14 00:33:35 +02008185 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8186 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008187 return;
8188
8189 nla_put_failure:
8190 genlmsg_cancel(msg, hdr);
8191 nlmsg_free(msg);
8192}
8193
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008194void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
8195 struct ieee80211_channel *channel_before,
8196 struct ieee80211_channel *channel_after)
8197{
8198 struct sk_buff *msg;
8199 void *hdr;
8200 struct nlattr *nl_freq;
8201
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008203 if (!msg)
8204 return;
8205
8206 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
8207 if (!hdr) {
8208 nlmsg_free(msg);
8209 return;
8210 }
8211
8212 /*
8213 * Since we are applying the beacon hint to a wiphy we know its
8214 * wiphy_idx is valid
8215 */
David S. Miller9360ffd2012-03-29 04:41:26 -04008216 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8217 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008218
8219 /* Before */
8220 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
8221 if (!nl_freq)
8222 goto nla_put_failure;
8223 if (nl80211_msg_put_channel(msg, channel_before))
8224 goto nla_put_failure;
8225 nla_nest_end(msg, nl_freq);
8226
8227 /* After */
8228 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
8229 if (!nl_freq)
8230 goto nla_put_failure;
8231 if (nl80211_msg_put_channel(msg, channel_after))
8232 goto nla_put_failure;
8233 nla_nest_end(msg, nl_freq);
8234
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008235 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008236
Johannes Berg463d0182009-07-14 00:33:35 +02008237 rcu_read_lock();
8238 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8239 GFP_ATOMIC);
8240 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008241
8242 return;
8243
8244nla_put_failure:
8245 genlmsg_cancel(msg, hdr);
8246 nlmsg_free(msg);
8247}
8248
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008249static void nl80211_send_remain_on_chan_event(
8250 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008251 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008252 struct ieee80211_channel *chan,
8253 enum nl80211_channel_type channel_type,
8254 unsigned int duration, gfp_t gfp)
8255{
8256 struct sk_buff *msg;
8257 void *hdr;
8258
8259 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8260 if (!msg)
8261 return;
8262
8263 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8264 if (!hdr) {
8265 nlmsg_free(msg);
8266 return;
8267 }
8268
David S. Miller9360ffd2012-03-29 04:41:26 -04008269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008270 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8271 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02008272 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008273 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
8274 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
8275 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8276 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008277
David S. Miller9360ffd2012-03-29 04:41:26 -04008278 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
8279 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
8280 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008281
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008282 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008283
8284 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8285 nl80211_mlme_mcgrp.id, gfp);
8286 return;
8287
8288 nla_put_failure:
8289 genlmsg_cancel(msg, hdr);
8290 nlmsg_free(msg);
8291}
8292
8293void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008294 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008295 struct ieee80211_channel *chan,
8296 enum nl80211_channel_type channel_type,
8297 unsigned int duration, gfp_t gfp)
8298{
8299 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008300 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008301 channel_type, duration, gfp);
8302}
8303
8304void nl80211_send_remain_on_channel_cancel(
Johannes Berg71bbc992012-06-15 15:30:18 +02008305 struct cfg80211_registered_device *rdev,
8306 struct wireless_dev *wdev,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008307 u64 cookie, struct ieee80211_channel *chan,
8308 enum nl80211_channel_type channel_type, gfp_t gfp)
8309{
8310 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008311 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008312 channel_type, 0, gfp);
8313}
8314
Johannes Berg98b62182009-12-23 13:15:44 +01008315void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
8316 struct net_device *dev, const u8 *mac_addr,
8317 struct station_info *sinfo, gfp_t gfp)
8318{
8319 struct sk_buff *msg;
8320
Thomas Graf58050fc2012-06-28 03:57:45 +00008321 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01008322 if (!msg)
8323 return;
8324
John W. Linville66266b32012-03-15 13:25:41 -04008325 if (nl80211_send_station(msg, 0, 0, 0,
8326 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008327 nlmsg_free(msg);
8328 return;
8329 }
8330
8331 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8332 nl80211_mlme_mcgrp.id, gfp);
8333}
8334
Jouni Malinenec15e682011-03-23 15:29:52 +02008335void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8336 struct net_device *dev, const u8 *mac_addr,
8337 gfp_t gfp)
8338{
8339 struct sk_buff *msg;
8340 void *hdr;
8341
Thomas Graf58050fc2012-06-28 03:57:45 +00008342 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02008343 if (!msg)
8344 return;
8345
8346 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8347 if (!hdr) {
8348 nlmsg_free(msg);
8349 return;
8350 }
8351
David S. Miller9360ffd2012-03-29 04:41:26 -04008352 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8353 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8354 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008355
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008356 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008357
8358 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8359 nl80211_mlme_mcgrp.id, gfp);
8360 return;
8361
8362 nla_put_failure:
8363 genlmsg_cancel(msg, hdr);
8364 nlmsg_free(msg);
8365}
8366
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05308367void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
8368 struct net_device *dev, const u8 *mac_addr,
8369 enum nl80211_connect_failed_reason reason,
8370 gfp_t gfp)
8371{
8372 struct sk_buff *msg;
8373 void *hdr;
8374
8375 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8376 if (!msg)
8377 return;
8378
8379 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
8380 if (!hdr) {
8381 nlmsg_free(msg);
8382 return;
8383 }
8384
8385 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8386 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
8387 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
8388 goto nla_put_failure;
8389
8390 genlmsg_end(msg, hdr);
8391
8392 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8393 nl80211_mlme_mcgrp.id, gfp);
8394 return;
8395
8396 nla_put_failure:
8397 genlmsg_cancel(msg, hdr);
8398 nlmsg_free(msg);
8399}
8400
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008401static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8402 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008403{
8404 struct wireless_dev *wdev = dev->ieee80211_ptr;
8405 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8406 struct sk_buff *msg;
8407 void *hdr;
8408 int err;
8409 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8410
8411 if (!nlpid)
8412 return false;
8413
8414 msg = nlmsg_new(100, gfp);
8415 if (!msg)
8416 return true;
8417
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008418 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008419 if (!hdr) {
8420 nlmsg_free(msg);
8421 return true;
8422 }
8423
David S. Miller9360ffd2012-03-29 04:41:26 -04008424 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8426 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8427 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008428
8429 err = genlmsg_end(msg, hdr);
8430 if (err < 0) {
8431 nlmsg_free(msg);
8432 return true;
8433 }
8434
8435 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8436 return true;
8437
8438 nla_put_failure:
8439 genlmsg_cancel(msg, hdr);
8440 nlmsg_free(msg);
8441 return true;
8442}
8443
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008444bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8445{
8446 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8447 addr, gfp);
8448}
8449
8450bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8451 const u8 *addr, gfp_t gfp)
8452{
8453 return __nl80211_unexpected_frame(dev,
8454 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8455 addr, gfp);
8456}
8457
Johannes Berg2e161f72010-08-12 15:38:38 +02008458int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008459 struct wireless_dev *wdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008460 int freq, int sig_dbm,
8461 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008462{
Johannes Berg71bbc992012-06-15 15:30:18 +02008463 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008464 struct sk_buff *msg;
8465 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008466
8467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8468 if (!msg)
8469 return -ENOMEM;
8470
Johannes Berg2e161f72010-08-12 15:38:38 +02008471 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008472 if (!hdr) {
8473 nlmsg_free(msg);
8474 return -ENOMEM;
8475 }
8476
David S. Miller9360ffd2012-03-29 04:41:26 -04008477 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008478 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8479 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008480 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8481 (sig_dbm &&
8482 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8483 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8484 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008485
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008486 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008487
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008488 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008489
8490 nla_put_failure:
8491 genlmsg_cancel(msg, hdr);
8492 nlmsg_free(msg);
8493 return -ENOBUFS;
8494}
8495
Johannes Berg2e161f72010-08-12 15:38:38 +02008496void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008497 struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +02008498 const u8 *buf, size_t len, bool ack,
8499 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008500{
Johannes Berg71bbc992012-06-15 15:30:18 +02008501 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008502 struct sk_buff *msg;
8503 void *hdr;
8504
8505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8506 if (!msg)
8507 return;
8508
Johannes Berg2e161f72010-08-12 15:38:38 +02008509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008510 if (!hdr) {
8511 nlmsg_free(msg);
8512 return;
8513 }
8514
David S. Miller9360ffd2012-03-29 04:41:26 -04008515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008516 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8517 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008518 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8519 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8520 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8521 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008522
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008523 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008524
8525 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8526 return;
8527
8528 nla_put_failure:
8529 genlmsg_cancel(msg, hdr);
8530 nlmsg_free(msg);
8531}
8532
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008533void
8534nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8535 struct net_device *netdev,
8536 enum nl80211_cqm_rssi_threshold_event rssi_event,
8537 gfp_t gfp)
8538{
8539 struct sk_buff *msg;
8540 struct nlattr *pinfoattr;
8541 void *hdr;
8542
Thomas Graf58050fc2012-06-28 03:57:45 +00008543 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008544 if (!msg)
8545 return;
8546
8547 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8548 if (!hdr) {
8549 nlmsg_free(msg);
8550 return;
8551 }
8552
David S. Miller9360ffd2012-03-29 04:41:26 -04008553 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8554 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8555 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008556
8557 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8558 if (!pinfoattr)
8559 goto nla_put_failure;
8560
David S. Miller9360ffd2012-03-29 04:41:26 -04008561 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8562 rssi_event))
8563 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008564
8565 nla_nest_end(msg, pinfoattr);
8566
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008567 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008568
8569 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8570 nl80211_mlme_mcgrp.id, gfp);
8571 return;
8572
8573 nla_put_failure:
8574 genlmsg_cancel(msg, hdr);
8575 nlmsg_free(msg);
8576}
8577
Johannes Berge5497d72011-07-05 16:35:40 +02008578void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8579 struct net_device *netdev, const u8 *bssid,
8580 const u8 *replay_ctr, gfp_t gfp)
8581{
8582 struct sk_buff *msg;
8583 struct nlattr *rekey_attr;
8584 void *hdr;
8585
Thomas Graf58050fc2012-06-28 03:57:45 +00008586 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02008587 if (!msg)
8588 return;
8589
8590 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8591 if (!hdr) {
8592 nlmsg_free(msg);
8593 return;
8594 }
8595
David S. Miller9360ffd2012-03-29 04:41:26 -04008596 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8597 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8598 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8599 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008600
8601 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8602 if (!rekey_attr)
8603 goto nla_put_failure;
8604
David S. Miller9360ffd2012-03-29 04:41:26 -04008605 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8606 NL80211_REPLAY_CTR_LEN, replay_ctr))
8607 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008608
8609 nla_nest_end(msg, rekey_attr);
8610
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008611 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008612
8613 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8614 nl80211_mlme_mcgrp.id, gfp);
8615 return;
8616
8617 nla_put_failure:
8618 genlmsg_cancel(msg, hdr);
8619 nlmsg_free(msg);
8620}
8621
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008622void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8623 struct net_device *netdev, int index,
8624 const u8 *bssid, bool preauth, gfp_t gfp)
8625{
8626 struct sk_buff *msg;
8627 struct nlattr *attr;
8628 void *hdr;
8629
Thomas Graf58050fc2012-06-28 03:57:45 +00008630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008631 if (!msg)
8632 return;
8633
8634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8635 if (!hdr) {
8636 nlmsg_free(msg);
8637 return;
8638 }
8639
David S. Miller9360ffd2012-03-29 04:41:26 -04008640 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8641 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8642 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008643
8644 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8645 if (!attr)
8646 goto nla_put_failure;
8647
David S. Miller9360ffd2012-03-29 04:41:26 -04008648 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8649 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8650 (preauth &&
8651 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8652 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008653
8654 nla_nest_end(msg, attr);
8655
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008656 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008657
8658 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8659 nl80211_mlme_mcgrp.id, gfp);
8660 return;
8661
8662 nla_put_failure:
8663 genlmsg_cancel(msg, hdr);
8664 nlmsg_free(msg);
8665}
8666
Thomas Pedersen53145262012-04-06 13:35:47 -07008667void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8668 struct net_device *netdev, int freq,
8669 enum nl80211_channel_type type, gfp_t gfp)
8670{
8671 struct sk_buff *msg;
8672 void *hdr;
8673
Thomas Graf58050fc2012-06-28 03:57:45 +00008674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -07008675 if (!msg)
8676 return;
8677
8678 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8679 if (!hdr) {
8680 nlmsg_free(msg);
8681 return;
8682 }
8683
John W. Linville7eab0f62012-04-12 14:25:14 -04008684 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8685 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8686 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8687 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008688
8689 genlmsg_end(msg, hdr);
8690
8691 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8692 nl80211_mlme_mcgrp.id, gfp);
8693 return;
8694
8695 nla_put_failure:
8696 genlmsg_cancel(msg, hdr);
8697 nlmsg_free(msg);
8698}
8699
Johannes Bergc063dbf2010-11-24 08:10:05 +01008700void
Thomas Pedersen84f10702012-07-12 16:17:33 -07008701nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
8702 struct net_device *netdev, const u8 *peer,
8703 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
8704{
8705 struct sk_buff *msg;
8706 struct nlattr *pinfoattr;
8707 void *hdr;
8708
8709 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8710 if (!msg)
8711 return;
8712
8713 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8714 if (!hdr) {
8715 nlmsg_free(msg);
8716 return;
8717 }
8718
8719 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8720 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8721 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8722 goto nla_put_failure;
8723
8724 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8725 if (!pinfoattr)
8726 goto nla_put_failure;
8727
8728 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
8729 goto nla_put_failure;
8730
8731 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
8732 goto nla_put_failure;
8733
8734 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
8735 goto nla_put_failure;
8736
8737 nla_nest_end(msg, pinfoattr);
8738
8739 genlmsg_end(msg, hdr);
8740
8741 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8742 nl80211_mlme_mcgrp.id, gfp);
8743 return;
8744
8745 nla_put_failure:
8746 genlmsg_cancel(msg, hdr);
8747 nlmsg_free(msg);
8748}
8749
8750void
Johannes Bergc063dbf2010-11-24 08:10:05 +01008751nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8752 struct net_device *netdev, const u8 *peer,
8753 u32 num_packets, gfp_t gfp)
8754{
8755 struct sk_buff *msg;
8756 struct nlattr *pinfoattr;
8757 void *hdr;
8758
Thomas Graf58050fc2012-06-28 03:57:45 +00008759 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008760 if (!msg)
8761 return;
8762
8763 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8764 if (!hdr) {
8765 nlmsg_free(msg);
8766 return;
8767 }
8768
David S. Miller9360ffd2012-03-29 04:41:26 -04008769 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8770 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8771 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8772 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008773
8774 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8775 if (!pinfoattr)
8776 goto nla_put_failure;
8777
David S. Miller9360ffd2012-03-29 04:41:26 -04008778 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8779 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008780
8781 nla_nest_end(msg, pinfoattr);
8782
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008783 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008784
8785 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8786 nl80211_mlme_mcgrp.id, gfp);
8787 return;
8788
8789 nla_put_failure:
8790 genlmsg_cancel(msg, hdr);
8791 nlmsg_free(msg);
8792}
8793
Johannes Berg7f6cf312011-11-04 11:18:15 +01008794void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8795 u64 cookie, bool acked, gfp_t gfp)
8796{
8797 struct wireless_dev *wdev = dev->ieee80211_ptr;
8798 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8799 struct sk_buff *msg;
8800 void *hdr;
8801 int err;
8802
Thomas Graf58050fc2012-06-28 03:57:45 +00008803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008804 if (!msg)
8805 return;
8806
8807 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8808 if (!hdr) {
8809 nlmsg_free(msg);
8810 return;
8811 }
8812
David S. Miller9360ffd2012-03-29 04:41:26 -04008813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8815 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8816 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8817 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8818 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008819
8820 err = genlmsg_end(msg, hdr);
8821 if (err < 0) {
8822 nlmsg_free(msg);
8823 return;
8824 }
8825
8826 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8827 nl80211_mlme_mcgrp.id, gfp);
8828 return;
8829
8830 nla_put_failure:
8831 genlmsg_cancel(msg, hdr);
8832 nlmsg_free(msg);
8833}
8834EXPORT_SYMBOL(cfg80211_probe_status);
8835
Johannes Berg5e760232011-11-04 11:18:17 +01008836void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8837 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008838 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008839{
8840 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8841 struct sk_buff *msg;
8842 void *hdr;
8843 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8844
8845 if (!nlpid)
8846 return;
8847
8848 msg = nlmsg_new(len + 100, gfp);
8849 if (!msg)
8850 return;
8851
8852 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8853 if (!hdr) {
8854 nlmsg_free(msg);
8855 return;
8856 }
8857
David S. Miller9360ffd2012-03-29 04:41:26 -04008858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8859 (freq &&
8860 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8861 (sig_dbm &&
8862 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8863 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8864 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01008865
8866 genlmsg_end(msg, hdr);
8867
8868 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8869 return;
8870
8871 nla_put_failure:
8872 genlmsg_cancel(msg, hdr);
8873 nlmsg_free(msg);
8874}
8875EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8876
Jouni Malinen026331c2010-02-15 12:53:10 +02008877static int nl80211_netlink_notify(struct notifier_block * nb,
8878 unsigned long state,
8879 void *_notify)
8880{
8881 struct netlink_notify *notify = _notify;
8882 struct cfg80211_registered_device *rdev;
8883 struct wireless_dev *wdev;
8884
8885 if (state != NETLINK_URELEASE)
8886 return NOTIFY_DONE;
8887
8888 rcu_read_lock();
8889
Johannes Berg5e760232011-11-04 11:18:17 +01008890 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008891 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008892 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008893 if (rdev->ap_beacons_nlpid == notify->pid)
8894 rdev->ap_beacons_nlpid = 0;
8895 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008896
8897 rcu_read_unlock();
8898
8899 return NOTIFY_DONE;
8900}
8901
8902static struct notifier_block nl80211_netlink_notifier = {
8903 .notifier_call = nl80211_netlink_notify,
8904};
8905
Johannes Berg55682962007-09-20 13:09:35 -04008906/* initialisation/exit functions */
8907
8908int nl80211_init(void)
8909{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008910 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008911
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008912 err = genl_register_family_with_ops(&nl80211_fam,
8913 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008914 if (err)
8915 return err;
8916
Johannes Berg55682962007-09-20 13:09:35 -04008917 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8918 if (err)
8919 goto err_out;
8920
Johannes Berg2a519312009-02-10 21:25:55 +01008921 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8922 if (err)
8923 goto err_out;
8924
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008925 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8926 if (err)
8927 goto err_out;
8928
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008929 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8930 if (err)
8931 goto err_out;
8932
Johannes Bergaff89a92009-07-01 21:26:51 +02008933#ifdef CONFIG_NL80211_TESTMODE
8934 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8935 if (err)
8936 goto err_out;
8937#endif
8938
Jouni Malinen026331c2010-02-15 12:53:10 +02008939 err = netlink_register_notifier(&nl80211_netlink_notifier);
8940 if (err)
8941 goto err_out;
8942
Johannes Berg55682962007-09-20 13:09:35 -04008943 return 0;
8944 err_out:
8945 genl_unregister_family(&nl80211_fam);
8946 return err;
8947}
8948
8949void nl80211_exit(void)
8950{
Jouni Malinen026331c2010-02-15 12:53:10 +02008951 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008952 genl_unregister_family(&nl80211_fam);
8953}