blob: ca76977010768a4bd61e53cd710c668cf6992572 [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
Jouni Malinend2da5872011-08-08 12:10:30 +0300874 if (dev->ops->mgmt_tx_cancel_wait)
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100875 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
876
Johannes Berg2e161f72010-08-12 15:38:38 +0200877 if (mgmt_stypes) {
878 u16 stypes;
879 struct nlattr *nl_ftypes, *nl_ifs;
880 enum nl80211_iftype ift;
881
882 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
883 if (!nl_ifs)
884 goto nla_put_failure;
885
886 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
887 nl_ftypes = nla_nest_start(msg, ift);
888 if (!nl_ftypes)
889 goto nla_put_failure;
890 i = 0;
891 stypes = mgmt_stypes[ift].tx;
892 while (stypes) {
893 if (stypes & 1)
894 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
895 (i << 4) | IEEE80211_FTYPE_MGMT);
896 stypes >>= 1;
897 i++;
898 }
899 nla_nest_end(msg, nl_ftypes);
900 }
901
Johannes Berg74b70a42010-08-24 12:15:53 +0200902 nla_nest_end(msg, nl_ifs);
903
Johannes Berg2e161f72010-08-12 15:38:38 +0200904 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
905 if (!nl_ifs)
906 goto nla_put_failure;
907
908 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
909 nl_ftypes = nla_nest_start(msg, ift);
910 if (!nl_ftypes)
911 goto nla_put_failure;
912 i = 0;
913 stypes = mgmt_stypes[ift].rx;
914 while (stypes) {
915 if (stypes & 1)
916 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
917 (i << 4) | IEEE80211_FTYPE_MGMT);
918 stypes >>= 1;
919 i++;
920 }
921 nla_nest_end(msg, nl_ftypes);
922 }
923 nla_nest_end(msg, nl_ifs);
924 }
925
Johannes Bergff1b6e62011-05-04 15:37:28 +0200926 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
927 struct nlattr *nl_wowlan;
928
929 nl_wowlan = nla_nest_start(msg,
930 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
931 if (!nl_wowlan)
932 goto nla_put_failure;
933
934 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
935 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
936 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
937 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
938 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
939 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +0200940 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
941 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
942 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
943 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
944 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
945 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
946 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
947 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
948 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
949 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +0200950 if (dev->wiphy.wowlan.n_patterns) {
951 struct nl80211_wowlan_pattern_support pat = {
952 .max_patterns = dev->wiphy.wowlan.n_patterns,
953 .min_pattern_len =
954 dev->wiphy.wowlan.pattern_min_len,
955 .max_pattern_len =
956 dev->wiphy.wowlan.pattern_max_len,
957 };
958 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
959 sizeof(pat), &pat);
960 }
961
962 nla_nest_end(msg, nl_wowlan);
963 }
964
Johannes Berg7527a782011-05-13 10:58:57 +0200965 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
966 dev->wiphy.software_iftypes))
967 goto nla_put_failure;
968
969 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
970 goto nla_put_failure;
971
Johannes Berg55682962007-09-20 13:09:35 -0400972 return genlmsg_end(msg, hdr);
973
974 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700975 genlmsg_cancel(msg, hdr);
976 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -0400977}
978
979static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
980{
981 int idx = 0;
982 int start = cb->args[0];
983 struct cfg80211_registered_device *dev;
984
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500985 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +0200986 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +0200987 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
988 continue;
Julius Volzb4637272008-07-08 14:02:19 +0200989 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -0400990 continue;
991 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
992 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +0200993 dev) < 0) {
994 idx--;
Johannes Berg55682962007-09-20 13:09:35 -0400995 break;
Julius Volzb4637272008-07-08 14:02:19 +0200996 }
Johannes Berg55682962007-09-20 13:09:35 -0400997 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500998 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400999
1000 cb->args[0] = idx;
1001
1002 return skb->len;
1003}
1004
1005static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1006{
1007 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001008 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001009
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001010 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001011 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001012 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001013
Johannes Berg4c476992010-10-04 21:36:35 +02001014 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1015 nlmsg_free(msg);
1016 return -ENOBUFS;
1017 }
Johannes Berg55682962007-09-20 13:09:35 -04001018
Johannes Berg134e6372009-07-10 09:51:34 +00001019 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001020}
1021
Jouni Malinen31888482008-10-30 16:59:24 +02001022static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1023 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1024 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1025 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1026 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1027 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1028};
1029
1030static int parse_txq_params(struct nlattr *tb[],
1031 struct ieee80211_txq_params *txq_params)
1032{
1033 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1034 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1035 !tb[NL80211_TXQ_ATTR_AIFS])
1036 return -EINVAL;
1037
1038 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1039 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1040 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1041 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1042 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1043
1044 return 0;
1045}
1046
Johannes Bergf444de02010-05-05 15:25:02 +02001047static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1048{
1049 /*
1050 * You can only set the channel explicitly for AP, mesh
1051 * and WDS type interfaces; all others have their channel
1052 * managed via their respective "establish a connection"
1053 * command (connect, join, ...)
1054 *
1055 * Monitors are special as they are normally slaved to
1056 * whatever else is going on, so they behave as though
1057 * you tried setting the wiphy channel itself.
1058 */
1059 return !wdev ||
1060 wdev->iftype == NL80211_IFTYPE_AP ||
1061 wdev->iftype == NL80211_IFTYPE_WDS ||
1062 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001063 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1064 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001065}
1066
1067static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1068 struct wireless_dev *wdev,
1069 struct genl_info *info)
1070{
1071 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1072 u32 freq;
1073 int result;
1074
1075 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1076 return -EINVAL;
1077
1078 if (!nl80211_can_set_dev_channel(wdev))
1079 return -EOPNOTSUPP;
1080
1081 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1082 channel_type = nla_get_u32(info->attrs[
1083 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1084 if (channel_type != NL80211_CHAN_NO_HT &&
1085 channel_type != NL80211_CHAN_HT20 &&
1086 channel_type != NL80211_CHAN_HT40PLUS &&
1087 channel_type != NL80211_CHAN_HT40MINUS)
1088 return -EINVAL;
1089 }
1090
1091 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1092
1093 mutex_lock(&rdev->devlist_mtx);
1094 if (wdev) {
1095 wdev_lock(wdev);
1096 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1097 wdev_unlock(wdev);
1098 } else {
1099 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1100 }
1101 mutex_unlock(&rdev->devlist_mtx);
1102
1103 return result;
1104}
1105
1106static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1107{
Johannes Berg4c476992010-10-04 21:36:35 +02001108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1109 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001110
Johannes Berg4c476992010-10-04 21:36:35 +02001111 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001112}
1113
Bill Jordane8347eb2010-10-01 13:54:28 -04001114static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1115{
Johannes Berg43b19952010-10-07 13:10:30 +02001116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1117 struct net_device *dev = info->user_ptr[1];
1118 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001119 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001120
1121 if (!info->attrs[NL80211_ATTR_MAC])
1122 return -EINVAL;
1123
Johannes Berg43b19952010-10-07 13:10:30 +02001124 if (netif_running(dev))
1125 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001126
Johannes Berg43b19952010-10-07 13:10:30 +02001127 if (!rdev->ops->set_wds_peer)
1128 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001129
Johannes Berg43b19952010-10-07 13:10:30 +02001130 if (wdev->iftype != NL80211_IFTYPE_WDS)
1131 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001132
1133 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001134 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001135}
1136
1137
Johannes Berg55682962007-09-20 13:09:35 -04001138static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1139{
1140 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001141 struct net_device *netdev = NULL;
1142 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001143 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001144 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001145 u32 changed;
1146 u8 retry_short = 0, retry_long = 0;
1147 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001148 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001149
Johannes Bergf444de02010-05-05 15:25:02 +02001150 /*
1151 * Try to find the wiphy and netdev. Normally this
1152 * function shouldn't need the netdev, but this is
1153 * done for backward compatibility -- previously
1154 * setting the channel was done per wiphy, but now
1155 * it is per netdev. Previous userland like hostapd
1156 * also passed a netdev to set_wiphy, so that it is
1157 * possible to let that go to the right netdev!
1158 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001159 mutex_lock(&cfg80211_mutex);
1160
Johannes Bergf444de02010-05-05 15:25:02 +02001161 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1162 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1163
1164 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1165 if (netdev && netdev->ieee80211_ptr) {
1166 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1167 mutex_lock(&rdev->mtx);
1168 } else
1169 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001170 }
1171
Johannes Bergf444de02010-05-05 15:25:02 +02001172 if (!netdev) {
1173 rdev = __cfg80211_rdev_from_info(info);
1174 if (IS_ERR(rdev)) {
1175 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001176 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001177 }
1178 wdev = NULL;
1179 netdev = NULL;
1180 result = 0;
1181
1182 mutex_lock(&rdev->mtx);
1183 } else if (netif_running(netdev) &&
1184 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1185 wdev = netdev->ieee80211_ptr;
1186 else
1187 wdev = NULL;
1188
1189 /*
1190 * end workaround code, by now the rdev is available
1191 * and locked, and wdev may or may not be NULL.
1192 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001193
1194 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001195 result = cfg80211_dev_rename(
1196 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001197
1198 mutex_unlock(&cfg80211_mutex);
1199
1200 if (result)
1201 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001202
Jouni Malinen31888482008-10-30 16:59:24 +02001203 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1204 struct ieee80211_txq_params txq_params;
1205 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1206
1207 if (!rdev->ops->set_txq_params) {
1208 result = -EOPNOTSUPP;
1209 goto bad_res;
1210 }
1211
1212 nla_for_each_nested(nl_txq_params,
1213 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1214 rem_txq_params) {
1215 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1216 nla_data(nl_txq_params),
1217 nla_len(nl_txq_params),
1218 txq_params_policy);
1219 result = parse_txq_params(tb, &txq_params);
1220 if (result)
1221 goto bad_res;
1222
1223 result = rdev->ops->set_txq_params(&rdev->wiphy,
1224 &txq_params);
1225 if (result)
1226 goto bad_res;
1227 }
1228 }
1229
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001230 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001231 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001232 if (result)
1233 goto bad_res;
1234 }
1235
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001236 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1237 enum nl80211_tx_power_setting type;
1238 int idx, mbm = 0;
1239
1240 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001241 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001242 goto bad_res;
1243 }
1244
1245 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1246 type = nla_get_u32(info->attrs[idx]);
1247
1248 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1249 (type != NL80211_TX_POWER_AUTOMATIC)) {
1250 result = -EINVAL;
1251 goto bad_res;
1252 }
1253
1254 if (type != NL80211_TX_POWER_AUTOMATIC) {
1255 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1256 mbm = nla_get_u32(info->attrs[idx]);
1257 }
1258
1259 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1260 if (result)
1261 goto bad_res;
1262 }
1263
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001264 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1265 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1266 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001267 if ((!rdev->wiphy.available_antennas_tx &&
1268 !rdev->wiphy.available_antennas_rx) ||
1269 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001270 result = -EOPNOTSUPP;
1271 goto bad_res;
1272 }
1273
1274 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1275 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1276
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001277 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001278 * available antenna masks, except for the "all" mask */
1279 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1280 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001281 result = -EINVAL;
1282 goto bad_res;
1283 }
1284
Bruno Randolf7f531e02010-12-16 11:30:22 +09001285 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1286 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001287
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001288 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1289 if (result)
1290 goto bad_res;
1291 }
1292
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001293 changed = 0;
1294
1295 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1296 retry_short = nla_get_u8(
1297 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1298 if (retry_short == 0) {
1299 result = -EINVAL;
1300 goto bad_res;
1301 }
1302 changed |= WIPHY_PARAM_RETRY_SHORT;
1303 }
1304
1305 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1306 retry_long = nla_get_u8(
1307 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1308 if (retry_long == 0) {
1309 result = -EINVAL;
1310 goto bad_res;
1311 }
1312 changed |= WIPHY_PARAM_RETRY_LONG;
1313 }
1314
1315 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1316 frag_threshold = nla_get_u32(
1317 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1318 if (frag_threshold < 256) {
1319 result = -EINVAL;
1320 goto bad_res;
1321 }
1322 if (frag_threshold != (u32) -1) {
1323 /*
1324 * Fragments (apart from the last one) are required to
1325 * have even length. Make the fragmentation code
1326 * simpler by stripping LSB should someone try to use
1327 * odd threshold value.
1328 */
1329 frag_threshold &= ~0x1;
1330 }
1331 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1332 }
1333
1334 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1335 rts_threshold = nla_get_u32(
1336 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1337 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1338 }
1339
Lukáš Turek81077e82009-12-21 22:50:47 +01001340 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1341 coverage_class = nla_get_u8(
1342 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1343 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1344 }
1345
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001346 if (changed) {
1347 u8 old_retry_short, old_retry_long;
1348 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001349 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001350
1351 if (!rdev->ops->set_wiphy_params) {
1352 result = -EOPNOTSUPP;
1353 goto bad_res;
1354 }
1355
1356 old_retry_short = rdev->wiphy.retry_short;
1357 old_retry_long = rdev->wiphy.retry_long;
1358 old_frag_threshold = rdev->wiphy.frag_threshold;
1359 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001360 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001361
1362 if (changed & WIPHY_PARAM_RETRY_SHORT)
1363 rdev->wiphy.retry_short = retry_short;
1364 if (changed & WIPHY_PARAM_RETRY_LONG)
1365 rdev->wiphy.retry_long = retry_long;
1366 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1367 rdev->wiphy.frag_threshold = frag_threshold;
1368 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1369 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001370 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1371 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001372
1373 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1374 if (result) {
1375 rdev->wiphy.retry_short = old_retry_short;
1376 rdev->wiphy.retry_long = old_retry_long;
1377 rdev->wiphy.frag_threshold = old_frag_threshold;
1378 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001379 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001380 }
1381 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001382
Johannes Berg306d6112008-12-08 12:39:04 +01001383 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001384 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001385 if (netdev)
1386 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001387 return result;
1388}
1389
1390
1391static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001392 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001393 struct net_device *dev)
1394{
1395 void *hdr;
1396
1397 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1398 if (!hdr)
1399 return -1;
1400
1401 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001402 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001403 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001404 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001405
1406 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1407 rdev->devlist_generation ^
1408 (cfg80211_rdev_list_generation << 2));
1409
Johannes Berg55682962007-09-20 13:09:35 -04001410 return genlmsg_end(msg, hdr);
1411
1412 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001413 genlmsg_cancel(msg, hdr);
1414 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001415}
1416
1417static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1418{
1419 int wp_idx = 0;
1420 int if_idx = 0;
1421 int wp_start = cb->args[0];
1422 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001423 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001424 struct wireless_dev *wdev;
1425
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001426 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001427 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1428 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001429 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001430 if (wp_idx < wp_start) {
1431 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001432 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001433 }
Johannes Berg55682962007-09-20 13:09:35 -04001434 if_idx = 0;
1435
Johannes Bergf5ea9122009-08-07 16:17:38 +02001436 mutex_lock(&rdev->devlist_mtx);
1437 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001438 if (if_idx < if_start) {
1439 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001440 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001441 }
Johannes Berg55682962007-09-20 13:09:35 -04001442 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1443 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001444 rdev, wdev->netdev) < 0) {
1445 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001446 goto out;
1447 }
1448 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001449 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001450 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001451
1452 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001453 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001454 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001455 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001456
1457 cb->args[0] = wp_idx;
1458 cb->args[1] = if_idx;
1459
1460 return skb->len;
1461}
1462
1463static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1464{
1465 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001466 struct cfg80211_registered_device *dev = info->user_ptr[0];
1467 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001468
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001470 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001471 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001472
Johannes Bergd7264052009-04-19 16:23:20 +02001473 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001474 dev, netdev) < 0) {
1475 nlmsg_free(msg);
1476 return -ENOBUFS;
1477 }
Johannes Berg55682962007-09-20 13:09:35 -04001478
Johannes Berg134e6372009-07-10 09:51:34 +00001479 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001480}
1481
Michael Wu66f7ac52008-01-31 19:48:22 +01001482static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1483 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1484 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1485 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1486 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1487 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1488};
1489
1490static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1491{
1492 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1493 int flag;
1494
1495 *mntrflags = 0;
1496
1497 if (!nla)
1498 return -EINVAL;
1499
1500 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1501 nla, mntr_flags_policy))
1502 return -EINVAL;
1503
1504 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1505 if (flags[flag])
1506 *mntrflags |= (1<<flag);
1507
1508 return 0;
1509}
1510
Johannes Berg9bc383d2009-11-19 11:55:19 +01001511static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001512 struct net_device *netdev, u8 use_4addr,
1513 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001514{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001515 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001516 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001517 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001518 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001519 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001520
1521 switch (iftype) {
1522 case NL80211_IFTYPE_AP_VLAN:
1523 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1524 return 0;
1525 break;
1526 case NL80211_IFTYPE_STATION:
1527 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1528 return 0;
1529 break;
1530 default:
1531 break;
1532 }
1533
1534 return -EOPNOTSUPP;
1535}
1536
Johannes Berg55682962007-09-20 13:09:35 -04001537static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1538{
Johannes Berg4c476992010-10-04 21:36:35 +02001539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001540 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001541 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001542 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001543 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001544 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001545 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001546
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001547 memset(&params, 0, sizeof(params));
1548
Johannes Berg04a773a2009-04-19 21:24:32 +02001549 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001550
Johannes Berg723b0382008-09-16 20:22:09 +02001551 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001552 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001553 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001554 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001555 if (ntype > NL80211_IFTYPE_MAX)
1556 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001557 }
1558
Johannes Berg92ffe052008-09-16 20:39:36 +02001559 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001560 struct wireless_dev *wdev = dev->ieee80211_ptr;
1561
Johannes Berg4c476992010-10-04 21:36:35 +02001562 if (ntype != NL80211_IFTYPE_MESH_POINT)
1563 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001564 if (netif_running(dev))
1565 return -EBUSY;
1566
1567 wdev_lock(wdev);
1568 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1569 IEEE80211_MAX_MESH_ID_LEN);
1570 wdev->mesh_id_up_len =
1571 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1572 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1573 wdev->mesh_id_up_len);
1574 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001575 }
1576
Felix Fietkau8b787642009-11-10 18:53:10 +01001577 if (info->attrs[NL80211_ATTR_4ADDR]) {
1578 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1579 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001580 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001581 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001582 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001583 } else {
1584 params.use_4addr = -1;
1585 }
1586
Johannes Berg92ffe052008-09-16 20:39:36 +02001587 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001588 if (ntype != NL80211_IFTYPE_MONITOR)
1589 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001590 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1591 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001592 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001593 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001594
1595 flags = &_flags;
1596 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001597 }
Johannes Berg3b858752009-03-12 09:55:09 +01001598
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001599 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001600 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001601 else
1602 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001603
Johannes Berg9bc383d2009-11-19 11:55:19 +01001604 if (!err && params.use_4addr != -1)
1605 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1606
Johannes Berg55682962007-09-20 13:09:35 -04001607 return err;
1608}
1609
1610static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1611{
Johannes Berg4c476992010-10-04 21:36:35 +02001612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001613 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001614 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001615 int err;
1616 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001617 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001618
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001619 memset(&params, 0, sizeof(params));
1620
Johannes Berg55682962007-09-20 13:09:35 -04001621 if (!info->attrs[NL80211_ATTR_IFNAME])
1622 return -EINVAL;
1623
1624 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1625 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1626 if (type > NL80211_IFTYPE_MAX)
1627 return -EINVAL;
1628 }
1629
Johannes Berg79c97e92009-07-07 03:56:12 +02001630 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001631 !(rdev->wiphy.interface_modes & (1 << type)))
1632 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001633
Johannes Berg9bc383d2009-11-19 11:55:19 +01001634 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001635 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001636 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001637 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001638 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001639 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001640
Michael Wu66f7ac52008-01-31 19:48:22 +01001641 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1642 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1643 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001644 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001645 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001646 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001647 if (IS_ERR(dev))
1648 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001649
Johannes Berg29cbe682010-12-03 09:20:44 +01001650 if (type == NL80211_IFTYPE_MESH_POINT &&
1651 info->attrs[NL80211_ATTR_MESH_ID]) {
1652 struct wireless_dev *wdev = dev->ieee80211_ptr;
1653
1654 wdev_lock(wdev);
1655 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1656 IEEE80211_MAX_MESH_ID_LEN);
1657 wdev->mesh_id_up_len =
1658 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1659 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1660 wdev->mesh_id_up_len);
1661 wdev_unlock(wdev);
1662 }
1663
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001664 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001665}
1666
1667static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1668{
Johannes Berg4c476992010-10-04 21:36:35 +02001669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1670 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001671
Johannes Berg4c476992010-10-04 21:36:35 +02001672 if (!rdev->ops->del_virtual_intf)
1673 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001674
Johannes Berg4c476992010-10-04 21:36:35 +02001675 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001676}
1677
Johannes Berg41ade002007-12-19 02:03:29 +01001678struct get_key_cookie {
1679 struct sk_buff *msg;
1680 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001681 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001682};
1683
1684static void get_key_callback(void *c, struct key_params *params)
1685{
Johannes Bergb9454e82009-07-08 13:29:08 +02001686 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001687 struct get_key_cookie *cookie = c;
1688
1689 if (params->key)
1690 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1691 params->key_len, params->key);
1692
1693 if (params->seq)
1694 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1695 params->seq_len, params->seq);
1696
1697 if (params->cipher)
1698 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1699 params->cipher);
1700
Johannes Bergb9454e82009-07-08 13:29:08 +02001701 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1702 if (!key)
1703 goto nla_put_failure;
1704
1705 if (params->key)
1706 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1707 params->key_len, params->key);
1708
1709 if (params->seq)
1710 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1711 params->seq_len, params->seq);
1712
1713 if (params->cipher)
1714 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1715 params->cipher);
1716
1717 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1718
1719 nla_nest_end(cookie->msg, key);
1720
Johannes Berg41ade002007-12-19 02:03:29 +01001721 return;
1722 nla_put_failure:
1723 cookie->error = 1;
1724}
1725
1726static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1727{
Johannes Berg4c476992010-10-04 21:36:35 +02001728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001729 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001730 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001731 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001732 const u8 *mac_addr = NULL;
1733 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001734 struct get_key_cookie cookie = {
1735 .error = 0,
1736 };
1737 void *hdr;
1738 struct sk_buff *msg;
1739
1740 if (info->attrs[NL80211_ATTR_KEY_IDX])
1741 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1742
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001743 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001744 return -EINVAL;
1745
1746 if (info->attrs[NL80211_ATTR_MAC])
1747 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1748
Johannes Berge31b8212010-10-05 19:39:30 +02001749 pairwise = !!mac_addr;
1750 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1751 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1752 if (kt >= NUM_NL80211_KEYTYPES)
1753 return -EINVAL;
1754 if (kt != NL80211_KEYTYPE_GROUP &&
1755 kt != NL80211_KEYTYPE_PAIRWISE)
1756 return -EINVAL;
1757 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1758 }
1759
Johannes Berg4c476992010-10-04 21:36:35 +02001760 if (!rdev->ops->get_key)
1761 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001762
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001763 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001764 if (!msg)
1765 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001766
1767 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1768 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001769 if (IS_ERR(hdr))
1770 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001771
1772 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001773 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001774
1775 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1776 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1777 if (mac_addr)
1778 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1779
Johannes Berge31b8212010-10-05 19:39:30 +02001780 if (pairwise && mac_addr &&
1781 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1782 return -ENOENT;
1783
1784 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1785 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001786
1787 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001788 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001789
1790 if (cookie.error)
1791 goto nla_put_failure;
1792
1793 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001794 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001795
1796 nla_put_failure:
1797 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001798 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001799 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001800 return err;
1801}
1802
1803static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1804{
Johannes Berg4c476992010-10-04 21:36:35 +02001805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001806 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001807 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001808 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001809
Johannes Bergb9454e82009-07-08 13:29:08 +02001810 err = nl80211_parse_key(info, &key);
1811 if (err)
1812 return err;
1813
1814 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001815 return -EINVAL;
1816
Johannes Bergb9454e82009-07-08 13:29:08 +02001817 /* only support setting default key */
1818 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001819 return -EINVAL;
1820
Johannes Bergfffd0932009-07-08 14:22:54 +02001821 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001822
1823 if (key.def) {
1824 if (!rdev->ops->set_default_key) {
1825 err = -EOPNOTSUPP;
1826 goto out;
1827 }
1828
1829 err = nl80211_key_allowed(dev->ieee80211_ptr);
1830 if (err)
1831 goto out;
1832
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001833 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1834 key.def_uni, key.def_multi);
1835
1836 if (err)
1837 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001838
Johannes Berg3d23e342009-09-29 23:27:28 +02001839#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001840 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001841#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001842 } else {
1843 if (key.def_uni || !key.def_multi) {
1844 err = -EINVAL;
1845 goto out;
1846 }
1847
1848 if (!rdev->ops->set_default_mgmt_key) {
1849 err = -EOPNOTSUPP;
1850 goto out;
1851 }
1852
1853 err = nl80211_key_allowed(dev->ieee80211_ptr);
1854 if (err)
1855 goto out;
1856
1857 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1858 dev, key.idx);
1859 if (err)
1860 goto out;
1861
1862#ifdef CONFIG_CFG80211_WEXT
1863 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1864#endif
1865 }
1866
1867 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001868 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001869
Johannes Berg41ade002007-12-19 02:03:29 +01001870 return err;
1871}
1872
1873static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1874{
Johannes Berg4c476992010-10-04 21:36:35 +02001875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001876 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001877 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001878 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001879 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001880
Johannes Bergb9454e82009-07-08 13:29:08 +02001881 err = nl80211_parse_key(info, &key);
1882 if (err)
1883 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001884
Johannes Bergb9454e82009-07-08 13:29:08 +02001885 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001886 return -EINVAL;
1887
Johannes Berg41ade002007-12-19 02:03:29 +01001888 if (info->attrs[NL80211_ATTR_MAC])
1889 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1890
Johannes Berge31b8212010-10-05 19:39:30 +02001891 if (key.type == -1) {
1892 if (mac_addr)
1893 key.type = NL80211_KEYTYPE_PAIRWISE;
1894 else
1895 key.type = NL80211_KEYTYPE_GROUP;
1896 }
1897
1898 /* for now */
1899 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1900 key.type != NL80211_KEYTYPE_GROUP)
1901 return -EINVAL;
1902
Johannes Berg4c476992010-10-04 21:36:35 +02001903 if (!rdev->ops->add_key)
1904 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001905
Johannes Berge31b8212010-10-05 19:39:30 +02001906 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1907 key.type == NL80211_KEYTYPE_PAIRWISE,
1908 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001909 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001910
1911 wdev_lock(dev->ieee80211_ptr);
1912 err = nl80211_key_allowed(dev->ieee80211_ptr);
1913 if (!err)
1914 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001915 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001916 mac_addr, &key.p);
1917 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001918
Johannes Berg41ade002007-12-19 02:03:29 +01001919 return err;
1920}
1921
1922static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1923{
Johannes Berg4c476992010-10-04 21:36:35 +02001924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001925 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001926 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001927 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001928 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001929
Johannes Bergb9454e82009-07-08 13:29:08 +02001930 err = nl80211_parse_key(info, &key);
1931 if (err)
1932 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001933
1934 if (info->attrs[NL80211_ATTR_MAC])
1935 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1936
Johannes Berge31b8212010-10-05 19:39:30 +02001937 if (key.type == -1) {
1938 if (mac_addr)
1939 key.type = NL80211_KEYTYPE_PAIRWISE;
1940 else
1941 key.type = NL80211_KEYTYPE_GROUP;
1942 }
1943
1944 /* for now */
1945 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1946 key.type != NL80211_KEYTYPE_GROUP)
1947 return -EINVAL;
1948
Johannes Berg4c476992010-10-04 21:36:35 +02001949 if (!rdev->ops->del_key)
1950 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001951
Johannes Bergfffd0932009-07-08 14:22:54 +02001952 wdev_lock(dev->ieee80211_ptr);
1953 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02001954
1955 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
1956 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1957 err = -ENOENT;
1958
Johannes Bergfffd0932009-07-08 14:22:54 +02001959 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02001960 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
1961 key.type == NL80211_KEYTYPE_PAIRWISE,
1962 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01001963
Johannes Berg3d23e342009-09-29 23:27:28 +02001964#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02001965 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02001966 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02001967 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001968 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02001969 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
1970 }
1971#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02001972 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02001973
Johannes Berg41ade002007-12-19 02:03:29 +01001974 return err;
1975}
1976
Johannes Berged1b6cc2007-12-19 02:03:32 +01001977static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1978{
1979 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1980 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02001981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1982 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02001983 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001984 struct beacon_parameters params;
Johannes Berg56d18932011-05-09 18:41:15 +02001985 int haveinfo = 0, err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001986
Johannes Bergf4a11bb2009-03-27 12:40:28 +01001987 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1988 return -EINVAL;
1989
Johannes Berg074ac8d2010-09-16 14:58:22 +02001990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02001991 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
1992 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02001993
Johannes Berg56d18932011-05-09 18:41:15 +02001994 memset(&params, 0, sizeof(params));
1995
Johannes Berged1b6cc2007-12-19 02:03:32 +01001996 switch (info->genlhdr->cmd) {
1997 case NL80211_CMD_NEW_BEACON:
1998 /* these are required for NEW_BEACON */
1999 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2000 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02002001 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2002 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002003
Johannes Berg56d18932011-05-09 18:41:15 +02002004 params.interval =
2005 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2006 params.dtim_period =
2007 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2008
2009 err = cfg80211_validate_beacon_int(rdev, params.interval);
2010 if (err)
2011 return err;
2012
Johannes Berg79c97e92009-07-07 03:56:12 +02002013 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002014 break;
2015 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02002016 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002017 break;
2018 default:
2019 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02002020 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002021 }
2022
Johannes Berg4c476992010-10-04 21:36:35 +02002023 if (!call)
2024 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002025
Johannes Berged1b6cc2007-12-19 02:03:32 +01002026 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2027 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2028 params.head_len =
2029 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2030 haveinfo = 1;
2031 }
2032
2033 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2034 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2035 params.tail_len =
2036 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2037 haveinfo = 1;
2038 }
2039
Johannes Berg4c476992010-10-04 21:36:35 +02002040 if (!haveinfo)
2041 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002042
Johannes Berg56d18932011-05-09 18:41:15 +02002043 err = call(&rdev->wiphy, dev, &params);
2044 if (!err && params.interval)
2045 wdev->beacon_interval = params.interval;
2046 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002047}
2048
2049static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
2050{
Johannes Berg4c476992010-10-04 21:36:35 +02002051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2052 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002053 struct wireless_dev *wdev = dev->ieee80211_ptr;
2054 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002055
Johannes Berg4c476992010-10-04 21:36:35 +02002056 if (!rdev->ops->del_beacon)
2057 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002058
Johannes Berg074ac8d2010-09-16 14:58:22 +02002059 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002060 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2061 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002062
Johannes Berg56d18932011-05-09 18:41:15 +02002063 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
2064 if (!err)
2065 wdev->beacon_interval = 0;
2066 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002067}
2068
Johannes Berg5727ef12007-12-19 02:03:34 +01002069static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2070 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2071 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2072 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002073 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002074 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002075};
2076
Johannes Bergeccb8e82009-05-11 21:57:56 +03002077static int parse_station_flags(struct genl_info *info,
2078 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002079{
2080 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002081 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002082 int flag;
2083
Johannes Bergeccb8e82009-05-11 21:57:56 +03002084 /*
2085 * Try parsing the new attribute first so userspace
2086 * can specify both for older kernels.
2087 */
2088 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2089 if (nla) {
2090 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002091
Johannes Bergeccb8e82009-05-11 21:57:56 +03002092 sta_flags = nla_data(nla);
2093 params->sta_flags_mask = sta_flags->mask;
2094 params->sta_flags_set = sta_flags->set;
2095 if ((params->sta_flags_mask |
2096 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2097 return -EINVAL;
2098 return 0;
2099 }
2100
2101 /* if present, parse the old attribute */
2102
2103 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002104 if (!nla)
2105 return 0;
2106
2107 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2108 nla, sta_flags_policy))
2109 return -EINVAL;
2110
Johannes Bergeccb8e82009-05-11 21:57:56 +03002111 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
2112 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002113
2114 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2115 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002116 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002117
2118 return 0;
2119}
2120
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002121static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2122 int attr)
2123{
2124 struct nlattr *rate;
2125 u16 bitrate;
2126
2127 rate = nla_nest_start(msg, attr);
2128 if (!rate)
2129 goto nla_put_failure;
2130
2131 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2132 bitrate = cfg80211_calculate_bitrate(info);
2133 if (bitrate > 0)
2134 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2135
2136 if (info->flags & RATE_INFO_FLAGS_MCS)
2137 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2138 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2139 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2140 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2141 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2142
2143 nla_nest_end(msg, rate);
2144 return true;
2145
2146nla_put_failure:
2147 return false;
2148}
2149
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002150static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2151 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002152 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002153{
2154 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002155 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002156
2157 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2158 if (!hdr)
2159 return -1;
2160
2161 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2162 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2163
Johannes Bergf5ea9122009-08-07 16:17:38 +02002164 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2165
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002166 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2167 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002168 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302169 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2170 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2171 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002172 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2173 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2174 sinfo->inactive_time);
2175 if (sinfo->filled & STATION_INFO_RX_BYTES)
2176 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2177 sinfo->rx_bytes);
2178 if (sinfo->filled & STATION_INFO_TX_BYTES)
2179 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2180 sinfo->tx_bytes);
2181 if (sinfo->filled & STATION_INFO_LLID)
2182 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2183 sinfo->llid);
2184 if (sinfo->filled & STATION_INFO_PLID)
2185 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2186 sinfo->plid);
2187 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2188 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2189 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002190 if (sinfo->filled & STATION_INFO_SIGNAL)
2191 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2192 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002193 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2194 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2195 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002196 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002197 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2198 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002199 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002200 }
2201 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2202 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2203 NL80211_STA_INFO_RX_BITRATE))
2204 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002205 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002206 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2207 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2208 sinfo->rx_packets);
2209 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2210 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2211 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002212 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2213 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2214 sinfo->tx_retries);
2215 if (sinfo->filled & STATION_INFO_TX_FAILED)
2216 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2217 sinfo->tx_failed);
Paul Stewartf4263c92011-03-31 09:25:41 -07002218 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2219 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2220 if (!bss_param)
2221 goto nla_put_failure;
2222
2223 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2224 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2225 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2226 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2227 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2228 NLA_PUT_FLAG(msg,
2229 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2230 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2231 sinfo->bss_param.dtim_period);
2232 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2233 sinfo->bss_param.beacon_interval);
2234
2235 nla_nest_end(msg, bss_param);
2236 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002237 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002238
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002239 if (sinfo->assoc_req_ies)
2240 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2241 sinfo->assoc_req_ies);
2242
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002243 return genlmsg_end(msg, hdr);
2244
2245 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002246 genlmsg_cancel(msg, hdr);
2247 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002248}
2249
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002250static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002251 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002252{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002253 struct station_info sinfo;
2254 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002255 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002256 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002257 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002258 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002259
Johannes Berg67748892010-10-04 21:14:06 +02002260 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2261 if (err)
2262 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002263
2264 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002265 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002266 goto out_err;
2267 }
2268
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 while (1) {
2270 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2271 mac_addr, &sinfo);
2272 if (err == -ENOENT)
2273 break;
2274 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002275 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002276
2277 if (nl80211_send_station(skb,
2278 NETLINK_CB(cb->skb).pid,
2279 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2280 netdev, mac_addr,
2281 &sinfo) < 0)
2282 goto out;
2283
2284 sta_idx++;
2285 }
2286
2287
2288 out:
2289 cb->args[1] = sta_idx;
2290 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002291 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002292 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002293
2294 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002295}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002296
Johannes Berg5727ef12007-12-19 02:03:34 +01002297static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2298{
Johannes Berg4c476992010-10-04 21:36:35 +02002299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2300 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002301 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002302 struct sk_buff *msg;
2303 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002304 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002305
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002306 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002307
2308 if (!info->attrs[NL80211_ATTR_MAC])
2309 return -EINVAL;
2310
2311 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2312
Johannes Berg4c476992010-10-04 21:36:35 +02002313 if (!rdev->ops->get_station)
2314 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002315
Johannes Berg79c97e92009-07-07 03:56:12 +02002316 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002317 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002318 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002319
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002320 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002321 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002322 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002323
2324 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002325 dev, mac_addr, &sinfo) < 0) {
2326 nlmsg_free(msg);
2327 return -ENOBUFS;
2328 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002329
Johannes Berg4c476992010-10-04 21:36:35 +02002330 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002331}
2332
2333/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002334 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002335 */
Johannes Berg463d0182009-07-14 00:33:35 +02002336static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002337 struct cfg80211_registered_device *rdev,
2338 struct net_device **vlan)
2339{
Johannes Berg463d0182009-07-14 00:33:35 +02002340 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002341 *vlan = NULL;
2342
2343 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002344 *vlan = dev_get_by_index(genl_info_net(info),
2345 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002346 if (!*vlan)
2347 return -ENODEV;
2348 if (!(*vlan)->ieee80211_ptr)
2349 return -EINVAL;
2350 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2351 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002352 if (!netif_running(*vlan))
2353 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002354 }
2355 return 0;
2356}
2357
2358static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2359{
Johannes Berg4c476992010-10-04 21:36:35 +02002360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002361 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002362 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002363 struct station_parameters params;
2364 u8 *mac_addr = NULL;
2365
2366 memset(&params, 0, sizeof(params));
2367
2368 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002369 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002370
2371 if (info->attrs[NL80211_ATTR_STA_AID])
2372 return -EINVAL;
2373
2374 if (!info->attrs[NL80211_ATTR_MAC])
2375 return -EINVAL;
2376
2377 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2378
2379 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2380 params.supported_rates =
2381 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2382 params.supported_rates_len =
2383 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2384 }
2385
2386 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2387 params.listen_interval =
2388 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2389
Jouni Malinen36aedc92008-08-25 11:58:58 +03002390 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2391 params.ht_capa =
2392 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2393
Johannes Bergeccb8e82009-05-11 21:57:56 +03002394 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002395 return -EINVAL;
2396
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002397 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2398 params.plink_action =
2399 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2400
Javier Cardona9c3990a2011-05-03 16:57:11 -07002401 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2402 params.plink_state =
2403 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2404
Johannes Berg463d0182009-07-14 00:33:35 +02002405 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002406 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002407 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002408
2409 /* validate settings */
2410 err = 0;
2411
2412 switch (dev->ieee80211_ptr->iftype) {
2413 case NL80211_IFTYPE_AP:
2414 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002415 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002416 /* disallow mesh-specific things */
2417 if (params.plink_action)
2418 err = -EINVAL;
2419 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002420 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002421 case NL80211_IFTYPE_STATION:
2422 /* disallow everything but AUTHORIZED flag */
2423 if (params.plink_action)
2424 err = -EINVAL;
2425 if (params.vlan)
2426 err = -EINVAL;
2427 if (params.supported_rates)
2428 err = -EINVAL;
2429 if (params.ht_capa)
2430 err = -EINVAL;
2431 if (params.listen_interval >= 0)
2432 err = -EINVAL;
2433 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2434 err = -EINVAL;
2435 break;
2436 case NL80211_IFTYPE_MESH_POINT:
2437 /* disallow things mesh doesn't support */
2438 if (params.vlan)
2439 err = -EINVAL;
2440 if (params.ht_capa)
2441 err = -EINVAL;
2442 if (params.listen_interval >= 0)
2443 err = -EINVAL;
Javier Cardonab39c48f2011-04-07 15:08:30 -07002444 if (params.sta_flags_mask &
2445 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002446 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002447 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Berga97f4422009-06-18 17:23:43 +02002448 err = -EINVAL;
2449 break;
2450 default:
2451 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002452 }
2453
Johannes Berg5727ef12007-12-19 02:03:34 +01002454 if (err)
2455 goto out;
2456
Johannes Berg79c97e92009-07-07 03:56:12 +02002457 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002458 err = -EOPNOTSUPP;
2459 goto out;
2460 }
2461
Johannes Berg79c97e92009-07-07 03:56:12 +02002462 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002463
2464 out:
2465 if (params.vlan)
2466 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002467
Johannes Berg5727ef12007-12-19 02:03:34 +01002468 return err;
2469}
2470
2471static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2472{
Johannes Berg4c476992010-10-04 21:36:35 +02002473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002474 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002475 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002476 struct station_parameters params;
2477 u8 *mac_addr = NULL;
2478
2479 memset(&params, 0, sizeof(params));
2480
2481 if (!info->attrs[NL80211_ATTR_MAC])
2482 return -EINVAL;
2483
Johannes Berg5727ef12007-12-19 02:03:34 +01002484 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2485 return -EINVAL;
2486
2487 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2488 return -EINVAL;
2489
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002490 if (!info->attrs[NL80211_ATTR_STA_AID])
2491 return -EINVAL;
2492
Johannes Berg5727ef12007-12-19 02:03:34 +01002493 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2494 params.supported_rates =
2495 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2496 params.supported_rates_len =
2497 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2498 params.listen_interval =
2499 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002500
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002501 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2502 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2503 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002504
Jouni Malinen36aedc92008-08-25 11:58:58 +03002505 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2506 params.ht_capa =
2507 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002508
Javier Cardona96b78df2011-04-07 15:08:33 -07002509 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2510 params.plink_action =
2511 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2512
Johannes Bergeccb8e82009-05-11 21:57:56 +03002513 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002514 return -EINVAL;
2515
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002516 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002517 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardona96b78df2011-04-07 15:08:33 -07002518 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002519 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2520 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002521
Johannes Berg463d0182009-07-14 00:33:35 +02002522 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002523 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002524 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002525
2526 /* validate settings */
2527 err = 0;
2528
Johannes Berg79c97e92009-07-07 03:56:12 +02002529 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002530 err = -EOPNOTSUPP;
2531 goto out;
2532 }
2533
Johannes Berg79c97e92009-07-07 03:56:12 +02002534 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002535
2536 out:
2537 if (params.vlan)
2538 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002539 return err;
2540}
2541
2542static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2543{
Johannes Berg4c476992010-10-04 21:36:35 +02002544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2545 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002546 u8 *mac_addr = NULL;
2547
2548 if (info->attrs[NL80211_ATTR_MAC])
2549 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2550
Johannes Berge80cf852009-05-11 14:43:13 +02002551 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002552 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002553 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002554 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2555 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002556
Johannes Berg4c476992010-10-04 21:36:35 +02002557 if (!rdev->ops->del_station)
2558 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002559
Johannes Berg4c476992010-10-04 21:36:35 +02002560 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002561}
2562
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002563static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2564 int flags, struct net_device *dev,
2565 u8 *dst, u8 *next_hop,
2566 struct mpath_info *pinfo)
2567{
2568 void *hdr;
2569 struct nlattr *pinfoattr;
2570
2571 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2572 if (!hdr)
2573 return -1;
2574
2575 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2576 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2577 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2578
Johannes Bergf5ea9122009-08-07 16:17:38 +02002579 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2580
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002581 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2582 if (!pinfoattr)
2583 goto nla_put_failure;
2584 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2585 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2586 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002587 if (pinfo->filled & MPATH_INFO_SN)
2588 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2589 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002590 if (pinfo->filled & MPATH_INFO_METRIC)
2591 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2592 pinfo->metric);
2593 if (pinfo->filled & MPATH_INFO_EXPTIME)
2594 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2595 pinfo->exptime);
2596 if (pinfo->filled & MPATH_INFO_FLAGS)
2597 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2598 pinfo->flags);
2599 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2600 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2601 pinfo->discovery_timeout);
2602 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2603 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2604 pinfo->discovery_retries);
2605
2606 nla_nest_end(msg, pinfoattr);
2607
2608 return genlmsg_end(msg, hdr);
2609
2610 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002611 genlmsg_cancel(msg, hdr);
2612 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002613}
2614
2615static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002616 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002617{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002618 struct mpath_info pinfo;
2619 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002620 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002621 u8 dst[ETH_ALEN];
2622 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002623 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002624 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002625
Johannes Berg67748892010-10-04 21:14:06 +02002626 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2627 if (err)
2628 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002629
2630 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002631 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002632 goto out_err;
2633 }
2634
Jouni Malineneec60b02009-03-20 21:21:19 +02002635 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2636 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002637 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002638 }
2639
Johannes Bergbba95fe2008-07-29 13:22:51 +02002640 while (1) {
2641 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2642 dst, next_hop, &pinfo);
2643 if (err == -ENOENT)
2644 break;
2645 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002646 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002647
2648 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2649 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2650 netdev, dst, next_hop,
2651 &pinfo) < 0)
2652 goto out;
2653
2654 path_idx++;
2655 }
2656
2657
2658 out:
2659 cb->args[1] = path_idx;
2660 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002661 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002662 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002663 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002664}
2665
2666static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2667{
Johannes Berg4c476992010-10-04 21:36:35 +02002668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002669 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002670 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002671 struct mpath_info pinfo;
2672 struct sk_buff *msg;
2673 u8 *dst = NULL;
2674 u8 next_hop[ETH_ALEN];
2675
2676 memset(&pinfo, 0, sizeof(pinfo));
2677
2678 if (!info->attrs[NL80211_ATTR_MAC])
2679 return -EINVAL;
2680
2681 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2682
Johannes Berg4c476992010-10-04 21:36:35 +02002683 if (!rdev->ops->get_mpath)
2684 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002685
Johannes Berg4c476992010-10-04 21:36:35 +02002686 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2687 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002688
Johannes Berg79c97e92009-07-07 03:56:12 +02002689 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002690 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002691 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002692
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002694 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002695 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002696
2697 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002698 dev, dst, next_hop, &pinfo) < 0) {
2699 nlmsg_free(msg);
2700 return -ENOBUFS;
2701 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002702
Johannes Berg4c476992010-10-04 21:36:35 +02002703 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002704}
2705
2706static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2707{
Johannes Berg4c476992010-10-04 21:36:35 +02002708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2709 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002710 u8 *dst = NULL;
2711 u8 *next_hop = NULL;
2712
2713 if (!info->attrs[NL80211_ATTR_MAC])
2714 return -EINVAL;
2715
2716 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2717 return -EINVAL;
2718
2719 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2720 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2721
Johannes Berg4c476992010-10-04 21:36:35 +02002722 if (!rdev->ops->change_mpath)
2723 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002724
Johannes Berg4c476992010-10-04 21:36:35 +02002725 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2726 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002727
Johannes Berg4c476992010-10-04 21:36:35 +02002728 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002729}
Johannes Berg4c476992010-10-04 21:36:35 +02002730
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002731static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2732{
Johannes Berg4c476992010-10-04 21:36:35 +02002733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2734 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002735 u8 *dst = NULL;
2736 u8 *next_hop = NULL;
2737
2738 if (!info->attrs[NL80211_ATTR_MAC])
2739 return -EINVAL;
2740
2741 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2742 return -EINVAL;
2743
2744 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2745 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2746
Johannes Berg4c476992010-10-04 21:36:35 +02002747 if (!rdev->ops->add_mpath)
2748 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002749
Johannes Berg4c476992010-10-04 21:36:35 +02002750 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2751 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002752
Johannes Berg4c476992010-10-04 21:36:35 +02002753 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002754}
2755
2756static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2757{
Johannes Berg4c476992010-10-04 21:36:35 +02002758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2759 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002760 u8 *dst = NULL;
2761
2762 if (info->attrs[NL80211_ATTR_MAC])
2763 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2764
Johannes Berg4c476992010-10-04 21:36:35 +02002765 if (!rdev->ops->del_mpath)
2766 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002767
Johannes Berg4c476992010-10-04 21:36:35 +02002768 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002769}
2770
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002771static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2772{
Johannes Berg4c476992010-10-04 21:36:35 +02002773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2774 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002775 struct bss_parameters params;
2776
2777 memset(&params, 0, sizeof(params));
2778 /* default to not changing parameters */
2779 params.use_cts_prot = -1;
2780 params.use_short_preamble = -1;
2781 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002782 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002783 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002784
2785 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2786 params.use_cts_prot =
2787 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2788 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2789 params.use_short_preamble =
2790 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2791 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2792 params.use_short_slot_time =
2793 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002794 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2795 params.basic_rates =
2796 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2797 params.basic_rates_len =
2798 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2799 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002800 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2801 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01002802 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2803 params.ht_opmode =
2804 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002805
Johannes Berg4c476992010-10-04 21:36:35 +02002806 if (!rdev->ops->change_bss)
2807 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002808
Johannes Berg074ac8d2010-09-16 14:58:22 +02002809 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002810 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2811 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002812
Johannes Berg4c476992010-10-04 21:36:35 +02002813 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002814}
2815
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002816static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002817 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2818 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2819 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2820 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2821 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2822 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2823};
2824
2825static int parse_reg_rule(struct nlattr *tb[],
2826 struct ieee80211_reg_rule *reg_rule)
2827{
2828 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2829 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2830
2831 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2832 return -EINVAL;
2833 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2834 return -EINVAL;
2835 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2836 return -EINVAL;
2837 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2838 return -EINVAL;
2839 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2840 return -EINVAL;
2841
2842 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2843
2844 freq_range->start_freq_khz =
2845 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2846 freq_range->end_freq_khz =
2847 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2848 freq_range->max_bandwidth_khz =
2849 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2850
2851 power_rule->max_eirp =
2852 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2853
2854 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2855 power_rule->max_antenna_gain =
2856 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2857
2858 return 0;
2859}
2860
2861static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2862{
2863 int r;
2864 char *data = NULL;
2865
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002866 /*
2867 * You should only get this when cfg80211 hasn't yet initialized
2868 * completely when built-in to the kernel right between the time
2869 * window between nl80211_init() and regulatory_init(), if that is
2870 * even possible.
2871 */
2872 mutex_lock(&cfg80211_mutex);
2873 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002874 mutex_unlock(&cfg80211_mutex);
2875 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002876 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002877 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002878
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002879 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2880 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002881
2882 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2883
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002884 r = regulatory_hint_user(data);
2885
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002886 return r;
2887}
2888
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002889static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01002890 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002891{
Johannes Berg4c476992010-10-04 21:36:35 +02002892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02002893 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01002894 struct wireless_dev *wdev = dev->ieee80211_ptr;
2895 struct mesh_config cur_params;
2896 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002897 void *hdr;
2898 struct nlattr *pinfoattr;
2899 struct sk_buff *msg;
2900
Johannes Berg29cbe682010-12-03 09:20:44 +01002901 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2902 return -EOPNOTSUPP;
2903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002904 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02002905 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02002906
Johannes Berg29cbe682010-12-03 09:20:44 +01002907 wdev_lock(wdev);
2908 /* If not connected, get default parameters */
2909 if (!wdev->mesh_id_len)
2910 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
2911 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002912 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01002913 &cur_params);
2914 wdev_unlock(wdev);
2915
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002916 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002917 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002918
2919 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002921 if (!msg)
2922 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002923 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002924 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002925 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01002926 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002927 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002928 if (!pinfoattr)
2929 goto nla_put_failure;
2930 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2931 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2932 cur_params.dot11MeshRetryTimeout);
2933 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2934 cur_params.dot11MeshConfirmTimeout);
2935 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2936 cur_params.dot11MeshHoldingTimeout);
2937 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2938 cur_params.dot11MeshMaxPeerLinks);
2939 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2940 cur_params.dot11MeshMaxRetries);
2941 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2942 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01002943 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
2944 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002945 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2946 cur_params.auto_open_plinks);
2947 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2948 cur_params.dot11MeshHWMPmaxPREQretries);
2949 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2950 cur_params.path_refresh_time);
2951 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2952 cur_params.min_discovery_timeout);
2953 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2954 cur_params.dot11MeshHWMPactivePathTimeout);
2955 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2956 cur_params.dot11MeshHWMPpreqMinInterval);
2957 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2958 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00002959 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
2960 cur_params.dot11MeshHWMPRootMode);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002961 nla_nest_end(msg, pinfoattr);
2962 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002963 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002964
Johannes Berg3b858752009-03-12 09:55:09 +01002965 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002966 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01002967 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04002968 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02002969 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002970}
2971
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002972static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002973 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2974 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2975 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2976 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2977 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2978 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01002979 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002980 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2981
2982 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2983 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2984 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2985 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2986 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2987 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2988};
2989
Javier Cardonac80d5452010-12-16 17:37:49 -08002990static const struct nla_policy
2991 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
2992 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
2993 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07002994 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07002995 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08002996 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07002997 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08002998};
2999
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003000static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003001 struct mesh_config *cfg,
3002 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003003{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003004 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003005 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003006
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003007#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3008do {\
3009 if (table[attr_num]) {\
3010 cfg->param = nla_fn(table[attr_num]); \
3011 mask |= (1 << (attr_num - 1)); \
3012 } \
3013} while (0);\
3014
3015
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003016 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003017 return -EINVAL;
3018 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003019 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003020 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003021 return -EINVAL;
3022
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003023 /* This makes sure that there aren't more than 32 mesh config
3024 * parameters (otherwise our bitfield scheme would not work.) */
3025 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3026
3027 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003028 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3029 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3030 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3031 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3032 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3033 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3034 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3035 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3036 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3037 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3038 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3039 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003040 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3041 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003042 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3043 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3044 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3045 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3046 nla_get_u8);
3047 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3048 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3049 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3050 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3051 nla_get_u16);
3052 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3053 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3054 nla_get_u32);
3055 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3056 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3057 nla_get_u16);
3058 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3059 dot11MeshHWMPnetDiameterTraversalTime,
3060 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3061 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003062 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3063 dot11MeshHWMPRootMode, mask,
3064 NL80211_MESHCONF_HWMP_ROOTMODE,
3065 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003066 if (mask_out)
3067 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003068
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003069 return 0;
3070
3071#undef FILL_IN_MESH_PARAM_IF_SET
3072}
3073
Javier Cardonac80d5452010-12-16 17:37:49 -08003074static int nl80211_parse_mesh_setup(struct genl_info *info,
3075 struct mesh_setup *setup)
3076{
3077 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3078
3079 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3080 return -EINVAL;
3081 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3082 info->attrs[NL80211_ATTR_MESH_SETUP],
3083 nl80211_mesh_setup_params_policy))
3084 return -EINVAL;
3085
3086 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3087 setup->path_sel_proto =
3088 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3089 IEEE80211_PATH_PROTOCOL_VENDOR :
3090 IEEE80211_PATH_PROTOCOL_HWMP;
3091
3092 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3093 setup->path_metric =
3094 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3095 IEEE80211_PATH_METRIC_VENDOR :
3096 IEEE80211_PATH_METRIC_AIRTIME;
3097
Javier Cardona581a8b02011-04-07 15:08:27 -07003098
3099 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003100 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003101 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003102 if (!is_valid_ie_attr(ieattr))
3103 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003104 setup->ie = nla_data(ieattr);
3105 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003106 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003107 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3108 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003109
3110 return 0;
3111}
3112
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003113static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003114 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003115{
3116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3117 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003118 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003119 struct mesh_config cfg;
3120 u32 mask;
3121 int err;
3122
Johannes Berg29cbe682010-12-03 09:20:44 +01003123 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3124 return -EOPNOTSUPP;
3125
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003126 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003127 return -EOPNOTSUPP;
3128
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003129 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003130 if (err)
3131 return err;
3132
Johannes Berg29cbe682010-12-03 09:20:44 +01003133 wdev_lock(wdev);
3134 if (!wdev->mesh_id_len)
3135 err = -ENOLINK;
3136
3137 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003138 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003139 mask, &cfg);
3140
3141 wdev_unlock(wdev);
3142
3143 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003144}
3145
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003146static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3147{
3148 struct sk_buff *msg;
3149 void *hdr = NULL;
3150 struct nlattr *nl_reg_rules;
3151 unsigned int i;
3152 int err = -EINVAL;
3153
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003154 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003155
3156 if (!cfg80211_regdomain)
3157 goto out;
3158
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003159 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003160 if (!msg) {
3161 err = -ENOBUFS;
3162 goto out;
3163 }
3164
3165 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3166 NL80211_CMD_GET_REG);
3167 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003168 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003169
3170 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3171 cfg80211_regdomain->alpha2);
3172
3173 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3174 if (!nl_reg_rules)
3175 goto nla_put_failure;
3176
3177 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3178 struct nlattr *nl_reg_rule;
3179 const struct ieee80211_reg_rule *reg_rule;
3180 const struct ieee80211_freq_range *freq_range;
3181 const struct ieee80211_power_rule *power_rule;
3182
3183 reg_rule = &cfg80211_regdomain->reg_rules[i];
3184 freq_range = &reg_rule->freq_range;
3185 power_rule = &reg_rule->power_rule;
3186
3187 nl_reg_rule = nla_nest_start(msg, i);
3188 if (!nl_reg_rule)
3189 goto nla_put_failure;
3190
3191 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3192 reg_rule->flags);
3193 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3194 freq_range->start_freq_khz);
3195 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3196 freq_range->end_freq_khz);
3197 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3198 freq_range->max_bandwidth_khz);
3199 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3200 power_rule->max_antenna_gain);
3201 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3202 power_rule->max_eirp);
3203
3204 nla_nest_end(msg, nl_reg_rule);
3205 }
3206
3207 nla_nest_end(msg, nl_reg_rules);
3208
3209 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003210 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003211 goto out;
3212
3213nla_put_failure:
3214 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003215put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003216 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003217 err = -EMSGSIZE;
3218out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003219 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003220 return err;
3221}
3222
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003223static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3224{
3225 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3226 struct nlattr *nl_reg_rule;
3227 char *alpha2 = NULL;
3228 int rem_reg_rules = 0, r = 0;
3229 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3230 struct ieee80211_regdomain *rd = NULL;
3231
3232 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3233 return -EINVAL;
3234
3235 if (!info->attrs[NL80211_ATTR_REG_RULES])
3236 return -EINVAL;
3237
3238 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3239
3240 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3241 rem_reg_rules) {
3242 num_rules++;
3243 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003244 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003245 }
3246
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003247 mutex_lock(&cfg80211_mutex);
3248
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003249 if (!reg_is_valid_request(alpha2)) {
3250 r = -EINVAL;
3251 goto bad_reg;
3252 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003253
3254 size_of_regd = sizeof(struct ieee80211_regdomain) +
3255 (num_rules * sizeof(struct ieee80211_reg_rule));
3256
3257 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003258 if (!rd) {
3259 r = -ENOMEM;
3260 goto bad_reg;
3261 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003262
3263 rd->n_reg_rules = num_rules;
3264 rd->alpha2[0] = alpha2[0];
3265 rd->alpha2[1] = alpha2[1];
3266
3267 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3268 rem_reg_rules) {
3269 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3270 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3271 reg_rule_policy);
3272 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3273 if (r)
3274 goto bad_reg;
3275
3276 rule_idx++;
3277
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003278 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3279 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003280 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003281 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003282 }
3283
3284 BUG_ON(rule_idx != num_rules);
3285
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003286 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003287
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003288 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003289
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003290 return r;
3291
Johannes Bergd2372b32008-10-24 20:32:20 +02003292 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003293 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003294 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003295 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003296}
3297
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003298static int validate_scan_freqs(struct nlattr *freqs)
3299{
3300 struct nlattr *attr1, *attr2;
3301 int n_channels = 0, tmp1, tmp2;
3302
3303 nla_for_each_nested(attr1, freqs, tmp1) {
3304 n_channels++;
3305 /*
3306 * Some hardware has a limited channel list for
3307 * scanning, and it is pretty much nonsensical
3308 * to scan for a channel twice, so disallow that
3309 * and don't require drivers to check that the
3310 * channel list they get isn't longer than what
3311 * they can scan, as long as they can scan all
3312 * the channels they registered at once.
3313 */
3314 nla_for_each_nested(attr2, freqs, tmp2)
3315 if (attr1 != attr2 &&
3316 nla_get_u32(attr1) == nla_get_u32(attr2))
3317 return 0;
3318 }
3319
3320 return n_channels;
3321}
3322
Johannes Berg2a519312009-02-10 21:25:55 +01003323static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3324{
Johannes Berg4c476992010-10-04 21:36:35 +02003325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3326 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003327 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003328 struct nlattr *attr;
3329 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003330 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003331 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003332
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003333 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3334 return -EINVAL;
3335
Johannes Berg79c97e92009-07-07 03:56:12 +02003336 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003337
Johannes Berg4c476992010-10-04 21:36:35 +02003338 if (!rdev->ops->scan)
3339 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003340
Johannes Berg4c476992010-10-04 21:36:35 +02003341 if (rdev->scan_req)
3342 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003343
3344 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003345 n_channels = validate_scan_freqs(
3346 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003347 if (!n_channels)
3348 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003349 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003350 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003351 n_channels = 0;
3352
Johannes Berg2a519312009-02-10 21:25:55 +01003353 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3354 if (wiphy->bands[band])
3355 n_channels += wiphy->bands[band]->n_channels;
3356 }
3357
3358 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3359 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3360 n_ssids++;
3361
Johannes Berg4c476992010-10-04 21:36:35 +02003362 if (n_ssids > wiphy->max_scan_ssids)
3363 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003364
Jouni Malinen70692ad2009-02-16 19:39:13 +02003365 if (info->attrs[NL80211_ATTR_IE])
3366 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3367 else
3368 ie_len = 0;
3369
Johannes Berg4c476992010-10-04 21:36:35 +02003370 if (ie_len > wiphy->max_scan_ie_len)
3371 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003372
Johannes Berg2a519312009-02-10 21:25:55 +01003373 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003374 + sizeof(*request->ssids) * n_ssids
3375 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003376 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003377 if (!request)
3378 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003379
Johannes Berg2a519312009-02-10 21:25:55 +01003380 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003381 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003382 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003383 if (ie_len) {
3384 if (request->ssids)
3385 request->ie = (void *)(request->ssids + n_ssids);
3386 else
3387 request->ie = (void *)(request->channels + n_channels);
3388 }
Johannes Berg2a519312009-02-10 21:25:55 +01003389
Johannes Berg584991d2009-11-02 13:32:03 +01003390 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003391 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3392 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003393 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003394 struct ieee80211_channel *chan;
3395
3396 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3397
3398 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003399 err = -EINVAL;
3400 goto out_free;
3401 }
Johannes Berg584991d2009-11-02 13:32:03 +01003402
3403 /* ignore disabled channels */
3404 if (chan->flags & IEEE80211_CHAN_DISABLED)
3405 continue;
3406
3407 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003408 i++;
3409 }
3410 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003411 enum ieee80211_band band;
3412
Johannes Berg2a519312009-02-10 21:25:55 +01003413 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003414 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3415 int j;
3416 if (!wiphy->bands[band])
3417 continue;
3418 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003419 struct ieee80211_channel *chan;
3420
3421 chan = &wiphy->bands[band]->channels[j];
3422
3423 if (chan->flags & IEEE80211_CHAN_DISABLED)
3424 continue;
3425
3426 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003427 i++;
3428 }
3429 }
3430 }
3431
Johannes Berg584991d2009-11-02 13:32:03 +01003432 if (!i) {
3433 err = -EINVAL;
3434 goto out_free;
3435 }
3436
3437 request->n_channels = i;
3438
Johannes Berg2a519312009-02-10 21:25:55 +01003439 i = 0;
3440 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3441 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003442 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003443 err = -EINVAL;
3444 goto out_free;
3445 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003446 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003447 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003448 i++;
3449 }
3450 }
3451
Jouni Malinen70692ad2009-02-16 19:39:13 +02003452 if (info->attrs[NL80211_ATTR_IE]) {
3453 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003454 memcpy((void *)request->ie,
3455 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003456 request->ie_len);
3457 }
3458
Johannes Berg34850ab2011-07-18 18:08:35 +02003459 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003460 if (wiphy->bands[i])
3461 request->rates[i] =
3462 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003463
3464 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3465 nla_for_each_nested(attr,
3466 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3467 tmp) {
3468 enum ieee80211_band band = nla_type(attr);
3469
Dan Carpenter84404622011-07-29 11:52:18 +03003470 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003471 err = -EINVAL;
3472 goto out_free;
3473 }
3474 err = ieee80211_get_ratemask(wiphy->bands[band],
3475 nla_data(attr),
3476 nla_len(attr),
3477 &request->rates[band]);
3478 if (err)
3479 goto out_free;
3480 }
3481 }
3482
Johannes Berg463d0182009-07-14 00:33:35 +02003483 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003484 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003485
Johannes Berg79c97e92009-07-07 03:56:12 +02003486 rdev->scan_req = request;
3487 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003488
Johannes Berg463d0182009-07-14 00:33:35 +02003489 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003490 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003491 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003492 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003493 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003494 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003495 kfree(request);
3496 }
Johannes Berg3b858752009-03-12 09:55:09 +01003497
Johannes Berg2a519312009-02-10 21:25:55 +01003498 return err;
3499}
3500
Luciano Coelho807f8a82011-05-11 17:09:35 +03003501static int nl80211_start_sched_scan(struct sk_buff *skb,
3502 struct genl_info *info)
3503{
3504 struct cfg80211_sched_scan_request *request;
3505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3506 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003507 struct nlattr *attr;
3508 struct wiphy *wiphy;
3509 int err, tmp, n_ssids = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003510 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003511 enum ieee80211_band band;
3512 size_t ie_len;
3513
3514 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3515 !rdev->ops->sched_scan_start)
3516 return -EOPNOTSUPP;
3517
3518 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3519 return -EINVAL;
3520
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003521 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3522 return -EINVAL;
3523
3524 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3525 if (interval == 0)
3526 return -EINVAL;
3527
Luciano Coelho807f8a82011-05-11 17:09:35 +03003528 wiphy = &rdev->wiphy;
3529
3530 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3531 n_channels = validate_scan_freqs(
3532 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3533 if (!n_channels)
3534 return -EINVAL;
3535 } else {
3536 n_channels = 0;
3537
3538 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3539 if (wiphy->bands[band])
3540 n_channels += wiphy->bands[band]->n_channels;
3541 }
3542
3543 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3544 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3545 tmp)
3546 n_ssids++;
3547
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003548 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003549 return -EINVAL;
3550
3551 if (info->attrs[NL80211_ATTR_IE])
3552 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3553 else
3554 ie_len = 0;
3555
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003556 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003557 return -EINVAL;
3558
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003559 mutex_lock(&rdev->sched_scan_mtx);
3560
3561 if (rdev->sched_scan_req) {
3562 err = -EINPROGRESS;
3563 goto out;
3564 }
3565
Luciano Coelho807f8a82011-05-11 17:09:35 +03003566 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003567 + sizeof(*request->ssids) * n_ssids
3568 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003569 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003570 if (!request) {
3571 err = -ENOMEM;
3572 goto out;
3573 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003574
3575 if (n_ssids)
3576 request->ssids = (void *)&request->channels[n_channels];
3577 request->n_ssids = n_ssids;
3578 if (ie_len) {
3579 if (request->ssids)
3580 request->ie = (void *)(request->ssids + n_ssids);
3581 else
3582 request->ie = (void *)(request->channels + n_channels);
3583 }
3584
3585 i = 0;
3586 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3587 /* user specified, bail out if channel not found */
3588 nla_for_each_nested(attr,
3589 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3590 tmp) {
3591 struct ieee80211_channel *chan;
3592
3593 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3594
3595 if (!chan) {
3596 err = -EINVAL;
3597 goto out_free;
3598 }
3599
3600 /* ignore disabled channels */
3601 if (chan->flags & IEEE80211_CHAN_DISABLED)
3602 continue;
3603
3604 request->channels[i] = chan;
3605 i++;
3606 }
3607 } else {
3608 /* all channels */
3609 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3610 int j;
3611 if (!wiphy->bands[band])
3612 continue;
3613 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3614 struct ieee80211_channel *chan;
3615
3616 chan = &wiphy->bands[band]->channels[j];
3617
3618 if (chan->flags & IEEE80211_CHAN_DISABLED)
3619 continue;
3620
3621 request->channels[i] = chan;
3622 i++;
3623 }
3624 }
3625 }
3626
3627 if (!i) {
3628 err = -EINVAL;
3629 goto out_free;
3630 }
3631
3632 request->n_channels = i;
3633
3634 i = 0;
3635 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3636 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3637 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003638 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03003639 err = -EINVAL;
3640 goto out_free;
3641 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003642 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003643 memcpy(request->ssids[i].ssid, nla_data(attr),
3644 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03003645 i++;
3646 }
3647 }
3648
3649 if (info->attrs[NL80211_ATTR_IE]) {
3650 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3651 memcpy((void *)request->ie,
3652 nla_data(info->attrs[NL80211_ATTR_IE]),
3653 request->ie_len);
3654 }
3655
3656 request->dev = dev;
3657 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003658 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003659
3660 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3661 if (!err) {
3662 rdev->sched_scan_req = request;
3663 nl80211_send_sched_scan(rdev, dev,
3664 NL80211_CMD_START_SCHED_SCAN);
3665 goto out;
3666 }
3667
3668out_free:
3669 kfree(request);
3670out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003671 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003672 return err;
3673}
3674
3675static int nl80211_stop_sched_scan(struct sk_buff *skb,
3676 struct genl_info *info)
3677{
3678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003679 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003680
3681 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3682 !rdev->ops->sched_scan_stop)
3683 return -EOPNOTSUPP;
3684
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003685 mutex_lock(&rdev->sched_scan_mtx);
3686 err = __cfg80211_stop_sched_scan(rdev, false);
3687 mutex_unlock(&rdev->sched_scan_mtx);
3688
3689 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003690}
3691
Johannes Berg9720bb32011-06-21 09:45:33 +02003692static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3693 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003694 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003695 struct wireless_dev *wdev,
3696 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003697{
Johannes Berg48ab9052009-07-10 18:42:31 +02003698 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003699 void *hdr;
3700 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003701 int i;
3702
3703 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003704
Johannes Berg9720bb32011-06-21 09:45:33 +02003705 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003706 NL80211_CMD_NEW_SCAN_RESULTS);
3707 if (!hdr)
3708 return -1;
3709
Johannes Berg9720bb32011-06-21 09:45:33 +02003710 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
3711
Johannes Bergf5ea9122009-08-07 16:17:38 +02003712 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003713 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003714
3715 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3716 if (!bss)
3717 goto nla_put_failure;
3718 if (!is_zero_ether_addr(res->bssid))
3719 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3720 if (res->information_elements && res->len_information_elements)
3721 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3722 res->len_information_elements,
3723 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003724 if (res->beacon_ies && res->len_beacon_ies &&
3725 res->beacon_ies != res->information_elements)
3726 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3727 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003728 if (res->tsf)
3729 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3730 if (res->beacon_interval)
3731 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3732 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3733 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003734 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3735 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003736
Johannes Berg77965c92009-02-18 18:45:06 +01003737 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003738 case CFG80211_SIGNAL_TYPE_MBM:
3739 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3740 break;
3741 case CFG80211_SIGNAL_TYPE_UNSPEC:
3742 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3743 break;
3744 default:
3745 break;
3746 }
3747
Johannes Berg48ab9052009-07-10 18:42:31 +02003748 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003749 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003750 case NL80211_IFTYPE_STATION:
3751 if (intbss == wdev->current_bss)
3752 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3753 NL80211_BSS_STATUS_ASSOCIATED);
3754 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3755 if (intbss != wdev->auth_bsses[i])
3756 continue;
3757 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3758 NL80211_BSS_STATUS_AUTHENTICATED);
3759 break;
3760 }
3761 break;
3762 case NL80211_IFTYPE_ADHOC:
3763 if (intbss == wdev->current_bss)
3764 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3765 NL80211_BSS_STATUS_IBSS_JOINED);
3766 break;
3767 default:
3768 break;
3769 }
3770
Johannes Berg2a519312009-02-10 21:25:55 +01003771 nla_nest_end(msg, bss);
3772
3773 return genlmsg_end(msg, hdr);
3774
3775 nla_put_failure:
3776 genlmsg_cancel(msg, hdr);
3777 return -EMSGSIZE;
3778}
3779
3780static int nl80211_dump_scan(struct sk_buff *skb,
3781 struct netlink_callback *cb)
3782{
Johannes Berg48ab9052009-07-10 18:42:31 +02003783 struct cfg80211_registered_device *rdev;
3784 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01003785 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02003786 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01003787 int start = cb->args[1], idx = 0;
3788 int err;
3789
Johannes Berg67748892010-10-04 21:14:06 +02003790 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
3791 if (err)
3792 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01003793
Johannes Berg48ab9052009-07-10 18:42:31 +02003794 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01003795
Johannes Berg48ab9052009-07-10 18:42:31 +02003796 wdev_lock(wdev);
3797 spin_lock_bh(&rdev->bss_lock);
3798 cfg80211_bss_expire(rdev);
3799
Johannes Berg9720bb32011-06-21 09:45:33 +02003800 cb->seq = rdev->bss_generation;
3801
Johannes Berg48ab9052009-07-10 18:42:31 +02003802 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01003803 if (++idx <= start)
3804 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02003805 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01003806 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02003807 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01003808 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02003809 break;
Johannes Berg2a519312009-02-10 21:25:55 +01003810 }
3811 }
3812
Johannes Berg48ab9052009-07-10 18:42:31 +02003813 spin_unlock_bh(&rdev->bss_lock);
3814 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003815
3816 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02003817 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003818
Johannes Berg67748892010-10-04 21:14:06 +02003819 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01003820}
3821
Holger Schurig61fa7132009-11-11 12:25:40 +01003822static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3823 int flags, struct net_device *dev,
3824 struct survey_info *survey)
3825{
3826 void *hdr;
3827 struct nlattr *infoattr;
3828
Holger Schurig61fa7132009-11-11 12:25:40 +01003829 hdr = nl80211hdr_put(msg, pid, seq, flags,
3830 NL80211_CMD_NEW_SURVEY_RESULTS);
3831 if (!hdr)
3832 return -ENOMEM;
3833
3834 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3835
3836 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
3837 if (!infoattr)
3838 goto nla_put_failure;
3839
3840 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
3841 survey->channel->center_freq);
3842 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3843 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3844 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02003845 if (survey->filled & SURVEY_INFO_IN_USE)
3846 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02003847 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
3848 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
3849 survey->channel_time);
3850 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
3851 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
3852 survey->channel_time_busy);
3853 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
3854 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
3855 survey->channel_time_ext_busy);
3856 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
3857 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
3858 survey->channel_time_rx);
3859 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
3860 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
3861 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01003862
3863 nla_nest_end(msg, infoattr);
3864
3865 return genlmsg_end(msg, hdr);
3866
3867 nla_put_failure:
3868 genlmsg_cancel(msg, hdr);
3869 return -EMSGSIZE;
3870}
3871
3872static int nl80211_dump_survey(struct sk_buff *skb,
3873 struct netlink_callback *cb)
3874{
3875 struct survey_info survey;
3876 struct cfg80211_registered_device *dev;
3877 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01003878 int survey_idx = cb->args[1];
3879 int res;
3880
Johannes Berg67748892010-10-04 21:14:06 +02003881 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3882 if (res)
3883 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01003884
3885 if (!dev->ops->dump_survey) {
3886 res = -EOPNOTSUPP;
3887 goto out_err;
3888 }
3889
3890 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07003891 struct ieee80211_channel *chan;
3892
Holger Schurig61fa7132009-11-11 12:25:40 +01003893 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
3894 &survey);
3895 if (res == -ENOENT)
3896 break;
3897 if (res)
3898 goto out_err;
3899
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07003900 /* Survey without a channel doesn't make sense */
3901 if (!survey.channel) {
3902 res = -EINVAL;
3903 goto out;
3904 }
3905
3906 chan = ieee80211_get_channel(&dev->wiphy,
3907 survey.channel->center_freq);
3908 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
3909 survey_idx++;
3910 continue;
3911 }
3912
Holger Schurig61fa7132009-11-11 12:25:40 +01003913 if (nl80211_send_survey(skb,
3914 NETLINK_CB(cb->skb).pid,
3915 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3916 netdev,
3917 &survey) < 0)
3918 goto out;
3919 survey_idx++;
3920 }
3921
3922 out:
3923 cb->args[1] = survey_idx;
3924 res = skb->len;
3925 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003926 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01003927 return res;
3928}
3929
Jouni Malinen255e7372009-03-20 21:21:17 +02003930static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
3931{
Samuel Ortizb23aa672009-07-01 21:26:54 +02003932 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02003933}
3934
Samuel Ortizb23aa672009-07-01 21:26:54 +02003935static bool nl80211_valid_wpa_versions(u32 wpa_versions)
3936{
3937 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
3938 NL80211_WPA_VERSION_2));
3939}
3940
3941static bool nl80211_valid_akm_suite(u32 akm)
3942{
3943 return akm == WLAN_AKM_SUITE_8021X ||
3944 akm == WLAN_AKM_SUITE_PSK;
3945}
3946
3947static bool nl80211_valid_cipher_suite(u32 cipher)
3948{
3949 return cipher == WLAN_CIPHER_SUITE_WEP40 ||
3950 cipher == WLAN_CIPHER_SUITE_WEP104 ||
3951 cipher == WLAN_CIPHER_SUITE_TKIP ||
3952 cipher == WLAN_CIPHER_SUITE_CCMP ||
3953 cipher == WLAN_CIPHER_SUITE_AES_CMAC;
3954}
3955
3956
Jouni Malinen636a5d32009-03-19 13:39:22 +02003957static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3958{
Johannes Berg4c476992010-10-04 21:36:35 +02003959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3960 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003961 struct ieee80211_channel *chan;
3962 const u8 *bssid, *ssid, *ie = NULL;
3963 int err, ssid_len, ie_len = 0;
3964 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02003965 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003966 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003967
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003968 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3969 return -EINVAL;
3970
3971 if (!info->attrs[NL80211_ATTR_MAC])
3972 return -EINVAL;
3973
Jouni Malinen17780922009-03-27 20:52:47 +02003974 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
3975 return -EINVAL;
3976
Johannes Berg19957bb2009-07-02 17:20:43 +02003977 if (!info->attrs[NL80211_ATTR_SSID])
3978 return -EINVAL;
3979
3980 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
3981 return -EINVAL;
3982
Johannes Bergfffd0932009-07-08 14:22:54 +02003983 err = nl80211_parse_key(info, &key);
3984 if (err)
3985 return err;
3986
3987 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02003988 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
3989 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003990 if (!key.p.key || !key.p.key_len)
3991 return -EINVAL;
3992 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
3993 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
3994 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
3995 key.p.key_len != WLAN_KEY_LEN_WEP104))
3996 return -EINVAL;
3997 if (key.idx > 4)
3998 return -EINVAL;
3999 } else {
4000 key.p.key_len = 0;
4001 key.p.key = NULL;
4002 }
4003
Johannes Bergafea0b72010-08-10 09:46:42 +02004004 if (key.idx >= 0) {
4005 int i;
4006 bool ok = false;
4007 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4008 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4009 ok = true;
4010 break;
4011 }
4012 }
Johannes Berg4c476992010-10-04 21:36:35 +02004013 if (!ok)
4014 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004015 }
4016
Johannes Berg4c476992010-10-04 21:36:35 +02004017 if (!rdev->ops->auth)
4018 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004019
Johannes Berg074ac8d2010-09-16 14:58:22 +02004020 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004021 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4022 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004023
Johannes Berg19957bb2009-07-02 17:20:43 +02004024 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004025 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004026 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004027 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4028 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004029
Johannes Berg19957bb2009-07-02 17:20:43 +02004030 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4031 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4032
4033 if (info->attrs[NL80211_ATTR_IE]) {
4034 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4035 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4036 }
4037
4038 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004039 if (!nl80211_valid_auth_type(auth_type))
4040 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004041
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004042 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4043
Johannes Berg4c476992010-10-04 21:36:35 +02004044 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4045 ssid, ssid_len, ie, ie_len,
4046 key.p.key, key.p.key_len, key.idx,
4047 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004048}
4049
Johannes Bergc0692b82010-08-27 14:26:53 +03004050static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4051 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004052 struct cfg80211_crypto_settings *settings,
4053 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004054{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004055 memset(settings, 0, sizeof(*settings));
4056
Samuel Ortizb23aa672009-07-01 21:26:54 +02004057 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4058
Johannes Bergc0692b82010-08-27 14:26:53 +03004059 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4060 u16 proto;
4061 proto = nla_get_u16(
4062 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4063 settings->control_port_ethertype = cpu_to_be16(proto);
4064 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4065 proto != ETH_P_PAE)
4066 return -EINVAL;
4067 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4068 settings->control_port_no_encrypt = true;
4069 } else
4070 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4071
Samuel Ortizb23aa672009-07-01 21:26:54 +02004072 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4073 void *data;
4074 int len, i;
4075
4076 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4077 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4078 settings->n_ciphers_pairwise = len / sizeof(u32);
4079
4080 if (len % sizeof(u32))
4081 return -EINVAL;
4082
Johannes Berg3dc27d22009-07-02 21:36:37 +02004083 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004084 return -EINVAL;
4085
4086 memcpy(settings->ciphers_pairwise, data, len);
4087
4088 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4089 if (!nl80211_valid_cipher_suite(
4090 settings->ciphers_pairwise[i]))
4091 return -EINVAL;
4092 }
4093
4094 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4095 settings->cipher_group =
4096 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
4097 if (!nl80211_valid_cipher_suite(settings->cipher_group))
4098 return -EINVAL;
4099 }
4100
4101 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4102 settings->wpa_versions =
4103 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4104 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4105 return -EINVAL;
4106 }
4107
4108 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4109 void *data;
4110 int len, i;
4111
4112 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4113 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4114 settings->n_akm_suites = len / sizeof(u32);
4115
4116 if (len % sizeof(u32))
4117 return -EINVAL;
4118
4119 memcpy(settings->akm_suites, data, len);
4120
4121 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4122 if (!nl80211_valid_akm_suite(settings->akm_suites[i]))
4123 return -EINVAL;
4124 }
4125
4126 return 0;
4127}
4128
Jouni Malinen636a5d32009-03-19 13:39:22 +02004129static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4130{
Johannes Berg4c476992010-10-04 21:36:35 +02004131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4132 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004133 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004134 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004135 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004136 int err, ssid_len, ie_len = 0;
4137 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004138
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004139 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4140 return -EINVAL;
4141
4142 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004143 !info->attrs[NL80211_ATTR_SSID] ||
4144 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004145 return -EINVAL;
4146
Johannes Berg4c476992010-10-04 21:36:35 +02004147 if (!rdev->ops->assoc)
4148 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004149
Johannes Berg074ac8d2010-09-16 14:58:22 +02004150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004151 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4152 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004153
Johannes Berg19957bb2009-07-02 17:20:43 +02004154 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004155
Johannes Berg19957bb2009-07-02 17:20:43 +02004156 chan = ieee80211_get_channel(&rdev->wiphy,
4157 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004158 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4159 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004160
Johannes Berg19957bb2009-07-02 17:20:43 +02004161 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4162 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004163
4164 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004165 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4166 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004167 }
4168
Jouni Malinendc6382c2009-05-06 22:09:37 +03004169 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004170 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004171 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004172 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004173 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004174 else if (mfp != NL80211_MFP_NO)
4175 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004176 }
4177
Johannes Berg3e5d7642009-07-07 14:37:26 +02004178 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4179 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4180
Johannes Bergc0692b82010-08-27 14:26:53 +03004181 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004182 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004183 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4184 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02004185 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004186
Jouni Malinen636a5d32009-03-19 13:39:22 +02004187 return err;
4188}
4189
4190static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4191{
Johannes Berg4c476992010-10-04 21:36:35 +02004192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4193 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004194 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004195 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004196 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004197 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004198
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004199 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4200 return -EINVAL;
4201
4202 if (!info->attrs[NL80211_ATTR_MAC])
4203 return -EINVAL;
4204
4205 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4206 return -EINVAL;
4207
Johannes Berg4c476992010-10-04 21:36:35 +02004208 if (!rdev->ops->deauth)
4209 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004210
Johannes Berg074ac8d2010-09-16 14:58:22 +02004211 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004212 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4213 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004214
Johannes Berg19957bb2009-07-02 17:20:43 +02004215 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004216
Johannes Berg19957bb2009-07-02 17:20:43 +02004217 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4218 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004219 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004220 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004221 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004222
4223 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004224 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4225 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004226 }
4227
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004228 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4229
Johannes Berg4c476992010-10-04 21:36:35 +02004230 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4231 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004232}
4233
4234static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4235{
Johannes Berg4c476992010-10-04 21:36:35 +02004236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4237 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004238 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004239 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004240 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004241 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004242
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004243 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4244 return -EINVAL;
4245
4246 if (!info->attrs[NL80211_ATTR_MAC])
4247 return -EINVAL;
4248
4249 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4250 return -EINVAL;
4251
Johannes Berg4c476992010-10-04 21:36:35 +02004252 if (!rdev->ops->disassoc)
4253 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004254
Johannes Berg074ac8d2010-09-16 14:58:22 +02004255 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004256 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4257 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004258
Johannes Berg19957bb2009-07-02 17:20:43 +02004259 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004260
Johannes Berg19957bb2009-07-02 17:20:43 +02004261 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4262 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004263 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004264 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004265 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004266
4267 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004268 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4269 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004270 }
4271
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004272 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4273
Johannes Berg4c476992010-10-04 21:36:35 +02004274 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4275 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004276}
4277
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004278static bool
4279nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4280 int mcast_rate[IEEE80211_NUM_BANDS],
4281 int rateval)
4282{
4283 struct wiphy *wiphy = &rdev->wiphy;
4284 bool found = false;
4285 int band, i;
4286
4287 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4288 struct ieee80211_supported_band *sband;
4289
4290 sband = wiphy->bands[band];
4291 if (!sband)
4292 continue;
4293
4294 for (i = 0; i < sband->n_bitrates; i++) {
4295 if (sband->bitrates[i].bitrate == rateval) {
4296 mcast_rate[band] = i + 1;
4297 found = true;
4298 break;
4299 }
4300 }
4301 }
4302
4303 return found;
4304}
4305
Johannes Berg04a773a2009-04-19 21:24:32 +02004306static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4307{
Johannes Berg4c476992010-10-04 21:36:35 +02004308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4309 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004310 struct cfg80211_ibss_params ibss;
4311 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004312 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004313 int err;
4314
Johannes Berg8e30bc52009-04-22 17:45:38 +02004315 memset(&ibss, 0, sizeof(ibss));
4316
Johannes Berg04a773a2009-04-19 21:24:32 +02004317 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4318 return -EINVAL;
4319
4320 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4321 !info->attrs[NL80211_ATTR_SSID] ||
4322 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4323 return -EINVAL;
4324
Johannes Berg8e30bc52009-04-22 17:45:38 +02004325 ibss.beacon_interval = 100;
4326
4327 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4328 ibss.beacon_interval =
4329 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4330 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4331 return -EINVAL;
4332 }
4333
Johannes Berg4c476992010-10-04 21:36:35 +02004334 if (!rdev->ops->join_ibss)
4335 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004336
Johannes Berg4c476992010-10-04 21:36:35 +02004337 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4338 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004339
Johannes Berg79c97e92009-07-07 03:56:12 +02004340 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004341
4342 if (info->attrs[NL80211_ATTR_MAC])
4343 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4344 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4345 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4346
4347 if (info->attrs[NL80211_ATTR_IE]) {
4348 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4349 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4350 }
4351
4352 ibss.channel = ieee80211_get_channel(wiphy,
4353 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4354 if (!ibss.channel ||
4355 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004356 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4357 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004358
4359 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004360 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004361
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004362 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4363 u8 *rates =
4364 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4365 int n_rates =
4366 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4367 struct ieee80211_supported_band *sband =
4368 wiphy->bands[ibss.channel->band];
Johannes Berg34850ab2011-07-18 18:08:35 +02004369 int err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004370
Johannes Berg34850ab2011-07-18 18:08:35 +02004371 err = ieee80211_get_ratemask(sband, rates, n_rates,
4372 &ibss.basic_rates);
4373 if (err)
4374 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004375 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004376
4377 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4378 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4379 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4380 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004381
Johannes Berg4c476992010-10-04 21:36:35 +02004382 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4383 connkeys = nl80211_parse_connkeys(rdev,
4384 info->attrs[NL80211_ATTR_KEYS]);
4385 if (IS_ERR(connkeys))
4386 return PTR_ERR(connkeys);
4387 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004388
Johannes Berg4c476992010-10-04 21:36:35 +02004389 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004390 if (err)
4391 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004392 return err;
4393}
4394
4395static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4396{
Johannes Berg4c476992010-10-04 21:36:35 +02004397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4398 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004399
Johannes Berg4c476992010-10-04 21:36:35 +02004400 if (!rdev->ops->leave_ibss)
4401 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004402
Johannes Berg4c476992010-10-04 21:36:35 +02004403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4404 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004405
Johannes Berg4c476992010-10-04 21:36:35 +02004406 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004407}
4408
Johannes Bergaff89a92009-07-01 21:26:51 +02004409#ifdef CONFIG_NL80211_TESTMODE
4410static struct genl_multicast_group nl80211_testmode_mcgrp = {
4411 .name = "testmode",
4412};
4413
4414static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4415{
Johannes Berg4c476992010-10-04 21:36:35 +02004416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004417 int err;
4418
4419 if (!info->attrs[NL80211_ATTR_TESTDATA])
4420 return -EINVAL;
4421
Johannes Bergaff89a92009-07-01 21:26:51 +02004422 err = -EOPNOTSUPP;
4423 if (rdev->ops->testmode_cmd) {
4424 rdev->testmode_info = info;
4425 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4426 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4427 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4428 rdev->testmode_info = NULL;
4429 }
4430
Johannes Bergaff89a92009-07-01 21:26:51 +02004431 return err;
4432}
4433
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004434static int nl80211_testmode_dump(struct sk_buff *skb,
4435 struct netlink_callback *cb)
4436{
4437 struct cfg80211_registered_device *dev;
4438 int err;
4439 long phy_idx;
4440 void *data = NULL;
4441 int data_len = 0;
4442
4443 if (cb->args[0]) {
4444 /*
4445 * 0 is a valid index, but not valid for args[0],
4446 * so we need to offset by 1.
4447 */
4448 phy_idx = cb->args[0] - 1;
4449 } else {
4450 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4451 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4452 nl80211_policy);
4453 if (err)
4454 return err;
4455 if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY])
4456 return -EINVAL;
4457 phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4458 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4459 cb->args[1] =
4460 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4461 }
4462
4463 if (cb->args[1]) {
4464 data = nla_data((void *)cb->args[1]);
4465 data_len = nla_len((void *)cb->args[1]);
4466 }
4467
4468 mutex_lock(&cfg80211_mutex);
4469 dev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4470 if (!dev) {
4471 mutex_unlock(&cfg80211_mutex);
4472 return -ENOENT;
4473 }
4474 cfg80211_lock_rdev(dev);
4475 mutex_unlock(&cfg80211_mutex);
4476
4477 if (!dev->ops->testmode_dump) {
4478 err = -EOPNOTSUPP;
4479 goto out_err;
4480 }
4481
4482 while (1) {
4483 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4484 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4485 NL80211_CMD_TESTMODE);
4486 struct nlattr *tmdata;
4487
4488 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) {
4489 genlmsg_cancel(skb, hdr);
4490 break;
4491 }
4492
4493 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4494 if (!tmdata) {
4495 genlmsg_cancel(skb, hdr);
4496 break;
4497 }
4498 err = dev->ops->testmode_dump(&dev->wiphy, skb, cb,
4499 data, data_len);
4500 nla_nest_end(skb, tmdata);
4501
4502 if (err == -ENOBUFS || err == -ENOENT) {
4503 genlmsg_cancel(skb, hdr);
4504 break;
4505 } else if (err) {
4506 genlmsg_cancel(skb, hdr);
4507 goto out_err;
4508 }
4509
4510 genlmsg_end(skb, hdr);
4511 }
4512
4513 err = skb->len;
4514 /* see above */
4515 cb->args[0] = phy_idx + 1;
4516 out_err:
4517 cfg80211_unlock_rdev(dev);
4518 return err;
4519}
4520
Johannes Bergaff89a92009-07-01 21:26:51 +02004521static struct sk_buff *
4522__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4523 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4524{
4525 struct sk_buff *skb;
4526 void *hdr;
4527 struct nlattr *data;
4528
4529 skb = nlmsg_new(approxlen + 100, gfp);
4530 if (!skb)
4531 return NULL;
4532
4533 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4534 if (!hdr) {
4535 kfree_skb(skb);
4536 return NULL;
4537 }
4538
4539 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4540 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4541
4542 ((void **)skb->cb)[0] = rdev;
4543 ((void **)skb->cb)[1] = hdr;
4544 ((void **)skb->cb)[2] = data;
4545
4546 return skb;
4547
4548 nla_put_failure:
4549 kfree_skb(skb);
4550 return NULL;
4551}
4552
4553struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4554 int approxlen)
4555{
4556 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4557
4558 if (WARN_ON(!rdev->testmode_info))
4559 return NULL;
4560
4561 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4562 rdev->testmode_info->snd_pid,
4563 rdev->testmode_info->snd_seq,
4564 GFP_KERNEL);
4565}
4566EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4567
4568int cfg80211_testmode_reply(struct sk_buff *skb)
4569{
4570 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4571 void *hdr = ((void **)skb->cb)[1];
4572 struct nlattr *data = ((void **)skb->cb)[2];
4573
4574 if (WARN_ON(!rdev->testmode_info)) {
4575 kfree_skb(skb);
4576 return -EINVAL;
4577 }
4578
4579 nla_nest_end(skb, data);
4580 genlmsg_end(skb, hdr);
4581 return genlmsg_reply(skb, rdev->testmode_info);
4582}
4583EXPORT_SYMBOL(cfg80211_testmode_reply);
4584
4585struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4586 int approxlen, gfp_t gfp)
4587{
4588 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4589
4590 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4591}
4592EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4593
4594void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4595{
4596 void *hdr = ((void **)skb->cb)[1];
4597 struct nlattr *data = ((void **)skb->cb)[2];
4598
4599 nla_nest_end(skb, data);
4600 genlmsg_end(skb, hdr);
4601 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4602}
4603EXPORT_SYMBOL(cfg80211_testmode_event);
4604#endif
4605
Samuel Ortizb23aa672009-07-01 21:26:54 +02004606static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4607{
Johannes Berg4c476992010-10-04 21:36:35 +02004608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4609 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004610 struct cfg80211_connect_params connect;
4611 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004612 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004613 int err;
4614
4615 memset(&connect, 0, sizeof(connect));
4616
4617 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4618 return -EINVAL;
4619
4620 if (!info->attrs[NL80211_ATTR_SSID] ||
4621 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4622 return -EINVAL;
4623
4624 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4625 connect.auth_type =
4626 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4627 if (!nl80211_valid_auth_type(connect.auth_type))
4628 return -EINVAL;
4629 } else
4630 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4631
4632 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4633
Johannes Bergc0692b82010-08-27 14:26:53 +03004634 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004635 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004636 if (err)
4637 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004638
Johannes Berg074ac8d2010-09-16 14:58:22 +02004639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004640 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4641 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004642
Johannes Berg79c97e92009-07-07 03:56:12 +02004643 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004644
Samuel Ortizb23aa672009-07-01 21:26:54 +02004645 if (info->attrs[NL80211_ATTR_MAC])
4646 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4647 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4648 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4649
4650 if (info->attrs[NL80211_ATTR_IE]) {
4651 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4652 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4653 }
4654
4655 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4656 connect.channel =
4657 ieee80211_get_channel(wiphy,
4658 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4659 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004660 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4661 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004662 }
4663
Johannes Bergfffd0932009-07-08 14:22:54 +02004664 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4665 connkeys = nl80211_parse_connkeys(rdev,
4666 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004667 if (IS_ERR(connkeys))
4668 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004669 }
4670
4671 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004672 if (err)
4673 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004674 return err;
4675}
4676
4677static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4678{
Johannes Berg4c476992010-10-04 21:36:35 +02004679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4680 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004681 u16 reason;
4682
4683 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4684 reason = WLAN_REASON_DEAUTH_LEAVING;
4685 else
4686 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4687
4688 if (reason == 0)
4689 return -EINVAL;
4690
Johannes Berg074ac8d2010-09-16 14:58:22 +02004691 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004692 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4693 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004694
Johannes Berg4c476992010-10-04 21:36:35 +02004695 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004696}
4697
Johannes Berg463d0182009-07-14 00:33:35 +02004698static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4699{
Johannes Berg4c476992010-10-04 21:36:35 +02004700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004701 struct net *net;
4702 int err;
4703 u32 pid;
4704
4705 if (!info->attrs[NL80211_ATTR_PID])
4706 return -EINVAL;
4707
4708 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4709
Johannes Berg463d0182009-07-14 00:33:35 +02004710 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004711 if (IS_ERR(net))
4712 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004713
4714 err = 0;
4715
4716 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004717 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4718 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004719
Johannes Berg463d0182009-07-14 00:33:35 +02004720 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004721 return err;
4722}
4723
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004724static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4725{
Johannes Berg4c476992010-10-04 21:36:35 +02004726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004727 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4728 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004729 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004730 struct cfg80211_pmksa pmksa;
4731
4732 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4733
4734 if (!info->attrs[NL80211_ATTR_MAC])
4735 return -EINVAL;
4736
4737 if (!info->attrs[NL80211_ATTR_PMKID])
4738 return -EINVAL;
4739
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004740 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4741 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4742
Johannes Berg074ac8d2010-09-16 14:58:22 +02004743 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004744 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4745 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004746
4747 switch (info->genlhdr->cmd) {
4748 case NL80211_CMD_SET_PMKSA:
4749 rdev_ops = rdev->ops->set_pmksa;
4750 break;
4751 case NL80211_CMD_DEL_PMKSA:
4752 rdev_ops = rdev->ops->del_pmksa;
4753 break;
4754 default:
4755 WARN_ON(1);
4756 break;
4757 }
4758
Johannes Berg4c476992010-10-04 21:36:35 +02004759 if (!rdev_ops)
4760 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004761
Johannes Berg4c476992010-10-04 21:36:35 +02004762 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004763}
4764
4765static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4766{
Johannes Berg4c476992010-10-04 21:36:35 +02004767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4768 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004769
Johannes Berg074ac8d2010-09-16 14:58:22 +02004770 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004771 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4772 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004773
Johannes Berg4c476992010-10-04 21:36:35 +02004774 if (!rdev->ops->flush_pmksa)
4775 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004776
Johannes Berg4c476992010-10-04 21:36:35 +02004777 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004778}
4779
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004780static int nl80211_remain_on_channel(struct sk_buff *skb,
4781 struct genl_info *info)
4782{
Johannes Berg4c476992010-10-04 21:36:35 +02004783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4784 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004785 struct ieee80211_channel *chan;
4786 struct sk_buff *msg;
4787 void *hdr;
4788 u64 cookie;
4789 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4790 u32 freq, duration;
4791 int err;
4792
4793 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4794 !info->attrs[NL80211_ATTR_DURATION])
4795 return -EINVAL;
4796
4797 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4798
4799 /*
4800 * We should be on that channel for at least one jiffie,
4801 * and more than 5 seconds seems excessive.
4802 */
Johannes Berga2939112010-12-14 17:54:28 +01004803 if (!duration || !msecs_to_jiffies(duration) ||
4804 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004805 return -EINVAL;
4806
Johannes Berg4c476992010-10-04 21:36:35 +02004807 if (!rdev->ops->remain_on_channel)
4808 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004809
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004810 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4811 channel_type = nla_get_u32(
4812 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4813 if (channel_type != NL80211_CHAN_NO_HT &&
4814 channel_type != NL80211_CHAN_HT20 &&
4815 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004816 channel_type != NL80211_CHAN_HT40MINUS)
4817 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004818 }
4819
4820 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4821 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004822 if (chan == NULL)
4823 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004824
4825 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004826 if (!msg)
4827 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004828
4829 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4830 NL80211_CMD_REMAIN_ON_CHANNEL);
4831
4832 if (IS_ERR(hdr)) {
4833 err = PTR_ERR(hdr);
4834 goto free_msg;
4835 }
4836
4837 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
4838 channel_type, duration, &cookie);
4839
4840 if (err)
4841 goto free_msg;
4842
4843 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4844
4845 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004846
4847 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004848
4849 nla_put_failure:
4850 err = -ENOBUFS;
4851 free_msg:
4852 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004853 return err;
4854}
4855
4856static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4857 struct genl_info *info)
4858{
Johannes Berg4c476992010-10-04 21:36:35 +02004859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4860 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004861 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004862
4863 if (!info->attrs[NL80211_ATTR_COOKIE])
4864 return -EINVAL;
4865
Johannes Berg4c476992010-10-04 21:36:35 +02004866 if (!rdev->ops->cancel_remain_on_channel)
4867 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004868
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004869 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4870
Johannes Berg4c476992010-10-04 21:36:35 +02004871 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004872}
4873
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004874static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4875 u8 *rates, u8 rates_len)
4876{
4877 u8 i;
4878 u32 mask = 0;
4879
4880 for (i = 0; i < rates_len; i++) {
4881 int rate = (rates[i] & 0x7f) * 5;
4882 int ridx;
4883 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4884 struct ieee80211_rate *srate =
4885 &sband->bitrates[ridx];
4886 if (rate == srate->bitrate) {
4887 mask |= 1 << ridx;
4888 break;
4889 }
4890 }
4891 if (ridx == sband->n_bitrates)
4892 return 0; /* rate not found */
4893 }
4894
4895 return mask;
4896}
4897
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004898static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004899 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4900 .len = NL80211_MAX_SUPP_RATES },
4901};
4902
4903static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4904 struct genl_info *info)
4905{
4906 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02004907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004908 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02004909 int rem, i;
4910 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004911 struct nlattr *tx_rates;
4912 struct ieee80211_supported_band *sband;
4913
4914 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4915 return -EINVAL;
4916
Johannes Berg4c476992010-10-04 21:36:35 +02004917 if (!rdev->ops->set_bitrate_mask)
4918 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004919
4920 memset(&mask, 0, sizeof(mask));
4921 /* Default to all rates enabled */
4922 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
4923 sband = rdev->wiphy.bands[i];
4924 mask.control[i].legacy =
4925 sband ? (1 << sband->n_bitrates) - 1 : 0;
4926 }
4927
4928 /*
4929 * The nested attribute uses enum nl80211_band as the index. This maps
4930 * directly to the enum ieee80211_band values used in cfg80211.
4931 */
4932 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4933 {
4934 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02004935 if (band < 0 || band >= IEEE80211_NUM_BANDS)
4936 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004937 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02004938 if (sband == NULL)
4939 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004940 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4941 nla_len(tx_rates), nl80211_txattr_policy);
4942 if (tb[NL80211_TXRATE_LEGACY]) {
4943 mask.control[band].legacy = rateset_to_mask(
4944 sband,
4945 nla_data(tb[NL80211_TXRATE_LEGACY]),
4946 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02004947 if (mask.control[band].legacy == 0)
4948 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004949 }
4950 }
4951
Johannes Berg4c476992010-10-04 21:36:35 +02004952 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004953}
4954
Johannes Berg2e161f72010-08-12 15:38:38 +02004955static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004956{
Johannes Berg4c476992010-10-04 21:36:35 +02004957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4958 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02004959 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02004960
4961 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4962 return -EINVAL;
4963
Johannes Berg2e161f72010-08-12 15:38:38 +02004964 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
4965 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02004966
Johannes Berg9d38d852010-06-09 17:20:33 +02004967 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004968 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004969 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4970 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4971 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08004972 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004973 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4974 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004975
4976 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02004977 if (!rdev->ops->mgmt_tx)
4978 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004979
Johannes Berg4c476992010-10-04 21:36:35 +02004980 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02004981 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02004982 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4983 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02004984}
4985
Johannes Berg2e161f72010-08-12 15:38:38 +02004986static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004987{
Johannes Berg4c476992010-10-04 21:36:35 +02004988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4989 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02004990 struct ieee80211_channel *chan;
4991 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02004992 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02004993 u32 freq;
4994 int err;
4995 void *hdr;
4996 u64 cookie;
4997 struct sk_buff *msg;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004998 unsigned int wait = 0;
4999 bool offchan;
Jouni Malinen026331c2010-02-15 12:53:10 +02005000
5001 if (!info->attrs[NL80211_ATTR_FRAME] ||
5002 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5003 return -EINVAL;
5004
Johannes Berg4c476992010-10-04 21:36:35 +02005005 if (!rdev->ops->mgmt_tx)
5006 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005007
Johannes Berg9d38d852010-06-09 17:20:33 +02005008 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005009 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005010 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5011 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5012 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005013 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005014 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5015 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005016
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005017 if (info->attrs[NL80211_ATTR_DURATION]) {
5018 if (!rdev->ops->mgmt_tx_cancel_wait)
5019 return -EINVAL;
5020 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5021 }
5022
Jouni Malinen026331c2010-02-15 12:53:10 +02005023 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5024 channel_type = nla_get_u32(
5025 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5026 if (channel_type != NL80211_CHAN_NO_HT &&
5027 channel_type != NL80211_CHAN_HT20 &&
5028 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005029 channel_type != NL80211_CHAN_HT40MINUS)
5030 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005031 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005032 }
5033
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005034 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5035
Jouni Malinen026331c2010-02-15 12:53:10 +02005036 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5037 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005038 if (chan == NULL)
5039 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005040
5041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005042 if (!msg)
5043 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005044
5045 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02005046 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005047
5048 if (IS_ERR(hdr)) {
5049 err = PTR_ERR(hdr);
5050 goto free_msg;
5051 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005052 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5053 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005054 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5055 nla_len(info->attrs[NL80211_ATTR_FRAME]),
5056 &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005057 if (err)
5058 goto free_msg;
5059
5060 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5061
5062 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005063 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02005064
5065 nla_put_failure:
5066 err = -ENOBUFS;
5067 free_msg:
5068 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005069 return err;
5070}
5071
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005072static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5073{
5074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5075 struct net_device *dev = info->user_ptr[1];
5076 u64 cookie;
5077
5078 if (!info->attrs[NL80211_ATTR_COOKIE])
5079 return -EINVAL;
5080
5081 if (!rdev->ops->mgmt_tx_cancel_wait)
5082 return -EOPNOTSUPP;
5083
5084 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5085 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5086 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5087 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5088 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5089 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5090 return -EOPNOTSUPP;
5091
5092 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5093
5094 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5095}
5096
Kalle Valoffb9eb32010-02-17 17:58:10 +02005097static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5098{
Johannes Berg4c476992010-10-04 21:36:35 +02005099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005100 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005101 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005102 u8 ps_state;
5103 bool state;
5104 int err;
5105
Johannes Berg4c476992010-10-04 21:36:35 +02005106 if (!info->attrs[NL80211_ATTR_PS_STATE])
5107 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005108
5109 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5110
Johannes Berg4c476992010-10-04 21:36:35 +02005111 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5112 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005113
5114 wdev = dev->ieee80211_ptr;
5115
Johannes Berg4c476992010-10-04 21:36:35 +02005116 if (!rdev->ops->set_power_mgmt)
5117 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005118
5119 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5120
5121 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005122 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005123
Johannes Berg4c476992010-10-04 21:36:35 +02005124 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5125 wdev->ps_timeout);
5126 if (!err)
5127 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005128 return err;
5129}
5130
5131static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5132{
Johannes Berg4c476992010-10-04 21:36:35 +02005133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005134 enum nl80211_ps_state ps_state;
5135 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005136 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005137 struct sk_buff *msg;
5138 void *hdr;
5139 int err;
5140
Kalle Valoffb9eb32010-02-17 17:58:10 +02005141 wdev = dev->ieee80211_ptr;
5142
Johannes Berg4c476992010-10-04 21:36:35 +02005143 if (!rdev->ops->set_power_mgmt)
5144 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005145
5146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005147 if (!msg)
5148 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005149
5150 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5151 NL80211_CMD_GET_POWER_SAVE);
5152 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005153 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005154 goto free_msg;
5155 }
5156
5157 if (wdev->ps)
5158 ps_state = NL80211_PS_ENABLED;
5159 else
5160 ps_state = NL80211_PS_DISABLED;
5161
5162 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5163
5164 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005165 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005166
Johannes Berg4c476992010-10-04 21:36:35 +02005167 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005168 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005169 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005170 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005171 return err;
5172}
5173
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005174static struct nla_policy
5175nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5176 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5177 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5178 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5179};
5180
5181static int nl80211_set_cqm_rssi(struct genl_info *info,
5182 s32 threshold, u32 hysteresis)
5183{
Johannes Berg4c476992010-10-04 21:36:35 +02005184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005185 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005186 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005187
5188 if (threshold > 0)
5189 return -EINVAL;
5190
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005191 wdev = dev->ieee80211_ptr;
5192
Johannes Berg4c476992010-10-04 21:36:35 +02005193 if (!rdev->ops->set_cqm_rssi_config)
5194 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005195
Johannes Berg074ac8d2010-09-16 14:58:22 +02005196 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005197 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5198 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005199
Johannes Berg4c476992010-10-04 21:36:35 +02005200 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5201 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005202}
5203
5204static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5205{
5206 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5207 struct nlattr *cqm;
5208 int err;
5209
5210 cqm = info->attrs[NL80211_ATTR_CQM];
5211 if (!cqm) {
5212 err = -EINVAL;
5213 goto out;
5214 }
5215
5216 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5217 nl80211_attr_cqm_policy);
5218 if (err)
5219 goto out;
5220
5221 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5222 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5223 s32 threshold;
5224 u32 hysteresis;
5225 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5226 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5227 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5228 } else
5229 err = -EINVAL;
5230
5231out:
5232 return err;
5233}
5234
Johannes Berg29cbe682010-12-03 09:20:44 +01005235static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5236{
5237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5238 struct net_device *dev = info->user_ptr[1];
5239 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005240 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005241 int err;
5242
5243 /* start with default */
5244 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005245 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005246
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005247 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005248 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005249 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005250 if (err)
5251 return err;
5252 }
5253
5254 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5255 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5256 return -EINVAL;
5257
Javier Cardonac80d5452010-12-16 17:37:49 -08005258 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5259 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5260
5261 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5262 /* parse additional setup parameters if given */
5263 err = nl80211_parse_mesh_setup(info, &setup);
5264 if (err)
5265 return err;
5266 }
5267
5268 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005269}
5270
5271static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5272{
5273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5274 struct net_device *dev = info->user_ptr[1];
5275
5276 return cfg80211_leave_mesh(rdev, dev);
5277}
5278
Johannes Bergff1b6e62011-05-04 15:37:28 +02005279static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5280{
5281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5282 struct sk_buff *msg;
5283 void *hdr;
5284
5285 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5286 return -EOPNOTSUPP;
5287
5288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5289 if (!msg)
5290 return -ENOMEM;
5291
5292 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5293 NL80211_CMD_GET_WOWLAN);
5294 if (!hdr)
5295 goto nla_put_failure;
5296
5297 if (rdev->wowlan) {
5298 struct nlattr *nl_wowlan;
5299
5300 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5301 if (!nl_wowlan)
5302 goto nla_put_failure;
5303
5304 if (rdev->wowlan->any)
5305 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5306 if (rdev->wowlan->disconnect)
5307 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5308 if (rdev->wowlan->magic_pkt)
5309 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005310 if (rdev->wowlan->gtk_rekey_failure)
5311 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5312 if (rdev->wowlan->eap_identity_req)
5313 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5314 if (rdev->wowlan->four_way_handshake)
5315 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5316 if (rdev->wowlan->rfkill_release)
5317 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005318 if (rdev->wowlan->n_patterns) {
5319 struct nlattr *nl_pats, *nl_pat;
5320 int i, pat_len;
5321
5322 nl_pats = nla_nest_start(msg,
5323 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5324 if (!nl_pats)
5325 goto nla_put_failure;
5326
5327 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5328 nl_pat = nla_nest_start(msg, i + 1);
5329 if (!nl_pat)
5330 goto nla_put_failure;
5331 pat_len = rdev->wowlan->patterns[i].pattern_len;
5332 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5333 DIV_ROUND_UP(pat_len, 8),
5334 rdev->wowlan->patterns[i].mask);
5335 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5336 pat_len,
5337 rdev->wowlan->patterns[i].pattern);
5338 nla_nest_end(msg, nl_pat);
5339 }
5340 nla_nest_end(msg, nl_pats);
5341 }
5342
5343 nla_nest_end(msg, nl_wowlan);
5344 }
5345
5346 genlmsg_end(msg, hdr);
5347 return genlmsg_reply(msg, info);
5348
5349nla_put_failure:
5350 nlmsg_free(msg);
5351 return -ENOBUFS;
5352}
5353
5354static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5355{
5356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5357 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5358 struct cfg80211_wowlan no_triggers = {};
5359 struct cfg80211_wowlan new_triggers = {};
5360 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5361 int err, i;
5362
5363 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5364 return -EOPNOTSUPP;
5365
5366 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5367 goto no_triggers;
5368
5369 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5370 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5371 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5372 nl80211_wowlan_policy);
5373 if (err)
5374 return err;
5375
5376 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5377 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5378 return -EINVAL;
5379 new_triggers.any = true;
5380 }
5381
5382 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5383 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5384 return -EINVAL;
5385 new_triggers.disconnect = true;
5386 }
5387
5388 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5389 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5390 return -EINVAL;
5391 new_triggers.magic_pkt = true;
5392 }
5393
Johannes Berg77dbbb12011-07-13 10:48:55 +02005394 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5395 return -EINVAL;
5396
5397 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5398 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5399 return -EINVAL;
5400 new_triggers.gtk_rekey_failure = true;
5401 }
5402
5403 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5404 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5405 return -EINVAL;
5406 new_triggers.eap_identity_req = true;
5407 }
5408
5409 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5410 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5411 return -EINVAL;
5412 new_triggers.four_way_handshake = true;
5413 }
5414
5415 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5416 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5417 return -EINVAL;
5418 new_triggers.rfkill_release = true;
5419 }
5420
Johannes Bergff1b6e62011-05-04 15:37:28 +02005421 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5422 struct nlattr *pat;
5423 int n_patterns = 0;
5424 int rem, pat_len, mask_len;
5425 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5426
5427 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5428 rem)
5429 n_patterns++;
5430 if (n_patterns > wowlan->n_patterns)
5431 return -EINVAL;
5432
5433 new_triggers.patterns = kcalloc(n_patterns,
5434 sizeof(new_triggers.patterns[0]),
5435 GFP_KERNEL);
5436 if (!new_triggers.patterns)
5437 return -ENOMEM;
5438
5439 new_triggers.n_patterns = n_patterns;
5440 i = 0;
5441
5442 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5443 rem) {
5444 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5445 nla_data(pat), nla_len(pat), NULL);
5446 err = -EINVAL;
5447 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5448 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5449 goto error;
5450 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5451 mask_len = DIV_ROUND_UP(pat_len, 8);
5452 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5453 mask_len)
5454 goto error;
5455 if (pat_len > wowlan->pattern_max_len ||
5456 pat_len < wowlan->pattern_min_len)
5457 goto error;
5458
5459 new_triggers.patterns[i].mask =
5460 kmalloc(mask_len + pat_len, GFP_KERNEL);
5461 if (!new_triggers.patterns[i].mask) {
5462 err = -ENOMEM;
5463 goto error;
5464 }
5465 new_triggers.patterns[i].pattern =
5466 new_triggers.patterns[i].mask + mask_len;
5467 memcpy(new_triggers.patterns[i].mask,
5468 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5469 mask_len);
5470 new_triggers.patterns[i].pattern_len = pat_len;
5471 memcpy(new_triggers.patterns[i].pattern,
5472 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5473 pat_len);
5474 i++;
5475 }
5476 }
5477
5478 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5479 struct cfg80211_wowlan *ntrig;
5480 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5481 GFP_KERNEL);
5482 if (!ntrig) {
5483 err = -ENOMEM;
5484 goto error;
5485 }
5486 cfg80211_rdev_free_wowlan(rdev);
5487 rdev->wowlan = ntrig;
5488 } else {
5489 no_triggers:
5490 cfg80211_rdev_free_wowlan(rdev);
5491 rdev->wowlan = NULL;
5492 }
5493
5494 return 0;
5495 error:
5496 for (i = 0; i < new_triggers.n_patterns; i++)
5497 kfree(new_triggers.patterns[i].mask);
5498 kfree(new_triggers.patterns);
5499 return err;
5500}
5501
Johannes Berge5497d72011-07-05 16:35:40 +02005502static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
5503{
5504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5505 struct net_device *dev = info->user_ptr[1];
5506 struct wireless_dev *wdev = dev->ieee80211_ptr;
5507 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
5508 struct cfg80211_gtk_rekey_data rekey_data;
5509 int err;
5510
5511 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
5512 return -EINVAL;
5513
5514 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
5515 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
5516 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
5517 nl80211_rekey_policy);
5518 if (err)
5519 return err;
5520
5521 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
5522 return -ERANGE;
5523 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
5524 return -ERANGE;
5525 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
5526 return -ERANGE;
5527
5528 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
5529 NL80211_KEK_LEN);
5530 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
5531 NL80211_KCK_LEN);
5532 memcpy(rekey_data.replay_ctr,
5533 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
5534 NL80211_REPLAY_CTR_LEN);
5535
5536 wdev_lock(wdev);
5537 if (!wdev->current_bss) {
5538 err = -ENOTCONN;
5539 goto out;
5540 }
5541
5542 if (!rdev->ops->set_rekey_data) {
5543 err = -EOPNOTSUPP;
5544 goto out;
5545 }
5546
5547 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
5548 out:
5549 wdev_unlock(wdev);
5550 return err;
5551}
5552
Johannes Berg4c476992010-10-04 21:36:35 +02005553#define NL80211_FLAG_NEED_WIPHY 0x01
5554#define NL80211_FLAG_NEED_NETDEV 0x02
5555#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02005556#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5557#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5558 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02005559
5560static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5561 struct genl_info *info)
5562{
5563 struct cfg80211_registered_device *rdev;
5564 struct net_device *dev;
5565 int err;
5566 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5567
5568 if (rtnl)
5569 rtnl_lock();
5570
5571 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5572 rdev = cfg80211_get_dev_from_info(info);
5573 if (IS_ERR(rdev)) {
5574 if (rtnl)
5575 rtnl_unlock();
5576 return PTR_ERR(rdev);
5577 }
5578 info->user_ptr[0] = rdev;
5579 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5580 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5581 if (err) {
5582 if (rtnl)
5583 rtnl_unlock();
5584 return err;
5585 }
Johannes Berg41265712010-10-04 21:14:05 +02005586 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
5587 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02005588 cfg80211_unlock_rdev(rdev);
5589 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02005590 if (rtnl)
5591 rtnl_unlock();
5592 return -ENETDOWN;
5593 }
Johannes Berg4c476992010-10-04 21:36:35 +02005594 info->user_ptr[0] = rdev;
5595 info->user_ptr[1] = dev;
5596 }
5597
5598 return 0;
5599}
5600
5601static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
5602 struct genl_info *info)
5603{
5604 if (info->user_ptr[0])
5605 cfg80211_unlock_rdev(info->user_ptr[0]);
5606 if (info->user_ptr[1])
5607 dev_put(info->user_ptr[1]);
5608 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
5609 rtnl_unlock();
5610}
5611
Johannes Berg55682962007-09-20 13:09:35 -04005612static struct genl_ops nl80211_ops[] = {
5613 {
5614 .cmd = NL80211_CMD_GET_WIPHY,
5615 .doit = nl80211_get_wiphy,
5616 .dumpit = nl80211_dump_wiphy,
5617 .policy = nl80211_policy,
5618 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005619 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04005620 },
5621 {
5622 .cmd = NL80211_CMD_SET_WIPHY,
5623 .doit = nl80211_set_wiphy,
5624 .policy = nl80211_policy,
5625 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005626 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005627 },
5628 {
5629 .cmd = NL80211_CMD_GET_INTERFACE,
5630 .doit = nl80211_get_interface,
5631 .dumpit = nl80211_dump_interface,
5632 .policy = nl80211_policy,
5633 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005634 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04005635 },
5636 {
5637 .cmd = NL80211_CMD_SET_INTERFACE,
5638 .doit = nl80211_set_interface,
5639 .policy = nl80211_policy,
5640 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005641 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5642 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005643 },
5644 {
5645 .cmd = NL80211_CMD_NEW_INTERFACE,
5646 .doit = nl80211_new_interface,
5647 .policy = nl80211_policy,
5648 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005649 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5650 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005651 },
5652 {
5653 .cmd = NL80211_CMD_DEL_INTERFACE,
5654 .doit = nl80211_del_interface,
5655 .policy = nl80211_policy,
5656 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005657 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5658 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005659 },
Johannes Berg41ade002007-12-19 02:03:29 +01005660 {
5661 .cmd = NL80211_CMD_GET_KEY,
5662 .doit = nl80211_get_key,
5663 .policy = nl80211_policy,
5664 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005665 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5666 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005667 },
5668 {
5669 .cmd = NL80211_CMD_SET_KEY,
5670 .doit = nl80211_set_key,
5671 .policy = nl80211_policy,
5672 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005673 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005674 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005675 },
5676 {
5677 .cmd = NL80211_CMD_NEW_KEY,
5678 .doit = nl80211_new_key,
5679 .policy = nl80211_policy,
5680 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005681 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005682 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005683 },
5684 {
5685 .cmd = NL80211_CMD_DEL_KEY,
5686 .doit = nl80211_del_key,
5687 .policy = nl80211_policy,
5688 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005689 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005690 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005691 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01005692 {
5693 .cmd = NL80211_CMD_SET_BEACON,
5694 .policy = nl80211_policy,
5695 .flags = GENL_ADMIN_PERM,
5696 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005697 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5698 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005699 },
5700 {
5701 .cmd = NL80211_CMD_NEW_BEACON,
5702 .policy = nl80211_policy,
5703 .flags = GENL_ADMIN_PERM,
5704 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005705 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5706 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005707 },
5708 {
5709 .cmd = NL80211_CMD_DEL_BEACON,
5710 .policy = nl80211_policy,
5711 .flags = GENL_ADMIN_PERM,
5712 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005713 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5714 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005715 },
Johannes Berg5727ef12007-12-19 02:03:34 +01005716 {
5717 .cmd = NL80211_CMD_GET_STATION,
5718 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005719 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01005720 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02005721 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5722 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005723 },
5724 {
5725 .cmd = NL80211_CMD_SET_STATION,
5726 .doit = nl80211_set_station,
5727 .policy = nl80211_policy,
5728 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005729 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5730 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005731 },
5732 {
5733 .cmd = NL80211_CMD_NEW_STATION,
5734 .doit = nl80211_new_station,
5735 .policy = nl80211_policy,
5736 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005738 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005739 },
5740 {
5741 .cmd = NL80211_CMD_DEL_STATION,
5742 .doit = nl80211_del_station,
5743 .policy = nl80211_policy,
5744 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005745 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5746 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005747 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005748 {
5749 .cmd = NL80211_CMD_GET_MPATH,
5750 .doit = nl80211_get_mpath,
5751 .dumpit = nl80211_dump_mpath,
5752 .policy = nl80211_policy,
5753 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005755 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005756 },
5757 {
5758 .cmd = NL80211_CMD_SET_MPATH,
5759 .doit = nl80211_set_mpath,
5760 .policy = nl80211_policy,
5761 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005762 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005763 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005764 },
5765 {
5766 .cmd = NL80211_CMD_NEW_MPATH,
5767 .doit = nl80211_new_mpath,
5768 .policy = nl80211_policy,
5769 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005770 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005771 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005772 },
5773 {
5774 .cmd = NL80211_CMD_DEL_MPATH,
5775 .doit = nl80211_del_mpath,
5776 .policy = nl80211_policy,
5777 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005778 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5779 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005780 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005781 {
5782 .cmd = NL80211_CMD_SET_BSS,
5783 .doit = nl80211_set_bss,
5784 .policy = nl80211_policy,
5785 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005786 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5787 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005788 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005789 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005790 .cmd = NL80211_CMD_GET_REG,
5791 .doit = nl80211_get_reg,
5792 .policy = nl80211_policy,
5793 /* can be retrieved by unprivileged users */
5794 },
5795 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005796 .cmd = NL80211_CMD_SET_REG,
5797 .doit = nl80211_set_reg,
5798 .policy = nl80211_policy,
5799 .flags = GENL_ADMIN_PERM,
5800 },
5801 {
5802 .cmd = NL80211_CMD_REQ_SET_REG,
5803 .doit = nl80211_req_set_reg,
5804 .policy = nl80211_policy,
5805 .flags = GENL_ADMIN_PERM,
5806 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005807 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005808 .cmd = NL80211_CMD_GET_MESH_CONFIG,
5809 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005810 .policy = nl80211_policy,
5811 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005812 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5813 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005814 },
5815 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005816 .cmd = NL80211_CMD_SET_MESH_CONFIG,
5817 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005818 .policy = nl80211_policy,
5819 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01005820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005821 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005822 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02005823 {
Johannes Berg2a519312009-02-10 21:25:55 +01005824 .cmd = NL80211_CMD_TRIGGER_SCAN,
5825 .doit = nl80211_trigger_scan,
5826 .policy = nl80211_policy,
5827 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005828 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005829 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01005830 },
5831 {
5832 .cmd = NL80211_CMD_GET_SCAN,
5833 .policy = nl80211_policy,
5834 .dumpit = nl80211_dump_scan,
5835 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02005836 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005837 .cmd = NL80211_CMD_START_SCHED_SCAN,
5838 .doit = nl80211_start_sched_scan,
5839 .policy = nl80211_policy,
5840 .flags = GENL_ADMIN_PERM,
5841 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5842 NL80211_FLAG_NEED_RTNL,
5843 },
5844 {
5845 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
5846 .doit = nl80211_stop_sched_scan,
5847 .policy = nl80211_policy,
5848 .flags = GENL_ADMIN_PERM,
5849 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5850 NL80211_FLAG_NEED_RTNL,
5851 },
5852 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02005853 .cmd = NL80211_CMD_AUTHENTICATE,
5854 .doit = nl80211_authenticate,
5855 .policy = nl80211_policy,
5856 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005857 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005858 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005859 },
5860 {
5861 .cmd = NL80211_CMD_ASSOCIATE,
5862 .doit = nl80211_associate,
5863 .policy = nl80211_policy,
5864 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005865 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005866 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005867 },
5868 {
5869 .cmd = NL80211_CMD_DEAUTHENTICATE,
5870 .doit = nl80211_deauthenticate,
5871 .policy = nl80211_policy,
5872 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005873 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005874 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005875 },
5876 {
5877 .cmd = NL80211_CMD_DISASSOCIATE,
5878 .doit = nl80211_disassociate,
5879 .policy = nl80211_policy,
5880 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005881 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005882 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005883 },
Johannes Berg04a773a2009-04-19 21:24:32 +02005884 {
5885 .cmd = NL80211_CMD_JOIN_IBSS,
5886 .doit = nl80211_join_ibss,
5887 .policy = nl80211_policy,
5888 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005889 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005890 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005891 },
5892 {
5893 .cmd = NL80211_CMD_LEAVE_IBSS,
5894 .doit = nl80211_leave_ibss,
5895 .policy = nl80211_policy,
5896 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005897 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005898 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005899 },
Johannes Bergaff89a92009-07-01 21:26:51 +02005900#ifdef CONFIG_NL80211_TESTMODE
5901 {
5902 .cmd = NL80211_CMD_TESTMODE,
5903 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005904 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02005905 .policy = nl80211_policy,
5906 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005907 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5908 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02005909 },
5910#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02005911 {
5912 .cmd = NL80211_CMD_CONNECT,
5913 .doit = nl80211_connect,
5914 .policy = nl80211_policy,
5915 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005917 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005918 },
5919 {
5920 .cmd = NL80211_CMD_DISCONNECT,
5921 .doit = nl80211_disconnect,
5922 .policy = nl80211_policy,
5923 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005925 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005926 },
Johannes Berg463d0182009-07-14 00:33:35 +02005927 {
5928 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
5929 .doit = nl80211_wiphy_netns,
5930 .policy = nl80211_policy,
5931 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005932 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5933 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02005934 },
Holger Schurig61fa7132009-11-11 12:25:40 +01005935 {
5936 .cmd = NL80211_CMD_GET_SURVEY,
5937 .policy = nl80211_policy,
5938 .dumpit = nl80211_dump_survey,
5939 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005940 {
5941 .cmd = NL80211_CMD_SET_PMKSA,
5942 .doit = nl80211_setdel_pmksa,
5943 .policy = nl80211_policy,
5944 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005945 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5946 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005947 },
5948 {
5949 .cmd = NL80211_CMD_DEL_PMKSA,
5950 .doit = nl80211_setdel_pmksa,
5951 .policy = nl80211_policy,
5952 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005953 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5954 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005955 },
5956 {
5957 .cmd = NL80211_CMD_FLUSH_PMKSA,
5958 .doit = nl80211_flush_pmksa,
5959 .policy = nl80211_policy,
5960 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005961 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5962 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005963 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005964 {
5965 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
5966 .doit = nl80211_remain_on_channel,
5967 .policy = nl80211_policy,
5968 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005969 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005970 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005971 },
5972 {
5973 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5974 .doit = nl80211_cancel_remain_on_channel,
5975 .policy = nl80211_policy,
5976 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005977 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005978 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005979 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005980 {
5981 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
5982 .doit = nl80211_set_tx_bitrate_mask,
5983 .policy = nl80211_policy,
5984 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005985 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5986 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005987 },
Jouni Malinen026331c2010-02-15 12:53:10 +02005988 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005989 .cmd = NL80211_CMD_REGISTER_FRAME,
5990 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005991 .policy = nl80211_policy,
5992 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005993 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5994 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005995 },
5996 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005997 .cmd = NL80211_CMD_FRAME,
5998 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005999 .policy = nl80211_policy,
6000 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006001 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006002 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006003 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006004 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006005 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6006 .doit = nl80211_tx_mgmt_cancel_wait,
6007 .policy = nl80211_policy,
6008 .flags = GENL_ADMIN_PERM,
6009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6010 NL80211_FLAG_NEED_RTNL,
6011 },
6012 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006013 .cmd = NL80211_CMD_SET_POWER_SAVE,
6014 .doit = nl80211_set_power_save,
6015 .policy = nl80211_policy,
6016 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006017 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6018 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006019 },
6020 {
6021 .cmd = NL80211_CMD_GET_POWER_SAVE,
6022 .doit = nl80211_get_power_save,
6023 .policy = nl80211_policy,
6024 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006025 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6026 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006027 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006028 {
6029 .cmd = NL80211_CMD_SET_CQM,
6030 .doit = nl80211_set_cqm,
6031 .policy = nl80211_policy,
6032 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006033 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6034 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006035 },
Johannes Bergf444de02010-05-05 15:25:02 +02006036 {
6037 .cmd = NL80211_CMD_SET_CHANNEL,
6038 .doit = nl80211_set_channel,
6039 .policy = nl80211_policy,
6040 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006041 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6042 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006043 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006044 {
6045 .cmd = NL80211_CMD_SET_WDS_PEER,
6046 .doit = nl80211_set_wds_peer,
6047 .policy = nl80211_policy,
6048 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006049 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6050 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006051 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006052 {
6053 .cmd = NL80211_CMD_JOIN_MESH,
6054 .doit = nl80211_join_mesh,
6055 .policy = nl80211_policy,
6056 .flags = GENL_ADMIN_PERM,
6057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6058 NL80211_FLAG_NEED_RTNL,
6059 },
6060 {
6061 .cmd = NL80211_CMD_LEAVE_MESH,
6062 .doit = nl80211_leave_mesh,
6063 .policy = nl80211_policy,
6064 .flags = GENL_ADMIN_PERM,
6065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6066 NL80211_FLAG_NEED_RTNL,
6067 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006068 {
6069 .cmd = NL80211_CMD_GET_WOWLAN,
6070 .doit = nl80211_get_wowlan,
6071 .policy = nl80211_policy,
6072 /* can be retrieved by unprivileged users */
6073 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6074 NL80211_FLAG_NEED_RTNL,
6075 },
6076 {
6077 .cmd = NL80211_CMD_SET_WOWLAN,
6078 .doit = nl80211_set_wowlan,
6079 .policy = nl80211_policy,
6080 .flags = GENL_ADMIN_PERM,
6081 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6082 NL80211_FLAG_NEED_RTNL,
6083 },
Johannes Berge5497d72011-07-05 16:35:40 +02006084 {
6085 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6086 .doit = nl80211_set_rekey_data,
6087 .policy = nl80211_policy,
6088 .flags = GENL_ADMIN_PERM,
6089 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6090 NL80211_FLAG_NEED_RTNL,
6091 },
Johannes Berg55682962007-09-20 13:09:35 -04006092};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006093
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006094static struct genl_multicast_group nl80211_mlme_mcgrp = {
6095 .name = "mlme",
6096};
Johannes Berg55682962007-09-20 13:09:35 -04006097
6098/* multicast groups */
6099static struct genl_multicast_group nl80211_config_mcgrp = {
6100 .name = "config",
6101};
Johannes Berg2a519312009-02-10 21:25:55 +01006102static struct genl_multicast_group nl80211_scan_mcgrp = {
6103 .name = "scan",
6104};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006105static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6106 .name = "regulatory",
6107};
Johannes Berg55682962007-09-20 13:09:35 -04006108
6109/* notification functions */
6110
6111void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6112{
6113 struct sk_buff *msg;
6114
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006116 if (!msg)
6117 return;
6118
6119 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6120 nlmsg_free(msg);
6121 return;
6122 }
6123
Johannes Berg463d0182009-07-14 00:33:35 +02006124 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6125 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006126}
6127
Johannes Berg362a4152009-05-24 16:43:15 +02006128static int nl80211_add_scan_req(struct sk_buff *msg,
6129 struct cfg80211_registered_device *rdev)
6130{
6131 struct cfg80211_scan_request *req = rdev->scan_req;
6132 struct nlattr *nest;
6133 int i;
6134
Johannes Berg667503dd2009-07-07 03:56:11 +02006135 ASSERT_RDEV_LOCK(rdev);
6136
Johannes Berg362a4152009-05-24 16:43:15 +02006137 if (WARN_ON(!req))
6138 return 0;
6139
6140 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6141 if (!nest)
6142 goto nla_put_failure;
6143 for (i = 0; i < req->n_ssids; i++)
6144 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6145 nla_nest_end(msg, nest);
6146
6147 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6148 if (!nest)
6149 goto nla_put_failure;
6150 for (i = 0; i < req->n_channels; i++)
6151 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6152 nla_nest_end(msg, nest);
6153
6154 if (req->ie)
6155 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6156
6157 return 0;
6158 nla_put_failure:
6159 return -ENOBUFS;
6160}
6161
Johannes Berga538e2d2009-06-16 19:56:42 +02006162static int nl80211_send_scan_msg(struct sk_buff *msg,
6163 struct cfg80211_registered_device *rdev,
6164 struct net_device *netdev,
6165 u32 pid, u32 seq, int flags,
6166 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006167{
6168 void *hdr;
6169
6170 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6171 if (!hdr)
6172 return -1;
6173
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006174 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006175 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6176
Johannes Berg362a4152009-05-24 16:43:15 +02006177 /* ignore errors and send incomplete event anyway */
6178 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006179
6180 return genlmsg_end(msg, hdr);
6181
6182 nla_put_failure:
6183 genlmsg_cancel(msg, hdr);
6184 return -EMSGSIZE;
6185}
6186
Luciano Coelho807f8a82011-05-11 17:09:35 +03006187static int
6188nl80211_send_sched_scan_msg(struct sk_buff *msg,
6189 struct cfg80211_registered_device *rdev,
6190 struct net_device *netdev,
6191 u32 pid, u32 seq, int flags, u32 cmd)
6192{
6193 void *hdr;
6194
6195 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6196 if (!hdr)
6197 return -1;
6198
6199 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6200 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6201
6202 return genlmsg_end(msg, hdr);
6203
6204 nla_put_failure:
6205 genlmsg_cancel(msg, hdr);
6206 return -EMSGSIZE;
6207}
6208
Johannes Berga538e2d2009-06-16 19:56:42 +02006209void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6210 struct net_device *netdev)
6211{
6212 struct sk_buff *msg;
6213
6214 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6215 if (!msg)
6216 return;
6217
6218 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6219 NL80211_CMD_TRIGGER_SCAN) < 0) {
6220 nlmsg_free(msg);
6221 return;
6222 }
6223
Johannes Berg463d0182009-07-14 00:33:35 +02006224 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6225 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006226}
6227
Johannes Berg2a519312009-02-10 21:25:55 +01006228void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6229 struct net_device *netdev)
6230{
6231 struct sk_buff *msg;
6232
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006234 if (!msg)
6235 return;
6236
Johannes Berga538e2d2009-06-16 19:56:42 +02006237 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6238 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006239 nlmsg_free(msg);
6240 return;
6241 }
6242
Johannes Berg463d0182009-07-14 00:33:35 +02006243 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6244 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006245}
6246
6247void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6248 struct net_device *netdev)
6249{
6250 struct sk_buff *msg;
6251
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006253 if (!msg)
6254 return;
6255
Johannes Berga538e2d2009-06-16 19:56:42 +02006256 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6257 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006258 nlmsg_free(msg);
6259 return;
6260 }
6261
Johannes Berg463d0182009-07-14 00:33:35 +02006262 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6263 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006264}
6265
Luciano Coelho807f8a82011-05-11 17:09:35 +03006266void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6267 struct net_device *netdev)
6268{
6269 struct sk_buff *msg;
6270
6271 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6272 if (!msg)
6273 return;
6274
6275 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6276 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6277 nlmsg_free(msg);
6278 return;
6279 }
6280
6281 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6282 nl80211_scan_mcgrp.id, GFP_KERNEL);
6283}
6284
6285void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6286 struct net_device *netdev, u32 cmd)
6287{
6288 struct sk_buff *msg;
6289
6290 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6291 if (!msg)
6292 return;
6293
6294 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6295 nlmsg_free(msg);
6296 return;
6297 }
6298
6299 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6300 nl80211_scan_mcgrp.id, GFP_KERNEL);
6301}
6302
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006303/*
6304 * This can happen on global regulatory changes or device specific settings
6305 * based on custom world regulatory domains.
6306 */
6307void nl80211_send_reg_change_event(struct regulatory_request *request)
6308{
6309 struct sk_buff *msg;
6310 void *hdr;
6311
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006312 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006313 if (!msg)
6314 return;
6315
6316 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6317 if (!hdr) {
6318 nlmsg_free(msg);
6319 return;
6320 }
6321
6322 /* Userspace can always count this one always being set */
6323 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6324
6325 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6326 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6327 NL80211_REGDOM_TYPE_WORLD);
6328 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6329 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6330 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6331 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6332 request->intersect)
6333 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6334 NL80211_REGDOM_TYPE_INTERSECTION);
6335 else {
6336 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6337 NL80211_REGDOM_TYPE_COUNTRY);
6338 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6339 }
6340
6341 if (wiphy_idx_valid(request->wiphy_idx))
6342 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6343
6344 if (genlmsg_end(msg, hdr) < 0) {
6345 nlmsg_free(msg);
6346 return;
6347 }
6348
Johannes Bergbc43b282009-07-25 10:54:13 +02006349 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02006350 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02006351 GFP_ATOMIC);
6352 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006353
6354 return;
6355
6356nla_put_failure:
6357 genlmsg_cancel(msg, hdr);
6358 nlmsg_free(msg);
6359}
6360
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006361static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
6362 struct net_device *netdev,
6363 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006364 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006365{
6366 struct sk_buff *msg;
6367 void *hdr;
6368
Johannes Berge6d6e342009-07-01 21:26:47 +02006369 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006370 if (!msg)
6371 return;
6372
6373 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6374 if (!hdr) {
6375 nlmsg_free(msg);
6376 return;
6377 }
6378
6379 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6380 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6381 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6382
6383 if (genlmsg_end(msg, hdr) < 0) {
6384 nlmsg_free(msg);
6385 return;
6386 }
6387
Johannes Berg463d0182009-07-14 00:33:35 +02006388 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6389 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006390 return;
6391
6392 nla_put_failure:
6393 genlmsg_cancel(msg, hdr);
6394 nlmsg_free(msg);
6395}
6396
6397void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006398 struct net_device *netdev, const u8 *buf,
6399 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006400{
6401 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006402 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006403}
6404
6405void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
6406 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006407 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006408{
Johannes Berge6d6e342009-07-01 21:26:47 +02006409 nl80211_send_mlme_event(rdev, netdev, buf, len,
6410 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006411}
6412
Jouni Malinen53b46b82009-03-27 20:53:56 +02006413void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006414 struct net_device *netdev, const u8 *buf,
6415 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006416{
6417 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006418 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006419}
6420
Jouni Malinen53b46b82009-03-27 20:53:56 +02006421void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
6422 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006423 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006424{
6425 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006426 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006427}
6428
Jouni Malinencf4e5942010-12-16 00:52:40 +02006429void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6430 struct net_device *netdev, const u8 *buf,
6431 size_t len, gfp_t gfp)
6432{
6433 nl80211_send_mlme_event(rdev, netdev, buf, len,
6434 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6435}
6436
6437void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6438 struct net_device *netdev, const u8 *buf,
6439 size_t len, gfp_t gfp)
6440{
6441 nl80211_send_mlme_event(rdev, netdev, buf, len,
6442 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6443}
6444
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04006445static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
6446 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02006447 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006448{
6449 struct sk_buff *msg;
6450 void *hdr;
6451
Johannes Berge6d6e342009-07-01 21:26:47 +02006452 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006453 if (!msg)
6454 return;
6455
6456 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6457 if (!hdr) {
6458 nlmsg_free(msg);
6459 return;
6460 }
6461
6462 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6463 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6464 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
6465 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6466
6467 if (genlmsg_end(msg, hdr) < 0) {
6468 nlmsg_free(msg);
6469 return;
6470 }
6471
Johannes Berg463d0182009-07-14 00:33:35 +02006472 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6473 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006474 return;
6475
6476 nla_put_failure:
6477 genlmsg_cancel(msg, hdr);
6478 nlmsg_free(msg);
6479}
6480
6481void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006482 struct net_device *netdev, const u8 *addr,
6483 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006484{
6485 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02006486 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006487}
6488
6489void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006490 struct net_device *netdev, const u8 *addr,
6491 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006492{
Johannes Berge6d6e342009-07-01 21:26:47 +02006493 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
6494 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006495}
6496
Samuel Ortizb23aa672009-07-01 21:26:54 +02006497void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
6498 struct net_device *netdev, const u8 *bssid,
6499 const u8 *req_ie, size_t req_ie_len,
6500 const u8 *resp_ie, size_t resp_ie_len,
6501 u16 status, gfp_t gfp)
6502{
6503 struct sk_buff *msg;
6504 void *hdr;
6505
6506 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6507 if (!msg)
6508 return;
6509
6510 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
6511 if (!hdr) {
6512 nlmsg_free(msg);
6513 return;
6514 }
6515
6516 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6517 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6518 if (bssid)
6519 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6520 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
6521 if (req_ie)
6522 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6523 if (resp_ie)
6524 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6525
6526 if (genlmsg_end(msg, hdr) < 0) {
6527 nlmsg_free(msg);
6528 return;
6529 }
6530
Johannes Berg463d0182009-07-14 00:33:35 +02006531 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6532 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006533 return;
6534
6535 nla_put_failure:
6536 genlmsg_cancel(msg, hdr);
6537 nlmsg_free(msg);
6538
6539}
6540
6541void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
6542 struct net_device *netdev, const u8 *bssid,
6543 const u8 *req_ie, size_t req_ie_len,
6544 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
6545{
6546 struct sk_buff *msg;
6547 void *hdr;
6548
6549 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6550 if (!msg)
6551 return;
6552
6553 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
6554 if (!hdr) {
6555 nlmsg_free(msg);
6556 return;
6557 }
6558
6559 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6560 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6561 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6562 if (req_ie)
6563 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6564 if (resp_ie)
6565 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6566
6567 if (genlmsg_end(msg, hdr) < 0) {
6568 nlmsg_free(msg);
6569 return;
6570 }
6571
Johannes Berg463d0182009-07-14 00:33:35 +02006572 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6573 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006574 return;
6575
6576 nla_put_failure:
6577 genlmsg_cancel(msg, hdr);
6578 nlmsg_free(msg);
6579
6580}
6581
6582void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
6583 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02006584 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006585{
6586 struct sk_buff *msg;
6587 void *hdr;
6588
Johannes Berg667503dd2009-07-07 03:56:11 +02006589 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006590 if (!msg)
6591 return;
6592
6593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
6594 if (!hdr) {
6595 nlmsg_free(msg);
6596 return;
6597 }
6598
6599 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6600 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6601 if (from_ap && reason)
6602 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
6603 if (from_ap)
6604 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
6605 if (ie)
6606 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
6607
6608 if (genlmsg_end(msg, hdr) < 0) {
6609 nlmsg_free(msg);
6610 return;
6611 }
6612
Johannes Berg463d0182009-07-14 00:33:35 +02006613 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6614 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006615 return;
6616
6617 nla_put_failure:
6618 genlmsg_cancel(msg, hdr);
6619 nlmsg_free(msg);
6620
6621}
6622
Johannes Berg04a773a2009-04-19 21:24:32 +02006623void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
6624 struct net_device *netdev, const u8 *bssid,
6625 gfp_t gfp)
6626{
6627 struct sk_buff *msg;
6628 void *hdr;
6629
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006631 if (!msg)
6632 return;
6633
6634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
6635 if (!hdr) {
6636 nlmsg_free(msg);
6637 return;
6638 }
6639
6640 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6641 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6642 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6643
6644 if (genlmsg_end(msg, hdr) < 0) {
6645 nlmsg_free(msg);
6646 return;
6647 }
6648
Johannes Berg463d0182009-07-14 00:33:35 +02006649 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6650 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006651 return;
6652
6653 nla_put_failure:
6654 genlmsg_cancel(msg, hdr);
6655 nlmsg_free(msg);
6656}
6657
Javier Cardonac93b5e72011-04-07 15:08:34 -07006658void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
6659 struct net_device *netdev,
6660 const u8 *macaddr, const u8* ie, u8 ie_len,
6661 gfp_t gfp)
6662{
6663 struct sk_buff *msg;
6664 void *hdr;
6665
6666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6667 if (!msg)
6668 return;
6669
6670 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
6671 if (!hdr) {
6672 nlmsg_free(msg);
6673 return;
6674 }
6675
6676 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6677 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6678 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
6679 if (ie_len && ie)
6680 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
6681
6682 if (genlmsg_end(msg, hdr) < 0) {
6683 nlmsg_free(msg);
6684 return;
6685 }
6686
6687 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6688 nl80211_mlme_mcgrp.id, gfp);
6689 return;
6690
6691 nla_put_failure:
6692 genlmsg_cancel(msg, hdr);
6693 nlmsg_free(msg);
6694}
6695
Jouni Malinena3b8b052009-03-27 21:59:49 +02006696void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
6697 struct net_device *netdev, const u8 *addr,
6698 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02006699 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02006700{
6701 struct sk_buff *msg;
6702 void *hdr;
6703
Johannes Berge6d6e342009-07-01 21:26:47 +02006704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006705 if (!msg)
6706 return;
6707
6708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
6709 if (!hdr) {
6710 nlmsg_free(msg);
6711 return;
6712 }
6713
6714 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6715 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6716 if (addr)
6717 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6718 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03006719 if (key_id != -1)
6720 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006721 if (tsc)
6722 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
6723
6724 if (genlmsg_end(msg, hdr) < 0) {
6725 nlmsg_free(msg);
6726 return;
6727 }
6728
Johannes Berg463d0182009-07-14 00:33:35 +02006729 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6730 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006731 return;
6732
6733 nla_put_failure:
6734 genlmsg_cancel(msg, hdr);
6735 nlmsg_free(msg);
6736}
6737
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006738void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
6739 struct ieee80211_channel *channel_before,
6740 struct ieee80211_channel *channel_after)
6741{
6742 struct sk_buff *msg;
6743 void *hdr;
6744 struct nlattr *nl_freq;
6745
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006746 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006747 if (!msg)
6748 return;
6749
6750 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
6751 if (!hdr) {
6752 nlmsg_free(msg);
6753 return;
6754 }
6755
6756 /*
6757 * Since we are applying the beacon hint to a wiphy we know its
6758 * wiphy_idx is valid
6759 */
6760 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
6761
6762 /* Before */
6763 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
6764 if (!nl_freq)
6765 goto nla_put_failure;
6766 if (nl80211_msg_put_channel(msg, channel_before))
6767 goto nla_put_failure;
6768 nla_nest_end(msg, nl_freq);
6769
6770 /* After */
6771 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
6772 if (!nl_freq)
6773 goto nla_put_failure;
6774 if (nl80211_msg_put_channel(msg, channel_after))
6775 goto nla_put_failure;
6776 nla_nest_end(msg, nl_freq);
6777
6778 if (genlmsg_end(msg, hdr) < 0) {
6779 nlmsg_free(msg);
6780 return;
6781 }
6782
Johannes Berg463d0182009-07-14 00:33:35 +02006783 rcu_read_lock();
6784 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
6785 GFP_ATOMIC);
6786 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006787
6788 return;
6789
6790nla_put_failure:
6791 genlmsg_cancel(msg, hdr);
6792 nlmsg_free(msg);
6793}
6794
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006795static void nl80211_send_remain_on_chan_event(
6796 int cmd, struct cfg80211_registered_device *rdev,
6797 struct net_device *netdev, u64 cookie,
6798 struct ieee80211_channel *chan,
6799 enum nl80211_channel_type channel_type,
6800 unsigned int duration, gfp_t gfp)
6801{
6802 struct sk_buff *msg;
6803 void *hdr;
6804
6805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6806 if (!msg)
6807 return;
6808
6809 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6810 if (!hdr) {
6811 nlmsg_free(msg);
6812 return;
6813 }
6814
6815 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6816 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6817 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
6818 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
6819 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6820
6821 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
6822 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
6823
6824 if (genlmsg_end(msg, hdr) < 0) {
6825 nlmsg_free(msg);
6826 return;
6827 }
6828
6829 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6830 nl80211_mlme_mcgrp.id, gfp);
6831 return;
6832
6833 nla_put_failure:
6834 genlmsg_cancel(msg, hdr);
6835 nlmsg_free(msg);
6836}
6837
6838void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
6839 struct net_device *netdev, u64 cookie,
6840 struct ieee80211_channel *chan,
6841 enum nl80211_channel_type channel_type,
6842 unsigned int duration, gfp_t gfp)
6843{
6844 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
6845 rdev, netdev, cookie, chan,
6846 channel_type, duration, gfp);
6847}
6848
6849void nl80211_send_remain_on_channel_cancel(
6850 struct cfg80211_registered_device *rdev, struct net_device *netdev,
6851 u64 cookie, struct ieee80211_channel *chan,
6852 enum nl80211_channel_type channel_type, gfp_t gfp)
6853{
6854 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6855 rdev, netdev, cookie, chan,
6856 channel_type, 0, gfp);
6857}
6858
Johannes Berg98b62182009-12-23 13:15:44 +01006859void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
6860 struct net_device *dev, const u8 *mac_addr,
6861 struct station_info *sinfo, gfp_t gfp)
6862{
6863 struct sk_buff *msg;
6864
6865 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6866 if (!msg)
6867 return;
6868
6869 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
6870 nlmsg_free(msg);
6871 return;
6872 }
6873
6874 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6875 nl80211_mlme_mcgrp.id, gfp);
6876}
6877
Jouni Malinenec15e682011-03-23 15:29:52 +02006878void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
6879 struct net_device *dev, const u8 *mac_addr,
6880 gfp_t gfp)
6881{
6882 struct sk_buff *msg;
6883 void *hdr;
6884
6885 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6886 if (!msg)
6887 return;
6888
6889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
6890 if (!hdr) {
6891 nlmsg_free(msg);
6892 return;
6893 }
6894
6895 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
6896 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
6897
6898 if (genlmsg_end(msg, hdr) < 0) {
6899 nlmsg_free(msg);
6900 return;
6901 }
6902
6903 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6904 nl80211_mlme_mcgrp.id, gfp);
6905 return;
6906
6907 nla_put_failure:
6908 genlmsg_cancel(msg, hdr);
6909 nlmsg_free(msg);
6910}
6911
Johannes Berg2e161f72010-08-12 15:38:38 +02006912int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
6913 struct net_device *netdev, u32 nlpid,
6914 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02006915{
6916 struct sk_buff *msg;
6917 void *hdr;
6918 int err;
6919
6920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6921 if (!msg)
6922 return -ENOMEM;
6923
Johannes Berg2e161f72010-08-12 15:38:38 +02006924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006925 if (!hdr) {
6926 nlmsg_free(msg);
6927 return -ENOMEM;
6928 }
6929
6930 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6931 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6932 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
6933 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6934
6935 err = genlmsg_end(msg, hdr);
6936 if (err < 0) {
6937 nlmsg_free(msg);
6938 return err;
6939 }
6940
6941 err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
6942 if (err < 0)
6943 return err;
6944 return 0;
6945
6946 nla_put_failure:
6947 genlmsg_cancel(msg, hdr);
6948 nlmsg_free(msg);
6949 return -ENOBUFS;
6950}
6951
Johannes Berg2e161f72010-08-12 15:38:38 +02006952void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
6953 struct net_device *netdev, u64 cookie,
6954 const u8 *buf, size_t len, bool ack,
6955 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02006956{
6957 struct sk_buff *msg;
6958 void *hdr;
6959
6960 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6961 if (!msg)
6962 return;
6963
Johannes Berg2e161f72010-08-12 15:38:38 +02006964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02006965 if (!hdr) {
6966 nlmsg_free(msg);
6967 return;
6968 }
6969
6970 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6971 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6972 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6973 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6974 if (ack)
6975 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
6976
6977 if (genlmsg_end(msg, hdr) < 0) {
6978 nlmsg_free(msg);
6979 return;
6980 }
6981
6982 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
6983 return;
6984
6985 nla_put_failure:
6986 genlmsg_cancel(msg, hdr);
6987 nlmsg_free(msg);
6988}
6989
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006990void
6991nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
6992 struct net_device *netdev,
6993 enum nl80211_cqm_rssi_threshold_event rssi_event,
6994 gfp_t gfp)
6995{
6996 struct sk_buff *msg;
6997 struct nlattr *pinfoattr;
6998 void *hdr;
6999
7000 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7001 if (!msg)
7002 return;
7003
7004 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7005 if (!hdr) {
7006 nlmsg_free(msg);
7007 return;
7008 }
7009
7010 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7011 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7012
7013 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7014 if (!pinfoattr)
7015 goto nla_put_failure;
7016
7017 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7018 rssi_event);
7019
7020 nla_nest_end(msg, pinfoattr);
7021
7022 if (genlmsg_end(msg, hdr) < 0) {
7023 nlmsg_free(msg);
7024 return;
7025 }
7026
7027 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7028 nl80211_mlme_mcgrp.id, gfp);
7029 return;
7030
7031 nla_put_failure:
7032 genlmsg_cancel(msg, hdr);
7033 nlmsg_free(msg);
7034}
7035
Johannes Berge5497d72011-07-05 16:35:40 +02007036void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7037 struct net_device *netdev, const u8 *bssid,
7038 const u8 *replay_ctr, gfp_t gfp)
7039{
7040 struct sk_buff *msg;
7041 struct nlattr *rekey_attr;
7042 void *hdr;
7043
7044 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7045 if (!msg)
7046 return;
7047
7048 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7049 if (!hdr) {
7050 nlmsg_free(msg);
7051 return;
7052 }
7053
7054 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7055 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7056 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7057
7058 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7059 if (!rekey_attr)
7060 goto nla_put_failure;
7061
7062 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7063 NL80211_REPLAY_CTR_LEN, replay_ctr);
7064
7065 nla_nest_end(msg, rekey_attr);
7066
7067 if (genlmsg_end(msg, hdr) < 0) {
7068 nlmsg_free(msg);
7069 return;
7070 }
7071
7072 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7073 nl80211_mlme_mcgrp.id, gfp);
7074 return;
7075
7076 nla_put_failure:
7077 genlmsg_cancel(msg, hdr);
7078 nlmsg_free(msg);
7079}
7080
Johannes Bergc063dbf2010-11-24 08:10:05 +01007081void
7082nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7083 struct net_device *netdev, const u8 *peer,
7084 u32 num_packets, gfp_t gfp)
7085{
7086 struct sk_buff *msg;
7087 struct nlattr *pinfoattr;
7088 void *hdr;
7089
7090 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7091 if (!msg)
7092 return;
7093
7094 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7095 if (!hdr) {
7096 nlmsg_free(msg);
7097 return;
7098 }
7099
7100 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7101 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7102 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7103
7104 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7105 if (!pinfoattr)
7106 goto nla_put_failure;
7107
7108 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7109
7110 nla_nest_end(msg, pinfoattr);
7111
7112 if (genlmsg_end(msg, hdr) < 0) {
7113 nlmsg_free(msg);
7114 return;
7115 }
7116
7117 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7118 nl80211_mlme_mcgrp.id, gfp);
7119 return;
7120
7121 nla_put_failure:
7122 genlmsg_cancel(msg, hdr);
7123 nlmsg_free(msg);
7124}
7125
Jouni Malinen026331c2010-02-15 12:53:10 +02007126static int nl80211_netlink_notify(struct notifier_block * nb,
7127 unsigned long state,
7128 void *_notify)
7129{
7130 struct netlink_notify *notify = _notify;
7131 struct cfg80211_registered_device *rdev;
7132 struct wireless_dev *wdev;
7133
7134 if (state != NETLINK_URELEASE)
7135 return NOTIFY_DONE;
7136
7137 rcu_read_lock();
7138
7139 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
7140 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02007141 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007142
7143 rcu_read_unlock();
7144
7145 return NOTIFY_DONE;
7146}
7147
7148static struct notifier_block nl80211_netlink_notifier = {
7149 .notifier_call = nl80211_netlink_notify,
7150};
7151
Johannes Berg55682962007-09-20 13:09:35 -04007152/* initialisation/exit functions */
7153
7154int nl80211_init(void)
7155{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007156 int err;
Johannes Berg55682962007-09-20 13:09:35 -04007157
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007158 err = genl_register_family_with_ops(&nl80211_fam,
7159 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04007160 if (err)
7161 return err;
7162
Johannes Berg55682962007-09-20 13:09:35 -04007163 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7164 if (err)
7165 goto err_out;
7166
Johannes Berg2a519312009-02-10 21:25:55 +01007167 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7168 if (err)
7169 goto err_out;
7170
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007171 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7172 if (err)
7173 goto err_out;
7174
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007175 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7176 if (err)
7177 goto err_out;
7178
Johannes Bergaff89a92009-07-01 21:26:51 +02007179#ifdef CONFIG_NL80211_TESTMODE
7180 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7181 if (err)
7182 goto err_out;
7183#endif
7184
Jouni Malinen026331c2010-02-15 12:53:10 +02007185 err = netlink_register_notifier(&nl80211_netlink_notifier);
7186 if (err)
7187 goto err_out;
7188
Johannes Berg55682962007-09-20 13:09:35 -04007189 return 0;
7190 err_out:
7191 genl_unregister_family(&nl80211_fam);
7192 return err;
7193}
7194
7195void nl80211_exit(void)
7196{
Jouni Malinen026331c2010-02-15 12:53:10 +02007197 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04007198 genl_unregister_family(&nl80211_fam);
7199}