blob: bcf6f70e518db6654349fcaf852fb33720c76179 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Jouni Malinen5fb628e2011-08-10 23:54:35 +030026static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
30 int cipher_limit);
31
Johannes Berg4c476992010-10-04 21:36:35 +020032static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
36
Johannes Berg55682962007-09-20 13:09:35 -040037/* the netlink family */
38static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020044 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020045 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040047};
48
Johannes Berg79c97e92009-07-07 03:56:12 +020049/* internal helper: get rdev and dev */
Johannes Berg00918d32011-12-13 17:22:05 +010050static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
51 struct cfg80211_registered_device **rdev,
52 struct net_device **dev)
Johannes Berg55682962007-09-20 13:09:35 -040053{
54 int ifindex;
55
Johannes Bergbba95fe2008-07-29 13:22:51 +020056 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040057 return -EINVAL;
58
Johannes Bergbba95fe2008-07-29 13:22:51 +020059 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg00918d32011-12-13 17:22:05 +010060 *dev = dev_get_by_index(netns, ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040061 if (!*dev)
62 return -ENODEV;
63
Johannes Berg00918d32011-12-13 17:22:05 +010064 *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020065 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040066 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020067 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040068 }
69
70 return 0;
71}
72
73/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000074static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -040075 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
76 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -070077 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +020078 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020079 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053080 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020081 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
82 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
83 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
84 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +010085 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -040086
87 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
88 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
89 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010090
Eliad Pellere007b852011-11-24 18:13:56 +020091 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
92 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +010093
Johannes Bergb9454e82009-07-08 13:29:08 +020094 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +010095 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
96 .len = WLAN_MAX_KEY_LEN },
97 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
98 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
99 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200100 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200101 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100102
103 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
104 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
105 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
106 .len = IEEE80211_MAX_DATA_LEN },
107 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
108 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100109 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
110 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
111 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
112 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
113 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100114 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100115 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200116 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100117 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
118 .len = IEEE80211_MAX_MESH_ID_LEN },
119 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300120
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700121 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
122 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
123
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300124 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
125 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
126 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200127 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
128 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100129 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300130
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800131 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700132 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700133
Johannes Berg6c739412011-11-03 09:27:01 +0100134 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200135
136 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
137 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
138 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100139 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
140 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200141
142 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
143 .len = IEEE80211_MAX_SSID_LEN },
144 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
145 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200146 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300147 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300148 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300149 [NL80211_ATTR_STA_FLAGS2] = {
150 .len = sizeof(struct nl80211_sta_flag_update),
151 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300152 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300153 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
154 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200155 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
156 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
157 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200158 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100159 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100160 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
161 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100162 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
163 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200164 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200165 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
166 .len = IEEE80211_MAX_DATA_LEN },
167 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200168 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200169 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300170 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200171 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300172 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
173 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200174 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900175 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
176 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100177 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100178 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100179 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200180 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700181 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300182 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200183 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200184 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300185 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300186 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
187 .len = IEEE80211_MAX_DATA_LEN },
188 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
189 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530190 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300191 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530192 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300193 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
194 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
195 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
196 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
197 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100198 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200199 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
200 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700201 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800202 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
203 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
204 .len = NL80211_HT_CAPABILITY_LEN
205 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100206 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530207 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530208 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400209};
210
Johannes Berge31b8212010-10-05 19:39:30 +0200211/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000212static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200213 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200214 [NL80211_KEY_IDX] = { .type = NLA_U8 },
215 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200216 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
218 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200219 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100220 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
221};
222
223/* policy for the key default flags */
224static const struct nla_policy
225nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
226 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
227 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200228};
229
Johannes Bergff1b6e62011-05-04 15:37:28 +0200230/* policy for WoWLAN attributes */
231static const struct nla_policy
232nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
233 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
234 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
235 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
236 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200237 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
238 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
239 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
240 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200241};
242
Johannes Berge5497d72011-07-05 16:35:40 +0200243/* policy for GTK rekey offload attributes */
244static const struct nla_policy
245nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
246 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
247 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
248 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
249};
250
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300251static const struct nla_policy
252nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
253 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_SSID_LEN },
255};
256
Holger Schuriga0438972009-11-11 11:30:02 +0100257/* ifidx get helper */
258static int nl80211_get_ifidx(struct netlink_callback *cb)
259{
260 int res;
261
262 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
263 nl80211_fam.attrbuf, nl80211_fam.maxattr,
264 nl80211_policy);
265 if (res)
266 return res;
267
268 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
269 return -EINVAL;
270
271 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
272 if (!res)
273 return -EINVAL;
274 return res;
275}
276
Johannes Berg67748892010-10-04 21:14:06 +0200277static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
278 struct netlink_callback *cb,
279 struct cfg80211_registered_device **rdev,
280 struct net_device **dev)
281{
282 int ifidx = cb->args[0];
283 int err;
284
285 if (!ifidx)
286 ifidx = nl80211_get_ifidx(cb);
287 if (ifidx < 0)
288 return ifidx;
289
290 cb->args[0] = ifidx;
291
292 rtnl_lock();
293
294 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
295 if (!*dev) {
296 err = -ENODEV;
297 goto out_rtnl;
298 }
299
300 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100301 if (IS_ERR(*rdev)) {
302 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200303 goto out_rtnl;
304 }
305
306 return 0;
307 out_rtnl:
308 rtnl_unlock();
309 return err;
310}
311
312static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
313{
314 cfg80211_unlock_rdev(rdev);
315 rtnl_unlock();
316}
317
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100318/* IE validation */
319static bool is_valid_ie_attr(const struct nlattr *attr)
320{
321 const u8 *pos;
322 int len;
323
324 if (!attr)
325 return true;
326
327 pos = nla_data(attr);
328 len = nla_len(attr);
329
330 while (len) {
331 u8 elemlen;
332
333 if (len < 2)
334 return false;
335 len -= 2;
336
337 elemlen = pos[1];
338 if (elemlen > len)
339 return false;
340
341 len -= elemlen;
342 pos += 2 + elemlen;
343 }
344
345 return true;
346}
347
Johannes Berg55682962007-09-20 13:09:35 -0400348/* message building helper */
349static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
350 int flags, u8 cmd)
351{
352 /* since there is no private header just add the generic one */
353 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
354}
355
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400356static int nl80211_msg_put_channel(struct sk_buff *msg,
357 struct ieee80211_channel *chan)
358{
359 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
360 chan->center_freq);
361
362 if (chan->flags & IEEE80211_CHAN_DISABLED)
363 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
364 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
365 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
366 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
367 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
368 if (chan->flags & IEEE80211_CHAN_RADAR)
369 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
370
371 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
372 DBM_TO_MBM(chan->max_power));
373
374 return 0;
375
376 nla_put_failure:
377 return -ENOBUFS;
378}
379
Johannes Berg55682962007-09-20 13:09:35 -0400380/* netlink command implementations */
381
Johannes Bergb9454e82009-07-08 13:29:08 +0200382struct key_parse {
383 struct key_params p;
384 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200385 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200386 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100387 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200388};
389
390static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
391{
392 struct nlattr *tb[NL80211_KEY_MAX + 1];
393 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
394 nl80211_key_policy);
395 if (err)
396 return err;
397
398 k->def = !!tb[NL80211_KEY_DEFAULT];
399 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
400
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100401 if (k->def) {
402 k->def_uni = true;
403 k->def_multi = true;
404 }
405 if (k->defmgmt)
406 k->def_multi = true;
407
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 if (tb[NL80211_KEY_IDX])
409 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
410
411 if (tb[NL80211_KEY_DATA]) {
412 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
413 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
414 }
415
416 if (tb[NL80211_KEY_SEQ]) {
417 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
418 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
419 }
420
421 if (tb[NL80211_KEY_CIPHER])
422 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
423
Johannes Berge31b8212010-10-05 19:39:30 +0200424 if (tb[NL80211_KEY_TYPE]) {
425 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
426 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
427 return -EINVAL;
428 }
429
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100430 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
431 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100432 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
433 tb[NL80211_KEY_DEFAULT_TYPES],
434 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100435 if (err)
436 return err;
437
438 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
439 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
440 }
441
Johannes Bergb9454e82009-07-08 13:29:08 +0200442 return 0;
443}
444
445static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
446{
447 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
448 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
449 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
450 }
451
452 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
453 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
454 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
455 }
456
457 if (info->attrs[NL80211_ATTR_KEY_IDX])
458 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
459
460 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
461 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
462
463 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
464 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
465
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100466 if (k->def) {
467 k->def_uni = true;
468 k->def_multi = true;
469 }
470 if (k->defmgmt)
471 k->def_multi = true;
472
Johannes Berge31b8212010-10-05 19:39:30 +0200473 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
474 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
475 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
476 return -EINVAL;
477 }
478
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100479 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
480 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
481 int err = nla_parse_nested(
482 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
483 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
484 nl80211_key_default_policy);
485 if (err)
486 return err;
487
488 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
489 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
490 }
491
Johannes Bergb9454e82009-07-08 13:29:08 +0200492 return 0;
493}
494
495static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
496{
497 int err;
498
499 memset(k, 0, sizeof(*k));
500 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200501 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200502
503 if (info->attrs[NL80211_ATTR_KEY])
504 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
505 else
506 err = nl80211_parse_key_old(info, k);
507
508 if (err)
509 return err;
510
511 if (k->def && k->defmgmt)
512 return -EINVAL;
513
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100514 if (k->defmgmt) {
515 if (k->def_uni || !k->def_multi)
516 return -EINVAL;
517 }
518
Johannes Bergb9454e82009-07-08 13:29:08 +0200519 if (k->idx != -1) {
520 if (k->defmgmt) {
521 if (k->idx < 4 || k->idx > 5)
522 return -EINVAL;
523 } else if (k->def) {
524 if (k->idx < 0 || k->idx > 3)
525 return -EINVAL;
526 } else {
527 if (k->idx < 0 || k->idx > 5)
528 return -EINVAL;
529 }
530 }
531
532 return 0;
533}
534
Johannes Bergfffd0932009-07-08 14:22:54 +0200535static struct cfg80211_cached_keys *
536nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
537 struct nlattr *keys)
538{
539 struct key_parse parse;
540 struct nlattr *key;
541 struct cfg80211_cached_keys *result;
542 int rem, err, def = 0;
543
544 result = kzalloc(sizeof(*result), GFP_KERNEL);
545 if (!result)
546 return ERR_PTR(-ENOMEM);
547
548 result->def = -1;
549 result->defmgmt = -1;
550
551 nla_for_each_nested(key, keys, rem) {
552 memset(&parse, 0, sizeof(parse));
553 parse.idx = -1;
554
555 err = nl80211_parse_key_new(key, &parse);
556 if (err)
557 goto error;
558 err = -EINVAL;
559 if (!parse.p.key)
560 goto error;
561 if (parse.idx < 0 || parse.idx > 4)
562 goto error;
563 if (parse.def) {
564 if (def)
565 goto error;
566 def = 1;
567 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100568 if (!parse.def_uni || !parse.def_multi)
569 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200570 } else if (parse.defmgmt)
571 goto error;
572 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200573 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200574 if (err)
575 goto error;
576 result->params[parse.idx].cipher = parse.p.cipher;
577 result->params[parse.idx].key_len = parse.p.key_len;
578 result->params[parse.idx].key = result->data[parse.idx];
579 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
580 }
581
582 return result;
583 error:
584 kfree(result);
585 return ERR_PTR(err);
586}
587
588static int nl80211_key_allowed(struct wireless_dev *wdev)
589{
590 ASSERT_WDEV_LOCK(wdev);
591
Johannes Bergfffd0932009-07-08 14:22:54 +0200592 switch (wdev->iftype) {
593 case NL80211_IFTYPE_AP:
594 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200595 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700596 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200597 break;
598 case NL80211_IFTYPE_ADHOC:
599 if (!wdev->current_bss)
600 return -ENOLINK;
601 break;
602 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200603 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200604 if (wdev->sme_state != CFG80211_SME_CONNECTED)
605 return -ENOLINK;
606 break;
607 default:
608 return -EINVAL;
609 }
610
611 return 0;
612}
613
Johannes Berg7527a782011-05-13 10:58:57 +0200614static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
615{
616 struct nlattr *nl_modes = nla_nest_start(msg, attr);
617 int i;
618
619 if (!nl_modes)
620 goto nla_put_failure;
621
622 i = 0;
623 while (ifmodes) {
624 if (ifmodes & 1)
625 NLA_PUT_FLAG(msg, i);
626 ifmodes >>= 1;
627 i++;
628 }
629
630 nla_nest_end(msg, nl_modes);
631 return 0;
632
633nla_put_failure:
634 return -ENOBUFS;
635}
636
637static int nl80211_put_iface_combinations(struct wiphy *wiphy,
638 struct sk_buff *msg)
639{
640 struct nlattr *nl_combis;
641 int i, j;
642
643 nl_combis = nla_nest_start(msg,
644 NL80211_ATTR_INTERFACE_COMBINATIONS);
645 if (!nl_combis)
646 goto nla_put_failure;
647
648 for (i = 0; i < wiphy->n_iface_combinations; i++) {
649 const struct ieee80211_iface_combination *c;
650 struct nlattr *nl_combi, *nl_limits;
651
652 c = &wiphy->iface_combinations[i];
653
654 nl_combi = nla_nest_start(msg, i + 1);
655 if (!nl_combi)
656 goto nla_put_failure;
657
658 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
659 if (!nl_limits)
660 goto nla_put_failure;
661
662 for (j = 0; j < c->n_limits; j++) {
663 struct nlattr *nl_limit;
664
665 nl_limit = nla_nest_start(msg, j + 1);
666 if (!nl_limit)
667 goto nla_put_failure;
668 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
669 c->limits[j].max);
670 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
671 c->limits[j].types))
672 goto nla_put_failure;
673 nla_nest_end(msg, nl_limit);
674 }
675
676 nla_nest_end(msg, nl_limits);
677
678 if (c->beacon_int_infra_match)
679 NLA_PUT_FLAG(msg,
680 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
681 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
682 c->num_different_channels);
683 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
684 c->max_interfaces);
685
686 nla_nest_end(msg, nl_combi);
687 }
688
689 nla_nest_end(msg, nl_combis);
690
691 return 0;
692nla_put_failure:
693 return -ENOBUFS;
694}
695
Johannes Berg55682962007-09-20 13:09:35 -0400696static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
697 struct cfg80211_registered_device *dev)
698{
699 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100700 struct nlattr *nl_bands, *nl_band;
701 struct nlattr *nl_freqs, *nl_freq;
702 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100703 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100704 enum ieee80211_band band;
705 struct ieee80211_channel *chan;
706 struct ieee80211_rate *rate;
707 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +0200708 const struct ieee80211_txrx_stypes *mgmt_stypes =
709 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400710
711 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
712 if (!hdr)
713 return -1;
714
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500715 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400716 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200717
Johannes Bergf5ea9122009-08-07 16:17:38 +0200718 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
719 cfg80211_rdev_list_generation);
720
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200721 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
722 dev->wiphy.retry_short);
723 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
724 dev->wiphy.retry_long);
725 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
726 dev->wiphy.frag_threshold);
727 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
728 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100729 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
730 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100731 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
732 dev->wiphy.max_scan_ssids);
Luciano Coelho93b6aa62011-07-13 14:57:28 +0300733 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
734 dev->wiphy.max_sched_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200735 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
736 dev->wiphy.max_scan_ie_len);
Luciano Coelho5a865ba2011-07-13 14:57:29 +0300737 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
738 dev->wiphy.max_sched_scan_ie_len);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300739 NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
740 dev->wiphy.max_match_sets);
Johannes Bergee688b002008-01-24 19:38:39 +0100741
Johannes Berge31b8212010-10-05 19:39:30 +0200742 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
743 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
Javier Cardona15d5dda2011-04-07 15:08:28 -0700744 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
745 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
Eliad Pellercedb5412011-08-31 11:29:43 +0300746 if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
747 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530748 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
749 NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300750 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
751 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
752 if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
753 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530754
Johannes Berg25e47c182009-04-02 20:14:06 +0200755 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
756 sizeof(u32) * dev->wiphy.n_cipher_suites,
757 dev->wiphy.cipher_suites);
758
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100759 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
760 dev->wiphy.max_num_pmkids);
761
Johannes Bergc0692b82010-08-27 14:26:53 +0300762 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
763 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
764
Bruno Randolf39fd5de2010-12-16 11:30:28 +0900765 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
766 dev->wiphy.available_antennas_tx);
767 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
768 dev->wiphy.available_antennas_rx);
769
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200770 if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD)
771 NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
772 dev->wiphy.probe_resp_offload);
773
Bruno Randolf7f531e02010-12-16 11:30:22 +0900774 if ((dev->wiphy.available_antennas_tx ||
775 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900776 u32 tx_ant = 0, rx_ant = 0;
777 int res;
778 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
779 if (!res) {
780 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
781 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
782 }
783 }
784
Johannes Berg7527a782011-05-13 10:58:57 +0200785 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
786 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700787 goto nla_put_failure;
788
Johannes Bergee688b002008-01-24 19:38:39 +0100789 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
790 if (!nl_bands)
791 goto nla_put_failure;
792
793 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
794 if (!dev->wiphy.bands[band])
795 continue;
796
797 nl_band = nla_nest_start(msg, band);
798 if (!nl_band)
799 goto nla_put_failure;
800
Johannes Bergd51626d2008-10-09 12:20:13 +0200801 /* add HT info */
802 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
803 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
804 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
805 &dev->wiphy.bands[band]->ht_cap.mcs);
806 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
807 dev->wiphy.bands[band]->ht_cap.cap);
808 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
809 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
810 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
811 dev->wiphy.bands[band]->ht_cap.ampdu_density);
812 }
813
Johannes Bergee688b002008-01-24 19:38:39 +0100814 /* add frequencies */
815 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
816 if (!nl_freqs)
817 goto nla_put_failure;
818
819 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
820 nl_freq = nla_nest_start(msg, i);
821 if (!nl_freq)
822 goto nla_put_failure;
823
824 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100825
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400826 if (nl80211_msg_put_channel(msg, chan))
827 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200828
Johannes Bergee688b002008-01-24 19:38:39 +0100829 nla_nest_end(msg, nl_freq);
830 }
831
832 nla_nest_end(msg, nl_freqs);
833
834 /* add bitrates */
835 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
836 if (!nl_rates)
837 goto nla_put_failure;
838
839 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
840 nl_rate = nla_nest_start(msg, i);
841 if (!nl_rate)
842 goto nla_put_failure;
843
844 rate = &dev->wiphy.bands[band]->bitrates[i];
845 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
846 rate->bitrate);
847 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
848 NLA_PUT_FLAG(msg,
849 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
850
851 nla_nest_end(msg, nl_rate);
852 }
853
854 nla_nest_end(msg, nl_rates);
855
856 nla_nest_end(msg, nl_band);
857 }
858 nla_nest_end(msg, nl_bands);
859
Johannes Berg8fdc6212009-03-14 09:34:01 +0100860 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
861 if (!nl_cmds)
862 goto nla_put_failure;
863
864 i = 0;
865#define CMD(op, n) \
866 do { \
867 if (dev->ops->op) { \
868 i++; \
869 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
870 } \
871 } while (0)
872
873 CMD(add_virtual_intf, NEW_INTERFACE);
874 CMD(change_virtual_intf, SET_INTERFACE);
875 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100876 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100877 CMD(add_station, NEW_STATION);
878 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800879 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100880 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200881 CMD(auth, AUTHENTICATE);
882 CMD(assoc, ASSOCIATE);
883 CMD(deauth, DEAUTHENTICATE);
884 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200885 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100886 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100887 CMD(set_pmksa, SET_PMKSA);
888 CMD(del_pmksa, DEL_PMKSA);
889 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +0100890 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
891 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200892 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f782010-08-12 15:38:38 +0200893 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100894 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100895 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200896 i++;
897 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
898 }
Johannes Bergf444de02010-05-05 15:25:02 +0200899 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400900 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300901 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
902 CMD(tdls_mgmt, TDLS_MGMT);
903 CMD(tdls_oper, TDLS_OPER);
904 }
Luciano Coelho807f8a82011-05-11 17:09:35 +0300905 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
906 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +0100907 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100908 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +0100909 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
910 i++;
911 NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS);
912 }
Johannes Berg8fdc6212009-03-14 09:34:01 +0100913
Kalle Valo4745fc02011-11-17 19:06:10 +0200914#ifdef CONFIG_NL80211_TESTMODE
915 CMD(testmode_cmd, TESTMODE);
916#endif
917
Johannes Berg8fdc6212009-03-14 09:34:01 +0100918#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200919
Johannes Berg6829c872009-07-02 09:13:27 +0200920 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200921 i++;
922 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
923 }
924
Johannes Berg6829c872009-07-02 09:13:27 +0200925 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200926 i++;
927 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
928 }
929
Johannes Berg8fdc6212009-03-14 09:34:01 +0100930 nla_nest_end(msg, nl_cmds);
931
Johannes Berg7c4ef712011-11-18 15:33:48 +0100932 if (dev->ops->remain_on_channel &&
933 dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berga2939112010-12-14 17:54:28 +0100934 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
935 dev->wiphy.max_remain_on_channel_duration);
936
Johannes Berg7c4ef712011-11-18 15:33:48 +0100937 if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100938 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
939
Johannes Berg2e161f782010-08-12 15:38:38 +0200940 if (mgmt_stypes) {
941 u16 stypes;
942 struct nlattr *nl_ftypes, *nl_ifs;
943 enum nl80211_iftype ift;
944
945 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
946 if (!nl_ifs)
947 goto nla_put_failure;
948
949 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
950 nl_ftypes = nla_nest_start(msg, ift);
951 if (!nl_ftypes)
952 goto nla_put_failure;
953 i = 0;
954 stypes = mgmt_stypes[ift].tx;
955 while (stypes) {
956 if (stypes & 1)
957 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
958 (i << 4) | IEEE80211_FTYPE_MGMT);
959 stypes >>= 1;
960 i++;
961 }
962 nla_nest_end(msg, nl_ftypes);
963 }
964
Johannes Berg74b70a42010-08-24 12:15:53 +0200965 nla_nest_end(msg, nl_ifs);
966
Johannes Berg2e161f782010-08-12 15:38:38 +0200967 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
968 if (!nl_ifs)
969 goto nla_put_failure;
970
971 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
972 nl_ftypes = nla_nest_start(msg, ift);
973 if (!nl_ftypes)
974 goto nla_put_failure;
975 i = 0;
976 stypes = mgmt_stypes[ift].rx;
977 while (stypes) {
978 if (stypes & 1)
979 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
980 (i << 4) | IEEE80211_FTYPE_MGMT);
981 stypes >>= 1;
982 i++;
983 }
984 nla_nest_end(msg, nl_ftypes);
985 }
986 nla_nest_end(msg, nl_ifs);
987 }
988
Johannes Bergff1b6e62011-05-04 15:37:28 +0200989 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
990 struct nlattr *nl_wowlan;
991
992 nl_wowlan = nla_nest_start(msg,
993 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
994 if (!nl_wowlan)
995 goto nla_put_failure;
996
997 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
998 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
999 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
1000 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
1001 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
1002 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02001003 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
1004 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
1005 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
1006 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
1007 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
1008 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
1009 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
1010 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
1011 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
1012 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02001013 if (dev->wiphy.wowlan.n_patterns) {
1014 struct nl80211_wowlan_pattern_support pat = {
1015 .max_patterns = dev->wiphy.wowlan.n_patterns,
1016 .min_pattern_len =
1017 dev->wiphy.wowlan.pattern_min_len,
1018 .max_pattern_len =
1019 dev->wiphy.wowlan.pattern_max_len,
1020 };
1021 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1022 sizeof(pat), &pat);
1023 }
1024
1025 nla_nest_end(msg, nl_wowlan);
1026 }
1027
Johannes Berg7527a782011-05-13 10:58:57 +02001028 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1029 dev->wiphy.software_iftypes))
1030 goto nla_put_failure;
1031
1032 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1033 goto nla_put_failure;
1034
Johannes Berg562a7482011-11-07 12:39:33 +01001035 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
1036 NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
1037 dev->wiphy.ap_sme_capa);
1038
Johannes Berg1f074bd2011-11-06 14:13:33 +01001039 NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features);
1040
Ben Greear7e7c8922011-11-18 11:31:59 -08001041 if (dev->wiphy.ht_capa_mod_mask)
1042 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1043 sizeof(*dev->wiphy.ht_capa_mod_mask),
1044 dev->wiphy.ht_capa_mod_mask);
1045
Johannes Berg55682962007-09-20 13:09:35 -04001046 return genlmsg_end(msg, hdr);
1047
1048 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001049 genlmsg_cancel(msg, hdr);
1050 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001051}
1052
1053static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1054{
1055 int idx = 0;
1056 int start = cb->args[0];
1057 struct cfg80211_registered_device *dev;
1058
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001059 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001060 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001061 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1062 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001063 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001064 continue;
1065 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1066 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001067 dev) < 0) {
1068 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001069 break;
Julius Volzb4637272008-07-08 14:02:19 +02001070 }
Johannes Berg55682962007-09-20 13:09:35 -04001071 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001072 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001073
1074 cb->args[0] = idx;
1075
1076 return skb->len;
1077}
1078
1079static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1080{
1081 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001082 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001083
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001084 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001085 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001086 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001087
Johannes Berg4c476992010-10-04 21:36:35 +02001088 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1089 nlmsg_free(msg);
1090 return -ENOBUFS;
1091 }
Johannes Berg55682962007-09-20 13:09:35 -04001092
Johannes Berg134e6372009-07-10 09:51:34 +00001093 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001094}
1095
Jouni Malinen31888482008-10-30 16:59:24 +02001096static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1097 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1098 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1099 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1100 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1101 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1102};
1103
1104static int parse_txq_params(struct nlattr *tb[],
1105 struct ieee80211_txq_params *txq_params)
1106{
Johannes Berga3304b02012-03-28 11:04:24 +02001107 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001108 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1109 !tb[NL80211_TXQ_ATTR_AIFS])
1110 return -EINVAL;
1111
Johannes Berga3304b02012-03-28 11:04:24 +02001112 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001113 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1114 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1115 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1116 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1117
Johannes Berga3304b02012-03-28 11:04:24 +02001118 if (txq_params->ac >= NL80211_NUM_ACS)
1119 return -EINVAL;
1120
Jouni Malinen31888482008-10-30 16:59:24 +02001121 return 0;
1122}
1123
Johannes Bergf444de02010-05-05 15:25:02 +02001124static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1125{
1126 /*
1127 * You can only set the channel explicitly for AP, mesh
1128 * and WDS type interfaces; all others have their channel
1129 * managed via their respective "establish a connection"
1130 * command (connect, join, ...)
1131 *
1132 * Monitors are special as they are normally slaved to
1133 * whatever else is going on, so they behave as though
1134 * you tried setting the wiphy channel itself.
1135 */
1136 return !wdev ||
1137 wdev->iftype == NL80211_IFTYPE_AP ||
1138 wdev->iftype == NL80211_IFTYPE_WDS ||
1139 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001140 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1141 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001142}
1143
1144static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1145 struct wireless_dev *wdev,
1146 struct genl_info *info)
1147{
1148 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1149 u32 freq;
1150 int result;
1151
1152 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1153 return -EINVAL;
1154
1155 if (!nl80211_can_set_dev_channel(wdev))
1156 return -EOPNOTSUPP;
1157
1158 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1159 channel_type = nla_get_u32(info->attrs[
1160 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1161 if (channel_type != NL80211_CHAN_NO_HT &&
1162 channel_type != NL80211_CHAN_HT20 &&
1163 channel_type != NL80211_CHAN_HT40PLUS &&
1164 channel_type != NL80211_CHAN_HT40MINUS)
1165 return -EINVAL;
1166 }
1167
1168 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1169
1170 mutex_lock(&rdev->devlist_mtx);
1171 if (wdev) {
1172 wdev_lock(wdev);
1173 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1174 wdev_unlock(wdev);
1175 } else {
1176 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1177 }
1178 mutex_unlock(&rdev->devlist_mtx);
1179
1180 return result;
1181}
1182
1183static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1184{
Johannes Berg4c476992010-10-04 21:36:35 +02001185 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1186 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001187
Johannes Berg4c476992010-10-04 21:36:35 +02001188 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001189}
1190
Bill Jordane8347eb2010-10-01 13:54:28 -04001191static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1192{
Johannes Berg43b19952010-10-07 13:10:30 +02001193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1194 struct net_device *dev = info->user_ptr[1];
1195 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001196 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001197
1198 if (!info->attrs[NL80211_ATTR_MAC])
1199 return -EINVAL;
1200
Johannes Berg43b19952010-10-07 13:10:30 +02001201 if (netif_running(dev))
1202 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001203
Johannes Berg43b19952010-10-07 13:10:30 +02001204 if (!rdev->ops->set_wds_peer)
1205 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001206
Johannes Berg43b19952010-10-07 13:10:30 +02001207 if (wdev->iftype != NL80211_IFTYPE_WDS)
1208 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001209
1210 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001211 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001212}
1213
1214
Johannes Berg55682962007-09-20 13:09:35 -04001215static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1216{
1217 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001218 struct net_device *netdev = NULL;
1219 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001220 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001221 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001222 u32 changed;
1223 u8 retry_short = 0, retry_long = 0;
1224 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001225 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001226
Johannes Bergf444de02010-05-05 15:25:02 +02001227 /*
1228 * Try to find the wiphy and netdev. Normally this
1229 * function shouldn't need the netdev, but this is
1230 * done for backward compatibility -- previously
1231 * setting the channel was done per wiphy, but now
1232 * it is per netdev. Previous userland like hostapd
1233 * also passed a netdev to set_wiphy, so that it is
1234 * possible to let that go to the right netdev!
1235 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001236 mutex_lock(&cfg80211_mutex);
1237
Johannes Bergf444de02010-05-05 15:25:02 +02001238 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1239 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1240
1241 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1242 if (netdev && netdev->ieee80211_ptr) {
1243 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1244 mutex_lock(&rdev->mtx);
1245 } else
1246 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001247 }
1248
Johannes Bergf444de02010-05-05 15:25:02 +02001249 if (!netdev) {
1250 rdev = __cfg80211_rdev_from_info(info);
1251 if (IS_ERR(rdev)) {
1252 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001253 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001254 }
1255 wdev = NULL;
1256 netdev = NULL;
1257 result = 0;
1258
1259 mutex_lock(&rdev->mtx);
1260 } else if (netif_running(netdev) &&
1261 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1262 wdev = netdev->ieee80211_ptr;
1263 else
1264 wdev = NULL;
1265
1266 /*
1267 * end workaround code, by now the rdev is available
1268 * and locked, and wdev may or may not be NULL.
1269 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001270
1271 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001272 result = cfg80211_dev_rename(
1273 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001274
1275 mutex_unlock(&cfg80211_mutex);
1276
1277 if (result)
1278 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001279
Jouni Malinen31888482008-10-30 16:59:24 +02001280 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1281 struct ieee80211_txq_params txq_params;
1282 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1283
1284 if (!rdev->ops->set_txq_params) {
1285 result = -EOPNOTSUPP;
1286 goto bad_res;
1287 }
1288
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001289 if (!netdev) {
1290 result = -EINVAL;
1291 goto bad_res;
1292 }
1293
Johannes Berg133a3ff2011-11-03 14:50:13 +01001294 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1295 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1296 result = -EINVAL;
1297 goto bad_res;
1298 }
1299
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001300 if (!netif_running(netdev)) {
1301 result = -ENETDOWN;
1302 goto bad_res;
1303 }
1304
Jouni Malinen31888482008-10-30 16:59:24 +02001305 nla_for_each_nested(nl_txq_params,
1306 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1307 rem_txq_params) {
1308 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1309 nla_data(nl_txq_params),
1310 nla_len(nl_txq_params),
1311 txq_params_policy);
1312 result = parse_txq_params(tb, &txq_params);
1313 if (result)
1314 goto bad_res;
1315
1316 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001317 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001318 &txq_params);
1319 if (result)
1320 goto bad_res;
1321 }
1322 }
1323
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001324 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001325 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001326 if (result)
1327 goto bad_res;
1328 }
1329
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001330 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1331 enum nl80211_tx_power_setting type;
1332 int idx, mbm = 0;
1333
1334 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001335 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001336 goto bad_res;
1337 }
1338
1339 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1340 type = nla_get_u32(info->attrs[idx]);
1341
1342 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1343 (type != NL80211_TX_POWER_AUTOMATIC)) {
1344 result = -EINVAL;
1345 goto bad_res;
1346 }
1347
1348 if (type != NL80211_TX_POWER_AUTOMATIC) {
1349 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1350 mbm = nla_get_u32(info->attrs[idx]);
1351 }
1352
1353 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1354 if (result)
1355 goto bad_res;
1356 }
1357
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001358 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1359 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1360 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001361 if ((!rdev->wiphy.available_antennas_tx &&
1362 !rdev->wiphy.available_antennas_rx) ||
1363 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001364 result = -EOPNOTSUPP;
1365 goto bad_res;
1366 }
1367
1368 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1369 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1370
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001371 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001372 * available antenna masks, except for the "all" mask */
1373 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1374 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001375 result = -EINVAL;
1376 goto bad_res;
1377 }
1378
Bruno Randolf7f531e02010-12-16 11:30:22 +09001379 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1380 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001381
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001382 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1383 if (result)
1384 goto bad_res;
1385 }
1386
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001387 changed = 0;
1388
1389 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1390 retry_short = nla_get_u8(
1391 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1392 if (retry_short == 0) {
1393 result = -EINVAL;
1394 goto bad_res;
1395 }
1396 changed |= WIPHY_PARAM_RETRY_SHORT;
1397 }
1398
1399 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1400 retry_long = nla_get_u8(
1401 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1402 if (retry_long == 0) {
1403 result = -EINVAL;
1404 goto bad_res;
1405 }
1406 changed |= WIPHY_PARAM_RETRY_LONG;
1407 }
1408
1409 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1410 frag_threshold = nla_get_u32(
1411 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1412 if (frag_threshold < 256) {
1413 result = -EINVAL;
1414 goto bad_res;
1415 }
1416 if (frag_threshold != (u32) -1) {
1417 /*
1418 * Fragments (apart from the last one) are required to
1419 * have even length. Make the fragmentation code
1420 * simpler by stripping LSB should someone try to use
1421 * odd threshold value.
1422 */
1423 frag_threshold &= ~0x1;
1424 }
1425 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1426 }
1427
1428 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1429 rts_threshold = nla_get_u32(
1430 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1431 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1432 }
1433
Lukáš Turek81077e82009-12-21 22:50:47 +01001434 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1435 coverage_class = nla_get_u8(
1436 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1437 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1438 }
1439
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001440 if (changed) {
1441 u8 old_retry_short, old_retry_long;
1442 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001443 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001444
1445 if (!rdev->ops->set_wiphy_params) {
1446 result = -EOPNOTSUPP;
1447 goto bad_res;
1448 }
1449
1450 old_retry_short = rdev->wiphy.retry_short;
1451 old_retry_long = rdev->wiphy.retry_long;
1452 old_frag_threshold = rdev->wiphy.frag_threshold;
1453 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001454 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001455
1456 if (changed & WIPHY_PARAM_RETRY_SHORT)
1457 rdev->wiphy.retry_short = retry_short;
1458 if (changed & WIPHY_PARAM_RETRY_LONG)
1459 rdev->wiphy.retry_long = retry_long;
1460 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1461 rdev->wiphy.frag_threshold = frag_threshold;
1462 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1463 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001464 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1465 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001466
1467 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1468 if (result) {
1469 rdev->wiphy.retry_short = old_retry_short;
1470 rdev->wiphy.retry_long = old_retry_long;
1471 rdev->wiphy.frag_threshold = old_frag_threshold;
1472 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001473 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001474 }
1475 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001476
Johannes Berg306d6112008-12-08 12:39:04 +01001477 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001478 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001479 if (netdev)
1480 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001481 return result;
1482}
1483
1484
1485static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001486 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001487 struct net_device *dev)
1488{
1489 void *hdr;
1490
1491 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1492 if (!hdr)
1493 return -1;
1494
1495 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001496 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001497 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001498 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001499
1500 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1501 rdev->devlist_generation ^
1502 (cfg80211_rdev_list_generation << 2));
1503
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001504 if (rdev->ops->get_channel) {
1505 struct ieee80211_channel *chan;
1506 enum nl80211_channel_type channel_type;
1507
1508 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
1509 if (chan) {
1510 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
1511 chan->center_freq);
1512 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1513 channel_type);
1514 }
1515 }
1516
Johannes Berg55682962007-09-20 13:09:35 -04001517 return genlmsg_end(msg, hdr);
1518
1519 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001520 genlmsg_cancel(msg, hdr);
1521 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001522}
1523
1524static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1525{
1526 int wp_idx = 0;
1527 int if_idx = 0;
1528 int wp_start = cb->args[0];
1529 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001530 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001531 struct wireless_dev *wdev;
1532
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001533 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001534 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1535 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001536 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001537 if (wp_idx < wp_start) {
1538 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001539 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001540 }
Johannes Berg55682962007-09-20 13:09:35 -04001541 if_idx = 0;
1542
Johannes Bergf5ea9122009-08-07 16:17:38 +02001543 mutex_lock(&rdev->devlist_mtx);
1544 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001545 if (if_idx < if_start) {
1546 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001547 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001548 }
Johannes Berg55682962007-09-20 13:09:35 -04001549 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1550 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001551 rdev, wdev->netdev) < 0) {
1552 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001553 goto out;
1554 }
1555 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001556 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001557 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001558
1559 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001560 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001561 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001562 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001563
1564 cb->args[0] = wp_idx;
1565 cb->args[1] = if_idx;
1566
1567 return skb->len;
1568}
1569
1570static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1571{
1572 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001573 struct cfg80211_registered_device *dev = info->user_ptr[0];
1574 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001575
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001577 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001578 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001579
Johannes Bergd7264052009-04-19 16:23:20 +02001580 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001581 dev, netdev) < 0) {
1582 nlmsg_free(msg);
1583 return -ENOBUFS;
1584 }
Johannes Berg55682962007-09-20 13:09:35 -04001585
Johannes Berg134e6372009-07-10 09:51:34 +00001586 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001587}
1588
Michael Wu66f7ac52008-01-31 19:48:22 +01001589static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1590 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1591 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1592 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1593 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1594 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1595};
1596
1597static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1598{
1599 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1600 int flag;
1601
1602 *mntrflags = 0;
1603
1604 if (!nla)
1605 return -EINVAL;
1606
1607 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1608 nla, mntr_flags_policy))
1609 return -EINVAL;
1610
1611 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1612 if (flags[flag])
1613 *mntrflags |= (1<<flag);
1614
1615 return 0;
1616}
1617
Johannes Berg9bc383d2009-11-19 11:55:19 +01001618static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001619 struct net_device *netdev, u8 use_4addr,
1620 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001621{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001622 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001623 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001624 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001625 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001626 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001627
1628 switch (iftype) {
1629 case NL80211_IFTYPE_AP_VLAN:
1630 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1631 return 0;
1632 break;
1633 case NL80211_IFTYPE_STATION:
1634 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1635 return 0;
1636 break;
1637 default:
1638 break;
1639 }
1640
1641 return -EOPNOTSUPP;
1642}
1643
Johannes Berg55682962007-09-20 13:09:35 -04001644static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1645{
Johannes Berg4c476992010-10-04 21:36:35 +02001646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001647 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001648 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001649 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001650 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001651 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001652 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001653
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001654 memset(&params, 0, sizeof(params));
1655
Johannes Berg04a773a2009-04-19 21:24:32 +02001656 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001657
Johannes Berg723b0382008-09-16 20:22:09 +02001658 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001659 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001660 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001661 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001662 if (ntype > NL80211_IFTYPE_MAX)
1663 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001664 }
1665
Johannes Berg92ffe052008-09-16 20:39:36 +02001666 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001667 struct wireless_dev *wdev = dev->ieee80211_ptr;
1668
Johannes Berg4c476992010-10-04 21:36:35 +02001669 if (ntype != NL80211_IFTYPE_MESH_POINT)
1670 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001671 if (netif_running(dev))
1672 return -EBUSY;
1673
1674 wdev_lock(wdev);
1675 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1676 IEEE80211_MAX_MESH_ID_LEN);
1677 wdev->mesh_id_up_len =
1678 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1679 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1680 wdev->mesh_id_up_len);
1681 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001682 }
1683
Felix Fietkau8b787642009-11-10 18:53:10 +01001684 if (info->attrs[NL80211_ATTR_4ADDR]) {
1685 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1686 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001687 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001688 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001689 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001690 } else {
1691 params.use_4addr = -1;
1692 }
1693
Johannes Berg92ffe052008-09-16 20:39:36 +02001694 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001695 if (ntype != NL80211_IFTYPE_MONITOR)
1696 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001697 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1698 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001699 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001700 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001701
1702 flags = &_flags;
1703 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001704 }
Johannes Berg3b858752009-03-12 09:55:09 +01001705
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001706 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001707 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001708 else
1709 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001710
Johannes Berg9bc383d2009-11-19 11:55:19 +01001711 if (!err && params.use_4addr != -1)
1712 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1713
Johannes Berg55682962007-09-20 13:09:35 -04001714 return err;
1715}
1716
1717static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1718{
Johannes Berg4c476992010-10-04 21:36:35 +02001719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001720 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001721 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001722 int err;
1723 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001724 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001725
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001726 memset(&params, 0, sizeof(params));
1727
Johannes Berg55682962007-09-20 13:09:35 -04001728 if (!info->attrs[NL80211_ATTR_IFNAME])
1729 return -EINVAL;
1730
1731 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1732 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1733 if (type > NL80211_IFTYPE_MAX)
1734 return -EINVAL;
1735 }
1736
Johannes Berg79c97e92009-07-07 03:56:12 +02001737 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001738 !(rdev->wiphy.interface_modes & (1 << type)))
1739 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001740
Johannes Berg9bc383d2009-11-19 11:55:19 +01001741 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001742 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001743 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001744 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001745 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001746 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001747
Michael Wu66f7ac52008-01-31 19:48:22 +01001748 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1749 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1750 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001751 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001752 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001753 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001754 if (IS_ERR(dev))
1755 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001756
Johannes Berg29cbe682010-12-03 09:20:44 +01001757 if (type == NL80211_IFTYPE_MESH_POINT &&
1758 info->attrs[NL80211_ATTR_MESH_ID]) {
1759 struct wireless_dev *wdev = dev->ieee80211_ptr;
1760
1761 wdev_lock(wdev);
1762 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1763 IEEE80211_MAX_MESH_ID_LEN);
1764 wdev->mesh_id_up_len =
1765 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1766 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1767 wdev->mesh_id_up_len);
1768 wdev_unlock(wdev);
1769 }
1770
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001771 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001772}
1773
1774static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1775{
Johannes Berg4c476992010-10-04 21:36:35 +02001776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1777 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001778
Johannes Berg4c476992010-10-04 21:36:35 +02001779 if (!rdev->ops->del_virtual_intf)
1780 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001781
Johannes Berg4c476992010-10-04 21:36:35 +02001782 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001783}
1784
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001785static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1786{
1787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1788 struct net_device *dev = info->user_ptr[1];
1789 u16 noack_map;
1790
1791 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1792 return -EINVAL;
1793
1794 if (!rdev->ops->set_noack_map)
1795 return -EOPNOTSUPP;
1796
1797 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1798
1799 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1800}
1801
Johannes Berg41ade002007-12-19 02:03:29 +01001802struct get_key_cookie {
1803 struct sk_buff *msg;
1804 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001805 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001806};
1807
1808static void get_key_callback(void *c, struct key_params *params)
1809{
Johannes Bergb9454e82009-07-08 13:29:08 +02001810 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001811 struct get_key_cookie *cookie = c;
1812
1813 if (params->key)
1814 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1815 params->key_len, params->key);
1816
1817 if (params->seq)
1818 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1819 params->seq_len, params->seq);
1820
1821 if (params->cipher)
1822 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1823 params->cipher);
1824
Johannes Bergb9454e82009-07-08 13:29:08 +02001825 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1826 if (!key)
1827 goto nla_put_failure;
1828
1829 if (params->key)
1830 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1831 params->key_len, params->key);
1832
1833 if (params->seq)
1834 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1835 params->seq_len, params->seq);
1836
1837 if (params->cipher)
1838 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1839 params->cipher);
1840
1841 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1842
1843 nla_nest_end(cookie->msg, key);
1844
Johannes Berg41ade002007-12-19 02:03:29 +01001845 return;
1846 nla_put_failure:
1847 cookie->error = 1;
1848}
1849
1850static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1851{
Johannes Berg4c476992010-10-04 21:36:35 +02001852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001853 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001854 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001855 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001856 const u8 *mac_addr = NULL;
1857 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001858 struct get_key_cookie cookie = {
1859 .error = 0,
1860 };
1861 void *hdr;
1862 struct sk_buff *msg;
1863
1864 if (info->attrs[NL80211_ATTR_KEY_IDX])
1865 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1866
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001867 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001868 return -EINVAL;
1869
1870 if (info->attrs[NL80211_ATTR_MAC])
1871 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1872
Johannes Berge31b8212010-10-05 19:39:30 +02001873 pairwise = !!mac_addr;
1874 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1875 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1876 if (kt >= NUM_NL80211_KEYTYPES)
1877 return -EINVAL;
1878 if (kt != NL80211_KEYTYPE_GROUP &&
1879 kt != NL80211_KEYTYPE_PAIRWISE)
1880 return -EINVAL;
1881 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1882 }
1883
Johannes Berg4c476992010-10-04 21:36:35 +02001884 if (!rdev->ops->get_key)
1885 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001886
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001887 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001888 if (!msg)
1889 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001890
1891 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1892 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001893 if (IS_ERR(hdr))
1894 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001895
1896 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001897 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001898
1899 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1900 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1901 if (mac_addr)
1902 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1903
Johannes Berge31b8212010-10-05 19:39:30 +02001904 if (pairwise && mac_addr &&
1905 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1906 return -ENOENT;
1907
1908 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1909 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001910
1911 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001912 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001913
1914 if (cookie.error)
1915 goto nla_put_failure;
1916
1917 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001918 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001919
1920 nla_put_failure:
1921 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001922 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001923 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001924 return err;
1925}
1926
1927static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1928{
Johannes Berg4c476992010-10-04 21:36:35 +02001929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001930 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001931 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001932 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001933
Johannes Bergb9454e82009-07-08 13:29:08 +02001934 err = nl80211_parse_key(info, &key);
1935 if (err)
1936 return err;
1937
1938 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001939 return -EINVAL;
1940
Johannes Bergb9454e82009-07-08 13:29:08 +02001941 /* only support setting default key */
1942 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001943 return -EINVAL;
1944
Johannes Bergfffd0932009-07-08 14:22:54 +02001945 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001946
1947 if (key.def) {
1948 if (!rdev->ops->set_default_key) {
1949 err = -EOPNOTSUPP;
1950 goto out;
1951 }
1952
1953 err = nl80211_key_allowed(dev->ieee80211_ptr);
1954 if (err)
1955 goto out;
1956
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001957 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1958 key.def_uni, key.def_multi);
1959
1960 if (err)
1961 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001962
Johannes Berg3d23e342009-09-29 23:27:28 +02001963#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001964 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001965#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001966 } else {
1967 if (key.def_uni || !key.def_multi) {
1968 err = -EINVAL;
1969 goto out;
1970 }
1971
1972 if (!rdev->ops->set_default_mgmt_key) {
1973 err = -EOPNOTSUPP;
1974 goto out;
1975 }
1976
1977 err = nl80211_key_allowed(dev->ieee80211_ptr);
1978 if (err)
1979 goto out;
1980
1981 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1982 dev, key.idx);
1983 if (err)
1984 goto out;
1985
1986#ifdef CONFIG_CFG80211_WEXT
1987 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1988#endif
1989 }
1990
1991 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001992 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001993
Johannes Berg41ade002007-12-19 02:03:29 +01001994 return err;
1995}
1996
1997static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1998{
Johannes Berg4c476992010-10-04 21:36:35 +02001999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002000 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002001 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002002 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002003 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002004
Johannes Bergb9454e82009-07-08 13:29:08 +02002005 err = nl80211_parse_key(info, &key);
2006 if (err)
2007 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002008
Johannes Bergb9454e82009-07-08 13:29:08 +02002009 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002010 return -EINVAL;
2011
Johannes Berg41ade002007-12-19 02:03:29 +01002012 if (info->attrs[NL80211_ATTR_MAC])
2013 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2014
Johannes Berge31b8212010-10-05 19:39:30 +02002015 if (key.type == -1) {
2016 if (mac_addr)
2017 key.type = NL80211_KEYTYPE_PAIRWISE;
2018 else
2019 key.type = NL80211_KEYTYPE_GROUP;
2020 }
2021
2022 /* for now */
2023 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2024 key.type != NL80211_KEYTYPE_GROUP)
2025 return -EINVAL;
2026
Johannes Berg4c476992010-10-04 21:36:35 +02002027 if (!rdev->ops->add_key)
2028 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002029
Johannes Berge31b8212010-10-05 19:39:30 +02002030 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2031 key.type == NL80211_KEYTYPE_PAIRWISE,
2032 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002033 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002034
2035 wdev_lock(dev->ieee80211_ptr);
2036 err = nl80211_key_allowed(dev->ieee80211_ptr);
2037 if (!err)
2038 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002039 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002040 mac_addr, &key.p);
2041 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002042
Johannes Berg41ade002007-12-19 02:03:29 +01002043 return err;
2044}
2045
2046static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2047{
Johannes Berg4c476992010-10-04 21:36:35 +02002048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002049 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002050 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002051 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002052 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002053
Johannes Bergb9454e82009-07-08 13:29:08 +02002054 err = nl80211_parse_key(info, &key);
2055 if (err)
2056 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002057
2058 if (info->attrs[NL80211_ATTR_MAC])
2059 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2060
Johannes Berge31b8212010-10-05 19:39:30 +02002061 if (key.type == -1) {
2062 if (mac_addr)
2063 key.type = NL80211_KEYTYPE_PAIRWISE;
2064 else
2065 key.type = NL80211_KEYTYPE_GROUP;
2066 }
2067
2068 /* for now */
2069 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2070 key.type != NL80211_KEYTYPE_GROUP)
2071 return -EINVAL;
2072
Johannes Berg4c476992010-10-04 21:36:35 +02002073 if (!rdev->ops->del_key)
2074 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002075
Johannes Bergfffd0932009-07-08 14:22:54 +02002076 wdev_lock(dev->ieee80211_ptr);
2077 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002078
2079 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2080 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2081 err = -ENOENT;
2082
Johannes Bergfffd0932009-07-08 14:22:54 +02002083 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002084 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2085 key.type == NL80211_KEYTYPE_PAIRWISE,
2086 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002087
Johannes Berg3d23e342009-09-29 23:27:28 +02002088#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002089 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002090 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002091 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002092 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002093 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2094 }
2095#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002096 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002097
Johannes Berg41ade002007-12-19 02:03:29 +01002098 return err;
2099}
2100
Johannes Berg88600202012-02-13 15:17:18 +01002101static int nl80211_parse_beacon(struct genl_info *info,
2102 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002103{
Johannes Berg88600202012-02-13 15:17:18 +01002104 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002105
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002106 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2107 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2108 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2109 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002110 return -EINVAL;
2111
Johannes Berg88600202012-02-13 15:17:18 +01002112 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002113
Johannes Berged1b6cc2007-12-19 02:03:32 +01002114 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002115 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2116 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2117 if (!bcn->head_len)
2118 return -EINVAL;
2119 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002120 }
2121
2122 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002123 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2124 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002125 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002126 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002127 }
2128
Johannes Berg4c476992010-10-04 21:36:35 +02002129 if (!haveinfo)
2130 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002131
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002132 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002133 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2134 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002135 }
2136
2137 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002138 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002139 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002140 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002141 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2142 }
2143
2144 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002145 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002146 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002147 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002148 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2149 }
2150
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002151 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002152 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002153 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002154 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002155 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2156 }
2157
Johannes Berg88600202012-02-13 15:17:18 +01002158 return 0;
2159}
2160
2161static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2162{
2163 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2164 struct net_device *dev = info->user_ptr[1];
2165 struct wireless_dev *wdev = dev->ieee80211_ptr;
2166 struct cfg80211_ap_settings params;
2167 int err;
2168
2169 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2170 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2171 return -EOPNOTSUPP;
2172
2173 if (!rdev->ops->start_ap)
2174 return -EOPNOTSUPP;
2175
2176 if (wdev->beacon_interval)
2177 return -EALREADY;
2178
2179 memset(&params, 0, sizeof(params));
2180
2181 /* these are required for START_AP */
2182 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2183 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2184 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2185 return -EINVAL;
2186
2187 err = nl80211_parse_beacon(info, &params.beacon);
2188 if (err)
2189 return err;
2190
2191 params.beacon_interval =
2192 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2193 params.dtim_period =
2194 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2195
2196 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2197 if (err)
2198 return err;
2199
2200 /*
2201 * In theory, some of these attributes should be required here
2202 * but since they were not used when the command was originally
2203 * added, keep them optional for old user space programs to let
2204 * them continue to work with drivers that do not need the
2205 * additional information -- drivers must check!
2206 */
2207 if (info->attrs[NL80211_ATTR_SSID]) {
2208 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2209 params.ssid_len =
2210 nla_len(info->attrs[NL80211_ATTR_SSID]);
2211 if (params.ssid_len == 0 ||
2212 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2213 return -EINVAL;
2214 }
2215
2216 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2217 params.hidden_ssid = nla_get_u32(
2218 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2219 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2220 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2221 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2222 return -EINVAL;
2223 }
2224
2225 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2226
2227 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2228 params.auth_type = nla_get_u32(
2229 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2230 if (!nl80211_valid_auth_type(params.auth_type))
2231 return -EINVAL;
2232 } else
2233 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2234
2235 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2236 NL80211_MAX_NR_CIPHER_SUITES);
2237 if (err)
2238 return err;
2239
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302240 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2241 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2242 return -EOPNOTSUPP;
2243 params.inactivity_timeout = nla_get_u16(
2244 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2245 }
2246
Johannes Berg88600202012-02-13 15:17:18 +01002247 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2248 if (!err)
2249 wdev->beacon_interval = params.beacon_interval;
Johannes Berg56d18932011-05-09 18:41:15 +02002250 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002251}
2252
Johannes Berg88600202012-02-13 15:17:18 +01002253static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2254{
2255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2256 struct net_device *dev = info->user_ptr[1];
2257 struct wireless_dev *wdev = dev->ieee80211_ptr;
2258 struct cfg80211_beacon_data params;
2259 int err;
2260
2261 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2262 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2263 return -EOPNOTSUPP;
2264
2265 if (!rdev->ops->change_beacon)
2266 return -EOPNOTSUPP;
2267
2268 if (!wdev->beacon_interval)
2269 return -EINVAL;
2270
2271 err = nl80211_parse_beacon(info, &params);
2272 if (err)
2273 return err;
2274
2275 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2276}
2277
2278static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002279{
Johannes Berg4c476992010-10-04 21:36:35 +02002280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2281 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002282 struct wireless_dev *wdev = dev->ieee80211_ptr;
2283 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002284
Johannes Berg88600202012-02-13 15:17:18 +01002285 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002286 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002287
Johannes Berg074ac8d2010-09-16 14:58:22 +02002288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2290 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002291
Johannes Berg88600202012-02-13 15:17:18 +01002292 if (!wdev->beacon_interval)
2293 return -ENOENT;
2294
2295 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002296 if (!err)
2297 wdev->beacon_interval = 0;
2298 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002299}
2300
Johannes Berg5727ef12007-12-19 02:03:34 +01002301static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2302 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2303 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2304 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002305 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002306 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002307 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002308};
2309
Johannes Bergeccb8e82009-05-11 21:57:56 +03002310static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002311 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002312 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002313{
2314 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002315 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002316 int flag;
2317
Johannes Bergeccb8e82009-05-11 21:57:56 +03002318 /*
2319 * Try parsing the new attribute first so userspace
2320 * can specify both for older kernels.
2321 */
2322 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2323 if (nla) {
2324 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002325
Johannes Bergeccb8e82009-05-11 21:57:56 +03002326 sta_flags = nla_data(nla);
2327 params->sta_flags_mask = sta_flags->mask;
2328 params->sta_flags_set = sta_flags->set;
2329 if ((params->sta_flags_mask |
2330 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2331 return -EINVAL;
2332 return 0;
2333 }
2334
2335 /* if present, parse the old attribute */
2336
2337 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002338 if (!nla)
2339 return 0;
2340
2341 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2342 nla, sta_flags_policy))
2343 return -EINVAL;
2344
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002345 /*
2346 * Only allow certain flags for interface types so that
2347 * other attributes are silently ignored. Remember that
2348 * this is backward compatibility code with old userspace
2349 * and shouldn't be hit in other cases anyway.
2350 */
2351 switch (iftype) {
2352 case NL80211_IFTYPE_AP:
2353 case NL80211_IFTYPE_AP_VLAN:
2354 case NL80211_IFTYPE_P2P_GO:
2355 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2356 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2357 BIT(NL80211_STA_FLAG_WME) |
2358 BIT(NL80211_STA_FLAG_MFP);
2359 break;
2360 case NL80211_IFTYPE_P2P_CLIENT:
2361 case NL80211_IFTYPE_STATION:
2362 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2363 BIT(NL80211_STA_FLAG_TDLS_PEER);
2364 break;
2365 case NL80211_IFTYPE_MESH_POINT:
2366 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2367 BIT(NL80211_STA_FLAG_MFP) |
2368 BIT(NL80211_STA_FLAG_AUTHORIZED);
2369 default:
2370 return -EINVAL;
2371 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002372
2373 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2374 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002375 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002376
2377 return 0;
2378}
2379
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002380static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2381 int attr)
2382{
2383 struct nlattr *rate;
2384 u16 bitrate;
2385
2386 rate = nla_nest_start(msg, attr);
2387 if (!rate)
2388 goto nla_put_failure;
2389
2390 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2391 bitrate = cfg80211_calculate_bitrate(info);
2392 if (bitrate > 0)
2393 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2394
2395 if (info->flags & RATE_INFO_FLAGS_MCS)
2396 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2397 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2398 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2399 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2400 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2401
2402 nla_nest_end(msg, rate);
2403 return true;
2404
2405nla_put_failure:
2406 return false;
2407}
2408
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002409static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002410 int flags,
2411 struct cfg80211_registered_device *rdev,
2412 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002413 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002414{
2415 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002416 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002417
2418 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2419 if (!hdr)
2420 return -1;
2421
2422 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2423 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2424
Johannes Bergf5ea9122009-08-07 16:17:38 +02002425 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2426
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002427 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2428 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002429 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302430 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2431 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2432 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002433 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2434 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2435 sinfo->inactive_time);
2436 if (sinfo->filled & STATION_INFO_RX_BYTES)
2437 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2438 sinfo->rx_bytes);
2439 if (sinfo->filled & STATION_INFO_TX_BYTES)
2440 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2441 sinfo->tx_bytes);
2442 if (sinfo->filled & STATION_INFO_LLID)
2443 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2444 sinfo->llid);
2445 if (sinfo->filled & STATION_INFO_PLID)
2446 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2447 sinfo->plid);
2448 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2449 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2450 sinfo->plink_state);
John W. Linville66266b32012-03-15 13:25:41 -04002451 switch (rdev->wiphy.signal_type) {
2452 case CFG80211_SIGNAL_TYPE_MBM:
2453 if (sinfo->filled & STATION_INFO_SIGNAL)
2454 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2455 sinfo->signal);
2456 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2457 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2458 sinfo->signal_avg);
2459 break;
2460 default:
2461 break;
2462 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002463 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002464 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2465 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002466 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002467 }
2468 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2469 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2470 NL80211_STA_INFO_RX_BITRATE))
2471 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002472 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002473 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2474 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2475 sinfo->rx_packets);
2476 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2477 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2478 sinfo->tx_packets);
Bruno Randolfb206b4ef2010-10-06 18:34:12 +09002479 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2480 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2481 sinfo->tx_retries);
2482 if (sinfo->filled & STATION_INFO_TX_FAILED)
2483 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2484 sinfo->tx_failed);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002485 if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT)
2486 NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS,
2487 sinfo->beacon_loss_count);
Paul Stewartf4263c92011-03-31 09:25:41 -07002488 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2489 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2490 if (!bss_param)
2491 goto nla_put_failure;
2492
2493 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2494 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2495 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2496 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2497 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2498 NLA_PUT_FLAG(msg,
2499 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2500 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2501 sinfo->bss_param.dtim_period);
2502 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2503 sinfo->bss_param.beacon_interval);
2504
2505 nla_nest_end(msg, bss_param);
2506 }
Helmut Schaabb6e7532011-10-13 16:30:39 +02002507 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2508 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2509 sizeof(struct nl80211_sta_flag_update),
2510 &sinfo->sta_flags);
Javier Cardonad299a1f2012-03-31 11:31:33 -07002511 if (sinfo->filled & STATION_INFO_T_OFFSET)
2512 NLA_PUT_U64(msg, NL80211_STA_INFO_T_OFFSET,
2513 sinfo->t_offset);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002514 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002515
Felix Fietkau040bdf72011-08-10 19:00:33 -06002516 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002517 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2518 sinfo->assoc_req_ies);
2519
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002520 return genlmsg_end(msg, hdr);
2521
2522 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002523 genlmsg_cancel(msg, hdr);
2524 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002525}
2526
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002527static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002528 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002529{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002530 struct station_info sinfo;
2531 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002532 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002533 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002534 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002535 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002536
Johannes Berg67748892010-10-04 21:14:06 +02002537 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2538 if (err)
2539 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002540
2541 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002542 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002543 goto out_err;
2544 }
2545
Johannes Bergbba95fe2008-07-29 13:22:51 +02002546 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002547 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002548 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2549 mac_addr, &sinfo);
2550 if (err == -ENOENT)
2551 break;
2552 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002553 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002554
2555 if (nl80211_send_station(skb,
2556 NETLINK_CB(cb->skb).pid,
2557 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002558 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002559 &sinfo) < 0)
2560 goto out;
2561
2562 sta_idx++;
2563 }
2564
2565
2566 out:
2567 cb->args[1] = sta_idx;
2568 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002569 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002570 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002571
2572 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002573}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002574
Johannes Berg5727ef12007-12-19 02:03:34 +01002575static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2576{
Johannes Berg4c476992010-10-04 21:36:35 +02002577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2578 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002579 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002580 struct sk_buff *msg;
2581 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002582 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002583
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002584 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002585
2586 if (!info->attrs[NL80211_ATTR_MAC])
2587 return -EINVAL;
2588
2589 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2590
Johannes Berg4c476992010-10-04 21:36:35 +02002591 if (!rdev->ops->get_station)
2592 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002593
Johannes Berg79c97e92009-07-07 03:56:12 +02002594 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002595 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002596 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002597
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002599 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002600 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002601
2602 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002603 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002604 nlmsg_free(msg);
2605 return -ENOBUFS;
2606 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002607
Johannes Berg4c476992010-10-04 21:36:35 +02002608 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002609}
2610
2611/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002612 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002613 */
Johannes Berg80b99892011-11-18 16:23:01 +01002614static struct net_device *get_vlan(struct genl_info *info,
2615 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002616{
Johannes Berg463d0182009-07-14 00:33:35 +02002617 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002618 struct net_device *v;
2619 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002620
Johannes Berg80b99892011-11-18 16:23:01 +01002621 if (!vlanattr)
2622 return NULL;
2623
2624 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2625 if (!v)
2626 return ERR_PTR(-ENODEV);
2627
2628 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2629 ret = -EINVAL;
2630 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002631 }
Johannes Berg80b99892011-11-18 16:23:01 +01002632
2633 if (!netif_running(v)) {
2634 ret = -ENETDOWN;
2635 goto error;
2636 }
2637
2638 return v;
2639 error:
2640 dev_put(v);
2641 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002642}
2643
2644static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2645{
Johannes Berg4c476992010-10-04 21:36:35 +02002646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002647 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002648 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002649 struct station_parameters params;
2650 u8 *mac_addr = NULL;
2651
2652 memset(&params, 0, sizeof(params));
2653
2654 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002655 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002656
2657 if (info->attrs[NL80211_ATTR_STA_AID])
2658 return -EINVAL;
2659
2660 if (!info->attrs[NL80211_ATTR_MAC])
2661 return -EINVAL;
2662
2663 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2664
2665 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2666 params.supported_rates =
2667 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2668 params.supported_rates_len =
2669 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2670 }
2671
2672 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2673 params.listen_interval =
2674 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2675
Jouni Malinen36aedc92008-08-25 11:58:58 +03002676 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2677 params.ht_capa =
2678 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2679
Johannes Bergbdd90d52011-12-14 12:20:27 +01002680 if (!rdev->ops->change_station)
2681 return -EOPNOTSUPP;
2682
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002683 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002684 return -EINVAL;
2685
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002686 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2687 params.plink_action =
2688 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2689
Javier Cardona9c3990a2011-05-03 16:57:11 -07002690 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2691 params.plink_state =
2692 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2693
Johannes Berga97f4422009-06-18 17:23:43 +02002694 switch (dev->ieee80211_ptr->iftype) {
2695 case NL80211_IFTYPE_AP:
2696 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002697 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002698 /* disallow mesh-specific things */
2699 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002700 return -EINVAL;
2701
2702 /* TDLS can't be set, ... */
2703 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2704 return -EINVAL;
2705 /*
2706 * ... but don't bother the driver with it. This works around
2707 * a hostapd/wpa_supplicant issue -- it always includes the
2708 * TLDS_PEER flag in the mask even for AP mode.
2709 */
2710 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2711
2712 /* accept only the listed bits */
2713 if (params.sta_flags_mask &
2714 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2715 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2716 BIT(NL80211_STA_FLAG_WME) |
2717 BIT(NL80211_STA_FLAG_MFP)))
2718 return -EINVAL;
2719
2720 /* must be last in here for error handling */
2721 params.vlan = get_vlan(info, rdev);
2722 if (IS_ERR(params.vlan))
2723 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002724 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002725 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002726 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002727 /*
2728 * Don't allow userspace to change the TDLS_PEER flag,
2729 * but silently ignore attempts to change it since we
2730 * don't have state here to verify that it doesn't try
2731 * to change the flag.
2732 */
2733 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002734 /* fall through */
2735 case NL80211_IFTYPE_ADHOC:
2736 /* disallow things sta doesn't support */
2737 if (params.plink_action)
2738 return -EINVAL;
2739 if (params.ht_capa)
2740 return -EINVAL;
2741 if (params.listen_interval >= 0)
2742 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002743 /* reject any changes other than AUTHORIZED */
2744 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2745 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002746 break;
2747 case NL80211_IFTYPE_MESH_POINT:
2748 /* disallow things mesh doesn't support */
2749 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002750 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002751 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002752 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002753 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002754 return -EINVAL;
2755 /*
2756 * No special handling for TDLS here -- the userspace
2757 * mesh code doesn't have this bug.
2758 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07002759 if (params.sta_flags_mask &
2760 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002761 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002762 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01002763 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002764 break;
2765 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002766 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02002767 }
2768
Johannes Bergbdd90d52011-12-14 12:20:27 +01002769 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002770
Johannes Berg79c97e92009-07-07 03:56:12 +02002771 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002772
Johannes Berg5727ef12007-12-19 02:03:34 +01002773 if (params.vlan)
2774 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002775
Johannes Berg5727ef12007-12-19 02:03:34 +01002776 return err;
2777}
2778
Eliad Pellerc75786c2011-08-23 14:37:46 +03002779static struct nla_policy
2780nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2781 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2782 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2783};
2784
Johannes Berg5727ef12007-12-19 02:03:34 +01002785static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2786{
Johannes Berg4c476992010-10-04 21:36:35 +02002787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002788 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002789 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002790 struct station_parameters params;
2791 u8 *mac_addr = NULL;
2792
2793 memset(&params, 0, sizeof(params));
2794
2795 if (!info->attrs[NL80211_ATTR_MAC])
2796 return -EINVAL;
2797
Johannes Berg5727ef12007-12-19 02:03:34 +01002798 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2799 return -EINVAL;
2800
2801 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2802 return -EINVAL;
2803
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002804 if (!info->attrs[NL80211_ATTR_STA_AID])
2805 return -EINVAL;
2806
Johannes Berg5727ef12007-12-19 02:03:34 +01002807 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2808 params.supported_rates =
2809 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2810 params.supported_rates_len =
2811 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2812 params.listen_interval =
2813 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002814
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002815 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2816 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2817 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002818
Jouni Malinen36aedc92008-08-25 11:58:58 +03002819 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2820 params.ht_capa =
2821 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002822
Javier Cardona96b78df2011-04-07 15:08:33 -07002823 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2824 params.plink_action =
2825 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2826
Johannes Bergbdd90d52011-12-14 12:20:27 +01002827 if (!rdev->ops->add_station)
2828 return -EOPNOTSUPP;
2829
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002830 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002831 return -EINVAL;
2832
Johannes Bergbdd90d52011-12-14 12:20:27 +01002833 switch (dev->ieee80211_ptr->iftype) {
2834 case NL80211_IFTYPE_AP:
2835 case NL80211_IFTYPE_AP_VLAN:
2836 case NL80211_IFTYPE_P2P_GO:
2837 /* parse WME attributes if sta is WME capable */
2838 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2839 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
2840 info->attrs[NL80211_ATTR_STA_WME]) {
2841 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2842 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002843
Johannes Bergbdd90d52011-12-14 12:20:27 +01002844 nla = info->attrs[NL80211_ATTR_STA_WME];
2845 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2846 nl80211_sta_wme_policy);
2847 if (err)
2848 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002849
Johannes Bergbdd90d52011-12-14 12:20:27 +01002850 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2851 params.uapsd_queues =
2852 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
2853 if (params.uapsd_queues &
2854 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2855 return -EINVAL;
2856
2857 if (tb[NL80211_STA_WME_MAX_SP])
2858 params.max_sp =
2859 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
2860
2861 if (params.max_sp &
2862 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2863 return -EINVAL;
2864
2865 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
2866 }
2867 /* TDLS peers cannot be added */
2868 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02002869 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002870 /* but don't bother the driver with it */
2871 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03002872
Johannes Bergbdd90d52011-12-14 12:20:27 +01002873 /* must be last in here for error handling */
2874 params.vlan = get_vlan(info, rdev);
2875 if (IS_ERR(params.vlan))
2876 return PTR_ERR(params.vlan);
2877 break;
2878 case NL80211_IFTYPE_MESH_POINT:
2879 /* TDLS peers cannot be added */
2880 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02002881 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002882 break;
2883 case NL80211_IFTYPE_STATION:
2884 /* Only TDLS peers can be added */
2885 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2886 return -EINVAL;
2887 /* Can only add if TDLS ... */
2888 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
2889 return -EOPNOTSUPP;
2890 /* ... with external setup is supported */
2891 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
2892 return -EOPNOTSUPP;
2893 break;
2894 default:
2895 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002896 }
2897
Johannes Bergbdd90d52011-12-14 12:20:27 +01002898 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002899
Johannes Berg79c97e92009-07-07 03:56:12 +02002900 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002901
Johannes Berg5727ef12007-12-19 02:03:34 +01002902 if (params.vlan)
2903 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002904 return err;
2905}
2906
2907static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2908{
Johannes Berg4c476992010-10-04 21:36:35 +02002909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2910 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002911 u8 *mac_addr = NULL;
2912
2913 if (info->attrs[NL80211_ATTR_MAC])
2914 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2915
Johannes Berge80cf852009-05-11 14:43:13 +02002916 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002917 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002919 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2920 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002921
Johannes Berg4c476992010-10-04 21:36:35 +02002922 if (!rdev->ops->del_station)
2923 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002924
Johannes Berg4c476992010-10-04 21:36:35 +02002925 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002926}
2927
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002928static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2929 int flags, struct net_device *dev,
2930 u8 *dst, u8 *next_hop,
2931 struct mpath_info *pinfo)
2932{
2933 void *hdr;
2934 struct nlattr *pinfoattr;
2935
2936 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2937 if (!hdr)
2938 return -1;
2939
2940 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2941 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2942 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2943
Johannes Bergf5ea9122009-08-07 16:17:38 +02002944 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2945
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002946 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2947 if (!pinfoattr)
2948 goto nla_put_failure;
2949 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2950 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2951 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002952 if (pinfo->filled & MPATH_INFO_SN)
2953 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2954 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002955 if (pinfo->filled & MPATH_INFO_METRIC)
2956 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2957 pinfo->metric);
2958 if (pinfo->filled & MPATH_INFO_EXPTIME)
2959 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2960 pinfo->exptime);
2961 if (pinfo->filled & MPATH_INFO_FLAGS)
2962 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2963 pinfo->flags);
2964 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2965 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2966 pinfo->discovery_timeout);
2967 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2968 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2969 pinfo->discovery_retries);
2970
2971 nla_nest_end(msg, pinfoattr);
2972
2973 return genlmsg_end(msg, hdr);
2974
2975 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002976 genlmsg_cancel(msg, hdr);
2977 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002978}
2979
2980static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002981 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002982{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002983 struct mpath_info pinfo;
2984 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002985 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002986 u8 dst[ETH_ALEN];
2987 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002988 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002989 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002990
Johannes Berg67748892010-10-04 21:14:06 +02002991 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2992 if (err)
2993 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002994
2995 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002996 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002997 goto out_err;
2998 }
2999
Jouni Malineneec60b02009-03-20 21:21:19 +02003000 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3001 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003002 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003003 }
3004
Johannes Bergbba95fe2008-07-29 13:22:51 +02003005 while (1) {
3006 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3007 dst, next_hop, &pinfo);
3008 if (err == -ENOENT)
3009 break;
3010 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003011 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003012
3013 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3014 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3015 netdev, dst, next_hop,
3016 &pinfo) < 0)
3017 goto out;
3018
3019 path_idx++;
3020 }
3021
3022
3023 out:
3024 cb->args[1] = path_idx;
3025 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003026 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003027 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003028 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003029}
3030
3031static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3032{
Johannes Berg4c476992010-10-04 21:36:35 +02003033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003034 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003035 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003036 struct mpath_info pinfo;
3037 struct sk_buff *msg;
3038 u8 *dst = NULL;
3039 u8 next_hop[ETH_ALEN];
3040
3041 memset(&pinfo, 0, sizeof(pinfo));
3042
3043 if (!info->attrs[NL80211_ATTR_MAC])
3044 return -EINVAL;
3045
3046 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3047
Johannes Berg4c476992010-10-04 21:36:35 +02003048 if (!rdev->ops->get_mpath)
3049 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003050
Johannes Berg4c476992010-10-04 21:36:35 +02003051 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3052 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003053
Johannes Berg79c97e92009-07-07 03:56:12 +02003054 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003055 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003056 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003057
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003059 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003060 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003061
3062 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003063 dev, dst, next_hop, &pinfo) < 0) {
3064 nlmsg_free(msg);
3065 return -ENOBUFS;
3066 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003067
Johannes Berg4c476992010-10-04 21:36:35 +02003068 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003069}
3070
3071static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3072{
Johannes Berg4c476992010-10-04 21:36:35 +02003073 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3074 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003075 u8 *dst = NULL;
3076 u8 *next_hop = NULL;
3077
3078 if (!info->attrs[NL80211_ATTR_MAC])
3079 return -EINVAL;
3080
3081 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3082 return -EINVAL;
3083
3084 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3085 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3086
Johannes Berg4c476992010-10-04 21:36:35 +02003087 if (!rdev->ops->change_mpath)
3088 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003089
Johannes Berg4c476992010-10-04 21:36:35 +02003090 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3091 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003092
Johannes Berg4c476992010-10-04 21:36:35 +02003093 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003094}
Johannes Berg4c476992010-10-04 21:36:35 +02003095
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003096static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3097{
Johannes Berg4c476992010-10-04 21:36:35 +02003098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3099 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003100 u8 *dst = NULL;
3101 u8 *next_hop = NULL;
3102
3103 if (!info->attrs[NL80211_ATTR_MAC])
3104 return -EINVAL;
3105
3106 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3107 return -EINVAL;
3108
3109 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3110 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3111
Johannes Berg4c476992010-10-04 21:36:35 +02003112 if (!rdev->ops->add_mpath)
3113 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003114
Johannes Berg4c476992010-10-04 21:36:35 +02003115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3116 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003117
Johannes Berg4c476992010-10-04 21:36:35 +02003118 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003119}
3120
3121static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3122{
Johannes Berg4c476992010-10-04 21:36:35 +02003123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3124 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003125 u8 *dst = NULL;
3126
3127 if (info->attrs[NL80211_ATTR_MAC])
3128 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3129
Johannes Berg4c476992010-10-04 21:36:35 +02003130 if (!rdev->ops->del_mpath)
3131 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003132
Johannes Berg4c476992010-10-04 21:36:35 +02003133 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003134}
3135
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003136static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3137{
Johannes Berg4c476992010-10-04 21:36:35 +02003138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3139 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003140 struct bss_parameters params;
3141
3142 memset(&params, 0, sizeof(params));
3143 /* default to not changing parameters */
3144 params.use_cts_prot = -1;
3145 params.use_short_preamble = -1;
3146 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003147 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003148 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003149
3150 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3151 params.use_cts_prot =
3152 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3153 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3154 params.use_short_preamble =
3155 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3156 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3157 params.use_short_slot_time =
3158 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003159 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3160 params.basic_rates =
3161 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3162 params.basic_rates_len =
3163 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3164 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003165 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3166 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003167 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3168 params.ht_opmode =
3169 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003170
Johannes Berg4c476992010-10-04 21:36:35 +02003171 if (!rdev->ops->change_bss)
3172 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003173
Johannes Berg074ac8d2010-09-16 14:58:22 +02003174 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003175 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3176 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003177
Johannes Berg4c476992010-10-04 21:36:35 +02003178 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003179}
3180
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003181static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003182 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3183 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3184 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3185 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3186 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3187 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3188};
3189
3190static int parse_reg_rule(struct nlattr *tb[],
3191 struct ieee80211_reg_rule *reg_rule)
3192{
3193 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3194 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3195
3196 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3197 return -EINVAL;
3198 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3199 return -EINVAL;
3200 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3201 return -EINVAL;
3202 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3203 return -EINVAL;
3204 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3205 return -EINVAL;
3206
3207 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3208
3209 freq_range->start_freq_khz =
3210 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3211 freq_range->end_freq_khz =
3212 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3213 freq_range->max_bandwidth_khz =
3214 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3215
3216 power_rule->max_eirp =
3217 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3218
3219 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3220 power_rule->max_antenna_gain =
3221 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3222
3223 return 0;
3224}
3225
3226static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3227{
3228 int r;
3229 char *data = NULL;
3230
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003231 /*
3232 * You should only get this when cfg80211 hasn't yet initialized
3233 * completely when built-in to the kernel right between the time
3234 * window between nl80211_init() and regulatory_init(), if that is
3235 * even possible.
3236 */
3237 mutex_lock(&cfg80211_mutex);
3238 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003239 mutex_unlock(&cfg80211_mutex);
3240 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003241 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003242 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003243
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003244 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3245 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003246
3247 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3248
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003249 r = regulatory_hint_user(data);
3250
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003251 return r;
3252}
3253
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003254static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003255 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003256{
Johannes Berg4c476992010-10-04 21:36:35 +02003257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003258 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003259 struct wireless_dev *wdev = dev->ieee80211_ptr;
3260 struct mesh_config cur_params;
3261 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003262 void *hdr;
3263 struct nlattr *pinfoattr;
3264 struct sk_buff *msg;
3265
Johannes Berg29cbe682010-12-03 09:20:44 +01003266 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3267 return -EOPNOTSUPP;
3268
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003269 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003270 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003271
Johannes Berg29cbe682010-12-03 09:20:44 +01003272 wdev_lock(wdev);
3273 /* If not connected, get default parameters */
3274 if (!wdev->mesh_id_len)
3275 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3276 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003277 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003278 &cur_params);
3279 wdev_unlock(wdev);
3280
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003281 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003282 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003283
3284 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003286 if (!msg)
3287 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003288 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003289 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003290 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003291 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003292 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003293 if (!pinfoattr)
3294 goto nla_put_failure;
3295 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3296 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3297 cur_params.dot11MeshRetryTimeout);
3298 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3299 cur_params.dot11MeshConfirmTimeout);
3300 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3301 cur_params.dot11MeshHoldingTimeout);
3302 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3303 cur_params.dot11MeshMaxPeerLinks);
3304 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3305 cur_params.dot11MeshMaxRetries);
3306 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3307 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01003308 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3309 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003310 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3311 cur_params.auto_open_plinks);
Javier Cardonad299a1f2012-03-31 11:31:33 -07003312 NLA_PUT_U32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3313 cur_params.dot11MeshNbrOffsetMaxNeighbor);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003314 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3315 cur_params.dot11MeshHWMPmaxPREQretries);
3316 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3317 cur_params.path_refresh_time);
3318 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3319 cur_params.min_discovery_timeout);
3320 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3321 cur_params.dot11MeshHWMPactivePathTimeout);
3322 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3323 cur_params.dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003324 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3325 cur_params.dot11MeshHWMPperrMinInterval);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003326 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3327 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00003328 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3329 cur_params.dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -07003330 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3331 cur_params.dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -07003332 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3333 cur_params.dot11MeshGateAnnouncementProtocol);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003334 NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING,
3335 cur_params.dot11MeshForwarding);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003336 NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
3337 cur_params.rssi_threshold);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003338 nla_nest_end(msg, pinfoattr);
3339 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003340 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003341
Johannes Berg3b858752009-03-12 09:55:09 +01003342 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003343 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003344 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003345 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003346 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003347}
3348
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003349static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003350 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3351 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3352 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3353 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3354 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3355 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003356 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003357 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003358 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003359
3360 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3361 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3362 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3363 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3364 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003365 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003366 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003367 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003368 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003369 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003370 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Ashok Nagarajan55335132012-02-28 17:04:08 -08003371 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32},
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003372};
3373
Javier Cardonac80d5452010-12-16 17:37:49 -08003374static const struct nla_policy
3375 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003376 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003377 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3378 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003379 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003380 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08003381 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003382 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003383};
3384
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003385static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003386 struct mesh_config *cfg,
3387 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003388{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003389 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003390 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003391
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003392#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3393do {\
3394 if (table[attr_num]) {\
3395 cfg->param = nla_fn(table[attr_num]); \
3396 mask |= (1 << (attr_num - 1)); \
3397 } \
3398} while (0);\
3399
3400
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003401 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003402 return -EINVAL;
3403 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003404 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003405 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003406 return -EINVAL;
3407
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003408 /* This makes sure that there aren't more than 32 mesh config
3409 * parameters (otherwise our bitfield scheme would not work.) */
3410 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3411
3412 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3414 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3415 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3416 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3417 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3418 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3419 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3420 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3421 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3422 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3423 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3424 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003425 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3426 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003427 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3428 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
Javier Cardonad299a1f2012-03-31 11:31:33 -07003429 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
3430 mask, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3431 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3433 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3434 nla_get_u8);
3435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3436 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3437 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3438 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3439 nla_get_u16);
3440 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3441 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3442 nla_get_u32);
3443 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3444 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3445 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003446 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
3447 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3448 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003449 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3450 dot11MeshHWMPnetDiameterTraversalTime,
3451 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3452 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003453 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3454 dot11MeshHWMPRootMode, mask,
3455 NL80211_MESHCONF_HWMP_ROOTMODE,
3456 nla_get_u8);
Javier Cardona0507e152011-08-09 16:45:10 -07003457 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3458 dot11MeshHWMPRannInterval, mask,
3459 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3460 nla_get_u16);
Javier Cardona16dd7262011-08-09 16:45:11 -07003461 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3462 dot11MeshGateAnnouncementProtocol, mask,
3463 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3464 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003465 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
3466 mask, NL80211_MESHCONF_FORWARDING, nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003467 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
3468 mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003469 if (mask_out)
3470 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003471
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003472 return 0;
3473
3474#undef FILL_IN_MESH_PARAM_IF_SET
3475}
3476
Javier Cardonac80d5452010-12-16 17:37:49 -08003477static int nl80211_parse_mesh_setup(struct genl_info *info,
3478 struct mesh_setup *setup)
3479{
3480 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3481
3482 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3483 return -EINVAL;
3484 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3485 info->attrs[NL80211_ATTR_MESH_SETUP],
3486 nl80211_mesh_setup_params_policy))
3487 return -EINVAL;
3488
Javier Cardonad299a1f2012-03-31 11:31:33 -07003489 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3490 setup->sync_method =
3491 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3492 IEEE80211_SYNC_METHOD_VENDOR :
3493 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3494
Javier Cardonac80d5452010-12-16 17:37:49 -08003495 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3496 setup->path_sel_proto =
3497 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3498 IEEE80211_PATH_PROTOCOL_VENDOR :
3499 IEEE80211_PATH_PROTOCOL_HWMP;
3500
3501 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3502 setup->path_metric =
3503 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3504 IEEE80211_PATH_METRIC_VENDOR :
3505 IEEE80211_PATH_METRIC_AIRTIME;
3506
Javier Cardona581a8b02011-04-07 15:08:27 -07003507
3508 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003509 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003510 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003511 if (!is_valid_ie_attr(ieattr))
3512 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003513 setup->ie = nla_data(ieattr);
3514 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003515 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003516 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3517 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003518
3519 return 0;
3520}
3521
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003522static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003523 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003524{
3525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3526 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003527 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003528 struct mesh_config cfg;
3529 u32 mask;
3530 int err;
3531
Johannes Berg29cbe682010-12-03 09:20:44 +01003532 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3533 return -EOPNOTSUPP;
3534
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003535 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003536 return -EOPNOTSUPP;
3537
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003538 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003539 if (err)
3540 return err;
3541
Johannes Berg29cbe682010-12-03 09:20:44 +01003542 wdev_lock(wdev);
3543 if (!wdev->mesh_id_len)
3544 err = -ENOLINK;
3545
3546 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003547 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003548 mask, &cfg);
3549
3550 wdev_unlock(wdev);
3551
3552 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003553}
3554
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003555static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3556{
3557 struct sk_buff *msg;
3558 void *hdr = NULL;
3559 struct nlattr *nl_reg_rules;
3560 unsigned int i;
3561 int err = -EINVAL;
3562
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003563 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003564
3565 if (!cfg80211_regdomain)
3566 goto out;
3567
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003569 if (!msg) {
3570 err = -ENOBUFS;
3571 goto out;
3572 }
3573
3574 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3575 NL80211_CMD_GET_REG);
3576 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003577 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003578
3579 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3580 cfg80211_regdomain->alpha2);
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003581 if (cfg80211_regdomain->dfs_region)
3582 NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
3583 cfg80211_regdomain->dfs_region);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003584
3585 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3586 if (!nl_reg_rules)
3587 goto nla_put_failure;
3588
3589 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3590 struct nlattr *nl_reg_rule;
3591 const struct ieee80211_reg_rule *reg_rule;
3592 const struct ieee80211_freq_range *freq_range;
3593 const struct ieee80211_power_rule *power_rule;
3594
3595 reg_rule = &cfg80211_regdomain->reg_rules[i];
3596 freq_range = &reg_rule->freq_range;
3597 power_rule = &reg_rule->power_rule;
3598
3599 nl_reg_rule = nla_nest_start(msg, i);
3600 if (!nl_reg_rule)
3601 goto nla_put_failure;
3602
3603 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3604 reg_rule->flags);
3605 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3606 freq_range->start_freq_khz);
3607 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3608 freq_range->end_freq_khz);
3609 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3610 freq_range->max_bandwidth_khz);
3611 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3612 power_rule->max_antenna_gain);
3613 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3614 power_rule->max_eirp);
3615
3616 nla_nest_end(msg, nl_reg_rule);
3617 }
3618
3619 nla_nest_end(msg, nl_reg_rules);
3620
3621 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003622 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003623 goto out;
3624
3625nla_put_failure:
3626 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003627put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003628 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003629 err = -EMSGSIZE;
3630out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003631 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003632 return err;
3633}
3634
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003635static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3636{
3637 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3638 struct nlattr *nl_reg_rule;
3639 char *alpha2 = NULL;
3640 int rem_reg_rules = 0, r = 0;
3641 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003642 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003643 struct ieee80211_regdomain *rd = NULL;
3644
3645 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3646 return -EINVAL;
3647
3648 if (!info->attrs[NL80211_ATTR_REG_RULES])
3649 return -EINVAL;
3650
3651 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3652
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003653 if (info->attrs[NL80211_ATTR_DFS_REGION])
3654 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3655
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003656 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3657 rem_reg_rules) {
3658 num_rules++;
3659 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003660 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003661 }
3662
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003663 mutex_lock(&cfg80211_mutex);
3664
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003665 if (!reg_is_valid_request(alpha2)) {
3666 r = -EINVAL;
3667 goto bad_reg;
3668 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003669
3670 size_of_regd = sizeof(struct ieee80211_regdomain) +
3671 (num_rules * sizeof(struct ieee80211_reg_rule));
3672
3673 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003674 if (!rd) {
3675 r = -ENOMEM;
3676 goto bad_reg;
3677 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003678
3679 rd->n_reg_rules = num_rules;
3680 rd->alpha2[0] = alpha2[0];
3681 rd->alpha2[1] = alpha2[1];
3682
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003683 /*
3684 * Disable DFS master mode if the DFS region was
3685 * not supported or known on this kernel.
3686 */
3687 if (reg_supported_dfs_region(dfs_region))
3688 rd->dfs_region = dfs_region;
3689
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003690 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3691 rem_reg_rules) {
3692 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3693 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3694 reg_rule_policy);
3695 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3696 if (r)
3697 goto bad_reg;
3698
3699 rule_idx++;
3700
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003701 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3702 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003703 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003704 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003705 }
3706
3707 BUG_ON(rule_idx != num_rules);
3708
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003709 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003710
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003711 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003712
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003713 return r;
3714
Johannes Bergd2372b32008-10-24 20:32:20 +02003715 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003716 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003717 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003718 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003719}
3720
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003721static int validate_scan_freqs(struct nlattr *freqs)
3722{
3723 struct nlattr *attr1, *attr2;
3724 int n_channels = 0, tmp1, tmp2;
3725
3726 nla_for_each_nested(attr1, freqs, tmp1) {
3727 n_channels++;
3728 /*
3729 * Some hardware has a limited channel list for
3730 * scanning, and it is pretty much nonsensical
3731 * to scan for a channel twice, so disallow that
3732 * and don't require drivers to check that the
3733 * channel list they get isn't longer than what
3734 * they can scan, as long as they can scan all
3735 * the channels they registered at once.
3736 */
3737 nla_for_each_nested(attr2, freqs, tmp2)
3738 if (attr1 != attr2 &&
3739 nla_get_u32(attr1) == nla_get_u32(attr2))
3740 return 0;
3741 }
3742
3743 return n_channels;
3744}
3745
Johannes Berg2a519312009-02-10 21:25:55 +01003746static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3747{
Johannes Berg4c476992010-10-04 21:36:35 +02003748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3749 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003750 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003751 struct nlattr *attr;
3752 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003753 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003754 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003755
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003756 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3757 return -EINVAL;
3758
Johannes Berg79c97e92009-07-07 03:56:12 +02003759 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003760
Johannes Berg4c476992010-10-04 21:36:35 +02003761 if (!rdev->ops->scan)
3762 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003763
Johannes Berg4c476992010-10-04 21:36:35 +02003764 if (rdev->scan_req)
3765 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003766
3767 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003768 n_channels = validate_scan_freqs(
3769 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003770 if (!n_channels)
3771 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003772 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003773 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003774 n_channels = 0;
3775
Johannes Berg2a519312009-02-10 21:25:55 +01003776 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3777 if (wiphy->bands[band])
3778 n_channels += wiphy->bands[band]->n_channels;
3779 }
3780
3781 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3782 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3783 n_ssids++;
3784
Johannes Berg4c476992010-10-04 21:36:35 +02003785 if (n_ssids > wiphy->max_scan_ssids)
3786 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003787
Jouni Malinen70692ad2009-02-16 19:39:13 +02003788 if (info->attrs[NL80211_ATTR_IE])
3789 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3790 else
3791 ie_len = 0;
3792
Johannes Berg4c476992010-10-04 21:36:35 +02003793 if (ie_len > wiphy->max_scan_ie_len)
3794 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003795
Johannes Berg2a519312009-02-10 21:25:55 +01003796 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003797 + sizeof(*request->ssids) * n_ssids
3798 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003799 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003800 if (!request)
3801 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003802
Johannes Berg2a519312009-02-10 21:25:55 +01003803 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003804 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003805 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003806 if (ie_len) {
3807 if (request->ssids)
3808 request->ie = (void *)(request->ssids + n_ssids);
3809 else
3810 request->ie = (void *)(request->channels + n_channels);
3811 }
Johannes Berg2a519312009-02-10 21:25:55 +01003812
Johannes Berg584991d2009-11-02 13:32:03 +01003813 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003814 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3815 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003816 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003817 struct ieee80211_channel *chan;
3818
3819 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3820
3821 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003822 err = -EINVAL;
3823 goto out_free;
3824 }
Johannes Berg584991d2009-11-02 13:32:03 +01003825
3826 /* ignore disabled channels */
3827 if (chan->flags & IEEE80211_CHAN_DISABLED)
3828 continue;
3829
3830 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003831 i++;
3832 }
3833 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003834 enum ieee80211_band band;
3835
Johannes Berg2a519312009-02-10 21:25:55 +01003836 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003837 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3838 int j;
3839 if (!wiphy->bands[band])
3840 continue;
3841 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003842 struct ieee80211_channel *chan;
3843
3844 chan = &wiphy->bands[band]->channels[j];
3845
3846 if (chan->flags & IEEE80211_CHAN_DISABLED)
3847 continue;
3848
3849 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003850 i++;
3851 }
3852 }
3853 }
3854
Johannes Berg584991d2009-11-02 13:32:03 +01003855 if (!i) {
3856 err = -EINVAL;
3857 goto out_free;
3858 }
3859
3860 request->n_channels = i;
3861
Johannes Berg2a519312009-02-10 21:25:55 +01003862 i = 0;
3863 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3864 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003865 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003866 err = -EINVAL;
3867 goto out_free;
3868 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003869 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003870 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003871 i++;
3872 }
3873 }
3874
Jouni Malinen70692ad2009-02-16 19:39:13 +02003875 if (info->attrs[NL80211_ATTR_IE]) {
3876 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02003877 memcpy((void *)request->ie,
3878 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003879 request->ie_len);
3880 }
3881
Johannes Berg34850ab2011-07-18 18:08:35 +02003882 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003883 if (wiphy->bands[i])
3884 request->rates[i] =
3885 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003886
3887 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3888 nla_for_each_nested(attr,
3889 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3890 tmp) {
3891 enum ieee80211_band band = nla_type(attr);
3892
Dan Carpenter84404622011-07-29 11:52:18 +03003893 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003894 err = -EINVAL;
3895 goto out_free;
3896 }
3897 err = ieee80211_get_ratemask(wiphy->bands[band],
3898 nla_data(attr),
3899 nla_len(attr),
3900 &request->rates[band]);
3901 if (err)
3902 goto out_free;
3903 }
3904 }
3905
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05303906 request->no_cck =
3907 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3908
Johannes Berg463d0182009-07-14 00:33:35 +02003909 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003910 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003911
Johannes Berg79c97e92009-07-07 03:56:12 +02003912 rdev->scan_req = request;
3913 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003914
Johannes Berg463d0182009-07-14 00:33:35 +02003915 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003916 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003917 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003918 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003919 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003920 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003921 kfree(request);
3922 }
Johannes Berg3b858752009-03-12 09:55:09 +01003923
Johannes Berg2a519312009-02-10 21:25:55 +01003924 return err;
3925}
3926
Luciano Coelho807f8a82011-05-11 17:09:35 +03003927static int nl80211_start_sched_scan(struct sk_buff *skb,
3928 struct genl_info *info)
3929{
3930 struct cfg80211_sched_scan_request *request;
3931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3932 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003933 struct nlattr *attr;
3934 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003935 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003936 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003937 enum ieee80211_band band;
3938 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003939 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003940
3941 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3942 !rdev->ops->sched_scan_start)
3943 return -EOPNOTSUPP;
3944
3945 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3946 return -EINVAL;
3947
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003948 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3949 return -EINVAL;
3950
3951 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3952 if (interval == 0)
3953 return -EINVAL;
3954
Luciano Coelho807f8a82011-05-11 17:09:35 +03003955 wiphy = &rdev->wiphy;
3956
3957 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3958 n_channels = validate_scan_freqs(
3959 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3960 if (!n_channels)
3961 return -EINVAL;
3962 } else {
3963 n_channels = 0;
3964
3965 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3966 if (wiphy->bands[band])
3967 n_channels += wiphy->bands[band]->n_channels;
3968 }
3969
3970 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3971 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3972 tmp)
3973 n_ssids++;
3974
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003975 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003976 return -EINVAL;
3977
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003978 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3979 nla_for_each_nested(attr,
3980 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3981 tmp)
3982 n_match_sets++;
3983
3984 if (n_match_sets > wiphy->max_match_sets)
3985 return -EINVAL;
3986
Luciano Coelho807f8a82011-05-11 17:09:35 +03003987 if (info->attrs[NL80211_ATTR_IE])
3988 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3989 else
3990 ie_len = 0;
3991
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003992 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003993 return -EINVAL;
3994
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003995 mutex_lock(&rdev->sched_scan_mtx);
3996
3997 if (rdev->sched_scan_req) {
3998 err = -EINPROGRESS;
3999 goto out;
4000 }
4001
Luciano Coelho807f8a82011-05-11 17:09:35 +03004002 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004003 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004004 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004005 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004006 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004007 if (!request) {
4008 err = -ENOMEM;
4009 goto out;
4010 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004011
4012 if (n_ssids)
4013 request->ssids = (void *)&request->channels[n_channels];
4014 request->n_ssids = n_ssids;
4015 if (ie_len) {
4016 if (request->ssids)
4017 request->ie = (void *)(request->ssids + n_ssids);
4018 else
4019 request->ie = (void *)(request->channels + n_channels);
4020 }
4021
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004022 if (n_match_sets) {
4023 if (request->ie)
4024 request->match_sets = (void *)(request->ie + ie_len);
4025 else if (request->ssids)
4026 request->match_sets =
4027 (void *)(request->ssids + n_ssids);
4028 else
4029 request->match_sets =
4030 (void *)(request->channels + n_channels);
4031 }
4032 request->n_match_sets = n_match_sets;
4033
Luciano Coelho807f8a82011-05-11 17:09:35 +03004034 i = 0;
4035 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4036 /* user specified, bail out if channel not found */
4037 nla_for_each_nested(attr,
4038 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4039 tmp) {
4040 struct ieee80211_channel *chan;
4041
4042 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4043
4044 if (!chan) {
4045 err = -EINVAL;
4046 goto out_free;
4047 }
4048
4049 /* ignore disabled channels */
4050 if (chan->flags & IEEE80211_CHAN_DISABLED)
4051 continue;
4052
4053 request->channels[i] = chan;
4054 i++;
4055 }
4056 } else {
4057 /* all channels */
4058 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4059 int j;
4060 if (!wiphy->bands[band])
4061 continue;
4062 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4063 struct ieee80211_channel *chan;
4064
4065 chan = &wiphy->bands[band]->channels[j];
4066
4067 if (chan->flags & IEEE80211_CHAN_DISABLED)
4068 continue;
4069
4070 request->channels[i] = chan;
4071 i++;
4072 }
4073 }
4074 }
4075
4076 if (!i) {
4077 err = -EINVAL;
4078 goto out_free;
4079 }
4080
4081 request->n_channels = i;
4082
4083 i = 0;
4084 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4085 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4086 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004087 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004088 err = -EINVAL;
4089 goto out_free;
4090 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004091 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004092 memcpy(request->ssids[i].ssid, nla_data(attr),
4093 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004094 i++;
4095 }
4096 }
4097
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004098 i = 0;
4099 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4100 nla_for_each_nested(attr,
4101 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4102 tmp) {
4103 struct nlattr *ssid;
4104
4105 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4106 nla_data(attr), nla_len(attr),
4107 nl80211_match_policy);
4108 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
4109 if (ssid) {
4110 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4111 err = -EINVAL;
4112 goto out_free;
4113 }
4114 memcpy(request->match_sets[i].ssid.ssid,
4115 nla_data(ssid), nla_len(ssid));
4116 request->match_sets[i].ssid.ssid_len =
4117 nla_len(ssid);
4118 }
4119 i++;
4120 }
4121 }
4122
Luciano Coelho807f8a82011-05-11 17:09:35 +03004123 if (info->attrs[NL80211_ATTR_IE]) {
4124 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4125 memcpy((void *)request->ie,
4126 nla_data(info->attrs[NL80211_ATTR_IE]),
4127 request->ie_len);
4128 }
4129
4130 request->dev = dev;
4131 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004132 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004133
4134 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4135 if (!err) {
4136 rdev->sched_scan_req = request;
4137 nl80211_send_sched_scan(rdev, dev,
4138 NL80211_CMD_START_SCHED_SCAN);
4139 goto out;
4140 }
4141
4142out_free:
4143 kfree(request);
4144out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004145 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004146 return err;
4147}
4148
4149static int nl80211_stop_sched_scan(struct sk_buff *skb,
4150 struct genl_info *info)
4151{
4152 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004153 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004154
4155 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4156 !rdev->ops->sched_scan_stop)
4157 return -EOPNOTSUPP;
4158
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004159 mutex_lock(&rdev->sched_scan_mtx);
4160 err = __cfg80211_stop_sched_scan(rdev, false);
4161 mutex_unlock(&rdev->sched_scan_mtx);
4162
4163 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004164}
4165
Johannes Berg9720bb32011-06-21 09:45:33 +02004166static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4167 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004168 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004169 struct wireless_dev *wdev,
4170 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004171{
Johannes Berg48ab9052009-07-10 18:42:31 +02004172 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004173 void *hdr;
4174 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004175
4176 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004177
Johannes Berg9720bb32011-06-21 09:45:33 +02004178 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004179 NL80211_CMD_NEW_SCAN_RESULTS);
4180 if (!hdr)
4181 return -1;
4182
Johannes Berg9720bb32011-06-21 09:45:33 +02004183 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4184
Johannes Bergf5ea9122009-08-07 16:17:38 +02004185 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02004186 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01004187
4188 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4189 if (!bss)
4190 goto nla_put_failure;
4191 if (!is_zero_ether_addr(res->bssid))
4192 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
4193 if (res->information_elements && res->len_information_elements)
4194 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4195 res->len_information_elements,
4196 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02004197 if (res->beacon_ies && res->len_beacon_ies &&
4198 res->beacon_ies != res->information_elements)
4199 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
4200 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01004201 if (res->tsf)
4202 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
4203 if (res->beacon_interval)
4204 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
4205 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
4206 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02004207 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
4208 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01004209
Johannes Berg77965c972009-02-18 18:45:06 +01004210 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004211 case CFG80211_SIGNAL_TYPE_MBM:
4212 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
4213 break;
4214 case CFG80211_SIGNAL_TYPE_UNSPEC:
4215 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
4216 break;
4217 default:
4218 break;
4219 }
4220
Johannes Berg48ab9052009-07-10 18:42:31 +02004221 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004222 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004223 case NL80211_IFTYPE_STATION:
4224 if (intbss == wdev->current_bss)
4225 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4226 NL80211_BSS_STATUS_ASSOCIATED);
Johannes Berg48ab9052009-07-10 18:42:31 +02004227 break;
4228 case NL80211_IFTYPE_ADHOC:
4229 if (intbss == wdev->current_bss)
4230 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4231 NL80211_BSS_STATUS_IBSS_JOINED);
4232 break;
4233 default:
4234 break;
4235 }
4236
Johannes Berg2a519312009-02-10 21:25:55 +01004237 nla_nest_end(msg, bss);
4238
4239 return genlmsg_end(msg, hdr);
4240
4241 nla_put_failure:
4242 genlmsg_cancel(msg, hdr);
4243 return -EMSGSIZE;
4244}
4245
4246static int nl80211_dump_scan(struct sk_buff *skb,
4247 struct netlink_callback *cb)
4248{
Johannes Berg48ab9052009-07-10 18:42:31 +02004249 struct cfg80211_registered_device *rdev;
4250 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004251 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004252 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004253 int start = cb->args[1], idx = 0;
4254 int err;
4255
Johannes Berg67748892010-10-04 21:14:06 +02004256 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4257 if (err)
4258 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004259
Johannes Berg48ab9052009-07-10 18:42:31 +02004260 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004261
Johannes Berg48ab9052009-07-10 18:42:31 +02004262 wdev_lock(wdev);
4263 spin_lock_bh(&rdev->bss_lock);
4264 cfg80211_bss_expire(rdev);
4265
Johannes Berg9720bb32011-06-21 09:45:33 +02004266 cb->seq = rdev->bss_generation;
4267
Johannes Berg48ab9052009-07-10 18:42:31 +02004268 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004269 if (++idx <= start)
4270 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004271 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004272 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004273 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004274 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004275 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004276 }
4277 }
4278
Johannes Berg48ab9052009-07-10 18:42:31 +02004279 spin_unlock_bh(&rdev->bss_lock);
4280 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004281
4282 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004283 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004284
Johannes Berg67748892010-10-04 21:14:06 +02004285 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004286}
4287
Holger Schurig61fa7132009-11-11 12:25:40 +01004288static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4289 int flags, struct net_device *dev,
4290 struct survey_info *survey)
4291{
4292 void *hdr;
4293 struct nlattr *infoattr;
4294
Holger Schurig61fa7132009-11-11 12:25:40 +01004295 hdr = nl80211hdr_put(msg, pid, seq, flags,
4296 NL80211_CMD_NEW_SURVEY_RESULTS);
4297 if (!hdr)
4298 return -ENOMEM;
4299
4300 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4301
4302 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4303 if (!infoattr)
4304 goto nla_put_failure;
4305
4306 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4307 survey->channel->center_freq);
4308 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4309 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4310 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02004311 if (survey->filled & SURVEY_INFO_IN_USE)
4312 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02004313 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4314 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4315 survey->channel_time);
4316 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4317 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4318 survey->channel_time_busy);
4319 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4320 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4321 survey->channel_time_ext_busy);
4322 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4323 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4324 survey->channel_time_rx);
4325 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4326 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4327 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01004328
4329 nla_nest_end(msg, infoattr);
4330
4331 return genlmsg_end(msg, hdr);
4332
4333 nla_put_failure:
4334 genlmsg_cancel(msg, hdr);
4335 return -EMSGSIZE;
4336}
4337
4338static int nl80211_dump_survey(struct sk_buff *skb,
4339 struct netlink_callback *cb)
4340{
4341 struct survey_info survey;
4342 struct cfg80211_registered_device *dev;
4343 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004344 int survey_idx = cb->args[1];
4345 int res;
4346
Johannes Berg67748892010-10-04 21:14:06 +02004347 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4348 if (res)
4349 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004350
4351 if (!dev->ops->dump_survey) {
4352 res = -EOPNOTSUPP;
4353 goto out_err;
4354 }
4355
4356 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004357 struct ieee80211_channel *chan;
4358
Holger Schurig61fa7132009-11-11 12:25:40 +01004359 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4360 &survey);
4361 if (res == -ENOENT)
4362 break;
4363 if (res)
4364 goto out_err;
4365
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004366 /* Survey without a channel doesn't make sense */
4367 if (!survey.channel) {
4368 res = -EINVAL;
4369 goto out;
4370 }
4371
4372 chan = ieee80211_get_channel(&dev->wiphy,
4373 survey.channel->center_freq);
4374 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4375 survey_idx++;
4376 continue;
4377 }
4378
Holger Schurig61fa7132009-11-11 12:25:40 +01004379 if (nl80211_send_survey(skb,
4380 NETLINK_CB(cb->skb).pid,
4381 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4382 netdev,
4383 &survey) < 0)
4384 goto out;
4385 survey_idx++;
4386 }
4387
4388 out:
4389 cb->args[1] = survey_idx;
4390 res = skb->len;
4391 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004392 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004393 return res;
4394}
4395
Jouni Malinen255e7372009-03-20 21:21:17 +02004396static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4397{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004398 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004399}
4400
Samuel Ortizb23aa672009-07-01 21:26:54 +02004401static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4402{
4403 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4404 NL80211_WPA_VERSION_2));
4405}
4406
Jouni Malinen636a5d32009-03-19 13:39:22 +02004407static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4408{
Johannes Berg4c476992010-10-04 21:36:35 +02004409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4410 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004411 struct ieee80211_channel *chan;
4412 const u8 *bssid, *ssid, *ie = NULL;
4413 int err, ssid_len, ie_len = 0;
4414 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004415 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004416 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004417
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004418 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4419 return -EINVAL;
4420
4421 if (!info->attrs[NL80211_ATTR_MAC])
4422 return -EINVAL;
4423
Jouni Malinen17780922009-03-27 20:52:47 +02004424 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4425 return -EINVAL;
4426
Johannes Berg19957bb2009-07-02 17:20:43 +02004427 if (!info->attrs[NL80211_ATTR_SSID])
4428 return -EINVAL;
4429
4430 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4431 return -EINVAL;
4432
Johannes Bergfffd0932009-07-08 14:22:54 +02004433 err = nl80211_parse_key(info, &key);
4434 if (err)
4435 return err;
4436
4437 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004438 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4439 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004440 if (!key.p.key || !key.p.key_len)
4441 return -EINVAL;
4442 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4443 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4444 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4445 key.p.key_len != WLAN_KEY_LEN_WEP104))
4446 return -EINVAL;
4447 if (key.idx > 4)
4448 return -EINVAL;
4449 } else {
4450 key.p.key_len = 0;
4451 key.p.key = NULL;
4452 }
4453
Johannes Bergafea0b72010-08-10 09:46:42 +02004454 if (key.idx >= 0) {
4455 int i;
4456 bool ok = false;
4457 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4458 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4459 ok = true;
4460 break;
4461 }
4462 }
Johannes Berg4c476992010-10-04 21:36:35 +02004463 if (!ok)
4464 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004465 }
4466
Johannes Berg4c476992010-10-04 21:36:35 +02004467 if (!rdev->ops->auth)
4468 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004469
Johannes Berg074ac8d2010-09-16 14:58:22 +02004470 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004471 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4472 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004473
Johannes Berg19957bb2009-07-02 17:20:43 +02004474 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004475 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004476 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004477 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4478 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004479
Johannes Berg19957bb2009-07-02 17:20:43 +02004480 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4481 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4482
4483 if (info->attrs[NL80211_ATTR_IE]) {
4484 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4485 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4486 }
4487
4488 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004489 if (!nl80211_valid_auth_type(auth_type))
4490 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004491
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004492 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4493
Johannes Berg95de8172012-01-20 13:55:25 +01004494 /*
4495 * Since we no longer track auth state, ignore
4496 * requests to only change local state.
4497 */
4498 if (local_state_change)
4499 return 0;
4500
Johannes Berg4c476992010-10-04 21:36:35 +02004501 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4502 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004503 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004504}
4505
Johannes Bergc0692b82010-08-27 14:26:53 +03004506static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4507 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004508 struct cfg80211_crypto_settings *settings,
4509 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004510{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004511 memset(settings, 0, sizeof(*settings));
4512
Samuel Ortizb23aa672009-07-01 21:26:54 +02004513 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4514
Johannes Bergc0692b82010-08-27 14:26:53 +03004515 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4516 u16 proto;
4517 proto = nla_get_u16(
4518 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4519 settings->control_port_ethertype = cpu_to_be16(proto);
4520 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4521 proto != ETH_P_PAE)
4522 return -EINVAL;
4523 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4524 settings->control_port_no_encrypt = true;
4525 } else
4526 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4527
Samuel Ortizb23aa672009-07-01 21:26:54 +02004528 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4529 void *data;
4530 int len, i;
4531
4532 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4533 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4534 settings->n_ciphers_pairwise = len / sizeof(u32);
4535
4536 if (len % sizeof(u32))
4537 return -EINVAL;
4538
Johannes Berg3dc27d22009-07-02 21:36:37 +02004539 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004540 return -EINVAL;
4541
4542 memcpy(settings->ciphers_pairwise, data, len);
4543
4544 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004545 if (!cfg80211_supported_cipher_suite(
4546 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004547 settings->ciphers_pairwise[i]))
4548 return -EINVAL;
4549 }
4550
4551 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4552 settings->cipher_group =
4553 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004554 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4555 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004556 return -EINVAL;
4557 }
4558
4559 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4560 settings->wpa_versions =
4561 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4562 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4563 return -EINVAL;
4564 }
4565
4566 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4567 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004568 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004569
4570 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4571 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4572 settings->n_akm_suites = len / sizeof(u32);
4573
4574 if (len % sizeof(u32))
4575 return -EINVAL;
4576
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004577 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4578 return -EINVAL;
4579
Samuel Ortizb23aa672009-07-01 21:26:54 +02004580 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004581 }
4582
4583 return 0;
4584}
4585
Jouni Malinen636a5d32009-03-19 13:39:22 +02004586static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4587{
Johannes Berg4c476992010-10-04 21:36:35 +02004588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4589 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004590 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004591 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004592 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004593 int err, ssid_len, ie_len = 0;
4594 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004595 u32 flags = 0;
4596 struct ieee80211_ht_cap *ht_capa = NULL;
4597 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004598
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004599 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4600 return -EINVAL;
4601
4602 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004603 !info->attrs[NL80211_ATTR_SSID] ||
4604 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004605 return -EINVAL;
4606
Johannes Berg4c476992010-10-04 21:36:35 +02004607 if (!rdev->ops->assoc)
4608 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004609
Johannes Berg074ac8d2010-09-16 14:58:22 +02004610 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004611 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4612 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004613
Johannes Berg19957bb2009-07-02 17:20:43 +02004614 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004615
Johannes Berg19957bb2009-07-02 17:20:43 +02004616 chan = ieee80211_get_channel(&rdev->wiphy,
4617 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004618 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4619 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004620
Johannes Berg19957bb2009-07-02 17:20:43 +02004621 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4622 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004623
4624 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004625 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4626 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004627 }
4628
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004629 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004630 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004631 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004632 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004633 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004634 else if (mfp != NL80211_MFP_NO)
4635 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004636 }
4637
Johannes Berg3e5d7642009-07-07 14:37:26 +02004638 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4639 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4640
Ben Greear7e7c8922011-11-18 11:31:59 -08004641 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4642 flags |= ASSOC_REQ_DISABLE_HT;
4643
4644 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4645 ht_capa_mask =
4646 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4647
4648 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4649 if (!ht_capa_mask)
4650 return -EINVAL;
4651 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4652 }
4653
Johannes Bergc0692b82010-08-27 14:26:53 +03004654 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004655 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004656 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4657 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004658 &crypto, flags, ht_capa,
4659 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004660
Jouni Malinen636a5d32009-03-19 13:39:22 +02004661 return err;
4662}
4663
4664static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4665{
Johannes Berg4c476992010-10-04 21:36:35 +02004666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4667 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004668 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004669 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004670 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004671 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004672
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004673 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4674 return -EINVAL;
4675
4676 if (!info->attrs[NL80211_ATTR_MAC])
4677 return -EINVAL;
4678
4679 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4680 return -EINVAL;
4681
Johannes Berg4c476992010-10-04 21:36:35 +02004682 if (!rdev->ops->deauth)
4683 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004684
Johannes Berg074ac8d2010-09-16 14:58:22 +02004685 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004686 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4687 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004688
Johannes Berg19957bb2009-07-02 17:20:43 +02004689 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004690
Johannes Berg19957bb2009-07-02 17:20:43 +02004691 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4692 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004693 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004694 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004695 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004696
4697 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004698 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4699 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004700 }
4701
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004702 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4703
Johannes Berg4c476992010-10-04 21:36:35 +02004704 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4705 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004706}
4707
4708static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4709{
Johannes Berg4c476992010-10-04 21:36:35 +02004710 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4711 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004712 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004713 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004714 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004715 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004716
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004717 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4718 return -EINVAL;
4719
4720 if (!info->attrs[NL80211_ATTR_MAC])
4721 return -EINVAL;
4722
4723 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4724 return -EINVAL;
4725
Johannes Berg4c476992010-10-04 21:36:35 +02004726 if (!rdev->ops->disassoc)
4727 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004728
Johannes Berg074ac8d2010-09-16 14:58:22 +02004729 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004730 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4731 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004732
Johannes Berg19957bb2009-07-02 17:20:43 +02004733 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004734
Johannes Berg19957bb2009-07-02 17:20:43 +02004735 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4736 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004737 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004738 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004739 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004740
4741 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004742 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4743 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004744 }
4745
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004746 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4747
Johannes Berg4c476992010-10-04 21:36:35 +02004748 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4749 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004750}
4751
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004752static bool
4753nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4754 int mcast_rate[IEEE80211_NUM_BANDS],
4755 int rateval)
4756{
4757 struct wiphy *wiphy = &rdev->wiphy;
4758 bool found = false;
4759 int band, i;
4760
4761 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4762 struct ieee80211_supported_band *sband;
4763
4764 sband = wiphy->bands[band];
4765 if (!sband)
4766 continue;
4767
4768 for (i = 0; i < sband->n_bitrates; i++) {
4769 if (sband->bitrates[i].bitrate == rateval) {
4770 mcast_rate[band] = i + 1;
4771 found = true;
4772 break;
4773 }
4774 }
4775 }
4776
4777 return found;
4778}
4779
Johannes Berg04a773a2009-04-19 21:24:32 +02004780static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4781{
Johannes Berg4c476992010-10-04 21:36:35 +02004782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4783 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004784 struct cfg80211_ibss_params ibss;
4785 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004786 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004787 int err;
4788
Johannes Berg8e30bc52009-04-22 17:45:38 +02004789 memset(&ibss, 0, sizeof(ibss));
4790
Johannes Berg04a773a2009-04-19 21:24:32 +02004791 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4792 return -EINVAL;
4793
4794 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4795 !info->attrs[NL80211_ATTR_SSID] ||
4796 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4797 return -EINVAL;
4798
Johannes Berg8e30bc52009-04-22 17:45:38 +02004799 ibss.beacon_interval = 100;
4800
4801 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4802 ibss.beacon_interval =
4803 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4804 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4805 return -EINVAL;
4806 }
4807
Johannes Berg4c476992010-10-04 21:36:35 +02004808 if (!rdev->ops->join_ibss)
4809 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004810
Johannes Berg4c476992010-10-04 21:36:35 +02004811 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4812 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004813
Johannes Berg79c97e92009-07-07 03:56:12 +02004814 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004815
Johannes Berg39193492011-09-16 13:45:25 +02004816 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02004817 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02004818
4819 if (!is_valid_ether_addr(ibss.bssid))
4820 return -EINVAL;
4821 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004822 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4823 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4824
4825 if (info->attrs[NL80211_ATTR_IE]) {
4826 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4827 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4828 }
4829
Alexander Simon54858ee5b2011-11-30 16:56:32 +01004830 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4831 enum nl80211_channel_type channel_type;
4832
4833 channel_type = nla_get_u32(
4834 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4835 if (channel_type != NL80211_CHAN_NO_HT &&
4836 channel_type != NL80211_CHAN_HT20 &&
4837 channel_type != NL80211_CHAN_HT40MINUS &&
4838 channel_type != NL80211_CHAN_HT40PLUS)
4839 return -EINVAL;
4840
4841 if (channel_type != NL80211_CHAN_NO_HT &&
4842 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
4843 return -EINVAL;
4844
4845 ibss.channel_type = channel_type;
4846 } else {
4847 ibss.channel_type = NL80211_CHAN_NO_HT;
4848 }
4849
4850 ibss.channel = rdev_freq_to_chan(rdev,
4851 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
4852 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02004853 if (!ibss.channel ||
4854 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004855 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4856 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004857
Alexander Simon54858ee5b2011-11-30 16:56:32 +01004858 /* Both channels should be able to initiate communication */
4859 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
4860 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
4861 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
4862 ibss.channel_type))
4863 return -EINVAL;
4864
Johannes Berg04a773a2009-04-19 21:24:32 +02004865 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004866 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004867
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004868 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4869 u8 *rates =
4870 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4871 int n_rates =
4872 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4873 struct ieee80211_supported_band *sband =
4874 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004875
Johannes Berg34850ab2011-07-18 18:08:35 +02004876 err = ieee80211_get_ratemask(sband, rates, n_rates,
4877 &ibss.basic_rates);
4878 if (err)
4879 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004880 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004881
4882 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4883 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4884 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4885 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004886
Johannes Berg4c476992010-10-04 21:36:35 +02004887 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4888 connkeys = nl80211_parse_connkeys(rdev,
4889 info->attrs[NL80211_ATTR_KEYS]);
4890 if (IS_ERR(connkeys))
4891 return PTR_ERR(connkeys);
4892 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004893
Antonio Quartulli267335d2012-01-31 20:25:47 +01004894 ibss.control_port =
4895 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
4896
Johannes Berg4c476992010-10-04 21:36:35 +02004897 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004898 if (err)
4899 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004900 return err;
4901}
4902
4903static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4904{
Johannes Berg4c476992010-10-04 21:36:35 +02004905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4906 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004907
Johannes Berg4c476992010-10-04 21:36:35 +02004908 if (!rdev->ops->leave_ibss)
4909 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004910
Johannes Berg4c476992010-10-04 21:36:35 +02004911 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4912 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004913
Johannes Berg4c476992010-10-04 21:36:35 +02004914 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004915}
4916
Johannes Bergaff89a92009-07-01 21:26:51 +02004917#ifdef CONFIG_NL80211_TESTMODE
4918static struct genl_multicast_group nl80211_testmode_mcgrp = {
4919 .name = "testmode",
4920};
4921
4922static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4923{
Johannes Berg4c476992010-10-04 21:36:35 +02004924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004925 int err;
4926
4927 if (!info->attrs[NL80211_ATTR_TESTDATA])
4928 return -EINVAL;
4929
Johannes Bergaff89a92009-07-01 21:26:51 +02004930 err = -EOPNOTSUPP;
4931 if (rdev->ops->testmode_cmd) {
4932 rdev->testmode_info = info;
4933 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4934 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4935 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4936 rdev->testmode_info = NULL;
4937 }
4938
Johannes Bergaff89a92009-07-01 21:26:51 +02004939 return err;
4940}
4941
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004942static int nl80211_testmode_dump(struct sk_buff *skb,
4943 struct netlink_callback *cb)
4944{
Johannes Berg00918d32011-12-13 17:22:05 +01004945 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004946 int err;
4947 long phy_idx;
4948 void *data = NULL;
4949 int data_len = 0;
4950
4951 if (cb->args[0]) {
4952 /*
4953 * 0 is a valid index, but not valid for args[0],
4954 * so we need to offset by 1.
4955 */
4956 phy_idx = cb->args[0] - 1;
4957 } else {
4958 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4959 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4960 nl80211_policy);
4961 if (err)
4962 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01004963 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
4964 phy_idx = nla_get_u32(
4965 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4966 } else {
4967 struct net_device *netdev;
4968
4969 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
4970 nl80211_fam.attrbuf,
4971 &rdev, &netdev);
4972 if (err)
4973 return err;
4974 dev_put(netdev);
4975 phy_idx = rdev->wiphy_idx;
4976 cfg80211_unlock_rdev(rdev);
4977 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004978 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4979 cb->args[1] =
4980 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4981 }
4982
4983 if (cb->args[1]) {
4984 data = nla_data((void *)cb->args[1]);
4985 data_len = nla_len((void *)cb->args[1]);
4986 }
4987
4988 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01004989 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4990 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004991 mutex_unlock(&cfg80211_mutex);
4992 return -ENOENT;
4993 }
Johannes Berg00918d32011-12-13 17:22:05 +01004994 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004995 mutex_unlock(&cfg80211_mutex);
4996
Johannes Berg00918d32011-12-13 17:22:05 +01004997 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004998 err = -EOPNOTSUPP;
4999 goto out_err;
5000 }
5001
5002 while (1) {
5003 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5004 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5005 NL80211_CMD_TESTMODE);
5006 struct nlattr *tmdata;
5007
Johannes Berg00918d32011-12-13 17:22:05 +01005008 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005009 genlmsg_cancel(skb, hdr);
5010 break;
5011 }
5012
5013 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5014 if (!tmdata) {
5015 genlmsg_cancel(skb, hdr);
5016 break;
5017 }
Johannes Berg00918d32011-12-13 17:22:05 +01005018 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5019 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005020 nla_nest_end(skb, tmdata);
5021
5022 if (err == -ENOBUFS || err == -ENOENT) {
5023 genlmsg_cancel(skb, hdr);
5024 break;
5025 } else if (err) {
5026 genlmsg_cancel(skb, hdr);
5027 goto out_err;
5028 }
5029
5030 genlmsg_end(skb, hdr);
5031 }
5032
5033 err = skb->len;
5034 /* see above */
5035 cb->args[0] = phy_idx + 1;
5036 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005037 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005038 return err;
5039}
5040
Johannes Bergaff89a92009-07-01 21:26:51 +02005041static struct sk_buff *
5042__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5043 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5044{
5045 struct sk_buff *skb;
5046 void *hdr;
5047 struct nlattr *data;
5048
5049 skb = nlmsg_new(approxlen + 100, gfp);
5050 if (!skb)
5051 return NULL;
5052
5053 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5054 if (!hdr) {
5055 kfree_skb(skb);
5056 return NULL;
5057 }
5058
5059 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5060 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5061
5062 ((void **)skb->cb)[0] = rdev;
5063 ((void **)skb->cb)[1] = hdr;
5064 ((void **)skb->cb)[2] = data;
5065
5066 return skb;
5067
5068 nla_put_failure:
5069 kfree_skb(skb);
5070 return NULL;
5071}
5072
5073struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5074 int approxlen)
5075{
5076 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5077
5078 if (WARN_ON(!rdev->testmode_info))
5079 return NULL;
5080
5081 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5082 rdev->testmode_info->snd_pid,
5083 rdev->testmode_info->snd_seq,
5084 GFP_KERNEL);
5085}
5086EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5087
5088int cfg80211_testmode_reply(struct sk_buff *skb)
5089{
5090 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5091 void *hdr = ((void **)skb->cb)[1];
5092 struct nlattr *data = ((void **)skb->cb)[2];
5093
5094 if (WARN_ON(!rdev->testmode_info)) {
5095 kfree_skb(skb);
5096 return -EINVAL;
5097 }
5098
5099 nla_nest_end(skb, data);
5100 genlmsg_end(skb, hdr);
5101 return genlmsg_reply(skb, rdev->testmode_info);
5102}
5103EXPORT_SYMBOL(cfg80211_testmode_reply);
5104
5105struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5106 int approxlen, gfp_t gfp)
5107{
5108 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5109
5110 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5111}
5112EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5113
5114void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5115{
5116 void *hdr = ((void **)skb->cb)[1];
5117 struct nlattr *data = ((void **)skb->cb)[2];
5118
5119 nla_nest_end(skb, data);
5120 genlmsg_end(skb, hdr);
5121 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5122}
5123EXPORT_SYMBOL(cfg80211_testmode_event);
5124#endif
5125
Samuel Ortizb23aa672009-07-01 21:26:54 +02005126static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5127{
Johannes Berg4c476992010-10-04 21:36:35 +02005128 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5129 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005130 struct cfg80211_connect_params connect;
5131 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005132 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005133 int err;
5134
5135 memset(&connect, 0, sizeof(connect));
5136
5137 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5138 return -EINVAL;
5139
5140 if (!info->attrs[NL80211_ATTR_SSID] ||
5141 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5142 return -EINVAL;
5143
5144 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5145 connect.auth_type =
5146 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5147 if (!nl80211_valid_auth_type(connect.auth_type))
5148 return -EINVAL;
5149 } else
5150 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5151
5152 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5153
Johannes Bergc0692b82010-08-27 14:26:53 +03005154 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005155 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005156 if (err)
5157 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005158
Johannes Berg074ac8d2010-09-16 14:58:22 +02005159 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005160 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5161 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005162
Johannes Berg79c97e92009-07-07 03:56:12 +02005163 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005164
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305165 connect.bg_scan_period = -1;
5166 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5167 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5168 connect.bg_scan_period =
5169 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5170 }
5171
Samuel Ortizb23aa672009-07-01 21:26:54 +02005172 if (info->attrs[NL80211_ATTR_MAC])
5173 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5174 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5175 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5176
5177 if (info->attrs[NL80211_ATTR_IE]) {
5178 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5179 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5180 }
5181
5182 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5183 connect.channel =
5184 ieee80211_get_channel(wiphy,
5185 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5186 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005187 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5188 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005189 }
5190
Johannes Bergfffd0932009-07-08 14:22:54 +02005191 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5192 connkeys = nl80211_parse_connkeys(rdev,
5193 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005194 if (IS_ERR(connkeys))
5195 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005196 }
5197
Ben Greear7e7c8922011-11-18 11:31:59 -08005198 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5199 connect.flags |= ASSOC_REQ_DISABLE_HT;
5200
5201 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5202 memcpy(&connect.ht_capa_mask,
5203 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5204 sizeof(connect.ht_capa_mask));
5205
5206 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5207 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5208 return -EINVAL;
5209 memcpy(&connect.ht_capa,
5210 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5211 sizeof(connect.ht_capa));
5212 }
5213
Johannes Bergfffd0932009-07-08 14:22:54 +02005214 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005215 if (err)
5216 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005217 return err;
5218}
5219
5220static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5221{
Johannes Berg4c476992010-10-04 21:36:35 +02005222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5223 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005224 u16 reason;
5225
5226 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5227 reason = WLAN_REASON_DEAUTH_LEAVING;
5228 else
5229 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5230
5231 if (reason == 0)
5232 return -EINVAL;
5233
Johannes Berg074ac8d2010-09-16 14:58:22 +02005234 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005235 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5236 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005237
Johannes Berg4c476992010-10-04 21:36:35 +02005238 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005239}
5240
Johannes Berg463d0182009-07-14 00:33:35 +02005241static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5242{
Johannes Berg4c476992010-10-04 21:36:35 +02005243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005244 struct net *net;
5245 int err;
5246 u32 pid;
5247
5248 if (!info->attrs[NL80211_ATTR_PID])
5249 return -EINVAL;
5250
5251 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5252
Johannes Berg463d0182009-07-14 00:33:35 +02005253 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005254 if (IS_ERR(net))
5255 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005256
5257 err = 0;
5258
5259 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005260 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5261 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005262
Johannes Berg463d0182009-07-14 00:33:35 +02005263 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005264 return err;
5265}
5266
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005267static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5268{
Johannes Berg4c476992010-10-04 21:36:35 +02005269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005270 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5271 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005272 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005273 struct cfg80211_pmksa pmksa;
5274
5275 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5276
5277 if (!info->attrs[NL80211_ATTR_MAC])
5278 return -EINVAL;
5279
5280 if (!info->attrs[NL80211_ATTR_PMKID])
5281 return -EINVAL;
5282
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005283 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5284 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5285
Johannes Berg074ac8d2010-09-16 14:58:22 +02005286 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005287 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5288 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005289
5290 switch (info->genlhdr->cmd) {
5291 case NL80211_CMD_SET_PMKSA:
5292 rdev_ops = rdev->ops->set_pmksa;
5293 break;
5294 case NL80211_CMD_DEL_PMKSA:
5295 rdev_ops = rdev->ops->del_pmksa;
5296 break;
5297 default:
5298 WARN_ON(1);
5299 break;
5300 }
5301
Johannes Berg4c476992010-10-04 21:36:35 +02005302 if (!rdev_ops)
5303 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005304
Johannes Berg4c476992010-10-04 21:36:35 +02005305 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005306}
5307
5308static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5309{
Johannes Berg4c476992010-10-04 21:36:35 +02005310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5311 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005312
Johannes Berg074ac8d2010-09-16 14:58:22 +02005313 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005314 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5315 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005316
Johannes Berg4c476992010-10-04 21:36:35 +02005317 if (!rdev->ops->flush_pmksa)
5318 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005319
Johannes Berg4c476992010-10-04 21:36:35 +02005320 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005321}
5322
Arik Nemtsov109086c2011-09-28 14:12:50 +03005323static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5324{
5325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5326 struct net_device *dev = info->user_ptr[1];
5327 u8 action_code, dialog_token;
5328 u16 status_code;
5329 u8 *peer;
5330
5331 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5332 !rdev->ops->tdls_mgmt)
5333 return -EOPNOTSUPP;
5334
5335 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5336 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5337 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5338 !info->attrs[NL80211_ATTR_IE] ||
5339 !info->attrs[NL80211_ATTR_MAC])
5340 return -EINVAL;
5341
5342 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5343 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5344 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5345 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5346
5347 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5348 dialog_token, status_code,
5349 nla_data(info->attrs[NL80211_ATTR_IE]),
5350 nla_len(info->attrs[NL80211_ATTR_IE]));
5351}
5352
5353static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5354{
5355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5356 struct net_device *dev = info->user_ptr[1];
5357 enum nl80211_tdls_operation operation;
5358 u8 *peer;
5359
5360 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5361 !rdev->ops->tdls_oper)
5362 return -EOPNOTSUPP;
5363
5364 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5365 !info->attrs[NL80211_ATTR_MAC])
5366 return -EINVAL;
5367
5368 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5369 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5370
5371 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5372}
5373
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005374static int nl80211_remain_on_channel(struct sk_buff *skb,
5375 struct genl_info *info)
5376{
Johannes Berg4c476992010-10-04 21:36:35 +02005377 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5378 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005379 struct ieee80211_channel *chan;
5380 struct sk_buff *msg;
5381 void *hdr;
5382 u64 cookie;
5383 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5384 u32 freq, duration;
5385 int err;
5386
5387 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5388 !info->attrs[NL80211_ATTR_DURATION])
5389 return -EINVAL;
5390
5391 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5392
5393 /*
5394 * We should be on that channel for at least one jiffie,
5395 * and more than 5 seconds seems excessive.
5396 */
Johannes Berga2939112010-12-14 17:54:28 +01005397 if (!duration || !msecs_to_jiffies(duration) ||
5398 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005399 return -EINVAL;
5400
Johannes Berg7c4ef712011-11-18 15:33:48 +01005401 if (!rdev->ops->remain_on_channel ||
5402 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005403 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005404
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005405 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5406 channel_type = nla_get_u32(
5407 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5408 if (channel_type != NL80211_CHAN_NO_HT &&
5409 channel_type != NL80211_CHAN_HT20 &&
5410 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005411 channel_type != NL80211_CHAN_HT40MINUS)
5412 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005413 }
5414
5415 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5416 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005417 if (chan == NULL)
5418 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005419
5420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005421 if (!msg)
5422 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005423
5424 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5425 NL80211_CMD_REMAIN_ON_CHANNEL);
5426
5427 if (IS_ERR(hdr)) {
5428 err = PTR_ERR(hdr);
5429 goto free_msg;
5430 }
5431
5432 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5433 channel_type, duration, &cookie);
5434
5435 if (err)
5436 goto free_msg;
5437
5438 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5439
5440 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005441
5442 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005443
5444 nla_put_failure:
5445 err = -ENOBUFS;
5446 free_msg:
5447 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005448 return err;
5449}
5450
5451static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5452 struct genl_info *info)
5453{
Johannes Berg4c476992010-10-04 21:36:35 +02005454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5455 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005456 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005457
5458 if (!info->attrs[NL80211_ATTR_COOKIE])
5459 return -EINVAL;
5460
Johannes Berg4c476992010-10-04 21:36:35 +02005461 if (!rdev->ops->cancel_remain_on_channel)
5462 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005463
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005464 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5465
Johannes Berg4c476992010-10-04 21:36:35 +02005466 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005467}
5468
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005469static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5470 u8 *rates, u8 rates_len)
5471{
5472 u8 i;
5473 u32 mask = 0;
5474
5475 for (i = 0; i < rates_len; i++) {
5476 int rate = (rates[i] & 0x7f) * 5;
5477 int ridx;
5478 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5479 struct ieee80211_rate *srate =
5480 &sband->bitrates[ridx];
5481 if (rate == srate->bitrate) {
5482 mask |= 1 << ridx;
5483 break;
5484 }
5485 }
5486 if (ridx == sband->n_bitrates)
5487 return 0; /* rate not found */
5488 }
5489
5490 return mask;
5491}
5492
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005493static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5494 u8 *rates, u8 rates_len,
5495 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5496{
5497 u8 i;
5498
5499 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5500
5501 for (i = 0; i < rates_len; i++) {
5502 int ridx, rbit;
5503
5504 ridx = rates[i] / 8;
5505 rbit = BIT(rates[i] % 8);
5506
5507 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005508 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005509 return false;
5510
5511 /* check availability */
5512 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5513 mcs[ridx] |= rbit;
5514 else
5515 return false;
5516 }
5517
5518 return true;
5519}
5520
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005521static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005522 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5523 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005524 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5525 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005526};
5527
5528static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5529 struct genl_info *info)
5530{
5531 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005533 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005534 int rem, i;
5535 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005536 struct nlattr *tx_rates;
5537 struct ieee80211_supported_band *sband;
5538
5539 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5540 return -EINVAL;
5541
Johannes Berg4c476992010-10-04 21:36:35 +02005542 if (!rdev->ops->set_bitrate_mask)
5543 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005544
5545 memset(&mask, 0, sizeof(mask));
5546 /* Default to all rates enabled */
5547 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5548 sband = rdev->wiphy.bands[i];
5549 mask.control[i].legacy =
5550 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005551 if (sband)
5552 memcpy(mask.control[i].mcs,
5553 sband->ht_cap.mcs.rx_mask,
5554 sizeof(mask.control[i].mcs));
5555 else
5556 memset(mask.control[i].mcs, 0,
5557 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005558 }
5559
5560 /*
5561 * The nested attribute uses enum nl80211_band as the index. This maps
5562 * directly to the enum ieee80211_band values used in cfg80211.
5563 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005564 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005565 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5566 {
5567 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005568 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5569 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005570 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005571 if (sband == NULL)
5572 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005573 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5574 nla_len(tx_rates), nl80211_txattr_policy);
5575 if (tb[NL80211_TXRATE_LEGACY]) {
5576 mask.control[band].legacy = rateset_to_mask(
5577 sband,
5578 nla_data(tb[NL80211_TXRATE_LEGACY]),
5579 nla_len(tb[NL80211_TXRATE_LEGACY]));
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005580 }
5581 if (tb[NL80211_TXRATE_MCS]) {
5582 if (!ht_rateset_to_mask(
5583 sband,
5584 nla_data(tb[NL80211_TXRATE_MCS]),
5585 nla_len(tb[NL80211_TXRATE_MCS]),
5586 mask.control[band].mcs))
5587 return -EINVAL;
5588 }
5589
5590 if (mask.control[band].legacy == 0) {
5591 /* don't allow empty legacy rates if HT
5592 * is not even supported. */
5593 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5594 return -EINVAL;
5595
5596 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5597 if (mask.control[band].mcs[i])
5598 break;
5599
5600 /* legacy and mcs rates may not be both empty */
5601 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005602 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005603 }
5604 }
5605
Johannes Berg4c476992010-10-04 21:36:35 +02005606 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005607}
5608
Johannes Berg2e161f782010-08-12 15:38:38 +02005609static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005610{
Johannes Berg4c476992010-10-04 21:36:35 +02005611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5612 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02005613 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005614
5615 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5616 return -EINVAL;
5617
Johannes Berg2e161f782010-08-12 15:38:38 +02005618 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5619 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005620
Johannes Berg9d38d852010-06-09 17:20:33 +02005621 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005622 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005623 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5624 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5625 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005626 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005627 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5628 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005629
5630 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005631 if (!rdev->ops->mgmt_tx)
5632 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005633
Johannes Berg4c476992010-10-04 21:36:35 +02005634 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f782010-08-12 15:38:38 +02005635 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005636 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5637 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005638}
5639
Johannes Berg2e161f782010-08-12 15:38:38 +02005640static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005641{
Johannes Berg4c476992010-10-04 21:36:35 +02005642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5643 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005644 struct ieee80211_channel *chan;
5645 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005646 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005647 u32 freq;
5648 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005649 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005650 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005651 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005652 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005653 bool offchan, no_cck, dont_wait_for_ack;
5654
5655 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005656
5657 if (!info->attrs[NL80211_ATTR_FRAME] ||
5658 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5659 return -EINVAL;
5660
Johannes Berg4c476992010-10-04 21:36:35 +02005661 if (!rdev->ops->mgmt_tx)
5662 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005663
Johannes Berg9d38d852010-06-09 17:20:33 +02005664 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005665 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005666 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5667 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5668 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005669 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005670 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5671 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005672
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005673 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005674 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005675 return -EINVAL;
5676 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5677 }
5678
Jouni Malinen026331c2010-02-15 12:53:10 +02005679 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5680 channel_type = nla_get_u32(
5681 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5682 if (channel_type != NL80211_CHAN_NO_HT &&
5683 channel_type != NL80211_CHAN_HT20 &&
5684 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005685 channel_type != NL80211_CHAN_HT40MINUS)
5686 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005687 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005688 }
5689
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005690 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5691
Johannes Berg7c4ef712011-11-18 15:33:48 +01005692 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5693 return -EINVAL;
5694
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305695 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5696
Jouni Malinen026331c2010-02-15 12:53:10 +02005697 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5698 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005699 if (chan == NULL)
5700 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005701
Johannes Berge247bd902011-11-04 11:18:21 +01005702 if (!dont_wait_for_ack) {
5703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5704 if (!msg)
5705 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005706
Johannes Berge247bd902011-11-04 11:18:21 +01005707 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5708 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005709
Johannes Berge247bd902011-11-04 11:18:21 +01005710 if (IS_ERR(hdr)) {
5711 err = PTR_ERR(hdr);
5712 goto free_msg;
5713 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005714 }
Johannes Berge247bd902011-11-04 11:18:21 +01005715
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005716 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5717 channel_type_valid, wait,
Johannes Berg2e161f782010-08-12 15:38:38 +02005718 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5719 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005720 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005721 if (err)
5722 goto free_msg;
5723
Johannes Berge247bd902011-11-04 11:18:21 +01005724 if (msg) {
5725 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005726
Johannes Berge247bd902011-11-04 11:18:21 +01005727 genlmsg_end(msg, hdr);
5728 return genlmsg_reply(msg, info);
5729 }
5730
5731 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02005732
5733 nla_put_failure:
5734 err = -ENOBUFS;
5735 free_msg:
5736 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005737 return err;
5738}
5739
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005740static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5741{
5742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5743 struct net_device *dev = info->user_ptr[1];
5744 u64 cookie;
5745
5746 if (!info->attrs[NL80211_ATTR_COOKIE])
5747 return -EINVAL;
5748
5749 if (!rdev->ops->mgmt_tx_cancel_wait)
5750 return -EOPNOTSUPP;
5751
5752 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5753 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5754 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5755 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5756 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5757 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5758 return -EOPNOTSUPP;
5759
5760 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5761
5762 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5763}
5764
Kalle Valoffb9eb32010-02-17 17:58:10 +02005765static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5766{
Johannes Berg4c476992010-10-04 21:36:35 +02005767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005768 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005769 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005770 u8 ps_state;
5771 bool state;
5772 int err;
5773
Johannes Berg4c476992010-10-04 21:36:35 +02005774 if (!info->attrs[NL80211_ATTR_PS_STATE])
5775 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005776
5777 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5778
Johannes Berg4c476992010-10-04 21:36:35 +02005779 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5780 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005781
5782 wdev = dev->ieee80211_ptr;
5783
Johannes Berg4c476992010-10-04 21:36:35 +02005784 if (!rdev->ops->set_power_mgmt)
5785 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005786
5787 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5788
5789 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005790 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005791
Johannes Berg4c476992010-10-04 21:36:35 +02005792 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5793 wdev->ps_timeout);
5794 if (!err)
5795 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005796 return err;
5797}
5798
5799static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5800{
Johannes Berg4c476992010-10-04 21:36:35 +02005801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005802 enum nl80211_ps_state ps_state;
5803 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005804 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005805 struct sk_buff *msg;
5806 void *hdr;
5807 int err;
5808
Kalle Valoffb9eb32010-02-17 17:58:10 +02005809 wdev = dev->ieee80211_ptr;
5810
Johannes Berg4c476992010-10-04 21:36:35 +02005811 if (!rdev->ops->set_power_mgmt)
5812 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005813
5814 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005815 if (!msg)
5816 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005817
5818 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5819 NL80211_CMD_GET_POWER_SAVE);
5820 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005821 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005822 goto free_msg;
5823 }
5824
5825 if (wdev->ps)
5826 ps_state = NL80211_PS_ENABLED;
5827 else
5828 ps_state = NL80211_PS_DISABLED;
5829
5830 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5831
5832 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005833 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005834
Johannes Berg4c476992010-10-04 21:36:35 +02005835 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005836 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005837 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005838 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005839 return err;
5840}
5841
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005842static struct nla_policy
5843nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5844 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5845 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5846 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5847};
5848
5849static int nl80211_set_cqm_rssi(struct genl_info *info,
5850 s32 threshold, u32 hysteresis)
5851{
Johannes Berg4c476992010-10-04 21:36:35 +02005852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005853 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005854 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005855
5856 if (threshold > 0)
5857 return -EINVAL;
5858
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005859 wdev = dev->ieee80211_ptr;
5860
Johannes Berg4c476992010-10-04 21:36:35 +02005861 if (!rdev->ops->set_cqm_rssi_config)
5862 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005863
Johannes Berg074ac8d2010-09-16 14:58:22 +02005864 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005865 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5866 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005867
Johannes Berg4c476992010-10-04 21:36:35 +02005868 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5869 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005870}
5871
5872static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5873{
5874 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5875 struct nlattr *cqm;
5876 int err;
5877
5878 cqm = info->attrs[NL80211_ATTR_CQM];
5879 if (!cqm) {
5880 err = -EINVAL;
5881 goto out;
5882 }
5883
5884 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5885 nl80211_attr_cqm_policy);
5886 if (err)
5887 goto out;
5888
5889 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5890 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5891 s32 threshold;
5892 u32 hysteresis;
5893 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5894 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5895 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5896 } else
5897 err = -EINVAL;
5898
5899out:
5900 return err;
5901}
5902
Johannes Berg29cbe682010-12-03 09:20:44 +01005903static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5904{
5905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5906 struct net_device *dev = info->user_ptr[1];
5907 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005908 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005909 int err;
5910
5911 /* start with default */
5912 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005913 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005914
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005915 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005916 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005917 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005918 if (err)
5919 return err;
5920 }
5921
5922 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5923 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5924 return -EINVAL;
5925
Javier Cardonac80d5452010-12-16 17:37:49 -08005926 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5927 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5928
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08005929 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5930 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
5931 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5932 return -EINVAL;
5933
Javier Cardonac80d5452010-12-16 17:37:49 -08005934 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5935 /* parse additional setup parameters if given */
5936 err = nl80211_parse_mesh_setup(info, &setup);
5937 if (err)
5938 return err;
5939 }
5940
5941 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005942}
5943
5944static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5945{
5946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5947 struct net_device *dev = info->user_ptr[1];
5948
5949 return cfg80211_leave_mesh(rdev, dev);
5950}
5951
Johannes Bergff1b6e62011-05-04 15:37:28 +02005952static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5953{
5954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5955 struct sk_buff *msg;
5956 void *hdr;
5957
5958 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5959 return -EOPNOTSUPP;
5960
5961 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5962 if (!msg)
5963 return -ENOMEM;
5964
5965 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5966 NL80211_CMD_GET_WOWLAN);
5967 if (!hdr)
5968 goto nla_put_failure;
5969
5970 if (rdev->wowlan) {
5971 struct nlattr *nl_wowlan;
5972
5973 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5974 if (!nl_wowlan)
5975 goto nla_put_failure;
5976
5977 if (rdev->wowlan->any)
5978 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5979 if (rdev->wowlan->disconnect)
5980 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5981 if (rdev->wowlan->magic_pkt)
5982 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005983 if (rdev->wowlan->gtk_rekey_failure)
5984 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5985 if (rdev->wowlan->eap_identity_req)
5986 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5987 if (rdev->wowlan->four_way_handshake)
5988 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5989 if (rdev->wowlan->rfkill_release)
5990 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005991 if (rdev->wowlan->n_patterns) {
5992 struct nlattr *nl_pats, *nl_pat;
5993 int i, pat_len;
5994
5995 nl_pats = nla_nest_start(msg,
5996 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5997 if (!nl_pats)
5998 goto nla_put_failure;
5999
6000 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6001 nl_pat = nla_nest_start(msg, i + 1);
6002 if (!nl_pat)
6003 goto nla_put_failure;
6004 pat_len = rdev->wowlan->patterns[i].pattern_len;
6005 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
6006 DIV_ROUND_UP(pat_len, 8),
6007 rdev->wowlan->patterns[i].mask);
6008 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6009 pat_len,
6010 rdev->wowlan->patterns[i].pattern);
6011 nla_nest_end(msg, nl_pat);
6012 }
6013 nla_nest_end(msg, nl_pats);
6014 }
6015
6016 nla_nest_end(msg, nl_wowlan);
6017 }
6018
6019 genlmsg_end(msg, hdr);
6020 return genlmsg_reply(msg, info);
6021
6022nla_put_failure:
6023 nlmsg_free(msg);
6024 return -ENOBUFS;
6025}
6026
6027static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6028{
6029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6030 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6031 struct cfg80211_wowlan no_triggers = {};
6032 struct cfg80211_wowlan new_triggers = {};
6033 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6034 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006035 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006036
6037 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6038 return -EOPNOTSUPP;
6039
6040 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6041 goto no_triggers;
6042
6043 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6044 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6045 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6046 nl80211_wowlan_policy);
6047 if (err)
6048 return err;
6049
6050 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6051 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6052 return -EINVAL;
6053 new_triggers.any = true;
6054 }
6055
6056 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6057 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6058 return -EINVAL;
6059 new_triggers.disconnect = true;
6060 }
6061
6062 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6063 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6064 return -EINVAL;
6065 new_triggers.magic_pkt = true;
6066 }
6067
Johannes Berg77dbbb12011-07-13 10:48:55 +02006068 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6069 return -EINVAL;
6070
6071 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6072 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6073 return -EINVAL;
6074 new_triggers.gtk_rekey_failure = true;
6075 }
6076
6077 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6078 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6079 return -EINVAL;
6080 new_triggers.eap_identity_req = true;
6081 }
6082
6083 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6084 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6085 return -EINVAL;
6086 new_triggers.four_way_handshake = true;
6087 }
6088
6089 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6090 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6091 return -EINVAL;
6092 new_triggers.rfkill_release = true;
6093 }
6094
Johannes Bergff1b6e62011-05-04 15:37:28 +02006095 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6096 struct nlattr *pat;
6097 int n_patterns = 0;
6098 int rem, pat_len, mask_len;
6099 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6100
6101 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6102 rem)
6103 n_patterns++;
6104 if (n_patterns > wowlan->n_patterns)
6105 return -EINVAL;
6106
6107 new_triggers.patterns = kcalloc(n_patterns,
6108 sizeof(new_triggers.patterns[0]),
6109 GFP_KERNEL);
6110 if (!new_triggers.patterns)
6111 return -ENOMEM;
6112
6113 new_triggers.n_patterns = n_patterns;
6114 i = 0;
6115
6116 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6117 rem) {
6118 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6119 nla_data(pat), nla_len(pat), NULL);
6120 err = -EINVAL;
6121 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6122 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6123 goto error;
6124 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6125 mask_len = DIV_ROUND_UP(pat_len, 8);
6126 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6127 mask_len)
6128 goto error;
6129 if (pat_len > wowlan->pattern_max_len ||
6130 pat_len < wowlan->pattern_min_len)
6131 goto error;
6132
6133 new_triggers.patterns[i].mask =
6134 kmalloc(mask_len + pat_len, GFP_KERNEL);
6135 if (!new_triggers.patterns[i].mask) {
6136 err = -ENOMEM;
6137 goto error;
6138 }
6139 new_triggers.patterns[i].pattern =
6140 new_triggers.patterns[i].mask + mask_len;
6141 memcpy(new_triggers.patterns[i].mask,
6142 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6143 mask_len);
6144 new_triggers.patterns[i].pattern_len = pat_len;
6145 memcpy(new_triggers.patterns[i].pattern,
6146 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6147 pat_len);
6148 i++;
6149 }
6150 }
6151
6152 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6153 struct cfg80211_wowlan *ntrig;
6154 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6155 GFP_KERNEL);
6156 if (!ntrig) {
6157 err = -ENOMEM;
6158 goto error;
6159 }
6160 cfg80211_rdev_free_wowlan(rdev);
6161 rdev->wowlan = ntrig;
6162 } else {
6163 no_triggers:
6164 cfg80211_rdev_free_wowlan(rdev);
6165 rdev->wowlan = NULL;
6166 }
6167
Johannes Berg6d525632012-04-04 15:05:25 +02006168 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6169 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6170
Johannes Bergff1b6e62011-05-04 15:37:28 +02006171 return 0;
6172 error:
6173 for (i = 0; i < new_triggers.n_patterns; i++)
6174 kfree(new_triggers.patterns[i].mask);
6175 kfree(new_triggers.patterns);
6176 return err;
6177}
6178
Johannes Berge5497d72011-07-05 16:35:40 +02006179static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6180{
6181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6182 struct net_device *dev = info->user_ptr[1];
6183 struct wireless_dev *wdev = dev->ieee80211_ptr;
6184 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6185 struct cfg80211_gtk_rekey_data rekey_data;
6186 int err;
6187
6188 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6189 return -EINVAL;
6190
6191 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6192 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6193 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6194 nl80211_rekey_policy);
6195 if (err)
6196 return err;
6197
6198 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6199 return -ERANGE;
6200 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6201 return -ERANGE;
6202 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6203 return -ERANGE;
6204
6205 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6206 NL80211_KEK_LEN);
6207 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6208 NL80211_KCK_LEN);
6209 memcpy(rekey_data.replay_ctr,
6210 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6211 NL80211_REPLAY_CTR_LEN);
6212
6213 wdev_lock(wdev);
6214 if (!wdev->current_bss) {
6215 err = -ENOTCONN;
6216 goto out;
6217 }
6218
6219 if (!rdev->ops->set_rekey_data) {
6220 err = -EOPNOTSUPP;
6221 goto out;
6222 }
6223
6224 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6225 out:
6226 wdev_unlock(wdev);
6227 return err;
6228}
6229
Johannes Berg28946da2011-11-04 11:18:12 +01006230static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6231 struct genl_info *info)
6232{
6233 struct net_device *dev = info->user_ptr[1];
6234 struct wireless_dev *wdev = dev->ieee80211_ptr;
6235
6236 if (wdev->iftype != NL80211_IFTYPE_AP &&
6237 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6238 return -EINVAL;
6239
6240 if (wdev->ap_unexpected_nlpid)
6241 return -EBUSY;
6242
6243 wdev->ap_unexpected_nlpid = info->snd_pid;
6244 return 0;
6245}
6246
Johannes Berg7f6cf312011-11-04 11:18:15 +01006247static int nl80211_probe_client(struct sk_buff *skb,
6248 struct genl_info *info)
6249{
6250 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6251 struct net_device *dev = info->user_ptr[1];
6252 struct wireless_dev *wdev = dev->ieee80211_ptr;
6253 struct sk_buff *msg;
6254 void *hdr;
6255 const u8 *addr;
6256 u64 cookie;
6257 int err;
6258
6259 if (wdev->iftype != NL80211_IFTYPE_AP &&
6260 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6261 return -EOPNOTSUPP;
6262
6263 if (!info->attrs[NL80211_ATTR_MAC])
6264 return -EINVAL;
6265
6266 if (!rdev->ops->probe_client)
6267 return -EOPNOTSUPP;
6268
6269 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6270 if (!msg)
6271 return -ENOMEM;
6272
6273 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6274 NL80211_CMD_PROBE_CLIENT);
6275
6276 if (IS_ERR(hdr)) {
6277 err = PTR_ERR(hdr);
6278 goto free_msg;
6279 }
6280
6281 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6282
6283 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6284 if (err)
6285 goto free_msg;
6286
6287 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6288
6289 genlmsg_end(msg, hdr);
6290
6291 return genlmsg_reply(msg, info);
6292
6293 nla_put_failure:
6294 err = -ENOBUFS;
6295 free_msg:
6296 nlmsg_free(msg);
6297 return err;
6298}
6299
Johannes Berg5e760232011-11-04 11:18:17 +01006300static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6301{
6302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6303
6304 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6305 return -EOPNOTSUPP;
6306
6307 if (rdev->ap_beacons_nlpid)
6308 return -EBUSY;
6309
6310 rdev->ap_beacons_nlpid = info->snd_pid;
6311
6312 return 0;
6313}
6314
Johannes Berg4c476992010-10-04 21:36:35 +02006315#define NL80211_FLAG_NEED_WIPHY 0x01
6316#define NL80211_FLAG_NEED_NETDEV 0x02
6317#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006318#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6319#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6320 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006321
6322static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6323 struct genl_info *info)
6324{
6325 struct cfg80211_registered_device *rdev;
6326 struct net_device *dev;
6327 int err;
6328 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6329
6330 if (rtnl)
6331 rtnl_lock();
6332
6333 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
6334 rdev = cfg80211_get_dev_from_info(info);
6335 if (IS_ERR(rdev)) {
6336 if (rtnl)
6337 rtnl_unlock();
6338 return PTR_ERR(rdev);
6339 }
6340 info->user_ptr[0] = rdev;
6341 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006342 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6343 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006344 if (err) {
6345 if (rtnl)
6346 rtnl_unlock();
6347 return err;
6348 }
Johannes Berg41265712010-10-04 21:14:05 +02006349 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6350 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006351 cfg80211_unlock_rdev(rdev);
6352 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006353 if (rtnl)
6354 rtnl_unlock();
6355 return -ENETDOWN;
6356 }
Johannes Berg4c476992010-10-04 21:36:35 +02006357 info->user_ptr[0] = rdev;
6358 info->user_ptr[1] = dev;
6359 }
6360
6361 return 0;
6362}
6363
6364static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6365 struct genl_info *info)
6366{
6367 if (info->user_ptr[0])
6368 cfg80211_unlock_rdev(info->user_ptr[0]);
6369 if (info->user_ptr[1])
6370 dev_put(info->user_ptr[1]);
6371 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6372 rtnl_unlock();
6373}
6374
Johannes Berg55682962007-09-20 13:09:35 -04006375static struct genl_ops nl80211_ops[] = {
6376 {
6377 .cmd = NL80211_CMD_GET_WIPHY,
6378 .doit = nl80211_get_wiphy,
6379 .dumpit = nl80211_dump_wiphy,
6380 .policy = nl80211_policy,
6381 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006382 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006383 },
6384 {
6385 .cmd = NL80211_CMD_SET_WIPHY,
6386 .doit = nl80211_set_wiphy,
6387 .policy = nl80211_policy,
6388 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006389 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006390 },
6391 {
6392 .cmd = NL80211_CMD_GET_INTERFACE,
6393 .doit = nl80211_get_interface,
6394 .dumpit = nl80211_dump_interface,
6395 .policy = nl80211_policy,
6396 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006397 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006398 },
6399 {
6400 .cmd = NL80211_CMD_SET_INTERFACE,
6401 .doit = nl80211_set_interface,
6402 .policy = nl80211_policy,
6403 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006404 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6405 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006406 },
6407 {
6408 .cmd = NL80211_CMD_NEW_INTERFACE,
6409 .doit = nl80211_new_interface,
6410 .policy = nl80211_policy,
6411 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006412 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6413 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006414 },
6415 {
6416 .cmd = NL80211_CMD_DEL_INTERFACE,
6417 .doit = nl80211_del_interface,
6418 .policy = nl80211_policy,
6419 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006420 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6421 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006422 },
Johannes Berg41ade002007-12-19 02:03:29 +01006423 {
6424 .cmd = NL80211_CMD_GET_KEY,
6425 .doit = nl80211_get_key,
6426 .policy = nl80211_policy,
6427 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006429 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006430 },
6431 {
6432 .cmd = NL80211_CMD_SET_KEY,
6433 .doit = nl80211_set_key,
6434 .policy = nl80211_policy,
6435 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006436 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006437 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006438 },
6439 {
6440 .cmd = NL80211_CMD_NEW_KEY,
6441 .doit = nl80211_new_key,
6442 .policy = nl80211_policy,
6443 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006444 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006445 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006446 },
6447 {
6448 .cmd = NL80211_CMD_DEL_KEY,
6449 .doit = nl80211_del_key,
6450 .policy = nl80211_policy,
6451 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006452 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006453 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006454 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006455 {
6456 .cmd = NL80211_CMD_SET_BEACON,
6457 .policy = nl80211_policy,
6458 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006459 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006460 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006461 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006462 },
6463 {
Johannes Berg88600202012-02-13 15:17:18 +01006464 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006465 .policy = nl80211_policy,
6466 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006467 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006468 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006469 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006470 },
6471 {
Johannes Berg88600202012-02-13 15:17:18 +01006472 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006473 .policy = nl80211_policy,
6474 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006475 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006477 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006478 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006479 {
6480 .cmd = NL80211_CMD_GET_STATION,
6481 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006482 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006483 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006484 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6485 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006486 },
6487 {
6488 .cmd = NL80211_CMD_SET_STATION,
6489 .doit = nl80211_set_station,
6490 .policy = nl80211_policy,
6491 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006492 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006493 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006494 },
6495 {
6496 .cmd = NL80211_CMD_NEW_STATION,
6497 .doit = nl80211_new_station,
6498 .policy = nl80211_policy,
6499 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006500 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006501 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006502 },
6503 {
6504 .cmd = NL80211_CMD_DEL_STATION,
6505 .doit = nl80211_del_station,
6506 .policy = nl80211_policy,
6507 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006508 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006509 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006510 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006511 {
6512 .cmd = NL80211_CMD_GET_MPATH,
6513 .doit = nl80211_get_mpath,
6514 .dumpit = nl80211_dump_mpath,
6515 .policy = nl80211_policy,
6516 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006518 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006519 },
6520 {
6521 .cmd = NL80211_CMD_SET_MPATH,
6522 .doit = nl80211_set_mpath,
6523 .policy = nl80211_policy,
6524 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006526 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006527 },
6528 {
6529 .cmd = NL80211_CMD_NEW_MPATH,
6530 .doit = nl80211_new_mpath,
6531 .policy = nl80211_policy,
6532 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006534 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006535 },
6536 {
6537 .cmd = NL80211_CMD_DEL_MPATH,
6538 .doit = nl80211_del_mpath,
6539 .policy = nl80211_policy,
6540 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006542 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006543 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006544 {
6545 .cmd = NL80211_CMD_SET_BSS,
6546 .doit = nl80211_set_bss,
6547 .policy = nl80211_policy,
6548 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006550 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006551 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006552 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006553 .cmd = NL80211_CMD_GET_REG,
6554 .doit = nl80211_get_reg,
6555 .policy = nl80211_policy,
6556 /* can be retrieved by unprivileged users */
6557 },
6558 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006559 .cmd = NL80211_CMD_SET_REG,
6560 .doit = nl80211_set_reg,
6561 .policy = nl80211_policy,
6562 .flags = GENL_ADMIN_PERM,
6563 },
6564 {
6565 .cmd = NL80211_CMD_REQ_SET_REG,
6566 .doit = nl80211_req_set_reg,
6567 .policy = nl80211_policy,
6568 .flags = GENL_ADMIN_PERM,
6569 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006570 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006571 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6572 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006573 .policy = nl80211_policy,
6574 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006575 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006576 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006577 },
6578 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006579 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6580 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006581 .policy = nl80211_policy,
6582 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006584 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006585 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006586 {
Johannes Berg2a519312009-02-10 21:25:55 +01006587 .cmd = NL80211_CMD_TRIGGER_SCAN,
6588 .doit = nl80211_trigger_scan,
6589 .policy = nl80211_policy,
6590 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006592 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006593 },
6594 {
6595 .cmd = NL80211_CMD_GET_SCAN,
6596 .policy = nl80211_policy,
6597 .dumpit = nl80211_dump_scan,
6598 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006599 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006600 .cmd = NL80211_CMD_START_SCHED_SCAN,
6601 .doit = nl80211_start_sched_scan,
6602 .policy = nl80211_policy,
6603 .flags = GENL_ADMIN_PERM,
6604 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6605 NL80211_FLAG_NEED_RTNL,
6606 },
6607 {
6608 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6609 .doit = nl80211_stop_sched_scan,
6610 .policy = nl80211_policy,
6611 .flags = GENL_ADMIN_PERM,
6612 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6613 NL80211_FLAG_NEED_RTNL,
6614 },
6615 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006616 .cmd = NL80211_CMD_AUTHENTICATE,
6617 .doit = nl80211_authenticate,
6618 .policy = nl80211_policy,
6619 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006620 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006621 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006622 },
6623 {
6624 .cmd = NL80211_CMD_ASSOCIATE,
6625 .doit = nl80211_associate,
6626 .policy = nl80211_policy,
6627 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006628 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006629 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006630 },
6631 {
6632 .cmd = NL80211_CMD_DEAUTHENTICATE,
6633 .doit = nl80211_deauthenticate,
6634 .policy = nl80211_policy,
6635 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006636 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006637 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006638 },
6639 {
6640 .cmd = NL80211_CMD_DISASSOCIATE,
6641 .doit = nl80211_disassociate,
6642 .policy = nl80211_policy,
6643 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006644 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006645 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006646 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006647 {
6648 .cmd = NL80211_CMD_JOIN_IBSS,
6649 .doit = nl80211_join_ibss,
6650 .policy = nl80211_policy,
6651 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006652 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006653 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006654 },
6655 {
6656 .cmd = NL80211_CMD_LEAVE_IBSS,
6657 .doit = nl80211_leave_ibss,
6658 .policy = nl80211_policy,
6659 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006660 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006661 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006662 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006663#ifdef CONFIG_NL80211_TESTMODE
6664 {
6665 .cmd = NL80211_CMD_TESTMODE,
6666 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006667 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006668 .policy = nl80211_policy,
6669 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006670 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6671 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006672 },
6673#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006674 {
6675 .cmd = NL80211_CMD_CONNECT,
6676 .doit = nl80211_connect,
6677 .policy = nl80211_policy,
6678 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006680 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006681 },
6682 {
6683 .cmd = NL80211_CMD_DISCONNECT,
6684 .doit = nl80211_disconnect,
6685 .policy = nl80211_policy,
6686 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006688 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006689 },
Johannes Berg463d0182009-07-14 00:33:35 +02006690 {
6691 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6692 .doit = nl80211_wiphy_netns,
6693 .policy = nl80211_policy,
6694 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006695 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6696 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006697 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006698 {
6699 .cmd = NL80211_CMD_GET_SURVEY,
6700 .policy = nl80211_policy,
6701 .dumpit = nl80211_dump_survey,
6702 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006703 {
6704 .cmd = NL80211_CMD_SET_PMKSA,
6705 .doit = nl80211_setdel_pmksa,
6706 .policy = nl80211_policy,
6707 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006708 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006709 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006710 },
6711 {
6712 .cmd = NL80211_CMD_DEL_PMKSA,
6713 .doit = nl80211_setdel_pmksa,
6714 .policy = nl80211_policy,
6715 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006716 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006717 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006718 },
6719 {
6720 .cmd = NL80211_CMD_FLUSH_PMKSA,
6721 .doit = nl80211_flush_pmksa,
6722 .policy = nl80211_policy,
6723 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006724 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006725 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006726 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006727 {
6728 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6729 .doit = nl80211_remain_on_channel,
6730 .policy = nl80211_policy,
6731 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006732 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006733 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006734 },
6735 {
6736 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6737 .doit = nl80211_cancel_remain_on_channel,
6738 .policy = nl80211_policy,
6739 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006740 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006741 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006742 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006743 {
6744 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6745 .doit = nl80211_set_tx_bitrate_mask,
6746 .policy = nl80211_policy,
6747 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006748 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6749 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006750 },
Jouni Malinen026331c2010-02-15 12:53:10 +02006751 {
Johannes Berg2e161f782010-08-12 15:38:38 +02006752 .cmd = NL80211_CMD_REGISTER_FRAME,
6753 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006754 .policy = nl80211_policy,
6755 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006756 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6757 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006758 },
6759 {
Johannes Berg2e161f782010-08-12 15:38:38 +02006760 .cmd = NL80211_CMD_FRAME,
6761 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006762 .policy = nl80211_policy,
6763 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006764 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006765 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006766 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006767 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006768 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6769 .doit = nl80211_tx_mgmt_cancel_wait,
6770 .policy = nl80211_policy,
6771 .flags = GENL_ADMIN_PERM,
6772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6773 NL80211_FLAG_NEED_RTNL,
6774 },
6775 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006776 .cmd = NL80211_CMD_SET_POWER_SAVE,
6777 .doit = nl80211_set_power_save,
6778 .policy = nl80211_policy,
6779 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006780 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6781 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006782 },
6783 {
6784 .cmd = NL80211_CMD_GET_POWER_SAVE,
6785 .doit = nl80211_get_power_save,
6786 .policy = nl80211_policy,
6787 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006788 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6789 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006790 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006791 {
6792 .cmd = NL80211_CMD_SET_CQM,
6793 .doit = nl80211_set_cqm,
6794 .policy = nl80211_policy,
6795 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006796 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6797 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006798 },
Johannes Bergf444de02010-05-05 15:25:02 +02006799 {
6800 .cmd = NL80211_CMD_SET_CHANNEL,
6801 .doit = nl80211_set_channel,
6802 .policy = nl80211_policy,
6803 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006804 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6805 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006806 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006807 {
6808 .cmd = NL80211_CMD_SET_WDS_PEER,
6809 .doit = nl80211_set_wds_peer,
6810 .policy = nl80211_policy,
6811 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006812 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6813 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006814 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006815 {
6816 .cmd = NL80211_CMD_JOIN_MESH,
6817 .doit = nl80211_join_mesh,
6818 .policy = nl80211_policy,
6819 .flags = GENL_ADMIN_PERM,
6820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6821 NL80211_FLAG_NEED_RTNL,
6822 },
6823 {
6824 .cmd = NL80211_CMD_LEAVE_MESH,
6825 .doit = nl80211_leave_mesh,
6826 .policy = nl80211_policy,
6827 .flags = GENL_ADMIN_PERM,
6828 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6829 NL80211_FLAG_NEED_RTNL,
6830 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006831 {
6832 .cmd = NL80211_CMD_GET_WOWLAN,
6833 .doit = nl80211_get_wowlan,
6834 .policy = nl80211_policy,
6835 /* can be retrieved by unprivileged users */
6836 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6837 NL80211_FLAG_NEED_RTNL,
6838 },
6839 {
6840 .cmd = NL80211_CMD_SET_WOWLAN,
6841 .doit = nl80211_set_wowlan,
6842 .policy = nl80211_policy,
6843 .flags = GENL_ADMIN_PERM,
6844 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6845 NL80211_FLAG_NEED_RTNL,
6846 },
Johannes Berge5497d72011-07-05 16:35:40 +02006847 {
6848 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6849 .doit = nl80211_set_rekey_data,
6850 .policy = nl80211_policy,
6851 .flags = GENL_ADMIN_PERM,
6852 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6853 NL80211_FLAG_NEED_RTNL,
6854 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03006855 {
6856 .cmd = NL80211_CMD_TDLS_MGMT,
6857 .doit = nl80211_tdls_mgmt,
6858 .policy = nl80211_policy,
6859 .flags = GENL_ADMIN_PERM,
6860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6861 NL80211_FLAG_NEED_RTNL,
6862 },
6863 {
6864 .cmd = NL80211_CMD_TDLS_OPER,
6865 .doit = nl80211_tdls_oper,
6866 .policy = nl80211_policy,
6867 .flags = GENL_ADMIN_PERM,
6868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6869 NL80211_FLAG_NEED_RTNL,
6870 },
Johannes Berg28946da2011-11-04 11:18:12 +01006871 {
6872 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6873 .doit = nl80211_register_unexpected_frame,
6874 .policy = nl80211_policy,
6875 .flags = GENL_ADMIN_PERM,
6876 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6877 NL80211_FLAG_NEED_RTNL,
6878 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01006879 {
6880 .cmd = NL80211_CMD_PROBE_CLIENT,
6881 .doit = nl80211_probe_client,
6882 .policy = nl80211_policy,
6883 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006884 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01006885 NL80211_FLAG_NEED_RTNL,
6886 },
Johannes Berg5e760232011-11-04 11:18:17 +01006887 {
6888 .cmd = NL80211_CMD_REGISTER_BEACONS,
6889 .doit = nl80211_register_beacons,
6890 .policy = nl80211_policy,
6891 .flags = GENL_ADMIN_PERM,
6892 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6893 NL80211_FLAG_NEED_RTNL,
6894 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01006895 {
6896 .cmd = NL80211_CMD_SET_NOACK_MAP,
6897 .doit = nl80211_set_noack_map,
6898 .policy = nl80211_policy,
6899 .flags = GENL_ADMIN_PERM,
6900 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6901 NL80211_FLAG_NEED_RTNL,
6902 },
6903
Johannes Berg55682962007-09-20 13:09:35 -04006904};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006905
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006906static struct genl_multicast_group nl80211_mlme_mcgrp = {
6907 .name = "mlme",
6908};
Johannes Berg55682962007-09-20 13:09:35 -04006909
6910/* multicast groups */
6911static struct genl_multicast_group nl80211_config_mcgrp = {
6912 .name = "config",
6913};
Johannes Berg2a519312009-02-10 21:25:55 +01006914static struct genl_multicast_group nl80211_scan_mcgrp = {
6915 .name = "scan",
6916};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006917static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6918 .name = "regulatory",
6919};
Johannes Berg55682962007-09-20 13:09:35 -04006920
6921/* notification functions */
6922
6923void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6924{
6925 struct sk_buff *msg;
6926
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006928 if (!msg)
6929 return;
6930
6931 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6932 nlmsg_free(msg);
6933 return;
6934 }
6935
Johannes Berg463d0182009-07-14 00:33:35 +02006936 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6937 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006938}
6939
Johannes Berg362a4152009-05-24 16:43:15 +02006940static int nl80211_add_scan_req(struct sk_buff *msg,
6941 struct cfg80211_registered_device *rdev)
6942{
6943 struct cfg80211_scan_request *req = rdev->scan_req;
6944 struct nlattr *nest;
6945 int i;
6946
Johannes Berg667503d2009-07-07 03:56:11 +02006947 ASSERT_RDEV_LOCK(rdev);
6948
Johannes Berg362a4152009-05-24 16:43:15 +02006949 if (WARN_ON(!req))
6950 return 0;
6951
6952 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6953 if (!nest)
6954 goto nla_put_failure;
6955 for (i = 0; i < req->n_ssids; i++)
6956 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6957 nla_nest_end(msg, nest);
6958
6959 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6960 if (!nest)
6961 goto nla_put_failure;
6962 for (i = 0; i < req->n_channels; i++)
6963 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6964 nla_nest_end(msg, nest);
6965
6966 if (req->ie)
6967 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6968
6969 return 0;
6970 nla_put_failure:
6971 return -ENOBUFS;
6972}
6973
Johannes Berga538e2d2009-06-16 19:56:42 +02006974static int nl80211_send_scan_msg(struct sk_buff *msg,
6975 struct cfg80211_registered_device *rdev,
6976 struct net_device *netdev,
6977 u32 pid, u32 seq, int flags,
6978 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006979{
6980 void *hdr;
6981
6982 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6983 if (!hdr)
6984 return -1;
6985
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006986 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006987 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6988
Johannes Berg362a4152009-05-24 16:43:15 +02006989 /* ignore errors and send incomplete event anyway */
6990 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006991
6992 return genlmsg_end(msg, hdr);
6993
6994 nla_put_failure:
6995 genlmsg_cancel(msg, hdr);
6996 return -EMSGSIZE;
6997}
6998
Luciano Coelho807f8a82011-05-11 17:09:35 +03006999static int
7000nl80211_send_sched_scan_msg(struct sk_buff *msg,
7001 struct cfg80211_registered_device *rdev,
7002 struct net_device *netdev,
7003 u32 pid, u32 seq, int flags, u32 cmd)
7004{
7005 void *hdr;
7006
7007 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7008 if (!hdr)
7009 return -1;
7010
7011 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7012 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7013
7014 return genlmsg_end(msg, hdr);
7015
7016 nla_put_failure:
7017 genlmsg_cancel(msg, hdr);
7018 return -EMSGSIZE;
7019}
7020
Johannes Berga538e2d2009-06-16 19:56:42 +02007021void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7022 struct net_device *netdev)
7023{
7024 struct sk_buff *msg;
7025
7026 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7027 if (!msg)
7028 return;
7029
7030 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7031 NL80211_CMD_TRIGGER_SCAN) < 0) {
7032 nlmsg_free(msg);
7033 return;
7034 }
7035
Johannes Berg463d0182009-07-14 00:33:35 +02007036 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7037 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007038}
7039
Johannes Berg2a519312009-02-10 21:25:55 +01007040void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7041 struct net_device *netdev)
7042{
7043 struct sk_buff *msg;
7044
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007046 if (!msg)
7047 return;
7048
Johannes Berga538e2d2009-06-16 19:56:42 +02007049 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7050 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007051 nlmsg_free(msg);
7052 return;
7053 }
7054
Johannes Berg463d0182009-07-14 00:33:35 +02007055 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7056 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007057}
7058
7059void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7060 struct net_device *netdev)
7061{
7062 struct sk_buff *msg;
7063
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007064 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007065 if (!msg)
7066 return;
7067
Johannes Berga538e2d2009-06-16 19:56:42 +02007068 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7069 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007070 nlmsg_free(msg);
7071 return;
7072 }
7073
Johannes Berg463d0182009-07-14 00:33:35 +02007074 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7075 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007076}
7077
Luciano Coelho807f8a82011-05-11 17:09:35 +03007078void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7079 struct net_device *netdev)
7080{
7081 struct sk_buff *msg;
7082
7083 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7084 if (!msg)
7085 return;
7086
7087 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7088 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7089 nlmsg_free(msg);
7090 return;
7091 }
7092
7093 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7094 nl80211_scan_mcgrp.id, GFP_KERNEL);
7095}
7096
7097void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7098 struct net_device *netdev, u32 cmd)
7099{
7100 struct sk_buff *msg;
7101
7102 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7103 if (!msg)
7104 return;
7105
7106 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7107 nlmsg_free(msg);
7108 return;
7109 }
7110
7111 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7112 nl80211_scan_mcgrp.id, GFP_KERNEL);
7113}
7114
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007115/*
7116 * This can happen on global regulatory changes or device specific settings
7117 * based on custom world regulatory domains.
7118 */
7119void nl80211_send_reg_change_event(struct regulatory_request *request)
7120{
7121 struct sk_buff *msg;
7122 void *hdr;
7123
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007124 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007125 if (!msg)
7126 return;
7127
7128 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7129 if (!hdr) {
7130 nlmsg_free(msg);
7131 return;
7132 }
7133
7134 /* Userspace can always count this one always being set */
7135 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
7136
7137 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
7138 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7139 NL80211_REGDOM_TYPE_WORLD);
7140 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
7141 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7142 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
7143 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7144 request->intersect)
7145 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7146 NL80211_REGDOM_TYPE_INTERSECTION);
7147 else {
7148 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7149 NL80211_REGDOM_TYPE_COUNTRY);
7150 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
7151 }
7152
7153 if (wiphy_idx_valid(request->wiphy_idx))
7154 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
7155
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007156 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007157
Johannes Bergbc43b282009-07-25 10:54:13 +02007158 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007159 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007160 GFP_ATOMIC);
7161 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007162
7163 return;
7164
7165nla_put_failure:
7166 genlmsg_cancel(msg, hdr);
7167 nlmsg_free(msg);
7168}
7169
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007170static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7171 struct net_device *netdev,
7172 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007173 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007174{
7175 struct sk_buff *msg;
7176 void *hdr;
7177
Johannes Berge6d6e342009-07-01 21:26:47 +02007178 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007179 if (!msg)
7180 return;
7181
7182 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7183 if (!hdr) {
7184 nlmsg_free(msg);
7185 return;
7186 }
7187
7188 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7189 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7190 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7191
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007192 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007193
Johannes Berg463d0182009-07-14 00:33:35 +02007194 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7195 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007196 return;
7197
7198 nla_put_failure:
7199 genlmsg_cancel(msg, hdr);
7200 nlmsg_free(msg);
7201}
7202
7203void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007204 struct net_device *netdev, const u8 *buf,
7205 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007206{
7207 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007208 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007209}
7210
7211void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7212 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007213 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007214{
Johannes Berge6d6e342009-07-01 21:26:47 +02007215 nl80211_send_mlme_event(rdev, netdev, buf, len,
7216 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007217}
7218
Jouni Malinen53b46b82009-03-27 20:53:56 +02007219void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007220 struct net_device *netdev, const u8 *buf,
7221 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007222{
7223 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007224 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007225}
7226
Jouni Malinen53b46b82009-03-27 20:53:56 +02007227void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7228 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007229 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007230{
7231 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007232 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007233}
7234
Jouni Malinencf4e5942010-12-16 00:52:40 +02007235void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7236 struct net_device *netdev, const u8 *buf,
7237 size_t len, gfp_t gfp)
7238{
7239 nl80211_send_mlme_event(rdev, netdev, buf, len,
7240 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7241}
7242
7243void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7244 struct net_device *netdev, const u8 *buf,
7245 size_t len, gfp_t gfp)
7246{
7247 nl80211_send_mlme_event(rdev, netdev, buf, len,
7248 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7249}
7250
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007251static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7252 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007253 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007254{
7255 struct sk_buff *msg;
7256 void *hdr;
7257
Johannes Berge6d6e342009-07-01 21:26:47 +02007258 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007259 if (!msg)
7260 return;
7261
7262 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7263 if (!hdr) {
7264 nlmsg_free(msg);
7265 return;
7266 }
7267
7268 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7269 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7270 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
7271 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7272
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007273 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007274
Johannes Berg463d0182009-07-14 00:33:35 +02007275 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7276 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007277 return;
7278
7279 nla_put_failure:
7280 genlmsg_cancel(msg, hdr);
7281 nlmsg_free(msg);
7282}
7283
7284void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007285 struct net_device *netdev, const u8 *addr,
7286 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007287{
7288 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007289 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007290}
7291
7292void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007293 struct net_device *netdev, const u8 *addr,
7294 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007295{
Johannes Berge6d6e342009-07-01 21:26:47 +02007296 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7297 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007298}
7299
Samuel Ortizb23aa672009-07-01 21:26:54 +02007300void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7301 struct net_device *netdev, const u8 *bssid,
7302 const u8 *req_ie, size_t req_ie_len,
7303 const u8 *resp_ie, size_t resp_ie_len,
7304 u16 status, gfp_t gfp)
7305{
7306 struct sk_buff *msg;
7307 void *hdr;
7308
7309 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7310 if (!msg)
7311 return;
7312
7313 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7314 if (!hdr) {
7315 nlmsg_free(msg);
7316 return;
7317 }
7318
7319 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7320 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7321 if (bssid)
7322 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7323 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
7324 if (req_ie)
7325 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7326 if (resp_ie)
7327 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7328
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007329 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007330
Johannes Berg463d0182009-07-14 00:33:35 +02007331 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7332 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007333 return;
7334
7335 nla_put_failure:
7336 genlmsg_cancel(msg, hdr);
7337 nlmsg_free(msg);
7338
7339}
7340
7341void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7342 struct net_device *netdev, const u8 *bssid,
7343 const u8 *req_ie, size_t req_ie_len,
7344 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7345{
7346 struct sk_buff *msg;
7347 void *hdr;
7348
7349 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7350 if (!msg)
7351 return;
7352
7353 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7354 if (!hdr) {
7355 nlmsg_free(msg);
7356 return;
7357 }
7358
7359 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7360 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7361 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7362 if (req_ie)
7363 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7364 if (resp_ie)
7365 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7366
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007367 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007368
Johannes Berg463d0182009-07-14 00:33:35 +02007369 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7370 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007371 return;
7372
7373 nla_put_failure:
7374 genlmsg_cancel(msg, hdr);
7375 nlmsg_free(msg);
7376
7377}
7378
7379void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7380 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02007381 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007382{
7383 struct sk_buff *msg;
7384 void *hdr;
7385
Johannes Berg667503d2009-07-07 03:56:11 +02007386 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007387 if (!msg)
7388 return;
7389
7390 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7391 if (!hdr) {
7392 nlmsg_free(msg);
7393 return;
7394 }
7395
7396 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7397 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7398 if (from_ap && reason)
7399 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
7400 if (from_ap)
7401 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
7402 if (ie)
7403 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
7404
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007405 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007406
Johannes Berg463d0182009-07-14 00:33:35 +02007407 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7408 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007409 return;
7410
7411 nla_put_failure:
7412 genlmsg_cancel(msg, hdr);
7413 nlmsg_free(msg);
7414
7415}
7416
Johannes Berg04a773a2009-04-19 21:24:32 +02007417void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7418 struct net_device *netdev, const u8 *bssid,
7419 gfp_t gfp)
7420{
7421 struct sk_buff *msg;
7422 void *hdr;
7423
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007425 if (!msg)
7426 return;
7427
7428 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7429 if (!hdr) {
7430 nlmsg_free(msg);
7431 return;
7432 }
7433
7434 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7435 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7436 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7437
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007438 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007439
Johannes Berg463d0182009-07-14 00:33:35 +02007440 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7441 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007442 return;
7443
7444 nla_put_failure:
7445 genlmsg_cancel(msg, hdr);
7446 nlmsg_free(msg);
7447}
7448
Javier Cardonac93b5e72011-04-07 15:08:34 -07007449void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7450 struct net_device *netdev,
7451 const u8 *macaddr, const u8* ie, u8 ie_len,
7452 gfp_t gfp)
7453{
7454 struct sk_buff *msg;
7455 void *hdr;
7456
7457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7458 if (!msg)
7459 return;
7460
7461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7462 if (!hdr) {
7463 nlmsg_free(msg);
7464 return;
7465 }
7466
7467 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7468 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7469 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
7470 if (ie_len && ie)
7471 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
7472
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007473 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007474
7475 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7476 nl80211_mlme_mcgrp.id, gfp);
7477 return;
7478
7479 nla_put_failure:
7480 genlmsg_cancel(msg, hdr);
7481 nlmsg_free(msg);
7482}
7483
Jouni Malinena3b8b052009-03-27 21:59:49 +02007484void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7485 struct net_device *netdev, const u8 *addr,
7486 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007487 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007488{
7489 struct sk_buff *msg;
7490 void *hdr;
7491
Johannes Berge6d6e342009-07-01 21:26:47 +02007492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007493 if (!msg)
7494 return;
7495
7496 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7497 if (!hdr) {
7498 nlmsg_free(msg);
7499 return;
7500 }
7501
7502 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7503 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7504 if (addr)
7505 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7506 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03007507 if (key_id != -1)
7508 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007509 if (tsc)
7510 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7511
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007512 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007513
Johannes Berg463d0182009-07-14 00:33:35 +02007514 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7515 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007516 return;
7517
7518 nla_put_failure:
7519 genlmsg_cancel(msg, hdr);
7520 nlmsg_free(msg);
7521}
7522
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007523void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7524 struct ieee80211_channel *channel_before,
7525 struct ieee80211_channel *channel_after)
7526{
7527 struct sk_buff *msg;
7528 void *hdr;
7529 struct nlattr *nl_freq;
7530
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007532 if (!msg)
7533 return;
7534
7535 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7536 if (!hdr) {
7537 nlmsg_free(msg);
7538 return;
7539 }
7540
7541 /*
7542 * Since we are applying the beacon hint to a wiphy we know its
7543 * wiphy_idx is valid
7544 */
7545 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7546
7547 /* Before */
7548 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7549 if (!nl_freq)
7550 goto nla_put_failure;
7551 if (nl80211_msg_put_channel(msg, channel_before))
7552 goto nla_put_failure;
7553 nla_nest_end(msg, nl_freq);
7554
7555 /* After */
7556 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7557 if (!nl_freq)
7558 goto nla_put_failure;
7559 if (nl80211_msg_put_channel(msg, channel_after))
7560 goto nla_put_failure;
7561 nla_nest_end(msg, nl_freq);
7562
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007563 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007564
Johannes Berg463d0182009-07-14 00:33:35 +02007565 rcu_read_lock();
7566 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7567 GFP_ATOMIC);
7568 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007569
7570 return;
7571
7572nla_put_failure:
7573 genlmsg_cancel(msg, hdr);
7574 nlmsg_free(msg);
7575}
7576
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007577static void nl80211_send_remain_on_chan_event(
7578 int cmd, struct cfg80211_registered_device *rdev,
7579 struct net_device *netdev, u64 cookie,
7580 struct ieee80211_channel *chan,
7581 enum nl80211_channel_type channel_type,
7582 unsigned int duration, gfp_t gfp)
7583{
7584 struct sk_buff *msg;
7585 void *hdr;
7586
7587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7588 if (!msg)
7589 return;
7590
7591 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7592 if (!hdr) {
7593 nlmsg_free(msg);
7594 return;
7595 }
7596
7597 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7598 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7599 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7600 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7601 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7602
7603 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7604 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7605
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007606 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007607
7608 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7609 nl80211_mlme_mcgrp.id, gfp);
7610 return;
7611
7612 nla_put_failure:
7613 genlmsg_cancel(msg, hdr);
7614 nlmsg_free(msg);
7615}
7616
7617void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7618 struct net_device *netdev, u64 cookie,
7619 struct ieee80211_channel *chan,
7620 enum nl80211_channel_type channel_type,
7621 unsigned int duration, gfp_t gfp)
7622{
7623 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7624 rdev, netdev, cookie, chan,
7625 channel_type, duration, gfp);
7626}
7627
7628void nl80211_send_remain_on_channel_cancel(
7629 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7630 u64 cookie, struct ieee80211_channel *chan,
7631 enum nl80211_channel_type channel_type, gfp_t gfp)
7632{
7633 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7634 rdev, netdev, cookie, chan,
7635 channel_type, 0, gfp);
7636}
7637
Johannes Berg98b62182009-12-23 13:15:44 +01007638void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7639 struct net_device *dev, const u8 *mac_addr,
7640 struct station_info *sinfo, gfp_t gfp)
7641{
7642 struct sk_buff *msg;
7643
7644 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7645 if (!msg)
7646 return;
7647
John W. Linville66266b32012-03-15 13:25:41 -04007648 if (nl80211_send_station(msg, 0, 0, 0,
7649 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007650 nlmsg_free(msg);
7651 return;
7652 }
7653
7654 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7655 nl80211_mlme_mcgrp.id, gfp);
7656}
7657
Jouni Malinenec15e682011-03-23 15:29:52 +02007658void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7659 struct net_device *dev, const u8 *mac_addr,
7660 gfp_t gfp)
7661{
7662 struct sk_buff *msg;
7663 void *hdr;
7664
7665 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7666 if (!msg)
7667 return;
7668
7669 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7670 if (!hdr) {
7671 nlmsg_free(msg);
7672 return;
7673 }
7674
7675 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7676 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7677
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007678 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007679
7680 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7681 nl80211_mlme_mcgrp.id, gfp);
7682 return;
7683
7684 nla_put_failure:
7685 genlmsg_cancel(msg, hdr);
7686 nlmsg_free(msg);
7687}
7688
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007689static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
7690 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01007691{
7692 struct wireless_dev *wdev = dev->ieee80211_ptr;
7693 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7694 struct sk_buff *msg;
7695 void *hdr;
7696 int err;
7697 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7698
7699 if (!nlpid)
7700 return false;
7701
7702 msg = nlmsg_new(100, gfp);
7703 if (!msg)
7704 return true;
7705
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007706 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01007707 if (!hdr) {
7708 nlmsg_free(msg);
7709 return true;
7710 }
7711
7712 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7713 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7714 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7715
7716 err = genlmsg_end(msg, hdr);
7717 if (err < 0) {
7718 nlmsg_free(msg);
7719 return true;
7720 }
7721
7722 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7723 return true;
7724
7725 nla_put_failure:
7726 genlmsg_cancel(msg, hdr);
7727 nlmsg_free(msg);
7728 return true;
7729}
7730
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007731bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7732{
7733 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
7734 addr, gfp);
7735}
7736
7737bool nl80211_unexpected_4addr_frame(struct net_device *dev,
7738 const u8 *addr, gfp_t gfp)
7739{
7740 return __nl80211_unexpected_frame(dev,
7741 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
7742 addr, gfp);
7743}
7744
Johannes Berg2e161f782010-08-12 15:38:38 +02007745int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7746 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01007747 int freq, int sig_dbm,
7748 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007749{
7750 struct sk_buff *msg;
7751 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02007752
7753 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7754 if (!msg)
7755 return -ENOMEM;
7756
Johannes Berg2e161f782010-08-12 15:38:38 +02007757 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007758 if (!hdr) {
7759 nlmsg_free(msg);
7760 return -ENOMEM;
7761 }
7762
7763 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7764 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7765 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
Johannes Berg804483e2012-03-05 22:18:41 +01007766 if (sig_dbm)
7767 NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
Jouni Malinen026331c2010-02-15 12:53:10 +02007768 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7769
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007770 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007771
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007772 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007773
7774 nla_put_failure:
7775 genlmsg_cancel(msg, hdr);
7776 nlmsg_free(msg);
7777 return -ENOBUFS;
7778}
7779
Johannes Berg2e161f782010-08-12 15:38:38 +02007780void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7781 struct net_device *netdev, u64 cookie,
7782 const u8 *buf, size_t len, bool ack,
7783 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007784{
7785 struct sk_buff *msg;
7786 void *hdr;
7787
7788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7789 if (!msg)
7790 return;
7791
Johannes Berg2e161f782010-08-12 15:38:38 +02007792 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02007793 if (!hdr) {
7794 nlmsg_free(msg);
7795 return;
7796 }
7797
7798 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7799 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7800 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7801 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7802 if (ack)
7803 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7804
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007805 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007806
7807 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7808 return;
7809
7810 nla_put_failure:
7811 genlmsg_cancel(msg, hdr);
7812 nlmsg_free(msg);
7813}
7814
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007815void
7816nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7817 struct net_device *netdev,
7818 enum nl80211_cqm_rssi_threshold_event rssi_event,
7819 gfp_t gfp)
7820{
7821 struct sk_buff *msg;
7822 struct nlattr *pinfoattr;
7823 void *hdr;
7824
7825 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7826 if (!msg)
7827 return;
7828
7829 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7830 if (!hdr) {
7831 nlmsg_free(msg);
7832 return;
7833 }
7834
7835 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7836 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7837
7838 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7839 if (!pinfoattr)
7840 goto nla_put_failure;
7841
7842 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7843 rssi_event);
7844
7845 nla_nest_end(msg, pinfoattr);
7846
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007847 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007848
7849 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7850 nl80211_mlme_mcgrp.id, gfp);
7851 return;
7852
7853 nla_put_failure:
7854 genlmsg_cancel(msg, hdr);
7855 nlmsg_free(msg);
7856}
7857
Johannes Berge5497d72011-07-05 16:35:40 +02007858void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7859 struct net_device *netdev, const u8 *bssid,
7860 const u8 *replay_ctr, gfp_t gfp)
7861{
7862 struct sk_buff *msg;
7863 struct nlattr *rekey_attr;
7864 void *hdr;
7865
7866 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7867 if (!msg)
7868 return;
7869
7870 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7871 if (!hdr) {
7872 nlmsg_free(msg);
7873 return;
7874 }
7875
7876 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7877 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7878 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7879
7880 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7881 if (!rekey_attr)
7882 goto nla_put_failure;
7883
7884 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7885 NL80211_REPLAY_CTR_LEN, replay_ctr);
7886
7887 nla_nest_end(msg, rekey_attr);
7888
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007889 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02007890
7891 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7892 nl80211_mlme_mcgrp.id, gfp);
7893 return;
7894
7895 nla_put_failure:
7896 genlmsg_cancel(msg, hdr);
7897 nlmsg_free(msg);
7898}
7899
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007900void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7901 struct net_device *netdev, int index,
7902 const u8 *bssid, bool preauth, gfp_t gfp)
7903{
7904 struct sk_buff *msg;
7905 struct nlattr *attr;
7906 void *hdr;
7907
7908 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7909 if (!msg)
7910 return;
7911
7912 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7913 if (!hdr) {
7914 nlmsg_free(msg);
7915 return;
7916 }
7917
7918 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7919 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7920
7921 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7922 if (!attr)
7923 goto nla_put_failure;
7924
7925 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7926 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7927 if (preauth)
7928 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7929
7930 nla_nest_end(msg, attr);
7931
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007932 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007933
7934 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7935 nl80211_mlme_mcgrp.id, gfp);
7936 return;
7937
7938 nla_put_failure:
7939 genlmsg_cancel(msg, hdr);
7940 nlmsg_free(msg);
7941}
7942
Thomas Pedersen53145262012-04-06 13:35:47 -07007943void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
7944 struct net_device *netdev, int freq,
7945 enum nl80211_channel_type type, gfp_t gfp)
7946{
7947 struct sk_buff *msg;
7948 void *hdr;
7949
7950 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7951 if (!msg)
7952 return;
7953
7954 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
7955 if (!hdr) {
7956 nlmsg_free(msg);
7957 return;
7958 }
7959
7960 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7961 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7962 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type);
7963
7964 genlmsg_end(msg, hdr);
7965
7966 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7967 nl80211_mlme_mcgrp.id, gfp);
7968 return;
7969
7970 nla_put_failure:
7971 genlmsg_cancel(msg, hdr);
7972 nlmsg_free(msg);
7973}
7974
Johannes Bergc063dbf2010-11-24 08:10:05 +01007975void
7976nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7977 struct net_device *netdev, const u8 *peer,
7978 u32 num_packets, gfp_t gfp)
7979{
7980 struct sk_buff *msg;
7981 struct nlattr *pinfoattr;
7982 void *hdr;
7983
7984 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7985 if (!msg)
7986 return;
7987
7988 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7989 if (!hdr) {
7990 nlmsg_free(msg);
7991 return;
7992 }
7993
7994 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7995 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7996 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7997
7998 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7999 if (!pinfoattr)
8000 goto nla_put_failure;
8001
8002 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
8003
8004 nla_nest_end(msg, pinfoattr);
8005
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008006 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008007
8008 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8009 nl80211_mlme_mcgrp.id, gfp);
8010 return;
8011
8012 nla_put_failure:
8013 genlmsg_cancel(msg, hdr);
8014 nlmsg_free(msg);
8015}
8016
Johannes Berg7f6cf312011-11-04 11:18:15 +01008017void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8018 u64 cookie, bool acked, gfp_t gfp)
8019{
8020 struct wireless_dev *wdev = dev->ieee80211_ptr;
8021 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8022 struct sk_buff *msg;
8023 void *hdr;
8024 int err;
8025
8026 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8027 if (!msg)
8028 return;
8029
8030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8031 if (!hdr) {
8032 nlmsg_free(msg);
8033 return;
8034 }
8035
8036 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
8037 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
8038 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
8039 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
8040 if (acked)
8041 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
8042
8043 err = genlmsg_end(msg, hdr);
8044 if (err < 0) {
8045 nlmsg_free(msg);
8046 return;
8047 }
8048
8049 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8050 nl80211_mlme_mcgrp.id, gfp);
8051 return;
8052
8053 nla_put_failure:
8054 genlmsg_cancel(msg, hdr);
8055 nlmsg_free(msg);
8056}
8057EXPORT_SYMBOL(cfg80211_probe_status);
8058
Johannes Berg5e760232011-11-04 11:18:17 +01008059void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8060 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008061 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008062{
8063 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8064 struct sk_buff *msg;
8065 void *hdr;
8066 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8067
8068 if (!nlpid)
8069 return;
8070
8071 msg = nlmsg_new(len + 100, gfp);
8072 if (!msg)
8073 return;
8074
8075 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8076 if (!hdr) {
8077 nlmsg_free(msg);
8078 return;
8079 }
8080
8081 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
8082 if (freq)
8083 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
Johannes Berg804483e2012-03-05 22:18:41 +01008084 if (sig_dbm)
8085 NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
Johannes Berg5e760232011-11-04 11:18:17 +01008086 NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
8087
8088 genlmsg_end(msg, hdr);
8089
8090 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8091 return;
8092
8093 nla_put_failure:
8094 genlmsg_cancel(msg, hdr);
8095 nlmsg_free(msg);
8096}
8097EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8098
Jouni Malinen026331c2010-02-15 12:53:10 +02008099static int nl80211_netlink_notify(struct notifier_block * nb,
8100 unsigned long state,
8101 void *_notify)
8102{
8103 struct netlink_notify *notify = _notify;
8104 struct cfg80211_registered_device *rdev;
8105 struct wireless_dev *wdev;
8106
8107 if (state != NETLINK_URELEASE)
8108 return NOTIFY_DONE;
8109
8110 rcu_read_lock();
8111
Johannes Berg5e760232011-11-04 11:18:17 +01008112 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008113 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f782010-08-12 15:38:38 +02008114 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008115 if (rdev->ap_beacons_nlpid == notify->pid)
8116 rdev->ap_beacons_nlpid = 0;
8117 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008118
8119 rcu_read_unlock();
8120
8121 return NOTIFY_DONE;
8122}
8123
8124static struct notifier_block nl80211_netlink_notifier = {
8125 .notifier_call = nl80211_netlink_notify,
8126};
8127
Johannes Berg55682962007-09-20 13:09:35 -04008128/* initialisation/exit functions */
8129
8130int nl80211_init(void)
8131{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008132 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008133
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008134 err = genl_register_family_with_ops(&nl80211_fam,
8135 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008136 if (err)
8137 return err;
8138
Johannes Berg55682962007-09-20 13:09:35 -04008139 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8140 if (err)
8141 goto err_out;
8142
Johannes Berg2a519312009-02-10 21:25:55 +01008143 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8144 if (err)
8145 goto err_out;
8146
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008147 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8148 if (err)
8149 goto err_out;
8150
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008151 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8152 if (err)
8153 goto err_out;
8154
Johannes Bergaff89a92009-07-01 21:26:51 +02008155#ifdef CONFIG_NL80211_TESTMODE
8156 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8157 if (err)
8158 goto err_out;
8159#endif
8160
Jouni Malinen026331c2010-02-15 12:53:10 +02008161 err = netlink_register_notifier(&nl80211_netlink_notifier);
8162 if (err)
8163 goto err_out;
8164
Johannes Berg55682962007-09-20 13:09:35 -04008165 return 0;
8166 err_out:
8167 genl_unregister_family(&nl80211_fam);
8168 return err;
8169}
8170
8171void nl80211_exit(void)
8172{
Jouni Malinen026331c2010-02-15 12:53:10 +02008173 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008174 genl_unregister_family(&nl80211_fam);
8175}