blob: 20aa390cf33875016e5e773d5a6e77354df3b084 [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
Johannes Berg4c476992010-10-04 21:36:35 +020026static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
27 struct genl_info *info);
28static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
29 struct genl_info *info);
30
Johannes Berg55682962007-09-20 13:09:35 -040031/* the netlink family */
32static struct genl_family nl80211_fam = {
33 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
34 .name = "nl80211", /* have users key off the name instead */
35 .hdrsize = 0, /* no private header */
36 .version = 1, /* no particular meaning now */
37 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020038 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020039 .pre_doit = nl80211_pre_doit,
40 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040041};
42
Johannes Berg79c97e92009-07-07 03:56:12 +020043/* internal helper: get rdev and dev */
Johannes Berg463d0182009-07-14 00:33:35 +020044static int get_rdev_dev_by_info_ifindex(struct genl_info *info,
Johannes Berg79c97e92009-07-07 03:56:12 +020045 struct cfg80211_registered_device **rdev,
Johannes Berg55682962007-09-20 13:09:35 -040046 struct net_device **dev)
47{
Johannes Berg463d0182009-07-14 00:33:35 +020048 struct nlattr **attrs = info->attrs;
Johannes Berg55682962007-09-20 13:09:35 -040049 int ifindex;
50
Johannes Bergbba95fe2008-07-29 13:22:51 +020051 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040052 return -EINVAL;
53
Johannes Bergbba95fe2008-07-29 13:22:51 +020054 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg463d0182009-07-14 00:33:35 +020055 *dev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040056 if (!*dev)
57 return -ENODEV;
58
Johannes Berg463d0182009-07-14 00:33:35 +020059 *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020060 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040061 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020062 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040063 }
64
65 return 0;
66}
67
68/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000069static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -040070 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
71 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -070072 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +020073 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020074 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053075 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020076 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
77 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +010080 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -040081
82 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
83 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
84 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010085
86 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg3e5d7642009-07-07 14:37:26 +020087 [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +010088
Johannes Bergb9454e82009-07-08 13:29:08 +020089 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +010090 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
91 .len = WLAN_MAX_KEY_LEN },
92 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
93 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
94 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen9f26a952009-05-15 12:38:32 +030095 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
Johannes Berge31b8212010-10-05 19:39:30 +020096 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010097
98 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
99 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
100 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
101 .len = IEEE80211_MAX_DATA_LEN },
102 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
103 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100104 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
105 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
106 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
107 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
108 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100109 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100110 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200111 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100112 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
113 .len = IEEE80211_MAX_MESH_ID_LEN },
114 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300115
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700116 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
117 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
118
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300119 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200122 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
123 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100124 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300125
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800126 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700127 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700128
Jouni Malinen36aedc92008-08-25 11:58:58 +0300129 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
130 .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200131
132 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
133 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
134 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100135 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
136 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200137
138 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
139 .len = IEEE80211_MAX_SSID_LEN },
140 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
141 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200142 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300143 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300144 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300145 [NL80211_ATTR_STA_FLAGS2] = {
146 .len = sizeof(struct nl80211_sta_flag_update),
147 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300148 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300149 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
150 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200151 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
152 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
153 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200154 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100155 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100156 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
157 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100158 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
159 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200160 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200161 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
162 .len = IEEE80211_MAX_DATA_LEN },
163 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200164 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200165 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300166 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200167 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300168 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
169 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200170 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900171 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
172 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100173 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100174 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100175 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200176 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700177 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300178 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200179 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200180 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Berg55682962007-09-20 13:09:35 -0400181};
182
Johannes Berge31b8212010-10-05 19:39:30 +0200183/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000184static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200185 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200186 [NL80211_KEY_IDX] = { .type = NLA_U8 },
187 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
188 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
189 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
190 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200191 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100192 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
193};
194
195/* policy for the key default flags */
196static const struct nla_policy
197nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
198 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
199 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200200};
201
Johannes Bergff1b6e62011-05-04 15:37:28 +0200202/* policy for WoWLAN attributes */
203static const struct nla_policy
204nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
205 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
206 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
207 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
208 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200209 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
210 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
211 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
212 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200213};
214
Johannes Berge5497d72011-07-05 16:35:40 +0200215/* policy for GTK rekey offload attributes */
216static const struct nla_policy
217nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
218 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
219 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
220 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
221};
222
Holger Schuriga0438972009-11-11 11:30:02 +0100223/* ifidx get helper */
224static int nl80211_get_ifidx(struct netlink_callback *cb)
225{
226 int res;
227
228 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
229 nl80211_fam.attrbuf, nl80211_fam.maxattr,
230 nl80211_policy);
231 if (res)
232 return res;
233
234 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
235 return -EINVAL;
236
237 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
238 if (!res)
239 return -EINVAL;
240 return res;
241}
242
Johannes Berg67748892010-10-04 21:14:06 +0200243static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
244 struct netlink_callback *cb,
245 struct cfg80211_registered_device **rdev,
246 struct net_device **dev)
247{
248 int ifidx = cb->args[0];
249 int err;
250
251 if (!ifidx)
252 ifidx = nl80211_get_ifidx(cb);
253 if (ifidx < 0)
254 return ifidx;
255
256 cb->args[0] = ifidx;
257
258 rtnl_lock();
259
260 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
261 if (!*dev) {
262 err = -ENODEV;
263 goto out_rtnl;
264 }
265
266 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100267 if (IS_ERR(*rdev)) {
268 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200269 goto out_rtnl;
270 }
271
272 return 0;
273 out_rtnl:
274 rtnl_unlock();
275 return err;
276}
277
278static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
279{
280 cfg80211_unlock_rdev(rdev);
281 rtnl_unlock();
282}
283
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100284/* IE validation */
285static bool is_valid_ie_attr(const struct nlattr *attr)
286{
287 const u8 *pos;
288 int len;
289
290 if (!attr)
291 return true;
292
293 pos = nla_data(attr);
294 len = nla_len(attr);
295
296 while (len) {
297 u8 elemlen;
298
299 if (len < 2)
300 return false;
301 len -= 2;
302
303 elemlen = pos[1];
304 if (elemlen > len)
305 return false;
306
307 len -= elemlen;
308 pos += 2 + elemlen;
309 }
310
311 return true;
312}
313
Johannes Berg55682962007-09-20 13:09:35 -0400314/* message building helper */
315static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
316 int flags, u8 cmd)
317{
318 /* since there is no private header just add the generic one */
319 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
320}
321
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400322static int nl80211_msg_put_channel(struct sk_buff *msg,
323 struct ieee80211_channel *chan)
324{
325 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
326 chan->center_freq);
327
328 if (chan->flags & IEEE80211_CHAN_DISABLED)
329 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
330 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
331 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
332 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
333 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
334 if (chan->flags & IEEE80211_CHAN_RADAR)
335 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
336
337 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
338 DBM_TO_MBM(chan->max_power));
339
340 return 0;
341
342 nla_put_failure:
343 return -ENOBUFS;
344}
345
Johannes Berg55682962007-09-20 13:09:35 -0400346/* netlink command implementations */
347
Johannes Bergb9454e82009-07-08 13:29:08 +0200348struct key_parse {
349 struct key_params p;
350 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200351 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200352 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100353 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200354};
355
356static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
357{
358 struct nlattr *tb[NL80211_KEY_MAX + 1];
359 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
360 nl80211_key_policy);
361 if (err)
362 return err;
363
364 k->def = !!tb[NL80211_KEY_DEFAULT];
365 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
366
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100367 if (k->def) {
368 k->def_uni = true;
369 k->def_multi = true;
370 }
371 if (k->defmgmt)
372 k->def_multi = true;
373
Johannes Bergb9454e82009-07-08 13:29:08 +0200374 if (tb[NL80211_KEY_IDX])
375 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
376
377 if (tb[NL80211_KEY_DATA]) {
378 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
379 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
380 }
381
382 if (tb[NL80211_KEY_SEQ]) {
383 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
384 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
385 }
386
387 if (tb[NL80211_KEY_CIPHER])
388 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
389
Johannes Berge31b8212010-10-05 19:39:30 +0200390 if (tb[NL80211_KEY_TYPE]) {
391 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
392 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
393 return -EINVAL;
394 }
395
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100396 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
397 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
398 int err = nla_parse_nested(kdt,
399 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
400 tb[NL80211_KEY_DEFAULT_TYPES],
401 nl80211_key_default_policy);
402 if (err)
403 return err;
404
405 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
406 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
407 }
408
Johannes Bergb9454e82009-07-08 13:29:08 +0200409 return 0;
410}
411
412static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
413{
414 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
415 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
416 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
417 }
418
419 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
420 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
421 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
422 }
423
424 if (info->attrs[NL80211_ATTR_KEY_IDX])
425 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
426
427 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
428 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
429
430 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
431 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
432
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100433 if (k->def) {
434 k->def_uni = true;
435 k->def_multi = true;
436 }
437 if (k->defmgmt)
438 k->def_multi = true;
439
Johannes Berge31b8212010-10-05 19:39:30 +0200440 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
441 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
442 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
443 return -EINVAL;
444 }
445
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100446 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
447 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
448 int err = nla_parse_nested(
449 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
450 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
451 nl80211_key_default_policy);
452 if (err)
453 return err;
454
455 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
456 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
457 }
458
Johannes Bergb9454e82009-07-08 13:29:08 +0200459 return 0;
460}
461
462static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
463{
464 int err;
465
466 memset(k, 0, sizeof(*k));
467 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200468 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200469
470 if (info->attrs[NL80211_ATTR_KEY])
471 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
472 else
473 err = nl80211_parse_key_old(info, k);
474
475 if (err)
476 return err;
477
478 if (k->def && k->defmgmt)
479 return -EINVAL;
480
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100481 if (k->defmgmt) {
482 if (k->def_uni || !k->def_multi)
483 return -EINVAL;
484 }
485
Johannes Bergb9454e82009-07-08 13:29:08 +0200486 if (k->idx != -1) {
487 if (k->defmgmt) {
488 if (k->idx < 4 || k->idx > 5)
489 return -EINVAL;
490 } else if (k->def) {
491 if (k->idx < 0 || k->idx > 3)
492 return -EINVAL;
493 } else {
494 if (k->idx < 0 || k->idx > 5)
495 return -EINVAL;
496 }
497 }
498
499 return 0;
500}
501
Johannes Bergfffd0932009-07-08 14:22:54 +0200502static struct cfg80211_cached_keys *
503nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
504 struct nlattr *keys)
505{
506 struct key_parse parse;
507 struct nlattr *key;
508 struct cfg80211_cached_keys *result;
509 int rem, err, def = 0;
510
511 result = kzalloc(sizeof(*result), GFP_KERNEL);
512 if (!result)
513 return ERR_PTR(-ENOMEM);
514
515 result->def = -1;
516 result->defmgmt = -1;
517
518 nla_for_each_nested(key, keys, rem) {
519 memset(&parse, 0, sizeof(parse));
520 parse.idx = -1;
521
522 err = nl80211_parse_key_new(key, &parse);
523 if (err)
524 goto error;
525 err = -EINVAL;
526 if (!parse.p.key)
527 goto error;
528 if (parse.idx < 0 || parse.idx > 4)
529 goto error;
530 if (parse.def) {
531 if (def)
532 goto error;
533 def = 1;
534 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100535 if (!parse.def_uni || !parse.def_multi)
536 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200537 } else if (parse.defmgmt)
538 goto error;
539 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200540 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200541 if (err)
542 goto error;
543 result->params[parse.idx].cipher = parse.p.cipher;
544 result->params[parse.idx].key_len = parse.p.key_len;
545 result->params[parse.idx].key = result->data[parse.idx];
546 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
547 }
548
549 return result;
550 error:
551 kfree(result);
552 return ERR_PTR(err);
553}
554
555static int nl80211_key_allowed(struct wireless_dev *wdev)
556{
557 ASSERT_WDEV_LOCK(wdev);
558
Johannes Bergfffd0932009-07-08 14:22:54 +0200559 switch (wdev->iftype) {
560 case NL80211_IFTYPE_AP:
561 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200562 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700563 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200564 break;
565 case NL80211_IFTYPE_ADHOC:
566 if (!wdev->current_bss)
567 return -ENOLINK;
568 break;
569 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200570 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200571 if (wdev->sme_state != CFG80211_SME_CONNECTED)
572 return -ENOLINK;
573 break;
574 default:
575 return -EINVAL;
576 }
577
578 return 0;
579}
580
Johannes Berg7527a782011-05-13 10:58:57 +0200581static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
582{
583 struct nlattr *nl_modes = nla_nest_start(msg, attr);
584 int i;
585
586 if (!nl_modes)
587 goto nla_put_failure;
588
589 i = 0;
590 while (ifmodes) {
591 if (ifmodes & 1)
592 NLA_PUT_FLAG(msg, i);
593 ifmodes >>= 1;
594 i++;
595 }
596
597 nla_nest_end(msg, nl_modes);
598 return 0;
599
600nla_put_failure:
601 return -ENOBUFS;
602}
603
604static int nl80211_put_iface_combinations(struct wiphy *wiphy,
605 struct sk_buff *msg)
606{
607 struct nlattr *nl_combis;
608 int i, j;
609
610 nl_combis = nla_nest_start(msg,
611 NL80211_ATTR_INTERFACE_COMBINATIONS);
612 if (!nl_combis)
613 goto nla_put_failure;
614
615 for (i = 0; i < wiphy->n_iface_combinations; i++) {
616 const struct ieee80211_iface_combination *c;
617 struct nlattr *nl_combi, *nl_limits;
618
619 c = &wiphy->iface_combinations[i];
620
621 nl_combi = nla_nest_start(msg, i + 1);
622 if (!nl_combi)
623 goto nla_put_failure;
624
625 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
626 if (!nl_limits)
627 goto nla_put_failure;
628
629 for (j = 0; j < c->n_limits; j++) {
630 struct nlattr *nl_limit;
631
632 nl_limit = nla_nest_start(msg, j + 1);
633 if (!nl_limit)
634 goto nla_put_failure;
635 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
636 c->limits[j].max);
637 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
638 c->limits[j].types))
639 goto nla_put_failure;
640 nla_nest_end(msg, nl_limit);
641 }
642
643 nla_nest_end(msg, nl_limits);
644
645 if (c->beacon_int_infra_match)
646 NLA_PUT_FLAG(msg,
647 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
648 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
649 c->num_different_channels);
650 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
651 c->max_interfaces);
652
653 nla_nest_end(msg, nl_combi);
654 }
655
656 nla_nest_end(msg, nl_combis);
657
658 return 0;
659nla_put_failure:
660 return -ENOBUFS;
661}
662
Johannes Berg55682962007-09-20 13:09:35 -0400663static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
664 struct cfg80211_registered_device *dev)
665{
666 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100667 struct nlattr *nl_bands, *nl_band;
668 struct nlattr *nl_freqs, *nl_freq;
669 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100670 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100671 enum ieee80211_band band;
672 struct ieee80211_channel *chan;
673 struct ieee80211_rate *rate;
674 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200675 const struct ieee80211_txrx_stypes *mgmt_stypes =
676 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400677
678 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
679 if (!hdr)
680 return -1;
681
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500682 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400683 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200684
Johannes Bergf5ea9122009-08-07 16:17:38 +0200685 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
686 cfg80211_rdev_list_generation);
687
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200688 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
689 dev->wiphy.retry_short);
690 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
691 dev->wiphy.retry_long);
692 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
693 dev->wiphy.frag_threshold);
694 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
695 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100696 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
697 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100698 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
699 dev->wiphy.max_scan_ssids);
Luciano Coelho93b6aa62011-07-13 14:57:28 +0300700 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
701 dev->wiphy.max_sched_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200702 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
703 dev->wiphy.max_scan_ie_len);
Luciano Coelho5a865ba2011-07-13 14:57:29 +0300704 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
705 dev->wiphy.max_sched_scan_ie_len);
Johannes Bergee688b002008-01-24 19:38:39 +0100706
Johannes Berge31b8212010-10-05 19:39:30 +0200707 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
708 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
Javier Cardona15d5dda2011-04-07 15:08:28 -0700709 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
710 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
Johannes Berge31b8212010-10-05 19:39:30 +0200711
Johannes Berg25e47c12009-04-02 20:14:06 +0200712 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
713 sizeof(u32) * dev->wiphy.n_cipher_suites,
714 dev->wiphy.cipher_suites);
715
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100716 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
717 dev->wiphy.max_num_pmkids);
718
Johannes Bergc0692b82010-08-27 14:26:53 +0300719 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
720 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
721
Bruno Randolf39fd5de2010-12-16 11:30:28 +0900722 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
723 dev->wiphy.available_antennas_tx);
724 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
725 dev->wiphy.available_antennas_rx);
726
Bruno Randolf7f531e02010-12-16 11:30:22 +0900727 if ((dev->wiphy.available_antennas_tx ||
728 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900729 u32 tx_ant = 0, rx_ant = 0;
730 int res;
731 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
732 if (!res) {
733 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
734 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
735 }
736 }
737
Johannes Berg7527a782011-05-13 10:58:57 +0200738 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
739 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700740 goto nla_put_failure;
741
Johannes Bergee688b002008-01-24 19:38:39 +0100742 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
743 if (!nl_bands)
744 goto nla_put_failure;
745
746 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
747 if (!dev->wiphy.bands[band])
748 continue;
749
750 nl_band = nla_nest_start(msg, band);
751 if (!nl_band)
752 goto nla_put_failure;
753
Johannes Bergd51626d2008-10-09 12:20:13 +0200754 /* add HT info */
755 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
756 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
757 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
758 &dev->wiphy.bands[band]->ht_cap.mcs);
759 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
760 dev->wiphy.bands[band]->ht_cap.cap);
761 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
762 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
763 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
764 dev->wiphy.bands[band]->ht_cap.ampdu_density);
765 }
766
Johannes Bergee688b002008-01-24 19:38:39 +0100767 /* add frequencies */
768 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
769 if (!nl_freqs)
770 goto nla_put_failure;
771
772 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
773 nl_freq = nla_nest_start(msg, i);
774 if (!nl_freq)
775 goto nla_put_failure;
776
777 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100778
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400779 if (nl80211_msg_put_channel(msg, chan))
780 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200781
Johannes Bergee688b002008-01-24 19:38:39 +0100782 nla_nest_end(msg, nl_freq);
783 }
784
785 nla_nest_end(msg, nl_freqs);
786
787 /* add bitrates */
788 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
789 if (!nl_rates)
790 goto nla_put_failure;
791
792 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
793 nl_rate = nla_nest_start(msg, i);
794 if (!nl_rate)
795 goto nla_put_failure;
796
797 rate = &dev->wiphy.bands[band]->bitrates[i];
798 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
799 rate->bitrate);
800 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
801 NLA_PUT_FLAG(msg,
802 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
803
804 nla_nest_end(msg, nl_rate);
805 }
806
807 nla_nest_end(msg, nl_rates);
808
809 nla_nest_end(msg, nl_band);
810 }
811 nla_nest_end(msg, nl_bands);
812
Johannes Berg8fdc6212009-03-14 09:34:01 +0100813 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
814 if (!nl_cmds)
815 goto nla_put_failure;
816
817 i = 0;
818#define CMD(op, n) \
819 do { \
820 if (dev->ops->op) { \
821 i++; \
822 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
823 } \
824 } while (0)
825
826 CMD(add_virtual_intf, NEW_INTERFACE);
827 CMD(change_virtual_intf, SET_INTERFACE);
828 CMD(add_key, NEW_KEY);
829 CMD(add_beacon, NEW_BEACON);
830 CMD(add_station, NEW_STATION);
831 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800832 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100833 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200834 CMD(auth, AUTHENTICATE);
835 CMD(assoc, ASSOCIATE);
836 CMD(deauth, DEAUTHENTICATE);
837 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200838 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100839 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100840 CMD(set_pmksa, SET_PMKSA);
841 CMD(del_pmksa, DEL_PMKSA);
842 CMD(flush_pmksa, FLUSH_PMKSA);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100843 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200844 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200845 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100846 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100847 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200848 i++;
849 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
850 }
Johannes Bergf444de02010-05-05 15:25:02 +0200851 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400852 CMD(set_wds_peer, SET_WDS_PEER);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300853 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
854 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100855
856#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200857
Johannes Berg6829c872009-07-02 09:13:27 +0200858 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200859 i++;
860 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
861 }
862
Johannes Berg6829c872009-07-02 09:13:27 +0200863 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200864 i++;
865 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
866 }
867
Johannes Berg8fdc6212009-03-14 09:34:01 +0100868 nla_nest_end(msg, nl_cmds);
869
Johannes Berga2939112010-12-14 17:54:28 +0100870 if (dev->ops->remain_on_channel)
871 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
872 dev->wiphy.max_remain_on_channel_duration);
873
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100874 /* for now at least assume all drivers have it */
875 if (dev->ops->mgmt_tx)
876 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
877
Johannes Berg2e161f72010-08-12 15:38:38 +0200878 if (mgmt_stypes) {
879 u16 stypes;
880 struct nlattr *nl_ftypes, *nl_ifs;
881 enum nl80211_iftype ift;
882
883 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
884 if (!nl_ifs)
885 goto nla_put_failure;
886
887 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
888 nl_ftypes = nla_nest_start(msg, ift);
889 if (!nl_ftypes)
890 goto nla_put_failure;
891 i = 0;
892 stypes = mgmt_stypes[ift].tx;
893 while (stypes) {
894 if (stypes & 1)
895 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
896 (i << 4) | IEEE80211_FTYPE_MGMT);
897 stypes >>= 1;
898 i++;
899 }
900 nla_nest_end(msg, nl_ftypes);
901 }
902
Johannes Berg74b70a42010-08-24 12:15:53 +0200903 nla_nest_end(msg, nl_ifs);
904
Johannes Berg2e161f72010-08-12 15:38:38 +0200905 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
906 if (!nl_ifs)
907 goto nla_put_failure;
908
909 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
910 nl_ftypes = nla_nest_start(msg, ift);
911 if (!nl_ftypes)
912 goto nla_put_failure;
913 i = 0;
914 stypes = mgmt_stypes[ift].rx;
915 while (stypes) {
916 if (stypes & 1)
917 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
918 (i << 4) | IEEE80211_FTYPE_MGMT);
919 stypes >>= 1;
920 i++;
921 }
922 nla_nest_end(msg, nl_ftypes);
923 }
924 nla_nest_end(msg, nl_ifs);
925 }
926
Johannes Bergff1b6e62011-05-04 15:37:28 +0200927 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
928 struct nlattr *nl_wowlan;
929
930 nl_wowlan = nla_nest_start(msg,
931 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
932 if (!nl_wowlan)
933 goto nla_put_failure;
934
935 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
936 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
937 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
938 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
939 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
940 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +0200941 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
942 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
943 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
944 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
945 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
946 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
947 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
948 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
949 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
950 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +0200951 if (dev->wiphy.wowlan.n_patterns) {
952 struct nl80211_wowlan_pattern_support pat = {
953 .max_patterns = dev->wiphy.wowlan.n_patterns,
954 .min_pattern_len =
955 dev->wiphy.wowlan.pattern_min_len,
956 .max_pattern_len =
957 dev->wiphy.wowlan.pattern_max_len,
958 };
959 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
960 sizeof(pat), &pat);
961 }
962
963 nla_nest_end(msg, nl_wowlan);
964 }
965
Johannes Berg7527a782011-05-13 10:58:57 +0200966 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
967 dev->wiphy.software_iftypes))
968 goto nla_put_failure;
969
970 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
971 goto nla_put_failure;
972
Johannes Berg55682962007-09-20 13:09:35 -0400973 return genlmsg_end(msg, hdr);
974
975 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700976 genlmsg_cancel(msg, hdr);
977 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -0400978}
979
980static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
981{
982 int idx = 0;
983 int start = cb->args[0];
984 struct cfg80211_registered_device *dev;
985
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500986 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +0200987 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +0200988 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
989 continue;
Julius Volzb4637272008-07-08 14:02:19 +0200990 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -0400991 continue;
992 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
993 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +0200994 dev) < 0) {
995 idx--;
Johannes Berg55682962007-09-20 13:09:35 -0400996 break;
Julius Volzb4637272008-07-08 14:02:19 +0200997 }
Johannes Berg55682962007-09-20 13:09:35 -0400998 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500999 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001000
1001 cb->args[0] = idx;
1002
1003 return skb->len;
1004}
1005
1006static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1007{
1008 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001009 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001010
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001012 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001013 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001014
Johannes Berg4c476992010-10-04 21:36:35 +02001015 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1016 nlmsg_free(msg);
1017 return -ENOBUFS;
1018 }
Johannes Berg55682962007-09-20 13:09:35 -04001019
Johannes Berg134e6372009-07-10 09:51:34 +00001020 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001021}
1022
Jouni Malinen31888482008-10-30 16:59:24 +02001023static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1024 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1025 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1026 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1027 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1028 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1029};
1030
1031static int parse_txq_params(struct nlattr *tb[],
1032 struct ieee80211_txq_params *txq_params)
1033{
1034 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1035 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1036 !tb[NL80211_TXQ_ATTR_AIFS])
1037 return -EINVAL;
1038
1039 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1040 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1041 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1042 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1043 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1044
1045 return 0;
1046}
1047
Johannes Bergf444de02010-05-05 15:25:02 +02001048static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1049{
1050 /*
1051 * You can only set the channel explicitly for AP, mesh
1052 * and WDS type interfaces; all others have their channel
1053 * managed via their respective "establish a connection"
1054 * command (connect, join, ...)
1055 *
1056 * Monitors are special as they are normally slaved to
1057 * whatever else is going on, so they behave as though
1058 * you tried setting the wiphy channel itself.
1059 */
1060 return !wdev ||
1061 wdev->iftype == NL80211_IFTYPE_AP ||
1062 wdev->iftype == NL80211_IFTYPE_WDS ||
1063 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001064 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1065 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001066}
1067
1068static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1069 struct wireless_dev *wdev,
1070 struct genl_info *info)
1071{
1072 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1073 u32 freq;
1074 int result;
1075
1076 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1077 return -EINVAL;
1078
1079 if (!nl80211_can_set_dev_channel(wdev))
1080 return -EOPNOTSUPP;
1081
1082 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1083 channel_type = nla_get_u32(info->attrs[
1084 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1085 if (channel_type != NL80211_CHAN_NO_HT &&
1086 channel_type != NL80211_CHAN_HT20 &&
1087 channel_type != NL80211_CHAN_HT40PLUS &&
1088 channel_type != NL80211_CHAN_HT40MINUS)
1089 return -EINVAL;
1090 }
1091
1092 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1093
1094 mutex_lock(&rdev->devlist_mtx);
1095 if (wdev) {
1096 wdev_lock(wdev);
1097 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1098 wdev_unlock(wdev);
1099 } else {
1100 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1101 }
1102 mutex_unlock(&rdev->devlist_mtx);
1103
1104 return result;
1105}
1106
1107static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1108{
Johannes Berg4c476992010-10-04 21:36:35 +02001109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1110 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001111
Johannes Berg4c476992010-10-04 21:36:35 +02001112 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001113}
1114
Bill Jordane8347eb2010-10-01 13:54:28 -04001115static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1116{
Johannes Berg43b19952010-10-07 13:10:30 +02001117 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1118 struct net_device *dev = info->user_ptr[1];
1119 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001120 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001121
1122 if (!info->attrs[NL80211_ATTR_MAC])
1123 return -EINVAL;
1124
Johannes Berg43b19952010-10-07 13:10:30 +02001125 if (netif_running(dev))
1126 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001127
Johannes Berg43b19952010-10-07 13:10:30 +02001128 if (!rdev->ops->set_wds_peer)
1129 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001130
Johannes Berg43b19952010-10-07 13:10:30 +02001131 if (wdev->iftype != NL80211_IFTYPE_WDS)
1132 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001133
1134 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001135 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001136}
1137
1138
Johannes Berg55682962007-09-20 13:09:35 -04001139static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1140{
1141 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001142 struct net_device *netdev = NULL;
1143 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001144 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001145 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001146 u32 changed;
1147 u8 retry_short = 0, retry_long = 0;
1148 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001149 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001150
Johannes Bergf444de02010-05-05 15:25:02 +02001151 /*
1152 * Try to find the wiphy and netdev. Normally this
1153 * function shouldn't need the netdev, but this is
1154 * done for backward compatibility -- previously
1155 * setting the channel was done per wiphy, but now
1156 * it is per netdev. Previous userland like hostapd
1157 * also passed a netdev to set_wiphy, so that it is
1158 * possible to let that go to the right netdev!
1159 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001160 mutex_lock(&cfg80211_mutex);
1161
Johannes Bergf444de02010-05-05 15:25:02 +02001162 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1163 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1164
1165 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1166 if (netdev && netdev->ieee80211_ptr) {
1167 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1168 mutex_lock(&rdev->mtx);
1169 } else
1170 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001171 }
1172
Johannes Bergf444de02010-05-05 15:25:02 +02001173 if (!netdev) {
1174 rdev = __cfg80211_rdev_from_info(info);
1175 if (IS_ERR(rdev)) {
1176 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001177 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001178 }
1179 wdev = NULL;
1180 netdev = NULL;
1181 result = 0;
1182
1183 mutex_lock(&rdev->mtx);
1184 } else if (netif_running(netdev) &&
1185 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1186 wdev = netdev->ieee80211_ptr;
1187 else
1188 wdev = NULL;
1189
1190 /*
1191 * end workaround code, by now the rdev is available
1192 * and locked, and wdev may or may not be NULL.
1193 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001194
1195 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001196 result = cfg80211_dev_rename(
1197 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001198
1199 mutex_unlock(&cfg80211_mutex);
1200
1201 if (result)
1202 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001203
Jouni Malinen31888482008-10-30 16:59:24 +02001204 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1205 struct ieee80211_txq_params txq_params;
1206 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1207
1208 if (!rdev->ops->set_txq_params) {
1209 result = -EOPNOTSUPP;
1210 goto bad_res;
1211 }
1212
1213 nla_for_each_nested(nl_txq_params,
1214 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1215 rem_txq_params) {
1216 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1217 nla_data(nl_txq_params),
1218 nla_len(nl_txq_params),
1219 txq_params_policy);
1220 result = parse_txq_params(tb, &txq_params);
1221 if (result)
1222 goto bad_res;
1223
1224 result = rdev->ops->set_txq_params(&rdev->wiphy,
1225 &txq_params);
1226 if (result)
1227 goto bad_res;
1228 }
1229 }
1230
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001231 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001232 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001233 if (result)
1234 goto bad_res;
1235 }
1236
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001237 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1238 enum nl80211_tx_power_setting type;
1239 int idx, mbm = 0;
1240
1241 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001242 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001243 goto bad_res;
1244 }
1245
1246 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1247 type = nla_get_u32(info->attrs[idx]);
1248
1249 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1250 (type != NL80211_TX_POWER_AUTOMATIC)) {
1251 result = -EINVAL;
1252 goto bad_res;
1253 }
1254
1255 if (type != NL80211_TX_POWER_AUTOMATIC) {
1256 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1257 mbm = nla_get_u32(info->attrs[idx]);
1258 }
1259
1260 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1261 if (result)
1262 goto bad_res;
1263 }
1264
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001265 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1266 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1267 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001268 if ((!rdev->wiphy.available_antennas_tx &&
1269 !rdev->wiphy.available_antennas_rx) ||
1270 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001271 result = -EOPNOTSUPP;
1272 goto bad_res;
1273 }
1274
1275 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1276 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1277
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001278 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001279 * available antenna masks, except for the "all" mask */
1280 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1281 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001282 result = -EINVAL;
1283 goto bad_res;
1284 }
1285
Bruno Randolf7f531e02010-12-16 11:30:22 +09001286 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1287 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001288
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001289 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1290 if (result)
1291 goto bad_res;
1292 }
1293
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001294 changed = 0;
1295
1296 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1297 retry_short = nla_get_u8(
1298 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1299 if (retry_short == 0) {
1300 result = -EINVAL;
1301 goto bad_res;
1302 }
1303 changed |= WIPHY_PARAM_RETRY_SHORT;
1304 }
1305
1306 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1307 retry_long = nla_get_u8(
1308 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1309 if (retry_long == 0) {
1310 result = -EINVAL;
1311 goto bad_res;
1312 }
1313 changed |= WIPHY_PARAM_RETRY_LONG;
1314 }
1315
1316 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1317 frag_threshold = nla_get_u32(
1318 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1319 if (frag_threshold < 256) {
1320 result = -EINVAL;
1321 goto bad_res;
1322 }
1323 if (frag_threshold != (u32) -1) {
1324 /*
1325 * Fragments (apart from the last one) are required to
1326 * have even length. Make the fragmentation code
1327 * simpler by stripping LSB should someone try to use
1328 * odd threshold value.
1329 */
1330 frag_threshold &= ~0x1;
1331 }
1332 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1333 }
1334
1335 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1336 rts_threshold = nla_get_u32(
1337 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1338 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1339 }
1340
Lukáš Turek81077e82009-12-21 22:50:47 +01001341 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1342 coverage_class = nla_get_u8(
1343 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1344 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1345 }
1346
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001347 if (changed) {
1348 u8 old_retry_short, old_retry_long;
1349 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001350 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001351
1352 if (!rdev->ops->set_wiphy_params) {
1353 result = -EOPNOTSUPP;
1354 goto bad_res;
1355 }
1356
1357 old_retry_short = rdev->wiphy.retry_short;
1358 old_retry_long = rdev->wiphy.retry_long;
1359 old_frag_threshold = rdev->wiphy.frag_threshold;
1360 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001361 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001362
1363 if (changed & WIPHY_PARAM_RETRY_SHORT)
1364 rdev->wiphy.retry_short = retry_short;
1365 if (changed & WIPHY_PARAM_RETRY_LONG)
1366 rdev->wiphy.retry_long = retry_long;
1367 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1368 rdev->wiphy.frag_threshold = frag_threshold;
1369 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1370 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001371 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1372 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001373
1374 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1375 if (result) {
1376 rdev->wiphy.retry_short = old_retry_short;
1377 rdev->wiphy.retry_long = old_retry_long;
1378 rdev->wiphy.frag_threshold = old_frag_threshold;
1379 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001380 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001381 }
1382 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001383
Johannes Berg306d6112008-12-08 12:39:04 +01001384 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001385 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001386 if (netdev)
1387 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001388 return result;
1389}
1390
1391
1392static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001393 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001394 struct net_device *dev)
1395{
1396 void *hdr;
1397
1398 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1399 if (!hdr)
1400 return -1;
1401
1402 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001403 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001404 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001405 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001406
1407 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1408 rdev->devlist_generation ^
1409 (cfg80211_rdev_list_generation << 2));
1410
Johannes Berg55682962007-09-20 13:09:35 -04001411 return genlmsg_end(msg, hdr);
1412
1413 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001414 genlmsg_cancel(msg, hdr);
1415 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001416}
1417
1418static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1419{
1420 int wp_idx = 0;
1421 int if_idx = 0;
1422 int wp_start = cb->args[0];
1423 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001424 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001425 struct wireless_dev *wdev;
1426
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001427 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001428 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1429 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001430 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001431 if (wp_idx < wp_start) {
1432 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001433 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001434 }
Johannes Berg55682962007-09-20 13:09:35 -04001435 if_idx = 0;
1436
Johannes Bergf5ea9122009-08-07 16:17:38 +02001437 mutex_lock(&rdev->devlist_mtx);
1438 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001439 if (if_idx < if_start) {
1440 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001441 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001442 }
Johannes Berg55682962007-09-20 13:09:35 -04001443 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1444 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001445 rdev, wdev->netdev) < 0) {
1446 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001447 goto out;
1448 }
1449 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001450 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001451 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001452
1453 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001454 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001455 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001456 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001457
1458 cb->args[0] = wp_idx;
1459 cb->args[1] = if_idx;
1460
1461 return skb->len;
1462}
1463
1464static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1465{
1466 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001467 struct cfg80211_registered_device *dev = info->user_ptr[0];
1468 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001469
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001470 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001471 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001472 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001473
Johannes Bergd7264052009-04-19 16:23:20 +02001474 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001475 dev, netdev) < 0) {
1476 nlmsg_free(msg);
1477 return -ENOBUFS;
1478 }
Johannes Berg55682962007-09-20 13:09:35 -04001479
Johannes Berg134e6372009-07-10 09:51:34 +00001480 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001481}
1482
Michael Wu66f7ac52008-01-31 19:48:22 +01001483static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1484 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1485 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1486 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1487 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1488 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1489};
1490
1491static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1492{
1493 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1494 int flag;
1495
1496 *mntrflags = 0;
1497
1498 if (!nla)
1499 return -EINVAL;
1500
1501 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1502 nla, mntr_flags_policy))
1503 return -EINVAL;
1504
1505 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1506 if (flags[flag])
1507 *mntrflags |= (1<<flag);
1508
1509 return 0;
1510}
1511
Johannes Berg9bc383d2009-11-19 11:55:19 +01001512static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001513 struct net_device *netdev, u8 use_4addr,
1514 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001515{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001516 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001517 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001518 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001519 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001520 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001521
1522 switch (iftype) {
1523 case NL80211_IFTYPE_AP_VLAN:
1524 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1525 return 0;
1526 break;
1527 case NL80211_IFTYPE_STATION:
1528 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1529 return 0;
1530 break;
1531 default:
1532 break;
1533 }
1534
1535 return -EOPNOTSUPP;
1536}
1537
Johannes Berg55682962007-09-20 13:09:35 -04001538static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1539{
Johannes Berg4c476992010-10-04 21:36:35 +02001540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001541 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001542 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001543 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001544 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001545 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001546 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001547
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001548 memset(&params, 0, sizeof(params));
1549
Johannes Berg04a773a2009-04-19 21:24:32 +02001550 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001551
Johannes Berg723b0382008-09-16 20:22:09 +02001552 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001553 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001554 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001555 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001556 if (ntype > NL80211_IFTYPE_MAX)
1557 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001558 }
1559
Johannes Berg92ffe052008-09-16 20:39:36 +02001560 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001561 struct wireless_dev *wdev = dev->ieee80211_ptr;
1562
Johannes Berg4c476992010-10-04 21:36:35 +02001563 if (ntype != NL80211_IFTYPE_MESH_POINT)
1564 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001565 if (netif_running(dev))
1566 return -EBUSY;
1567
1568 wdev_lock(wdev);
1569 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1570 IEEE80211_MAX_MESH_ID_LEN);
1571 wdev->mesh_id_up_len =
1572 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1573 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1574 wdev->mesh_id_up_len);
1575 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001576 }
1577
Felix Fietkau8b787642009-11-10 18:53:10 +01001578 if (info->attrs[NL80211_ATTR_4ADDR]) {
1579 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1580 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001581 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001582 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001583 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001584 } else {
1585 params.use_4addr = -1;
1586 }
1587
Johannes Berg92ffe052008-09-16 20:39:36 +02001588 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001589 if (ntype != NL80211_IFTYPE_MONITOR)
1590 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001591 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1592 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001593 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001594 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001595
1596 flags = &_flags;
1597 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001598 }
Johannes Berg3b858752009-03-12 09:55:09 +01001599
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001600 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001601 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001602 else
1603 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001604
Johannes Berg9bc383d2009-11-19 11:55:19 +01001605 if (!err && params.use_4addr != -1)
1606 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1607
Johannes Berg55682962007-09-20 13:09:35 -04001608 return err;
1609}
1610
1611static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1612{
Johannes Berg4c476992010-10-04 21:36:35 +02001613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001614 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001615 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001616 int err;
1617 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001618 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001619
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001620 memset(&params, 0, sizeof(params));
1621
Johannes Berg55682962007-09-20 13:09:35 -04001622 if (!info->attrs[NL80211_ATTR_IFNAME])
1623 return -EINVAL;
1624
1625 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1626 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1627 if (type > NL80211_IFTYPE_MAX)
1628 return -EINVAL;
1629 }
1630
Johannes Berg79c97e92009-07-07 03:56:12 +02001631 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001632 !(rdev->wiphy.interface_modes & (1 << type)))
1633 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001634
Johannes Berg9bc383d2009-11-19 11:55:19 +01001635 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001636 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001637 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001638 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001639 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001640 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001641
Michael Wu66f7ac52008-01-31 19:48:22 +01001642 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1643 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1644 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001645 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001646 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001647 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001648 if (IS_ERR(dev))
1649 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001650
Johannes Berg29cbe682010-12-03 09:20:44 +01001651 if (type == NL80211_IFTYPE_MESH_POINT &&
1652 info->attrs[NL80211_ATTR_MESH_ID]) {
1653 struct wireless_dev *wdev = dev->ieee80211_ptr;
1654
1655 wdev_lock(wdev);
1656 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1657 IEEE80211_MAX_MESH_ID_LEN);
1658 wdev->mesh_id_up_len =
1659 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1660 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1661 wdev->mesh_id_up_len);
1662 wdev_unlock(wdev);
1663 }
1664
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001665 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001666}
1667
1668static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1669{
Johannes Berg4c476992010-10-04 21:36:35 +02001670 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1671 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001672
Johannes Berg4c476992010-10-04 21:36:35 +02001673 if (!rdev->ops->del_virtual_intf)
1674 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001675
Johannes Berg4c476992010-10-04 21:36:35 +02001676 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001677}
1678
Johannes Berg41ade002007-12-19 02:03:29 +01001679struct get_key_cookie {
1680 struct sk_buff *msg;
1681 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001682 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001683};
1684
1685static void get_key_callback(void *c, struct key_params *params)
1686{
Johannes Bergb9454e82009-07-08 13:29:08 +02001687 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001688 struct get_key_cookie *cookie = c;
1689
1690 if (params->key)
1691 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1692 params->key_len, params->key);
1693
1694 if (params->seq)
1695 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1696 params->seq_len, params->seq);
1697
1698 if (params->cipher)
1699 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1700 params->cipher);
1701
Johannes Bergb9454e82009-07-08 13:29:08 +02001702 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1703 if (!key)
1704 goto nla_put_failure;
1705
1706 if (params->key)
1707 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1708 params->key_len, params->key);
1709
1710 if (params->seq)
1711 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1712 params->seq_len, params->seq);
1713
1714 if (params->cipher)
1715 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1716 params->cipher);
1717
1718 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1719
1720 nla_nest_end(cookie->msg, key);
1721
Johannes Berg41ade002007-12-19 02:03:29 +01001722 return;
1723 nla_put_failure:
1724 cookie->error = 1;
1725}
1726
1727static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1728{
Johannes Berg4c476992010-10-04 21:36:35 +02001729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001730 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001731 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001732 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001733 const u8 *mac_addr = NULL;
1734 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001735 struct get_key_cookie cookie = {
1736 .error = 0,
1737 };
1738 void *hdr;
1739 struct sk_buff *msg;
1740
1741 if (info->attrs[NL80211_ATTR_KEY_IDX])
1742 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1743
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001744 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001745 return -EINVAL;
1746
1747 if (info->attrs[NL80211_ATTR_MAC])
1748 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1749
Johannes Berge31b8212010-10-05 19:39:30 +02001750 pairwise = !!mac_addr;
1751 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1752 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1753 if (kt >= NUM_NL80211_KEYTYPES)
1754 return -EINVAL;
1755 if (kt != NL80211_KEYTYPE_GROUP &&
1756 kt != NL80211_KEYTYPE_PAIRWISE)
1757 return -EINVAL;
1758 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1759 }
1760
Johannes Berg4c476992010-10-04 21:36:35 +02001761 if (!rdev->ops->get_key)
1762 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001763
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001765 if (!msg)
1766 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001767
1768 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1769 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001770 if (IS_ERR(hdr))
1771 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001772
1773 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001774 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001775
1776 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1777 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1778 if (mac_addr)
1779 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1780
Johannes Berge31b8212010-10-05 19:39:30 +02001781 if (pairwise && mac_addr &&
1782 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1783 return -ENOENT;
1784
1785 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1786 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001787
1788 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001789 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001790
1791 if (cookie.error)
1792 goto nla_put_failure;
1793
1794 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001795 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001796
1797 nla_put_failure:
1798 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001799 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001800 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001801 return err;
1802}
1803
1804static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1805{
Johannes Berg4c476992010-10-04 21:36:35 +02001806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001807 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001808 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001809 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001810
Johannes Bergb9454e82009-07-08 13:29:08 +02001811 err = nl80211_parse_key(info, &key);
1812 if (err)
1813 return err;
1814
1815 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001816 return -EINVAL;
1817
Johannes Bergb9454e82009-07-08 13:29:08 +02001818 /* only support setting default key */
1819 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001820 return -EINVAL;
1821
Johannes Bergfffd0932009-07-08 14:22:54 +02001822 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001823
1824 if (key.def) {
1825 if (!rdev->ops->set_default_key) {
1826 err = -EOPNOTSUPP;
1827 goto out;
1828 }
1829
1830 err = nl80211_key_allowed(dev->ieee80211_ptr);
1831 if (err)
1832 goto out;
1833
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001834 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1835 key.def_uni, key.def_multi);
1836
1837 if (err)
1838 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001839
Johannes Berg3d23e342009-09-29 23:27:28 +02001840#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001841 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001842#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001843 } else {
1844 if (key.def_uni || !key.def_multi) {
1845 err = -EINVAL;
1846 goto out;
1847 }
1848
1849 if (!rdev->ops->set_default_mgmt_key) {
1850 err = -EOPNOTSUPP;
1851 goto out;
1852 }
1853
1854 err = nl80211_key_allowed(dev->ieee80211_ptr);
1855 if (err)
1856 goto out;
1857
1858 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1859 dev, key.idx);
1860 if (err)
1861 goto out;
1862
1863#ifdef CONFIG_CFG80211_WEXT
1864 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1865#endif
1866 }
1867
1868 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001869 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001870
Johannes Berg41ade002007-12-19 02:03:29 +01001871 return err;
1872}
1873
1874static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1875{
Johannes Berg4c476992010-10-04 21:36:35 +02001876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001877 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001878 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001879 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001880 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001881
Johannes Bergb9454e82009-07-08 13:29:08 +02001882 err = nl80211_parse_key(info, &key);
1883 if (err)
1884 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001885
Johannes Bergb9454e82009-07-08 13:29:08 +02001886 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001887 return -EINVAL;
1888
Johannes Berg41ade002007-12-19 02:03:29 +01001889 if (info->attrs[NL80211_ATTR_MAC])
1890 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1891
Johannes Berge31b8212010-10-05 19:39:30 +02001892 if (key.type == -1) {
1893 if (mac_addr)
1894 key.type = NL80211_KEYTYPE_PAIRWISE;
1895 else
1896 key.type = NL80211_KEYTYPE_GROUP;
1897 }
1898
1899 /* for now */
1900 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1901 key.type != NL80211_KEYTYPE_GROUP)
1902 return -EINVAL;
1903
Johannes Berg4c476992010-10-04 21:36:35 +02001904 if (!rdev->ops->add_key)
1905 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001906
Johannes Berge31b8212010-10-05 19:39:30 +02001907 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1908 key.type == NL80211_KEYTYPE_PAIRWISE,
1909 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001910 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001911
1912 wdev_lock(dev->ieee80211_ptr);
1913 err = nl80211_key_allowed(dev->ieee80211_ptr);
1914 if (!err)
1915 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001916 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001917 mac_addr, &key.p);
1918 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001919
Johannes Berg41ade002007-12-19 02:03:29 +01001920 return err;
1921}
1922
1923static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1924{
Johannes Berg4c476992010-10-04 21:36:35 +02001925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001926 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001927 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001928 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001929 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001930
Johannes Bergb9454e82009-07-08 13:29:08 +02001931 err = nl80211_parse_key(info, &key);
1932 if (err)
1933 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001934
1935 if (info->attrs[NL80211_ATTR_MAC])
1936 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1937
Johannes Berge31b8212010-10-05 19:39:30 +02001938 if (key.type == -1) {
1939 if (mac_addr)
1940 key.type = NL80211_KEYTYPE_PAIRWISE;
1941 else
1942 key.type = NL80211_KEYTYPE_GROUP;
1943 }
1944
1945 /* for now */
1946 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1947 key.type != NL80211_KEYTYPE_GROUP)
1948 return -EINVAL;
1949
Johannes Berg4c476992010-10-04 21:36:35 +02001950 if (!rdev->ops->del_key)
1951 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001952
Johannes Bergfffd0932009-07-08 14:22:54 +02001953 wdev_lock(dev->ieee80211_ptr);
1954 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02001955
1956 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
1957 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1958 err = -ENOENT;
1959
Johannes Bergfffd0932009-07-08 14:22:54 +02001960 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02001961 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
1962 key.type == NL80211_KEYTYPE_PAIRWISE,
1963 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01001964
Johannes Berg3d23e342009-09-29 23:27:28 +02001965#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02001966 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02001967 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02001968 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001969 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02001970 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
1971 }
1972#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02001973 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02001974
Johannes Berg41ade002007-12-19 02:03:29 +01001975 return err;
1976}
1977
Johannes Berged1b6cc2007-12-19 02:03:32 +01001978static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1979{
1980 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1981 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02001982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1983 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02001984 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001985 struct beacon_parameters params;
Johannes Berg56d18932011-05-09 18:41:15 +02001986 int haveinfo = 0, err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001987
Johannes Bergf4a11bb2009-03-27 12:40:28 +01001988 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1989 return -EINVAL;
1990
Johannes Berg074ac8d2010-09-16 14:58:22 +02001991 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02001992 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1993 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02001994
Johannes Berg56d18932011-05-09 18:41:15 +02001995 memset(&params, 0, sizeof(params));
1996
Johannes Berged1b6cc2007-12-19 02:03:32 +01001997 switch (info->genlhdr->cmd) {
1998 case NL80211_CMD_NEW_BEACON:
1999 /* these are required for NEW_BEACON */
2000 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2001 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02002002 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2003 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002004
Johannes Berg56d18932011-05-09 18:41:15 +02002005 params.interval =
2006 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2007 params.dtim_period =
2008 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2009
2010 err = cfg80211_validate_beacon_int(rdev, params.interval);
2011 if (err)
2012 return err;
2013
Johannes Berg79c97e92009-07-07 03:56:12 +02002014 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002015 break;
2016 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02002017 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002018 break;
2019 default:
2020 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02002021 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002022 }
2023
Johannes Berg4c476992010-10-04 21:36:35 +02002024 if (!call)
2025 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002026
Johannes Berged1b6cc2007-12-19 02:03:32 +01002027 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2028 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2029 params.head_len =
2030 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2031 haveinfo = 1;
2032 }
2033
2034 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2035 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2036 params.tail_len =
2037 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2038 haveinfo = 1;
2039 }
2040
Johannes Berg4c476992010-10-04 21:36:35 +02002041 if (!haveinfo)
2042 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002043
Johannes Berg56d18932011-05-09 18:41:15 +02002044 err = call(&rdev->wiphy, dev, &params);
2045 if (!err && params.interval)
2046 wdev->beacon_interval = params.interval;
2047 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002048}
2049
2050static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
2051{
Johannes Berg4c476992010-10-04 21:36:35 +02002052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2053 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002054 struct wireless_dev *wdev = dev->ieee80211_ptr;
2055 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002056
Johannes Berg4c476992010-10-04 21:36:35 +02002057 if (!rdev->ops->del_beacon)
2058 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002059
Johannes Berg074ac8d2010-09-16 14:58:22 +02002060 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002061 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2062 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002063
Johannes Berg56d18932011-05-09 18:41:15 +02002064 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
2065 if (!err)
2066 wdev->beacon_interval = 0;
2067 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002068}
2069
Johannes Berg5727ef12007-12-19 02:03:34 +01002070static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2071 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2072 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2073 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002074 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002075 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002076};
2077
Johannes Bergeccb8e82009-05-11 21:57:56 +03002078static int parse_station_flags(struct genl_info *info,
2079 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002080{
2081 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002082 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002083 int flag;
2084
Johannes Bergeccb8e82009-05-11 21:57:56 +03002085 /*
2086 * Try parsing the new attribute first so userspace
2087 * can specify both for older kernels.
2088 */
2089 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2090 if (nla) {
2091 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002092
Johannes Bergeccb8e82009-05-11 21:57:56 +03002093 sta_flags = nla_data(nla);
2094 params->sta_flags_mask = sta_flags->mask;
2095 params->sta_flags_set = sta_flags->set;
2096 if ((params->sta_flags_mask |
2097 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2098 return -EINVAL;
2099 return 0;
2100 }
2101
2102 /* if present, parse the old attribute */
2103
2104 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002105 if (!nla)
2106 return 0;
2107
2108 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2109 nla, sta_flags_policy))
2110 return -EINVAL;
2111
Johannes Bergeccb8e82009-05-11 21:57:56 +03002112 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
2113 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002114
2115 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2116 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002117 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002118
2119 return 0;
2120}
2121
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002122static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2123 int attr)
2124{
2125 struct nlattr *rate;
2126 u16 bitrate;
2127
2128 rate = nla_nest_start(msg, attr);
2129 if (!rate)
2130 goto nla_put_failure;
2131
2132 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2133 bitrate = cfg80211_calculate_bitrate(info);
2134 if (bitrate > 0)
2135 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2136
2137 if (info->flags & RATE_INFO_FLAGS_MCS)
2138 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2139 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2140 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2141 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2142 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2143
2144 nla_nest_end(msg, rate);
2145 return true;
2146
2147nla_put_failure:
2148 return false;
2149}
2150
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002151static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2152 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002153 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002154{
2155 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002156 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002157
2158 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2159 if (!hdr)
2160 return -1;
2161
2162 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2163 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2164
Johannes Bergf5ea9122009-08-07 16:17:38 +02002165 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2166
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002167 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2168 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002169 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302170 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2171 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2172 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002173 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2174 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2175 sinfo->inactive_time);
2176 if (sinfo->filled & STATION_INFO_RX_BYTES)
2177 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2178 sinfo->rx_bytes);
2179 if (sinfo->filled & STATION_INFO_TX_BYTES)
2180 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2181 sinfo->tx_bytes);
2182 if (sinfo->filled & STATION_INFO_LLID)
2183 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2184 sinfo->llid);
2185 if (sinfo->filled & STATION_INFO_PLID)
2186 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2187 sinfo->plid);
2188 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2189 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2190 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002191 if (sinfo->filled & STATION_INFO_SIGNAL)
2192 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2193 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002194 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2195 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2196 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002197 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002198 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2199 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002200 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002201 }
2202 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2203 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2204 NL80211_STA_INFO_RX_BITRATE))
2205 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002206 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002207 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2208 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2209 sinfo->rx_packets);
2210 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2211 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2212 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002213 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2214 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2215 sinfo->tx_retries);
2216 if (sinfo->filled & STATION_INFO_TX_FAILED)
2217 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2218 sinfo->tx_failed);
Paul Stewartf4263c92011-03-31 09:25:41 -07002219 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2220 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2221 if (!bss_param)
2222 goto nla_put_failure;
2223
2224 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2225 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2226 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2227 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2228 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2229 NLA_PUT_FLAG(msg,
2230 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2231 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2232 sinfo->bss_param.dtim_period);
2233 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2234 sinfo->bss_param.beacon_interval);
2235
2236 nla_nest_end(msg, bss_param);
2237 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002238 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002239
2240 return genlmsg_end(msg, hdr);
2241
2242 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002243 genlmsg_cancel(msg, hdr);
2244 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002245}
2246
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002247static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002248 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002249{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002250 struct station_info sinfo;
2251 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002252 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002253 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002254 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002255 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002256
Johannes Berg67748892010-10-04 21:14:06 +02002257 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2258 if (err)
2259 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002260
2261 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002262 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002263 goto out_err;
2264 }
2265
Johannes Bergbba95fe2008-07-29 13:22:51 +02002266 while (1) {
2267 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2268 mac_addr, &sinfo);
2269 if (err == -ENOENT)
2270 break;
2271 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002272 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002273
2274 if (nl80211_send_station(skb,
2275 NETLINK_CB(cb->skb).pid,
2276 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2277 netdev, mac_addr,
2278 &sinfo) < 0)
2279 goto out;
2280
2281 sta_idx++;
2282 }
2283
2284
2285 out:
2286 cb->args[1] = sta_idx;
2287 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002288 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002289 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002290
2291 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002292}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002293
Johannes Berg5727ef12007-12-19 02:03:34 +01002294static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2295{
Johannes Berg4c476992010-10-04 21:36:35 +02002296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2297 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002298 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002299 struct sk_buff *msg;
2300 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002301 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002302
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002303 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002304
2305 if (!info->attrs[NL80211_ATTR_MAC])
2306 return -EINVAL;
2307
2308 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2309
Johannes Berg4c476992010-10-04 21:36:35 +02002310 if (!rdev->ops->get_station)
2311 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002312
Johannes Berg79c97e92009-07-07 03:56:12 +02002313 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002314 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002315 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002316
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002317 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002318 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002319 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002320
2321 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002322 dev, mac_addr, &sinfo) < 0) {
2323 nlmsg_free(msg);
2324 return -ENOBUFS;
2325 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002326
Johannes Berg4c476992010-10-04 21:36:35 +02002327 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002328}
2329
2330/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002331 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002332 */
Johannes Berg463d0182009-07-14 00:33:35 +02002333static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002334 struct cfg80211_registered_device *rdev,
2335 struct net_device **vlan)
2336{
Johannes Berg463d0182009-07-14 00:33:35 +02002337 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002338 *vlan = NULL;
2339
2340 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002341 *vlan = dev_get_by_index(genl_info_net(info),
2342 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002343 if (!*vlan)
2344 return -ENODEV;
2345 if (!(*vlan)->ieee80211_ptr)
2346 return -EINVAL;
2347 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2348 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002349 if (!netif_running(*vlan))
2350 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002351 }
2352 return 0;
2353}
2354
2355static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2356{
Johannes Berg4c476992010-10-04 21:36:35 +02002357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002358 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002359 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002360 struct station_parameters params;
2361 u8 *mac_addr = NULL;
2362
2363 memset(&params, 0, sizeof(params));
2364
2365 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002366 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002367
2368 if (info->attrs[NL80211_ATTR_STA_AID])
2369 return -EINVAL;
2370
2371 if (!info->attrs[NL80211_ATTR_MAC])
2372 return -EINVAL;
2373
2374 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2375
2376 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2377 params.supported_rates =
2378 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2379 params.supported_rates_len =
2380 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2381 }
2382
2383 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2384 params.listen_interval =
2385 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2386
Jouni Malinen36aedc92008-08-25 11:58:58 +03002387 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2388 params.ht_capa =
2389 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2390
Johannes Bergeccb8e82009-05-11 21:57:56 +03002391 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002392 return -EINVAL;
2393
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002394 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2395 params.plink_action =
2396 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2397
Javier Cardona9c3990a2011-05-03 16:57:11 -07002398 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2399 params.plink_state =
2400 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2401
Johannes Berg463d0182009-07-14 00:33:35 +02002402 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002403 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002404 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002405
2406 /* validate settings */
2407 err = 0;
2408
2409 switch (dev->ieee80211_ptr->iftype) {
2410 case NL80211_IFTYPE_AP:
2411 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002412 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002413 /* disallow mesh-specific things */
2414 if (params.plink_action)
2415 err = -EINVAL;
2416 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002417 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002418 case NL80211_IFTYPE_STATION:
2419 /* disallow everything but AUTHORIZED flag */
2420 if (params.plink_action)
2421 err = -EINVAL;
2422 if (params.vlan)
2423 err = -EINVAL;
2424 if (params.supported_rates)
2425 err = -EINVAL;
2426 if (params.ht_capa)
2427 err = -EINVAL;
2428 if (params.listen_interval >= 0)
2429 err = -EINVAL;
2430 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2431 err = -EINVAL;
2432 break;
2433 case NL80211_IFTYPE_MESH_POINT:
2434 /* disallow things mesh doesn't support */
2435 if (params.vlan)
2436 err = -EINVAL;
2437 if (params.ht_capa)
2438 err = -EINVAL;
2439 if (params.listen_interval >= 0)
2440 err = -EINVAL;
Javier Cardonab39c48f2011-04-07 15:08:30 -07002441 if (params.sta_flags_mask &
2442 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002443 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002444 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Berga97f4422009-06-18 17:23:43 +02002445 err = -EINVAL;
2446 break;
2447 default:
2448 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002449 }
2450
Johannes Berg5727ef12007-12-19 02:03:34 +01002451 if (err)
2452 goto out;
2453
Johannes Berg79c97e92009-07-07 03:56:12 +02002454 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002455 err = -EOPNOTSUPP;
2456 goto out;
2457 }
2458
Johannes Berg79c97e92009-07-07 03:56:12 +02002459 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002460
2461 out:
2462 if (params.vlan)
2463 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002464
Johannes Berg5727ef12007-12-19 02:03:34 +01002465 return err;
2466}
2467
2468static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2469{
Johannes Berg4c476992010-10-04 21:36:35 +02002470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002471 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002472 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002473 struct station_parameters params;
2474 u8 *mac_addr = NULL;
2475
2476 memset(&params, 0, sizeof(params));
2477
2478 if (!info->attrs[NL80211_ATTR_MAC])
2479 return -EINVAL;
2480
Johannes Berg5727ef12007-12-19 02:03:34 +01002481 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2482 return -EINVAL;
2483
2484 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2485 return -EINVAL;
2486
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002487 if (!info->attrs[NL80211_ATTR_STA_AID])
2488 return -EINVAL;
2489
Johannes Berg5727ef12007-12-19 02:03:34 +01002490 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2491 params.supported_rates =
2492 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2493 params.supported_rates_len =
2494 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2495 params.listen_interval =
2496 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002497
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002498 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2499 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2500 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002501
Jouni Malinen36aedc92008-08-25 11:58:58 +03002502 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2503 params.ht_capa =
2504 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002505
Javier Cardona96b78df2011-04-07 15:08:33 -07002506 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2507 params.plink_action =
2508 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2509
Johannes Bergeccb8e82009-05-11 21:57:56 +03002510 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002511 return -EINVAL;
2512
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002513 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002514 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardona96b78df2011-04-07 15:08:33 -07002515 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002516 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2517 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002518
Johannes Berg463d0182009-07-14 00:33:35 +02002519 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002520 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002521 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002522
2523 /* validate settings */
2524 err = 0;
2525
Johannes Berg79c97e92009-07-07 03:56:12 +02002526 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002527 err = -EOPNOTSUPP;
2528 goto out;
2529 }
2530
Johannes Berg79c97e92009-07-07 03:56:12 +02002531 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002532
2533 out:
2534 if (params.vlan)
2535 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002536 return err;
2537}
2538
2539static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2540{
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2542 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002543 u8 *mac_addr = NULL;
2544
2545 if (info->attrs[NL80211_ATTR_MAC])
2546 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2547
Johannes Berge80cf852009-05-11 14:43:13 +02002548 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002549 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002550 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002551 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2552 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002553
Johannes Berg4c476992010-10-04 21:36:35 +02002554 if (!rdev->ops->del_station)
2555 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002556
Johannes Berg4c476992010-10-04 21:36:35 +02002557 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002558}
2559
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002560static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2561 int flags, struct net_device *dev,
2562 u8 *dst, u8 *next_hop,
2563 struct mpath_info *pinfo)
2564{
2565 void *hdr;
2566 struct nlattr *pinfoattr;
2567
2568 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2569 if (!hdr)
2570 return -1;
2571
2572 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2573 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2574 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2575
Johannes Bergf5ea9122009-08-07 16:17:38 +02002576 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2577
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002578 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2579 if (!pinfoattr)
2580 goto nla_put_failure;
2581 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2582 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2583 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002584 if (pinfo->filled & MPATH_INFO_SN)
2585 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2586 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002587 if (pinfo->filled & MPATH_INFO_METRIC)
2588 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2589 pinfo->metric);
2590 if (pinfo->filled & MPATH_INFO_EXPTIME)
2591 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2592 pinfo->exptime);
2593 if (pinfo->filled & MPATH_INFO_FLAGS)
2594 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2595 pinfo->flags);
2596 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2597 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2598 pinfo->discovery_timeout);
2599 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2600 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2601 pinfo->discovery_retries);
2602
2603 nla_nest_end(msg, pinfoattr);
2604
2605 return genlmsg_end(msg, hdr);
2606
2607 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002608 genlmsg_cancel(msg, hdr);
2609 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002610}
2611
2612static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002613 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002614{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002615 struct mpath_info pinfo;
2616 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002617 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002618 u8 dst[ETH_ALEN];
2619 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002620 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002621 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002622
Johannes Berg67748892010-10-04 21:14:06 +02002623 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2624 if (err)
2625 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002626
2627 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002628 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002629 goto out_err;
2630 }
2631
Jouni Malineneec60b02009-03-20 21:21:19 +02002632 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2633 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002634 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002635 }
2636
Johannes Bergbba95fe2008-07-29 13:22:51 +02002637 while (1) {
2638 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2639 dst, next_hop, &pinfo);
2640 if (err == -ENOENT)
2641 break;
2642 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002643 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002644
2645 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2646 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2647 netdev, dst, next_hop,
2648 &pinfo) < 0)
2649 goto out;
2650
2651 path_idx++;
2652 }
2653
2654
2655 out:
2656 cb->args[1] = path_idx;
2657 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002658 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002659 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002660 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002661}
2662
2663static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2664{
Johannes Berg4c476992010-10-04 21:36:35 +02002665 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002666 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002667 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002668 struct mpath_info pinfo;
2669 struct sk_buff *msg;
2670 u8 *dst = NULL;
2671 u8 next_hop[ETH_ALEN];
2672
2673 memset(&pinfo, 0, sizeof(pinfo));
2674
2675 if (!info->attrs[NL80211_ATTR_MAC])
2676 return -EINVAL;
2677
2678 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2679
Johannes Berg4c476992010-10-04 21:36:35 +02002680 if (!rdev->ops->get_mpath)
2681 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002682
Johannes Berg4c476992010-10-04 21:36:35 +02002683 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2684 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002685
Johannes Berg79c97e92009-07-07 03:56:12 +02002686 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002687 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002688 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002689
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002690 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002691 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002692 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002693
2694 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002695 dev, dst, next_hop, &pinfo) < 0) {
2696 nlmsg_free(msg);
2697 return -ENOBUFS;
2698 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002699
Johannes Berg4c476992010-10-04 21:36:35 +02002700 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002701}
2702
2703static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2704{
Johannes Berg4c476992010-10-04 21:36:35 +02002705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2706 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002707 u8 *dst = NULL;
2708 u8 *next_hop = NULL;
2709
2710 if (!info->attrs[NL80211_ATTR_MAC])
2711 return -EINVAL;
2712
2713 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2714 return -EINVAL;
2715
2716 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2717 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2718
Johannes Berg4c476992010-10-04 21:36:35 +02002719 if (!rdev->ops->change_mpath)
2720 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002721
Johannes Berg4c476992010-10-04 21:36:35 +02002722 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2723 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002724
Johannes Berg4c476992010-10-04 21:36:35 +02002725 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002726}
Johannes Berg4c476992010-10-04 21:36:35 +02002727
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002728static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2729{
Johannes Berg4c476992010-10-04 21:36:35 +02002730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2731 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002732 u8 *dst = NULL;
2733 u8 *next_hop = NULL;
2734
2735 if (!info->attrs[NL80211_ATTR_MAC])
2736 return -EINVAL;
2737
2738 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2739 return -EINVAL;
2740
2741 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2742 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2743
Johannes Berg4c476992010-10-04 21:36:35 +02002744 if (!rdev->ops->add_mpath)
2745 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002746
Johannes Berg4c476992010-10-04 21:36:35 +02002747 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2748 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002749
Johannes Berg4c476992010-10-04 21:36:35 +02002750 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002751}
2752
2753static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2754{
Johannes Berg4c476992010-10-04 21:36:35 +02002755 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2756 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002757 u8 *dst = NULL;
2758
2759 if (info->attrs[NL80211_ATTR_MAC])
2760 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2761
Johannes Berg4c476992010-10-04 21:36:35 +02002762 if (!rdev->ops->del_mpath)
2763 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002764
Johannes Berg4c476992010-10-04 21:36:35 +02002765 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002766}
2767
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002768static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2769{
Johannes Berg4c476992010-10-04 21:36:35 +02002770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2771 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002772 struct bss_parameters params;
2773
2774 memset(&params, 0, sizeof(params));
2775 /* default to not changing parameters */
2776 params.use_cts_prot = -1;
2777 params.use_short_preamble = -1;
2778 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002779 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002780 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002781
2782 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2783 params.use_cts_prot =
2784 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2785 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2786 params.use_short_preamble =
2787 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2788 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2789 params.use_short_slot_time =
2790 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002791 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2792 params.basic_rates =
2793 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2794 params.basic_rates_len =
2795 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2796 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002797 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2798 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01002799 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2800 params.ht_opmode =
2801 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002802
Johannes Berg4c476992010-10-04 21:36:35 +02002803 if (!rdev->ops->change_bss)
2804 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002805
Johannes Berg074ac8d2010-09-16 14:58:22 +02002806 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002807 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2808 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002809
Johannes Berg4c476992010-10-04 21:36:35 +02002810 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002811}
2812
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002813static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002814 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2815 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2816 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2817 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2818 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2819 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2820};
2821
2822static int parse_reg_rule(struct nlattr *tb[],
2823 struct ieee80211_reg_rule *reg_rule)
2824{
2825 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2826 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2827
2828 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2829 return -EINVAL;
2830 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2831 return -EINVAL;
2832 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2833 return -EINVAL;
2834 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2835 return -EINVAL;
2836 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2837 return -EINVAL;
2838
2839 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2840
2841 freq_range->start_freq_khz =
2842 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2843 freq_range->end_freq_khz =
2844 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2845 freq_range->max_bandwidth_khz =
2846 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2847
2848 power_rule->max_eirp =
2849 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2850
2851 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2852 power_rule->max_antenna_gain =
2853 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2854
2855 return 0;
2856}
2857
2858static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2859{
2860 int r;
2861 char *data = NULL;
2862
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002863 /*
2864 * You should only get this when cfg80211 hasn't yet initialized
2865 * completely when built-in to the kernel right between the time
2866 * window between nl80211_init() and regulatory_init(), if that is
2867 * even possible.
2868 */
2869 mutex_lock(&cfg80211_mutex);
2870 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002871 mutex_unlock(&cfg80211_mutex);
2872 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002873 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002874 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002875
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002876 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2877 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002878
2879 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2880
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002881 r = regulatory_hint_user(data);
2882
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002883 return r;
2884}
2885
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002886static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01002887 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002888{
Johannes Berg4c476992010-10-04 21:36:35 +02002889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02002890 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01002891 struct wireless_dev *wdev = dev->ieee80211_ptr;
2892 struct mesh_config cur_params;
2893 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002894 void *hdr;
2895 struct nlattr *pinfoattr;
2896 struct sk_buff *msg;
2897
Johannes Berg29cbe682010-12-03 09:20:44 +01002898 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2899 return -EOPNOTSUPP;
2900
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002901 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02002902 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02002903
Johannes Berg29cbe682010-12-03 09:20:44 +01002904 wdev_lock(wdev);
2905 /* If not connected, get default parameters */
2906 if (!wdev->mesh_id_len)
2907 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
2908 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002909 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01002910 &cur_params);
2911 wdev_unlock(wdev);
2912
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002913 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002914 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002915
2916 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002917 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002918 if (!msg)
2919 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002920 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002921 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002922 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01002923 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002924 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002925 if (!pinfoattr)
2926 goto nla_put_failure;
2927 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2928 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2929 cur_params.dot11MeshRetryTimeout);
2930 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2931 cur_params.dot11MeshConfirmTimeout);
2932 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2933 cur_params.dot11MeshHoldingTimeout);
2934 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2935 cur_params.dot11MeshMaxPeerLinks);
2936 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2937 cur_params.dot11MeshMaxRetries);
2938 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2939 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01002940 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
2941 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002942 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2943 cur_params.auto_open_plinks);
2944 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2945 cur_params.dot11MeshHWMPmaxPREQretries);
2946 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2947 cur_params.path_refresh_time);
2948 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2949 cur_params.min_discovery_timeout);
2950 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2951 cur_params.dot11MeshHWMPactivePathTimeout);
2952 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2953 cur_params.dot11MeshHWMPpreqMinInterval);
2954 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2955 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00002956 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
2957 cur_params.dot11MeshHWMPRootMode);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002958 nla_nest_end(msg, pinfoattr);
2959 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002960 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002961
Johannes Berg3b858752009-03-12 09:55:09 +01002962 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002963 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01002964 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04002965 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02002966 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002967}
2968
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002969static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002970 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2971 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2972 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2973 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2974 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2975 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01002976 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002977 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2978
2979 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2980 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2981 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2982 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2983 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2984 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2985};
2986
Javier Cardonac80d5452010-12-16 17:37:49 -08002987static const struct nla_policy
2988 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
2989 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
2990 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07002991 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07002992 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08002993 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07002994 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08002995};
2996
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002997static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002998 struct mesh_config *cfg,
2999 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003000{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003001 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003002 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003003
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003004#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3005do {\
3006 if (table[attr_num]) {\
3007 cfg->param = nla_fn(table[attr_num]); \
3008 mask |= (1 << (attr_num - 1)); \
3009 } \
3010} while (0);\
3011
3012
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003013 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003014 return -EINVAL;
3015 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003016 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003017 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003018 return -EINVAL;
3019
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003020 /* This makes sure that there aren't more than 32 mesh config
3021 * parameters (otherwise our bitfield scheme would not work.) */
3022 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3023
3024 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003025 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3026 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3027 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3028 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3029 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3030 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3031 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3032 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3033 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3034 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3035 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3036 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003037 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3038 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003039 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3040 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3041 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3042 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3043 nla_get_u8);
3044 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3045 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3046 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3047 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3048 nla_get_u16);
3049 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3050 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3051 nla_get_u32);
3052 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3053 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3054 nla_get_u16);
3055 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3056 dot11MeshHWMPnetDiameterTraversalTime,
3057 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3058 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003059 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3060 dot11MeshHWMPRootMode, mask,
3061 NL80211_MESHCONF_HWMP_ROOTMODE,
3062 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003063 if (mask_out)
3064 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003065
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003066 return 0;
3067
3068#undef FILL_IN_MESH_PARAM_IF_SET
3069}
3070
Javier Cardonac80d5452010-12-16 17:37:49 -08003071static int nl80211_parse_mesh_setup(struct genl_info *info,
3072 struct mesh_setup *setup)
3073{
3074 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3075
3076 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3077 return -EINVAL;
3078 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3079 info->attrs[NL80211_ATTR_MESH_SETUP],
3080 nl80211_mesh_setup_params_policy))
3081 return -EINVAL;
3082
3083 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3084 setup->path_sel_proto =
3085 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3086 IEEE80211_PATH_PROTOCOL_VENDOR :
3087 IEEE80211_PATH_PROTOCOL_HWMP;
3088
3089 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3090 setup->path_metric =
3091 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3092 IEEE80211_PATH_METRIC_VENDOR :
3093 IEEE80211_PATH_METRIC_AIRTIME;
3094
Javier Cardona581a8b02011-04-07 15:08:27 -07003095
3096 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003097 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003098 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003099 if (!is_valid_ie_attr(ieattr))
3100 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003101 setup->ie = nla_data(ieattr);
3102 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003103 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003104 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3105 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003106
3107 return 0;
3108}
3109
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003110static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003111 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003112{
3113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3114 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003115 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003116 struct mesh_config cfg;
3117 u32 mask;
3118 int err;
3119
Johannes Berg29cbe682010-12-03 09:20:44 +01003120 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3121 return -EOPNOTSUPP;
3122
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003123 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003124 return -EOPNOTSUPP;
3125
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003126 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003127 if (err)
3128 return err;
3129
Johannes Berg29cbe682010-12-03 09:20:44 +01003130 wdev_lock(wdev);
3131 if (!wdev->mesh_id_len)
3132 err = -ENOLINK;
3133
3134 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003135 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003136 mask, &cfg);
3137
3138 wdev_unlock(wdev);
3139
3140 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003141}
3142
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003143static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3144{
3145 struct sk_buff *msg;
3146 void *hdr = NULL;
3147 struct nlattr *nl_reg_rules;
3148 unsigned int i;
3149 int err = -EINVAL;
3150
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003151 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003152
3153 if (!cfg80211_regdomain)
3154 goto out;
3155
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003156 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003157 if (!msg) {
3158 err = -ENOBUFS;
3159 goto out;
3160 }
3161
3162 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3163 NL80211_CMD_GET_REG);
3164 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003165 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003166
3167 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3168 cfg80211_regdomain->alpha2);
3169
3170 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3171 if (!nl_reg_rules)
3172 goto nla_put_failure;
3173
3174 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3175 struct nlattr *nl_reg_rule;
3176 const struct ieee80211_reg_rule *reg_rule;
3177 const struct ieee80211_freq_range *freq_range;
3178 const struct ieee80211_power_rule *power_rule;
3179
3180 reg_rule = &cfg80211_regdomain->reg_rules[i];
3181 freq_range = &reg_rule->freq_range;
3182 power_rule = &reg_rule->power_rule;
3183
3184 nl_reg_rule = nla_nest_start(msg, i);
3185 if (!nl_reg_rule)
3186 goto nla_put_failure;
3187
3188 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3189 reg_rule->flags);
3190 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3191 freq_range->start_freq_khz);
3192 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3193 freq_range->end_freq_khz);
3194 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3195 freq_range->max_bandwidth_khz);
3196 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3197 power_rule->max_antenna_gain);
3198 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3199 power_rule->max_eirp);
3200
3201 nla_nest_end(msg, nl_reg_rule);
3202 }
3203
3204 nla_nest_end(msg, nl_reg_rules);
3205
3206 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003207 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003208 goto out;
3209
3210nla_put_failure:
3211 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003212put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003213 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003214 err = -EMSGSIZE;
3215out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003216 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003217 return err;
3218}
3219
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003220static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3221{
3222 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3223 struct nlattr *nl_reg_rule;
3224 char *alpha2 = NULL;
3225 int rem_reg_rules = 0, r = 0;
3226 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3227 struct ieee80211_regdomain *rd = NULL;
3228
3229 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3230 return -EINVAL;
3231
3232 if (!info->attrs[NL80211_ATTR_REG_RULES])
3233 return -EINVAL;
3234
3235 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3236
3237 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3238 rem_reg_rules) {
3239 num_rules++;
3240 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003241 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003242 }
3243
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003244 mutex_lock(&cfg80211_mutex);
3245
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003246 if (!reg_is_valid_request(alpha2)) {
3247 r = -EINVAL;
3248 goto bad_reg;
3249 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003250
3251 size_of_regd = sizeof(struct ieee80211_regdomain) +
3252 (num_rules * sizeof(struct ieee80211_reg_rule));
3253
3254 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003255 if (!rd) {
3256 r = -ENOMEM;
3257 goto bad_reg;
3258 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003259
3260 rd->n_reg_rules = num_rules;
3261 rd->alpha2[0] = alpha2[0];
3262 rd->alpha2[1] = alpha2[1];
3263
3264 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3265 rem_reg_rules) {
3266 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3267 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3268 reg_rule_policy);
3269 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3270 if (r)
3271 goto bad_reg;
3272
3273 rule_idx++;
3274
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003275 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3276 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003277 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003278 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003279 }
3280
3281 BUG_ON(rule_idx != num_rules);
3282
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003283 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003284
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003285 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003286
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003287 return r;
3288
Johannes Bergd2372b32008-10-24 20:32:20 +02003289 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003290 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003291 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003292 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003293}
3294
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003295static int validate_scan_freqs(struct nlattr *freqs)
3296{
3297 struct nlattr *attr1, *attr2;
3298 int n_channels = 0, tmp1, tmp2;
3299
3300 nla_for_each_nested(attr1, freqs, tmp1) {
3301 n_channels++;
3302 /*
3303 * Some hardware has a limited channel list for
3304 * scanning, and it is pretty much nonsensical
3305 * to scan for a channel twice, so disallow that
3306 * and don't require drivers to check that the
3307 * channel list they get isn't longer than what
3308 * they can scan, as long as they can scan all
3309 * the channels they registered at once.
3310 */
3311 nla_for_each_nested(attr2, freqs, tmp2)
3312 if (attr1 != attr2 &&
3313 nla_get_u32(attr1) == nla_get_u32(attr2))
3314 return 0;
3315 }
3316
3317 return n_channels;
3318}
3319
Johannes Berg2a519312009-02-10 21:25:55 +01003320static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3321{
Johannes Berg4c476992010-10-04 21:36:35 +02003322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3323 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003324 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003325 struct nlattr *attr;
3326 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003327 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003328 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003329
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003330 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3331 return -EINVAL;
3332
Johannes Berg79c97e92009-07-07 03:56:12 +02003333 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003334
Johannes Berg4c476992010-10-04 21:36:35 +02003335 if (!rdev->ops->scan)
3336 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003337
Johannes Berg4c476992010-10-04 21:36:35 +02003338 if (rdev->scan_req)
3339 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003340
3341 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003342 n_channels = validate_scan_freqs(
3343 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003344 if (!n_channels)
3345 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003346 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003347 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003348 n_channels = 0;
3349
Johannes Berg2a519312009-02-10 21:25:55 +01003350 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3351 if (wiphy->bands[band])
3352 n_channels += wiphy->bands[band]->n_channels;
3353 }
3354
3355 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3356 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3357 n_ssids++;
3358
Johannes Berg4c476992010-10-04 21:36:35 +02003359 if (n_ssids > wiphy->max_scan_ssids)
3360 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003361
Jouni Malinen70692ad2009-02-16 19:39:13 +02003362 if (info->attrs[NL80211_ATTR_IE])
3363 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3364 else
3365 ie_len = 0;
3366
Johannes Berg4c476992010-10-04 21:36:35 +02003367 if (ie_len > wiphy->max_scan_ie_len)
3368 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003369
Johannes Berg2a519312009-02-10 21:25:55 +01003370 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003371 + sizeof(*request->ssids) * n_ssids
3372 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003373 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003374 if (!request)
3375 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003376
Johannes Berg2a519312009-02-10 21:25:55 +01003377 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003378 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003379 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003380 if (ie_len) {
3381 if (request->ssids)
3382 request->ie = (void *)(request->ssids + n_ssids);
3383 else
3384 request->ie = (void *)(request->channels + n_channels);
3385 }
Johannes Berg2a519312009-02-10 21:25:55 +01003386
Johannes Berg584991d2009-11-02 13:32:03 +01003387 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003388 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3389 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003390 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003391 struct ieee80211_channel *chan;
3392
3393 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3394
3395 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003396 err = -EINVAL;
3397 goto out_free;
3398 }
Johannes Berg584991d2009-11-02 13:32:03 +01003399
3400 /* ignore disabled channels */
3401 if (chan->flags & IEEE80211_CHAN_DISABLED)
3402 continue;
3403
3404 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003405 i++;
3406 }
3407 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003408 enum ieee80211_band band;
3409
Johannes Berg2a519312009-02-10 21:25:55 +01003410 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003411 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3412 int j;
3413 if (!wiphy->bands[band])
3414 continue;
3415 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003416 struct ieee80211_channel *chan;
3417
3418 chan = &wiphy->bands[band]->channels[j];
3419
3420 if (chan->flags & IEEE80211_CHAN_DISABLED)
3421 continue;
3422
3423 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003424 i++;
3425 }
3426 }
3427 }
3428
Johannes Berg584991d2009-11-02 13:32:03 +01003429 if (!i) {
3430 err = -EINVAL;
3431 goto out_free;
3432 }
3433
3434 request->n_channels = i;
3435
Johannes Berg2a519312009-02-10 21:25:55 +01003436 i = 0;
3437 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3438 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003439 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003440 err = -EINVAL;
3441 goto out_free;
3442 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003443 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003444 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003445 i++;
3446 }
3447 }
3448
Jouni Malinen70692ad2009-02-16 19:39:13 +02003449 if (info->attrs[NL80211_ATTR_IE]) {
3450 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003451 memcpy((void *)request->ie,
3452 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003453 request->ie_len);
3454 }
3455
Johannes Berg34850ab2011-07-18 18:08:35 +02003456 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
3457 request->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
3458
3459 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3460 nla_for_each_nested(attr,
3461 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3462 tmp) {
3463 enum ieee80211_band band = nla_type(attr);
3464
3465 if (band < 0 || band > IEEE80211_NUM_BANDS) {
3466 err = -EINVAL;
3467 goto out_free;
3468 }
3469 err = ieee80211_get_ratemask(wiphy->bands[band],
3470 nla_data(attr),
3471 nla_len(attr),
3472 &request->rates[band]);
3473 if (err)
3474 goto out_free;
3475 }
3476 }
3477
Johannes Berg463d0182009-07-14 00:33:35 +02003478 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003479 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003480
Johannes Berg79c97e92009-07-07 03:56:12 +02003481 rdev->scan_req = request;
3482 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003483
Johannes Berg463d0182009-07-14 00:33:35 +02003484 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003485 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003486 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003487 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003488 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003489 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003490 kfree(request);
3491 }
Johannes Berg3b858752009-03-12 09:55:09 +01003492
Johannes Berg2a519312009-02-10 21:25:55 +01003493 return err;
3494}
3495
Luciano Coelho807f8a82011-05-11 17:09:35 +03003496static int nl80211_start_sched_scan(struct sk_buff *skb,
3497 struct genl_info *info)
3498{
3499 struct cfg80211_sched_scan_request *request;
3500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3501 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003502 struct nlattr *attr;
3503 struct wiphy *wiphy;
3504 int err, tmp, n_ssids = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003505 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003506 enum ieee80211_band band;
3507 size_t ie_len;
3508
3509 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3510 !rdev->ops->sched_scan_start)
3511 return -EOPNOTSUPP;
3512
3513 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3514 return -EINVAL;
3515
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003516 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3517 return -EINVAL;
3518
3519 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3520 if (interval == 0)
3521 return -EINVAL;
3522
Luciano Coelho807f8a82011-05-11 17:09:35 +03003523 wiphy = &rdev->wiphy;
3524
3525 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3526 n_channels = validate_scan_freqs(
3527 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3528 if (!n_channels)
3529 return -EINVAL;
3530 } else {
3531 n_channels = 0;
3532
3533 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3534 if (wiphy->bands[band])
3535 n_channels += wiphy->bands[band]->n_channels;
3536 }
3537
3538 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3539 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3540 tmp)
3541 n_ssids++;
3542
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003543 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003544 return -EINVAL;
3545
3546 if (info->attrs[NL80211_ATTR_IE])
3547 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3548 else
3549 ie_len = 0;
3550
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003551 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003552 return -EINVAL;
3553
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003554 mutex_lock(&rdev->sched_scan_mtx);
3555
3556 if (rdev->sched_scan_req) {
3557 err = -EINPROGRESS;
3558 goto out;
3559 }
3560
Luciano Coelho807f8a82011-05-11 17:09:35 +03003561 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003562 + sizeof(*request->ssids) * n_ssids
3563 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003564 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003565 if (!request) {
3566 err = -ENOMEM;
3567 goto out;
3568 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003569
3570 if (n_ssids)
3571 request->ssids = (void *)&request->channels[n_channels];
3572 request->n_ssids = n_ssids;
3573 if (ie_len) {
3574 if (request->ssids)
3575 request->ie = (void *)(request->ssids + n_ssids);
3576 else
3577 request->ie = (void *)(request->channels + n_channels);
3578 }
3579
3580 i = 0;
3581 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3582 /* user specified, bail out if channel not found */
3583 nla_for_each_nested(attr,
3584 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3585 tmp) {
3586 struct ieee80211_channel *chan;
3587
3588 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3589
3590 if (!chan) {
3591 err = -EINVAL;
3592 goto out_free;
3593 }
3594
3595 /* ignore disabled channels */
3596 if (chan->flags & IEEE80211_CHAN_DISABLED)
3597 continue;
3598
3599 request->channels[i] = chan;
3600 i++;
3601 }
3602 } else {
3603 /* all channels */
3604 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3605 int j;
3606 if (!wiphy->bands[band])
3607 continue;
3608 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3609 struct ieee80211_channel *chan;
3610
3611 chan = &wiphy->bands[band]->channels[j];
3612
3613 if (chan->flags & IEEE80211_CHAN_DISABLED)
3614 continue;
3615
3616 request->channels[i] = chan;
3617 i++;
3618 }
3619 }
3620 }
3621
3622 if (!i) {
3623 err = -EINVAL;
3624 goto out_free;
3625 }
3626
3627 request->n_channels = i;
3628
3629 i = 0;
3630 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3631 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3632 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003633 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03003634 err = -EINVAL;
3635 goto out_free;
3636 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003637 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003638 memcpy(request->ssids[i].ssid, nla_data(attr),
3639 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03003640 i++;
3641 }
3642 }
3643
3644 if (info->attrs[NL80211_ATTR_IE]) {
3645 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3646 memcpy((void *)request->ie,
3647 nla_data(info->attrs[NL80211_ATTR_IE]),
3648 request->ie_len);
3649 }
3650
3651 request->dev = dev;
3652 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003653 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003654
3655 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3656 if (!err) {
3657 rdev->sched_scan_req = request;
3658 nl80211_send_sched_scan(rdev, dev,
3659 NL80211_CMD_START_SCHED_SCAN);
3660 goto out;
3661 }
3662
3663out_free:
3664 kfree(request);
3665out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003666 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003667 return err;
3668}
3669
3670static int nl80211_stop_sched_scan(struct sk_buff *skb,
3671 struct genl_info *info)
3672{
3673 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003674 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003675
3676 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3677 !rdev->ops->sched_scan_stop)
3678 return -EOPNOTSUPP;
3679
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003680 mutex_lock(&rdev->sched_scan_mtx);
3681 err = __cfg80211_stop_sched_scan(rdev, false);
3682 mutex_unlock(&rdev->sched_scan_mtx);
3683
3684 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003685}
3686
Johannes Berg9720bb32011-06-21 09:45:33 +02003687static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3688 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003689 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003690 struct wireless_dev *wdev,
3691 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003692{
Johannes Berg48ab9052009-07-10 18:42:31 +02003693 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003694 void *hdr;
3695 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003696 int i;
3697
3698 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003699
Johannes Berg9720bb32011-06-21 09:45:33 +02003700 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003701 NL80211_CMD_NEW_SCAN_RESULTS);
3702 if (!hdr)
3703 return -1;
3704
Johannes Berg9720bb32011-06-21 09:45:33 +02003705 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
3706
Johannes Bergf5ea9122009-08-07 16:17:38 +02003707 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003708 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003709
3710 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3711 if (!bss)
3712 goto nla_put_failure;
3713 if (!is_zero_ether_addr(res->bssid))
3714 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3715 if (res->information_elements && res->len_information_elements)
3716 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3717 res->len_information_elements,
3718 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003719 if (res->beacon_ies && res->len_beacon_ies &&
3720 res->beacon_ies != res->information_elements)
3721 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3722 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003723 if (res->tsf)
3724 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3725 if (res->beacon_interval)
3726 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3727 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3728 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003729 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3730 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003731
Johannes Berg77965c92009-02-18 18:45:06 +01003732 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003733 case CFG80211_SIGNAL_TYPE_MBM:
3734 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3735 break;
3736 case CFG80211_SIGNAL_TYPE_UNSPEC:
3737 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3738 break;
3739 default:
3740 break;
3741 }
3742
Johannes Berg48ab9052009-07-10 18:42:31 +02003743 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003744 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003745 case NL80211_IFTYPE_STATION:
3746 if (intbss == wdev->current_bss)
3747 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3748 NL80211_BSS_STATUS_ASSOCIATED);
3749 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3750 if (intbss != wdev->auth_bsses[i])
3751 continue;
3752 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3753 NL80211_BSS_STATUS_AUTHENTICATED);
3754 break;
3755 }
3756 break;
3757 case NL80211_IFTYPE_ADHOC:
3758 if (intbss == wdev->current_bss)
3759 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3760 NL80211_BSS_STATUS_IBSS_JOINED);
3761 break;
3762 default:
3763 break;
3764 }
3765
Johannes Berg2a519312009-02-10 21:25:55 +01003766 nla_nest_end(msg, bss);
3767
3768 return genlmsg_end(msg, hdr);
3769
3770 nla_put_failure:
3771 genlmsg_cancel(msg, hdr);
3772 return -EMSGSIZE;
3773}
3774
3775static int nl80211_dump_scan(struct sk_buff *skb,
3776 struct netlink_callback *cb)
3777{
Johannes Berg48ab9052009-07-10 18:42:31 +02003778 struct cfg80211_registered_device *rdev;
3779 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01003780 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02003781 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01003782 int start = cb->args[1], idx = 0;
3783 int err;
3784
Johannes Berg67748892010-10-04 21:14:06 +02003785 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
3786 if (err)
3787 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01003788
Johannes Berg48ab9052009-07-10 18:42:31 +02003789 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01003790
Johannes Berg48ab9052009-07-10 18:42:31 +02003791 wdev_lock(wdev);
3792 spin_lock_bh(&rdev->bss_lock);
3793 cfg80211_bss_expire(rdev);
3794
Johannes Berg9720bb32011-06-21 09:45:33 +02003795 cb->seq = rdev->bss_generation;
3796
Johannes Berg48ab9052009-07-10 18:42:31 +02003797 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01003798 if (++idx <= start)
3799 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02003800 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01003801 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02003802 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01003803 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02003804 break;
Johannes Berg2a519312009-02-10 21:25:55 +01003805 }
3806 }
3807
Johannes Berg48ab9052009-07-10 18:42:31 +02003808 spin_unlock_bh(&rdev->bss_lock);
3809 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003810
3811 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02003812 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003813
Johannes Berg67748892010-10-04 21:14:06 +02003814 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01003815}
3816
Holger Schurig61fa7132009-11-11 12:25:40 +01003817static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3818 int flags, struct net_device *dev,
3819 struct survey_info *survey)
3820{
3821 void *hdr;
3822 struct nlattr *infoattr;
3823
Holger Schurig61fa7132009-11-11 12:25:40 +01003824 hdr = nl80211hdr_put(msg, pid, seq, flags,
3825 NL80211_CMD_NEW_SURVEY_RESULTS);
3826 if (!hdr)
3827 return -ENOMEM;
3828
3829 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3830
3831 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
3832 if (!infoattr)
3833 goto nla_put_failure;
3834
3835 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
3836 survey->channel->center_freq);
3837 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3838 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3839 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02003840 if (survey->filled & SURVEY_INFO_IN_USE)
3841 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02003842 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
3843 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
3844 survey->channel_time);
3845 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
3846 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
3847 survey->channel_time_busy);
3848 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
3849 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
3850 survey->channel_time_ext_busy);
3851 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
3852 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
3853 survey->channel_time_rx);
3854 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
3855 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
3856 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01003857
3858 nla_nest_end(msg, infoattr);
3859
3860 return genlmsg_end(msg, hdr);
3861
3862 nla_put_failure:
3863 genlmsg_cancel(msg, hdr);
3864 return -EMSGSIZE;
3865}
3866
3867static int nl80211_dump_survey(struct sk_buff *skb,
3868 struct netlink_callback *cb)
3869{
3870 struct survey_info survey;
3871 struct cfg80211_registered_device *dev;
3872 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01003873 int survey_idx = cb->args[1];
3874 int res;
3875
Johannes Berg67748892010-10-04 21:14:06 +02003876 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3877 if (res)
3878 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01003879
3880 if (!dev->ops->dump_survey) {
3881 res = -EOPNOTSUPP;
3882 goto out_err;
3883 }
3884
3885 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07003886 struct ieee80211_channel *chan;
3887
Holger Schurig61fa7132009-11-11 12:25:40 +01003888 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
3889 &survey);
3890 if (res == -ENOENT)
3891 break;
3892 if (res)
3893 goto out_err;
3894
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07003895 /* Survey without a channel doesn't make sense */
3896 if (!survey.channel) {
3897 res = -EINVAL;
3898 goto out;
3899 }
3900
3901 chan = ieee80211_get_channel(&dev->wiphy,
3902 survey.channel->center_freq);
3903 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
3904 survey_idx++;
3905 continue;
3906 }
3907
Holger Schurig61fa7132009-11-11 12:25:40 +01003908 if (nl80211_send_survey(skb,
3909 NETLINK_CB(cb->skb).pid,
3910 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3911 netdev,
3912 &survey) < 0)
3913 goto out;
3914 survey_idx++;
3915 }
3916
3917 out:
3918 cb->args[1] = survey_idx;
3919 res = skb->len;
3920 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003921 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01003922 return res;
3923}
3924
Jouni Malinen255e7372009-03-20 21:21:17 +02003925static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
3926{
Samuel Ortizb23aa672009-07-01 21:26:54 +02003927 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02003928}
3929
Samuel Ortizb23aa672009-07-01 21:26:54 +02003930static bool nl80211_valid_wpa_versions(u32 wpa_versions)
3931{
3932 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
3933 NL80211_WPA_VERSION_2));
3934}
3935
3936static bool nl80211_valid_akm_suite(u32 akm)
3937{
3938 return akm == WLAN_AKM_SUITE_8021X ||
3939 akm == WLAN_AKM_SUITE_PSK;
3940}
3941
3942static bool nl80211_valid_cipher_suite(u32 cipher)
3943{
3944 return cipher == WLAN_CIPHER_SUITE_WEP40 ||
3945 cipher == WLAN_CIPHER_SUITE_WEP104 ||
3946 cipher == WLAN_CIPHER_SUITE_TKIP ||
3947 cipher == WLAN_CIPHER_SUITE_CCMP ||
3948 cipher == WLAN_CIPHER_SUITE_AES_CMAC;
3949}
3950
3951
Jouni Malinen636a5d32009-03-19 13:39:22 +02003952static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3953{
Johannes Berg4c476992010-10-04 21:36:35 +02003954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3955 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003956 struct ieee80211_channel *chan;
3957 const u8 *bssid, *ssid, *ie = NULL;
3958 int err, ssid_len, ie_len = 0;
3959 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02003960 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003961 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003962
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003963 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3964 return -EINVAL;
3965
3966 if (!info->attrs[NL80211_ATTR_MAC])
3967 return -EINVAL;
3968
Jouni Malinen17780922009-03-27 20:52:47 +02003969 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
3970 return -EINVAL;
3971
Johannes Berg19957bb2009-07-02 17:20:43 +02003972 if (!info->attrs[NL80211_ATTR_SSID])
3973 return -EINVAL;
3974
3975 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
3976 return -EINVAL;
3977
Johannes Bergfffd0932009-07-08 14:22:54 +02003978 err = nl80211_parse_key(info, &key);
3979 if (err)
3980 return err;
3981
3982 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02003983 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
3984 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003985 if (!key.p.key || !key.p.key_len)
3986 return -EINVAL;
3987 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
3988 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
3989 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
3990 key.p.key_len != WLAN_KEY_LEN_WEP104))
3991 return -EINVAL;
3992 if (key.idx > 4)
3993 return -EINVAL;
3994 } else {
3995 key.p.key_len = 0;
3996 key.p.key = NULL;
3997 }
3998
Johannes Bergafea0b72010-08-10 09:46:42 +02003999 if (key.idx >= 0) {
4000 int i;
4001 bool ok = false;
4002 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4003 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4004 ok = true;
4005 break;
4006 }
4007 }
Johannes Berg4c476992010-10-04 21:36:35 +02004008 if (!ok)
4009 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004010 }
4011
Johannes Berg4c476992010-10-04 21:36:35 +02004012 if (!rdev->ops->auth)
4013 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004014
Johannes Berg074ac8d2010-09-16 14:58:22 +02004015 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004016 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4017 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004018
Johannes Berg19957bb2009-07-02 17:20:43 +02004019 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004020 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004021 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004022 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4023 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004024
Johannes Berg19957bb2009-07-02 17:20:43 +02004025 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4026 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4027
4028 if (info->attrs[NL80211_ATTR_IE]) {
4029 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4030 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4031 }
4032
4033 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004034 if (!nl80211_valid_auth_type(auth_type))
4035 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004036
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004037 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4038
Johannes Berg4c476992010-10-04 21:36:35 +02004039 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4040 ssid, ssid_len, ie, ie_len,
4041 key.p.key, key.p.key_len, key.idx,
4042 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004043}
4044
Johannes Bergc0692b82010-08-27 14:26:53 +03004045static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4046 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004047 struct cfg80211_crypto_settings *settings,
4048 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004049{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004050 memset(settings, 0, sizeof(*settings));
4051
Samuel Ortizb23aa672009-07-01 21:26:54 +02004052 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4053
Johannes Bergc0692b82010-08-27 14:26:53 +03004054 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4055 u16 proto;
4056 proto = nla_get_u16(
4057 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4058 settings->control_port_ethertype = cpu_to_be16(proto);
4059 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4060 proto != ETH_P_PAE)
4061 return -EINVAL;
4062 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4063 settings->control_port_no_encrypt = true;
4064 } else
4065 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4066
Samuel Ortizb23aa672009-07-01 21:26:54 +02004067 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4068 void *data;
4069 int len, i;
4070
4071 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4072 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4073 settings->n_ciphers_pairwise = len / sizeof(u32);
4074
4075 if (len % sizeof(u32))
4076 return -EINVAL;
4077
Johannes Berg3dc27d22009-07-02 21:36:37 +02004078 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004079 return -EINVAL;
4080
4081 memcpy(settings->ciphers_pairwise, data, len);
4082
4083 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4084 if (!nl80211_valid_cipher_suite(
4085 settings->ciphers_pairwise[i]))
4086 return -EINVAL;
4087 }
4088
4089 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4090 settings->cipher_group =
4091 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
4092 if (!nl80211_valid_cipher_suite(settings->cipher_group))
4093 return -EINVAL;
4094 }
4095
4096 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4097 settings->wpa_versions =
4098 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4099 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4100 return -EINVAL;
4101 }
4102
4103 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4104 void *data;
4105 int len, i;
4106
4107 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4108 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4109 settings->n_akm_suites = len / sizeof(u32);
4110
4111 if (len % sizeof(u32))
4112 return -EINVAL;
4113
4114 memcpy(settings->akm_suites, data, len);
4115
4116 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4117 if (!nl80211_valid_akm_suite(settings->akm_suites[i]))
4118 return -EINVAL;
4119 }
4120
4121 return 0;
4122}
4123
Jouni Malinen636a5d32009-03-19 13:39:22 +02004124static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4125{
Johannes Berg4c476992010-10-04 21:36:35 +02004126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4127 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004128 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004129 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004130 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004131 int err, ssid_len, ie_len = 0;
4132 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004133
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004134 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4135 return -EINVAL;
4136
4137 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004138 !info->attrs[NL80211_ATTR_SSID] ||
4139 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004140 return -EINVAL;
4141
Johannes Berg4c476992010-10-04 21:36:35 +02004142 if (!rdev->ops->assoc)
4143 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004144
Johannes Berg074ac8d2010-09-16 14:58:22 +02004145 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004146 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4147 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004148
Johannes Berg19957bb2009-07-02 17:20:43 +02004149 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004150
Johannes Berg19957bb2009-07-02 17:20:43 +02004151 chan = ieee80211_get_channel(&rdev->wiphy,
4152 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004153 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4154 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004155
Johannes Berg19957bb2009-07-02 17:20:43 +02004156 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4157 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004158
4159 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004160 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4161 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004162 }
4163
Jouni Malinendc6382c2009-05-06 22:09:37 +03004164 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004165 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004166 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004167 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004168 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004169 else if (mfp != NL80211_MFP_NO)
4170 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004171 }
4172
Johannes Berg3e5d7642009-07-07 14:37:26 +02004173 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4174 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4175
Johannes Bergc0692b82010-08-27 14:26:53 +03004176 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004177 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004178 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4179 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02004180 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004181
Jouni Malinen636a5d32009-03-19 13:39:22 +02004182 return err;
4183}
4184
4185static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4186{
Johannes Berg4c476992010-10-04 21:36:35 +02004187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4188 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004189 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004190 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004191 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004192 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004193
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004194 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4195 return -EINVAL;
4196
4197 if (!info->attrs[NL80211_ATTR_MAC])
4198 return -EINVAL;
4199
4200 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4201 return -EINVAL;
4202
Johannes Berg4c476992010-10-04 21:36:35 +02004203 if (!rdev->ops->deauth)
4204 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004205
Johannes Berg074ac8d2010-09-16 14:58:22 +02004206 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004207 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4208 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004209
Johannes Berg19957bb2009-07-02 17:20:43 +02004210 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004211
Johannes Berg19957bb2009-07-02 17:20:43 +02004212 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4213 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004214 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004215 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004216 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004217
4218 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004219 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4220 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004221 }
4222
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004223 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4224
Johannes Berg4c476992010-10-04 21:36:35 +02004225 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4226 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004227}
4228
4229static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4230{
Johannes Berg4c476992010-10-04 21:36:35 +02004231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4232 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004233 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004234 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004235 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004236 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004237
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004238 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4239 return -EINVAL;
4240
4241 if (!info->attrs[NL80211_ATTR_MAC])
4242 return -EINVAL;
4243
4244 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4245 return -EINVAL;
4246
Johannes Berg4c476992010-10-04 21:36:35 +02004247 if (!rdev->ops->disassoc)
4248 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004249
Johannes Berg074ac8d2010-09-16 14:58:22 +02004250 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004251 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4252 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004253
Johannes Berg19957bb2009-07-02 17:20:43 +02004254 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004255
Johannes Berg19957bb2009-07-02 17:20:43 +02004256 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4257 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004258 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004259 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004260 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004261
4262 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004263 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4264 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004265 }
4266
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004267 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4268
Johannes Berg4c476992010-10-04 21:36:35 +02004269 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4270 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004271}
4272
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004273static bool
4274nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4275 int mcast_rate[IEEE80211_NUM_BANDS],
4276 int rateval)
4277{
4278 struct wiphy *wiphy = &rdev->wiphy;
4279 bool found = false;
4280 int band, i;
4281
4282 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4283 struct ieee80211_supported_band *sband;
4284
4285 sband = wiphy->bands[band];
4286 if (!sband)
4287 continue;
4288
4289 for (i = 0; i < sband->n_bitrates; i++) {
4290 if (sband->bitrates[i].bitrate == rateval) {
4291 mcast_rate[band] = i + 1;
4292 found = true;
4293 break;
4294 }
4295 }
4296 }
4297
4298 return found;
4299}
4300
Johannes Berg04a773a2009-04-19 21:24:32 +02004301static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4302{
Johannes Berg4c476992010-10-04 21:36:35 +02004303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4304 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004305 struct cfg80211_ibss_params ibss;
4306 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004307 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004308 int err;
4309
Johannes Berg8e30bc52009-04-22 17:45:38 +02004310 memset(&ibss, 0, sizeof(ibss));
4311
Johannes Berg04a773a2009-04-19 21:24:32 +02004312 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4313 return -EINVAL;
4314
4315 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4316 !info->attrs[NL80211_ATTR_SSID] ||
4317 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4318 return -EINVAL;
4319
Johannes Berg8e30bc52009-04-22 17:45:38 +02004320 ibss.beacon_interval = 100;
4321
4322 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4323 ibss.beacon_interval =
4324 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4325 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4326 return -EINVAL;
4327 }
4328
Johannes Berg4c476992010-10-04 21:36:35 +02004329 if (!rdev->ops->join_ibss)
4330 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004331
Johannes Berg4c476992010-10-04 21:36:35 +02004332 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4333 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004334
Johannes Berg79c97e92009-07-07 03:56:12 +02004335 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004336
4337 if (info->attrs[NL80211_ATTR_MAC])
4338 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4339 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4340 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4341
4342 if (info->attrs[NL80211_ATTR_IE]) {
4343 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4344 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4345 }
4346
4347 ibss.channel = ieee80211_get_channel(wiphy,
4348 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4349 if (!ibss.channel ||
4350 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004351 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4352 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004353
4354 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004355 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004356
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004357 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4358 u8 *rates =
4359 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4360 int n_rates =
4361 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4362 struct ieee80211_supported_band *sband =
4363 wiphy->bands[ibss.channel->band];
Johannes Berg34850ab2011-07-18 18:08:35 +02004364 int err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004365
Johannes Berg34850ab2011-07-18 18:08:35 +02004366 err = ieee80211_get_ratemask(sband, rates, n_rates,
4367 &ibss.basic_rates);
4368 if (err)
4369 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004370 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004371
4372 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4373 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4374 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4375 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004376
Johannes Berg4c476992010-10-04 21:36:35 +02004377 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4378 connkeys = nl80211_parse_connkeys(rdev,
4379 info->attrs[NL80211_ATTR_KEYS]);
4380 if (IS_ERR(connkeys))
4381 return PTR_ERR(connkeys);
4382 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004383
Johannes Berg4c476992010-10-04 21:36:35 +02004384 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004385 if (err)
4386 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004387 return err;
4388}
4389
4390static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4391{
Johannes Berg4c476992010-10-04 21:36:35 +02004392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4393 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004394
Johannes Berg4c476992010-10-04 21:36:35 +02004395 if (!rdev->ops->leave_ibss)
4396 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004397
Johannes Berg4c476992010-10-04 21:36:35 +02004398 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4399 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004400
Johannes Berg4c476992010-10-04 21:36:35 +02004401 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004402}
4403
Johannes Bergaff89a92009-07-01 21:26:51 +02004404#ifdef CONFIG_NL80211_TESTMODE
4405static struct genl_multicast_group nl80211_testmode_mcgrp = {
4406 .name = "testmode",
4407};
4408
4409static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4410{
Johannes Berg4c476992010-10-04 21:36:35 +02004411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004412 int err;
4413
4414 if (!info->attrs[NL80211_ATTR_TESTDATA])
4415 return -EINVAL;
4416
Johannes Bergaff89a92009-07-01 21:26:51 +02004417 err = -EOPNOTSUPP;
4418 if (rdev->ops->testmode_cmd) {
4419 rdev->testmode_info = info;
4420 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4421 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4422 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4423 rdev->testmode_info = NULL;
4424 }
4425
Johannes Bergaff89a92009-07-01 21:26:51 +02004426 return err;
4427}
4428
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004429static int nl80211_testmode_dump(struct sk_buff *skb,
4430 struct netlink_callback *cb)
4431{
4432 struct cfg80211_registered_device *dev;
4433 int err;
4434 long phy_idx;
4435 void *data = NULL;
4436 int data_len = 0;
4437
4438 if (cb->args[0]) {
4439 /*
4440 * 0 is a valid index, but not valid for args[0],
4441 * so we need to offset by 1.
4442 */
4443 phy_idx = cb->args[0] - 1;
4444 } else {
4445 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4446 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4447 nl80211_policy);
4448 if (err)
4449 return err;
4450 if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY])
4451 return -EINVAL;
4452 phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4453 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4454 cb->args[1] =
4455 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4456 }
4457
4458 if (cb->args[1]) {
4459 data = nla_data((void *)cb->args[1]);
4460 data_len = nla_len((void *)cb->args[1]);
4461 }
4462
4463 mutex_lock(&cfg80211_mutex);
4464 dev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4465 if (!dev) {
4466 mutex_unlock(&cfg80211_mutex);
4467 return -ENOENT;
4468 }
4469 cfg80211_lock_rdev(dev);
4470 mutex_unlock(&cfg80211_mutex);
4471
4472 if (!dev->ops->testmode_dump) {
4473 err = -EOPNOTSUPP;
4474 goto out_err;
4475 }
4476
4477 while (1) {
4478 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4479 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4480 NL80211_CMD_TESTMODE);
4481 struct nlattr *tmdata;
4482
4483 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) {
4484 genlmsg_cancel(skb, hdr);
4485 break;
4486 }
4487
4488 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4489 if (!tmdata) {
4490 genlmsg_cancel(skb, hdr);
4491 break;
4492 }
4493 err = dev->ops->testmode_dump(&dev->wiphy, skb, cb,
4494 data, data_len);
4495 nla_nest_end(skb, tmdata);
4496
4497 if (err == -ENOBUFS || err == -ENOENT) {
4498 genlmsg_cancel(skb, hdr);
4499 break;
4500 } else if (err) {
4501 genlmsg_cancel(skb, hdr);
4502 goto out_err;
4503 }
4504
4505 genlmsg_end(skb, hdr);
4506 }
4507
4508 err = skb->len;
4509 /* see above */
4510 cb->args[0] = phy_idx + 1;
4511 out_err:
4512 cfg80211_unlock_rdev(dev);
4513 return err;
4514}
4515
Johannes Bergaff89a92009-07-01 21:26:51 +02004516static struct sk_buff *
4517__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4518 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4519{
4520 struct sk_buff *skb;
4521 void *hdr;
4522 struct nlattr *data;
4523
4524 skb = nlmsg_new(approxlen + 100, gfp);
4525 if (!skb)
4526 return NULL;
4527
4528 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4529 if (!hdr) {
4530 kfree_skb(skb);
4531 return NULL;
4532 }
4533
4534 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4535 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4536
4537 ((void **)skb->cb)[0] = rdev;
4538 ((void **)skb->cb)[1] = hdr;
4539 ((void **)skb->cb)[2] = data;
4540
4541 return skb;
4542
4543 nla_put_failure:
4544 kfree_skb(skb);
4545 return NULL;
4546}
4547
4548struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4549 int approxlen)
4550{
4551 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4552
4553 if (WARN_ON(!rdev->testmode_info))
4554 return NULL;
4555
4556 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4557 rdev->testmode_info->snd_pid,
4558 rdev->testmode_info->snd_seq,
4559 GFP_KERNEL);
4560}
4561EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4562
4563int cfg80211_testmode_reply(struct sk_buff *skb)
4564{
4565 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4566 void *hdr = ((void **)skb->cb)[1];
4567 struct nlattr *data = ((void **)skb->cb)[2];
4568
4569 if (WARN_ON(!rdev->testmode_info)) {
4570 kfree_skb(skb);
4571 return -EINVAL;
4572 }
4573
4574 nla_nest_end(skb, data);
4575 genlmsg_end(skb, hdr);
4576 return genlmsg_reply(skb, rdev->testmode_info);
4577}
4578EXPORT_SYMBOL(cfg80211_testmode_reply);
4579
4580struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4581 int approxlen, gfp_t gfp)
4582{
4583 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4584
4585 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4586}
4587EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4588
4589void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4590{
4591 void *hdr = ((void **)skb->cb)[1];
4592 struct nlattr *data = ((void **)skb->cb)[2];
4593
4594 nla_nest_end(skb, data);
4595 genlmsg_end(skb, hdr);
4596 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4597}
4598EXPORT_SYMBOL(cfg80211_testmode_event);
4599#endif
4600
Samuel Ortizb23aa672009-07-01 21:26:54 +02004601static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4602{
Johannes Berg4c476992010-10-04 21:36:35 +02004603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4604 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004605 struct cfg80211_connect_params connect;
4606 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004607 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004608 int err;
4609
4610 memset(&connect, 0, sizeof(connect));
4611
4612 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4613 return -EINVAL;
4614
4615 if (!info->attrs[NL80211_ATTR_SSID] ||
4616 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4617 return -EINVAL;
4618
4619 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4620 connect.auth_type =
4621 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4622 if (!nl80211_valid_auth_type(connect.auth_type))
4623 return -EINVAL;
4624 } else
4625 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4626
4627 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4628
Johannes Bergc0692b82010-08-27 14:26:53 +03004629 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004630 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004631 if (err)
4632 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004633
Johannes Berg074ac8d2010-09-16 14:58:22 +02004634 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004635 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4636 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004637
Johannes Berg79c97e92009-07-07 03:56:12 +02004638 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004639
Samuel Ortizb23aa672009-07-01 21:26:54 +02004640 if (info->attrs[NL80211_ATTR_MAC])
4641 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4642 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4643 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4644
4645 if (info->attrs[NL80211_ATTR_IE]) {
4646 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4647 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4648 }
4649
4650 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4651 connect.channel =
4652 ieee80211_get_channel(wiphy,
4653 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4654 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004655 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4656 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004657 }
4658
Johannes Bergfffd0932009-07-08 14:22:54 +02004659 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4660 connkeys = nl80211_parse_connkeys(rdev,
4661 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004662 if (IS_ERR(connkeys))
4663 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004664 }
4665
4666 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004667 if (err)
4668 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004669 return err;
4670}
4671
4672static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4673{
Johannes Berg4c476992010-10-04 21:36:35 +02004674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4675 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004676 u16 reason;
4677
4678 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4679 reason = WLAN_REASON_DEAUTH_LEAVING;
4680 else
4681 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4682
4683 if (reason == 0)
4684 return -EINVAL;
4685
Johannes Berg074ac8d2010-09-16 14:58:22 +02004686 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004687 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4688 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004689
Johannes Berg4c476992010-10-04 21:36:35 +02004690 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004691}
4692
Johannes Berg463d0182009-07-14 00:33:35 +02004693static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4694{
Johannes Berg4c476992010-10-04 21:36:35 +02004695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004696 struct net *net;
4697 int err;
4698 u32 pid;
4699
4700 if (!info->attrs[NL80211_ATTR_PID])
4701 return -EINVAL;
4702
4703 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4704
Johannes Berg463d0182009-07-14 00:33:35 +02004705 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004706 if (IS_ERR(net))
4707 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004708
4709 err = 0;
4710
4711 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004712 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4713 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004714
Johannes Berg463d0182009-07-14 00:33:35 +02004715 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004716 return err;
4717}
4718
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004719static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4720{
Johannes Berg4c476992010-10-04 21:36:35 +02004721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004722 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4723 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004724 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004725 struct cfg80211_pmksa pmksa;
4726
4727 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4728
4729 if (!info->attrs[NL80211_ATTR_MAC])
4730 return -EINVAL;
4731
4732 if (!info->attrs[NL80211_ATTR_PMKID])
4733 return -EINVAL;
4734
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004735 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4736 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4737
Johannes Berg074ac8d2010-09-16 14:58:22 +02004738 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004739 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4740 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004741
4742 switch (info->genlhdr->cmd) {
4743 case NL80211_CMD_SET_PMKSA:
4744 rdev_ops = rdev->ops->set_pmksa;
4745 break;
4746 case NL80211_CMD_DEL_PMKSA:
4747 rdev_ops = rdev->ops->del_pmksa;
4748 break;
4749 default:
4750 WARN_ON(1);
4751 break;
4752 }
4753
Johannes Berg4c476992010-10-04 21:36:35 +02004754 if (!rdev_ops)
4755 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004756
Johannes Berg4c476992010-10-04 21:36:35 +02004757 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004758}
4759
4760static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4761{
Johannes Berg4c476992010-10-04 21:36:35 +02004762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4763 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004764
Johannes Berg074ac8d2010-09-16 14:58:22 +02004765 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004766 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4767 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004768
Johannes Berg4c476992010-10-04 21:36:35 +02004769 if (!rdev->ops->flush_pmksa)
4770 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004771
Johannes Berg4c476992010-10-04 21:36:35 +02004772 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004773}
4774
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004775static int nl80211_remain_on_channel(struct sk_buff *skb,
4776 struct genl_info *info)
4777{
Johannes Berg4c476992010-10-04 21:36:35 +02004778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4779 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004780 struct ieee80211_channel *chan;
4781 struct sk_buff *msg;
4782 void *hdr;
4783 u64 cookie;
4784 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4785 u32 freq, duration;
4786 int err;
4787
4788 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4789 !info->attrs[NL80211_ATTR_DURATION])
4790 return -EINVAL;
4791
4792 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4793
4794 /*
4795 * We should be on that channel for at least one jiffie,
4796 * and more than 5 seconds seems excessive.
4797 */
Johannes Berga2939112010-12-14 17:54:28 +01004798 if (!duration || !msecs_to_jiffies(duration) ||
4799 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004800 return -EINVAL;
4801
Johannes Berg4c476992010-10-04 21:36:35 +02004802 if (!rdev->ops->remain_on_channel)
4803 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004804
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004805 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4806 channel_type = nla_get_u32(
4807 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4808 if (channel_type != NL80211_CHAN_NO_HT &&
4809 channel_type != NL80211_CHAN_HT20 &&
4810 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004811 channel_type != NL80211_CHAN_HT40MINUS)
4812 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004813 }
4814
4815 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4816 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004817 if (chan == NULL)
4818 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004819
4820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004821 if (!msg)
4822 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004823
4824 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4825 NL80211_CMD_REMAIN_ON_CHANNEL);
4826
4827 if (IS_ERR(hdr)) {
4828 err = PTR_ERR(hdr);
4829 goto free_msg;
4830 }
4831
4832 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
4833 channel_type, duration, &cookie);
4834
4835 if (err)
4836 goto free_msg;
4837
4838 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4839
4840 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004841
4842 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004843
4844 nla_put_failure:
4845 err = -ENOBUFS;
4846 free_msg:
4847 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004848 return err;
4849}
4850
4851static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4852 struct genl_info *info)
4853{
Johannes Berg4c476992010-10-04 21:36:35 +02004854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4855 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004856 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004857
4858 if (!info->attrs[NL80211_ATTR_COOKIE])
4859 return -EINVAL;
4860
Johannes Berg4c476992010-10-04 21:36:35 +02004861 if (!rdev->ops->cancel_remain_on_channel)
4862 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004863
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004864 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4865
Johannes Berg4c476992010-10-04 21:36:35 +02004866 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004867}
4868
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004869static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4870 u8 *rates, u8 rates_len)
4871{
4872 u8 i;
4873 u32 mask = 0;
4874
4875 for (i = 0; i < rates_len; i++) {
4876 int rate = (rates[i] & 0x7f) * 5;
4877 int ridx;
4878 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4879 struct ieee80211_rate *srate =
4880 &sband->bitrates[ridx];
4881 if (rate == srate->bitrate) {
4882 mask |= 1 << ridx;
4883 break;
4884 }
4885 }
4886 if (ridx == sband->n_bitrates)
4887 return 0; /* rate not found */
4888 }
4889
4890 return mask;
4891}
4892
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004893static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004894 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4895 .len = NL80211_MAX_SUPP_RATES },
4896};
4897
4898static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4899 struct genl_info *info)
4900{
4901 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02004902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004903 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02004904 int rem, i;
4905 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004906 struct nlattr *tx_rates;
4907 struct ieee80211_supported_band *sband;
4908
4909 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4910 return -EINVAL;
4911
Johannes Berg4c476992010-10-04 21:36:35 +02004912 if (!rdev->ops->set_bitrate_mask)
4913 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004914
4915 memset(&mask, 0, sizeof(mask));
4916 /* Default to all rates enabled */
4917 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
4918 sband = rdev->wiphy.bands[i];
4919 mask.control[i].legacy =
4920 sband ? (1 << sband->n_bitrates) - 1 : 0;
4921 }
4922
4923 /*
4924 * The nested attribute uses enum nl80211_band as the index. This maps
4925 * directly to the enum ieee80211_band values used in cfg80211.
4926 */
4927 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4928 {
4929 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02004930 if (band < 0 || band >= IEEE80211_NUM_BANDS)
4931 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004932 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02004933 if (sband == NULL)
4934 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004935 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4936 nla_len(tx_rates), nl80211_txattr_policy);
4937 if (tb[NL80211_TXRATE_LEGACY]) {
4938 mask.control[band].legacy = rateset_to_mask(
4939 sband,
4940 nla_data(tb[NL80211_TXRATE_LEGACY]),
4941 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02004942 if (mask.control[band].legacy == 0)
4943 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004944 }
4945 }
4946
Johannes Berg4c476992010-10-04 21:36:35 +02004947 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004948}
4949
Johannes Berg2e161f72010-08-12 15:38:38 +02004950static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004951{
Johannes Berg4c476992010-10-04 21:36:35 +02004952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4953 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02004954 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02004955
4956 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4957 return -EINVAL;
4958
Johannes Berg2e161f72010-08-12 15:38:38 +02004959 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
4960 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02004961
Johannes Berg9d38d852010-06-09 17:20:33 +02004962 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004963 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4965 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4966 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08004967 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004968 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4969 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004970
4971 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02004972 if (!rdev->ops->mgmt_tx)
4973 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004974
Johannes Berg4c476992010-10-04 21:36:35 +02004975 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02004976 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02004977 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4978 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02004979}
4980
Johannes Berg2e161f72010-08-12 15:38:38 +02004981static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004982{
Johannes Berg4c476992010-10-04 21:36:35 +02004983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4984 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02004985 struct ieee80211_channel *chan;
4986 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02004987 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02004988 u32 freq;
4989 int err;
4990 void *hdr;
4991 u64 cookie;
4992 struct sk_buff *msg;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004993 unsigned int wait = 0;
4994 bool offchan;
Jouni Malinen026331c2010-02-15 12:53:10 +02004995
4996 if (!info->attrs[NL80211_ATTR_FRAME] ||
4997 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4998 return -EINVAL;
4999
Johannes Berg4c476992010-10-04 21:36:35 +02005000 if (!rdev->ops->mgmt_tx)
5001 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005002
Johannes Berg9d38d852010-06-09 17:20:33 +02005003 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005004 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005005 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5006 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5007 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005008 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005009 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5010 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005011
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005012 if (info->attrs[NL80211_ATTR_DURATION]) {
5013 if (!rdev->ops->mgmt_tx_cancel_wait)
5014 return -EINVAL;
5015 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5016 }
5017
Jouni Malinen026331c2010-02-15 12:53:10 +02005018 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5019 channel_type = nla_get_u32(
5020 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5021 if (channel_type != NL80211_CHAN_NO_HT &&
5022 channel_type != NL80211_CHAN_HT20 &&
5023 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005024 channel_type != NL80211_CHAN_HT40MINUS)
5025 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005026 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005027 }
5028
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005029 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5030
Jouni Malinen026331c2010-02-15 12:53:10 +02005031 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5032 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005033 if (chan == NULL)
5034 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005035
5036 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005037 if (!msg)
5038 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005039
5040 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02005041 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005042
5043 if (IS_ERR(hdr)) {
5044 err = PTR_ERR(hdr);
5045 goto free_msg;
5046 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005047 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5048 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005049 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5050 nla_len(info->attrs[NL80211_ATTR_FRAME]),
5051 &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005052 if (err)
5053 goto free_msg;
5054
5055 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5056
5057 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005058 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02005059
5060 nla_put_failure:
5061 err = -ENOBUFS;
5062 free_msg:
5063 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005064 return err;
5065}
5066
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005067static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5068{
5069 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5070 struct net_device *dev = info->user_ptr[1];
5071 u64 cookie;
5072
5073 if (!info->attrs[NL80211_ATTR_COOKIE])
5074 return -EINVAL;
5075
5076 if (!rdev->ops->mgmt_tx_cancel_wait)
5077 return -EOPNOTSUPP;
5078
5079 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5080 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5081 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5082 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5083 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5084 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5085 return -EOPNOTSUPP;
5086
5087 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5088
5089 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5090}
5091
Kalle Valoffb9eb32010-02-17 17:58:10 +02005092static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5093{
Johannes Berg4c476992010-10-04 21:36:35 +02005094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005095 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005096 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005097 u8 ps_state;
5098 bool state;
5099 int err;
5100
Johannes Berg4c476992010-10-04 21:36:35 +02005101 if (!info->attrs[NL80211_ATTR_PS_STATE])
5102 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005103
5104 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5105
Johannes Berg4c476992010-10-04 21:36:35 +02005106 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5107 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005108
5109 wdev = dev->ieee80211_ptr;
5110
Johannes Berg4c476992010-10-04 21:36:35 +02005111 if (!rdev->ops->set_power_mgmt)
5112 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005113
5114 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5115
5116 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005117 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005118
Johannes Berg4c476992010-10-04 21:36:35 +02005119 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5120 wdev->ps_timeout);
5121 if (!err)
5122 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005123 return err;
5124}
5125
5126static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5127{
Johannes Berg4c476992010-10-04 21:36:35 +02005128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005129 enum nl80211_ps_state ps_state;
5130 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005131 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005132 struct sk_buff *msg;
5133 void *hdr;
5134 int err;
5135
Kalle Valoffb9eb32010-02-17 17:58:10 +02005136 wdev = dev->ieee80211_ptr;
5137
Johannes Berg4c476992010-10-04 21:36:35 +02005138 if (!rdev->ops->set_power_mgmt)
5139 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005140
5141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005142 if (!msg)
5143 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005144
5145 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5146 NL80211_CMD_GET_POWER_SAVE);
5147 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005148 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005149 goto free_msg;
5150 }
5151
5152 if (wdev->ps)
5153 ps_state = NL80211_PS_ENABLED;
5154 else
5155 ps_state = NL80211_PS_DISABLED;
5156
5157 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5158
5159 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005160 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005161
Johannes Berg4c476992010-10-04 21:36:35 +02005162 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005163 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005164 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005165 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005166 return err;
5167}
5168
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005169static struct nla_policy
5170nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5171 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5172 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5173 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5174};
5175
5176static int nl80211_set_cqm_rssi(struct genl_info *info,
5177 s32 threshold, u32 hysteresis)
5178{
Johannes Berg4c476992010-10-04 21:36:35 +02005179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005180 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005181 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005182
5183 if (threshold > 0)
5184 return -EINVAL;
5185
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005186 wdev = dev->ieee80211_ptr;
5187
Johannes Berg4c476992010-10-04 21:36:35 +02005188 if (!rdev->ops->set_cqm_rssi_config)
5189 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005190
Johannes Berg074ac8d2010-09-16 14:58:22 +02005191 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005192 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5193 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005194
Johannes Berg4c476992010-10-04 21:36:35 +02005195 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5196 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005197}
5198
5199static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5200{
5201 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5202 struct nlattr *cqm;
5203 int err;
5204
5205 cqm = info->attrs[NL80211_ATTR_CQM];
5206 if (!cqm) {
5207 err = -EINVAL;
5208 goto out;
5209 }
5210
5211 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5212 nl80211_attr_cqm_policy);
5213 if (err)
5214 goto out;
5215
5216 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5217 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5218 s32 threshold;
5219 u32 hysteresis;
5220 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5221 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5222 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5223 } else
5224 err = -EINVAL;
5225
5226out:
5227 return err;
5228}
5229
Johannes Berg29cbe682010-12-03 09:20:44 +01005230static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5231{
5232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5233 struct net_device *dev = info->user_ptr[1];
5234 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005235 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005236 int err;
5237
5238 /* start with default */
5239 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005240 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005241
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005242 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005243 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005244 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005245 if (err)
5246 return err;
5247 }
5248
5249 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5250 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5251 return -EINVAL;
5252
Javier Cardonac80d5452010-12-16 17:37:49 -08005253 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5254 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5255
5256 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5257 /* parse additional setup parameters if given */
5258 err = nl80211_parse_mesh_setup(info, &setup);
5259 if (err)
5260 return err;
5261 }
5262
5263 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005264}
5265
5266static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5267{
5268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5269 struct net_device *dev = info->user_ptr[1];
5270
5271 return cfg80211_leave_mesh(rdev, dev);
5272}
5273
Johannes Bergff1b6e62011-05-04 15:37:28 +02005274static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5275{
5276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5277 struct sk_buff *msg;
5278 void *hdr;
5279
5280 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5281 return -EOPNOTSUPP;
5282
5283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5284 if (!msg)
5285 return -ENOMEM;
5286
5287 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5288 NL80211_CMD_GET_WOWLAN);
5289 if (!hdr)
5290 goto nla_put_failure;
5291
5292 if (rdev->wowlan) {
5293 struct nlattr *nl_wowlan;
5294
5295 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5296 if (!nl_wowlan)
5297 goto nla_put_failure;
5298
5299 if (rdev->wowlan->any)
5300 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5301 if (rdev->wowlan->disconnect)
5302 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5303 if (rdev->wowlan->magic_pkt)
5304 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005305 if (rdev->wowlan->gtk_rekey_failure)
5306 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5307 if (rdev->wowlan->eap_identity_req)
5308 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5309 if (rdev->wowlan->four_way_handshake)
5310 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5311 if (rdev->wowlan->rfkill_release)
5312 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005313 if (rdev->wowlan->n_patterns) {
5314 struct nlattr *nl_pats, *nl_pat;
5315 int i, pat_len;
5316
5317 nl_pats = nla_nest_start(msg,
5318 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5319 if (!nl_pats)
5320 goto nla_put_failure;
5321
5322 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5323 nl_pat = nla_nest_start(msg, i + 1);
5324 if (!nl_pat)
5325 goto nla_put_failure;
5326 pat_len = rdev->wowlan->patterns[i].pattern_len;
5327 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5328 DIV_ROUND_UP(pat_len, 8),
5329 rdev->wowlan->patterns[i].mask);
5330 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5331 pat_len,
5332 rdev->wowlan->patterns[i].pattern);
5333 nla_nest_end(msg, nl_pat);
5334 }
5335 nla_nest_end(msg, nl_pats);
5336 }
5337
5338 nla_nest_end(msg, nl_wowlan);
5339 }
5340
5341 genlmsg_end(msg, hdr);
5342 return genlmsg_reply(msg, info);
5343
5344nla_put_failure:
5345 nlmsg_free(msg);
5346 return -ENOBUFS;
5347}
5348
5349static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5350{
5351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5352 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5353 struct cfg80211_wowlan no_triggers = {};
5354 struct cfg80211_wowlan new_triggers = {};
5355 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5356 int err, i;
5357
5358 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5359 return -EOPNOTSUPP;
5360
5361 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5362 goto no_triggers;
5363
5364 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5365 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5366 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5367 nl80211_wowlan_policy);
5368 if (err)
5369 return err;
5370
5371 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5372 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5373 return -EINVAL;
5374 new_triggers.any = true;
5375 }
5376
5377 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5378 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5379 return -EINVAL;
5380 new_triggers.disconnect = true;
5381 }
5382
5383 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5384 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5385 return -EINVAL;
5386 new_triggers.magic_pkt = true;
5387 }
5388
Johannes Berg77dbbb12011-07-13 10:48:55 +02005389 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5390 return -EINVAL;
5391
5392 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5393 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5394 return -EINVAL;
5395 new_triggers.gtk_rekey_failure = true;
5396 }
5397
5398 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5399 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5400 return -EINVAL;
5401 new_triggers.eap_identity_req = true;
5402 }
5403
5404 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5405 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5406 return -EINVAL;
5407 new_triggers.four_way_handshake = true;
5408 }
5409
5410 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5411 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5412 return -EINVAL;
5413 new_triggers.rfkill_release = true;
5414 }
5415
Johannes Bergff1b6e62011-05-04 15:37:28 +02005416 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5417 struct nlattr *pat;
5418 int n_patterns = 0;
5419 int rem, pat_len, mask_len;
5420 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5421
5422 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5423 rem)
5424 n_patterns++;
5425 if (n_patterns > wowlan->n_patterns)
5426 return -EINVAL;
5427
5428 new_triggers.patterns = kcalloc(n_patterns,
5429 sizeof(new_triggers.patterns[0]),
5430 GFP_KERNEL);
5431 if (!new_triggers.patterns)
5432 return -ENOMEM;
5433
5434 new_triggers.n_patterns = n_patterns;
5435 i = 0;
5436
5437 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5438 rem) {
5439 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5440 nla_data(pat), nla_len(pat), NULL);
5441 err = -EINVAL;
5442 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5443 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5444 goto error;
5445 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5446 mask_len = DIV_ROUND_UP(pat_len, 8);
5447 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5448 mask_len)
5449 goto error;
5450 if (pat_len > wowlan->pattern_max_len ||
5451 pat_len < wowlan->pattern_min_len)
5452 goto error;
5453
5454 new_triggers.patterns[i].mask =
5455 kmalloc(mask_len + pat_len, GFP_KERNEL);
5456 if (!new_triggers.patterns[i].mask) {
5457 err = -ENOMEM;
5458 goto error;
5459 }
5460 new_triggers.patterns[i].pattern =
5461 new_triggers.patterns[i].mask + mask_len;
5462 memcpy(new_triggers.patterns[i].mask,
5463 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5464 mask_len);
5465 new_triggers.patterns[i].pattern_len = pat_len;
5466 memcpy(new_triggers.patterns[i].pattern,
5467 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5468 pat_len);
5469 i++;
5470 }
5471 }
5472
5473 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5474 struct cfg80211_wowlan *ntrig;
5475 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5476 GFP_KERNEL);
5477 if (!ntrig) {
5478 err = -ENOMEM;
5479 goto error;
5480 }
5481 cfg80211_rdev_free_wowlan(rdev);
5482 rdev->wowlan = ntrig;
5483 } else {
5484 no_triggers:
5485 cfg80211_rdev_free_wowlan(rdev);
5486 rdev->wowlan = NULL;
5487 }
5488
5489 return 0;
5490 error:
5491 for (i = 0; i < new_triggers.n_patterns; i++)
5492 kfree(new_triggers.patterns[i].mask);
5493 kfree(new_triggers.patterns);
5494 return err;
5495}
5496
Johannes Berge5497d72011-07-05 16:35:40 +02005497static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
5498{
5499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5500 struct net_device *dev = info->user_ptr[1];
5501 struct wireless_dev *wdev = dev->ieee80211_ptr;
5502 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
5503 struct cfg80211_gtk_rekey_data rekey_data;
5504 int err;
5505
5506 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
5507 return -EINVAL;
5508
5509 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
5510 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
5511 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
5512 nl80211_rekey_policy);
5513 if (err)
5514 return err;
5515
5516 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
5517 return -ERANGE;
5518 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
5519 return -ERANGE;
5520 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
5521 return -ERANGE;
5522
5523 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
5524 NL80211_KEK_LEN);
5525 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
5526 NL80211_KCK_LEN);
5527 memcpy(rekey_data.replay_ctr,
5528 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
5529 NL80211_REPLAY_CTR_LEN);
5530
5531 wdev_lock(wdev);
5532 if (!wdev->current_bss) {
5533 err = -ENOTCONN;
5534 goto out;
5535 }
5536
5537 if (!rdev->ops->set_rekey_data) {
5538 err = -EOPNOTSUPP;
5539 goto out;
5540 }
5541
5542 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
5543 out:
5544 wdev_unlock(wdev);
5545 return err;
5546}
5547
Johannes Berg4c476992010-10-04 21:36:35 +02005548#define NL80211_FLAG_NEED_WIPHY 0x01
5549#define NL80211_FLAG_NEED_NETDEV 0x02
5550#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02005551#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5552#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5553 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02005554
5555static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5556 struct genl_info *info)
5557{
5558 struct cfg80211_registered_device *rdev;
5559 struct net_device *dev;
5560 int err;
5561 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5562
5563 if (rtnl)
5564 rtnl_lock();
5565
5566 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5567 rdev = cfg80211_get_dev_from_info(info);
5568 if (IS_ERR(rdev)) {
5569 if (rtnl)
5570 rtnl_unlock();
5571 return PTR_ERR(rdev);
5572 }
5573 info->user_ptr[0] = rdev;
5574 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5575 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5576 if (err) {
5577 if (rtnl)
5578 rtnl_unlock();
5579 return err;
5580 }
Johannes Berg41265712010-10-04 21:14:05 +02005581 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
5582 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02005583 cfg80211_unlock_rdev(rdev);
5584 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02005585 if (rtnl)
5586 rtnl_unlock();
5587 return -ENETDOWN;
5588 }
Johannes Berg4c476992010-10-04 21:36:35 +02005589 info->user_ptr[0] = rdev;
5590 info->user_ptr[1] = dev;
5591 }
5592
5593 return 0;
5594}
5595
5596static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
5597 struct genl_info *info)
5598{
5599 if (info->user_ptr[0])
5600 cfg80211_unlock_rdev(info->user_ptr[0]);
5601 if (info->user_ptr[1])
5602 dev_put(info->user_ptr[1]);
5603 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
5604 rtnl_unlock();
5605}
5606
Johannes Berg55682962007-09-20 13:09:35 -04005607static struct genl_ops nl80211_ops[] = {
5608 {
5609 .cmd = NL80211_CMD_GET_WIPHY,
5610 .doit = nl80211_get_wiphy,
5611 .dumpit = nl80211_dump_wiphy,
5612 .policy = nl80211_policy,
5613 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005614 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04005615 },
5616 {
5617 .cmd = NL80211_CMD_SET_WIPHY,
5618 .doit = nl80211_set_wiphy,
5619 .policy = nl80211_policy,
5620 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005621 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005622 },
5623 {
5624 .cmd = NL80211_CMD_GET_INTERFACE,
5625 .doit = nl80211_get_interface,
5626 .dumpit = nl80211_dump_interface,
5627 .policy = nl80211_policy,
5628 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005629 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04005630 },
5631 {
5632 .cmd = NL80211_CMD_SET_INTERFACE,
5633 .doit = nl80211_set_interface,
5634 .policy = nl80211_policy,
5635 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005636 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5637 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005638 },
5639 {
5640 .cmd = NL80211_CMD_NEW_INTERFACE,
5641 .doit = nl80211_new_interface,
5642 .policy = nl80211_policy,
5643 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005644 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5645 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005646 },
5647 {
5648 .cmd = NL80211_CMD_DEL_INTERFACE,
5649 .doit = nl80211_del_interface,
5650 .policy = nl80211_policy,
5651 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005652 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5653 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005654 },
Johannes Berg41ade002007-12-19 02:03:29 +01005655 {
5656 .cmd = NL80211_CMD_GET_KEY,
5657 .doit = nl80211_get_key,
5658 .policy = nl80211_policy,
5659 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005660 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5661 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005662 },
5663 {
5664 .cmd = NL80211_CMD_SET_KEY,
5665 .doit = nl80211_set_key,
5666 .policy = nl80211_policy,
5667 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005669 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005670 },
5671 {
5672 .cmd = NL80211_CMD_NEW_KEY,
5673 .doit = nl80211_new_key,
5674 .policy = nl80211_policy,
5675 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005677 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005678 },
5679 {
5680 .cmd = NL80211_CMD_DEL_KEY,
5681 .doit = nl80211_del_key,
5682 .policy = nl80211_policy,
5683 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005685 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005686 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01005687 {
5688 .cmd = NL80211_CMD_SET_BEACON,
5689 .policy = nl80211_policy,
5690 .flags = GENL_ADMIN_PERM,
5691 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005692 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5693 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005694 },
5695 {
5696 .cmd = NL80211_CMD_NEW_BEACON,
5697 .policy = nl80211_policy,
5698 .flags = GENL_ADMIN_PERM,
5699 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005700 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5701 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005702 },
5703 {
5704 .cmd = NL80211_CMD_DEL_BEACON,
5705 .policy = nl80211_policy,
5706 .flags = GENL_ADMIN_PERM,
5707 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005708 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5709 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005710 },
Johannes Berg5727ef12007-12-19 02:03:34 +01005711 {
5712 .cmd = NL80211_CMD_GET_STATION,
5713 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005714 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01005715 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02005716 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5717 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005718 },
5719 {
5720 .cmd = NL80211_CMD_SET_STATION,
5721 .doit = nl80211_set_station,
5722 .policy = nl80211_policy,
5723 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005724 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5725 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005726 },
5727 {
5728 .cmd = NL80211_CMD_NEW_STATION,
5729 .doit = nl80211_new_station,
5730 .policy = nl80211_policy,
5731 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005732 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005733 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005734 },
5735 {
5736 .cmd = NL80211_CMD_DEL_STATION,
5737 .doit = nl80211_del_station,
5738 .policy = nl80211_policy,
5739 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005740 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5741 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005742 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005743 {
5744 .cmd = NL80211_CMD_GET_MPATH,
5745 .doit = nl80211_get_mpath,
5746 .dumpit = nl80211_dump_mpath,
5747 .policy = nl80211_policy,
5748 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005749 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005750 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005751 },
5752 {
5753 .cmd = NL80211_CMD_SET_MPATH,
5754 .doit = nl80211_set_mpath,
5755 .policy = nl80211_policy,
5756 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005757 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005758 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005759 },
5760 {
5761 .cmd = NL80211_CMD_NEW_MPATH,
5762 .doit = nl80211_new_mpath,
5763 .policy = nl80211_policy,
5764 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005765 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005766 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005767 },
5768 {
5769 .cmd = NL80211_CMD_DEL_MPATH,
5770 .doit = nl80211_del_mpath,
5771 .policy = nl80211_policy,
5772 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005773 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5774 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005775 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005776 {
5777 .cmd = NL80211_CMD_SET_BSS,
5778 .doit = nl80211_set_bss,
5779 .policy = nl80211_policy,
5780 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005781 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5782 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005783 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005784 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005785 .cmd = NL80211_CMD_GET_REG,
5786 .doit = nl80211_get_reg,
5787 .policy = nl80211_policy,
5788 /* can be retrieved by unprivileged users */
5789 },
5790 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005791 .cmd = NL80211_CMD_SET_REG,
5792 .doit = nl80211_set_reg,
5793 .policy = nl80211_policy,
5794 .flags = GENL_ADMIN_PERM,
5795 },
5796 {
5797 .cmd = NL80211_CMD_REQ_SET_REG,
5798 .doit = nl80211_req_set_reg,
5799 .policy = nl80211_policy,
5800 .flags = GENL_ADMIN_PERM,
5801 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005802 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005803 .cmd = NL80211_CMD_GET_MESH_CONFIG,
5804 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005805 .policy = nl80211_policy,
5806 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5808 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005809 },
5810 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005811 .cmd = NL80211_CMD_SET_MESH_CONFIG,
5812 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005813 .policy = nl80211_policy,
5814 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01005815 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005816 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005817 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02005818 {
Johannes Berg2a519312009-02-10 21:25:55 +01005819 .cmd = NL80211_CMD_TRIGGER_SCAN,
5820 .doit = nl80211_trigger_scan,
5821 .policy = nl80211_policy,
5822 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005824 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01005825 },
5826 {
5827 .cmd = NL80211_CMD_GET_SCAN,
5828 .policy = nl80211_policy,
5829 .dumpit = nl80211_dump_scan,
5830 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02005831 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005832 .cmd = NL80211_CMD_START_SCHED_SCAN,
5833 .doit = nl80211_start_sched_scan,
5834 .policy = nl80211_policy,
5835 .flags = GENL_ADMIN_PERM,
5836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5837 NL80211_FLAG_NEED_RTNL,
5838 },
5839 {
5840 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
5841 .doit = nl80211_stop_sched_scan,
5842 .policy = nl80211_policy,
5843 .flags = GENL_ADMIN_PERM,
5844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5845 NL80211_FLAG_NEED_RTNL,
5846 },
5847 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02005848 .cmd = NL80211_CMD_AUTHENTICATE,
5849 .doit = nl80211_authenticate,
5850 .policy = nl80211_policy,
5851 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005852 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005853 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005854 },
5855 {
5856 .cmd = NL80211_CMD_ASSOCIATE,
5857 .doit = nl80211_associate,
5858 .policy = nl80211_policy,
5859 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005861 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005862 },
5863 {
5864 .cmd = NL80211_CMD_DEAUTHENTICATE,
5865 .doit = nl80211_deauthenticate,
5866 .policy = nl80211_policy,
5867 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005869 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005870 },
5871 {
5872 .cmd = NL80211_CMD_DISASSOCIATE,
5873 .doit = nl80211_disassociate,
5874 .policy = nl80211_policy,
5875 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005876 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005877 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005878 },
Johannes Berg04a773a2009-04-19 21:24:32 +02005879 {
5880 .cmd = NL80211_CMD_JOIN_IBSS,
5881 .doit = nl80211_join_ibss,
5882 .policy = nl80211_policy,
5883 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005884 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005885 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005886 },
5887 {
5888 .cmd = NL80211_CMD_LEAVE_IBSS,
5889 .doit = nl80211_leave_ibss,
5890 .policy = nl80211_policy,
5891 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005892 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005893 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005894 },
Johannes Bergaff89a92009-07-01 21:26:51 +02005895#ifdef CONFIG_NL80211_TESTMODE
5896 {
5897 .cmd = NL80211_CMD_TESTMODE,
5898 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005899 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02005900 .policy = nl80211_policy,
5901 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005902 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5903 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02005904 },
5905#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02005906 {
5907 .cmd = NL80211_CMD_CONNECT,
5908 .doit = nl80211_connect,
5909 .policy = nl80211_policy,
5910 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005911 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005912 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005913 },
5914 {
5915 .cmd = NL80211_CMD_DISCONNECT,
5916 .doit = nl80211_disconnect,
5917 .policy = nl80211_policy,
5918 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005919 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005920 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005921 },
Johannes Berg463d0182009-07-14 00:33:35 +02005922 {
5923 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
5924 .doit = nl80211_wiphy_netns,
5925 .policy = nl80211_policy,
5926 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005927 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5928 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02005929 },
Holger Schurig61fa7132009-11-11 12:25:40 +01005930 {
5931 .cmd = NL80211_CMD_GET_SURVEY,
5932 .policy = nl80211_policy,
5933 .dumpit = nl80211_dump_survey,
5934 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005935 {
5936 .cmd = NL80211_CMD_SET_PMKSA,
5937 .doit = nl80211_setdel_pmksa,
5938 .policy = nl80211_policy,
5939 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005940 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5941 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005942 },
5943 {
5944 .cmd = NL80211_CMD_DEL_PMKSA,
5945 .doit = nl80211_setdel_pmksa,
5946 .policy = nl80211_policy,
5947 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005948 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5949 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005950 },
5951 {
5952 .cmd = NL80211_CMD_FLUSH_PMKSA,
5953 .doit = nl80211_flush_pmksa,
5954 .policy = nl80211_policy,
5955 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005956 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5957 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005958 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005959 {
5960 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
5961 .doit = nl80211_remain_on_channel,
5962 .policy = nl80211_policy,
5963 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005964 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005965 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005966 },
5967 {
5968 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5969 .doit = nl80211_cancel_remain_on_channel,
5970 .policy = nl80211_policy,
5971 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005972 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005973 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005974 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005975 {
5976 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
5977 .doit = nl80211_set_tx_bitrate_mask,
5978 .policy = nl80211_policy,
5979 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005980 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5981 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005982 },
Jouni Malinen026331c2010-02-15 12:53:10 +02005983 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005984 .cmd = NL80211_CMD_REGISTER_FRAME,
5985 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005986 .policy = nl80211_policy,
5987 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005988 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5989 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005990 },
5991 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005992 .cmd = NL80211_CMD_FRAME,
5993 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005994 .policy = nl80211_policy,
5995 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005996 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005997 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005998 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02005999 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006000 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6001 .doit = nl80211_tx_mgmt_cancel_wait,
6002 .policy = nl80211_policy,
6003 .flags = GENL_ADMIN_PERM,
6004 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6005 NL80211_FLAG_NEED_RTNL,
6006 },
6007 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006008 .cmd = NL80211_CMD_SET_POWER_SAVE,
6009 .doit = nl80211_set_power_save,
6010 .policy = nl80211_policy,
6011 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006012 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6013 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006014 },
6015 {
6016 .cmd = NL80211_CMD_GET_POWER_SAVE,
6017 .doit = nl80211_get_power_save,
6018 .policy = nl80211_policy,
6019 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006020 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6021 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006022 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006023 {
6024 .cmd = NL80211_CMD_SET_CQM,
6025 .doit = nl80211_set_cqm,
6026 .policy = nl80211_policy,
6027 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006028 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6029 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006030 },
Johannes Bergf444de02010-05-05 15:25:02 +02006031 {
6032 .cmd = NL80211_CMD_SET_CHANNEL,
6033 .doit = nl80211_set_channel,
6034 .policy = nl80211_policy,
6035 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006036 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6037 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006038 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006039 {
6040 .cmd = NL80211_CMD_SET_WDS_PEER,
6041 .doit = nl80211_set_wds_peer,
6042 .policy = nl80211_policy,
6043 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006044 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6045 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006046 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006047 {
6048 .cmd = NL80211_CMD_JOIN_MESH,
6049 .doit = nl80211_join_mesh,
6050 .policy = nl80211_policy,
6051 .flags = GENL_ADMIN_PERM,
6052 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6053 NL80211_FLAG_NEED_RTNL,
6054 },
6055 {
6056 .cmd = NL80211_CMD_LEAVE_MESH,
6057 .doit = nl80211_leave_mesh,
6058 .policy = nl80211_policy,
6059 .flags = GENL_ADMIN_PERM,
6060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6061 NL80211_FLAG_NEED_RTNL,
6062 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006063 {
6064 .cmd = NL80211_CMD_GET_WOWLAN,
6065 .doit = nl80211_get_wowlan,
6066 .policy = nl80211_policy,
6067 /* can be retrieved by unprivileged users */
6068 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6069 NL80211_FLAG_NEED_RTNL,
6070 },
6071 {
6072 .cmd = NL80211_CMD_SET_WOWLAN,
6073 .doit = nl80211_set_wowlan,
6074 .policy = nl80211_policy,
6075 .flags = GENL_ADMIN_PERM,
6076 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6077 NL80211_FLAG_NEED_RTNL,
6078 },
Johannes Berge5497d72011-07-05 16:35:40 +02006079 {
6080 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6081 .doit = nl80211_set_rekey_data,
6082 .policy = nl80211_policy,
6083 .flags = GENL_ADMIN_PERM,
6084 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6085 NL80211_FLAG_NEED_RTNL,
6086 },
Johannes Berg55682962007-09-20 13:09:35 -04006087};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006088
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006089static struct genl_multicast_group nl80211_mlme_mcgrp = {
6090 .name = "mlme",
6091};
Johannes Berg55682962007-09-20 13:09:35 -04006092
6093/* multicast groups */
6094static struct genl_multicast_group nl80211_config_mcgrp = {
6095 .name = "config",
6096};
Johannes Berg2a519312009-02-10 21:25:55 +01006097static struct genl_multicast_group nl80211_scan_mcgrp = {
6098 .name = "scan",
6099};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006100static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6101 .name = "regulatory",
6102};
Johannes Berg55682962007-09-20 13:09:35 -04006103
6104/* notification functions */
6105
6106void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6107{
6108 struct sk_buff *msg;
6109
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006111 if (!msg)
6112 return;
6113
6114 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6115 nlmsg_free(msg);
6116 return;
6117 }
6118
Johannes Berg463d0182009-07-14 00:33:35 +02006119 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6120 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006121}
6122
Johannes Berg362a4152009-05-24 16:43:15 +02006123static int nl80211_add_scan_req(struct sk_buff *msg,
6124 struct cfg80211_registered_device *rdev)
6125{
6126 struct cfg80211_scan_request *req = rdev->scan_req;
6127 struct nlattr *nest;
6128 int i;
6129
Johannes Berg667503dd2009-07-07 03:56:11 +02006130 ASSERT_RDEV_LOCK(rdev);
6131
Johannes Berg362a4152009-05-24 16:43:15 +02006132 if (WARN_ON(!req))
6133 return 0;
6134
6135 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6136 if (!nest)
6137 goto nla_put_failure;
6138 for (i = 0; i < req->n_ssids; i++)
6139 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6140 nla_nest_end(msg, nest);
6141
6142 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6143 if (!nest)
6144 goto nla_put_failure;
6145 for (i = 0; i < req->n_channels; i++)
6146 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6147 nla_nest_end(msg, nest);
6148
6149 if (req->ie)
6150 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6151
6152 return 0;
6153 nla_put_failure:
6154 return -ENOBUFS;
6155}
6156
Johannes Berga538e2d2009-06-16 19:56:42 +02006157static int nl80211_send_scan_msg(struct sk_buff *msg,
6158 struct cfg80211_registered_device *rdev,
6159 struct net_device *netdev,
6160 u32 pid, u32 seq, int flags,
6161 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006162{
6163 void *hdr;
6164
6165 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6166 if (!hdr)
6167 return -1;
6168
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006169 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006170 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6171
Johannes Berg362a4152009-05-24 16:43:15 +02006172 /* ignore errors and send incomplete event anyway */
6173 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006174
6175 return genlmsg_end(msg, hdr);
6176
6177 nla_put_failure:
6178 genlmsg_cancel(msg, hdr);
6179 return -EMSGSIZE;
6180}
6181
Luciano Coelho807f8a82011-05-11 17:09:35 +03006182static int
6183nl80211_send_sched_scan_msg(struct sk_buff *msg,
6184 struct cfg80211_registered_device *rdev,
6185 struct net_device *netdev,
6186 u32 pid, u32 seq, int flags, u32 cmd)
6187{
6188 void *hdr;
6189
6190 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6191 if (!hdr)
6192 return -1;
6193
6194 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6195 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6196
6197 return genlmsg_end(msg, hdr);
6198
6199 nla_put_failure:
6200 genlmsg_cancel(msg, hdr);
6201 return -EMSGSIZE;
6202}
6203
Johannes Berga538e2d2009-06-16 19:56:42 +02006204void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6205 struct net_device *netdev)
6206{
6207 struct sk_buff *msg;
6208
6209 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6210 if (!msg)
6211 return;
6212
6213 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6214 NL80211_CMD_TRIGGER_SCAN) < 0) {
6215 nlmsg_free(msg);
6216 return;
6217 }
6218
Johannes Berg463d0182009-07-14 00:33:35 +02006219 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6220 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006221}
6222
Johannes Berg2a519312009-02-10 21:25:55 +01006223void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6224 struct net_device *netdev)
6225{
6226 struct sk_buff *msg;
6227
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006229 if (!msg)
6230 return;
6231
Johannes Berga538e2d2009-06-16 19:56:42 +02006232 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6233 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006234 nlmsg_free(msg);
6235 return;
6236 }
6237
Johannes Berg463d0182009-07-14 00:33:35 +02006238 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6239 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006240}
6241
6242void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6243 struct net_device *netdev)
6244{
6245 struct sk_buff *msg;
6246
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006248 if (!msg)
6249 return;
6250
Johannes Berga538e2d2009-06-16 19:56:42 +02006251 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6252 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006253 nlmsg_free(msg);
6254 return;
6255 }
6256
Johannes Berg463d0182009-07-14 00:33:35 +02006257 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6258 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006259}
6260
Luciano Coelho807f8a82011-05-11 17:09:35 +03006261void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6262 struct net_device *netdev)
6263{
6264 struct sk_buff *msg;
6265
6266 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6267 if (!msg)
6268 return;
6269
6270 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6271 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6272 nlmsg_free(msg);
6273 return;
6274 }
6275
6276 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6277 nl80211_scan_mcgrp.id, GFP_KERNEL);
6278}
6279
6280void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6281 struct net_device *netdev, u32 cmd)
6282{
6283 struct sk_buff *msg;
6284
6285 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6286 if (!msg)
6287 return;
6288
6289 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6290 nlmsg_free(msg);
6291 return;
6292 }
6293
6294 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6295 nl80211_scan_mcgrp.id, GFP_KERNEL);
6296}
6297
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006298/*
6299 * This can happen on global regulatory changes or device specific settings
6300 * based on custom world regulatory domains.
6301 */
6302void nl80211_send_reg_change_event(struct regulatory_request *request)
6303{
6304 struct sk_buff *msg;
6305 void *hdr;
6306
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006307 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006308 if (!msg)
6309 return;
6310
6311 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6312 if (!hdr) {
6313 nlmsg_free(msg);
6314 return;
6315 }
6316
6317 /* Userspace can always count this one always being set */
6318 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6319
6320 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6321 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6322 NL80211_REGDOM_TYPE_WORLD);
6323 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6324 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6325 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6326 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6327 request->intersect)
6328 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6329 NL80211_REGDOM_TYPE_INTERSECTION);
6330 else {
6331 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6332 NL80211_REGDOM_TYPE_COUNTRY);
6333 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6334 }
6335
6336 if (wiphy_idx_valid(request->wiphy_idx))
6337 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6338
6339 if (genlmsg_end(msg, hdr) < 0) {
6340 nlmsg_free(msg);
6341 return;
6342 }
6343
Johannes Bergbc43b282009-07-25 10:54:13 +02006344 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02006345 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02006346 GFP_ATOMIC);
6347 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006348
6349 return;
6350
6351nla_put_failure:
6352 genlmsg_cancel(msg, hdr);
6353 nlmsg_free(msg);
6354}
6355
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006356static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
6357 struct net_device *netdev,
6358 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006359 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006360{
6361 struct sk_buff *msg;
6362 void *hdr;
6363
Johannes Berge6d6e342009-07-01 21:26:47 +02006364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006365 if (!msg)
6366 return;
6367
6368 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6369 if (!hdr) {
6370 nlmsg_free(msg);
6371 return;
6372 }
6373
6374 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6375 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6376 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6377
6378 if (genlmsg_end(msg, hdr) < 0) {
6379 nlmsg_free(msg);
6380 return;
6381 }
6382
Johannes Berg463d0182009-07-14 00:33:35 +02006383 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6384 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006385 return;
6386
6387 nla_put_failure:
6388 genlmsg_cancel(msg, hdr);
6389 nlmsg_free(msg);
6390}
6391
6392void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006393 struct net_device *netdev, const u8 *buf,
6394 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006395{
6396 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006397 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006398}
6399
6400void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
6401 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006402 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006403{
Johannes Berge6d6e342009-07-01 21:26:47 +02006404 nl80211_send_mlme_event(rdev, netdev, buf, len,
6405 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006406}
6407
Jouni Malinen53b46b82009-03-27 20:53:56 +02006408void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006409 struct net_device *netdev, const u8 *buf,
6410 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006411{
6412 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006413 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006414}
6415
Jouni Malinen53b46b82009-03-27 20:53:56 +02006416void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
6417 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006418 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006419{
6420 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006421 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006422}
6423
Jouni Malinencf4e5942010-12-16 00:52:40 +02006424void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6425 struct net_device *netdev, const u8 *buf,
6426 size_t len, gfp_t gfp)
6427{
6428 nl80211_send_mlme_event(rdev, netdev, buf, len,
6429 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6430}
6431
6432void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6433 struct net_device *netdev, const u8 *buf,
6434 size_t len, gfp_t gfp)
6435{
6436 nl80211_send_mlme_event(rdev, netdev, buf, len,
6437 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6438}
6439
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04006440static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
6441 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02006442 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006443{
6444 struct sk_buff *msg;
6445 void *hdr;
6446
Johannes Berge6d6e342009-07-01 21:26:47 +02006447 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006448 if (!msg)
6449 return;
6450
6451 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6452 if (!hdr) {
6453 nlmsg_free(msg);
6454 return;
6455 }
6456
6457 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6458 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6459 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
6460 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6461
6462 if (genlmsg_end(msg, hdr) < 0) {
6463 nlmsg_free(msg);
6464 return;
6465 }
6466
Johannes Berg463d0182009-07-14 00:33:35 +02006467 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6468 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006469 return;
6470
6471 nla_put_failure:
6472 genlmsg_cancel(msg, hdr);
6473 nlmsg_free(msg);
6474}
6475
6476void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006477 struct net_device *netdev, const u8 *addr,
6478 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006479{
6480 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02006481 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006482}
6483
6484void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006485 struct net_device *netdev, const u8 *addr,
6486 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006487{
Johannes Berge6d6e342009-07-01 21:26:47 +02006488 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
6489 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006490}
6491
Samuel Ortizb23aa672009-07-01 21:26:54 +02006492void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
6493 struct net_device *netdev, const u8 *bssid,
6494 const u8 *req_ie, size_t req_ie_len,
6495 const u8 *resp_ie, size_t resp_ie_len,
6496 u16 status, gfp_t gfp)
6497{
6498 struct sk_buff *msg;
6499 void *hdr;
6500
6501 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6502 if (!msg)
6503 return;
6504
6505 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
6506 if (!hdr) {
6507 nlmsg_free(msg);
6508 return;
6509 }
6510
6511 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6512 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6513 if (bssid)
6514 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6515 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
6516 if (req_ie)
6517 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6518 if (resp_ie)
6519 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6520
6521 if (genlmsg_end(msg, hdr) < 0) {
6522 nlmsg_free(msg);
6523 return;
6524 }
6525
Johannes Berg463d0182009-07-14 00:33:35 +02006526 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6527 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006528 return;
6529
6530 nla_put_failure:
6531 genlmsg_cancel(msg, hdr);
6532 nlmsg_free(msg);
6533
6534}
6535
6536void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
6537 struct net_device *netdev, const u8 *bssid,
6538 const u8 *req_ie, size_t req_ie_len,
6539 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
6540{
6541 struct sk_buff *msg;
6542 void *hdr;
6543
6544 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6545 if (!msg)
6546 return;
6547
6548 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
6549 if (!hdr) {
6550 nlmsg_free(msg);
6551 return;
6552 }
6553
6554 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6555 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6556 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6557 if (req_ie)
6558 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6559 if (resp_ie)
6560 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6561
6562 if (genlmsg_end(msg, hdr) < 0) {
6563 nlmsg_free(msg);
6564 return;
6565 }
6566
Johannes Berg463d0182009-07-14 00:33:35 +02006567 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6568 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006569 return;
6570
6571 nla_put_failure:
6572 genlmsg_cancel(msg, hdr);
6573 nlmsg_free(msg);
6574
6575}
6576
6577void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
6578 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02006579 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006580{
6581 struct sk_buff *msg;
6582 void *hdr;
6583
Johannes Berg667503dd2009-07-07 03:56:11 +02006584 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006585 if (!msg)
6586 return;
6587
6588 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
6589 if (!hdr) {
6590 nlmsg_free(msg);
6591 return;
6592 }
6593
6594 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6595 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6596 if (from_ap && reason)
6597 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
6598 if (from_ap)
6599 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
6600 if (ie)
6601 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
6602
6603 if (genlmsg_end(msg, hdr) < 0) {
6604 nlmsg_free(msg);
6605 return;
6606 }
6607
Johannes Berg463d0182009-07-14 00:33:35 +02006608 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6609 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006610 return;
6611
6612 nla_put_failure:
6613 genlmsg_cancel(msg, hdr);
6614 nlmsg_free(msg);
6615
6616}
6617
Johannes Berg04a773a2009-04-19 21:24:32 +02006618void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
6619 struct net_device *netdev, const u8 *bssid,
6620 gfp_t gfp)
6621{
6622 struct sk_buff *msg;
6623 void *hdr;
6624
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006625 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006626 if (!msg)
6627 return;
6628
6629 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
6630 if (!hdr) {
6631 nlmsg_free(msg);
6632 return;
6633 }
6634
6635 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6636 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6637 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6638
6639 if (genlmsg_end(msg, hdr) < 0) {
6640 nlmsg_free(msg);
6641 return;
6642 }
6643
Johannes Berg463d0182009-07-14 00:33:35 +02006644 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6645 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006646 return;
6647
6648 nla_put_failure:
6649 genlmsg_cancel(msg, hdr);
6650 nlmsg_free(msg);
6651}
6652
Javier Cardonac93b5e72011-04-07 15:08:34 -07006653void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
6654 struct net_device *netdev,
6655 const u8 *macaddr, const u8* ie, u8 ie_len,
6656 gfp_t gfp)
6657{
6658 struct sk_buff *msg;
6659 void *hdr;
6660
6661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6662 if (!msg)
6663 return;
6664
6665 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
6666 if (!hdr) {
6667 nlmsg_free(msg);
6668 return;
6669 }
6670
6671 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6672 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6673 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
6674 if (ie_len && ie)
6675 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
6676
6677 if (genlmsg_end(msg, hdr) < 0) {
6678 nlmsg_free(msg);
6679 return;
6680 }
6681
6682 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6683 nl80211_mlme_mcgrp.id, gfp);
6684 return;
6685
6686 nla_put_failure:
6687 genlmsg_cancel(msg, hdr);
6688 nlmsg_free(msg);
6689}
6690
Jouni Malinena3b8b052009-03-27 21:59:49 +02006691void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
6692 struct net_device *netdev, const u8 *addr,
6693 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02006694 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02006695{
6696 struct sk_buff *msg;
6697 void *hdr;
6698
Johannes Berge6d6e342009-07-01 21:26:47 +02006699 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006700 if (!msg)
6701 return;
6702
6703 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
6704 if (!hdr) {
6705 nlmsg_free(msg);
6706 return;
6707 }
6708
6709 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6710 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6711 if (addr)
6712 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6713 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03006714 if (key_id != -1)
6715 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006716 if (tsc)
6717 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
6718
6719 if (genlmsg_end(msg, hdr) < 0) {
6720 nlmsg_free(msg);
6721 return;
6722 }
6723
Johannes Berg463d0182009-07-14 00:33:35 +02006724 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6725 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006726 return;
6727
6728 nla_put_failure:
6729 genlmsg_cancel(msg, hdr);
6730 nlmsg_free(msg);
6731}
6732
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006733void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
6734 struct ieee80211_channel *channel_before,
6735 struct ieee80211_channel *channel_after)
6736{
6737 struct sk_buff *msg;
6738 void *hdr;
6739 struct nlattr *nl_freq;
6740
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006741 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006742 if (!msg)
6743 return;
6744
6745 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
6746 if (!hdr) {
6747 nlmsg_free(msg);
6748 return;
6749 }
6750
6751 /*
6752 * Since we are applying the beacon hint to a wiphy we know its
6753 * wiphy_idx is valid
6754 */
6755 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
6756
6757 /* Before */
6758 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
6759 if (!nl_freq)
6760 goto nla_put_failure;
6761 if (nl80211_msg_put_channel(msg, channel_before))
6762 goto nla_put_failure;
6763 nla_nest_end(msg, nl_freq);
6764
6765 /* After */
6766 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
6767 if (!nl_freq)
6768 goto nla_put_failure;
6769 if (nl80211_msg_put_channel(msg, channel_after))
6770 goto nla_put_failure;
6771 nla_nest_end(msg, nl_freq);
6772
6773 if (genlmsg_end(msg, hdr) < 0) {
6774 nlmsg_free(msg);
6775 return;
6776 }
6777
Johannes Berg463d0182009-07-14 00:33:35 +02006778 rcu_read_lock();
6779 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
6780 GFP_ATOMIC);
6781 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006782
6783 return;
6784
6785nla_put_failure:
6786 genlmsg_cancel(msg, hdr);
6787 nlmsg_free(msg);
6788}
6789
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006790static void nl80211_send_remain_on_chan_event(
6791 int cmd, struct cfg80211_registered_device *rdev,
6792 struct net_device *netdev, u64 cookie,
6793 struct ieee80211_channel *chan,
6794 enum nl80211_channel_type channel_type,
6795 unsigned int duration, gfp_t gfp)
6796{
6797 struct sk_buff *msg;
6798 void *hdr;
6799
6800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6801 if (!msg)
6802 return;
6803
6804 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6805 if (!hdr) {
6806 nlmsg_free(msg);
6807 return;
6808 }
6809
6810 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6811 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6812 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
6813 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
6814 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6815
6816 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
6817 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
6818
6819 if (genlmsg_end(msg, hdr) < 0) {
6820 nlmsg_free(msg);
6821 return;
6822 }
6823
6824 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6825 nl80211_mlme_mcgrp.id, gfp);
6826 return;
6827
6828 nla_put_failure:
6829 genlmsg_cancel(msg, hdr);
6830 nlmsg_free(msg);
6831}
6832
6833void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
6834 struct net_device *netdev, u64 cookie,
6835 struct ieee80211_channel *chan,
6836 enum nl80211_channel_type channel_type,
6837 unsigned int duration, gfp_t gfp)
6838{
6839 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
6840 rdev, netdev, cookie, chan,
6841 channel_type, duration, gfp);
6842}
6843
6844void nl80211_send_remain_on_channel_cancel(
6845 struct cfg80211_registered_device *rdev, struct net_device *netdev,
6846 u64 cookie, struct ieee80211_channel *chan,
6847 enum nl80211_channel_type channel_type, gfp_t gfp)
6848{
6849 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6850 rdev, netdev, cookie, chan,
6851 channel_type, 0, gfp);
6852}
6853
Johannes Berg98b62182009-12-23 13:15:44 +01006854void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
6855 struct net_device *dev, const u8 *mac_addr,
6856 struct station_info *sinfo, gfp_t gfp)
6857{
6858 struct sk_buff *msg;
6859
6860 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6861 if (!msg)
6862 return;
6863
6864 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
6865 nlmsg_free(msg);
6866 return;
6867 }
6868
6869 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6870 nl80211_mlme_mcgrp.id, gfp);
6871}
6872
Jouni Malinenec15e682011-03-23 15:29:52 +02006873void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
6874 struct net_device *dev, const u8 *mac_addr,
6875 gfp_t gfp)
6876{
6877 struct sk_buff *msg;
6878 void *hdr;
6879
6880 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6881 if (!msg)
6882 return;
6883
6884 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
6885 if (!hdr) {
6886 nlmsg_free(msg);
6887 return;
6888 }
6889
6890 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
6891 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
6892
6893 if (genlmsg_end(msg, hdr) < 0) {
6894 nlmsg_free(msg);
6895 return;
6896 }
6897
6898 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6899 nl80211_mlme_mcgrp.id, gfp);
6900 return;
6901
6902 nla_put_failure:
6903 genlmsg_cancel(msg, hdr);
6904 nlmsg_free(msg);
6905}
6906
Johannes Berg2e161f72010-08-12 15:38:38 +02006907int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
6908 struct net_device *netdev, u32 nlpid,
6909 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02006910{
6911 struct sk_buff *msg;
6912 void *hdr;
6913 int err;
6914
6915 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6916 if (!msg)
6917 return -ENOMEM;
6918
Johannes Berg2e161f72010-08-12 15:38:38 +02006919 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006920 if (!hdr) {
6921 nlmsg_free(msg);
6922 return -ENOMEM;
6923 }
6924
6925 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6926 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6927 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
6928 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6929
6930 err = genlmsg_end(msg, hdr);
6931 if (err < 0) {
6932 nlmsg_free(msg);
6933 return err;
6934 }
6935
6936 err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
6937 if (err < 0)
6938 return err;
6939 return 0;
6940
6941 nla_put_failure:
6942 genlmsg_cancel(msg, hdr);
6943 nlmsg_free(msg);
6944 return -ENOBUFS;
6945}
6946
Johannes Berg2e161f72010-08-12 15:38:38 +02006947void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
6948 struct net_device *netdev, u64 cookie,
6949 const u8 *buf, size_t len, bool ack,
6950 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02006951{
6952 struct sk_buff *msg;
6953 void *hdr;
6954
6955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6956 if (!msg)
6957 return;
6958
Johannes Berg2e161f72010-08-12 15:38:38 +02006959 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02006960 if (!hdr) {
6961 nlmsg_free(msg);
6962 return;
6963 }
6964
6965 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6966 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6967 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6968 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6969 if (ack)
6970 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
6971
6972 if (genlmsg_end(msg, hdr) < 0) {
6973 nlmsg_free(msg);
6974 return;
6975 }
6976
6977 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
6978 return;
6979
6980 nla_put_failure:
6981 genlmsg_cancel(msg, hdr);
6982 nlmsg_free(msg);
6983}
6984
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006985void
6986nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
6987 struct net_device *netdev,
6988 enum nl80211_cqm_rssi_threshold_event rssi_event,
6989 gfp_t gfp)
6990{
6991 struct sk_buff *msg;
6992 struct nlattr *pinfoattr;
6993 void *hdr;
6994
6995 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6996 if (!msg)
6997 return;
6998
6999 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7000 if (!hdr) {
7001 nlmsg_free(msg);
7002 return;
7003 }
7004
7005 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7006 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7007
7008 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7009 if (!pinfoattr)
7010 goto nla_put_failure;
7011
7012 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7013 rssi_event);
7014
7015 nla_nest_end(msg, pinfoattr);
7016
7017 if (genlmsg_end(msg, hdr) < 0) {
7018 nlmsg_free(msg);
7019 return;
7020 }
7021
7022 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7023 nl80211_mlme_mcgrp.id, gfp);
7024 return;
7025
7026 nla_put_failure:
7027 genlmsg_cancel(msg, hdr);
7028 nlmsg_free(msg);
7029}
7030
Johannes Berge5497d72011-07-05 16:35:40 +02007031void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7032 struct net_device *netdev, const u8 *bssid,
7033 const u8 *replay_ctr, gfp_t gfp)
7034{
7035 struct sk_buff *msg;
7036 struct nlattr *rekey_attr;
7037 void *hdr;
7038
7039 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7040 if (!msg)
7041 return;
7042
7043 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7044 if (!hdr) {
7045 nlmsg_free(msg);
7046 return;
7047 }
7048
7049 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7050 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7051 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7052
7053 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7054 if (!rekey_attr)
7055 goto nla_put_failure;
7056
7057 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7058 NL80211_REPLAY_CTR_LEN, replay_ctr);
7059
7060 nla_nest_end(msg, rekey_attr);
7061
7062 if (genlmsg_end(msg, hdr) < 0) {
7063 nlmsg_free(msg);
7064 return;
7065 }
7066
7067 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7068 nl80211_mlme_mcgrp.id, gfp);
7069 return;
7070
7071 nla_put_failure:
7072 genlmsg_cancel(msg, hdr);
7073 nlmsg_free(msg);
7074}
7075
Johannes Bergc063dbf2010-11-24 08:10:05 +01007076void
7077nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7078 struct net_device *netdev, const u8 *peer,
7079 u32 num_packets, gfp_t gfp)
7080{
7081 struct sk_buff *msg;
7082 struct nlattr *pinfoattr;
7083 void *hdr;
7084
7085 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7086 if (!msg)
7087 return;
7088
7089 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7090 if (!hdr) {
7091 nlmsg_free(msg);
7092 return;
7093 }
7094
7095 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7096 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7097 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7098
7099 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7100 if (!pinfoattr)
7101 goto nla_put_failure;
7102
7103 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7104
7105 nla_nest_end(msg, pinfoattr);
7106
7107 if (genlmsg_end(msg, hdr) < 0) {
7108 nlmsg_free(msg);
7109 return;
7110 }
7111
7112 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7113 nl80211_mlme_mcgrp.id, gfp);
7114 return;
7115
7116 nla_put_failure:
7117 genlmsg_cancel(msg, hdr);
7118 nlmsg_free(msg);
7119}
7120
Jouni Malinen026331c2010-02-15 12:53:10 +02007121static int nl80211_netlink_notify(struct notifier_block * nb,
7122 unsigned long state,
7123 void *_notify)
7124{
7125 struct netlink_notify *notify = _notify;
7126 struct cfg80211_registered_device *rdev;
7127 struct wireless_dev *wdev;
7128
7129 if (state != NETLINK_URELEASE)
7130 return NOTIFY_DONE;
7131
7132 rcu_read_lock();
7133
7134 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
7135 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02007136 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007137
7138 rcu_read_unlock();
7139
7140 return NOTIFY_DONE;
7141}
7142
7143static struct notifier_block nl80211_netlink_notifier = {
7144 .notifier_call = nl80211_netlink_notify,
7145};
7146
Johannes Berg55682962007-09-20 13:09:35 -04007147/* initialisation/exit functions */
7148
7149int nl80211_init(void)
7150{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007151 int err;
Johannes Berg55682962007-09-20 13:09:35 -04007152
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007153 err = genl_register_family_with_ops(&nl80211_fam,
7154 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04007155 if (err)
7156 return err;
7157
Johannes Berg55682962007-09-20 13:09:35 -04007158 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7159 if (err)
7160 goto err_out;
7161
Johannes Berg2a519312009-02-10 21:25:55 +01007162 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7163 if (err)
7164 goto err_out;
7165
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007166 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7167 if (err)
7168 goto err_out;
7169
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007170 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7171 if (err)
7172 goto err_out;
7173
Johannes Bergaff89a92009-07-01 21:26:51 +02007174#ifdef CONFIG_NL80211_TESTMODE
7175 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7176 if (err)
7177 goto err_out;
7178#endif
7179
Jouni Malinen026331c2010-02-15 12:53:10 +02007180 err = netlink_register_notifier(&nl80211_netlink_notifier);
7181 if (err)
7182 goto err_out;
7183
Johannes Berg55682962007-09-20 13:09:35 -04007184 return 0;
7185 err_out:
7186 genl_unregister_family(&nl80211_fam);
7187 return err;
7188}
7189
7190void nl80211_exit(void)
7191{
Jouni Malinen026331c2010-02-15 12:53:10 +02007192 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04007193 genl_unregister_family(&nl80211_fam);
7194}