blob: 44a3fc2ce38d711dc5d1e461201d8ea1d1f22e78 [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 Malinendc6382ce2009-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 Berg55682962007-09-20 13:09:35 -0400180};
181
Johannes Berge31b8212010-10-05 19:39:30 +0200182/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000183static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200184 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200185 [NL80211_KEY_IDX] = { .type = NLA_U8 },
186 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
187 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 },
188 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
189 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200190 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100191 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
192};
193
194/* policy for the key default flags */
195static const struct nla_policy
196nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
197 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
198 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200199};
200
Johannes Bergff1b6e62011-05-04 15:37:28 +0200201/* policy for WoWLAN attributes */
202static const struct nla_policy
203nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
204 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
205 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
206 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
207 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200208 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
209 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
210 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
211 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200212};
213
Johannes Berge5497d72011-07-05 16:35:40 +0200214/* policy for GTK rekey offload attributes */
215static const struct nla_policy
216nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
217 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
218 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
219 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
220};
221
Holger Schuriga0438972009-11-11 11:30:02 +0100222/* ifidx get helper */
223static int nl80211_get_ifidx(struct netlink_callback *cb)
224{
225 int res;
226
227 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
228 nl80211_fam.attrbuf, nl80211_fam.maxattr,
229 nl80211_policy);
230 if (res)
231 return res;
232
233 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
234 return -EINVAL;
235
236 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
237 if (!res)
238 return -EINVAL;
239 return res;
240}
241
Johannes Berg67748892010-10-04 21:14:06 +0200242static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
243 struct netlink_callback *cb,
244 struct cfg80211_registered_device **rdev,
245 struct net_device **dev)
246{
247 int ifidx = cb->args[0];
248 int err;
249
250 if (!ifidx)
251 ifidx = nl80211_get_ifidx(cb);
252 if (ifidx < 0)
253 return ifidx;
254
255 cb->args[0] = ifidx;
256
257 rtnl_lock();
258
259 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
260 if (!*dev) {
261 err = -ENODEV;
262 goto out_rtnl;
263 }
264
265 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100266 if (IS_ERR(*rdev)) {
267 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200268 goto out_rtnl;
269 }
270
271 return 0;
272 out_rtnl:
273 rtnl_unlock();
274 return err;
275}
276
277static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
278{
279 cfg80211_unlock_rdev(rdev);
280 rtnl_unlock();
281}
282
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100283/* IE validation */
284static bool is_valid_ie_attr(const struct nlattr *attr)
285{
286 const u8 *pos;
287 int len;
288
289 if (!attr)
290 return true;
291
292 pos = nla_data(attr);
293 len = nla_len(attr);
294
295 while (len) {
296 u8 elemlen;
297
298 if (len < 2)
299 return false;
300 len -= 2;
301
302 elemlen = pos[1];
303 if (elemlen > len)
304 return false;
305
306 len -= elemlen;
307 pos += 2 + elemlen;
308 }
309
310 return true;
311}
312
Johannes Berg55682962007-09-20 13:09:35 -0400313/* message building helper */
314static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
315 int flags, u8 cmd)
316{
317 /* since there is no private header just add the generic one */
318 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
319}
320
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400321static int nl80211_msg_put_channel(struct sk_buff *msg,
322 struct ieee80211_channel *chan)
323{
324 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
325 chan->center_freq);
326
327 if (chan->flags & IEEE80211_CHAN_DISABLED)
328 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
329 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
330 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
331 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
332 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
333 if (chan->flags & IEEE80211_CHAN_RADAR)
334 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
335
336 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
337 DBM_TO_MBM(chan->max_power));
338
339 return 0;
340
341 nla_put_failure:
342 return -ENOBUFS;
343}
344
Johannes Berg55682962007-09-20 13:09:35 -0400345/* netlink command implementations */
346
Johannes Bergb9454e82009-07-08 13:29:08 +0200347struct key_parse {
348 struct key_params p;
349 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200350 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200351 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100352 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200353};
354
355static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
356{
357 struct nlattr *tb[NL80211_KEY_MAX + 1];
358 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
359 nl80211_key_policy);
360 if (err)
361 return err;
362
363 k->def = !!tb[NL80211_KEY_DEFAULT];
364 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
365
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100366 if (k->def) {
367 k->def_uni = true;
368 k->def_multi = true;
369 }
370 if (k->defmgmt)
371 k->def_multi = true;
372
Johannes Bergb9454e82009-07-08 13:29:08 +0200373 if (tb[NL80211_KEY_IDX])
374 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
375
376 if (tb[NL80211_KEY_DATA]) {
377 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
378 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
379 }
380
381 if (tb[NL80211_KEY_SEQ]) {
382 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
383 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
384 }
385
386 if (tb[NL80211_KEY_CIPHER])
387 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
388
Johannes Berge31b8212010-10-05 19:39:30 +0200389 if (tb[NL80211_KEY_TYPE]) {
390 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
391 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
392 return -EINVAL;
393 }
394
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100395 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
396 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
397 int err = nla_parse_nested(kdt,
398 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
399 tb[NL80211_KEY_DEFAULT_TYPES],
400 nl80211_key_default_policy);
401 if (err)
402 return err;
403
404 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
405 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
406 }
407
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 return 0;
409}
410
411static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
412{
413 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
414 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
415 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
416 }
417
418 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
419 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
420 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
421 }
422
423 if (info->attrs[NL80211_ATTR_KEY_IDX])
424 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
425
426 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
427 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
428
429 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
430 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
431
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100432 if (k->def) {
433 k->def_uni = true;
434 k->def_multi = true;
435 }
436 if (k->defmgmt)
437 k->def_multi = true;
438
Johannes Berge31b8212010-10-05 19:39:30 +0200439 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
440 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
441 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
442 return -EINVAL;
443 }
444
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100445 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
446 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
447 int err = nla_parse_nested(
448 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
449 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
450 nl80211_key_default_policy);
451 if (err)
452 return err;
453
454 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
455 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
456 }
457
Johannes Bergb9454e82009-07-08 13:29:08 +0200458 return 0;
459}
460
461static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
462{
463 int err;
464
465 memset(k, 0, sizeof(*k));
466 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200467 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200468
469 if (info->attrs[NL80211_ATTR_KEY])
470 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
471 else
472 err = nl80211_parse_key_old(info, k);
473
474 if (err)
475 return err;
476
477 if (k->def && k->defmgmt)
478 return -EINVAL;
479
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100480 if (k->defmgmt) {
481 if (k->def_uni || !k->def_multi)
482 return -EINVAL;
483 }
484
Johannes Bergb9454e82009-07-08 13:29:08 +0200485 if (k->idx != -1) {
486 if (k->defmgmt) {
487 if (k->idx < 4 || k->idx > 5)
488 return -EINVAL;
489 } else if (k->def) {
490 if (k->idx < 0 || k->idx > 3)
491 return -EINVAL;
492 } else {
493 if (k->idx < 0 || k->idx > 5)
494 return -EINVAL;
495 }
496 }
497
498 return 0;
499}
500
Johannes Bergfffd0932009-07-08 14:22:54 +0200501static struct cfg80211_cached_keys *
502nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
503 struct nlattr *keys)
504{
505 struct key_parse parse;
506 struct nlattr *key;
507 struct cfg80211_cached_keys *result;
508 int rem, err, def = 0;
509
510 result = kzalloc(sizeof(*result), GFP_KERNEL);
511 if (!result)
512 return ERR_PTR(-ENOMEM);
513
514 result->def = -1;
515 result->defmgmt = -1;
516
517 nla_for_each_nested(key, keys, rem) {
518 memset(&parse, 0, sizeof(parse));
519 parse.idx = -1;
520
521 err = nl80211_parse_key_new(key, &parse);
522 if (err)
523 goto error;
524 err = -EINVAL;
525 if (!parse.p.key)
526 goto error;
527 if (parse.idx < 0 || parse.idx > 4)
528 goto error;
529 if (parse.def) {
530 if (def)
531 goto error;
532 def = 1;
533 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100534 if (!parse.def_uni || !parse.def_multi)
535 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200536 } else if (parse.defmgmt)
537 goto error;
538 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200539 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200540 if (err)
541 goto error;
542 result->params[parse.idx].cipher = parse.p.cipher;
543 result->params[parse.idx].key_len = parse.p.key_len;
544 result->params[parse.idx].key = result->data[parse.idx];
545 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
546 }
547
548 return result;
549 error:
550 kfree(result);
551 return ERR_PTR(err);
552}
553
554static int nl80211_key_allowed(struct wireless_dev *wdev)
555{
556 ASSERT_WDEV_LOCK(wdev);
557
Johannes Bergfffd0932009-07-08 14:22:54 +0200558 switch (wdev->iftype) {
559 case NL80211_IFTYPE_AP:
560 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200561 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700562 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200563 break;
564 case NL80211_IFTYPE_ADHOC:
565 if (!wdev->current_bss)
566 return -ENOLINK;
567 break;
568 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200569 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200570 if (wdev->sme_state != CFG80211_SME_CONNECTED)
571 return -ENOLINK;
572 break;
573 default:
574 return -EINVAL;
575 }
576
577 return 0;
578}
579
Johannes Berg7527a782011-05-13 10:58:57 +0200580static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
581{
582 struct nlattr *nl_modes = nla_nest_start(msg, attr);
583 int i;
584
585 if (!nl_modes)
586 goto nla_put_failure;
587
588 i = 0;
589 while (ifmodes) {
590 if (ifmodes & 1)
591 NLA_PUT_FLAG(msg, i);
592 ifmodes >>= 1;
593 i++;
594 }
595
596 nla_nest_end(msg, nl_modes);
597 return 0;
598
599nla_put_failure:
600 return -ENOBUFS;
601}
602
603static int nl80211_put_iface_combinations(struct wiphy *wiphy,
604 struct sk_buff *msg)
605{
606 struct nlattr *nl_combis;
607 int i, j;
608
609 nl_combis = nla_nest_start(msg,
610 NL80211_ATTR_INTERFACE_COMBINATIONS);
611 if (!nl_combis)
612 goto nla_put_failure;
613
614 for (i = 0; i < wiphy->n_iface_combinations; i++) {
615 const struct ieee80211_iface_combination *c;
616 struct nlattr *nl_combi, *nl_limits;
617
618 c = &wiphy->iface_combinations[i];
619
620 nl_combi = nla_nest_start(msg, i + 1);
621 if (!nl_combi)
622 goto nla_put_failure;
623
624 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
625 if (!nl_limits)
626 goto nla_put_failure;
627
628 for (j = 0; j < c->n_limits; j++) {
629 struct nlattr *nl_limit;
630
631 nl_limit = nla_nest_start(msg, j + 1);
632 if (!nl_limit)
633 goto nla_put_failure;
634 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
635 c->limits[j].max);
636 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
637 c->limits[j].types))
638 goto nla_put_failure;
639 nla_nest_end(msg, nl_limit);
640 }
641
642 nla_nest_end(msg, nl_limits);
643
644 if (c->beacon_int_infra_match)
645 NLA_PUT_FLAG(msg,
646 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
647 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
648 c->num_different_channels);
649 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
650 c->max_interfaces);
651
652 nla_nest_end(msg, nl_combi);
653 }
654
655 nla_nest_end(msg, nl_combis);
656
657 return 0;
658nla_put_failure:
659 return -ENOBUFS;
660}
661
Johannes Berg55682962007-09-20 13:09:35 -0400662static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
663 struct cfg80211_registered_device *dev)
664{
665 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100666 struct nlattr *nl_bands, *nl_band;
667 struct nlattr *nl_freqs, *nl_freq;
668 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100669 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100670 enum ieee80211_band band;
671 struct ieee80211_channel *chan;
672 struct ieee80211_rate *rate;
673 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200674 const struct ieee80211_txrx_stypes *mgmt_stypes =
675 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400676
677 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
678 if (!hdr)
679 return -1;
680
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500681 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400682 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200683
Johannes Bergf5ea9122009-08-07 16:17:38 +0200684 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
685 cfg80211_rdev_list_generation);
686
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200687 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
688 dev->wiphy.retry_short);
689 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
690 dev->wiphy.retry_long);
691 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
692 dev->wiphy.frag_threshold);
693 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
694 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100695 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
696 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100697 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
698 dev->wiphy.max_scan_ssids);
Luciano Coelho93b6aa62011-07-13 14:57:28 +0300699 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
700 dev->wiphy.max_sched_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200701 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
702 dev->wiphy.max_scan_ie_len);
Luciano Coelho5a865ba2011-07-13 14:57:29 +0300703 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
704 dev->wiphy.max_sched_scan_ie_len);
Johannes Bergee688b002008-01-24 19:38:39 +0100705
Johannes Berge31b8212010-10-05 19:39:30 +0200706 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
707 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
Javier Cardona15d5dda2011-04-07 15:08:28 -0700708 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
709 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
Johannes Berge31b8212010-10-05 19:39:30 +0200710
Johannes Berg25e47c182009-04-02 20:14:06 +0200711 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
712 sizeof(u32) * dev->wiphy.n_cipher_suites,
713 dev->wiphy.cipher_suites);
714
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100715 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
716 dev->wiphy.max_num_pmkids);
717
Johannes Bergc0692b82010-08-27 14:26:53 +0300718 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
719 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
720
Bruno Randolf39fd5de2010-12-16 11:30:28 +0900721 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
722 dev->wiphy.available_antennas_tx);
723 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
724 dev->wiphy.available_antennas_rx);
725
Bruno Randolf7f531e02010-12-16 11:30:22 +0900726 if ((dev->wiphy.available_antennas_tx ||
727 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900728 u32 tx_ant = 0, rx_ant = 0;
729 int res;
730 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
731 if (!res) {
732 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
733 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
734 }
735 }
736
Johannes Berg7527a782011-05-13 10:58:57 +0200737 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
738 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700739 goto nla_put_failure;
740
Johannes Bergee688b002008-01-24 19:38:39 +0100741 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
742 if (!nl_bands)
743 goto nla_put_failure;
744
745 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
746 if (!dev->wiphy.bands[band])
747 continue;
748
749 nl_band = nla_nest_start(msg, band);
750 if (!nl_band)
751 goto nla_put_failure;
752
Johannes Bergd51626d2008-10-09 12:20:13 +0200753 /* add HT info */
754 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
755 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
756 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
757 &dev->wiphy.bands[band]->ht_cap.mcs);
758 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
759 dev->wiphy.bands[band]->ht_cap.cap);
760 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
761 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
762 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
763 dev->wiphy.bands[band]->ht_cap.ampdu_density);
764 }
765
Johannes Bergee688b002008-01-24 19:38:39 +0100766 /* add frequencies */
767 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
768 if (!nl_freqs)
769 goto nla_put_failure;
770
771 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
772 nl_freq = nla_nest_start(msg, i);
773 if (!nl_freq)
774 goto nla_put_failure;
775
776 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100777
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400778 if (nl80211_msg_put_channel(msg, chan))
779 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200780
Johannes Bergee688b002008-01-24 19:38:39 +0100781 nla_nest_end(msg, nl_freq);
782 }
783
784 nla_nest_end(msg, nl_freqs);
785
786 /* add bitrates */
787 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
788 if (!nl_rates)
789 goto nla_put_failure;
790
791 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
792 nl_rate = nla_nest_start(msg, i);
793 if (!nl_rate)
794 goto nla_put_failure;
795
796 rate = &dev->wiphy.bands[band]->bitrates[i];
797 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
798 rate->bitrate);
799 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
800 NLA_PUT_FLAG(msg,
801 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
802
803 nla_nest_end(msg, nl_rate);
804 }
805
806 nla_nest_end(msg, nl_rates);
807
808 nla_nest_end(msg, nl_band);
809 }
810 nla_nest_end(msg, nl_bands);
811
Johannes Berg8fdc6212009-03-14 09:34:01 +0100812 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
813 if (!nl_cmds)
814 goto nla_put_failure;
815
816 i = 0;
817#define CMD(op, n) \
818 do { \
819 if (dev->ops->op) { \
820 i++; \
821 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
822 } \
823 } while (0)
824
825 CMD(add_virtual_intf, NEW_INTERFACE);
826 CMD(change_virtual_intf, SET_INTERFACE);
827 CMD(add_key, NEW_KEY);
828 CMD(add_beacon, NEW_BEACON);
829 CMD(add_station, NEW_STATION);
830 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800831 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100832 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200833 CMD(auth, AUTHENTICATE);
834 CMD(assoc, ASSOCIATE);
835 CMD(deauth, DEAUTHENTICATE);
836 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200837 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100838 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100839 CMD(set_pmksa, SET_PMKSA);
840 CMD(del_pmksa, DEL_PMKSA);
841 CMD(flush_pmksa, FLUSH_PMKSA);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100842 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200843 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200844 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100845 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100846 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200847 i++;
848 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
849 }
Johannes Bergf444de02010-05-05 15:25:02 +0200850 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400851 CMD(set_wds_peer, SET_WDS_PEER);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300852 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
853 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100854
855#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200856
Johannes Berg6829c8782009-07-02 09:13:27 +0200857 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200858 i++;
859 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
860 }
861
Johannes Berg6829c8782009-07-02 09:13:27 +0200862 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200863 i++;
864 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
865 }
866
Johannes Berg8fdc6212009-03-14 09:34:01 +0100867 nla_nest_end(msg, nl_cmds);
868
Johannes Berga2939112010-12-14 17:54:28 +0100869 if (dev->ops->remain_on_channel)
870 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
871 dev->wiphy.max_remain_on_channel_duration);
872
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100873 /* for now at least assume all drivers have it */
874 if (dev->ops->mgmt_tx)
875 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
2239 return genlmsg_end(msg, hdr);
2240
2241 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002242 genlmsg_cancel(msg, hdr);
2243 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002244}
2245
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002246static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002247 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002248{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002249 struct station_info sinfo;
2250 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002251 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002252 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002253 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002254 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002255
Johannes Berg67748892010-10-04 21:14:06 +02002256 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2257 if (err)
2258 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002259
2260 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002261 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 goto out_err;
2263 }
2264
Johannes Bergbba95fe2008-07-29 13:22:51 +02002265 while (1) {
2266 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2267 mac_addr, &sinfo);
2268 if (err == -ENOENT)
2269 break;
2270 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002271 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002272
2273 if (nl80211_send_station(skb,
2274 NETLINK_CB(cb->skb).pid,
2275 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2276 netdev, mac_addr,
2277 &sinfo) < 0)
2278 goto out;
2279
2280 sta_idx++;
2281 }
2282
2283
2284 out:
2285 cb->args[1] = sta_idx;
2286 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002287 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002288 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002289
2290 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002291}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002292
Johannes Berg5727ef12007-12-19 02:03:34 +01002293static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2294{
Johannes Berg4c476992010-10-04 21:36:35 +02002295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2296 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002297 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002298 struct sk_buff *msg;
2299 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002300 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002301
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002302 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002303
2304 if (!info->attrs[NL80211_ATTR_MAC])
2305 return -EINVAL;
2306
2307 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2308
Johannes Berg4c476992010-10-04 21:36:35 +02002309 if (!rdev->ops->get_station)
2310 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002311
Johannes Berg79c97e92009-07-07 03:56:12 +02002312 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002313 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002314 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002315
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002316 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002317 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002318 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002319
2320 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002321 dev, mac_addr, &sinfo) < 0) {
2322 nlmsg_free(msg);
2323 return -ENOBUFS;
2324 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002325
Johannes Berg4c476992010-10-04 21:36:35 +02002326 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002327}
2328
2329/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002330 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002331 */
Johannes Berg463d0182009-07-14 00:33:35 +02002332static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002333 struct cfg80211_registered_device *rdev,
2334 struct net_device **vlan)
2335{
Johannes Berg463d0182009-07-14 00:33:35 +02002336 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002337 *vlan = NULL;
2338
2339 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002340 *vlan = dev_get_by_index(genl_info_net(info),
2341 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002342 if (!*vlan)
2343 return -ENODEV;
2344 if (!(*vlan)->ieee80211_ptr)
2345 return -EINVAL;
2346 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2347 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002348 if (!netif_running(*vlan))
2349 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002350 }
2351 return 0;
2352}
2353
2354static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2355{
Johannes Berg4c476992010-10-04 21:36:35 +02002356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002357 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002358 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002359 struct station_parameters params;
2360 u8 *mac_addr = NULL;
2361
2362 memset(&params, 0, sizeof(params));
2363
2364 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002365 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002366
2367 if (info->attrs[NL80211_ATTR_STA_AID])
2368 return -EINVAL;
2369
2370 if (!info->attrs[NL80211_ATTR_MAC])
2371 return -EINVAL;
2372
2373 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2374
2375 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2376 params.supported_rates =
2377 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2378 params.supported_rates_len =
2379 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2380 }
2381
2382 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2383 params.listen_interval =
2384 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2385
Jouni Malinen36aedc92008-08-25 11:58:58 +03002386 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2387 params.ht_capa =
2388 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2389
Johannes Bergeccb8e82009-05-11 21:57:56 +03002390 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002391 return -EINVAL;
2392
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002393 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2394 params.plink_action =
2395 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2396
Javier Cardona9c3990a2011-05-03 16:57:11 -07002397 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2398 params.plink_state =
2399 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2400
Johannes Berg463d0182009-07-14 00:33:35 +02002401 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002402 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002403 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002404
2405 /* validate settings */
2406 err = 0;
2407
2408 switch (dev->ieee80211_ptr->iftype) {
2409 case NL80211_IFTYPE_AP:
2410 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002411 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002412 /* disallow mesh-specific things */
2413 if (params.plink_action)
2414 err = -EINVAL;
2415 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002416 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002417 case NL80211_IFTYPE_STATION:
2418 /* disallow everything but AUTHORIZED flag */
2419 if (params.plink_action)
2420 err = -EINVAL;
2421 if (params.vlan)
2422 err = -EINVAL;
2423 if (params.supported_rates)
2424 err = -EINVAL;
2425 if (params.ht_capa)
2426 err = -EINVAL;
2427 if (params.listen_interval >= 0)
2428 err = -EINVAL;
2429 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2430 err = -EINVAL;
2431 break;
2432 case NL80211_IFTYPE_MESH_POINT:
2433 /* disallow things mesh doesn't support */
2434 if (params.vlan)
2435 err = -EINVAL;
2436 if (params.ht_capa)
2437 err = -EINVAL;
2438 if (params.listen_interval >= 0)
2439 err = -EINVAL;
Javier Cardonab39c48f2011-04-07 15:08:30 -07002440 if (params.sta_flags_mask &
2441 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002442 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002443 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Berga97f4422009-06-18 17:23:43 +02002444 err = -EINVAL;
2445 break;
2446 default:
2447 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002448 }
2449
Johannes Berg5727ef12007-12-19 02:03:34 +01002450 if (err)
2451 goto out;
2452
Johannes Berg79c97e92009-07-07 03:56:12 +02002453 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002454 err = -EOPNOTSUPP;
2455 goto out;
2456 }
2457
Johannes Berg79c97e92009-07-07 03:56:12 +02002458 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002459
2460 out:
2461 if (params.vlan)
2462 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002463
Johannes Berg5727ef12007-12-19 02:03:34 +01002464 return err;
2465}
2466
2467static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2468{
Johannes Berg4c476992010-10-04 21:36:35 +02002469 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002470 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002471 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002472 struct station_parameters params;
2473 u8 *mac_addr = NULL;
2474
2475 memset(&params, 0, sizeof(params));
2476
2477 if (!info->attrs[NL80211_ATTR_MAC])
2478 return -EINVAL;
2479
Johannes Berg5727ef12007-12-19 02:03:34 +01002480 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2481 return -EINVAL;
2482
2483 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2484 return -EINVAL;
2485
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002486 if (!info->attrs[NL80211_ATTR_STA_AID])
2487 return -EINVAL;
2488
Johannes Berg5727ef12007-12-19 02:03:34 +01002489 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2490 params.supported_rates =
2491 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2492 params.supported_rates_len =
2493 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2494 params.listen_interval =
2495 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002496
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002497 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2498 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2499 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002500
Jouni Malinen36aedc92008-08-25 11:58:58 +03002501 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2502 params.ht_capa =
2503 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002504
Javier Cardona96b78df2011-04-07 15:08:33 -07002505 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2506 params.plink_action =
2507 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2508
Johannes Bergeccb8e82009-05-11 21:57:56 +03002509 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002510 return -EINVAL;
2511
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002512 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002513 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardona96b78df2011-04-07 15:08:33 -07002514 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002515 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2516 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002517
Johannes Berg463d0182009-07-14 00:33:35 +02002518 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002519 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002520 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002521
2522 /* validate settings */
2523 err = 0;
2524
Johannes Berg79c97e92009-07-07 03:56:12 +02002525 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002526 err = -EOPNOTSUPP;
2527 goto out;
2528 }
2529
Johannes Berg79c97e92009-07-07 03:56:12 +02002530 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002531
2532 out:
2533 if (params.vlan)
2534 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002535 return err;
2536}
2537
2538static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2539{
Johannes Berg4c476992010-10-04 21:36:35 +02002540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2541 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002542 u8 *mac_addr = NULL;
2543
2544 if (info->attrs[NL80211_ATTR_MAC])
2545 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2546
Johannes Berge80cf852009-05-11 14:43:13 +02002547 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002548 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002549 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002550 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2551 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002552
Johannes Berg4c476992010-10-04 21:36:35 +02002553 if (!rdev->ops->del_station)
2554 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002555
Johannes Berg4c476992010-10-04 21:36:35 +02002556 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002557}
2558
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002559static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2560 int flags, struct net_device *dev,
2561 u8 *dst, u8 *next_hop,
2562 struct mpath_info *pinfo)
2563{
2564 void *hdr;
2565 struct nlattr *pinfoattr;
2566
2567 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2568 if (!hdr)
2569 return -1;
2570
2571 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2572 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2573 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2574
Johannes Bergf5ea9122009-08-07 16:17:38 +02002575 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2576
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002577 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2578 if (!pinfoattr)
2579 goto nla_put_failure;
2580 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2581 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2582 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002583 if (pinfo->filled & MPATH_INFO_SN)
2584 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2585 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002586 if (pinfo->filled & MPATH_INFO_METRIC)
2587 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2588 pinfo->metric);
2589 if (pinfo->filled & MPATH_INFO_EXPTIME)
2590 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2591 pinfo->exptime);
2592 if (pinfo->filled & MPATH_INFO_FLAGS)
2593 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2594 pinfo->flags);
2595 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2596 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2597 pinfo->discovery_timeout);
2598 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2599 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2600 pinfo->discovery_retries);
2601
2602 nla_nest_end(msg, pinfoattr);
2603
2604 return genlmsg_end(msg, hdr);
2605
2606 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002607 genlmsg_cancel(msg, hdr);
2608 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002609}
2610
2611static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002612 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002613{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002614 struct mpath_info pinfo;
2615 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002616 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002617 u8 dst[ETH_ALEN];
2618 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002619 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002620 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002621
Johannes Berg67748892010-10-04 21:14:06 +02002622 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2623 if (err)
2624 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002625
2626 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002627 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002628 goto out_err;
2629 }
2630
Jouni Malineneec60b02009-03-20 21:21:19 +02002631 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2632 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002633 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002634 }
2635
Johannes Bergbba95fe2008-07-29 13:22:51 +02002636 while (1) {
2637 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2638 dst, next_hop, &pinfo);
2639 if (err == -ENOENT)
2640 break;
2641 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002642 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002643
2644 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2645 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2646 netdev, dst, next_hop,
2647 &pinfo) < 0)
2648 goto out;
2649
2650 path_idx++;
2651 }
2652
2653
2654 out:
2655 cb->args[1] = path_idx;
2656 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002657 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002658 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002659 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002660}
2661
2662static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2663{
Johannes Berg4c476992010-10-04 21:36:35 +02002664 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002665 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002666 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002667 struct mpath_info pinfo;
2668 struct sk_buff *msg;
2669 u8 *dst = NULL;
2670 u8 next_hop[ETH_ALEN];
2671
2672 memset(&pinfo, 0, sizeof(pinfo));
2673
2674 if (!info->attrs[NL80211_ATTR_MAC])
2675 return -EINVAL;
2676
2677 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2678
Johannes Berg4c476992010-10-04 21:36:35 +02002679 if (!rdev->ops->get_mpath)
2680 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002681
Johannes Berg4c476992010-10-04 21:36:35 +02002682 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2683 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002684
Johannes Berg79c97e92009-07-07 03:56:12 +02002685 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002686 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002687 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002688
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002689 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002690 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002691 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002692
2693 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002694 dev, dst, next_hop, &pinfo) < 0) {
2695 nlmsg_free(msg);
2696 return -ENOBUFS;
2697 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002698
Johannes Berg4c476992010-10-04 21:36:35 +02002699 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002700}
2701
2702static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2703{
Johannes Berg4c476992010-10-04 21:36:35 +02002704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2705 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002706 u8 *dst = NULL;
2707 u8 *next_hop = NULL;
2708
2709 if (!info->attrs[NL80211_ATTR_MAC])
2710 return -EINVAL;
2711
2712 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2713 return -EINVAL;
2714
2715 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2716 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2717
Johannes Berg4c476992010-10-04 21:36:35 +02002718 if (!rdev->ops->change_mpath)
2719 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002720
Johannes Berg4c476992010-10-04 21:36:35 +02002721 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2722 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002723
Johannes Berg4c476992010-10-04 21:36:35 +02002724 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002725}
Johannes Berg4c476992010-10-04 21:36:35 +02002726
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002727static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2728{
Johannes Berg4c476992010-10-04 21:36:35 +02002729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2730 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002731 u8 *dst = NULL;
2732 u8 *next_hop = NULL;
2733
2734 if (!info->attrs[NL80211_ATTR_MAC])
2735 return -EINVAL;
2736
2737 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2738 return -EINVAL;
2739
2740 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2741 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2742
Johannes Berg4c476992010-10-04 21:36:35 +02002743 if (!rdev->ops->add_mpath)
2744 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002745
Johannes Berg4c476992010-10-04 21:36:35 +02002746 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2747 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002748
Johannes Berg4c476992010-10-04 21:36:35 +02002749 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002750}
2751
2752static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2753{
Johannes Berg4c476992010-10-04 21:36:35 +02002754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2755 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002756 u8 *dst = NULL;
2757
2758 if (info->attrs[NL80211_ATTR_MAC])
2759 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2760
Johannes Berg4c476992010-10-04 21:36:35 +02002761 if (!rdev->ops->del_mpath)
2762 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002763
Johannes Berg4c476992010-10-04 21:36:35 +02002764 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002765}
2766
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002767static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2768{
Johannes Berg4c476992010-10-04 21:36:35 +02002769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2770 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002771 struct bss_parameters params;
2772
2773 memset(&params, 0, sizeof(params));
2774 /* default to not changing parameters */
2775 params.use_cts_prot = -1;
2776 params.use_short_preamble = -1;
2777 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002778 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002779 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002780
2781 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2782 params.use_cts_prot =
2783 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2784 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2785 params.use_short_preamble =
2786 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2787 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2788 params.use_short_slot_time =
2789 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002790 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2791 params.basic_rates =
2792 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2793 params.basic_rates_len =
2794 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2795 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002796 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2797 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01002798 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2799 params.ht_opmode =
2800 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002801
Johannes Berg4c476992010-10-04 21:36:35 +02002802 if (!rdev->ops->change_bss)
2803 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002804
Johannes Berg074ac8d2010-09-16 14:58:22 +02002805 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002806 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2807 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002808
Johannes Berg4c476992010-10-04 21:36:35 +02002809 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002810}
2811
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002812static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002813 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2814 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2815 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2816 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2817 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2818 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2819};
2820
2821static int parse_reg_rule(struct nlattr *tb[],
2822 struct ieee80211_reg_rule *reg_rule)
2823{
2824 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2825 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2826
2827 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2828 return -EINVAL;
2829 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2830 return -EINVAL;
2831 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2832 return -EINVAL;
2833 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2834 return -EINVAL;
2835 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2836 return -EINVAL;
2837
2838 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2839
2840 freq_range->start_freq_khz =
2841 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2842 freq_range->end_freq_khz =
2843 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2844 freq_range->max_bandwidth_khz =
2845 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2846
2847 power_rule->max_eirp =
2848 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2849
2850 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2851 power_rule->max_antenna_gain =
2852 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2853
2854 return 0;
2855}
2856
2857static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2858{
2859 int r;
2860 char *data = NULL;
2861
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002862 /*
2863 * You should only get this when cfg80211 hasn't yet initialized
2864 * completely when built-in to the kernel right between the time
2865 * window between nl80211_init() and regulatory_init(), if that is
2866 * even possible.
2867 */
2868 mutex_lock(&cfg80211_mutex);
2869 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002870 mutex_unlock(&cfg80211_mutex);
2871 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002872 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002873 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002874
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002875 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2876 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002877
2878 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2879
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002880 r = regulatory_hint_user(data);
2881
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002882 return r;
2883}
2884
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002885static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01002886 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002887{
Johannes Berg4c476992010-10-04 21:36:35 +02002888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02002889 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01002890 struct wireless_dev *wdev = dev->ieee80211_ptr;
2891 struct mesh_config cur_params;
2892 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002893 void *hdr;
2894 struct nlattr *pinfoattr;
2895 struct sk_buff *msg;
2896
Johannes Berg29cbe682010-12-03 09:20:44 +01002897 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2898 return -EOPNOTSUPP;
2899
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002900 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02002901 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02002902
Johannes Berg29cbe682010-12-03 09:20:44 +01002903 wdev_lock(wdev);
2904 /* If not connected, get default parameters */
2905 if (!wdev->mesh_id_len)
2906 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
2907 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002908 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01002909 &cur_params);
2910 wdev_unlock(wdev);
2911
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002912 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002913 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002914
2915 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002916 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002917 if (!msg)
2918 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002919 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002920 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002921 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01002922 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002923 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002924 if (!pinfoattr)
2925 goto nla_put_failure;
2926 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2927 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2928 cur_params.dot11MeshRetryTimeout);
2929 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2930 cur_params.dot11MeshConfirmTimeout);
2931 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2932 cur_params.dot11MeshHoldingTimeout);
2933 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2934 cur_params.dot11MeshMaxPeerLinks);
2935 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2936 cur_params.dot11MeshMaxRetries);
2937 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2938 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01002939 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
2940 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002941 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2942 cur_params.auto_open_plinks);
2943 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2944 cur_params.dot11MeshHWMPmaxPREQretries);
2945 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2946 cur_params.path_refresh_time);
2947 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2948 cur_params.min_discovery_timeout);
2949 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2950 cur_params.dot11MeshHWMPactivePathTimeout);
2951 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2952 cur_params.dot11MeshHWMPpreqMinInterval);
2953 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2954 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00002955 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
2956 cur_params.dot11MeshHWMPRootMode);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002957 nla_nest_end(msg, pinfoattr);
2958 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002959 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002960
Johannes Berg3b858752009-03-12 09:55:09 +01002961 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002962 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01002963 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04002964 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02002965 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002966}
2967
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002968static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002969 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2970 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2971 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2972 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2973 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2974 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01002975 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002976 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2977
2978 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2979 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2980 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2981 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2982 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2983 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2984};
2985
Javier Cardonac80d5452010-12-16 17:37:49 -08002986static const struct nla_policy
2987 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
2988 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
2989 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07002990 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07002991 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08002992 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07002993 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08002994};
2995
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002996static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01002997 struct mesh_config *cfg,
2998 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002999{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003000 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003001 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003002
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003003#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3004do {\
3005 if (table[attr_num]) {\
3006 cfg->param = nla_fn(table[attr_num]); \
3007 mask |= (1 << (attr_num - 1)); \
3008 } \
3009} while (0);\
3010
3011
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003012 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003013 return -EINVAL;
3014 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003015 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003016 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003017 return -EINVAL;
3018
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003019 /* This makes sure that there aren't more than 32 mesh config
3020 * parameters (otherwise our bitfield scheme would not work.) */
3021 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3022
3023 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003024 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3025 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3026 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3027 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3028 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3029 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3030 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3031 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3032 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3033 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3034 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3035 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003036 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3037 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003038 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3039 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3040 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3041 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3042 nla_get_u8);
3043 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3044 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3045 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3046 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3047 nla_get_u16);
3048 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3049 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3050 nla_get_u32);
3051 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3052 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3053 nla_get_u16);
3054 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3055 dot11MeshHWMPnetDiameterTraversalTime,
3056 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3057 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003058 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3059 dot11MeshHWMPRootMode, mask,
3060 NL80211_MESHCONF_HWMP_ROOTMODE,
3061 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003062 if (mask_out)
3063 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003064
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003065 return 0;
3066
3067#undef FILL_IN_MESH_PARAM_IF_SET
3068}
3069
Javier Cardonac80d5452010-12-16 17:37:49 -08003070static int nl80211_parse_mesh_setup(struct genl_info *info,
3071 struct mesh_setup *setup)
3072{
3073 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3074
3075 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3076 return -EINVAL;
3077 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3078 info->attrs[NL80211_ATTR_MESH_SETUP],
3079 nl80211_mesh_setup_params_policy))
3080 return -EINVAL;
3081
3082 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3083 setup->path_sel_proto =
3084 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3085 IEEE80211_PATH_PROTOCOL_VENDOR :
3086 IEEE80211_PATH_PROTOCOL_HWMP;
3087
3088 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3089 setup->path_metric =
3090 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3091 IEEE80211_PATH_METRIC_VENDOR :
3092 IEEE80211_PATH_METRIC_AIRTIME;
3093
Javier Cardona581a8b02011-04-07 15:08:27 -07003094
3095 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003096 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003097 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003098 if (!is_valid_ie_attr(ieattr))
3099 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003100 setup->ie = nla_data(ieattr);
3101 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003102 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003103 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3104 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003105
3106 return 0;
3107}
3108
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003109static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003110 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003111{
3112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3113 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003114 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003115 struct mesh_config cfg;
3116 u32 mask;
3117 int err;
3118
Johannes Berg29cbe682010-12-03 09:20:44 +01003119 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3120 return -EOPNOTSUPP;
3121
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003122 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003123 return -EOPNOTSUPP;
3124
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003125 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003126 if (err)
3127 return err;
3128
Johannes Berg29cbe682010-12-03 09:20:44 +01003129 wdev_lock(wdev);
3130 if (!wdev->mesh_id_len)
3131 err = -ENOLINK;
3132
3133 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003134 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003135 mask, &cfg);
3136
3137 wdev_unlock(wdev);
3138
3139 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003140}
3141
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003142static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3143{
3144 struct sk_buff *msg;
3145 void *hdr = NULL;
3146 struct nlattr *nl_reg_rules;
3147 unsigned int i;
3148 int err = -EINVAL;
3149
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003150 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003151
3152 if (!cfg80211_regdomain)
3153 goto out;
3154
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003155 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003156 if (!msg) {
3157 err = -ENOBUFS;
3158 goto out;
3159 }
3160
3161 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3162 NL80211_CMD_GET_REG);
3163 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003164 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003165
3166 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3167 cfg80211_regdomain->alpha2);
3168
3169 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3170 if (!nl_reg_rules)
3171 goto nla_put_failure;
3172
3173 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3174 struct nlattr *nl_reg_rule;
3175 const struct ieee80211_reg_rule *reg_rule;
3176 const struct ieee80211_freq_range *freq_range;
3177 const struct ieee80211_power_rule *power_rule;
3178
3179 reg_rule = &cfg80211_regdomain->reg_rules[i];
3180 freq_range = &reg_rule->freq_range;
3181 power_rule = &reg_rule->power_rule;
3182
3183 nl_reg_rule = nla_nest_start(msg, i);
3184 if (!nl_reg_rule)
3185 goto nla_put_failure;
3186
3187 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3188 reg_rule->flags);
3189 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3190 freq_range->start_freq_khz);
3191 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3192 freq_range->end_freq_khz);
3193 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3194 freq_range->max_bandwidth_khz);
3195 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3196 power_rule->max_antenna_gain);
3197 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3198 power_rule->max_eirp);
3199
3200 nla_nest_end(msg, nl_reg_rule);
3201 }
3202
3203 nla_nest_end(msg, nl_reg_rules);
3204
3205 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003206 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003207 goto out;
3208
3209nla_put_failure:
3210 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003211put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003212 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003213 err = -EMSGSIZE;
3214out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003215 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003216 return err;
3217}
3218
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003219static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3220{
3221 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3222 struct nlattr *nl_reg_rule;
3223 char *alpha2 = NULL;
3224 int rem_reg_rules = 0, r = 0;
3225 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3226 struct ieee80211_regdomain *rd = NULL;
3227
3228 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3229 return -EINVAL;
3230
3231 if (!info->attrs[NL80211_ATTR_REG_RULES])
3232 return -EINVAL;
3233
3234 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3235
3236 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3237 rem_reg_rules) {
3238 num_rules++;
3239 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003240 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003241 }
3242
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003243 mutex_lock(&cfg80211_mutex);
3244
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003245 if (!reg_is_valid_request(alpha2)) {
3246 r = -EINVAL;
3247 goto bad_reg;
3248 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003249
3250 size_of_regd = sizeof(struct ieee80211_regdomain) +
3251 (num_rules * sizeof(struct ieee80211_reg_rule));
3252
3253 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003254 if (!rd) {
3255 r = -ENOMEM;
3256 goto bad_reg;
3257 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003258
3259 rd->n_reg_rules = num_rules;
3260 rd->alpha2[0] = alpha2[0];
3261 rd->alpha2[1] = alpha2[1];
3262
3263 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3264 rem_reg_rules) {
3265 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3266 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3267 reg_rule_policy);
3268 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3269 if (r)
3270 goto bad_reg;
3271
3272 rule_idx++;
3273
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003274 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3275 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003276 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003277 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003278 }
3279
3280 BUG_ON(rule_idx != num_rules);
3281
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003282 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003283
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003284 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003285
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003286 return r;
3287
Johannes Bergd2372b32008-10-24 20:32:20 +02003288 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003289 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003290 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003291 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003292}
3293
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003294static int validate_scan_freqs(struct nlattr *freqs)
3295{
3296 struct nlattr *attr1, *attr2;
3297 int n_channels = 0, tmp1, tmp2;
3298
3299 nla_for_each_nested(attr1, freqs, tmp1) {
3300 n_channels++;
3301 /*
3302 * Some hardware has a limited channel list for
3303 * scanning, and it is pretty much nonsensical
3304 * to scan for a channel twice, so disallow that
3305 * and don't require drivers to check that the
3306 * channel list they get isn't longer than what
3307 * they can scan, as long as they can scan all
3308 * the channels they registered at once.
3309 */
3310 nla_for_each_nested(attr2, freqs, tmp2)
3311 if (attr1 != attr2 &&
3312 nla_get_u32(attr1) == nla_get_u32(attr2))
3313 return 0;
3314 }
3315
3316 return n_channels;
3317}
3318
Johannes Berg2a519312009-02-10 21:25:55 +01003319static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3320{
Johannes Berg4c476992010-10-04 21:36:35 +02003321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3322 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003323 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003324 struct nlattr *attr;
3325 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003326 int err, tmp, n_ssids = 0, n_channels, i;
Johannes Berg2a519312009-02-10 21:25:55 +01003327 enum ieee80211_band band;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003328 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003329
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003330 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3331 return -EINVAL;
3332
Johannes Berg79c97e92009-07-07 03:56:12 +02003333 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003334
Johannes Berg4c476992010-10-04 21:36:35 +02003335 if (!rdev->ops->scan)
3336 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003337
Johannes Berg4c476992010-10-04 21:36:35 +02003338 if (rdev->scan_req)
3339 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003340
3341 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003342 n_channels = validate_scan_freqs(
3343 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003344 if (!n_channels)
3345 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003346 } else {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003347 n_channels = 0;
3348
Johannes Berg2a519312009-02-10 21:25:55 +01003349 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3350 if (wiphy->bands[band])
3351 n_channels += wiphy->bands[band]->n_channels;
3352 }
3353
3354 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3355 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3356 n_ssids++;
3357
Johannes Berg4c476992010-10-04 21:36:35 +02003358 if (n_ssids > wiphy->max_scan_ssids)
3359 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003360
Jouni Malinen70692ad2009-02-16 19:39:13 +02003361 if (info->attrs[NL80211_ATTR_IE])
3362 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3363 else
3364 ie_len = 0;
3365
Johannes Berg4c476992010-10-04 21:36:35 +02003366 if (ie_len > wiphy->max_scan_ie_len)
3367 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003368
Johannes Berg2a519312009-02-10 21:25:55 +01003369 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003370 + sizeof(*request->ssids) * n_ssids
3371 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003372 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003373 if (!request)
3374 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003375
Johannes Berg2a519312009-02-10 21:25:55 +01003376 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003377 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003378 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003379 if (ie_len) {
3380 if (request->ssids)
3381 request->ie = (void *)(request->ssids + n_ssids);
3382 else
3383 request->ie = (void *)(request->channels + n_channels);
3384 }
Johannes Berg2a519312009-02-10 21:25:55 +01003385
Johannes Berg584991d2009-11-02 13:32:03 +01003386 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003387 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3388 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003389 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003390 struct ieee80211_channel *chan;
3391
3392 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3393
3394 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003395 err = -EINVAL;
3396 goto out_free;
3397 }
Johannes Berg584991d2009-11-02 13:32:03 +01003398
3399 /* ignore disabled channels */
3400 if (chan->flags & IEEE80211_CHAN_DISABLED)
3401 continue;
3402
3403 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003404 i++;
3405 }
3406 } else {
3407 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003408 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3409 int j;
3410 if (!wiphy->bands[band])
3411 continue;
3412 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003413 struct ieee80211_channel *chan;
3414
3415 chan = &wiphy->bands[band]->channels[j];
3416
3417 if (chan->flags & IEEE80211_CHAN_DISABLED)
3418 continue;
3419
3420 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003421 i++;
3422 }
3423 }
3424 }
3425
Johannes Berg584991d2009-11-02 13:32:03 +01003426 if (!i) {
3427 err = -EINVAL;
3428 goto out_free;
3429 }
3430
3431 request->n_channels = i;
3432
Johannes Berg2a519312009-02-10 21:25:55 +01003433 i = 0;
3434 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3435 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003436 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003437 err = -EINVAL;
3438 goto out_free;
3439 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003440 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003441 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003442 i++;
3443 }
3444 }
3445
Jouni Malinen70692ad2009-02-16 19:39:13 +02003446 if (info->attrs[NL80211_ATTR_IE]) {
3447 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003448 memcpy((void *)request->ie,
3449 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003450 request->ie_len);
3451 }
3452
Johannes Berg463d0182009-07-14 00:33:35 +02003453 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003454 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003455
Johannes Berg79c97e92009-07-07 03:56:12 +02003456 rdev->scan_req = request;
3457 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003458
Johannes Berg463d0182009-07-14 00:33:35 +02003459 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003460 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003461 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003462 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003463 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003464 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003465 kfree(request);
3466 }
Johannes Berg3b858752009-03-12 09:55:09 +01003467
Johannes Berg2a519312009-02-10 21:25:55 +01003468 return err;
3469}
3470
Luciano Coelho807f8a82011-05-11 17:09:35 +03003471static int nl80211_start_sched_scan(struct sk_buff *skb,
3472 struct genl_info *info)
3473{
3474 struct cfg80211_sched_scan_request *request;
3475 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3476 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003477 struct nlattr *attr;
3478 struct wiphy *wiphy;
3479 int err, tmp, n_ssids = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003480 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003481 enum ieee80211_band band;
3482 size_t ie_len;
3483
3484 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3485 !rdev->ops->sched_scan_start)
3486 return -EOPNOTSUPP;
3487
3488 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3489 return -EINVAL;
3490
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003491 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3492 return -EINVAL;
3493
3494 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3495 if (interval == 0)
3496 return -EINVAL;
3497
Luciano Coelho807f8a82011-05-11 17:09:35 +03003498 wiphy = &rdev->wiphy;
3499
3500 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3501 n_channels = validate_scan_freqs(
3502 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3503 if (!n_channels)
3504 return -EINVAL;
3505 } else {
3506 n_channels = 0;
3507
3508 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3509 if (wiphy->bands[band])
3510 n_channels += wiphy->bands[band]->n_channels;
3511 }
3512
3513 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3514 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3515 tmp)
3516 n_ssids++;
3517
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003518 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003519 return -EINVAL;
3520
3521 if (info->attrs[NL80211_ATTR_IE])
3522 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3523 else
3524 ie_len = 0;
3525
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003526 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003527 return -EINVAL;
3528
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003529 mutex_lock(&rdev->sched_scan_mtx);
3530
3531 if (rdev->sched_scan_req) {
3532 err = -EINPROGRESS;
3533 goto out;
3534 }
3535
Luciano Coelho807f8a82011-05-11 17:09:35 +03003536 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003537 + sizeof(*request->ssids) * n_ssids
3538 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003539 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003540 if (!request) {
3541 err = -ENOMEM;
3542 goto out;
3543 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003544
3545 if (n_ssids)
3546 request->ssids = (void *)&request->channels[n_channels];
3547 request->n_ssids = n_ssids;
3548 if (ie_len) {
3549 if (request->ssids)
3550 request->ie = (void *)(request->ssids + n_ssids);
3551 else
3552 request->ie = (void *)(request->channels + n_channels);
3553 }
3554
3555 i = 0;
3556 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3557 /* user specified, bail out if channel not found */
3558 nla_for_each_nested(attr,
3559 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3560 tmp) {
3561 struct ieee80211_channel *chan;
3562
3563 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3564
3565 if (!chan) {
3566 err = -EINVAL;
3567 goto out_free;
3568 }
3569
3570 /* ignore disabled channels */
3571 if (chan->flags & IEEE80211_CHAN_DISABLED)
3572 continue;
3573
3574 request->channels[i] = chan;
3575 i++;
3576 }
3577 } else {
3578 /* all channels */
3579 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3580 int j;
3581 if (!wiphy->bands[band])
3582 continue;
3583 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3584 struct ieee80211_channel *chan;
3585
3586 chan = &wiphy->bands[band]->channels[j];
3587
3588 if (chan->flags & IEEE80211_CHAN_DISABLED)
3589 continue;
3590
3591 request->channels[i] = chan;
3592 i++;
3593 }
3594 }
3595 }
3596
3597 if (!i) {
3598 err = -EINVAL;
3599 goto out_free;
3600 }
3601
3602 request->n_channels = i;
3603
3604 i = 0;
3605 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3606 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3607 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003608 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03003609 err = -EINVAL;
3610 goto out_free;
3611 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003612 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003613 memcpy(request->ssids[i].ssid, nla_data(attr),
3614 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03003615 i++;
3616 }
3617 }
3618
3619 if (info->attrs[NL80211_ATTR_IE]) {
3620 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3621 memcpy((void *)request->ie,
3622 nla_data(info->attrs[NL80211_ATTR_IE]),
3623 request->ie_len);
3624 }
3625
3626 request->dev = dev;
3627 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003628 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003629
3630 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3631 if (!err) {
3632 rdev->sched_scan_req = request;
3633 nl80211_send_sched_scan(rdev, dev,
3634 NL80211_CMD_START_SCHED_SCAN);
3635 goto out;
3636 }
3637
3638out_free:
3639 kfree(request);
3640out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003641 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003642 return err;
3643}
3644
3645static int nl80211_stop_sched_scan(struct sk_buff *skb,
3646 struct genl_info *info)
3647{
3648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003649 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003650
3651 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3652 !rdev->ops->sched_scan_stop)
3653 return -EOPNOTSUPP;
3654
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003655 mutex_lock(&rdev->sched_scan_mtx);
3656 err = __cfg80211_stop_sched_scan(rdev, false);
3657 mutex_unlock(&rdev->sched_scan_mtx);
3658
3659 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003660}
3661
Johannes Berg9720bb32011-06-21 09:45:33 +02003662static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3663 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003664 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003665 struct wireless_dev *wdev,
3666 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003667{
Johannes Berg48ab9052009-07-10 18:42:31 +02003668 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003669 void *hdr;
3670 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003671 int i;
3672
3673 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003674
Johannes Berg9720bb32011-06-21 09:45:33 +02003675 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003676 NL80211_CMD_NEW_SCAN_RESULTS);
3677 if (!hdr)
3678 return -1;
3679
Johannes Berg9720bb32011-06-21 09:45:33 +02003680 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
3681
Johannes Bergf5ea9122009-08-07 16:17:38 +02003682 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003683 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003684
3685 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3686 if (!bss)
3687 goto nla_put_failure;
3688 if (!is_zero_ether_addr(res->bssid))
3689 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3690 if (res->information_elements && res->len_information_elements)
3691 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3692 res->len_information_elements,
3693 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003694 if (res->beacon_ies && res->len_beacon_ies &&
3695 res->beacon_ies != res->information_elements)
3696 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3697 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003698 if (res->tsf)
3699 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3700 if (res->beacon_interval)
3701 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3702 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3703 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003704 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3705 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003706
Johannes Berg77965c92009-02-18 18:45:06 +01003707 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003708 case CFG80211_SIGNAL_TYPE_MBM:
3709 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3710 break;
3711 case CFG80211_SIGNAL_TYPE_UNSPEC:
3712 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3713 break;
3714 default:
3715 break;
3716 }
3717
Johannes Berg48ab9052009-07-10 18:42:31 +02003718 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003719 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003720 case NL80211_IFTYPE_STATION:
3721 if (intbss == wdev->current_bss)
3722 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3723 NL80211_BSS_STATUS_ASSOCIATED);
3724 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3725 if (intbss != wdev->auth_bsses[i])
3726 continue;
3727 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3728 NL80211_BSS_STATUS_AUTHENTICATED);
3729 break;
3730 }
3731 break;
3732 case NL80211_IFTYPE_ADHOC:
3733 if (intbss == wdev->current_bss)
3734 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3735 NL80211_BSS_STATUS_IBSS_JOINED);
3736 break;
3737 default:
3738 break;
3739 }
3740
Johannes Berg2a519312009-02-10 21:25:55 +01003741 nla_nest_end(msg, bss);
3742
3743 return genlmsg_end(msg, hdr);
3744
3745 nla_put_failure:
3746 genlmsg_cancel(msg, hdr);
3747 return -EMSGSIZE;
3748}
3749
3750static int nl80211_dump_scan(struct sk_buff *skb,
3751 struct netlink_callback *cb)
3752{
Johannes Berg48ab9052009-07-10 18:42:31 +02003753 struct cfg80211_registered_device *rdev;
3754 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01003755 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02003756 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01003757 int start = cb->args[1], idx = 0;
3758 int err;
3759
Johannes Berg67748892010-10-04 21:14:06 +02003760 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
3761 if (err)
3762 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01003763
Johannes Berg48ab9052009-07-10 18:42:31 +02003764 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01003765
Johannes Berg48ab9052009-07-10 18:42:31 +02003766 wdev_lock(wdev);
3767 spin_lock_bh(&rdev->bss_lock);
3768 cfg80211_bss_expire(rdev);
3769
Johannes Berg9720bb32011-06-21 09:45:33 +02003770 cb->seq = rdev->bss_generation;
3771
Johannes Berg48ab9052009-07-10 18:42:31 +02003772 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01003773 if (++idx <= start)
3774 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02003775 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01003776 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02003777 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01003778 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02003779 break;
Johannes Berg2a519312009-02-10 21:25:55 +01003780 }
3781 }
3782
Johannes Berg48ab9052009-07-10 18:42:31 +02003783 spin_unlock_bh(&rdev->bss_lock);
3784 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003785
3786 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02003787 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003788
Johannes Berg67748892010-10-04 21:14:06 +02003789 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01003790}
3791
Holger Schurig61fa7132009-11-11 12:25:40 +01003792static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
3793 int flags, struct net_device *dev,
3794 struct survey_info *survey)
3795{
3796 void *hdr;
3797 struct nlattr *infoattr;
3798
Holger Schurig61fa7132009-11-11 12:25:40 +01003799 hdr = nl80211hdr_put(msg, pid, seq, flags,
3800 NL80211_CMD_NEW_SURVEY_RESULTS);
3801 if (!hdr)
3802 return -ENOMEM;
3803
3804 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3805
3806 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
3807 if (!infoattr)
3808 goto nla_put_failure;
3809
3810 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
3811 survey->channel->center_freq);
3812 if (survey->filled & SURVEY_INFO_NOISE_DBM)
3813 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
3814 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02003815 if (survey->filled & SURVEY_INFO_IN_USE)
3816 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02003817 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
3818 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
3819 survey->channel_time);
3820 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
3821 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
3822 survey->channel_time_busy);
3823 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
3824 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
3825 survey->channel_time_ext_busy);
3826 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
3827 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
3828 survey->channel_time_rx);
3829 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
3830 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
3831 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01003832
3833 nla_nest_end(msg, infoattr);
3834
3835 return genlmsg_end(msg, hdr);
3836
3837 nla_put_failure:
3838 genlmsg_cancel(msg, hdr);
3839 return -EMSGSIZE;
3840}
3841
3842static int nl80211_dump_survey(struct sk_buff *skb,
3843 struct netlink_callback *cb)
3844{
3845 struct survey_info survey;
3846 struct cfg80211_registered_device *dev;
3847 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01003848 int survey_idx = cb->args[1];
3849 int res;
3850
Johannes Berg67748892010-10-04 21:14:06 +02003851 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3852 if (res)
3853 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01003854
3855 if (!dev->ops->dump_survey) {
3856 res = -EOPNOTSUPP;
3857 goto out_err;
3858 }
3859
3860 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07003861 struct ieee80211_channel *chan;
3862
Holger Schurig61fa7132009-11-11 12:25:40 +01003863 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
3864 &survey);
3865 if (res == -ENOENT)
3866 break;
3867 if (res)
3868 goto out_err;
3869
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07003870 /* Survey without a channel doesn't make sense */
3871 if (!survey.channel) {
3872 res = -EINVAL;
3873 goto out;
3874 }
3875
3876 chan = ieee80211_get_channel(&dev->wiphy,
3877 survey.channel->center_freq);
3878 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
3879 survey_idx++;
3880 continue;
3881 }
3882
Holger Schurig61fa7132009-11-11 12:25:40 +01003883 if (nl80211_send_survey(skb,
3884 NETLINK_CB(cb->skb).pid,
3885 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3886 netdev,
3887 &survey) < 0)
3888 goto out;
3889 survey_idx++;
3890 }
3891
3892 out:
3893 cb->args[1] = survey_idx;
3894 res = skb->len;
3895 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003896 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01003897 return res;
3898}
3899
Jouni Malinen255e7372009-03-20 21:21:17 +02003900static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
3901{
Samuel Ortizb23aa672009-07-01 21:26:54 +02003902 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02003903}
3904
Samuel Ortizb23aa672009-07-01 21:26:54 +02003905static bool nl80211_valid_wpa_versions(u32 wpa_versions)
3906{
3907 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
3908 NL80211_WPA_VERSION_2));
3909}
3910
3911static bool nl80211_valid_akm_suite(u32 akm)
3912{
3913 return akm == WLAN_AKM_SUITE_8021X ||
3914 akm == WLAN_AKM_SUITE_PSK;
3915}
3916
3917static bool nl80211_valid_cipher_suite(u32 cipher)
3918{
3919 return cipher == WLAN_CIPHER_SUITE_WEP40 ||
3920 cipher == WLAN_CIPHER_SUITE_WEP104 ||
3921 cipher == WLAN_CIPHER_SUITE_TKIP ||
3922 cipher == WLAN_CIPHER_SUITE_CCMP ||
3923 cipher == WLAN_CIPHER_SUITE_AES_CMAC;
3924}
3925
3926
Jouni Malinen636a5d32009-03-19 13:39:22 +02003927static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3928{
Johannes Berg4c476992010-10-04 21:36:35 +02003929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3930 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02003931 struct ieee80211_channel *chan;
3932 const u8 *bssid, *ssid, *ie = NULL;
3933 int err, ssid_len, ie_len = 0;
3934 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02003935 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03003936 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003937
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003938 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3939 return -EINVAL;
3940
3941 if (!info->attrs[NL80211_ATTR_MAC])
3942 return -EINVAL;
3943
Jouni Malinen17780922009-03-27 20:52:47 +02003944 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
3945 return -EINVAL;
3946
Johannes Berg19957bb2009-07-02 17:20:43 +02003947 if (!info->attrs[NL80211_ATTR_SSID])
3948 return -EINVAL;
3949
3950 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
3951 return -EINVAL;
3952
Johannes Bergfffd0932009-07-08 14:22:54 +02003953 err = nl80211_parse_key(info, &key);
3954 if (err)
3955 return err;
3956
3957 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02003958 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
3959 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003960 if (!key.p.key || !key.p.key_len)
3961 return -EINVAL;
3962 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
3963 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
3964 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
3965 key.p.key_len != WLAN_KEY_LEN_WEP104))
3966 return -EINVAL;
3967 if (key.idx > 4)
3968 return -EINVAL;
3969 } else {
3970 key.p.key_len = 0;
3971 key.p.key = NULL;
3972 }
3973
Johannes Bergafea0b72010-08-10 09:46:42 +02003974 if (key.idx >= 0) {
3975 int i;
3976 bool ok = false;
3977 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
3978 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
3979 ok = true;
3980 break;
3981 }
3982 }
Johannes Berg4c476992010-10-04 21:36:35 +02003983 if (!ok)
3984 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02003985 }
3986
Johannes Berg4c476992010-10-04 21:36:35 +02003987 if (!rdev->ops->auth)
3988 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003989
Johannes Berg074ac8d2010-09-16 14:58:22 +02003990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02003991 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
3992 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003993
Johannes Berg19957bb2009-07-02 17:20:43 +02003994 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02003995 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02003996 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02003997 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
3998 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02003999
Johannes Berg19957bb2009-07-02 17:20:43 +02004000 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4001 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4002
4003 if (info->attrs[NL80211_ATTR_IE]) {
4004 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4005 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4006 }
4007
4008 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004009 if (!nl80211_valid_auth_type(auth_type))
4010 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004011
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004012 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4013
Johannes Berg4c476992010-10-04 21:36:35 +02004014 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4015 ssid, ssid_len, ie, ie_len,
4016 key.p.key, key.p.key_len, key.idx,
4017 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004018}
4019
Johannes Bergc0692b82010-08-27 14:26:53 +03004020static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4021 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004022 struct cfg80211_crypto_settings *settings,
4023 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004024{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004025 memset(settings, 0, sizeof(*settings));
4026
Samuel Ortizb23aa672009-07-01 21:26:54 +02004027 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4028
Johannes Bergc0692b82010-08-27 14:26:53 +03004029 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4030 u16 proto;
4031 proto = nla_get_u16(
4032 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4033 settings->control_port_ethertype = cpu_to_be16(proto);
4034 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4035 proto != ETH_P_PAE)
4036 return -EINVAL;
4037 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4038 settings->control_port_no_encrypt = true;
4039 } else
4040 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4041
Samuel Ortizb23aa672009-07-01 21:26:54 +02004042 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4043 void *data;
4044 int len, i;
4045
4046 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4047 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4048 settings->n_ciphers_pairwise = len / sizeof(u32);
4049
4050 if (len % sizeof(u32))
4051 return -EINVAL;
4052
Johannes Berg3dc27d22009-07-02 21:36:37 +02004053 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004054 return -EINVAL;
4055
4056 memcpy(settings->ciphers_pairwise, data, len);
4057
4058 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4059 if (!nl80211_valid_cipher_suite(
4060 settings->ciphers_pairwise[i]))
4061 return -EINVAL;
4062 }
4063
4064 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4065 settings->cipher_group =
4066 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
4067 if (!nl80211_valid_cipher_suite(settings->cipher_group))
4068 return -EINVAL;
4069 }
4070
4071 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4072 settings->wpa_versions =
4073 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4074 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4075 return -EINVAL;
4076 }
4077
4078 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4079 void *data;
4080 int len, i;
4081
4082 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4083 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4084 settings->n_akm_suites = len / sizeof(u32);
4085
4086 if (len % sizeof(u32))
4087 return -EINVAL;
4088
4089 memcpy(settings->akm_suites, data, len);
4090
4091 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4092 if (!nl80211_valid_akm_suite(settings->akm_suites[i]))
4093 return -EINVAL;
4094 }
4095
4096 return 0;
4097}
4098
Jouni Malinen636a5d32009-03-19 13:39:22 +02004099static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4100{
Johannes Berg4c476992010-10-04 21:36:35 +02004101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4102 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004103 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004104 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004105 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004106 int err, ssid_len, ie_len = 0;
4107 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004108
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004109 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4110 return -EINVAL;
4111
4112 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004113 !info->attrs[NL80211_ATTR_SSID] ||
4114 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004115 return -EINVAL;
4116
Johannes Berg4c476992010-10-04 21:36:35 +02004117 if (!rdev->ops->assoc)
4118 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004119
Johannes Berg074ac8d2010-09-16 14:58:22 +02004120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004121 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4122 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004123
Johannes Berg19957bb2009-07-02 17:20:43 +02004124 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004125
Johannes Berg19957bb2009-07-02 17:20:43 +02004126 chan = ieee80211_get_channel(&rdev->wiphy,
4127 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004128 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4129 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004130
Johannes Berg19957bb2009-07-02 17:20:43 +02004131 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4132 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004133
4134 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004135 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4136 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004137 }
4138
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004139 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004140 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004141 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004142 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004143 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004144 else if (mfp != NL80211_MFP_NO)
4145 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004146 }
4147
Johannes Berg3e5d7642009-07-07 14:37:26 +02004148 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4149 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4150
Johannes Bergc0692b82010-08-27 14:26:53 +03004151 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004152 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004153 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4154 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02004155 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004156
Jouni Malinen636a5d32009-03-19 13:39:22 +02004157 return err;
4158}
4159
4160static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4161{
Johannes Berg4c476992010-10-04 21:36:35 +02004162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4163 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004164 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004165 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004166 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004167 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004168
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004169 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4170 return -EINVAL;
4171
4172 if (!info->attrs[NL80211_ATTR_MAC])
4173 return -EINVAL;
4174
4175 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4176 return -EINVAL;
4177
Johannes Berg4c476992010-10-04 21:36:35 +02004178 if (!rdev->ops->deauth)
4179 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004180
Johannes Berg074ac8d2010-09-16 14:58:22 +02004181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4183 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004184
Johannes Berg19957bb2009-07-02 17:20:43 +02004185 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004186
Johannes Berg19957bb2009-07-02 17:20:43 +02004187 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4188 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004189 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004190 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004191 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004192
4193 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004194 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4195 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004196 }
4197
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004198 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4199
Johannes Berg4c476992010-10-04 21:36:35 +02004200 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4201 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004202}
4203
4204static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4205{
Johannes Berg4c476992010-10-04 21:36:35 +02004206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4207 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004208 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004209 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004210 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004211 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004212
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004213 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4214 return -EINVAL;
4215
4216 if (!info->attrs[NL80211_ATTR_MAC])
4217 return -EINVAL;
4218
4219 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4220 return -EINVAL;
4221
Johannes Berg4c476992010-10-04 21:36:35 +02004222 if (!rdev->ops->disassoc)
4223 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004224
Johannes Berg074ac8d2010-09-16 14:58:22 +02004225 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004226 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4227 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004228
Johannes Berg19957bb2009-07-02 17:20:43 +02004229 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004230
Johannes Berg19957bb2009-07-02 17:20:43 +02004231 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4232 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004233 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004234 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004235 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004236
4237 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004238 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4239 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004240 }
4241
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004242 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4243
Johannes Berg4c476992010-10-04 21:36:35 +02004244 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4245 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004246}
4247
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004248static bool
4249nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4250 int mcast_rate[IEEE80211_NUM_BANDS],
4251 int rateval)
4252{
4253 struct wiphy *wiphy = &rdev->wiphy;
4254 bool found = false;
4255 int band, i;
4256
4257 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4258 struct ieee80211_supported_band *sband;
4259
4260 sband = wiphy->bands[band];
4261 if (!sband)
4262 continue;
4263
4264 for (i = 0; i < sband->n_bitrates; i++) {
4265 if (sband->bitrates[i].bitrate == rateval) {
4266 mcast_rate[band] = i + 1;
4267 found = true;
4268 break;
4269 }
4270 }
4271 }
4272
4273 return found;
4274}
4275
Johannes Berg04a773a2009-04-19 21:24:32 +02004276static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4277{
Johannes Berg4c476992010-10-04 21:36:35 +02004278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4279 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004280 struct cfg80211_ibss_params ibss;
4281 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004282 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004283 int err;
4284
Johannes Berg8e30bc52009-04-22 17:45:38 +02004285 memset(&ibss, 0, sizeof(ibss));
4286
Johannes Berg04a773a2009-04-19 21:24:32 +02004287 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4288 return -EINVAL;
4289
4290 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4291 !info->attrs[NL80211_ATTR_SSID] ||
4292 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4293 return -EINVAL;
4294
Johannes Berg8e30bc52009-04-22 17:45:38 +02004295 ibss.beacon_interval = 100;
4296
4297 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4298 ibss.beacon_interval =
4299 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4300 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4301 return -EINVAL;
4302 }
4303
Johannes Berg4c476992010-10-04 21:36:35 +02004304 if (!rdev->ops->join_ibss)
4305 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004306
Johannes Berg4c476992010-10-04 21:36:35 +02004307 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4308 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004309
Johannes Berg79c97e92009-07-07 03:56:12 +02004310 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004311
4312 if (info->attrs[NL80211_ATTR_MAC])
4313 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4314 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4315 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4316
4317 if (info->attrs[NL80211_ATTR_IE]) {
4318 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4319 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4320 }
4321
4322 ibss.channel = ieee80211_get_channel(wiphy,
4323 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4324 if (!ibss.channel ||
4325 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004326 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4327 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004328
4329 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004330 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004331
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004332 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4333 u8 *rates =
4334 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4335 int n_rates =
4336 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4337 struct ieee80211_supported_band *sband =
4338 wiphy->bands[ibss.channel->band];
4339 int i, j;
4340
Johannes Berg4c476992010-10-04 21:36:35 +02004341 if (n_rates == 0)
4342 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004343
4344 for (i = 0; i < n_rates; i++) {
4345 int rate = (rates[i] & 0x7f) * 5;
4346 bool found = false;
4347
4348 for (j = 0; j < sband->n_bitrates; j++) {
4349 if (sband->bitrates[j].bitrate == rate) {
4350 found = true;
4351 ibss.basic_rates |= BIT(j);
4352 break;
4353 }
4354 }
Johannes Berg4c476992010-10-04 21:36:35 +02004355 if (!found)
4356 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004357 }
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004358 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004359
4360 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4361 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4362 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4363 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004364
Johannes Berg4c476992010-10-04 21:36:35 +02004365 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4366 connkeys = nl80211_parse_connkeys(rdev,
4367 info->attrs[NL80211_ATTR_KEYS]);
4368 if (IS_ERR(connkeys))
4369 return PTR_ERR(connkeys);
4370 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004371
Johannes Berg4c476992010-10-04 21:36:35 +02004372 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004373 if (err)
4374 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004375 return err;
4376}
4377
4378static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4379{
Johannes Berg4c476992010-10-04 21:36:35 +02004380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4381 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004382
Johannes Berg4c476992010-10-04 21:36:35 +02004383 if (!rdev->ops->leave_ibss)
4384 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004385
Johannes Berg4c476992010-10-04 21:36:35 +02004386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4387 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004388
Johannes Berg4c476992010-10-04 21:36:35 +02004389 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004390}
4391
Johannes Bergaff89a92009-07-01 21:26:51 +02004392#ifdef CONFIG_NL80211_TESTMODE
4393static struct genl_multicast_group nl80211_testmode_mcgrp = {
4394 .name = "testmode",
4395};
4396
4397static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4398{
Johannes Berg4c476992010-10-04 21:36:35 +02004399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004400 int err;
4401
4402 if (!info->attrs[NL80211_ATTR_TESTDATA])
4403 return -EINVAL;
4404
Johannes Bergaff89a92009-07-01 21:26:51 +02004405 err = -EOPNOTSUPP;
4406 if (rdev->ops->testmode_cmd) {
4407 rdev->testmode_info = info;
4408 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4409 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4410 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4411 rdev->testmode_info = NULL;
4412 }
4413
Johannes Bergaff89a92009-07-01 21:26:51 +02004414 return err;
4415}
4416
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004417static int nl80211_testmode_dump(struct sk_buff *skb,
4418 struct netlink_callback *cb)
4419{
4420 struct cfg80211_registered_device *dev;
4421 int err;
4422 long phy_idx;
4423 void *data = NULL;
4424 int data_len = 0;
4425
4426 if (cb->args[0]) {
4427 /*
4428 * 0 is a valid index, but not valid for args[0],
4429 * so we need to offset by 1.
4430 */
4431 phy_idx = cb->args[0] - 1;
4432 } else {
4433 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4434 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4435 nl80211_policy);
4436 if (err)
4437 return err;
4438 if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY])
4439 return -EINVAL;
4440 phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4441 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4442 cb->args[1] =
4443 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4444 }
4445
4446 if (cb->args[1]) {
4447 data = nla_data((void *)cb->args[1]);
4448 data_len = nla_len((void *)cb->args[1]);
4449 }
4450
4451 mutex_lock(&cfg80211_mutex);
4452 dev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4453 if (!dev) {
4454 mutex_unlock(&cfg80211_mutex);
4455 return -ENOENT;
4456 }
4457 cfg80211_lock_rdev(dev);
4458 mutex_unlock(&cfg80211_mutex);
4459
4460 if (!dev->ops->testmode_dump) {
4461 err = -EOPNOTSUPP;
4462 goto out_err;
4463 }
4464
4465 while (1) {
4466 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4467 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4468 NL80211_CMD_TESTMODE);
4469 struct nlattr *tmdata;
4470
4471 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) {
4472 genlmsg_cancel(skb, hdr);
4473 break;
4474 }
4475
4476 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4477 if (!tmdata) {
4478 genlmsg_cancel(skb, hdr);
4479 break;
4480 }
4481 err = dev->ops->testmode_dump(&dev->wiphy, skb, cb,
4482 data, data_len);
4483 nla_nest_end(skb, tmdata);
4484
4485 if (err == -ENOBUFS || err == -ENOENT) {
4486 genlmsg_cancel(skb, hdr);
4487 break;
4488 } else if (err) {
4489 genlmsg_cancel(skb, hdr);
4490 goto out_err;
4491 }
4492
4493 genlmsg_end(skb, hdr);
4494 }
4495
4496 err = skb->len;
4497 /* see above */
4498 cb->args[0] = phy_idx + 1;
4499 out_err:
4500 cfg80211_unlock_rdev(dev);
4501 return err;
4502}
4503
Johannes Bergaff89a92009-07-01 21:26:51 +02004504static struct sk_buff *
4505__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4506 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4507{
4508 struct sk_buff *skb;
4509 void *hdr;
4510 struct nlattr *data;
4511
4512 skb = nlmsg_new(approxlen + 100, gfp);
4513 if (!skb)
4514 return NULL;
4515
4516 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4517 if (!hdr) {
4518 kfree_skb(skb);
4519 return NULL;
4520 }
4521
4522 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4523 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4524
4525 ((void **)skb->cb)[0] = rdev;
4526 ((void **)skb->cb)[1] = hdr;
4527 ((void **)skb->cb)[2] = data;
4528
4529 return skb;
4530
4531 nla_put_failure:
4532 kfree_skb(skb);
4533 return NULL;
4534}
4535
4536struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4537 int approxlen)
4538{
4539 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4540
4541 if (WARN_ON(!rdev->testmode_info))
4542 return NULL;
4543
4544 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4545 rdev->testmode_info->snd_pid,
4546 rdev->testmode_info->snd_seq,
4547 GFP_KERNEL);
4548}
4549EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4550
4551int cfg80211_testmode_reply(struct sk_buff *skb)
4552{
4553 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4554 void *hdr = ((void **)skb->cb)[1];
4555 struct nlattr *data = ((void **)skb->cb)[2];
4556
4557 if (WARN_ON(!rdev->testmode_info)) {
4558 kfree_skb(skb);
4559 return -EINVAL;
4560 }
4561
4562 nla_nest_end(skb, data);
4563 genlmsg_end(skb, hdr);
4564 return genlmsg_reply(skb, rdev->testmode_info);
4565}
4566EXPORT_SYMBOL(cfg80211_testmode_reply);
4567
4568struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4569 int approxlen, gfp_t gfp)
4570{
4571 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4572
4573 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4574}
4575EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4576
4577void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4578{
4579 void *hdr = ((void **)skb->cb)[1];
4580 struct nlattr *data = ((void **)skb->cb)[2];
4581
4582 nla_nest_end(skb, data);
4583 genlmsg_end(skb, hdr);
4584 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4585}
4586EXPORT_SYMBOL(cfg80211_testmode_event);
4587#endif
4588
Samuel Ortizb23aa672009-07-01 21:26:54 +02004589static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4590{
Johannes Berg4c476992010-10-04 21:36:35 +02004591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4592 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004593 struct cfg80211_connect_params connect;
4594 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004595 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004596 int err;
4597
4598 memset(&connect, 0, sizeof(connect));
4599
4600 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4601 return -EINVAL;
4602
4603 if (!info->attrs[NL80211_ATTR_SSID] ||
4604 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4605 return -EINVAL;
4606
4607 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4608 connect.auth_type =
4609 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4610 if (!nl80211_valid_auth_type(connect.auth_type))
4611 return -EINVAL;
4612 } else
4613 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4614
4615 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4616
Johannes Bergc0692b82010-08-27 14:26:53 +03004617 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004618 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004619 if (err)
4620 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004621
Johannes Berg074ac8d2010-09-16 14:58:22 +02004622 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004623 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4624 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004625
Johannes Berg79c97e92009-07-07 03:56:12 +02004626 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004627
Samuel Ortizb23aa672009-07-01 21:26:54 +02004628 if (info->attrs[NL80211_ATTR_MAC])
4629 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4630 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4631 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4632
4633 if (info->attrs[NL80211_ATTR_IE]) {
4634 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4635 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4636 }
4637
4638 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4639 connect.channel =
4640 ieee80211_get_channel(wiphy,
4641 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4642 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004643 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4644 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004645 }
4646
Johannes Bergfffd0932009-07-08 14:22:54 +02004647 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4648 connkeys = nl80211_parse_connkeys(rdev,
4649 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004650 if (IS_ERR(connkeys))
4651 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004652 }
4653
4654 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004655 if (err)
4656 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004657 return err;
4658}
4659
4660static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4661{
Johannes Berg4c476992010-10-04 21:36:35 +02004662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4663 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004664 u16 reason;
4665
4666 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4667 reason = WLAN_REASON_DEAUTH_LEAVING;
4668 else
4669 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4670
4671 if (reason == 0)
4672 return -EINVAL;
4673
Johannes Berg074ac8d2010-09-16 14:58:22 +02004674 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004675 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4676 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004677
Johannes Berg4c476992010-10-04 21:36:35 +02004678 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004679}
4680
Johannes Berg463d0182009-07-14 00:33:35 +02004681static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4682{
Johannes Berg4c476992010-10-04 21:36:35 +02004683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004684 struct net *net;
4685 int err;
4686 u32 pid;
4687
4688 if (!info->attrs[NL80211_ATTR_PID])
4689 return -EINVAL;
4690
4691 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4692
Johannes Berg463d0182009-07-14 00:33:35 +02004693 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004694 if (IS_ERR(net))
4695 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004696
4697 err = 0;
4698
4699 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004700 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4701 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004702
Johannes Berg463d0182009-07-14 00:33:35 +02004703 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004704 return err;
4705}
4706
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004707static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4708{
Johannes Berg4c476992010-10-04 21:36:35 +02004709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004710 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4711 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004712 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004713 struct cfg80211_pmksa pmksa;
4714
4715 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4716
4717 if (!info->attrs[NL80211_ATTR_MAC])
4718 return -EINVAL;
4719
4720 if (!info->attrs[NL80211_ATTR_PMKID])
4721 return -EINVAL;
4722
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004723 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4724 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4725
Johannes Berg074ac8d2010-09-16 14:58:22 +02004726 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004727 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4728 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004729
4730 switch (info->genlhdr->cmd) {
4731 case NL80211_CMD_SET_PMKSA:
4732 rdev_ops = rdev->ops->set_pmksa;
4733 break;
4734 case NL80211_CMD_DEL_PMKSA:
4735 rdev_ops = rdev->ops->del_pmksa;
4736 break;
4737 default:
4738 WARN_ON(1);
4739 break;
4740 }
4741
Johannes Berg4c476992010-10-04 21:36:35 +02004742 if (!rdev_ops)
4743 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004744
Johannes Berg4c476992010-10-04 21:36:35 +02004745 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004746}
4747
4748static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4749{
Johannes Berg4c476992010-10-04 21:36:35 +02004750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4751 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004752
Johannes Berg074ac8d2010-09-16 14:58:22 +02004753 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004754 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4755 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004756
Johannes Berg4c476992010-10-04 21:36:35 +02004757 if (!rdev->ops->flush_pmksa)
4758 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004759
Johannes Berg4c476992010-10-04 21:36:35 +02004760 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004761}
4762
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004763static int nl80211_remain_on_channel(struct sk_buff *skb,
4764 struct genl_info *info)
4765{
Johannes Berg4c476992010-10-04 21:36:35 +02004766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4767 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004768 struct ieee80211_channel *chan;
4769 struct sk_buff *msg;
4770 void *hdr;
4771 u64 cookie;
4772 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
4773 u32 freq, duration;
4774 int err;
4775
4776 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4777 !info->attrs[NL80211_ATTR_DURATION])
4778 return -EINVAL;
4779
4780 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
4781
4782 /*
4783 * We should be on that channel for at least one jiffie,
4784 * and more than 5 seconds seems excessive.
4785 */
Johannes Berga2939112010-12-14 17:54:28 +01004786 if (!duration || !msecs_to_jiffies(duration) ||
4787 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004788 return -EINVAL;
4789
Johannes Berg4c476992010-10-04 21:36:35 +02004790 if (!rdev->ops->remain_on_channel)
4791 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004792
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004793 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4794 channel_type = nla_get_u32(
4795 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4796 if (channel_type != NL80211_CHAN_NO_HT &&
4797 channel_type != NL80211_CHAN_HT20 &&
4798 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02004799 channel_type != NL80211_CHAN_HT40MINUS)
4800 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004801 }
4802
4803 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
4804 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02004805 if (chan == NULL)
4806 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004807
4808 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004809 if (!msg)
4810 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004811
4812 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
4813 NL80211_CMD_REMAIN_ON_CHANNEL);
4814
4815 if (IS_ERR(hdr)) {
4816 err = PTR_ERR(hdr);
4817 goto free_msg;
4818 }
4819
4820 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
4821 channel_type, duration, &cookie);
4822
4823 if (err)
4824 goto free_msg;
4825
4826 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
4827
4828 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004829
4830 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004831
4832 nla_put_failure:
4833 err = -ENOBUFS;
4834 free_msg:
4835 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004836 return err;
4837}
4838
4839static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
4840 struct genl_info *info)
4841{
Johannes Berg4c476992010-10-04 21:36:35 +02004842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4843 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004844 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004845
4846 if (!info->attrs[NL80211_ATTR_COOKIE])
4847 return -EINVAL;
4848
Johannes Berg4c476992010-10-04 21:36:35 +02004849 if (!rdev->ops->cancel_remain_on_channel)
4850 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004851
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004852 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
4853
Johannes Berg4c476992010-10-04 21:36:35 +02004854 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01004855}
4856
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004857static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4858 u8 *rates, u8 rates_len)
4859{
4860 u8 i;
4861 u32 mask = 0;
4862
4863 for (i = 0; i < rates_len; i++) {
4864 int rate = (rates[i] & 0x7f) * 5;
4865 int ridx;
4866 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4867 struct ieee80211_rate *srate =
4868 &sband->bitrates[ridx];
4869 if (rate == srate->bitrate) {
4870 mask |= 1 << ridx;
4871 break;
4872 }
4873 }
4874 if (ridx == sband->n_bitrates)
4875 return 0; /* rate not found */
4876 }
4877
4878 return mask;
4879}
4880
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004881static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004882 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4883 .len = NL80211_MAX_SUPP_RATES },
4884};
4885
4886static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
4887 struct genl_info *info)
4888{
4889 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02004890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004891 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02004892 int rem, i;
4893 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004894 struct nlattr *tx_rates;
4895 struct ieee80211_supported_band *sband;
4896
4897 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
4898 return -EINVAL;
4899
Johannes Berg4c476992010-10-04 21:36:35 +02004900 if (!rdev->ops->set_bitrate_mask)
4901 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004902
4903 memset(&mask, 0, sizeof(mask));
4904 /* Default to all rates enabled */
4905 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
4906 sband = rdev->wiphy.bands[i];
4907 mask.control[i].legacy =
4908 sband ? (1 << sband->n_bitrates) - 1 : 0;
4909 }
4910
4911 /*
4912 * The nested attribute uses enum nl80211_band as the index. This maps
4913 * directly to the enum ieee80211_band values used in cfg80211.
4914 */
4915 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
4916 {
4917 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02004918 if (band < 0 || band >= IEEE80211_NUM_BANDS)
4919 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004920 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02004921 if (sband == NULL)
4922 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004923 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
4924 nla_len(tx_rates), nl80211_txattr_policy);
4925 if (tb[NL80211_TXRATE_LEGACY]) {
4926 mask.control[band].legacy = rateset_to_mask(
4927 sband,
4928 nla_data(tb[NL80211_TXRATE_LEGACY]),
4929 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02004930 if (mask.control[band].legacy == 0)
4931 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004932 }
4933 }
4934
Johannes Berg4c476992010-10-04 21:36:35 +02004935 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02004936}
4937
Johannes Berg2e161f72010-08-12 15:38:38 +02004938static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004939{
Johannes Berg4c476992010-10-04 21:36:35 +02004940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4941 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02004942 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02004943
4944 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
4945 return -EINVAL;
4946
Johannes Berg2e161f72010-08-12 15:38:38 +02004947 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
4948 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02004949
Johannes Berg9d38d852010-06-09 17:20:33 +02004950 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004951 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004952 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4953 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4954 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08004955 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004956 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4957 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004958
4959 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02004960 if (!rdev->ops->mgmt_tx)
4961 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004962
Johannes Berg4c476992010-10-04 21:36:35 +02004963 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02004964 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02004965 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
4966 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02004967}
4968
Johannes Berg2e161f72010-08-12 15:38:38 +02004969static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02004970{
Johannes Berg4c476992010-10-04 21:36:35 +02004971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4972 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02004973 struct ieee80211_channel *chan;
4974 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02004975 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02004976 u32 freq;
4977 int err;
4978 void *hdr;
4979 u64 cookie;
4980 struct sk_buff *msg;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01004981 unsigned int wait = 0;
4982 bool offchan;
Jouni Malinen026331c2010-02-15 12:53:10 +02004983
4984 if (!info->attrs[NL80211_ATTR_FRAME] ||
4985 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4986 return -EINVAL;
4987
Johannes Berg4c476992010-10-04 21:36:35 +02004988 if (!rdev->ops->mgmt_tx)
4989 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004990
Johannes Berg9d38d852010-06-09 17:20:33 +02004991 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004992 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02004993 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
4994 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4995 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08004996 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004997 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4998 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02004999
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005000 if (info->attrs[NL80211_ATTR_DURATION]) {
5001 if (!rdev->ops->mgmt_tx_cancel_wait)
5002 return -EINVAL;
5003 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5004 }
5005
Jouni Malinen026331c2010-02-15 12:53:10 +02005006 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5007 channel_type = nla_get_u32(
5008 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5009 if (channel_type != NL80211_CHAN_NO_HT &&
5010 channel_type != NL80211_CHAN_HT20 &&
5011 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005012 channel_type != NL80211_CHAN_HT40MINUS)
5013 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005014 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005015 }
5016
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005017 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5018
Jouni Malinen026331c2010-02-15 12:53:10 +02005019 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5020 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005021 if (chan == NULL)
5022 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005023
5024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005025 if (!msg)
5026 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005027
5028 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02005029 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005030
5031 if (IS_ERR(hdr)) {
5032 err = PTR_ERR(hdr);
5033 goto free_msg;
5034 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005035 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5036 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005037 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5038 nla_len(info->attrs[NL80211_ATTR_FRAME]),
5039 &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005040 if (err)
5041 goto free_msg;
5042
5043 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5044
5045 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005046 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02005047
5048 nla_put_failure:
5049 err = -ENOBUFS;
5050 free_msg:
5051 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005052 return err;
5053}
5054
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005055static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5056{
5057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5058 struct net_device *dev = info->user_ptr[1];
5059 u64 cookie;
5060
5061 if (!info->attrs[NL80211_ATTR_COOKIE])
5062 return -EINVAL;
5063
5064 if (!rdev->ops->mgmt_tx_cancel_wait)
5065 return -EOPNOTSUPP;
5066
5067 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5068 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5069 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5070 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5071 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5072 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5073 return -EOPNOTSUPP;
5074
5075 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5076
5077 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5078}
5079
Kalle Valoffb9eb32010-02-17 17:58:10 +02005080static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5081{
Johannes Berg4c476992010-10-04 21:36:35 +02005082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005083 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005084 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005085 u8 ps_state;
5086 bool state;
5087 int err;
5088
Johannes Berg4c476992010-10-04 21:36:35 +02005089 if (!info->attrs[NL80211_ATTR_PS_STATE])
5090 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005091
5092 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5093
Johannes Berg4c476992010-10-04 21:36:35 +02005094 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5095 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005096
5097 wdev = dev->ieee80211_ptr;
5098
Johannes Berg4c476992010-10-04 21:36:35 +02005099 if (!rdev->ops->set_power_mgmt)
5100 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005101
5102 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5103
5104 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005105 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005106
Johannes Berg4c476992010-10-04 21:36:35 +02005107 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5108 wdev->ps_timeout);
5109 if (!err)
5110 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005111 return err;
5112}
5113
5114static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5115{
Johannes Berg4c476992010-10-04 21:36:35 +02005116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005117 enum nl80211_ps_state ps_state;
5118 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005119 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005120 struct sk_buff *msg;
5121 void *hdr;
5122 int err;
5123
Kalle Valoffb9eb32010-02-17 17:58:10 +02005124 wdev = dev->ieee80211_ptr;
5125
Johannes Berg4c476992010-10-04 21:36:35 +02005126 if (!rdev->ops->set_power_mgmt)
5127 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005128
5129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005130 if (!msg)
5131 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005132
5133 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5134 NL80211_CMD_GET_POWER_SAVE);
5135 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005136 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005137 goto free_msg;
5138 }
5139
5140 if (wdev->ps)
5141 ps_state = NL80211_PS_ENABLED;
5142 else
5143 ps_state = NL80211_PS_DISABLED;
5144
5145 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5146
5147 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005148 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005149
Johannes Berg4c476992010-10-04 21:36:35 +02005150 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005151 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005152 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005153 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005154 return err;
5155}
5156
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005157static struct nla_policy
5158nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5159 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5160 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5161 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5162};
5163
5164static int nl80211_set_cqm_rssi(struct genl_info *info,
5165 s32 threshold, u32 hysteresis)
5166{
Johannes Berg4c476992010-10-04 21:36:35 +02005167 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005168 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005169 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005170
5171 if (threshold > 0)
5172 return -EINVAL;
5173
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005174 wdev = dev->ieee80211_ptr;
5175
Johannes Berg4c476992010-10-04 21:36:35 +02005176 if (!rdev->ops->set_cqm_rssi_config)
5177 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005178
Johannes Berg074ac8d2010-09-16 14:58:22 +02005179 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005180 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5181 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005182
Johannes Berg4c476992010-10-04 21:36:35 +02005183 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5184 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005185}
5186
5187static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5188{
5189 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5190 struct nlattr *cqm;
5191 int err;
5192
5193 cqm = info->attrs[NL80211_ATTR_CQM];
5194 if (!cqm) {
5195 err = -EINVAL;
5196 goto out;
5197 }
5198
5199 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5200 nl80211_attr_cqm_policy);
5201 if (err)
5202 goto out;
5203
5204 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5205 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5206 s32 threshold;
5207 u32 hysteresis;
5208 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5209 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5210 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5211 } else
5212 err = -EINVAL;
5213
5214out:
5215 return err;
5216}
5217
Johannes Berg29cbe682010-12-03 09:20:44 +01005218static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5219{
5220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5221 struct net_device *dev = info->user_ptr[1];
5222 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005223 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005224 int err;
5225
5226 /* start with default */
5227 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005228 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005229
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005230 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005231 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005232 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005233 if (err)
5234 return err;
5235 }
5236
5237 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5238 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5239 return -EINVAL;
5240
Javier Cardonac80d5452010-12-16 17:37:49 -08005241 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5242 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5243
5244 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5245 /* parse additional setup parameters if given */
5246 err = nl80211_parse_mesh_setup(info, &setup);
5247 if (err)
5248 return err;
5249 }
5250
5251 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005252}
5253
5254static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5255{
5256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5257 struct net_device *dev = info->user_ptr[1];
5258
5259 return cfg80211_leave_mesh(rdev, dev);
5260}
5261
Johannes Bergff1b6e62011-05-04 15:37:28 +02005262static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5263{
5264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5265 struct sk_buff *msg;
5266 void *hdr;
5267
5268 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5269 return -EOPNOTSUPP;
5270
5271 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5272 if (!msg)
5273 return -ENOMEM;
5274
5275 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5276 NL80211_CMD_GET_WOWLAN);
5277 if (!hdr)
5278 goto nla_put_failure;
5279
5280 if (rdev->wowlan) {
5281 struct nlattr *nl_wowlan;
5282
5283 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5284 if (!nl_wowlan)
5285 goto nla_put_failure;
5286
5287 if (rdev->wowlan->any)
5288 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5289 if (rdev->wowlan->disconnect)
5290 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5291 if (rdev->wowlan->magic_pkt)
5292 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005293 if (rdev->wowlan->gtk_rekey_failure)
5294 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5295 if (rdev->wowlan->eap_identity_req)
5296 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5297 if (rdev->wowlan->four_way_handshake)
5298 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5299 if (rdev->wowlan->rfkill_release)
5300 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005301 if (rdev->wowlan->n_patterns) {
5302 struct nlattr *nl_pats, *nl_pat;
5303 int i, pat_len;
5304
5305 nl_pats = nla_nest_start(msg,
5306 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5307 if (!nl_pats)
5308 goto nla_put_failure;
5309
5310 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5311 nl_pat = nla_nest_start(msg, i + 1);
5312 if (!nl_pat)
5313 goto nla_put_failure;
5314 pat_len = rdev->wowlan->patterns[i].pattern_len;
5315 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5316 DIV_ROUND_UP(pat_len, 8),
5317 rdev->wowlan->patterns[i].mask);
5318 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5319 pat_len,
5320 rdev->wowlan->patterns[i].pattern);
5321 nla_nest_end(msg, nl_pat);
5322 }
5323 nla_nest_end(msg, nl_pats);
5324 }
5325
5326 nla_nest_end(msg, nl_wowlan);
5327 }
5328
5329 genlmsg_end(msg, hdr);
5330 return genlmsg_reply(msg, info);
5331
5332nla_put_failure:
5333 nlmsg_free(msg);
5334 return -ENOBUFS;
5335}
5336
5337static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5338{
5339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5340 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5341 struct cfg80211_wowlan no_triggers = {};
5342 struct cfg80211_wowlan new_triggers = {};
5343 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5344 int err, i;
5345
5346 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5347 return -EOPNOTSUPP;
5348
5349 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5350 goto no_triggers;
5351
5352 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5353 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5354 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5355 nl80211_wowlan_policy);
5356 if (err)
5357 return err;
5358
5359 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5360 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5361 return -EINVAL;
5362 new_triggers.any = true;
5363 }
5364
5365 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5366 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5367 return -EINVAL;
5368 new_triggers.disconnect = true;
5369 }
5370
5371 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5372 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5373 return -EINVAL;
5374 new_triggers.magic_pkt = true;
5375 }
5376
Johannes Berg77dbbb12011-07-13 10:48:55 +02005377 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5378 return -EINVAL;
5379
5380 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5381 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5382 return -EINVAL;
5383 new_triggers.gtk_rekey_failure = true;
5384 }
5385
5386 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5387 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5388 return -EINVAL;
5389 new_triggers.eap_identity_req = true;
5390 }
5391
5392 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5393 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5394 return -EINVAL;
5395 new_triggers.four_way_handshake = true;
5396 }
5397
5398 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5399 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5400 return -EINVAL;
5401 new_triggers.rfkill_release = true;
5402 }
5403
Johannes Bergff1b6e62011-05-04 15:37:28 +02005404 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5405 struct nlattr *pat;
5406 int n_patterns = 0;
5407 int rem, pat_len, mask_len;
5408 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5409
5410 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5411 rem)
5412 n_patterns++;
5413 if (n_patterns > wowlan->n_patterns)
5414 return -EINVAL;
5415
5416 new_triggers.patterns = kcalloc(n_patterns,
5417 sizeof(new_triggers.patterns[0]),
5418 GFP_KERNEL);
5419 if (!new_triggers.patterns)
5420 return -ENOMEM;
5421
5422 new_triggers.n_patterns = n_patterns;
5423 i = 0;
5424
5425 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5426 rem) {
5427 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5428 nla_data(pat), nla_len(pat), NULL);
5429 err = -EINVAL;
5430 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5431 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5432 goto error;
5433 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5434 mask_len = DIV_ROUND_UP(pat_len, 8);
5435 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5436 mask_len)
5437 goto error;
5438 if (pat_len > wowlan->pattern_max_len ||
5439 pat_len < wowlan->pattern_min_len)
5440 goto error;
5441
5442 new_triggers.patterns[i].mask =
5443 kmalloc(mask_len + pat_len, GFP_KERNEL);
5444 if (!new_triggers.patterns[i].mask) {
5445 err = -ENOMEM;
5446 goto error;
5447 }
5448 new_triggers.patterns[i].pattern =
5449 new_triggers.patterns[i].mask + mask_len;
5450 memcpy(new_triggers.patterns[i].mask,
5451 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5452 mask_len);
5453 new_triggers.patterns[i].pattern_len = pat_len;
5454 memcpy(new_triggers.patterns[i].pattern,
5455 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5456 pat_len);
5457 i++;
5458 }
5459 }
5460
5461 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5462 struct cfg80211_wowlan *ntrig;
5463 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5464 GFP_KERNEL);
5465 if (!ntrig) {
5466 err = -ENOMEM;
5467 goto error;
5468 }
5469 cfg80211_rdev_free_wowlan(rdev);
5470 rdev->wowlan = ntrig;
5471 } else {
5472 no_triggers:
5473 cfg80211_rdev_free_wowlan(rdev);
5474 rdev->wowlan = NULL;
5475 }
5476
5477 return 0;
5478 error:
5479 for (i = 0; i < new_triggers.n_patterns; i++)
5480 kfree(new_triggers.patterns[i].mask);
5481 kfree(new_triggers.patterns);
5482 return err;
5483}
5484
Johannes Berge5497d72011-07-05 16:35:40 +02005485static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
5486{
5487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5488 struct net_device *dev = info->user_ptr[1];
5489 struct wireless_dev *wdev = dev->ieee80211_ptr;
5490 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
5491 struct cfg80211_gtk_rekey_data rekey_data;
5492 int err;
5493
5494 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
5495 return -EINVAL;
5496
5497 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
5498 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
5499 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
5500 nl80211_rekey_policy);
5501 if (err)
5502 return err;
5503
5504 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
5505 return -ERANGE;
5506 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
5507 return -ERANGE;
5508 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
5509 return -ERANGE;
5510
5511 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
5512 NL80211_KEK_LEN);
5513 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
5514 NL80211_KCK_LEN);
5515 memcpy(rekey_data.replay_ctr,
5516 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
5517 NL80211_REPLAY_CTR_LEN);
5518
5519 wdev_lock(wdev);
5520 if (!wdev->current_bss) {
5521 err = -ENOTCONN;
5522 goto out;
5523 }
5524
5525 if (!rdev->ops->set_rekey_data) {
5526 err = -EOPNOTSUPP;
5527 goto out;
5528 }
5529
5530 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
5531 out:
5532 wdev_unlock(wdev);
5533 return err;
5534}
5535
Johannes Berg4c476992010-10-04 21:36:35 +02005536#define NL80211_FLAG_NEED_WIPHY 0x01
5537#define NL80211_FLAG_NEED_NETDEV 0x02
5538#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02005539#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5540#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5541 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02005542
5543static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5544 struct genl_info *info)
5545{
5546 struct cfg80211_registered_device *rdev;
5547 struct net_device *dev;
5548 int err;
5549 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5550
5551 if (rtnl)
5552 rtnl_lock();
5553
5554 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5555 rdev = cfg80211_get_dev_from_info(info);
5556 if (IS_ERR(rdev)) {
5557 if (rtnl)
5558 rtnl_unlock();
5559 return PTR_ERR(rdev);
5560 }
5561 info->user_ptr[0] = rdev;
5562 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5563 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5564 if (err) {
5565 if (rtnl)
5566 rtnl_unlock();
5567 return err;
5568 }
Johannes Berg41265712010-10-04 21:14:05 +02005569 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
5570 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02005571 cfg80211_unlock_rdev(rdev);
5572 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02005573 if (rtnl)
5574 rtnl_unlock();
5575 return -ENETDOWN;
5576 }
Johannes Berg4c476992010-10-04 21:36:35 +02005577 info->user_ptr[0] = rdev;
5578 info->user_ptr[1] = dev;
5579 }
5580
5581 return 0;
5582}
5583
5584static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
5585 struct genl_info *info)
5586{
5587 if (info->user_ptr[0])
5588 cfg80211_unlock_rdev(info->user_ptr[0]);
5589 if (info->user_ptr[1])
5590 dev_put(info->user_ptr[1]);
5591 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
5592 rtnl_unlock();
5593}
5594
Johannes Berg55682962007-09-20 13:09:35 -04005595static struct genl_ops nl80211_ops[] = {
5596 {
5597 .cmd = NL80211_CMD_GET_WIPHY,
5598 .doit = nl80211_get_wiphy,
5599 .dumpit = nl80211_dump_wiphy,
5600 .policy = nl80211_policy,
5601 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005602 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04005603 },
5604 {
5605 .cmd = NL80211_CMD_SET_WIPHY,
5606 .doit = nl80211_set_wiphy,
5607 .policy = nl80211_policy,
5608 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005609 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005610 },
5611 {
5612 .cmd = NL80211_CMD_GET_INTERFACE,
5613 .doit = nl80211_get_interface,
5614 .dumpit = nl80211_dump_interface,
5615 .policy = nl80211_policy,
5616 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005617 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04005618 },
5619 {
5620 .cmd = NL80211_CMD_SET_INTERFACE,
5621 .doit = nl80211_set_interface,
5622 .policy = nl80211_policy,
5623 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005624 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5625 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005626 },
5627 {
5628 .cmd = NL80211_CMD_NEW_INTERFACE,
5629 .doit = nl80211_new_interface,
5630 .policy = nl80211_policy,
5631 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005632 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5633 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005634 },
5635 {
5636 .cmd = NL80211_CMD_DEL_INTERFACE,
5637 .doit = nl80211_del_interface,
5638 .policy = nl80211_policy,
5639 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005640 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5641 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005642 },
Johannes Berg41ade002007-12-19 02:03:29 +01005643 {
5644 .cmd = NL80211_CMD_GET_KEY,
5645 .doit = nl80211_get_key,
5646 .policy = nl80211_policy,
5647 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005648 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5649 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005650 },
5651 {
5652 .cmd = NL80211_CMD_SET_KEY,
5653 .doit = nl80211_set_key,
5654 .policy = nl80211_policy,
5655 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005656 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005657 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005658 },
5659 {
5660 .cmd = NL80211_CMD_NEW_KEY,
5661 .doit = nl80211_new_key,
5662 .policy = nl80211_policy,
5663 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005665 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005666 },
5667 {
5668 .cmd = NL80211_CMD_DEL_KEY,
5669 .doit = nl80211_del_key,
5670 .policy = nl80211_policy,
5671 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005673 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005674 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01005675 {
5676 .cmd = NL80211_CMD_SET_BEACON,
5677 .policy = nl80211_policy,
5678 .flags = GENL_ADMIN_PERM,
5679 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005680 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5681 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005682 },
5683 {
5684 .cmd = NL80211_CMD_NEW_BEACON,
5685 .policy = nl80211_policy,
5686 .flags = GENL_ADMIN_PERM,
5687 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005688 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5689 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005690 },
5691 {
5692 .cmd = NL80211_CMD_DEL_BEACON,
5693 .policy = nl80211_policy,
5694 .flags = GENL_ADMIN_PERM,
5695 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005696 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5697 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005698 },
Johannes Berg5727ef12007-12-19 02:03:34 +01005699 {
5700 .cmd = NL80211_CMD_GET_STATION,
5701 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005702 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01005703 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02005704 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5705 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005706 },
5707 {
5708 .cmd = NL80211_CMD_SET_STATION,
5709 .doit = nl80211_set_station,
5710 .policy = nl80211_policy,
5711 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5713 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005714 },
5715 {
5716 .cmd = NL80211_CMD_NEW_STATION,
5717 .doit = nl80211_new_station,
5718 .policy = nl80211_policy,
5719 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005720 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005721 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005722 },
5723 {
5724 .cmd = NL80211_CMD_DEL_STATION,
5725 .doit = nl80211_del_station,
5726 .policy = nl80211_policy,
5727 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5729 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01005730 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005731 {
5732 .cmd = NL80211_CMD_GET_MPATH,
5733 .doit = nl80211_get_mpath,
5734 .dumpit = nl80211_dump_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005739 },
5740 {
5741 .cmd = NL80211_CMD_SET_MPATH,
5742 .doit = nl80211_set_mpath,
5743 .policy = nl80211_policy,
5744 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005746 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005747 },
5748 {
5749 .cmd = NL80211_CMD_NEW_MPATH,
5750 .doit = nl80211_new_mpath,
5751 .policy = nl80211_policy,
5752 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005753 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005754 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005755 },
5756 {
5757 .cmd = NL80211_CMD_DEL_MPATH,
5758 .doit = nl80211_del_mpath,
5759 .policy = nl80211_policy,
5760 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005761 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5762 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005763 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005764 {
5765 .cmd = NL80211_CMD_SET_BSS,
5766 .doit = nl80211_set_bss,
5767 .policy = nl80211_policy,
5768 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005769 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5770 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005771 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005772 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005773 .cmd = NL80211_CMD_GET_REG,
5774 .doit = nl80211_get_reg,
5775 .policy = nl80211_policy,
5776 /* can be retrieved by unprivileged users */
5777 },
5778 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005779 .cmd = NL80211_CMD_SET_REG,
5780 .doit = nl80211_set_reg,
5781 .policy = nl80211_policy,
5782 .flags = GENL_ADMIN_PERM,
5783 },
5784 {
5785 .cmd = NL80211_CMD_REQ_SET_REG,
5786 .doit = nl80211_req_set_reg,
5787 .policy = nl80211_policy,
5788 .flags = GENL_ADMIN_PERM,
5789 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005790 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005791 .cmd = NL80211_CMD_GET_MESH_CONFIG,
5792 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005793 .policy = nl80211_policy,
5794 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005795 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5796 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005797 },
5798 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005799 .cmd = NL80211_CMD_SET_MESH_CONFIG,
5800 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005801 .policy = nl80211_policy,
5802 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01005803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005804 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005805 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02005806 {
Johannes Berg2a519312009-02-10 21:25:55 +01005807 .cmd = NL80211_CMD_TRIGGER_SCAN,
5808 .doit = nl80211_trigger_scan,
5809 .policy = nl80211_policy,
5810 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005812 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01005813 },
5814 {
5815 .cmd = NL80211_CMD_GET_SCAN,
5816 .policy = nl80211_policy,
5817 .dumpit = nl80211_dump_scan,
5818 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02005819 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005820 .cmd = NL80211_CMD_START_SCHED_SCAN,
5821 .doit = nl80211_start_sched_scan,
5822 .policy = nl80211_policy,
5823 .flags = GENL_ADMIN_PERM,
5824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5825 NL80211_FLAG_NEED_RTNL,
5826 },
5827 {
5828 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
5829 .doit = nl80211_stop_sched_scan,
5830 .policy = nl80211_policy,
5831 .flags = GENL_ADMIN_PERM,
5832 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5833 NL80211_FLAG_NEED_RTNL,
5834 },
5835 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02005836 .cmd = NL80211_CMD_AUTHENTICATE,
5837 .doit = nl80211_authenticate,
5838 .policy = nl80211_policy,
5839 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005840 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005841 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005842 },
5843 {
5844 .cmd = NL80211_CMD_ASSOCIATE,
5845 .doit = nl80211_associate,
5846 .policy = nl80211_policy,
5847 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005849 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005850 },
5851 {
5852 .cmd = NL80211_CMD_DEAUTHENTICATE,
5853 .doit = nl80211_deauthenticate,
5854 .policy = nl80211_policy,
5855 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005856 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005857 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005858 },
5859 {
5860 .cmd = NL80211_CMD_DISASSOCIATE,
5861 .doit = nl80211_disassociate,
5862 .policy = nl80211_policy,
5863 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005864 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005865 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02005866 },
Johannes Berg04a773a2009-04-19 21:24:32 +02005867 {
5868 .cmd = NL80211_CMD_JOIN_IBSS,
5869 .doit = nl80211_join_ibss,
5870 .policy = nl80211_policy,
5871 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005872 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005873 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005874 },
5875 {
5876 .cmd = NL80211_CMD_LEAVE_IBSS,
5877 .doit = nl80211_leave_ibss,
5878 .policy = nl80211_policy,
5879 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005880 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005881 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02005882 },
Johannes Bergaff89a92009-07-01 21:26:51 +02005883#ifdef CONFIG_NL80211_TESTMODE
5884 {
5885 .cmd = NL80211_CMD_TESTMODE,
5886 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005887 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02005888 .policy = nl80211_policy,
5889 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005890 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5891 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02005892 },
5893#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02005894 {
5895 .cmd = NL80211_CMD_CONNECT,
5896 .doit = nl80211_connect,
5897 .policy = nl80211_policy,
5898 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005899 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005900 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005901 },
5902 {
5903 .cmd = NL80211_CMD_DISCONNECT,
5904 .doit = nl80211_disconnect,
5905 .policy = nl80211_policy,
5906 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005908 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005909 },
Johannes Berg463d0182009-07-14 00:33:35 +02005910 {
5911 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
5912 .doit = nl80211_wiphy_netns,
5913 .policy = nl80211_policy,
5914 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005915 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5916 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02005917 },
Holger Schurig61fa7132009-11-11 12:25:40 +01005918 {
5919 .cmd = NL80211_CMD_GET_SURVEY,
5920 .policy = nl80211_policy,
5921 .dumpit = nl80211_dump_survey,
5922 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005923 {
5924 .cmd = NL80211_CMD_SET_PMKSA,
5925 .doit = nl80211_setdel_pmksa,
5926 .policy = nl80211_policy,
5927 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005928 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5929 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005930 },
5931 {
5932 .cmd = NL80211_CMD_DEL_PMKSA,
5933 .doit = nl80211_setdel_pmksa,
5934 .policy = nl80211_policy,
5935 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005936 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5937 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005938 },
5939 {
5940 .cmd = NL80211_CMD_FLUSH_PMKSA,
5941 .doit = nl80211_flush_pmksa,
5942 .policy = nl80211_policy,
5943 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005944 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5945 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005946 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005947 {
5948 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
5949 .doit = nl80211_remain_on_channel,
5950 .policy = nl80211_policy,
5951 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005953 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005954 },
5955 {
5956 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
5957 .doit = nl80211_cancel_remain_on_channel,
5958 .policy = nl80211_policy,
5959 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005960 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005961 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005962 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005963 {
5964 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
5965 .doit = nl80211_set_tx_bitrate_mask,
5966 .policy = nl80211_policy,
5967 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005968 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5969 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005970 },
Jouni Malinen026331c2010-02-15 12:53:10 +02005971 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005972 .cmd = NL80211_CMD_REGISTER_FRAME,
5973 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005974 .policy = nl80211_policy,
5975 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005976 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5977 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005978 },
5979 {
Johannes Berg2e161f72010-08-12 15:38:38 +02005980 .cmd = NL80211_CMD_FRAME,
5981 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02005982 .policy = nl80211_policy,
5983 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005985 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02005986 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02005987 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005988 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
5989 .doit = nl80211_tx_mgmt_cancel_wait,
5990 .policy = nl80211_policy,
5991 .flags = GENL_ADMIN_PERM,
5992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5993 NL80211_FLAG_NEED_RTNL,
5994 },
5995 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02005996 .cmd = NL80211_CMD_SET_POWER_SAVE,
5997 .doit = nl80211_set_power_save,
5998 .policy = nl80211_policy,
5999 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006000 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6001 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006002 },
6003 {
6004 .cmd = NL80211_CMD_GET_POWER_SAVE,
6005 .doit = nl80211_get_power_save,
6006 .policy = nl80211_policy,
6007 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006008 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6009 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006010 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006011 {
6012 .cmd = NL80211_CMD_SET_CQM,
6013 .doit = nl80211_set_cqm,
6014 .policy = nl80211_policy,
6015 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006016 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6017 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006018 },
Johannes Bergf444de02010-05-05 15:25:02 +02006019 {
6020 .cmd = NL80211_CMD_SET_CHANNEL,
6021 .doit = nl80211_set_channel,
6022 .policy = nl80211_policy,
6023 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006024 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6025 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006026 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006027 {
6028 .cmd = NL80211_CMD_SET_WDS_PEER,
6029 .doit = nl80211_set_wds_peer,
6030 .policy = nl80211_policy,
6031 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006032 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6033 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006034 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006035 {
6036 .cmd = NL80211_CMD_JOIN_MESH,
6037 .doit = nl80211_join_mesh,
6038 .policy = nl80211_policy,
6039 .flags = GENL_ADMIN_PERM,
6040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6041 NL80211_FLAG_NEED_RTNL,
6042 },
6043 {
6044 .cmd = NL80211_CMD_LEAVE_MESH,
6045 .doit = nl80211_leave_mesh,
6046 .policy = nl80211_policy,
6047 .flags = GENL_ADMIN_PERM,
6048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6049 NL80211_FLAG_NEED_RTNL,
6050 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006051 {
6052 .cmd = NL80211_CMD_GET_WOWLAN,
6053 .doit = nl80211_get_wowlan,
6054 .policy = nl80211_policy,
6055 /* can be retrieved by unprivileged users */
6056 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6057 NL80211_FLAG_NEED_RTNL,
6058 },
6059 {
6060 .cmd = NL80211_CMD_SET_WOWLAN,
6061 .doit = nl80211_set_wowlan,
6062 .policy = nl80211_policy,
6063 .flags = GENL_ADMIN_PERM,
6064 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6065 NL80211_FLAG_NEED_RTNL,
6066 },
Johannes Berge5497d72011-07-05 16:35:40 +02006067 {
6068 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6069 .doit = nl80211_set_rekey_data,
6070 .policy = nl80211_policy,
6071 .flags = GENL_ADMIN_PERM,
6072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6073 NL80211_FLAG_NEED_RTNL,
6074 },
Johannes Berg55682962007-09-20 13:09:35 -04006075};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006076
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006077static struct genl_multicast_group nl80211_mlme_mcgrp = {
6078 .name = "mlme",
6079};
Johannes Berg55682962007-09-20 13:09:35 -04006080
6081/* multicast groups */
6082static struct genl_multicast_group nl80211_config_mcgrp = {
6083 .name = "config",
6084};
Johannes Berg2a519312009-02-10 21:25:55 +01006085static struct genl_multicast_group nl80211_scan_mcgrp = {
6086 .name = "scan",
6087};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006088static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6089 .name = "regulatory",
6090};
Johannes Berg55682962007-09-20 13:09:35 -04006091
6092/* notification functions */
6093
6094void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6095{
6096 struct sk_buff *msg;
6097
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006099 if (!msg)
6100 return;
6101
6102 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6103 nlmsg_free(msg);
6104 return;
6105 }
6106
Johannes Berg463d0182009-07-14 00:33:35 +02006107 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6108 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006109}
6110
Johannes Berg362a4152009-05-24 16:43:15 +02006111static int nl80211_add_scan_req(struct sk_buff *msg,
6112 struct cfg80211_registered_device *rdev)
6113{
6114 struct cfg80211_scan_request *req = rdev->scan_req;
6115 struct nlattr *nest;
6116 int i;
6117
Johannes Berg667503d2009-07-07 03:56:11 +02006118 ASSERT_RDEV_LOCK(rdev);
6119
Johannes Berg362a4152009-05-24 16:43:15 +02006120 if (WARN_ON(!req))
6121 return 0;
6122
6123 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6124 if (!nest)
6125 goto nla_put_failure;
6126 for (i = 0; i < req->n_ssids; i++)
6127 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6128 nla_nest_end(msg, nest);
6129
6130 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6131 if (!nest)
6132 goto nla_put_failure;
6133 for (i = 0; i < req->n_channels; i++)
6134 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6135 nla_nest_end(msg, nest);
6136
6137 if (req->ie)
6138 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6139
6140 return 0;
6141 nla_put_failure:
6142 return -ENOBUFS;
6143}
6144
Johannes Berga538e2d2009-06-16 19:56:42 +02006145static int nl80211_send_scan_msg(struct sk_buff *msg,
6146 struct cfg80211_registered_device *rdev,
6147 struct net_device *netdev,
6148 u32 pid, u32 seq, int flags,
6149 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006150{
6151 void *hdr;
6152
6153 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6154 if (!hdr)
6155 return -1;
6156
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006157 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006158 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6159
Johannes Berg362a4152009-05-24 16:43:15 +02006160 /* ignore errors and send incomplete event anyway */
6161 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006162
6163 return genlmsg_end(msg, hdr);
6164
6165 nla_put_failure:
6166 genlmsg_cancel(msg, hdr);
6167 return -EMSGSIZE;
6168}
6169
Luciano Coelho807f8a82011-05-11 17:09:35 +03006170static int
6171nl80211_send_sched_scan_msg(struct sk_buff *msg,
6172 struct cfg80211_registered_device *rdev,
6173 struct net_device *netdev,
6174 u32 pid, u32 seq, int flags, u32 cmd)
6175{
6176 void *hdr;
6177
6178 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6179 if (!hdr)
6180 return -1;
6181
6182 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6183 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6184
6185 return genlmsg_end(msg, hdr);
6186
6187 nla_put_failure:
6188 genlmsg_cancel(msg, hdr);
6189 return -EMSGSIZE;
6190}
6191
Johannes Berga538e2d2009-06-16 19:56:42 +02006192void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6193 struct net_device *netdev)
6194{
6195 struct sk_buff *msg;
6196
6197 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6198 if (!msg)
6199 return;
6200
6201 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6202 NL80211_CMD_TRIGGER_SCAN) < 0) {
6203 nlmsg_free(msg);
6204 return;
6205 }
6206
Johannes Berg463d0182009-07-14 00:33:35 +02006207 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6208 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006209}
6210
Johannes Berg2a519312009-02-10 21:25:55 +01006211void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6212 struct net_device *netdev)
6213{
6214 struct sk_buff *msg;
6215
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006217 if (!msg)
6218 return;
6219
Johannes Berga538e2d2009-06-16 19:56:42 +02006220 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6221 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006222 nlmsg_free(msg);
6223 return;
6224 }
6225
Johannes Berg463d0182009-07-14 00:33:35 +02006226 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6227 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006228}
6229
6230void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6231 struct net_device *netdev)
6232{
6233 struct sk_buff *msg;
6234
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006235 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006236 if (!msg)
6237 return;
6238
Johannes Berga538e2d2009-06-16 19:56:42 +02006239 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6240 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006241 nlmsg_free(msg);
6242 return;
6243 }
6244
Johannes Berg463d0182009-07-14 00:33:35 +02006245 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6246 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006247}
6248
Luciano Coelho807f8a82011-05-11 17:09:35 +03006249void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6250 struct net_device *netdev)
6251{
6252 struct sk_buff *msg;
6253
6254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6255 if (!msg)
6256 return;
6257
6258 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6259 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6260 nlmsg_free(msg);
6261 return;
6262 }
6263
6264 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6265 nl80211_scan_mcgrp.id, GFP_KERNEL);
6266}
6267
6268void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6269 struct net_device *netdev, u32 cmd)
6270{
6271 struct sk_buff *msg;
6272
6273 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6274 if (!msg)
6275 return;
6276
6277 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6278 nlmsg_free(msg);
6279 return;
6280 }
6281
6282 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6283 nl80211_scan_mcgrp.id, GFP_KERNEL);
6284}
6285
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006286/*
6287 * This can happen on global regulatory changes or device specific settings
6288 * based on custom world regulatory domains.
6289 */
6290void nl80211_send_reg_change_event(struct regulatory_request *request)
6291{
6292 struct sk_buff *msg;
6293 void *hdr;
6294
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006296 if (!msg)
6297 return;
6298
6299 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6300 if (!hdr) {
6301 nlmsg_free(msg);
6302 return;
6303 }
6304
6305 /* Userspace can always count this one always being set */
6306 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6307
6308 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6309 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6310 NL80211_REGDOM_TYPE_WORLD);
6311 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6312 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6313 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6314 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6315 request->intersect)
6316 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6317 NL80211_REGDOM_TYPE_INTERSECTION);
6318 else {
6319 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6320 NL80211_REGDOM_TYPE_COUNTRY);
6321 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6322 }
6323
6324 if (wiphy_idx_valid(request->wiphy_idx))
6325 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6326
6327 if (genlmsg_end(msg, hdr) < 0) {
6328 nlmsg_free(msg);
6329 return;
6330 }
6331
Johannes Bergbc43b282009-07-25 10:54:13 +02006332 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02006333 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02006334 GFP_ATOMIC);
6335 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006336
6337 return;
6338
6339nla_put_failure:
6340 genlmsg_cancel(msg, hdr);
6341 nlmsg_free(msg);
6342}
6343
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006344static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
6345 struct net_device *netdev,
6346 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006347 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006348{
6349 struct sk_buff *msg;
6350 void *hdr;
6351
Johannes Berge6d6e342009-07-01 21:26:47 +02006352 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006353 if (!msg)
6354 return;
6355
6356 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6357 if (!hdr) {
6358 nlmsg_free(msg);
6359 return;
6360 }
6361
6362 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6363 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6364 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6365
6366 if (genlmsg_end(msg, hdr) < 0) {
6367 nlmsg_free(msg);
6368 return;
6369 }
6370
Johannes Berg463d0182009-07-14 00:33:35 +02006371 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6372 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006373 return;
6374
6375 nla_put_failure:
6376 genlmsg_cancel(msg, hdr);
6377 nlmsg_free(msg);
6378}
6379
6380void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006381 struct net_device *netdev, const u8 *buf,
6382 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006383{
6384 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006385 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006386}
6387
6388void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
6389 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006390 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006391{
Johannes Berge6d6e342009-07-01 21:26:47 +02006392 nl80211_send_mlme_event(rdev, netdev, buf, len,
6393 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006394}
6395
Jouni Malinen53b46b82009-03-27 20:53:56 +02006396void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006397 struct net_device *netdev, const u8 *buf,
6398 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006399{
6400 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006401 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006402}
6403
Jouni Malinen53b46b82009-03-27 20:53:56 +02006404void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
6405 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006406 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006407{
6408 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006409 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006410}
6411
Jouni Malinencf4e5942010-12-16 00:52:40 +02006412void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6413 struct net_device *netdev, const u8 *buf,
6414 size_t len, gfp_t gfp)
6415{
6416 nl80211_send_mlme_event(rdev, netdev, buf, len,
6417 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6418}
6419
6420void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6421 struct net_device *netdev, const u8 *buf,
6422 size_t len, gfp_t gfp)
6423{
6424 nl80211_send_mlme_event(rdev, netdev, buf, len,
6425 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6426}
6427
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04006428static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
6429 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02006430 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006431{
6432 struct sk_buff *msg;
6433 void *hdr;
6434
Johannes Berge6d6e342009-07-01 21:26:47 +02006435 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006436 if (!msg)
6437 return;
6438
6439 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6440 if (!hdr) {
6441 nlmsg_free(msg);
6442 return;
6443 }
6444
6445 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6446 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6447 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
6448 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6449
6450 if (genlmsg_end(msg, hdr) < 0) {
6451 nlmsg_free(msg);
6452 return;
6453 }
6454
Johannes Berg463d0182009-07-14 00:33:35 +02006455 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6456 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006457 return;
6458
6459 nla_put_failure:
6460 genlmsg_cancel(msg, hdr);
6461 nlmsg_free(msg);
6462}
6463
6464void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006465 struct net_device *netdev, const u8 *addr,
6466 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006467{
6468 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02006469 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006470}
6471
6472void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006473 struct net_device *netdev, const u8 *addr,
6474 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006475{
Johannes Berge6d6e342009-07-01 21:26:47 +02006476 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
6477 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006478}
6479
Samuel Ortizb23aa672009-07-01 21:26:54 +02006480void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
6481 struct net_device *netdev, const u8 *bssid,
6482 const u8 *req_ie, size_t req_ie_len,
6483 const u8 *resp_ie, size_t resp_ie_len,
6484 u16 status, gfp_t gfp)
6485{
6486 struct sk_buff *msg;
6487 void *hdr;
6488
6489 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6490 if (!msg)
6491 return;
6492
6493 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
6494 if (!hdr) {
6495 nlmsg_free(msg);
6496 return;
6497 }
6498
6499 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6500 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6501 if (bssid)
6502 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6503 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
6504 if (req_ie)
6505 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6506 if (resp_ie)
6507 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6508
6509 if (genlmsg_end(msg, hdr) < 0) {
6510 nlmsg_free(msg);
6511 return;
6512 }
6513
Johannes Berg463d0182009-07-14 00:33:35 +02006514 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6515 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006516 return;
6517
6518 nla_put_failure:
6519 genlmsg_cancel(msg, hdr);
6520 nlmsg_free(msg);
6521
6522}
6523
6524void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
6525 struct net_device *netdev, const u8 *bssid,
6526 const u8 *req_ie, size_t req_ie_len,
6527 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
6528{
6529 struct sk_buff *msg;
6530 void *hdr;
6531
6532 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6533 if (!msg)
6534 return;
6535
6536 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
6537 if (!hdr) {
6538 nlmsg_free(msg);
6539 return;
6540 }
6541
6542 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6543 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6544 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6545 if (req_ie)
6546 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6547 if (resp_ie)
6548 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6549
6550 if (genlmsg_end(msg, hdr) < 0) {
6551 nlmsg_free(msg);
6552 return;
6553 }
6554
Johannes Berg463d0182009-07-14 00:33:35 +02006555 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6556 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006557 return;
6558
6559 nla_put_failure:
6560 genlmsg_cancel(msg, hdr);
6561 nlmsg_free(msg);
6562
6563}
6564
6565void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
6566 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02006567 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006568{
6569 struct sk_buff *msg;
6570 void *hdr;
6571
Johannes Berg667503d2009-07-07 03:56:11 +02006572 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006573 if (!msg)
6574 return;
6575
6576 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
6577 if (!hdr) {
6578 nlmsg_free(msg);
6579 return;
6580 }
6581
6582 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6583 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6584 if (from_ap && reason)
6585 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
6586 if (from_ap)
6587 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
6588 if (ie)
6589 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
6590
6591 if (genlmsg_end(msg, hdr) < 0) {
6592 nlmsg_free(msg);
6593 return;
6594 }
6595
Johannes Berg463d0182009-07-14 00:33:35 +02006596 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6597 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006598 return;
6599
6600 nla_put_failure:
6601 genlmsg_cancel(msg, hdr);
6602 nlmsg_free(msg);
6603
6604}
6605
Johannes Berg04a773a2009-04-19 21:24:32 +02006606void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
6607 struct net_device *netdev, const u8 *bssid,
6608 gfp_t gfp)
6609{
6610 struct sk_buff *msg;
6611 void *hdr;
6612
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006614 if (!msg)
6615 return;
6616
6617 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
6618 if (!hdr) {
6619 nlmsg_free(msg);
6620 return;
6621 }
6622
6623 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6624 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6625 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6626
6627 if (genlmsg_end(msg, hdr) < 0) {
6628 nlmsg_free(msg);
6629 return;
6630 }
6631
Johannes Berg463d0182009-07-14 00:33:35 +02006632 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6633 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006634 return;
6635
6636 nla_put_failure:
6637 genlmsg_cancel(msg, hdr);
6638 nlmsg_free(msg);
6639}
6640
Javier Cardonac93b5e72011-04-07 15:08:34 -07006641void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
6642 struct net_device *netdev,
6643 const u8 *macaddr, const u8* ie, u8 ie_len,
6644 gfp_t gfp)
6645{
6646 struct sk_buff *msg;
6647 void *hdr;
6648
6649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6650 if (!msg)
6651 return;
6652
6653 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
6654 if (!hdr) {
6655 nlmsg_free(msg);
6656 return;
6657 }
6658
6659 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6660 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6661 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
6662 if (ie_len && ie)
6663 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
6664
6665 if (genlmsg_end(msg, hdr) < 0) {
6666 nlmsg_free(msg);
6667 return;
6668 }
6669
6670 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6671 nl80211_mlme_mcgrp.id, gfp);
6672 return;
6673
6674 nla_put_failure:
6675 genlmsg_cancel(msg, hdr);
6676 nlmsg_free(msg);
6677}
6678
Jouni Malinena3b8b052009-03-27 21:59:49 +02006679void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
6680 struct net_device *netdev, const u8 *addr,
6681 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02006682 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02006683{
6684 struct sk_buff *msg;
6685 void *hdr;
6686
Johannes Berge6d6e342009-07-01 21:26:47 +02006687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006688 if (!msg)
6689 return;
6690
6691 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
6692 if (!hdr) {
6693 nlmsg_free(msg);
6694 return;
6695 }
6696
6697 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6698 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6699 if (addr)
6700 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6701 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03006702 if (key_id != -1)
6703 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006704 if (tsc)
6705 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
6706
6707 if (genlmsg_end(msg, hdr) < 0) {
6708 nlmsg_free(msg);
6709 return;
6710 }
6711
Johannes Berg463d0182009-07-14 00:33:35 +02006712 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6713 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02006714 return;
6715
6716 nla_put_failure:
6717 genlmsg_cancel(msg, hdr);
6718 nlmsg_free(msg);
6719}
6720
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006721void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
6722 struct ieee80211_channel *channel_before,
6723 struct ieee80211_channel *channel_after)
6724{
6725 struct sk_buff *msg;
6726 void *hdr;
6727 struct nlattr *nl_freq;
6728
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006730 if (!msg)
6731 return;
6732
6733 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
6734 if (!hdr) {
6735 nlmsg_free(msg);
6736 return;
6737 }
6738
6739 /*
6740 * Since we are applying the beacon hint to a wiphy we know its
6741 * wiphy_idx is valid
6742 */
6743 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
6744
6745 /* Before */
6746 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
6747 if (!nl_freq)
6748 goto nla_put_failure;
6749 if (nl80211_msg_put_channel(msg, channel_before))
6750 goto nla_put_failure;
6751 nla_nest_end(msg, nl_freq);
6752
6753 /* After */
6754 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
6755 if (!nl_freq)
6756 goto nla_put_failure;
6757 if (nl80211_msg_put_channel(msg, channel_after))
6758 goto nla_put_failure;
6759 nla_nest_end(msg, nl_freq);
6760
6761 if (genlmsg_end(msg, hdr) < 0) {
6762 nlmsg_free(msg);
6763 return;
6764 }
6765
Johannes Berg463d0182009-07-14 00:33:35 +02006766 rcu_read_lock();
6767 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
6768 GFP_ATOMIC);
6769 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04006770
6771 return;
6772
6773nla_put_failure:
6774 genlmsg_cancel(msg, hdr);
6775 nlmsg_free(msg);
6776}
6777
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006778static void nl80211_send_remain_on_chan_event(
6779 int cmd, struct cfg80211_registered_device *rdev,
6780 struct net_device *netdev, u64 cookie,
6781 struct ieee80211_channel *chan,
6782 enum nl80211_channel_type channel_type,
6783 unsigned int duration, gfp_t gfp)
6784{
6785 struct sk_buff *msg;
6786 void *hdr;
6787
6788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6789 if (!msg)
6790 return;
6791
6792 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6793 if (!hdr) {
6794 nlmsg_free(msg);
6795 return;
6796 }
6797
6798 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6799 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6800 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
6801 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
6802 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6803
6804 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
6805 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
6806
6807 if (genlmsg_end(msg, hdr) < 0) {
6808 nlmsg_free(msg);
6809 return;
6810 }
6811
6812 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6813 nl80211_mlme_mcgrp.id, gfp);
6814 return;
6815
6816 nla_put_failure:
6817 genlmsg_cancel(msg, hdr);
6818 nlmsg_free(msg);
6819}
6820
6821void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
6822 struct net_device *netdev, u64 cookie,
6823 struct ieee80211_channel *chan,
6824 enum nl80211_channel_type channel_type,
6825 unsigned int duration, gfp_t gfp)
6826{
6827 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
6828 rdev, netdev, cookie, chan,
6829 channel_type, duration, gfp);
6830}
6831
6832void nl80211_send_remain_on_channel_cancel(
6833 struct cfg80211_registered_device *rdev, struct net_device *netdev,
6834 u64 cookie, struct ieee80211_channel *chan,
6835 enum nl80211_channel_type channel_type, gfp_t gfp)
6836{
6837 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6838 rdev, netdev, cookie, chan,
6839 channel_type, 0, gfp);
6840}
6841
Johannes Berg98b62182009-12-23 13:15:44 +01006842void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
6843 struct net_device *dev, const u8 *mac_addr,
6844 struct station_info *sinfo, gfp_t gfp)
6845{
6846 struct sk_buff *msg;
6847
6848 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6849 if (!msg)
6850 return;
6851
6852 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
6853 nlmsg_free(msg);
6854 return;
6855 }
6856
6857 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6858 nl80211_mlme_mcgrp.id, gfp);
6859}
6860
Jouni Malinenec15e682011-03-23 15:29:52 +02006861void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
6862 struct net_device *dev, const u8 *mac_addr,
6863 gfp_t gfp)
6864{
6865 struct sk_buff *msg;
6866 void *hdr;
6867
6868 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6869 if (!msg)
6870 return;
6871
6872 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
6873 if (!hdr) {
6874 nlmsg_free(msg);
6875 return;
6876 }
6877
6878 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
6879 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
6880
6881 if (genlmsg_end(msg, hdr) < 0) {
6882 nlmsg_free(msg);
6883 return;
6884 }
6885
6886 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6887 nl80211_mlme_mcgrp.id, gfp);
6888 return;
6889
6890 nla_put_failure:
6891 genlmsg_cancel(msg, hdr);
6892 nlmsg_free(msg);
6893}
6894
Johannes Berg2e161f72010-08-12 15:38:38 +02006895int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
6896 struct net_device *netdev, u32 nlpid,
6897 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02006898{
6899 struct sk_buff *msg;
6900 void *hdr;
6901 int err;
6902
6903 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6904 if (!msg)
6905 return -ENOMEM;
6906
Johannes Berg2e161f72010-08-12 15:38:38 +02006907 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006908 if (!hdr) {
6909 nlmsg_free(msg);
6910 return -ENOMEM;
6911 }
6912
6913 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6914 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6915 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
6916 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6917
6918 err = genlmsg_end(msg, hdr);
6919 if (err < 0) {
6920 nlmsg_free(msg);
6921 return err;
6922 }
6923
6924 err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
6925 if (err < 0)
6926 return err;
6927 return 0;
6928
6929 nla_put_failure:
6930 genlmsg_cancel(msg, hdr);
6931 nlmsg_free(msg);
6932 return -ENOBUFS;
6933}
6934
Johannes Berg2e161f72010-08-12 15:38:38 +02006935void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
6936 struct net_device *netdev, u64 cookie,
6937 const u8 *buf, size_t len, bool ack,
6938 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02006939{
6940 struct sk_buff *msg;
6941 void *hdr;
6942
6943 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6944 if (!msg)
6945 return;
6946
Johannes Berg2e161f72010-08-12 15:38:38 +02006947 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02006948 if (!hdr) {
6949 nlmsg_free(msg);
6950 return;
6951 }
6952
6953 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6954 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6955 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6956 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6957 if (ack)
6958 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
6959
6960 if (genlmsg_end(msg, hdr) < 0) {
6961 nlmsg_free(msg);
6962 return;
6963 }
6964
6965 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
6966 return;
6967
6968 nla_put_failure:
6969 genlmsg_cancel(msg, hdr);
6970 nlmsg_free(msg);
6971}
6972
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006973void
6974nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
6975 struct net_device *netdev,
6976 enum nl80211_cqm_rssi_threshold_event rssi_event,
6977 gfp_t gfp)
6978{
6979 struct sk_buff *msg;
6980 struct nlattr *pinfoattr;
6981 void *hdr;
6982
6983 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6984 if (!msg)
6985 return;
6986
6987 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
6988 if (!hdr) {
6989 nlmsg_free(msg);
6990 return;
6991 }
6992
6993 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6994 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6995
6996 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
6997 if (!pinfoattr)
6998 goto nla_put_failure;
6999
7000 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7001 rssi_event);
7002
7003 nla_nest_end(msg, pinfoattr);
7004
7005 if (genlmsg_end(msg, hdr) < 0) {
7006 nlmsg_free(msg);
7007 return;
7008 }
7009
7010 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7011 nl80211_mlme_mcgrp.id, gfp);
7012 return;
7013
7014 nla_put_failure:
7015 genlmsg_cancel(msg, hdr);
7016 nlmsg_free(msg);
7017}
7018
Johannes Berge5497d72011-07-05 16:35:40 +02007019void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7020 struct net_device *netdev, const u8 *bssid,
7021 const u8 *replay_ctr, gfp_t gfp)
7022{
7023 struct sk_buff *msg;
7024 struct nlattr *rekey_attr;
7025 void *hdr;
7026
7027 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7028 if (!msg)
7029 return;
7030
7031 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7032 if (!hdr) {
7033 nlmsg_free(msg);
7034 return;
7035 }
7036
7037 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7038 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7039 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7040
7041 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7042 if (!rekey_attr)
7043 goto nla_put_failure;
7044
7045 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7046 NL80211_REPLAY_CTR_LEN, replay_ctr);
7047
7048 nla_nest_end(msg, rekey_attr);
7049
7050 if (genlmsg_end(msg, hdr) < 0) {
7051 nlmsg_free(msg);
7052 return;
7053 }
7054
7055 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7056 nl80211_mlme_mcgrp.id, gfp);
7057 return;
7058
7059 nla_put_failure:
7060 genlmsg_cancel(msg, hdr);
7061 nlmsg_free(msg);
7062}
7063
Johannes Bergc063dbf2010-11-24 08:10:05 +01007064void
7065nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7066 struct net_device *netdev, const u8 *peer,
7067 u32 num_packets, gfp_t gfp)
7068{
7069 struct sk_buff *msg;
7070 struct nlattr *pinfoattr;
7071 void *hdr;
7072
7073 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7074 if (!msg)
7075 return;
7076
7077 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7078 if (!hdr) {
7079 nlmsg_free(msg);
7080 return;
7081 }
7082
7083 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7084 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7085 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7086
7087 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7088 if (!pinfoattr)
7089 goto nla_put_failure;
7090
7091 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7092
7093 nla_nest_end(msg, pinfoattr);
7094
7095 if (genlmsg_end(msg, hdr) < 0) {
7096 nlmsg_free(msg);
7097 return;
7098 }
7099
7100 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7101 nl80211_mlme_mcgrp.id, gfp);
7102 return;
7103
7104 nla_put_failure:
7105 genlmsg_cancel(msg, hdr);
7106 nlmsg_free(msg);
7107}
7108
Jouni Malinen026331c2010-02-15 12:53:10 +02007109static int nl80211_netlink_notify(struct notifier_block * nb,
7110 unsigned long state,
7111 void *_notify)
7112{
7113 struct netlink_notify *notify = _notify;
7114 struct cfg80211_registered_device *rdev;
7115 struct wireless_dev *wdev;
7116
7117 if (state != NETLINK_URELEASE)
7118 return NOTIFY_DONE;
7119
7120 rcu_read_lock();
7121
7122 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
7123 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02007124 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007125
7126 rcu_read_unlock();
7127
7128 return NOTIFY_DONE;
7129}
7130
7131static struct notifier_block nl80211_netlink_notifier = {
7132 .notifier_call = nl80211_netlink_notify,
7133};
7134
Johannes Berg55682962007-09-20 13:09:35 -04007135/* initialisation/exit functions */
7136
7137int nl80211_init(void)
7138{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007139 int err;
Johannes Berg55682962007-09-20 13:09:35 -04007140
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007141 err = genl_register_family_with_ops(&nl80211_fam,
7142 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04007143 if (err)
7144 return err;
7145
Johannes Berg55682962007-09-20 13:09:35 -04007146 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7147 if (err)
7148 goto err_out;
7149
Johannes Berg2a519312009-02-10 21:25:55 +01007150 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7151 if (err)
7152 goto err_out;
7153
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007154 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7155 if (err)
7156 goto err_out;
7157
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007158 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7159 if (err)
7160 goto err_out;
7161
Johannes Bergaff89a92009-07-01 21:26:51 +02007162#ifdef CONFIG_NL80211_TESTMODE
7163 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7164 if (err)
7165 goto err_out;
7166#endif
7167
Jouni Malinen026331c2010-02-15 12:53:10 +02007168 err = netlink_register_notifier(&nl80211_netlink_notifier);
7169 if (err)
7170 goto err_out;
7171
Johannes Berg55682962007-09-20 13:09:35 -04007172 return 0;
7173 err_out:
7174 genl_unregister_family(&nl80211_fam);
7175 return err;
7176}
7177
7178void nl80211_exit(void)
7179{
Jouni Malinen026331c2010-02-15 12:53:10 +02007180 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04007181 genl_unregister_family(&nl80211_fam);
7182}