blob: c3e82af72bf56eac0d5e04d9cdb62bd52be7b88e [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 Berg2e161f72010-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 Berg2e161f72010-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 Berg2e161f72010-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 Berg6829c8782009-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 Berg6829c8782009-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 Berg2e161f72010-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 Berg2e161f72010-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
Jouni Malinen31888482008-10-30 16:59:24 +02001300 nla_for_each_nested(nl_txq_params,
1301 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1302 rem_txq_params) {
1303 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1304 nla_data(nl_txq_params),
1305 nla_len(nl_txq_params),
1306 txq_params_policy);
1307 result = parse_txq_params(tb, &txq_params);
1308 if (result)
1309 goto bad_res;
1310
1311 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001312 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001313 &txq_params);
1314 if (result)
1315 goto bad_res;
1316 }
1317 }
1318
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001319 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001320 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001321 if (result)
1322 goto bad_res;
1323 }
1324
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001325 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1326 enum nl80211_tx_power_setting type;
1327 int idx, mbm = 0;
1328
1329 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001330 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001331 goto bad_res;
1332 }
1333
1334 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1335 type = nla_get_u32(info->attrs[idx]);
1336
1337 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1338 (type != NL80211_TX_POWER_AUTOMATIC)) {
1339 result = -EINVAL;
1340 goto bad_res;
1341 }
1342
1343 if (type != NL80211_TX_POWER_AUTOMATIC) {
1344 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1345 mbm = nla_get_u32(info->attrs[idx]);
1346 }
1347
1348 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1349 if (result)
1350 goto bad_res;
1351 }
1352
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001353 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1354 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1355 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001356 if ((!rdev->wiphy.available_antennas_tx &&
1357 !rdev->wiphy.available_antennas_rx) ||
1358 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001359 result = -EOPNOTSUPP;
1360 goto bad_res;
1361 }
1362
1363 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1364 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1365
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001366 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001367 * available antenna masks, except for the "all" mask */
1368 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1369 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001370 result = -EINVAL;
1371 goto bad_res;
1372 }
1373
Bruno Randolf7f531e02010-12-16 11:30:22 +09001374 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1375 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001376
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001377 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1378 if (result)
1379 goto bad_res;
1380 }
1381
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001382 changed = 0;
1383
1384 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1385 retry_short = nla_get_u8(
1386 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1387 if (retry_short == 0) {
1388 result = -EINVAL;
1389 goto bad_res;
1390 }
1391 changed |= WIPHY_PARAM_RETRY_SHORT;
1392 }
1393
1394 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1395 retry_long = nla_get_u8(
1396 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1397 if (retry_long == 0) {
1398 result = -EINVAL;
1399 goto bad_res;
1400 }
1401 changed |= WIPHY_PARAM_RETRY_LONG;
1402 }
1403
1404 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1405 frag_threshold = nla_get_u32(
1406 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1407 if (frag_threshold < 256) {
1408 result = -EINVAL;
1409 goto bad_res;
1410 }
1411 if (frag_threshold != (u32) -1) {
1412 /*
1413 * Fragments (apart from the last one) are required to
1414 * have even length. Make the fragmentation code
1415 * simpler by stripping LSB should someone try to use
1416 * odd threshold value.
1417 */
1418 frag_threshold &= ~0x1;
1419 }
1420 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1421 }
1422
1423 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1424 rts_threshold = nla_get_u32(
1425 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1426 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1427 }
1428
Lukáš Turek81077e82009-12-21 22:50:47 +01001429 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1430 coverage_class = nla_get_u8(
1431 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1432 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1433 }
1434
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001435 if (changed) {
1436 u8 old_retry_short, old_retry_long;
1437 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001438 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001439
1440 if (!rdev->ops->set_wiphy_params) {
1441 result = -EOPNOTSUPP;
1442 goto bad_res;
1443 }
1444
1445 old_retry_short = rdev->wiphy.retry_short;
1446 old_retry_long = rdev->wiphy.retry_long;
1447 old_frag_threshold = rdev->wiphy.frag_threshold;
1448 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001449 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001450
1451 if (changed & WIPHY_PARAM_RETRY_SHORT)
1452 rdev->wiphy.retry_short = retry_short;
1453 if (changed & WIPHY_PARAM_RETRY_LONG)
1454 rdev->wiphy.retry_long = retry_long;
1455 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1456 rdev->wiphy.frag_threshold = frag_threshold;
1457 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1458 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001459 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1460 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001461
1462 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1463 if (result) {
1464 rdev->wiphy.retry_short = old_retry_short;
1465 rdev->wiphy.retry_long = old_retry_long;
1466 rdev->wiphy.frag_threshold = old_frag_threshold;
1467 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001468 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001469 }
1470 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001471
Johannes Berg306d6112008-12-08 12:39:04 +01001472 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001473 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001474 if (netdev)
1475 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001476 return result;
1477}
1478
1479
1480static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001481 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001482 struct net_device *dev)
1483{
1484 void *hdr;
1485
1486 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1487 if (!hdr)
1488 return -1;
1489
1490 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001491 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001492 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001493 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001494
1495 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1496 rdev->devlist_generation ^
1497 (cfg80211_rdev_list_generation << 2));
1498
Johannes Berg55682962007-09-20 13:09:35 -04001499 return genlmsg_end(msg, hdr);
1500
1501 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001502 genlmsg_cancel(msg, hdr);
1503 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001504}
1505
1506static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1507{
1508 int wp_idx = 0;
1509 int if_idx = 0;
1510 int wp_start = cb->args[0];
1511 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001512 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001513 struct wireless_dev *wdev;
1514
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001515 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001516 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1517 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001518 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001519 if (wp_idx < wp_start) {
1520 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001521 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001522 }
Johannes Berg55682962007-09-20 13:09:35 -04001523 if_idx = 0;
1524
Johannes Bergf5ea9122009-08-07 16:17:38 +02001525 mutex_lock(&rdev->devlist_mtx);
1526 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001527 if (if_idx < if_start) {
1528 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001529 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001530 }
Johannes Berg55682962007-09-20 13:09:35 -04001531 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1532 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001533 rdev, wdev->netdev) < 0) {
1534 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001535 goto out;
1536 }
1537 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001538 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001539 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001540
1541 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001542 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001543 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001544 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001545
1546 cb->args[0] = wp_idx;
1547 cb->args[1] = if_idx;
1548
1549 return skb->len;
1550}
1551
1552static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1553{
1554 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001555 struct cfg80211_registered_device *dev = info->user_ptr[0];
1556 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001557
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001558 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001559 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001560 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001561
Johannes Bergd7264052009-04-19 16:23:20 +02001562 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001563 dev, netdev) < 0) {
1564 nlmsg_free(msg);
1565 return -ENOBUFS;
1566 }
Johannes Berg55682962007-09-20 13:09:35 -04001567
Johannes Berg134e6372009-07-10 09:51:34 +00001568 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001569}
1570
Michael Wu66f7ac52008-01-31 19:48:22 +01001571static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1572 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1573 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1574 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1575 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1576 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1577};
1578
1579static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1580{
1581 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1582 int flag;
1583
1584 *mntrflags = 0;
1585
1586 if (!nla)
1587 return -EINVAL;
1588
1589 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1590 nla, mntr_flags_policy))
1591 return -EINVAL;
1592
1593 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1594 if (flags[flag])
1595 *mntrflags |= (1<<flag);
1596
1597 return 0;
1598}
1599
Johannes Berg9bc383d2009-11-19 11:55:19 +01001600static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001601 struct net_device *netdev, u8 use_4addr,
1602 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001603{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001604 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001605 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001606 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001607 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001608 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001609
1610 switch (iftype) {
1611 case NL80211_IFTYPE_AP_VLAN:
1612 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1613 return 0;
1614 break;
1615 case NL80211_IFTYPE_STATION:
1616 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1617 return 0;
1618 break;
1619 default:
1620 break;
1621 }
1622
1623 return -EOPNOTSUPP;
1624}
1625
Johannes Berg55682962007-09-20 13:09:35 -04001626static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1627{
Johannes Berg4c476992010-10-04 21:36:35 +02001628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001629 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001630 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001631 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001632 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001633 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001634 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001635
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001636 memset(&params, 0, sizeof(params));
1637
Johannes Berg04a773a2009-04-19 21:24:32 +02001638 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001639
Johannes Berg723b0382008-09-16 20:22:09 +02001640 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001641 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001642 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001643 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001644 if (ntype > NL80211_IFTYPE_MAX)
1645 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001646 }
1647
Johannes Berg92ffe052008-09-16 20:39:36 +02001648 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001649 struct wireless_dev *wdev = dev->ieee80211_ptr;
1650
Johannes Berg4c476992010-10-04 21:36:35 +02001651 if (ntype != NL80211_IFTYPE_MESH_POINT)
1652 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001653 if (netif_running(dev))
1654 return -EBUSY;
1655
1656 wdev_lock(wdev);
1657 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1658 IEEE80211_MAX_MESH_ID_LEN);
1659 wdev->mesh_id_up_len =
1660 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1661 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1662 wdev->mesh_id_up_len);
1663 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001664 }
1665
Felix Fietkau8b787642009-11-10 18:53:10 +01001666 if (info->attrs[NL80211_ATTR_4ADDR]) {
1667 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1668 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001669 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001670 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001671 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001672 } else {
1673 params.use_4addr = -1;
1674 }
1675
Johannes Berg92ffe052008-09-16 20:39:36 +02001676 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001677 if (ntype != NL80211_IFTYPE_MONITOR)
1678 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001679 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1680 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001681 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001682 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001683
1684 flags = &_flags;
1685 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001686 }
Johannes Berg3b858752009-03-12 09:55:09 +01001687
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001688 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001689 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001690 else
1691 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001692
Johannes Berg9bc383d2009-11-19 11:55:19 +01001693 if (!err && params.use_4addr != -1)
1694 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1695
Johannes Berg55682962007-09-20 13:09:35 -04001696 return err;
1697}
1698
1699static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1700{
Johannes Berg4c476992010-10-04 21:36:35 +02001701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001702 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001703 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001704 int err;
1705 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001706 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001707
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001708 memset(&params, 0, sizeof(params));
1709
Johannes Berg55682962007-09-20 13:09:35 -04001710 if (!info->attrs[NL80211_ATTR_IFNAME])
1711 return -EINVAL;
1712
1713 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1714 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1715 if (type > NL80211_IFTYPE_MAX)
1716 return -EINVAL;
1717 }
1718
Johannes Berg79c97e92009-07-07 03:56:12 +02001719 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001720 !(rdev->wiphy.interface_modes & (1 << type)))
1721 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001722
Johannes Berg9bc383d2009-11-19 11:55:19 +01001723 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001724 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001725 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001726 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001727 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001728 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001729
Michael Wu66f7ac52008-01-31 19:48:22 +01001730 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1731 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1732 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001733 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001734 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001735 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001736 if (IS_ERR(dev))
1737 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001738
Johannes Berg29cbe682010-12-03 09:20:44 +01001739 if (type == NL80211_IFTYPE_MESH_POINT &&
1740 info->attrs[NL80211_ATTR_MESH_ID]) {
1741 struct wireless_dev *wdev = dev->ieee80211_ptr;
1742
1743 wdev_lock(wdev);
1744 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1745 IEEE80211_MAX_MESH_ID_LEN);
1746 wdev->mesh_id_up_len =
1747 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1748 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1749 wdev->mesh_id_up_len);
1750 wdev_unlock(wdev);
1751 }
1752
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001753 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001754}
1755
1756static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1757{
Johannes Berg4c476992010-10-04 21:36:35 +02001758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1759 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001760
Johannes Berg4c476992010-10-04 21:36:35 +02001761 if (!rdev->ops->del_virtual_intf)
1762 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001763
Johannes Berg4c476992010-10-04 21:36:35 +02001764 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001765}
1766
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001767static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1768{
1769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1770 struct net_device *dev = info->user_ptr[1];
1771 u16 noack_map;
1772
1773 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1774 return -EINVAL;
1775
1776 if (!rdev->ops->set_noack_map)
1777 return -EOPNOTSUPP;
1778
1779 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1780
1781 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1782}
1783
Johannes Berg41ade002007-12-19 02:03:29 +01001784struct get_key_cookie {
1785 struct sk_buff *msg;
1786 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001787 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001788};
1789
1790static void get_key_callback(void *c, struct key_params *params)
1791{
Johannes Bergb9454e82009-07-08 13:29:08 +02001792 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001793 struct get_key_cookie *cookie = c;
1794
1795 if (params->key)
1796 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1797 params->key_len, params->key);
1798
1799 if (params->seq)
1800 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1801 params->seq_len, params->seq);
1802
1803 if (params->cipher)
1804 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1805 params->cipher);
1806
Johannes Bergb9454e82009-07-08 13:29:08 +02001807 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1808 if (!key)
1809 goto nla_put_failure;
1810
1811 if (params->key)
1812 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1813 params->key_len, params->key);
1814
1815 if (params->seq)
1816 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1817 params->seq_len, params->seq);
1818
1819 if (params->cipher)
1820 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1821 params->cipher);
1822
1823 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1824
1825 nla_nest_end(cookie->msg, key);
1826
Johannes Berg41ade002007-12-19 02:03:29 +01001827 return;
1828 nla_put_failure:
1829 cookie->error = 1;
1830}
1831
1832static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1833{
Johannes Berg4c476992010-10-04 21:36:35 +02001834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001835 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001836 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001837 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001838 const u8 *mac_addr = NULL;
1839 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001840 struct get_key_cookie cookie = {
1841 .error = 0,
1842 };
1843 void *hdr;
1844 struct sk_buff *msg;
1845
1846 if (info->attrs[NL80211_ATTR_KEY_IDX])
1847 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1848
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001849 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001850 return -EINVAL;
1851
1852 if (info->attrs[NL80211_ATTR_MAC])
1853 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1854
Johannes Berge31b8212010-10-05 19:39:30 +02001855 pairwise = !!mac_addr;
1856 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1857 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1858 if (kt >= NUM_NL80211_KEYTYPES)
1859 return -EINVAL;
1860 if (kt != NL80211_KEYTYPE_GROUP &&
1861 kt != NL80211_KEYTYPE_PAIRWISE)
1862 return -EINVAL;
1863 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1864 }
1865
Johannes Berg4c476992010-10-04 21:36:35 +02001866 if (!rdev->ops->get_key)
1867 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001868
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001870 if (!msg)
1871 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001872
1873 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1874 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001875 if (IS_ERR(hdr))
1876 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001877
1878 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001879 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001880
1881 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1882 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1883 if (mac_addr)
1884 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1885
Johannes Berge31b8212010-10-05 19:39:30 +02001886 if (pairwise && mac_addr &&
1887 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1888 return -ENOENT;
1889
1890 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1891 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001892
1893 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001894 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001895
1896 if (cookie.error)
1897 goto nla_put_failure;
1898
1899 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001900 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001901
1902 nla_put_failure:
1903 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001904 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001905 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001906 return err;
1907}
1908
1909static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1910{
Johannes Berg4c476992010-10-04 21:36:35 +02001911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001912 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001913 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001914 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001915
Johannes Bergb9454e82009-07-08 13:29:08 +02001916 err = nl80211_parse_key(info, &key);
1917 if (err)
1918 return err;
1919
1920 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001921 return -EINVAL;
1922
Johannes Bergb9454e82009-07-08 13:29:08 +02001923 /* only support setting default key */
1924 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001925 return -EINVAL;
1926
Johannes Bergfffd0932009-07-08 14:22:54 +02001927 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001928
1929 if (key.def) {
1930 if (!rdev->ops->set_default_key) {
1931 err = -EOPNOTSUPP;
1932 goto out;
1933 }
1934
1935 err = nl80211_key_allowed(dev->ieee80211_ptr);
1936 if (err)
1937 goto out;
1938
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001939 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1940 key.def_uni, key.def_multi);
1941
1942 if (err)
1943 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001944
Johannes Berg3d23e342009-09-29 23:27:28 +02001945#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001946 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001947#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001948 } else {
1949 if (key.def_uni || !key.def_multi) {
1950 err = -EINVAL;
1951 goto out;
1952 }
1953
1954 if (!rdev->ops->set_default_mgmt_key) {
1955 err = -EOPNOTSUPP;
1956 goto out;
1957 }
1958
1959 err = nl80211_key_allowed(dev->ieee80211_ptr);
1960 if (err)
1961 goto out;
1962
1963 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1964 dev, key.idx);
1965 if (err)
1966 goto out;
1967
1968#ifdef CONFIG_CFG80211_WEXT
1969 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1970#endif
1971 }
1972
1973 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001974 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001975
Johannes Berg41ade002007-12-19 02:03:29 +01001976 return err;
1977}
1978
1979static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1980{
Johannes Berg4c476992010-10-04 21:36:35 +02001981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001982 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001983 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001984 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001985 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001986
Johannes Bergb9454e82009-07-08 13:29:08 +02001987 err = nl80211_parse_key(info, &key);
1988 if (err)
1989 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001990
Johannes Bergb9454e82009-07-08 13:29:08 +02001991 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001992 return -EINVAL;
1993
Johannes Berg41ade002007-12-19 02:03:29 +01001994 if (info->attrs[NL80211_ATTR_MAC])
1995 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1996
Johannes Berge31b8212010-10-05 19:39:30 +02001997 if (key.type == -1) {
1998 if (mac_addr)
1999 key.type = NL80211_KEYTYPE_PAIRWISE;
2000 else
2001 key.type = NL80211_KEYTYPE_GROUP;
2002 }
2003
2004 /* for now */
2005 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2006 key.type != NL80211_KEYTYPE_GROUP)
2007 return -EINVAL;
2008
Johannes Berg4c476992010-10-04 21:36:35 +02002009 if (!rdev->ops->add_key)
2010 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002011
Johannes Berge31b8212010-10-05 19:39:30 +02002012 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2013 key.type == NL80211_KEYTYPE_PAIRWISE,
2014 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002015 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002016
2017 wdev_lock(dev->ieee80211_ptr);
2018 err = nl80211_key_allowed(dev->ieee80211_ptr);
2019 if (!err)
2020 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002021 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002022 mac_addr, &key.p);
2023 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002024
Johannes Berg41ade002007-12-19 02:03:29 +01002025 return err;
2026}
2027
2028static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2029{
Johannes Berg4c476992010-10-04 21:36:35 +02002030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002031 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002032 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002033 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002034 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002035
Johannes Bergb9454e82009-07-08 13:29:08 +02002036 err = nl80211_parse_key(info, &key);
2037 if (err)
2038 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002039
2040 if (info->attrs[NL80211_ATTR_MAC])
2041 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2042
Johannes Berge31b8212010-10-05 19:39:30 +02002043 if (key.type == -1) {
2044 if (mac_addr)
2045 key.type = NL80211_KEYTYPE_PAIRWISE;
2046 else
2047 key.type = NL80211_KEYTYPE_GROUP;
2048 }
2049
2050 /* for now */
2051 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2052 key.type != NL80211_KEYTYPE_GROUP)
2053 return -EINVAL;
2054
Johannes Berg4c476992010-10-04 21:36:35 +02002055 if (!rdev->ops->del_key)
2056 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002057
Johannes Bergfffd0932009-07-08 14:22:54 +02002058 wdev_lock(dev->ieee80211_ptr);
2059 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002060
2061 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2062 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2063 err = -ENOENT;
2064
Johannes Bergfffd0932009-07-08 14:22:54 +02002065 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002066 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2067 key.type == NL80211_KEYTYPE_PAIRWISE,
2068 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002069
Johannes Berg3d23e342009-09-29 23:27:28 +02002070#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002071 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002072 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002073 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002074 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002075 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2076 }
2077#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002078 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002079
Johannes Berg41ade002007-12-19 02:03:29 +01002080 return err;
2081}
2082
Johannes Berg88600202012-02-13 15:17:18 +01002083static int nl80211_parse_beacon(struct genl_info *info,
2084 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002085{
Johannes Berg88600202012-02-13 15:17:18 +01002086 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002087
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002088 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2089 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2090 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2091 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002092 return -EINVAL;
2093
Johannes Berg88600202012-02-13 15:17:18 +01002094 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002095
Johannes Berged1b6cc2007-12-19 02:03:32 +01002096 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002097 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2098 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2099 if (!bcn->head_len)
2100 return -EINVAL;
2101 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002102 }
2103
2104 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002105 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2106 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002107 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002108 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002109 }
2110
Johannes Berg4c476992010-10-04 21:36:35 +02002111 if (!haveinfo)
2112 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002113
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002114 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002115 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2116 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002117 }
2118
2119 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002120 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002121 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002122 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002123 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2124 }
2125
2126 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002127 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002128 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002129 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002130 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2131 }
2132
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002133 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002134 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002135 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002136 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002137 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2138 }
2139
Johannes Berg88600202012-02-13 15:17:18 +01002140 return 0;
2141}
2142
2143static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2144{
2145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2146 struct net_device *dev = info->user_ptr[1];
2147 struct wireless_dev *wdev = dev->ieee80211_ptr;
2148 struct cfg80211_ap_settings params;
2149 int err;
2150
2151 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2152 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2153 return -EOPNOTSUPP;
2154
2155 if (!rdev->ops->start_ap)
2156 return -EOPNOTSUPP;
2157
2158 if (wdev->beacon_interval)
2159 return -EALREADY;
2160
2161 memset(&params, 0, sizeof(params));
2162
2163 /* these are required for START_AP */
2164 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2165 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2166 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2167 return -EINVAL;
2168
2169 err = nl80211_parse_beacon(info, &params.beacon);
2170 if (err)
2171 return err;
2172
2173 params.beacon_interval =
2174 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2175 params.dtim_period =
2176 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2177
2178 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2179 if (err)
2180 return err;
2181
2182 /*
2183 * In theory, some of these attributes should be required here
2184 * but since they were not used when the command was originally
2185 * added, keep them optional for old user space programs to let
2186 * them continue to work with drivers that do not need the
2187 * additional information -- drivers must check!
2188 */
2189 if (info->attrs[NL80211_ATTR_SSID]) {
2190 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2191 params.ssid_len =
2192 nla_len(info->attrs[NL80211_ATTR_SSID]);
2193 if (params.ssid_len == 0 ||
2194 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2195 return -EINVAL;
2196 }
2197
2198 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2199 params.hidden_ssid = nla_get_u32(
2200 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2201 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2202 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2203 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2204 return -EINVAL;
2205 }
2206
2207 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2208
2209 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2210 params.auth_type = nla_get_u32(
2211 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2212 if (!nl80211_valid_auth_type(params.auth_type))
2213 return -EINVAL;
2214 } else
2215 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2216
2217 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2218 NL80211_MAX_NR_CIPHER_SUITES);
2219 if (err)
2220 return err;
2221
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302222 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2223 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2224 return -EOPNOTSUPP;
2225 params.inactivity_timeout = nla_get_u16(
2226 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2227 }
2228
Johannes Berg88600202012-02-13 15:17:18 +01002229 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2230 if (!err)
2231 wdev->beacon_interval = params.beacon_interval;
Johannes Berg56d18932011-05-09 18:41:15 +02002232 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002233}
2234
Johannes Berg88600202012-02-13 15:17:18 +01002235static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2236{
2237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2238 struct net_device *dev = info->user_ptr[1];
2239 struct wireless_dev *wdev = dev->ieee80211_ptr;
2240 struct cfg80211_beacon_data params;
2241 int err;
2242
2243 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2244 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2245 return -EOPNOTSUPP;
2246
2247 if (!rdev->ops->change_beacon)
2248 return -EOPNOTSUPP;
2249
2250 if (!wdev->beacon_interval)
2251 return -EINVAL;
2252
2253 err = nl80211_parse_beacon(info, &params);
2254 if (err)
2255 return err;
2256
2257 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2258}
2259
2260static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002261{
Johannes Berg4c476992010-10-04 21:36:35 +02002262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2263 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002264 struct wireless_dev *wdev = dev->ieee80211_ptr;
2265 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002266
Johannes Berg88600202012-02-13 15:17:18 +01002267 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002268 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002269
Johannes Berg074ac8d2010-09-16 14:58:22 +02002270 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002271 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2272 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002273
Johannes Berg88600202012-02-13 15:17:18 +01002274 if (!wdev->beacon_interval)
2275 return -ENOENT;
2276
2277 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002278 if (!err)
2279 wdev->beacon_interval = 0;
2280 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002281}
2282
Johannes Berg5727ef12007-12-19 02:03:34 +01002283static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2284 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2285 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2286 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002287 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002288 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002289 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002290};
2291
Johannes Bergeccb8e82009-05-11 21:57:56 +03002292static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002293 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002294 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002295{
2296 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002297 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002298 int flag;
2299
Johannes Bergeccb8e82009-05-11 21:57:56 +03002300 /*
2301 * Try parsing the new attribute first so userspace
2302 * can specify both for older kernels.
2303 */
2304 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2305 if (nla) {
2306 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002307
Johannes Bergeccb8e82009-05-11 21:57:56 +03002308 sta_flags = nla_data(nla);
2309 params->sta_flags_mask = sta_flags->mask;
2310 params->sta_flags_set = sta_flags->set;
2311 if ((params->sta_flags_mask |
2312 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2313 return -EINVAL;
2314 return 0;
2315 }
2316
2317 /* if present, parse the old attribute */
2318
2319 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002320 if (!nla)
2321 return 0;
2322
2323 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2324 nla, sta_flags_policy))
2325 return -EINVAL;
2326
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002327 /*
2328 * Only allow certain flags for interface types so that
2329 * other attributes are silently ignored. Remember that
2330 * this is backward compatibility code with old userspace
2331 * and shouldn't be hit in other cases anyway.
2332 */
2333 switch (iftype) {
2334 case NL80211_IFTYPE_AP:
2335 case NL80211_IFTYPE_AP_VLAN:
2336 case NL80211_IFTYPE_P2P_GO:
2337 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2338 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2339 BIT(NL80211_STA_FLAG_WME) |
2340 BIT(NL80211_STA_FLAG_MFP);
2341 break;
2342 case NL80211_IFTYPE_P2P_CLIENT:
2343 case NL80211_IFTYPE_STATION:
2344 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2345 BIT(NL80211_STA_FLAG_TDLS_PEER);
2346 break;
2347 case NL80211_IFTYPE_MESH_POINT:
2348 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2349 BIT(NL80211_STA_FLAG_MFP) |
2350 BIT(NL80211_STA_FLAG_AUTHORIZED);
2351 default:
2352 return -EINVAL;
2353 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002354
2355 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2356 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002357 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002358
2359 return 0;
2360}
2361
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002362static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2363 int attr)
2364{
2365 struct nlattr *rate;
2366 u16 bitrate;
2367
2368 rate = nla_nest_start(msg, attr);
2369 if (!rate)
2370 goto nla_put_failure;
2371
2372 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2373 bitrate = cfg80211_calculate_bitrate(info);
2374 if (bitrate > 0)
2375 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2376
2377 if (info->flags & RATE_INFO_FLAGS_MCS)
2378 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2379 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2380 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2381 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2382 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2383
2384 nla_nest_end(msg, rate);
2385 return true;
2386
2387nla_put_failure:
2388 return false;
2389}
2390
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002391static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002392 int flags,
2393 struct cfg80211_registered_device *rdev,
2394 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002395 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002396{
2397 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002398 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002399
2400 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2401 if (!hdr)
2402 return -1;
2403
2404 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2405 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2406
Johannes Bergf5ea9122009-08-07 16:17:38 +02002407 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2408
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002409 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2410 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002411 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302412 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2413 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2414 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002415 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2416 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2417 sinfo->inactive_time);
2418 if (sinfo->filled & STATION_INFO_RX_BYTES)
2419 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2420 sinfo->rx_bytes);
2421 if (sinfo->filled & STATION_INFO_TX_BYTES)
2422 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2423 sinfo->tx_bytes);
2424 if (sinfo->filled & STATION_INFO_LLID)
2425 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2426 sinfo->llid);
2427 if (sinfo->filled & STATION_INFO_PLID)
2428 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2429 sinfo->plid);
2430 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2431 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2432 sinfo->plink_state);
John W. Linville66266b32012-03-15 13:25:41 -04002433 switch (rdev->wiphy.signal_type) {
2434 case CFG80211_SIGNAL_TYPE_MBM:
2435 if (sinfo->filled & STATION_INFO_SIGNAL)
2436 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2437 sinfo->signal);
2438 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2439 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2440 sinfo->signal_avg);
2441 break;
2442 default:
2443 break;
2444 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002445 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002446 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2447 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002448 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002449 }
2450 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2451 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2452 NL80211_STA_INFO_RX_BITRATE))
2453 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002454 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002455 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2456 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2457 sinfo->rx_packets);
2458 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2459 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2460 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002461 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2462 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2463 sinfo->tx_retries);
2464 if (sinfo->filled & STATION_INFO_TX_FAILED)
2465 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2466 sinfo->tx_failed);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002467 if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT)
2468 NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS,
2469 sinfo->beacon_loss_count);
Paul Stewartf4263c92011-03-31 09:25:41 -07002470 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2471 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2472 if (!bss_param)
2473 goto nla_put_failure;
2474
2475 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2476 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2477 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2478 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2479 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2480 NLA_PUT_FLAG(msg,
2481 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2482 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2483 sinfo->bss_param.dtim_period);
2484 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2485 sinfo->bss_param.beacon_interval);
2486
2487 nla_nest_end(msg, bss_param);
2488 }
Helmut Schaabb6e7532011-10-13 16:30:39 +02002489 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2490 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2491 sizeof(struct nl80211_sta_flag_update),
2492 &sinfo->sta_flags);
Javier Cardonad299a1f2012-03-31 11:31:33 -07002493 if (sinfo->filled & STATION_INFO_T_OFFSET)
2494 NLA_PUT_U64(msg, NL80211_STA_INFO_T_OFFSET,
2495 sinfo->t_offset);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002496 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002497
Felix Fietkau040bdf72011-08-10 19:00:33 -06002498 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002499 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2500 sinfo->assoc_req_ies);
2501
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002502 return genlmsg_end(msg, hdr);
2503
2504 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002505 genlmsg_cancel(msg, hdr);
2506 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002507}
2508
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002509static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002510 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002511{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002512 struct station_info sinfo;
2513 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002514 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002515 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002516 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002517 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002518
Johannes Berg67748892010-10-04 21:14:06 +02002519 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2520 if (err)
2521 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002522
2523 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002524 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002525 goto out_err;
2526 }
2527
Johannes Bergbba95fe2008-07-29 13:22:51 +02002528 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002529 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002530 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2531 mac_addr, &sinfo);
2532 if (err == -ENOENT)
2533 break;
2534 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002535 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002536
2537 if (nl80211_send_station(skb,
2538 NETLINK_CB(cb->skb).pid,
2539 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002540 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002541 &sinfo) < 0)
2542 goto out;
2543
2544 sta_idx++;
2545 }
2546
2547
2548 out:
2549 cb->args[1] = sta_idx;
2550 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002551 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002552 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002553
2554 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002555}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002556
Johannes Berg5727ef12007-12-19 02:03:34 +01002557static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2558{
Johannes Berg4c476992010-10-04 21:36:35 +02002559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2560 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002561 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002562 struct sk_buff *msg;
2563 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002564 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002565
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002566 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002567
2568 if (!info->attrs[NL80211_ATTR_MAC])
2569 return -EINVAL;
2570
2571 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2572
Johannes Berg4c476992010-10-04 21:36:35 +02002573 if (!rdev->ops->get_station)
2574 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002575
Johannes Berg79c97e92009-07-07 03:56:12 +02002576 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002577 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002578 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002579
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002580 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002581 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002582 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002583
2584 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002585 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002586 nlmsg_free(msg);
2587 return -ENOBUFS;
2588 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002589
Johannes Berg4c476992010-10-04 21:36:35 +02002590 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002591}
2592
2593/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002594 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002595 */
Johannes Berg80b99892011-11-18 16:23:01 +01002596static struct net_device *get_vlan(struct genl_info *info,
2597 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002598{
Johannes Berg463d0182009-07-14 00:33:35 +02002599 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002600 struct net_device *v;
2601 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002602
Johannes Berg80b99892011-11-18 16:23:01 +01002603 if (!vlanattr)
2604 return NULL;
2605
2606 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2607 if (!v)
2608 return ERR_PTR(-ENODEV);
2609
2610 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2611 ret = -EINVAL;
2612 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002613 }
Johannes Berg80b99892011-11-18 16:23:01 +01002614
2615 if (!netif_running(v)) {
2616 ret = -ENETDOWN;
2617 goto error;
2618 }
2619
2620 return v;
2621 error:
2622 dev_put(v);
2623 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002624}
2625
2626static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2627{
Johannes Berg4c476992010-10-04 21:36:35 +02002628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002629 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002630 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002631 struct station_parameters params;
2632 u8 *mac_addr = NULL;
2633
2634 memset(&params, 0, sizeof(params));
2635
2636 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002637 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002638
2639 if (info->attrs[NL80211_ATTR_STA_AID])
2640 return -EINVAL;
2641
2642 if (!info->attrs[NL80211_ATTR_MAC])
2643 return -EINVAL;
2644
2645 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2646
2647 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2648 params.supported_rates =
2649 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2650 params.supported_rates_len =
2651 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2652 }
2653
2654 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2655 params.listen_interval =
2656 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2657
Jouni Malinen36aedc92008-08-25 11:58:58 +03002658 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2659 params.ht_capa =
2660 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2661
Johannes Bergbdd90d52011-12-14 12:20:27 +01002662 if (!rdev->ops->change_station)
2663 return -EOPNOTSUPP;
2664
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002665 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002666 return -EINVAL;
2667
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002668 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2669 params.plink_action =
2670 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2671
Javier Cardona9c3990a2011-05-03 16:57:11 -07002672 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2673 params.plink_state =
2674 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2675
Johannes Berga97f4422009-06-18 17:23:43 +02002676 switch (dev->ieee80211_ptr->iftype) {
2677 case NL80211_IFTYPE_AP:
2678 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002679 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002680 /* disallow mesh-specific things */
2681 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002682 return -EINVAL;
2683
2684 /* TDLS can't be set, ... */
2685 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2686 return -EINVAL;
2687 /*
2688 * ... but don't bother the driver with it. This works around
2689 * a hostapd/wpa_supplicant issue -- it always includes the
2690 * TLDS_PEER flag in the mask even for AP mode.
2691 */
2692 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2693
2694 /* accept only the listed bits */
2695 if (params.sta_flags_mask &
2696 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2697 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2698 BIT(NL80211_STA_FLAG_WME) |
2699 BIT(NL80211_STA_FLAG_MFP)))
2700 return -EINVAL;
2701
2702 /* must be last in here for error handling */
2703 params.vlan = get_vlan(info, rdev);
2704 if (IS_ERR(params.vlan))
2705 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002706 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002707 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002708 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002709 /*
2710 * Don't allow userspace to change the TDLS_PEER flag,
2711 * but silently ignore attempts to change it since we
2712 * don't have state here to verify that it doesn't try
2713 * to change the flag.
2714 */
2715 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002716 /* fall through */
2717 case NL80211_IFTYPE_ADHOC:
2718 /* disallow things sta doesn't support */
2719 if (params.plink_action)
2720 return -EINVAL;
2721 if (params.ht_capa)
2722 return -EINVAL;
2723 if (params.listen_interval >= 0)
2724 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002725 /* reject any changes other than AUTHORIZED */
2726 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2727 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002728 break;
2729 case NL80211_IFTYPE_MESH_POINT:
2730 /* disallow things mesh doesn't support */
2731 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002732 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002733 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002734 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002735 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002736 return -EINVAL;
2737 /*
2738 * No special handling for TDLS here -- the userspace
2739 * mesh code doesn't have this bug.
2740 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07002741 if (params.sta_flags_mask &
2742 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002743 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002744 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01002745 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002746 break;
2747 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002748 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02002749 }
2750
Johannes Bergbdd90d52011-12-14 12:20:27 +01002751 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002752
Johannes Berg79c97e92009-07-07 03:56:12 +02002753 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002754
Johannes Berg5727ef12007-12-19 02:03:34 +01002755 if (params.vlan)
2756 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002757
Johannes Berg5727ef12007-12-19 02:03:34 +01002758 return err;
2759}
2760
Eliad Pellerc75786c2011-08-23 14:37:46 +03002761static struct nla_policy
2762nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2763 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2764 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2765};
2766
Johannes Berg5727ef12007-12-19 02:03:34 +01002767static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2768{
Johannes Berg4c476992010-10-04 21:36:35 +02002769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002770 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002771 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002772 struct station_parameters params;
2773 u8 *mac_addr = NULL;
2774
2775 memset(&params, 0, sizeof(params));
2776
2777 if (!info->attrs[NL80211_ATTR_MAC])
2778 return -EINVAL;
2779
Johannes Berg5727ef12007-12-19 02:03:34 +01002780 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2781 return -EINVAL;
2782
2783 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2784 return -EINVAL;
2785
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002786 if (!info->attrs[NL80211_ATTR_STA_AID])
2787 return -EINVAL;
2788
Johannes Berg5727ef12007-12-19 02:03:34 +01002789 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2790 params.supported_rates =
2791 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2792 params.supported_rates_len =
2793 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2794 params.listen_interval =
2795 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002796
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002797 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2798 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2799 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002800
Jouni Malinen36aedc92008-08-25 11:58:58 +03002801 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2802 params.ht_capa =
2803 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002804
Javier Cardona96b78df2011-04-07 15:08:33 -07002805 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2806 params.plink_action =
2807 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2808
Johannes Bergbdd90d52011-12-14 12:20:27 +01002809 if (!rdev->ops->add_station)
2810 return -EOPNOTSUPP;
2811
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002812 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002813 return -EINVAL;
2814
Johannes Bergbdd90d52011-12-14 12:20:27 +01002815 switch (dev->ieee80211_ptr->iftype) {
2816 case NL80211_IFTYPE_AP:
2817 case NL80211_IFTYPE_AP_VLAN:
2818 case NL80211_IFTYPE_P2P_GO:
2819 /* parse WME attributes if sta is WME capable */
2820 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2821 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
2822 info->attrs[NL80211_ATTR_STA_WME]) {
2823 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2824 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002825
Johannes Bergbdd90d52011-12-14 12:20:27 +01002826 nla = info->attrs[NL80211_ATTR_STA_WME];
2827 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2828 nl80211_sta_wme_policy);
2829 if (err)
2830 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002831
Johannes Bergbdd90d52011-12-14 12:20:27 +01002832 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2833 params.uapsd_queues =
2834 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
2835 if (params.uapsd_queues &
2836 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2837 return -EINVAL;
2838
2839 if (tb[NL80211_STA_WME_MAX_SP])
2840 params.max_sp =
2841 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
2842
2843 if (params.max_sp &
2844 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2845 return -EINVAL;
2846
2847 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
2848 }
2849 /* TDLS peers cannot be added */
2850 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02002851 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002852 /* but don't bother the driver with it */
2853 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03002854
Johannes Bergbdd90d52011-12-14 12:20:27 +01002855 /* must be last in here for error handling */
2856 params.vlan = get_vlan(info, rdev);
2857 if (IS_ERR(params.vlan))
2858 return PTR_ERR(params.vlan);
2859 break;
2860 case NL80211_IFTYPE_MESH_POINT:
2861 /* TDLS peers cannot be added */
2862 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02002863 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002864 break;
2865 case NL80211_IFTYPE_STATION:
2866 /* Only TDLS peers can be added */
2867 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2868 return -EINVAL;
2869 /* Can only add if TDLS ... */
2870 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
2871 return -EOPNOTSUPP;
2872 /* ... with external setup is supported */
2873 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
2874 return -EOPNOTSUPP;
2875 break;
2876 default:
2877 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002878 }
2879
Johannes Bergbdd90d52011-12-14 12:20:27 +01002880 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002881
Johannes Berg79c97e92009-07-07 03:56:12 +02002882 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002883
Johannes Berg5727ef12007-12-19 02:03:34 +01002884 if (params.vlan)
2885 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002886 return err;
2887}
2888
2889static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2890{
Johannes Berg4c476992010-10-04 21:36:35 +02002891 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2892 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002893 u8 *mac_addr = NULL;
2894
2895 if (info->attrs[NL80211_ATTR_MAC])
2896 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2897
Johannes Berge80cf852009-05-11 14:43:13 +02002898 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002899 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002900 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2902 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002903
Johannes Berg4c476992010-10-04 21:36:35 +02002904 if (!rdev->ops->del_station)
2905 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002906
Johannes Berg4c476992010-10-04 21:36:35 +02002907 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002908}
2909
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002910static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2911 int flags, struct net_device *dev,
2912 u8 *dst, u8 *next_hop,
2913 struct mpath_info *pinfo)
2914{
2915 void *hdr;
2916 struct nlattr *pinfoattr;
2917
2918 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2919 if (!hdr)
2920 return -1;
2921
2922 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2923 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2924 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2925
Johannes Bergf5ea9122009-08-07 16:17:38 +02002926 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2927
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002928 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2929 if (!pinfoattr)
2930 goto nla_put_failure;
2931 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2932 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2933 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002934 if (pinfo->filled & MPATH_INFO_SN)
2935 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2936 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002937 if (pinfo->filled & MPATH_INFO_METRIC)
2938 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2939 pinfo->metric);
2940 if (pinfo->filled & MPATH_INFO_EXPTIME)
2941 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2942 pinfo->exptime);
2943 if (pinfo->filled & MPATH_INFO_FLAGS)
2944 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2945 pinfo->flags);
2946 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2947 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2948 pinfo->discovery_timeout);
2949 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2950 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2951 pinfo->discovery_retries);
2952
2953 nla_nest_end(msg, pinfoattr);
2954
2955 return genlmsg_end(msg, hdr);
2956
2957 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002958 genlmsg_cancel(msg, hdr);
2959 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002960}
2961
2962static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002963 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002964{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002965 struct mpath_info pinfo;
2966 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002967 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002968 u8 dst[ETH_ALEN];
2969 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002970 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002971 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002972
Johannes Berg67748892010-10-04 21:14:06 +02002973 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2974 if (err)
2975 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002976
2977 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002978 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002979 goto out_err;
2980 }
2981
Jouni Malineneec60b02009-03-20 21:21:19 +02002982 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2983 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002984 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002985 }
2986
Johannes Bergbba95fe2008-07-29 13:22:51 +02002987 while (1) {
2988 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2989 dst, next_hop, &pinfo);
2990 if (err == -ENOENT)
2991 break;
2992 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002993 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002994
2995 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2996 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2997 netdev, dst, next_hop,
2998 &pinfo) < 0)
2999 goto out;
3000
3001 path_idx++;
3002 }
3003
3004
3005 out:
3006 cb->args[1] = path_idx;
3007 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003008 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003009 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003010 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003011}
3012
3013static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3014{
Johannes Berg4c476992010-10-04 21:36:35 +02003015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003016 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003017 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003018 struct mpath_info pinfo;
3019 struct sk_buff *msg;
3020 u8 *dst = NULL;
3021 u8 next_hop[ETH_ALEN];
3022
3023 memset(&pinfo, 0, sizeof(pinfo));
3024
3025 if (!info->attrs[NL80211_ATTR_MAC])
3026 return -EINVAL;
3027
3028 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3029
Johannes Berg4c476992010-10-04 21:36:35 +02003030 if (!rdev->ops->get_mpath)
3031 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003032
Johannes Berg4c476992010-10-04 21:36:35 +02003033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3034 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003035
Johannes Berg79c97e92009-07-07 03:56:12 +02003036 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003037 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003038 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003039
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003041 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003042 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003043
3044 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003045 dev, dst, next_hop, &pinfo) < 0) {
3046 nlmsg_free(msg);
3047 return -ENOBUFS;
3048 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003049
Johannes Berg4c476992010-10-04 21:36:35 +02003050 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003051}
3052
3053static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3054{
Johannes Berg4c476992010-10-04 21:36:35 +02003055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3056 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003057 u8 *dst = NULL;
3058 u8 *next_hop = NULL;
3059
3060 if (!info->attrs[NL80211_ATTR_MAC])
3061 return -EINVAL;
3062
3063 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3064 return -EINVAL;
3065
3066 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3067 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3068
Johannes Berg4c476992010-10-04 21:36:35 +02003069 if (!rdev->ops->change_mpath)
3070 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003071
Johannes Berg4c476992010-10-04 21:36:35 +02003072 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3073 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003074
Johannes Berg4c476992010-10-04 21:36:35 +02003075 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003076}
Johannes Berg4c476992010-10-04 21:36:35 +02003077
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003078static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3079{
Johannes Berg4c476992010-10-04 21:36:35 +02003080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3081 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003082 u8 *dst = NULL;
3083 u8 *next_hop = NULL;
3084
3085 if (!info->attrs[NL80211_ATTR_MAC])
3086 return -EINVAL;
3087
3088 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3089 return -EINVAL;
3090
3091 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3092 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3093
Johannes Berg4c476992010-10-04 21:36:35 +02003094 if (!rdev->ops->add_mpath)
3095 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003096
Johannes Berg4c476992010-10-04 21:36:35 +02003097 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3098 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003099
Johannes Berg4c476992010-10-04 21:36:35 +02003100 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003101}
3102
3103static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3104{
Johannes Berg4c476992010-10-04 21:36:35 +02003105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3106 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003107 u8 *dst = NULL;
3108
3109 if (info->attrs[NL80211_ATTR_MAC])
3110 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3111
Johannes Berg4c476992010-10-04 21:36:35 +02003112 if (!rdev->ops->del_mpath)
3113 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003114
Johannes Berg4c476992010-10-04 21:36:35 +02003115 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003116}
3117
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003118static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3119{
Johannes Berg4c476992010-10-04 21:36:35 +02003120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3121 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003122 struct bss_parameters params;
3123
3124 memset(&params, 0, sizeof(params));
3125 /* default to not changing parameters */
3126 params.use_cts_prot = -1;
3127 params.use_short_preamble = -1;
3128 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003129 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003130 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003131
3132 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3133 params.use_cts_prot =
3134 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3135 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3136 params.use_short_preamble =
3137 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3138 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3139 params.use_short_slot_time =
3140 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003141 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3142 params.basic_rates =
3143 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3144 params.basic_rates_len =
3145 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3146 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003147 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3148 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003149 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3150 params.ht_opmode =
3151 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003152
Johannes Berg4c476992010-10-04 21:36:35 +02003153 if (!rdev->ops->change_bss)
3154 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003155
Johannes Berg074ac8d2010-09-16 14:58:22 +02003156 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003157 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3158 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003159
Johannes Berg4c476992010-10-04 21:36:35 +02003160 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003161}
3162
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003163static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003164 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3165 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3166 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3167 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3168 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3169 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3170};
3171
3172static int parse_reg_rule(struct nlattr *tb[],
3173 struct ieee80211_reg_rule *reg_rule)
3174{
3175 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3176 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3177
3178 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3179 return -EINVAL;
3180 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3181 return -EINVAL;
3182 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3183 return -EINVAL;
3184 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3185 return -EINVAL;
3186 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3187 return -EINVAL;
3188
3189 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3190
3191 freq_range->start_freq_khz =
3192 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3193 freq_range->end_freq_khz =
3194 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3195 freq_range->max_bandwidth_khz =
3196 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3197
3198 power_rule->max_eirp =
3199 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3200
3201 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3202 power_rule->max_antenna_gain =
3203 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3204
3205 return 0;
3206}
3207
3208static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3209{
3210 int r;
3211 char *data = NULL;
3212
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003213 /*
3214 * You should only get this when cfg80211 hasn't yet initialized
3215 * completely when built-in to the kernel right between the time
3216 * window between nl80211_init() and regulatory_init(), if that is
3217 * even possible.
3218 */
3219 mutex_lock(&cfg80211_mutex);
3220 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003221 mutex_unlock(&cfg80211_mutex);
3222 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003223 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003224 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003225
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003226 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3227 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003228
3229 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3230
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003231 r = regulatory_hint_user(data);
3232
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003233 return r;
3234}
3235
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003236static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003237 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003238{
Johannes Berg4c476992010-10-04 21:36:35 +02003239 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003240 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003241 struct wireless_dev *wdev = dev->ieee80211_ptr;
3242 struct mesh_config cur_params;
3243 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003244 void *hdr;
3245 struct nlattr *pinfoattr;
3246 struct sk_buff *msg;
3247
Johannes Berg29cbe682010-12-03 09:20:44 +01003248 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3249 return -EOPNOTSUPP;
3250
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003251 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003252 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003253
Johannes Berg29cbe682010-12-03 09:20:44 +01003254 wdev_lock(wdev);
3255 /* If not connected, get default parameters */
3256 if (!wdev->mesh_id_len)
3257 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3258 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003259 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003260 &cur_params);
3261 wdev_unlock(wdev);
3262
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003263 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003264 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003265
3266 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003267 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003268 if (!msg)
3269 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003270 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003271 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003272 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003273 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003274 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003275 if (!pinfoattr)
3276 goto nla_put_failure;
3277 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3278 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3279 cur_params.dot11MeshRetryTimeout);
3280 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3281 cur_params.dot11MeshConfirmTimeout);
3282 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3283 cur_params.dot11MeshHoldingTimeout);
3284 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3285 cur_params.dot11MeshMaxPeerLinks);
3286 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3287 cur_params.dot11MeshMaxRetries);
3288 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3289 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01003290 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3291 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003292 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3293 cur_params.auto_open_plinks);
Javier Cardonad299a1f2012-03-31 11:31:33 -07003294 NLA_PUT_U32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3295 cur_params.dot11MeshNbrOffsetMaxNeighbor);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003296 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3297 cur_params.dot11MeshHWMPmaxPREQretries);
3298 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3299 cur_params.path_refresh_time);
3300 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3301 cur_params.min_discovery_timeout);
3302 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3303 cur_params.dot11MeshHWMPactivePathTimeout);
3304 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3305 cur_params.dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003306 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3307 cur_params.dot11MeshHWMPperrMinInterval);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003308 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3309 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00003310 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3311 cur_params.dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -07003312 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3313 cur_params.dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -07003314 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3315 cur_params.dot11MeshGateAnnouncementProtocol);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003316 NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING,
3317 cur_params.dot11MeshForwarding);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003318 NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
3319 cur_params.rssi_threshold);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003320 nla_nest_end(msg, pinfoattr);
3321 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003322 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003323
Johannes Berg3b858752009-03-12 09:55:09 +01003324 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003325 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003326 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003327 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003328 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003329}
3330
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003331static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003332 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3333 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3334 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3335 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3336 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3337 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003338 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003339 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003340 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003341
3342 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3343 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3344 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3345 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3346 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003347 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003348 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003349 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003350 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003351 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003352 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Ashok Nagarajan55335132012-02-28 17:04:08 -08003353 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32},
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003354};
3355
Javier Cardonac80d5452010-12-16 17:37:49 -08003356static const struct nla_policy
3357 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003358 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003359 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3360 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003361 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003362 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08003363 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003364 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003365};
3366
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003367static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003368 struct mesh_config *cfg,
3369 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003370{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003371 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003372 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003373
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003374#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3375do {\
3376 if (table[attr_num]) {\
3377 cfg->param = nla_fn(table[attr_num]); \
3378 mask |= (1 << (attr_num - 1)); \
3379 } \
3380} while (0);\
3381
3382
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003383 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003384 return -EINVAL;
3385 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003386 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003387 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003388 return -EINVAL;
3389
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003390 /* This makes sure that there aren't more than 32 mesh config
3391 * parameters (otherwise our bitfield scheme would not work.) */
3392 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3393
3394 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003395 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3396 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3397 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3398 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3399 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3400 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3401 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3402 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3403 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3404 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3405 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3406 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003407 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3408 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3410 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
Javier Cardonad299a1f2012-03-31 11:31:33 -07003411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
3412 mask, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3413 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003414 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3415 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3416 nla_get_u8);
3417 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3418 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3419 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3420 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3421 nla_get_u16);
3422 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3423 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3424 nla_get_u32);
3425 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3426 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3427 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003428 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
3429 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3430 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003431 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3432 dot11MeshHWMPnetDiameterTraversalTime,
3433 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3434 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003435 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3436 dot11MeshHWMPRootMode, mask,
3437 NL80211_MESHCONF_HWMP_ROOTMODE,
3438 nla_get_u8);
Javier Cardona0507e152011-08-09 16:45:10 -07003439 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3440 dot11MeshHWMPRannInterval, mask,
3441 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3442 nla_get_u16);
Javier Cardona16dd7262011-08-09 16:45:11 -07003443 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3444 dot11MeshGateAnnouncementProtocol, mask,
3445 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3446 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003447 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
3448 mask, NL80211_MESHCONF_FORWARDING, nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003449 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
3450 mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003451 if (mask_out)
3452 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003453
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003454 return 0;
3455
3456#undef FILL_IN_MESH_PARAM_IF_SET
3457}
3458
Javier Cardonac80d5452010-12-16 17:37:49 -08003459static int nl80211_parse_mesh_setup(struct genl_info *info,
3460 struct mesh_setup *setup)
3461{
3462 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3463
3464 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3465 return -EINVAL;
3466 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3467 info->attrs[NL80211_ATTR_MESH_SETUP],
3468 nl80211_mesh_setup_params_policy))
3469 return -EINVAL;
3470
Javier Cardonad299a1f2012-03-31 11:31:33 -07003471 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3472 setup->sync_method =
3473 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3474 IEEE80211_SYNC_METHOD_VENDOR :
3475 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3476
Javier Cardonac80d5452010-12-16 17:37:49 -08003477 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3478 setup->path_sel_proto =
3479 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3480 IEEE80211_PATH_PROTOCOL_VENDOR :
3481 IEEE80211_PATH_PROTOCOL_HWMP;
3482
3483 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3484 setup->path_metric =
3485 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3486 IEEE80211_PATH_METRIC_VENDOR :
3487 IEEE80211_PATH_METRIC_AIRTIME;
3488
Javier Cardona581a8b02011-04-07 15:08:27 -07003489
3490 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003491 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003492 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003493 if (!is_valid_ie_attr(ieattr))
3494 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003495 setup->ie = nla_data(ieattr);
3496 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003497 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003498 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3499 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003500
3501 return 0;
3502}
3503
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003504static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003505 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003506{
3507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3508 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003509 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003510 struct mesh_config cfg;
3511 u32 mask;
3512 int err;
3513
Johannes Berg29cbe682010-12-03 09:20:44 +01003514 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3515 return -EOPNOTSUPP;
3516
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003517 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003518 return -EOPNOTSUPP;
3519
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003520 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003521 if (err)
3522 return err;
3523
Johannes Berg29cbe682010-12-03 09:20:44 +01003524 wdev_lock(wdev);
3525 if (!wdev->mesh_id_len)
3526 err = -ENOLINK;
3527
3528 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003529 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003530 mask, &cfg);
3531
3532 wdev_unlock(wdev);
3533
3534 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003535}
3536
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003537static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3538{
3539 struct sk_buff *msg;
3540 void *hdr = NULL;
3541 struct nlattr *nl_reg_rules;
3542 unsigned int i;
3543 int err = -EINVAL;
3544
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003545 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003546
3547 if (!cfg80211_regdomain)
3548 goto out;
3549
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003551 if (!msg) {
3552 err = -ENOBUFS;
3553 goto out;
3554 }
3555
3556 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3557 NL80211_CMD_GET_REG);
3558 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003559 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003560
3561 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3562 cfg80211_regdomain->alpha2);
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003563 if (cfg80211_regdomain->dfs_region)
3564 NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
3565 cfg80211_regdomain->dfs_region);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003566
3567 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3568 if (!nl_reg_rules)
3569 goto nla_put_failure;
3570
3571 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3572 struct nlattr *nl_reg_rule;
3573 const struct ieee80211_reg_rule *reg_rule;
3574 const struct ieee80211_freq_range *freq_range;
3575 const struct ieee80211_power_rule *power_rule;
3576
3577 reg_rule = &cfg80211_regdomain->reg_rules[i];
3578 freq_range = &reg_rule->freq_range;
3579 power_rule = &reg_rule->power_rule;
3580
3581 nl_reg_rule = nla_nest_start(msg, i);
3582 if (!nl_reg_rule)
3583 goto nla_put_failure;
3584
3585 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3586 reg_rule->flags);
3587 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3588 freq_range->start_freq_khz);
3589 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3590 freq_range->end_freq_khz);
3591 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3592 freq_range->max_bandwidth_khz);
3593 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3594 power_rule->max_antenna_gain);
3595 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3596 power_rule->max_eirp);
3597
3598 nla_nest_end(msg, nl_reg_rule);
3599 }
3600
3601 nla_nest_end(msg, nl_reg_rules);
3602
3603 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003604 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003605 goto out;
3606
3607nla_put_failure:
3608 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003609put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003610 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003611 err = -EMSGSIZE;
3612out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003613 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003614 return err;
3615}
3616
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003617static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3618{
3619 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3620 struct nlattr *nl_reg_rule;
3621 char *alpha2 = NULL;
3622 int rem_reg_rules = 0, r = 0;
3623 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003624 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003625 struct ieee80211_regdomain *rd = NULL;
3626
3627 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3628 return -EINVAL;
3629
3630 if (!info->attrs[NL80211_ATTR_REG_RULES])
3631 return -EINVAL;
3632
3633 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3634
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003635 if (info->attrs[NL80211_ATTR_DFS_REGION])
3636 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3637
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003638 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3639 rem_reg_rules) {
3640 num_rules++;
3641 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003642 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003643 }
3644
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003645 mutex_lock(&cfg80211_mutex);
3646
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003647 if (!reg_is_valid_request(alpha2)) {
3648 r = -EINVAL;
3649 goto bad_reg;
3650 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003651
3652 size_of_regd = sizeof(struct ieee80211_regdomain) +
3653 (num_rules * sizeof(struct ieee80211_reg_rule));
3654
3655 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003656 if (!rd) {
3657 r = -ENOMEM;
3658 goto bad_reg;
3659 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003660
3661 rd->n_reg_rules = num_rules;
3662 rd->alpha2[0] = alpha2[0];
3663 rd->alpha2[1] = alpha2[1];
3664
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003665 /*
3666 * Disable DFS master mode if the DFS region was
3667 * not supported or known on this kernel.
3668 */
3669 if (reg_supported_dfs_region(dfs_region))
3670 rd->dfs_region = dfs_region;
3671
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003672 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3673 rem_reg_rules) {
3674 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3675 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3676 reg_rule_policy);
3677 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3678 if (r)
3679 goto bad_reg;
3680
3681 rule_idx++;
3682
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003683 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3684 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003685 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003686 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003687 }
3688
3689 BUG_ON(rule_idx != num_rules);
3690
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003691 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003692
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003693 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003694
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003695 return r;
3696
Johannes Bergd2372b32008-10-24 20:32:20 +02003697 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003698 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003699 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003700 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003701}
3702
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003703static int validate_scan_freqs(struct nlattr *freqs)
3704{
3705 struct nlattr *attr1, *attr2;
3706 int n_channels = 0, tmp1, tmp2;
3707
3708 nla_for_each_nested(attr1, freqs, tmp1) {
3709 n_channels++;
3710 /*
3711 * Some hardware has a limited channel list for
3712 * scanning, and it is pretty much nonsensical
3713 * to scan for a channel twice, so disallow that
3714 * and don't require drivers to check that the
3715 * channel list they get isn't longer than what
3716 * they can scan, as long as they can scan all
3717 * the channels they registered at once.
3718 */
3719 nla_for_each_nested(attr2, freqs, tmp2)
3720 if (attr1 != attr2 &&
3721 nla_get_u32(attr1) == nla_get_u32(attr2))
3722 return 0;
3723 }
3724
3725 return n_channels;
3726}
3727
Johannes Berg2a519312009-02-10 21:25:55 +01003728static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3729{
Johannes Berg4c476992010-10-04 21:36:35 +02003730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3731 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003732 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003733 struct nlattr *attr;
3734 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003735 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003736 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003737
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003738 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3739 return -EINVAL;
3740
Johannes Berg79c97e92009-07-07 03:56:12 +02003741 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003742
Johannes Berg4c476992010-10-04 21:36:35 +02003743 if (!rdev->ops->scan)
3744 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003745
Johannes Berg4c476992010-10-04 21:36:35 +02003746 if (rdev->scan_req)
3747 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003748
3749 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003750 n_channels = validate_scan_freqs(
3751 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003752 if (!n_channels)
3753 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003754 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003755 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003756 n_channels = 0;
3757
Johannes Berg2a519312009-02-10 21:25:55 +01003758 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3759 if (wiphy->bands[band])
3760 n_channels += wiphy->bands[band]->n_channels;
3761 }
3762
3763 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3764 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3765 n_ssids++;
3766
Johannes Berg4c476992010-10-04 21:36:35 +02003767 if (n_ssids > wiphy->max_scan_ssids)
3768 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003769
Jouni Malinen70692ad2009-02-16 19:39:13 +02003770 if (info->attrs[NL80211_ATTR_IE])
3771 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3772 else
3773 ie_len = 0;
3774
Johannes Berg4c476992010-10-04 21:36:35 +02003775 if (ie_len > wiphy->max_scan_ie_len)
3776 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003777
Johannes Berg2a519312009-02-10 21:25:55 +01003778 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003779 + sizeof(*request->ssids) * n_ssids
3780 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003781 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003782 if (!request)
3783 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003784
Johannes Berg2a519312009-02-10 21:25:55 +01003785 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003786 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003787 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003788 if (ie_len) {
3789 if (request->ssids)
3790 request->ie = (void *)(request->ssids + n_ssids);
3791 else
3792 request->ie = (void *)(request->channels + n_channels);
3793 }
Johannes Berg2a519312009-02-10 21:25:55 +01003794
Johannes Berg584991d2009-11-02 13:32:03 +01003795 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003796 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3797 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003798 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003799 struct ieee80211_channel *chan;
3800
3801 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3802
3803 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003804 err = -EINVAL;
3805 goto out_free;
3806 }
Johannes Berg584991d2009-11-02 13:32:03 +01003807
3808 /* ignore disabled channels */
3809 if (chan->flags & IEEE80211_CHAN_DISABLED)
3810 continue;
3811
3812 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003813 i++;
3814 }
3815 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003816 enum ieee80211_band band;
3817
Johannes Berg2a519312009-02-10 21:25:55 +01003818 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003819 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3820 int j;
3821 if (!wiphy->bands[band])
3822 continue;
3823 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003824 struct ieee80211_channel *chan;
3825
3826 chan = &wiphy->bands[band]->channels[j];
3827
3828 if (chan->flags & IEEE80211_CHAN_DISABLED)
3829 continue;
3830
3831 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003832 i++;
3833 }
3834 }
3835 }
3836
Johannes Berg584991d2009-11-02 13:32:03 +01003837 if (!i) {
3838 err = -EINVAL;
3839 goto out_free;
3840 }
3841
3842 request->n_channels = i;
3843
Johannes Berg2a519312009-02-10 21:25:55 +01003844 i = 0;
3845 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3846 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003847 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003848 err = -EINVAL;
3849 goto out_free;
3850 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003851 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003852 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003853 i++;
3854 }
3855 }
3856
Jouni Malinen70692ad2009-02-16 19:39:13 +02003857 if (info->attrs[NL80211_ATTR_IE]) {
3858 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003859 memcpy((void *)request->ie,
3860 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003861 request->ie_len);
3862 }
3863
Johannes Berg34850ab2011-07-18 18:08:35 +02003864 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003865 if (wiphy->bands[i])
3866 request->rates[i] =
3867 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003868
3869 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3870 nla_for_each_nested(attr,
3871 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3872 tmp) {
3873 enum ieee80211_band band = nla_type(attr);
3874
Dan Carpenter84404622011-07-29 11:52:18 +03003875 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003876 err = -EINVAL;
3877 goto out_free;
3878 }
3879 err = ieee80211_get_ratemask(wiphy->bands[band],
3880 nla_data(attr),
3881 nla_len(attr),
3882 &request->rates[band]);
3883 if (err)
3884 goto out_free;
3885 }
3886 }
3887
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05303888 request->no_cck =
3889 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3890
Johannes Berg463d0182009-07-14 00:33:35 +02003891 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003892 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003893
Johannes Berg79c97e92009-07-07 03:56:12 +02003894 rdev->scan_req = request;
3895 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003896
Johannes Berg463d0182009-07-14 00:33:35 +02003897 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003898 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003899 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003900 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003901 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003902 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003903 kfree(request);
3904 }
Johannes Berg3b858752009-03-12 09:55:09 +01003905
Johannes Berg2a519312009-02-10 21:25:55 +01003906 return err;
3907}
3908
Luciano Coelho807f8a82011-05-11 17:09:35 +03003909static int nl80211_start_sched_scan(struct sk_buff *skb,
3910 struct genl_info *info)
3911{
3912 struct cfg80211_sched_scan_request *request;
3913 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3914 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003915 struct nlattr *attr;
3916 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003917 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003918 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003919 enum ieee80211_band band;
3920 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003921 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003922
3923 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3924 !rdev->ops->sched_scan_start)
3925 return -EOPNOTSUPP;
3926
3927 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3928 return -EINVAL;
3929
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003930 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3931 return -EINVAL;
3932
3933 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3934 if (interval == 0)
3935 return -EINVAL;
3936
Luciano Coelho807f8a82011-05-11 17:09:35 +03003937 wiphy = &rdev->wiphy;
3938
3939 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3940 n_channels = validate_scan_freqs(
3941 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3942 if (!n_channels)
3943 return -EINVAL;
3944 } else {
3945 n_channels = 0;
3946
3947 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3948 if (wiphy->bands[band])
3949 n_channels += wiphy->bands[band]->n_channels;
3950 }
3951
3952 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3953 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3954 tmp)
3955 n_ssids++;
3956
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003957 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003958 return -EINVAL;
3959
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003960 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3961 nla_for_each_nested(attr,
3962 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3963 tmp)
3964 n_match_sets++;
3965
3966 if (n_match_sets > wiphy->max_match_sets)
3967 return -EINVAL;
3968
Luciano Coelho807f8a82011-05-11 17:09:35 +03003969 if (info->attrs[NL80211_ATTR_IE])
3970 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3971 else
3972 ie_len = 0;
3973
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003974 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003975 return -EINVAL;
3976
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003977 mutex_lock(&rdev->sched_scan_mtx);
3978
3979 if (rdev->sched_scan_req) {
3980 err = -EINPROGRESS;
3981 goto out;
3982 }
3983
Luciano Coelho807f8a82011-05-11 17:09:35 +03003984 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003985 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003986 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003987 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003988 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003989 if (!request) {
3990 err = -ENOMEM;
3991 goto out;
3992 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003993
3994 if (n_ssids)
3995 request->ssids = (void *)&request->channels[n_channels];
3996 request->n_ssids = n_ssids;
3997 if (ie_len) {
3998 if (request->ssids)
3999 request->ie = (void *)(request->ssids + n_ssids);
4000 else
4001 request->ie = (void *)(request->channels + n_channels);
4002 }
4003
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004004 if (n_match_sets) {
4005 if (request->ie)
4006 request->match_sets = (void *)(request->ie + ie_len);
4007 else if (request->ssids)
4008 request->match_sets =
4009 (void *)(request->ssids + n_ssids);
4010 else
4011 request->match_sets =
4012 (void *)(request->channels + n_channels);
4013 }
4014 request->n_match_sets = n_match_sets;
4015
Luciano Coelho807f8a82011-05-11 17:09:35 +03004016 i = 0;
4017 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4018 /* user specified, bail out if channel not found */
4019 nla_for_each_nested(attr,
4020 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4021 tmp) {
4022 struct ieee80211_channel *chan;
4023
4024 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4025
4026 if (!chan) {
4027 err = -EINVAL;
4028 goto out_free;
4029 }
4030
4031 /* ignore disabled channels */
4032 if (chan->flags & IEEE80211_CHAN_DISABLED)
4033 continue;
4034
4035 request->channels[i] = chan;
4036 i++;
4037 }
4038 } else {
4039 /* all channels */
4040 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4041 int j;
4042 if (!wiphy->bands[band])
4043 continue;
4044 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4045 struct ieee80211_channel *chan;
4046
4047 chan = &wiphy->bands[band]->channels[j];
4048
4049 if (chan->flags & IEEE80211_CHAN_DISABLED)
4050 continue;
4051
4052 request->channels[i] = chan;
4053 i++;
4054 }
4055 }
4056 }
4057
4058 if (!i) {
4059 err = -EINVAL;
4060 goto out_free;
4061 }
4062
4063 request->n_channels = i;
4064
4065 i = 0;
4066 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4067 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4068 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004069 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004070 err = -EINVAL;
4071 goto out_free;
4072 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004073 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004074 memcpy(request->ssids[i].ssid, nla_data(attr),
4075 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004076 i++;
4077 }
4078 }
4079
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004080 i = 0;
4081 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4082 nla_for_each_nested(attr,
4083 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4084 tmp) {
4085 struct nlattr *ssid;
4086
4087 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4088 nla_data(attr), nla_len(attr),
4089 nl80211_match_policy);
4090 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
4091 if (ssid) {
4092 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4093 err = -EINVAL;
4094 goto out_free;
4095 }
4096 memcpy(request->match_sets[i].ssid.ssid,
4097 nla_data(ssid), nla_len(ssid));
4098 request->match_sets[i].ssid.ssid_len =
4099 nla_len(ssid);
4100 }
4101 i++;
4102 }
4103 }
4104
Luciano Coelho807f8a82011-05-11 17:09:35 +03004105 if (info->attrs[NL80211_ATTR_IE]) {
4106 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4107 memcpy((void *)request->ie,
4108 nla_data(info->attrs[NL80211_ATTR_IE]),
4109 request->ie_len);
4110 }
4111
4112 request->dev = dev;
4113 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004114 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004115
4116 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4117 if (!err) {
4118 rdev->sched_scan_req = request;
4119 nl80211_send_sched_scan(rdev, dev,
4120 NL80211_CMD_START_SCHED_SCAN);
4121 goto out;
4122 }
4123
4124out_free:
4125 kfree(request);
4126out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004127 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004128 return err;
4129}
4130
4131static int nl80211_stop_sched_scan(struct sk_buff *skb,
4132 struct genl_info *info)
4133{
4134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004135 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004136
4137 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4138 !rdev->ops->sched_scan_stop)
4139 return -EOPNOTSUPP;
4140
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004141 mutex_lock(&rdev->sched_scan_mtx);
4142 err = __cfg80211_stop_sched_scan(rdev, false);
4143 mutex_unlock(&rdev->sched_scan_mtx);
4144
4145 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004146}
4147
Johannes Berg9720bb32011-06-21 09:45:33 +02004148static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4149 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004150 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004151 struct wireless_dev *wdev,
4152 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004153{
Johannes Berg48ab9052009-07-10 18:42:31 +02004154 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004155 void *hdr;
4156 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004157
4158 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004159
Johannes Berg9720bb32011-06-21 09:45:33 +02004160 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004161 NL80211_CMD_NEW_SCAN_RESULTS);
4162 if (!hdr)
4163 return -1;
4164
Johannes Berg9720bb32011-06-21 09:45:33 +02004165 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4166
Johannes Bergf5ea9122009-08-07 16:17:38 +02004167 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02004168 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01004169
4170 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4171 if (!bss)
4172 goto nla_put_failure;
4173 if (!is_zero_ether_addr(res->bssid))
4174 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
4175 if (res->information_elements && res->len_information_elements)
4176 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4177 res->len_information_elements,
4178 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02004179 if (res->beacon_ies && res->len_beacon_ies &&
4180 res->beacon_ies != res->information_elements)
4181 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
4182 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01004183 if (res->tsf)
4184 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
4185 if (res->beacon_interval)
4186 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
4187 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
4188 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02004189 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
4190 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01004191
Johannes Berg77965c92009-02-18 18:45:06 +01004192 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004193 case CFG80211_SIGNAL_TYPE_MBM:
4194 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
4195 break;
4196 case CFG80211_SIGNAL_TYPE_UNSPEC:
4197 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
4198 break;
4199 default:
4200 break;
4201 }
4202
Johannes Berg48ab9052009-07-10 18:42:31 +02004203 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004204 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004205 case NL80211_IFTYPE_STATION:
4206 if (intbss == wdev->current_bss)
4207 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4208 NL80211_BSS_STATUS_ASSOCIATED);
Johannes Berg48ab9052009-07-10 18:42:31 +02004209 break;
4210 case NL80211_IFTYPE_ADHOC:
4211 if (intbss == wdev->current_bss)
4212 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4213 NL80211_BSS_STATUS_IBSS_JOINED);
4214 break;
4215 default:
4216 break;
4217 }
4218
Johannes Berg2a519312009-02-10 21:25:55 +01004219 nla_nest_end(msg, bss);
4220
4221 return genlmsg_end(msg, hdr);
4222
4223 nla_put_failure:
4224 genlmsg_cancel(msg, hdr);
4225 return -EMSGSIZE;
4226}
4227
4228static int nl80211_dump_scan(struct sk_buff *skb,
4229 struct netlink_callback *cb)
4230{
Johannes Berg48ab9052009-07-10 18:42:31 +02004231 struct cfg80211_registered_device *rdev;
4232 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004233 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004234 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004235 int start = cb->args[1], idx = 0;
4236 int err;
4237
Johannes Berg67748892010-10-04 21:14:06 +02004238 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4239 if (err)
4240 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004241
Johannes Berg48ab9052009-07-10 18:42:31 +02004242 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004243
Johannes Berg48ab9052009-07-10 18:42:31 +02004244 wdev_lock(wdev);
4245 spin_lock_bh(&rdev->bss_lock);
4246 cfg80211_bss_expire(rdev);
4247
Johannes Berg9720bb32011-06-21 09:45:33 +02004248 cb->seq = rdev->bss_generation;
4249
Johannes Berg48ab9052009-07-10 18:42:31 +02004250 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004251 if (++idx <= start)
4252 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004253 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004254 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004255 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004256 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004257 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004258 }
4259 }
4260
Johannes Berg48ab9052009-07-10 18:42:31 +02004261 spin_unlock_bh(&rdev->bss_lock);
4262 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004263
4264 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004265 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004266
Johannes Berg67748892010-10-04 21:14:06 +02004267 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004268}
4269
Holger Schurig61fa7132009-11-11 12:25:40 +01004270static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4271 int flags, struct net_device *dev,
4272 struct survey_info *survey)
4273{
4274 void *hdr;
4275 struct nlattr *infoattr;
4276
Holger Schurig61fa7132009-11-11 12:25:40 +01004277 hdr = nl80211hdr_put(msg, pid, seq, flags,
4278 NL80211_CMD_NEW_SURVEY_RESULTS);
4279 if (!hdr)
4280 return -ENOMEM;
4281
4282 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4283
4284 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4285 if (!infoattr)
4286 goto nla_put_failure;
4287
4288 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4289 survey->channel->center_freq);
4290 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4291 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4292 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02004293 if (survey->filled & SURVEY_INFO_IN_USE)
4294 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02004295 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4296 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4297 survey->channel_time);
4298 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4299 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4300 survey->channel_time_busy);
4301 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4302 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4303 survey->channel_time_ext_busy);
4304 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4305 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4306 survey->channel_time_rx);
4307 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4308 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4309 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01004310
4311 nla_nest_end(msg, infoattr);
4312
4313 return genlmsg_end(msg, hdr);
4314
4315 nla_put_failure:
4316 genlmsg_cancel(msg, hdr);
4317 return -EMSGSIZE;
4318}
4319
4320static int nl80211_dump_survey(struct sk_buff *skb,
4321 struct netlink_callback *cb)
4322{
4323 struct survey_info survey;
4324 struct cfg80211_registered_device *dev;
4325 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004326 int survey_idx = cb->args[1];
4327 int res;
4328
Johannes Berg67748892010-10-04 21:14:06 +02004329 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4330 if (res)
4331 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004332
4333 if (!dev->ops->dump_survey) {
4334 res = -EOPNOTSUPP;
4335 goto out_err;
4336 }
4337
4338 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004339 struct ieee80211_channel *chan;
4340
Holger Schurig61fa7132009-11-11 12:25:40 +01004341 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4342 &survey);
4343 if (res == -ENOENT)
4344 break;
4345 if (res)
4346 goto out_err;
4347
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004348 /* Survey without a channel doesn't make sense */
4349 if (!survey.channel) {
4350 res = -EINVAL;
4351 goto out;
4352 }
4353
4354 chan = ieee80211_get_channel(&dev->wiphy,
4355 survey.channel->center_freq);
4356 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4357 survey_idx++;
4358 continue;
4359 }
4360
Holger Schurig61fa7132009-11-11 12:25:40 +01004361 if (nl80211_send_survey(skb,
4362 NETLINK_CB(cb->skb).pid,
4363 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4364 netdev,
4365 &survey) < 0)
4366 goto out;
4367 survey_idx++;
4368 }
4369
4370 out:
4371 cb->args[1] = survey_idx;
4372 res = skb->len;
4373 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004374 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004375 return res;
4376}
4377
Jouni Malinen255e7372009-03-20 21:21:17 +02004378static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4379{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004380 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004381}
4382
Samuel Ortizb23aa672009-07-01 21:26:54 +02004383static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4384{
4385 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4386 NL80211_WPA_VERSION_2));
4387}
4388
Jouni Malinen636a5d32009-03-19 13:39:22 +02004389static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4390{
Johannes Berg4c476992010-10-04 21:36:35 +02004391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4392 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004393 struct ieee80211_channel *chan;
4394 const u8 *bssid, *ssid, *ie = NULL;
4395 int err, ssid_len, ie_len = 0;
4396 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004397 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004398 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004399
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004400 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4401 return -EINVAL;
4402
4403 if (!info->attrs[NL80211_ATTR_MAC])
4404 return -EINVAL;
4405
Jouni Malinen17780922009-03-27 20:52:47 +02004406 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4407 return -EINVAL;
4408
Johannes Berg19957bb2009-07-02 17:20:43 +02004409 if (!info->attrs[NL80211_ATTR_SSID])
4410 return -EINVAL;
4411
4412 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4413 return -EINVAL;
4414
Johannes Bergfffd0932009-07-08 14:22:54 +02004415 err = nl80211_parse_key(info, &key);
4416 if (err)
4417 return err;
4418
4419 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004420 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4421 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004422 if (!key.p.key || !key.p.key_len)
4423 return -EINVAL;
4424 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4425 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4426 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4427 key.p.key_len != WLAN_KEY_LEN_WEP104))
4428 return -EINVAL;
4429 if (key.idx > 4)
4430 return -EINVAL;
4431 } else {
4432 key.p.key_len = 0;
4433 key.p.key = NULL;
4434 }
4435
Johannes Bergafea0b72010-08-10 09:46:42 +02004436 if (key.idx >= 0) {
4437 int i;
4438 bool ok = false;
4439 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4440 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4441 ok = true;
4442 break;
4443 }
4444 }
Johannes Berg4c476992010-10-04 21:36:35 +02004445 if (!ok)
4446 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004447 }
4448
Johannes Berg4c476992010-10-04 21:36:35 +02004449 if (!rdev->ops->auth)
4450 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004451
Johannes Berg074ac8d2010-09-16 14:58:22 +02004452 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004453 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4454 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004455
Johannes Berg19957bb2009-07-02 17:20:43 +02004456 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004457 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004458 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004459 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4460 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004461
Johannes Berg19957bb2009-07-02 17:20:43 +02004462 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4463 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4464
4465 if (info->attrs[NL80211_ATTR_IE]) {
4466 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4467 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4468 }
4469
4470 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004471 if (!nl80211_valid_auth_type(auth_type))
4472 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004473
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004474 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4475
Johannes Berg95de8172012-01-20 13:55:25 +01004476 /*
4477 * Since we no longer track auth state, ignore
4478 * requests to only change local state.
4479 */
4480 if (local_state_change)
4481 return 0;
4482
Johannes Berg4c476992010-10-04 21:36:35 +02004483 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4484 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004485 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004486}
4487
Johannes Bergc0692b82010-08-27 14:26:53 +03004488static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4489 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004490 struct cfg80211_crypto_settings *settings,
4491 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004492{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004493 memset(settings, 0, sizeof(*settings));
4494
Samuel Ortizb23aa672009-07-01 21:26:54 +02004495 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4496
Johannes Bergc0692b82010-08-27 14:26:53 +03004497 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4498 u16 proto;
4499 proto = nla_get_u16(
4500 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4501 settings->control_port_ethertype = cpu_to_be16(proto);
4502 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4503 proto != ETH_P_PAE)
4504 return -EINVAL;
4505 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4506 settings->control_port_no_encrypt = true;
4507 } else
4508 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4509
Samuel Ortizb23aa672009-07-01 21:26:54 +02004510 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4511 void *data;
4512 int len, i;
4513
4514 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4515 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4516 settings->n_ciphers_pairwise = len / sizeof(u32);
4517
4518 if (len % sizeof(u32))
4519 return -EINVAL;
4520
Johannes Berg3dc27d22009-07-02 21:36:37 +02004521 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004522 return -EINVAL;
4523
4524 memcpy(settings->ciphers_pairwise, data, len);
4525
4526 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004527 if (!cfg80211_supported_cipher_suite(
4528 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004529 settings->ciphers_pairwise[i]))
4530 return -EINVAL;
4531 }
4532
4533 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4534 settings->cipher_group =
4535 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004536 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4537 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004538 return -EINVAL;
4539 }
4540
4541 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4542 settings->wpa_versions =
4543 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4544 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4545 return -EINVAL;
4546 }
4547
4548 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4549 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004550 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004551
4552 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4553 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4554 settings->n_akm_suites = len / sizeof(u32);
4555
4556 if (len % sizeof(u32))
4557 return -EINVAL;
4558
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004559 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4560 return -EINVAL;
4561
Samuel Ortizb23aa672009-07-01 21:26:54 +02004562 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004563 }
4564
4565 return 0;
4566}
4567
Jouni Malinen636a5d32009-03-19 13:39:22 +02004568static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4569{
Johannes Berg4c476992010-10-04 21:36:35 +02004570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4571 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004572 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004573 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004574 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004575 int err, ssid_len, ie_len = 0;
4576 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004577 u32 flags = 0;
4578 struct ieee80211_ht_cap *ht_capa = NULL;
4579 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004580
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004581 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4582 return -EINVAL;
4583
4584 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004585 !info->attrs[NL80211_ATTR_SSID] ||
4586 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004587 return -EINVAL;
4588
Johannes Berg4c476992010-10-04 21:36:35 +02004589 if (!rdev->ops->assoc)
4590 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004591
Johannes Berg074ac8d2010-09-16 14:58:22 +02004592 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004593 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4594 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004595
Johannes Berg19957bb2009-07-02 17:20:43 +02004596 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004597
Johannes Berg19957bb2009-07-02 17:20:43 +02004598 chan = ieee80211_get_channel(&rdev->wiphy,
4599 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004600 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4601 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004602
Johannes Berg19957bb2009-07-02 17:20:43 +02004603 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4604 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004605
4606 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004607 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4608 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004609 }
4610
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004611 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004612 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004613 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004614 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004615 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004616 else if (mfp != NL80211_MFP_NO)
4617 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004618 }
4619
Johannes Berg3e5d7642009-07-07 14:37:26 +02004620 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4621 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4622
Ben Greear7e7c8922011-11-18 11:31:59 -08004623 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4624 flags |= ASSOC_REQ_DISABLE_HT;
4625
4626 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4627 ht_capa_mask =
4628 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4629
4630 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4631 if (!ht_capa_mask)
4632 return -EINVAL;
4633 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4634 }
4635
Johannes Bergc0692b82010-08-27 14:26:53 +03004636 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004637 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004638 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4639 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004640 &crypto, flags, ht_capa,
4641 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004642
Jouni Malinen636a5d32009-03-19 13:39:22 +02004643 return err;
4644}
4645
4646static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4647{
Johannes Berg4c476992010-10-04 21:36:35 +02004648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4649 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004650 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004651 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004652 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004653 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004654
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004655 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4656 return -EINVAL;
4657
4658 if (!info->attrs[NL80211_ATTR_MAC])
4659 return -EINVAL;
4660
4661 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4662 return -EINVAL;
4663
Johannes Berg4c476992010-10-04 21:36:35 +02004664 if (!rdev->ops->deauth)
4665 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004666
Johannes Berg074ac8d2010-09-16 14:58:22 +02004667 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004668 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4669 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004670
Johannes Berg19957bb2009-07-02 17:20:43 +02004671 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004672
Johannes Berg19957bb2009-07-02 17:20:43 +02004673 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4674 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004675 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004676 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004677 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004678
4679 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004680 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4681 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004682 }
4683
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004684 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4685
Johannes Berg4c476992010-10-04 21:36:35 +02004686 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4687 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004688}
4689
4690static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4691{
Johannes Berg4c476992010-10-04 21:36:35 +02004692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4693 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004694 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004695 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004696 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004697 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004698
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004699 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4700 return -EINVAL;
4701
4702 if (!info->attrs[NL80211_ATTR_MAC])
4703 return -EINVAL;
4704
4705 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4706 return -EINVAL;
4707
Johannes Berg4c476992010-10-04 21:36:35 +02004708 if (!rdev->ops->disassoc)
4709 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004710
Johannes Berg074ac8d2010-09-16 14:58:22 +02004711 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004712 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4713 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004714
Johannes Berg19957bb2009-07-02 17:20:43 +02004715 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004716
Johannes Berg19957bb2009-07-02 17:20:43 +02004717 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4718 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004719 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004720 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004721 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004722
4723 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004724 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4725 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004726 }
4727
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004728 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4729
Johannes Berg4c476992010-10-04 21:36:35 +02004730 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4731 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004732}
4733
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004734static bool
4735nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4736 int mcast_rate[IEEE80211_NUM_BANDS],
4737 int rateval)
4738{
4739 struct wiphy *wiphy = &rdev->wiphy;
4740 bool found = false;
4741 int band, i;
4742
4743 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4744 struct ieee80211_supported_band *sband;
4745
4746 sband = wiphy->bands[band];
4747 if (!sband)
4748 continue;
4749
4750 for (i = 0; i < sband->n_bitrates; i++) {
4751 if (sband->bitrates[i].bitrate == rateval) {
4752 mcast_rate[band] = i + 1;
4753 found = true;
4754 break;
4755 }
4756 }
4757 }
4758
4759 return found;
4760}
4761
Johannes Berg04a773a2009-04-19 21:24:32 +02004762static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4763{
Johannes Berg4c476992010-10-04 21:36:35 +02004764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4765 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004766 struct cfg80211_ibss_params ibss;
4767 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004768 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004769 int err;
4770
Johannes Berg8e30bc52009-04-22 17:45:38 +02004771 memset(&ibss, 0, sizeof(ibss));
4772
Johannes Berg04a773a2009-04-19 21:24:32 +02004773 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4774 return -EINVAL;
4775
4776 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4777 !info->attrs[NL80211_ATTR_SSID] ||
4778 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4779 return -EINVAL;
4780
Johannes Berg8e30bc52009-04-22 17:45:38 +02004781 ibss.beacon_interval = 100;
4782
4783 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4784 ibss.beacon_interval =
4785 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4786 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4787 return -EINVAL;
4788 }
4789
Johannes Berg4c476992010-10-04 21:36:35 +02004790 if (!rdev->ops->join_ibss)
4791 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004792
Johannes Berg4c476992010-10-04 21:36:35 +02004793 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4794 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004795
Johannes Berg79c97e92009-07-07 03:56:12 +02004796 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004797
Johannes Berg39193492011-09-16 13:45:25 +02004798 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02004799 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02004800
4801 if (!is_valid_ether_addr(ibss.bssid))
4802 return -EINVAL;
4803 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004804 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4805 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4806
4807 if (info->attrs[NL80211_ATTR_IE]) {
4808 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4809 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4810 }
4811
Alexander Simon54858ee5b2011-11-30 16:56:32 +01004812 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4813 enum nl80211_channel_type channel_type;
4814
4815 channel_type = nla_get_u32(
4816 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4817 if (channel_type != NL80211_CHAN_NO_HT &&
4818 channel_type != NL80211_CHAN_HT20 &&
4819 channel_type != NL80211_CHAN_HT40MINUS &&
4820 channel_type != NL80211_CHAN_HT40PLUS)
4821 return -EINVAL;
4822
4823 if (channel_type != NL80211_CHAN_NO_HT &&
4824 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
4825 return -EINVAL;
4826
4827 ibss.channel_type = channel_type;
4828 } else {
4829 ibss.channel_type = NL80211_CHAN_NO_HT;
4830 }
4831
4832 ibss.channel = rdev_freq_to_chan(rdev,
4833 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
4834 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02004835 if (!ibss.channel ||
4836 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004837 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4838 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004839
Alexander Simon54858ee5b2011-11-30 16:56:32 +01004840 /* Both channels should be able to initiate communication */
4841 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
4842 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
4843 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
4844 ibss.channel_type))
4845 return -EINVAL;
4846
Johannes Berg04a773a2009-04-19 21:24:32 +02004847 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004848 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004849
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004850 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4851 u8 *rates =
4852 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4853 int n_rates =
4854 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4855 struct ieee80211_supported_band *sband =
4856 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004857
Johannes Berg34850ab2011-07-18 18:08:35 +02004858 err = ieee80211_get_ratemask(sband, rates, n_rates,
4859 &ibss.basic_rates);
4860 if (err)
4861 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004862 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004863
4864 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4865 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4866 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4867 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004868
Johannes Berg4c476992010-10-04 21:36:35 +02004869 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4870 connkeys = nl80211_parse_connkeys(rdev,
4871 info->attrs[NL80211_ATTR_KEYS]);
4872 if (IS_ERR(connkeys))
4873 return PTR_ERR(connkeys);
4874 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004875
Antonio Quartulli267335d2012-01-31 20:25:47 +01004876 ibss.control_port =
4877 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
4878
Johannes Berg4c476992010-10-04 21:36:35 +02004879 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004880 if (err)
4881 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004882 return err;
4883}
4884
4885static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4886{
Johannes Berg4c476992010-10-04 21:36:35 +02004887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4888 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004889
Johannes Berg4c476992010-10-04 21:36:35 +02004890 if (!rdev->ops->leave_ibss)
4891 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004892
Johannes Berg4c476992010-10-04 21:36:35 +02004893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4894 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004895
Johannes Berg4c476992010-10-04 21:36:35 +02004896 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004897}
4898
Johannes Bergaff89a92009-07-01 21:26:51 +02004899#ifdef CONFIG_NL80211_TESTMODE
4900static struct genl_multicast_group nl80211_testmode_mcgrp = {
4901 .name = "testmode",
4902};
4903
4904static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4905{
Johannes Berg4c476992010-10-04 21:36:35 +02004906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004907 int err;
4908
4909 if (!info->attrs[NL80211_ATTR_TESTDATA])
4910 return -EINVAL;
4911
Johannes Bergaff89a92009-07-01 21:26:51 +02004912 err = -EOPNOTSUPP;
4913 if (rdev->ops->testmode_cmd) {
4914 rdev->testmode_info = info;
4915 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4916 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4917 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4918 rdev->testmode_info = NULL;
4919 }
4920
Johannes Bergaff89a92009-07-01 21:26:51 +02004921 return err;
4922}
4923
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004924static int nl80211_testmode_dump(struct sk_buff *skb,
4925 struct netlink_callback *cb)
4926{
Johannes Berg00918d32011-12-13 17:22:05 +01004927 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004928 int err;
4929 long phy_idx;
4930 void *data = NULL;
4931 int data_len = 0;
4932
4933 if (cb->args[0]) {
4934 /*
4935 * 0 is a valid index, but not valid for args[0],
4936 * so we need to offset by 1.
4937 */
4938 phy_idx = cb->args[0] - 1;
4939 } else {
4940 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4941 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4942 nl80211_policy);
4943 if (err)
4944 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01004945 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
4946 phy_idx = nla_get_u32(
4947 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4948 } else {
4949 struct net_device *netdev;
4950
4951 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
4952 nl80211_fam.attrbuf,
4953 &rdev, &netdev);
4954 if (err)
4955 return err;
4956 dev_put(netdev);
4957 phy_idx = rdev->wiphy_idx;
4958 cfg80211_unlock_rdev(rdev);
4959 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004960 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4961 cb->args[1] =
4962 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4963 }
4964
4965 if (cb->args[1]) {
4966 data = nla_data((void *)cb->args[1]);
4967 data_len = nla_len((void *)cb->args[1]);
4968 }
4969
4970 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01004971 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4972 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004973 mutex_unlock(&cfg80211_mutex);
4974 return -ENOENT;
4975 }
Johannes Berg00918d32011-12-13 17:22:05 +01004976 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004977 mutex_unlock(&cfg80211_mutex);
4978
Johannes Berg00918d32011-12-13 17:22:05 +01004979 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004980 err = -EOPNOTSUPP;
4981 goto out_err;
4982 }
4983
4984 while (1) {
4985 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4986 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4987 NL80211_CMD_TESTMODE);
4988 struct nlattr *tmdata;
4989
Johannes Berg00918d32011-12-13 17:22:05 +01004990 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004991 genlmsg_cancel(skb, hdr);
4992 break;
4993 }
4994
4995 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4996 if (!tmdata) {
4997 genlmsg_cancel(skb, hdr);
4998 break;
4999 }
Johannes Berg00918d32011-12-13 17:22:05 +01005000 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5001 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005002 nla_nest_end(skb, tmdata);
5003
5004 if (err == -ENOBUFS || err == -ENOENT) {
5005 genlmsg_cancel(skb, hdr);
5006 break;
5007 } else if (err) {
5008 genlmsg_cancel(skb, hdr);
5009 goto out_err;
5010 }
5011
5012 genlmsg_end(skb, hdr);
5013 }
5014
5015 err = skb->len;
5016 /* see above */
5017 cb->args[0] = phy_idx + 1;
5018 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005019 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005020 return err;
5021}
5022
Johannes Bergaff89a92009-07-01 21:26:51 +02005023static struct sk_buff *
5024__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5025 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5026{
5027 struct sk_buff *skb;
5028 void *hdr;
5029 struct nlattr *data;
5030
5031 skb = nlmsg_new(approxlen + 100, gfp);
5032 if (!skb)
5033 return NULL;
5034
5035 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5036 if (!hdr) {
5037 kfree_skb(skb);
5038 return NULL;
5039 }
5040
5041 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5042 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5043
5044 ((void **)skb->cb)[0] = rdev;
5045 ((void **)skb->cb)[1] = hdr;
5046 ((void **)skb->cb)[2] = data;
5047
5048 return skb;
5049
5050 nla_put_failure:
5051 kfree_skb(skb);
5052 return NULL;
5053}
5054
5055struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5056 int approxlen)
5057{
5058 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5059
5060 if (WARN_ON(!rdev->testmode_info))
5061 return NULL;
5062
5063 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5064 rdev->testmode_info->snd_pid,
5065 rdev->testmode_info->snd_seq,
5066 GFP_KERNEL);
5067}
5068EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5069
5070int cfg80211_testmode_reply(struct sk_buff *skb)
5071{
5072 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5073 void *hdr = ((void **)skb->cb)[1];
5074 struct nlattr *data = ((void **)skb->cb)[2];
5075
5076 if (WARN_ON(!rdev->testmode_info)) {
5077 kfree_skb(skb);
5078 return -EINVAL;
5079 }
5080
5081 nla_nest_end(skb, data);
5082 genlmsg_end(skb, hdr);
5083 return genlmsg_reply(skb, rdev->testmode_info);
5084}
5085EXPORT_SYMBOL(cfg80211_testmode_reply);
5086
5087struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5088 int approxlen, gfp_t gfp)
5089{
5090 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5091
5092 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5093}
5094EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5095
5096void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5097{
5098 void *hdr = ((void **)skb->cb)[1];
5099 struct nlattr *data = ((void **)skb->cb)[2];
5100
5101 nla_nest_end(skb, data);
5102 genlmsg_end(skb, hdr);
5103 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5104}
5105EXPORT_SYMBOL(cfg80211_testmode_event);
5106#endif
5107
Samuel Ortizb23aa672009-07-01 21:26:54 +02005108static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5109{
Johannes Berg4c476992010-10-04 21:36:35 +02005110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5111 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005112 struct cfg80211_connect_params connect;
5113 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005114 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005115 int err;
5116
5117 memset(&connect, 0, sizeof(connect));
5118
5119 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5120 return -EINVAL;
5121
5122 if (!info->attrs[NL80211_ATTR_SSID] ||
5123 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5124 return -EINVAL;
5125
5126 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5127 connect.auth_type =
5128 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5129 if (!nl80211_valid_auth_type(connect.auth_type))
5130 return -EINVAL;
5131 } else
5132 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5133
5134 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5135
Johannes Bergc0692b82010-08-27 14:26:53 +03005136 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005137 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005138 if (err)
5139 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005140
Johannes Berg074ac8d2010-09-16 14:58:22 +02005141 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005142 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5143 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005144
Johannes Berg79c97e92009-07-07 03:56:12 +02005145 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005146
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305147 connect.bg_scan_period = -1;
5148 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5149 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5150 connect.bg_scan_period =
5151 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5152 }
5153
Samuel Ortizb23aa672009-07-01 21:26:54 +02005154 if (info->attrs[NL80211_ATTR_MAC])
5155 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5156 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5157 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5158
5159 if (info->attrs[NL80211_ATTR_IE]) {
5160 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5161 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5162 }
5163
5164 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5165 connect.channel =
5166 ieee80211_get_channel(wiphy,
5167 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5168 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005169 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5170 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005171 }
5172
Johannes Bergfffd0932009-07-08 14:22:54 +02005173 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5174 connkeys = nl80211_parse_connkeys(rdev,
5175 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005176 if (IS_ERR(connkeys))
5177 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005178 }
5179
Ben Greear7e7c8922011-11-18 11:31:59 -08005180 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5181 connect.flags |= ASSOC_REQ_DISABLE_HT;
5182
5183 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5184 memcpy(&connect.ht_capa_mask,
5185 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5186 sizeof(connect.ht_capa_mask));
5187
5188 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5189 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5190 return -EINVAL;
5191 memcpy(&connect.ht_capa,
5192 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5193 sizeof(connect.ht_capa));
5194 }
5195
Johannes Bergfffd0932009-07-08 14:22:54 +02005196 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005197 if (err)
5198 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005199 return err;
5200}
5201
5202static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5203{
Johannes Berg4c476992010-10-04 21:36:35 +02005204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5205 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005206 u16 reason;
5207
5208 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5209 reason = WLAN_REASON_DEAUTH_LEAVING;
5210 else
5211 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5212
5213 if (reason == 0)
5214 return -EINVAL;
5215
Johannes Berg074ac8d2010-09-16 14:58:22 +02005216 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005217 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5218 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005219
Johannes Berg4c476992010-10-04 21:36:35 +02005220 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005221}
5222
Johannes Berg463d0182009-07-14 00:33:35 +02005223static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5224{
Johannes Berg4c476992010-10-04 21:36:35 +02005225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005226 struct net *net;
5227 int err;
5228 u32 pid;
5229
5230 if (!info->attrs[NL80211_ATTR_PID])
5231 return -EINVAL;
5232
5233 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5234
Johannes Berg463d0182009-07-14 00:33:35 +02005235 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005236 if (IS_ERR(net))
5237 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005238
5239 err = 0;
5240
5241 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005242 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5243 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005244
Johannes Berg463d0182009-07-14 00:33:35 +02005245 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005246 return err;
5247}
5248
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005249static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5250{
Johannes Berg4c476992010-10-04 21:36:35 +02005251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005252 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5253 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005254 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005255 struct cfg80211_pmksa pmksa;
5256
5257 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5258
5259 if (!info->attrs[NL80211_ATTR_MAC])
5260 return -EINVAL;
5261
5262 if (!info->attrs[NL80211_ATTR_PMKID])
5263 return -EINVAL;
5264
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005265 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5266 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5267
Johannes Berg074ac8d2010-09-16 14:58:22 +02005268 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005269 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5270 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005271
5272 switch (info->genlhdr->cmd) {
5273 case NL80211_CMD_SET_PMKSA:
5274 rdev_ops = rdev->ops->set_pmksa;
5275 break;
5276 case NL80211_CMD_DEL_PMKSA:
5277 rdev_ops = rdev->ops->del_pmksa;
5278 break;
5279 default:
5280 WARN_ON(1);
5281 break;
5282 }
5283
Johannes Berg4c476992010-10-04 21:36:35 +02005284 if (!rdev_ops)
5285 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005286
Johannes Berg4c476992010-10-04 21:36:35 +02005287 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005288}
5289
5290static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5291{
Johannes Berg4c476992010-10-04 21:36:35 +02005292 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5293 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005294
Johannes Berg074ac8d2010-09-16 14:58:22 +02005295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5297 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005298
Johannes Berg4c476992010-10-04 21:36:35 +02005299 if (!rdev->ops->flush_pmksa)
5300 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005301
Johannes Berg4c476992010-10-04 21:36:35 +02005302 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005303}
5304
Arik Nemtsov109086c2011-09-28 14:12:50 +03005305static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5306{
5307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5308 struct net_device *dev = info->user_ptr[1];
5309 u8 action_code, dialog_token;
5310 u16 status_code;
5311 u8 *peer;
5312
5313 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5314 !rdev->ops->tdls_mgmt)
5315 return -EOPNOTSUPP;
5316
5317 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5318 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5319 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5320 !info->attrs[NL80211_ATTR_IE] ||
5321 !info->attrs[NL80211_ATTR_MAC])
5322 return -EINVAL;
5323
5324 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5325 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5326 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5327 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5328
5329 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5330 dialog_token, status_code,
5331 nla_data(info->attrs[NL80211_ATTR_IE]),
5332 nla_len(info->attrs[NL80211_ATTR_IE]));
5333}
5334
5335static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5336{
5337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5338 struct net_device *dev = info->user_ptr[1];
5339 enum nl80211_tdls_operation operation;
5340 u8 *peer;
5341
5342 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5343 !rdev->ops->tdls_oper)
5344 return -EOPNOTSUPP;
5345
5346 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5347 !info->attrs[NL80211_ATTR_MAC])
5348 return -EINVAL;
5349
5350 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5351 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5352
5353 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5354}
5355
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005356static int nl80211_remain_on_channel(struct sk_buff *skb,
5357 struct genl_info *info)
5358{
Johannes Berg4c476992010-10-04 21:36:35 +02005359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5360 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005361 struct ieee80211_channel *chan;
5362 struct sk_buff *msg;
5363 void *hdr;
5364 u64 cookie;
5365 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5366 u32 freq, duration;
5367 int err;
5368
5369 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5370 !info->attrs[NL80211_ATTR_DURATION])
5371 return -EINVAL;
5372
5373 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5374
5375 /*
5376 * We should be on that channel for at least one jiffie,
5377 * and more than 5 seconds seems excessive.
5378 */
Johannes Berga2939112010-12-14 17:54:28 +01005379 if (!duration || !msecs_to_jiffies(duration) ||
5380 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005381 return -EINVAL;
5382
Johannes Berg7c4ef712011-11-18 15:33:48 +01005383 if (!rdev->ops->remain_on_channel ||
5384 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005385 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005386
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005387 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5388 channel_type = nla_get_u32(
5389 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5390 if (channel_type != NL80211_CHAN_NO_HT &&
5391 channel_type != NL80211_CHAN_HT20 &&
5392 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005393 channel_type != NL80211_CHAN_HT40MINUS)
5394 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005395 }
5396
5397 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5398 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005399 if (chan == NULL)
5400 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005401
5402 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005403 if (!msg)
5404 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005405
5406 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5407 NL80211_CMD_REMAIN_ON_CHANNEL);
5408
5409 if (IS_ERR(hdr)) {
5410 err = PTR_ERR(hdr);
5411 goto free_msg;
5412 }
5413
5414 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5415 channel_type, duration, &cookie);
5416
5417 if (err)
5418 goto free_msg;
5419
5420 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5421
5422 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005423
5424 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005425
5426 nla_put_failure:
5427 err = -ENOBUFS;
5428 free_msg:
5429 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005430 return err;
5431}
5432
5433static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5434 struct genl_info *info)
5435{
Johannes Berg4c476992010-10-04 21:36:35 +02005436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5437 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005438 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005439
5440 if (!info->attrs[NL80211_ATTR_COOKIE])
5441 return -EINVAL;
5442
Johannes Berg4c476992010-10-04 21:36:35 +02005443 if (!rdev->ops->cancel_remain_on_channel)
5444 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005445
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005446 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5447
Johannes Berg4c476992010-10-04 21:36:35 +02005448 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005449}
5450
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005451static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5452 u8 *rates, u8 rates_len)
5453{
5454 u8 i;
5455 u32 mask = 0;
5456
5457 for (i = 0; i < rates_len; i++) {
5458 int rate = (rates[i] & 0x7f) * 5;
5459 int ridx;
5460 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5461 struct ieee80211_rate *srate =
5462 &sband->bitrates[ridx];
5463 if (rate == srate->bitrate) {
5464 mask |= 1 << ridx;
5465 break;
5466 }
5467 }
5468 if (ridx == sband->n_bitrates)
5469 return 0; /* rate not found */
5470 }
5471
5472 return mask;
5473}
5474
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005475static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5476 u8 *rates, u8 rates_len,
5477 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5478{
5479 u8 i;
5480
5481 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5482
5483 for (i = 0; i < rates_len; i++) {
5484 int ridx, rbit;
5485
5486 ridx = rates[i] / 8;
5487 rbit = BIT(rates[i] % 8);
5488
5489 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005490 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005491 return false;
5492
5493 /* check availability */
5494 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5495 mcs[ridx] |= rbit;
5496 else
5497 return false;
5498 }
5499
5500 return true;
5501}
5502
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005503static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005504 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5505 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005506 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5507 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005508};
5509
5510static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5511 struct genl_info *info)
5512{
5513 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005515 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005516 int rem, i;
5517 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005518 struct nlattr *tx_rates;
5519 struct ieee80211_supported_band *sband;
5520
5521 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5522 return -EINVAL;
5523
Johannes Berg4c476992010-10-04 21:36:35 +02005524 if (!rdev->ops->set_bitrate_mask)
5525 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005526
5527 memset(&mask, 0, sizeof(mask));
5528 /* Default to all rates enabled */
5529 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5530 sband = rdev->wiphy.bands[i];
5531 mask.control[i].legacy =
5532 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005533 if (sband)
5534 memcpy(mask.control[i].mcs,
5535 sband->ht_cap.mcs.rx_mask,
5536 sizeof(mask.control[i].mcs));
5537 else
5538 memset(mask.control[i].mcs, 0,
5539 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005540 }
5541
5542 /*
5543 * The nested attribute uses enum nl80211_band as the index. This maps
5544 * directly to the enum ieee80211_band values used in cfg80211.
5545 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005546 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005547 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5548 {
5549 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005550 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5551 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005552 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005553 if (sband == NULL)
5554 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005555 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5556 nla_len(tx_rates), nl80211_txattr_policy);
5557 if (tb[NL80211_TXRATE_LEGACY]) {
5558 mask.control[band].legacy = rateset_to_mask(
5559 sband,
5560 nla_data(tb[NL80211_TXRATE_LEGACY]),
5561 nla_len(tb[NL80211_TXRATE_LEGACY]));
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005562 }
5563 if (tb[NL80211_TXRATE_MCS]) {
5564 if (!ht_rateset_to_mask(
5565 sband,
5566 nla_data(tb[NL80211_TXRATE_MCS]),
5567 nla_len(tb[NL80211_TXRATE_MCS]),
5568 mask.control[band].mcs))
5569 return -EINVAL;
5570 }
5571
5572 if (mask.control[band].legacy == 0) {
5573 /* don't allow empty legacy rates if HT
5574 * is not even supported. */
5575 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5576 return -EINVAL;
5577
5578 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5579 if (mask.control[band].mcs[i])
5580 break;
5581
5582 /* legacy and mcs rates may not be both empty */
5583 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005584 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005585 }
5586 }
5587
Johannes Berg4c476992010-10-04 21:36:35 +02005588 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005589}
5590
Johannes Berg2e161f72010-08-12 15:38:38 +02005591static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005592{
Johannes Berg4c476992010-10-04 21:36:35 +02005593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5594 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005595 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005596
5597 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5598 return -EINVAL;
5599
Johannes Berg2e161f72010-08-12 15:38:38 +02005600 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5601 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005602
Johannes Berg9d38d852010-06-09 17:20:33 +02005603 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005604 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005605 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5606 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5607 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005608 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005609 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5610 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005611
5612 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005613 if (!rdev->ops->mgmt_tx)
5614 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005615
Johannes Berg4c476992010-10-04 21:36:35 +02005616 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005617 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005618 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5619 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005620}
5621
Johannes Berg2e161f72010-08-12 15:38:38 +02005622static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005623{
Johannes Berg4c476992010-10-04 21:36:35 +02005624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5625 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005626 struct ieee80211_channel *chan;
5627 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005628 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005629 u32 freq;
5630 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005631 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005632 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005633 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005634 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005635 bool offchan, no_cck, dont_wait_for_ack;
5636
5637 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005638
5639 if (!info->attrs[NL80211_ATTR_FRAME] ||
5640 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5641 return -EINVAL;
5642
Johannes Berg4c476992010-10-04 21:36:35 +02005643 if (!rdev->ops->mgmt_tx)
5644 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005645
Johannes Berg9d38d852010-06-09 17:20:33 +02005646 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005647 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005648 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5649 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5650 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005651 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005652 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5653 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005654
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005655 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005656 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005657 return -EINVAL;
5658 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5659 }
5660
Jouni Malinen026331c2010-02-15 12:53:10 +02005661 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5662 channel_type = nla_get_u32(
5663 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5664 if (channel_type != NL80211_CHAN_NO_HT &&
5665 channel_type != NL80211_CHAN_HT20 &&
5666 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005667 channel_type != NL80211_CHAN_HT40MINUS)
5668 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005669 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005670 }
5671
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005672 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5673
Johannes Berg7c4ef712011-11-18 15:33:48 +01005674 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5675 return -EINVAL;
5676
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305677 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5678
Jouni Malinen026331c2010-02-15 12:53:10 +02005679 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5680 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005681 if (chan == NULL)
5682 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005683
Johannes Berge247bd902011-11-04 11:18:21 +01005684 if (!dont_wait_for_ack) {
5685 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5686 if (!msg)
5687 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005688
Johannes Berge247bd902011-11-04 11:18:21 +01005689 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5690 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005691
Johannes Berge247bd902011-11-04 11:18:21 +01005692 if (IS_ERR(hdr)) {
5693 err = PTR_ERR(hdr);
5694 goto free_msg;
5695 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005696 }
Johannes Berge247bd902011-11-04 11:18:21 +01005697
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005698 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5699 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005700 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5701 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005702 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005703 if (err)
5704 goto free_msg;
5705
Johannes Berge247bd902011-11-04 11:18:21 +01005706 if (msg) {
5707 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005708
Johannes Berge247bd902011-11-04 11:18:21 +01005709 genlmsg_end(msg, hdr);
5710 return genlmsg_reply(msg, info);
5711 }
5712
5713 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02005714
5715 nla_put_failure:
5716 err = -ENOBUFS;
5717 free_msg:
5718 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005719 return err;
5720}
5721
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005722static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5723{
5724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5725 struct net_device *dev = info->user_ptr[1];
5726 u64 cookie;
5727
5728 if (!info->attrs[NL80211_ATTR_COOKIE])
5729 return -EINVAL;
5730
5731 if (!rdev->ops->mgmt_tx_cancel_wait)
5732 return -EOPNOTSUPP;
5733
5734 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5735 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5736 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5737 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5738 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5739 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5740 return -EOPNOTSUPP;
5741
5742 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5743
5744 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5745}
5746
Kalle Valoffb9eb32010-02-17 17:58:10 +02005747static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5748{
Johannes Berg4c476992010-10-04 21:36:35 +02005749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005750 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005751 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005752 u8 ps_state;
5753 bool state;
5754 int err;
5755
Johannes Berg4c476992010-10-04 21:36:35 +02005756 if (!info->attrs[NL80211_ATTR_PS_STATE])
5757 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005758
5759 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5760
Johannes Berg4c476992010-10-04 21:36:35 +02005761 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5762 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005763
5764 wdev = dev->ieee80211_ptr;
5765
Johannes Berg4c476992010-10-04 21:36:35 +02005766 if (!rdev->ops->set_power_mgmt)
5767 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005768
5769 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5770
5771 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005772 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005773
Johannes Berg4c476992010-10-04 21:36:35 +02005774 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5775 wdev->ps_timeout);
5776 if (!err)
5777 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005778 return err;
5779}
5780
5781static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5782{
Johannes Berg4c476992010-10-04 21:36:35 +02005783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005784 enum nl80211_ps_state ps_state;
5785 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005786 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005787 struct sk_buff *msg;
5788 void *hdr;
5789 int err;
5790
Kalle Valoffb9eb32010-02-17 17:58:10 +02005791 wdev = dev->ieee80211_ptr;
5792
Johannes Berg4c476992010-10-04 21:36:35 +02005793 if (!rdev->ops->set_power_mgmt)
5794 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005795
5796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005797 if (!msg)
5798 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005799
5800 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5801 NL80211_CMD_GET_POWER_SAVE);
5802 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005803 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005804 goto free_msg;
5805 }
5806
5807 if (wdev->ps)
5808 ps_state = NL80211_PS_ENABLED;
5809 else
5810 ps_state = NL80211_PS_DISABLED;
5811
5812 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5813
5814 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005815 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005816
Johannes Berg4c476992010-10-04 21:36:35 +02005817 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005818 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005819 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005820 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005821 return err;
5822}
5823
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005824static struct nla_policy
5825nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5826 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5827 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5828 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5829};
5830
5831static int nl80211_set_cqm_rssi(struct genl_info *info,
5832 s32 threshold, u32 hysteresis)
5833{
Johannes Berg4c476992010-10-04 21:36:35 +02005834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005835 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005836 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005837
5838 if (threshold > 0)
5839 return -EINVAL;
5840
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005841 wdev = dev->ieee80211_ptr;
5842
Johannes Berg4c476992010-10-04 21:36:35 +02005843 if (!rdev->ops->set_cqm_rssi_config)
5844 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005845
Johannes Berg074ac8d2010-09-16 14:58:22 +02005846 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005847 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5848 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005849
Johannes Berg4c476992010-10-04 21:36:35 +02005850 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5851 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005852}
5853
5854static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5855{
5856 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5857 struct nlattr *cqm;
5858 int err;
5859
5860 cqm = info->attrs[NL80211_ATTR_CQM];
5861 if (!cqm) {
5862 err = -EINVAL;
5863 goto out;
5864 }
5865
5866 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5867 nl80211_attr_cqm_policy);
5868 if (err)
5869 goto out;
5870
5871 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5872 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5873 s32 threshold;
5874 u32 hysteresis;
5875 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5876 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5877 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5878 } else
5879 err = -EINVAL;
5880
5881out:
5882 return err;
5883}
5884
Johannes Berg29cbe682010-12-03 09:20:44 +01005885static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5886{
5887 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5888 struct net_device *dev = info->user_ptr[1];
5889 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005890 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005891 int err;
5892
5893 /* start with default */
5894 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005895 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005896
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005897 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005898 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005899 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005900 if (err)
5901 return err;
5902 }
5903
5904 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5905 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5906 return -EINVAL;
5907
Javier Cardonac80d5452010-12-16 17:37:49 -08005908 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5909 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5910
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08005911 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5912 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
5913 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5914 return -EINVAL;
5915
Javier Cardonac80d5452010-12-16 17:37:49 -08005916 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5917 /* parse additional setup parameters if given */
5918 err = nl80211_parse_mesh_setup(info, &setup);
5919 if (err)
5920 return err;
5921 }
5922
5923 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005924}
5925
5926static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5927{
5928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5929 struct net_device *dev = info->user_ptr[1];
5930
5931 return cfg80211_leave_mesh(rdev, dev);
5932}
5933
Johannes Bergff1b6e62011-05-04 15:37:28 +02005934static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5935{
5936 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5937 struct sk_buff *msg;
5938 void *hdr;
5939
5940 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5941 return -EOPNOTSUPP;
5942
5943 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5944 if (!msg)
5945 return -ENOMEM;
5946
5947 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5948 NL80211_CMD_GET_WOWLAN);
5949 if (!hdr)
5950 goto nla_put_failure;
5951
5952 if (rdev->wowlan) {
5953 struct nlattr *nl_wowlan;
5954
5955 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5956 if (!nl_wowlan)
5957 goto nla_put_failure;
5958
5959 if (rdev->wowlan->any)
5960 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5961 if (rdev->wowlan->disconnect)
5962 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5963 if (rdev->wowlan->magic_pkt)
5964 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005965 if (rdev->wowlan->gtk_rekey_failure)
5966 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5967 if (rdev->wowlan->eap_identity_req)
5968 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5969 if (rdev->wowlan->four_way_handshake)
5970 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5971 if (rdev->wowlan->rfkill_release)
5972 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005973 if (rdev->wowlan->n_patterns) {
5974 struct nlattr *nl_pats, *nl_pat;
5975 int i, pat_len;
5976
5977 nl_pats = nla_nest_start(msg,
5978 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5979 if (!nl_pats)
5980 goto nla_put_failure;
5981
5982 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5983 nl_pat = nla_nest_start(msg, i + 1);
5984 if (!nl_pat)
5985 goto nla_put_failure;
5986 pat_len = rdev->wowlan->patterns[i].pattern_len;
5987 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5988 DIV_ROUND_UP(pat_len, 8),
5989 rdev->wowlan->patterns[i].mask);
5990 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5991 pat_len,
5992 rdev->wowlan->patterns[i].pattern);
5993 nla_nest_end(msg, nl_pat);
5994 }
5995 nla_nest_end(msg, nl_pats);
5996 }
5997
5998 nla_nest_end(msg, nl_wowlan);
5999 }
6000
6001 genlmsg_end(msg, hdr);
6002 return genlmsg_reply(msg, info);
6003
6004nla_put_failure:
6005 nlmsg_free(msg);
6006 return -ENOBUFS;
6007}
6008
6009static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6010{
6011 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6012 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6013 struct cfg80211_wowlan no_triggers = {};
6014 struct cfg80211_wowlan new_triggers = {};
6015 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6016 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006017 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006018
6019 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6020 return -EOPNOTSUPP;
6021
6022 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6023 goto no_triggers;
6024
6025 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6026 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6027 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6028 nl80211_wowlan_policy);
6029 if (err)
6030 return err;
6031
6032 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6033 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6034 return -EINVAL;
6035 new_triggers.any = true;
6036 }
6037
6038 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6039 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6040 return -EINVAL;
6041 new_triggers.disconnect = true;
6042 }
6043
6044 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6045 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6046 return -EINVAL;
6047 new_triggers.magic_pkt = true;
6048 }
6049
Johannes Berg77dbbb12011-07-13 10:48:55 +02006050 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6051 return -EINVAL;
6052
6053 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6054 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6055 return -EINVAL;
6056 new_triggers.gtk_rekey_failure = true;
6057 }
6058
6059 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6060 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6061 return -EINVAL;
6062 new_triggers.eap_identity_req = true;
6063 }
6064
6065 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6066 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6067 return -EINVAL;
6068 new_triggers.four_way_handshake = true;
6069 }
6070
6071 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6072 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6073 return -EINVAL;
6074 new_triggers.rfkill_release = true;
6075 }
6076
Johannes Bergff1b6e62011-05-04 15:37:28 +02006077 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6078 struct nlattr *pat;
6079 int n_patterns = 0;
6080 int rem, pat_len, mask_len;
6081 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6082
6083 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6084 rem)
6085 n_patterns++;
6086 if (n_patterns > wowlan->n_patterns)
6087 return -EINVAL;
6088
6089 new_triggers.patterns = kcalloc(n_patterns,
6090 sizeof(new_triggers.patterns[0]),
6091 GFP_KERNEL);
6092 if (!new_triggers.patterns)
6093 return -ENOMEM;
6094
6095 new_triggers.n_patterns = n_patterns;
6096 i = 0;
6097
6098 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6099 rem) {
6100 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6101 nla_data(pat), nla_len(pat), NULL);
6102 err = -EINVAL;
6103 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6104 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6105 goto error;
6106 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6107 mask_len = DIV_ROUND_UP(pat_len, 8);
6108 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6109 mask_len)
6110 goto error;
6111 if (pat_len > wowlan->pattern_max_len ||
6112 pat_len < wowlan->pattern_min_len)
6113 goto error;
6114
6115 new_triggers.patterns[i].mask =
6116 kmalloc(mask_len + pat_len, GFP_KERNEL);
6117 if (!new_triggers.patterns[i].mask) {
6118 err = -ENOMEM;
6119 goto error;
6120 }
6121 new_triggers.patterns[i].pattern =
6122 new_triggers.patterns[i].mask + mask_len;
6123 memcpy(new_triggers.patterns[i].mask,
6124 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6125 mask_len);
6126 new_triggers.patterns[i].pattern_len = pat_len;
6127 memcpy(new_triggers.patterns[i].pattern,
6128 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6129 pat_len);
6130 i++;
6131 }
6132 }
6133
6134 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6135 struct cfg80211_wowlan *ntrig;
6136 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6137 GFP_KERNEL);
6138 if (!ntrig) {
6139 err = -ENOMEM;
6140 goto error;
6141 }
6142 cfg80211_rdev_free_wowlan(rdev);
6143 rdev->wowlan = ntrig;
6144 } else {
6145 no_triggers:
6146 cfg80211_rdev_free_wowlan(rdev);
6147 rdev->wowlan = NULL;
6148 }
6149
Johannes Berg6d525632012-04-04 15:05:25 +02006150 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6151 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6152
Johannes Bergff1b6e62011-05-04 15:37:28 +02006153 return 0;
6154 error:
6155 for (i = 0; i < new_triggers.n_patterns; i++)
6156 kfree(new_triggers.patterns[i].mask);
6157 kfree(new_triggers.patterns);
6158 return err;
6159}
6160
Johannes Berge5497d72011-07-05 16:35:40 +02006161static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6162{
6163 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6164 struct net_device *dev = info->user_ptr[1];
6165 struct wireless_dev *wdev = dev->ieee80211_ptr;
6166 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6167 struct cfg80211_gtk_rekey_data rekey_data;
6168 int err;
6169
6170 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6171 return -EINVAL;
6172
6173 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6174 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6175 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6176 nl80211_rekey_policy);
6177 if (err)
6178 return err;
6179
6180 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6181 return -ERANGE;
6182 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6183 return -ERANGE;
6184 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6185 return -ERANGE;
6186
6187 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6188 NL80211_KEK_LEN);
6189 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6190 NL80211_KCK_LEN);
6191 memcpy(rekey_data.replay_ctr,
6192 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6193 NL80211_REPLAY_CTR_LEN);
6194
6195 wdev_lock(wdev);
6196 if (!wdev->current_bss) {
6197 err = -ENOTCONN;
6198 goto out;
6199 }
6200
6201 if (!rdev->ops->set_rekey_data) {
6202 err = -EOPNOTSUPP;
6203 goto out;
6204 }
6205
6206 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6207 out:
6208 wdev_unlock(wdev);
6209 return err;
6210}
6211
Johannes Berg28946da2011-11-04 11:18:12 +01006212static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6213 struct genl_info *info)
6214{
6215 struct net_device *dev = info->user_ptr[1];
6216 struct wireless_dev *wdev = dev->ieee80211_ptr;
6217
6218 if (wdev->iftype != NL80211_IFTYPE_AP &&
6219 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6220 return -EINVAL;
6221
6222 if (wdev->ap_unexpected_nlpid)
6223 return -EBUSY;
6224
6225 wdev->ap_unexpected_nlpid = info->snd_pid;
6226 return 0;
6227}
6228
Johannes Berg7f6cf312011-11-04 11:18:15 +01006229static int nl80211_probe_client(struct sk_buff *skb,
6230 struct genl_info *info)
6231{
6232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6233 struct net_device *dev = info->user_ptr[1];
6234 struct wireless_dev *wdev = dev->ieee80211_ptr;
6235 struct sk_buff *msg;
6236 void *hdr;
6237 const u8 *addr;
6238 u64 cookie;
6239 int err;
6240
6241 if (wdev->iftype != NL80211_IFTYPE_AP &&
6242 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6243 return -EOPNOTSUPP;
6244
6245 if (!info->attrs[NL80211_ATTR_MAC])
6246 return -EINVAL;
6247
6248 if (!rdev->ops->probe_client)
6249 return -EOPNOTSUPP;
6250
6251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6252 if (!msg)
6253 return -ENOMEM;
6254
6255 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6256 NL80211_CMD_PROBE_CLIENT);
6257
6258 if (IS_ERR(hdr)) {
6259 err = PTR_ERR(hdr);
6260 goto free_msg;
6261 }
6262
6263 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6264
6265 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6266 if (err)
6267 goto free_msg;
6268
6269 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6270
6271 genlmsg_end(msg, hdr);
6272
6273 return genlmsg_reply(msg, info);
6274
6275 nla_put_failure:
6276 err = -ENOBUFS;
6277 free_msg:
6278 nlmsg_free(msg);
6279 return err;
6280}
6281
Johannes Berg5e760232011-11-04 11:18:17 +01006282static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6283{
6284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6285
6286 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6287 return -EOPNOTSUPP;
6288
6289 if (rdev->ap_beacons_nlpid)
6290 return -EBUSY;
6291
6292 rdev->ap_beacons_nlpid = info->snd_pid;
6293
6294 return 0;
6295}
6296
Johannes Berg4c476992010-10-04 21:36:35 +02006297#define NL80211_FLAG_NEED_WIPHY 0x01
6298#define NL80211_FLAG_NEED_NETDEV 0x02
6299#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006300#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6301#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6302 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006303
6304static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6305 struct genl_info *info)
6306{
6307 struct cfg80211_registered_device *rdev;
6308 struct net_device *dev;
6309 int err;
6310 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6311
6312 if (rtnl)
6313 rtnl_lock();
6314
6315 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
6316 rdev = cfg80211_get_dev_from_info(info);
6317 if (IS_ERR(rdev)) {
6318 if (rtnl)
6319 rtnl_unlock();
6320 return PTR_ERR(rdev);
6321 }
6322 info->user_ptr[0] = rdev;
6323 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006324 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6325 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006326 if (err) {
6327 if (rtnl)
6328 rtnl_unlock();
6329 return err;
6330 }
Johannes Berg41265712010-10-04 21:14:05 +02006331 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6332 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006333 cfg80211_unlock_rdev(rdev);
6334 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006335 if (rtnl)
6336 rtnl_unlock();
6337 return -ENETDOWN;
6338 }
Johannes Berg4c476992010-10-04 21:36:35 +02006339 info->user_ptr[0] = rdev;
6340 info->user_ptr[1] = dev;
6341 }
6342
6343 return 0;
6344}
6345
6346static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6347 struct genl_info *info)
6348{
6349 if (info->user_ptr[0])
6350 cfg80211_unlock_rdev(info->user_ptr[0]);
6351 if (info->user_ptr[1])
6352 dev_put(info->user_ptr[1]);
6353 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6354 rtnl_unlock();
6355}
6356
Johannes Berg55682962007-09-20 13:09:35 -04006357static struct genl_ops nl80211_ops[] = {
6358 {
6359 .cmd = NL80211_CMD_GET_WIPHY,
6360 .doit = nl80211_get_wiphy,
6361 .dumpit = nl80211_dump_wiphy,
6362 .policy = nl80211_policy,
6363 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006364 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006365 },
6366 {
6367 .cmd = NL80211_CMD_SET_WIPHY,
6368 .doit = nl80211_set_wiphy,
6369 .policy = nl80211_policy,
6370 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006371 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006372 },
6373 {
6374 .cmd = NL80211_CMD_GET_INTERFACE,
6375 .doit = nl80211_get_interface,
6376 .dumpit = nl80211_dump_interface,
6377 .policy = nl80211_policy,
6378 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006379 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006380 },
6381 {
6382 .cmd = NL80211_CMD_SET_INTERFACE,
6383 .doit = nl80211_set_interface,
6384 .policy = nl80211_policy,
6385 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006386 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6387 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006388 },
6389 {
6390 .cmd = NL80211_CMD_NEW_INTERFACE,
6391 .doit = nl80211_new_interface,
6392 .policy = nl80211_policy,
6393 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006394 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6395 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006396 },
6397 {
6398 .cmd = NL80211_CMD_DEL_INTERFACE,
6399 .doit = nl80211_del_interface,
6400 .policy = nl80211_policy,
6401 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006402 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6403 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006404 },
Johannes Berg41ade002007-12-19 02:03:29 +01006405 {
6406 .cmd = NL80211_CMD_GET_KEY,
6407 .doit = nl80211_get_key,
6408 .policy = nl80211_policy,
6409 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006410 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6411 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006412 },
6413 {
6414 .cmd = NL80211_CMD_SET_KEY,
6415 .doit = nl80211_set_key,
6416 .policy = nl80211_policy,
6417 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006419 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006420 },
6421 {
6422 .cmd = NL80211_CMD_NEW_KEY,
6423 .doit = nl80211_new_key,
6424 .policy = nl80211_policy,
6425 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006427 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006428 },
6429 {
6430 .cmd = NL80211_CMD_DEL_KEY,
6431 .doit = nl80211_del_key,
6432 .policy = nl80211_policy,
6433 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006434 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006435 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006436 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006437 {
6438 .cmd = NL80211_CMD_SET_BEACON,
6439 .policy = nl80211_policy,
6440 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006441 .doit = nl80211_set_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006442 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6443 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006444 },
6445 {
Johannes Berg88600202012-02-13 15:17:18 +01006446 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006447 .policy = nl80211_policy,
6448 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006449 .doit = nl80211_start_ap,
Johannes Berg4c476992010-10-04 21:36:35 +02006450 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6451 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006452 },
6453 {
Johannes Berg88600202012-02-13 15:17:18 +01006454 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006455 .policy = nl80211_policy,
6456 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006457 .doit = nl80211_stop_ap,
Johannes Berg4c476992010-10-04 21:36:35 +02006458 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6459 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006460 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006461 {
6462 .cmd = NL80211_CMD_GET_STATION,
6463 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006464 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006465 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006466 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6467 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006468 },
6469 {
6470 .cmd = NL80211_CMD_SET_STATION,
6471 .doit = nl80211_set_station,
6472 .policy = nl80211_policy,
6473 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006474 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6475 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006476 },
6477 {
6478 .cmd = NL80211_CMD_NEW_STATION,
6479 .doit = nl80211_new_station,
6480 .policy = nl80211_policy,
6481 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006482 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006483 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006484 },
6485 {
6486 .cmd = NL80211_CMD_DEL_STATION,
6487 .doit = nl80211_del_station,
6488 .policy = nl80211_policy,
6489 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006490 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6491 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006492 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006493 {
6494 .cmd = NL80211_CMD_GET_MPATH,
6495 .doit = nl80211_get_mpath,
6496 .dumpit = nl80211_dump_mpath,
6497 .policy = nl80211_policy,
6498 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006500 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006501 },
6502 {
6503 .cmd = NL80211_CMD_SET_MPATH,
6504 .doit = nl80211_set_mpath,
6505 .policy = nl80211_policy,
6506 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006508 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006509 },
6510 {
6511 .cmd = NL80211_CMD_NEW_MPATH,
6512 .doit = nl80211_new_mpath,
6513 .policy = nl80211_policy,
6514 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006516 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006517 },
6518 {
6519 .cmd = NL80211_CMD_DEL_MPATH,
6520 .doit = nl80211_del_mpath,
6521 .policy = nl80211_policy,
6522 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006523 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6524 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006525 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006526 {
6527 .cmd = NL80211_CMD_SET_BSS,
6528 .doit = nl80211_set_bss,
6529 .policy = nl80211_policy,
6530 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006531 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006533 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006534 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006535 .cmd = NL80211_CMD_GET_REG,
6536 .doit = nl80211_get_reg,
6537 .policy = nl80211_policy,
6538 /* can be retrieved by unprivileged users */
6539 },
6540 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006541 .cmd = NL80211_CMD_SET_REG,
6542 .doit = nl80211_set_reg,
6543 .policy = nl80211_policy,
6544 .flags = GENL_ADMIN_PERM,
6545 },
6546 {
6547 .cmd = NL80211_CMD_REQ_SET_REG,
6548 .doit = nl80211_req_set_reg,
6549 .policy = nl80211_policy,
6550 .flags = GENL_ADMIN_PERM,
6551 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006552 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006553 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6554 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006555 .policy = nl80211_policy,
6556 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006557 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6558 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006559 },
6560 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006561 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6562 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006563 .policy = nl80211_policy,
6564 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006565 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006566 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006567 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006568 {
Johannes Berg2a519312009-02-10 21:25:55 +01006569 .cmd = NL80211_CMD_TRIGGER_SCAN,
6570 .doit = nl80211_trigger_scan,
6571 .policy = nl80211_policy,
6572 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006573 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006574 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006575 },
6576 {
6577 .cmd = NL80211_CMD_GET_SCAN,
6578 .policy = nl80211_policy,
6579 .dumpit = nl80211_dump_scan,
6580 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006581 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006582 .cmd = NL80211_CMD_START_SCHED_SCAN,
6583 .doit = nl80211_start_sched_scan,
6584 .policy = nl80211_policy,
6585 .flags = GENL_ADMIN_PERM,
6586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6587 NL80211_FLAG_NEED_RTNL,
6588 },
6589 {
6590 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6591 .doit = nl80211_stop_sched_scan,
6592 .policy = nl80211_policy,
6593 .flags = GENL_ADMIN_PERM,
6594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6595 NL80211_FLAG_NEED_RTNL,
6596 },
6597 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006598 .cmd = NL80211_CMD_AUTHENTICATE,
6599 .doit = nl80211_authenticate,
6600 .policy = nl80211_policy,
6601 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006603 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006604 },
6605 {
6606 .cmd = NL80211_CMD_ASSOCIATE,
6607 .doit = nl80211_associate,
6608 .policy = nl80211_policy,
6609 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006611 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006612 },
6613 {
6614 .cmd = NL80211_CMD_DEAUTHENTICATE,
6615 .doit = nl80211_deauthenticate,
6616 .policy = nl80211_policy,
6617 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006619 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006620 },
6621 {
6622 .cmd = NL80211_CMD_DISASSOCIATE,
6623 .doit = nl80211_disassociate,
6624 .policy = nl80211_policy,
6625 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006627 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006628 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006629 {
6630 .cmd = NL80211_CMD_JOIN_IBSS,
6631 .doit = nl80211_join_ibss,
6632 .policy = nl80211_policy,
6633 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006635 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006636 },
6637 {
6638 .cmd = NL80211_CMD_LEAVE_IBSS,
6639 .doit = nl80211_leave_ibss,
6640 .policy = nl80211_policy,
6641 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006643 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006644 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006645#ifdef CONFIG_NL80211_TESTMODE
6646 {
6647 .cmd = NL80211_CMD_TESTMODE,
6648 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006649 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006650 .policy = nl80211_policy,
6651 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006652 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6653 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006654 },
6655#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006656 {
6657 .cmd = NL80211_CMD_CONNECT,
6658 .doit = nl80211_connect,
6659 .policy = nl80211_policy,
6660 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006662 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006663 },
6664 {
6665 .cmd = NL80211_CMD_DISCONNECT,
6666 .doit = nl80211_disconnect,
6667 .policy = nl80211_policy,
6668 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006670 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006671 },
Johannes Berg463d0182009-07-14 00:33:35 +02006672 {
6673 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6674 .doit = nl80211_wiphy_netns,
6675 .policy = nl80211_policy,
6676 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006677 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6678 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006679 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006680 {
6681 .cmd = NL80211_CMD_GET_SURVEY,
6682 .policy = nl80211_policy,
6683 .dumpit = nl80211_dump_survey,
6684 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006685 {
6686 .cmd = NL80211_CMD_SET_PMKSA,
6687 .doit = nl80211_setdel_pmksa,
6688 .policy = nl80211_policy,
6689 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006690 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6691 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006692 },
6693 {
6694 .cmd = NL80211_CMD_DEL_PMKSA,
6695 .doit = nl80211_setdel_pmksa,
6696 .policy = nl80211_policy,
6697 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6699 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006700 },
6701 {
6702 .cmd = NL80211_CMD_FLUSH_PMKSA,
6703 .doit = nl80211_flush_pmksa,
6704 .policy = nl80211_policy,
6705 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006706 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6707 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006708 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006709 {
6710 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6711 .doit = nl80211_remain_on_channel,
6712 .policy = nl80211_policy,
6713 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006715 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006716 },
6717 {
6718 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6719 .doit = nl80211_cancel_remain_on_channel,
6720 .policy = nl80211_policy,
6721 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006723 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006724 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006725 {
6726 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6727 .doit = nl80211_set_tx_bitrate_mask,
6728 .policy = nl80211_policy,
6729 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006730 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6731 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006732 },
Jouni Malinen026331c2010-02-15 12:53:10 +02006733 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006734 .cmd = NL80211_CMD_REGISTER_FRAME,
6735 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006736 .policy = nl80211_policy,
6737 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006738 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6739 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006740 },
6741 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006742 .cmd = NL80211_CMD_FRAME,
6743 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006744 .policy = nl80211_policy,
6745 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006747 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006748 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006749 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006750 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6751 .doit = nl80211_tx_mgmt_cancel_wait,
6752 .policy = nl80211_policy,
6753 .flags = GENL_ADMIN_PERM,
6754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6755 NL80211_FLAG_NEED_RTNL,
6756 },
6757 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006758 .cmd = NL80211_CMD_SET_POWER_SAVE,
6759 .doit = nl80211_set_power_save,
6760 .policy = nl80211_policy,
6761 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006762 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6763 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006764 },
6765 {
6766 .cmd = NL80211_CMD_GET_POWER_SAVE,
6767 .doit = nl80211_get_power_save,
6768 .policy = nl80211_policy,
6769 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006770 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6771 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006772 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006773 {
6774 .cmd = NL80211_CMD_SET_CQM,
6775 .doit = nl80211_set_cqm,
6776 .policy = nl80211_policy,
6777 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006778 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6779 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006780 },
Johannes Bergf444de02010-05-05 15:25:02 +02006781 {
6782 .cmd = NL80211_CMD_SET_CHANNEL,
6783 .doit = nl80211_set_channel,
6784 .policy = nl80211_policy,
6785 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006786 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6787 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006788 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006789 {
6790 .cmd = NL80211_CMD_SET_WDS_PEER,
6791 .doit = nl80211_set_wds_peer,
6792 .policy = nl80211_policy,
6793 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006794 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6795 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006796 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006797 {
6798 .cmd = NL80211_CMD_JOIN_MESH,
6799 .doit = nl80211_join_mesh,
6800 .policy = nl80211_policy,
6801 .flags = GENL_ADMIN_PERM,
6802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6803 NL80211_FLAG_NEED_RTNL,
6804 },
6805 {
6806 .cmd = NL80211_CMD_LEAVE_MESH,
6807 .doit = nl80211_leave_mesh,
6808 .policy = nl80211_policy,
6809 .flags = GENL_ADMIN_PERM,
6810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6811 NL80211_FLAG_NEED_RTNL,
6812 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006813 {
6814 .cmd = NL80211_CMD_GET_WOWLAN,
6815 .doit = nl80211_get_wowlan,
6816 .policy = nl80211_policy,
6817 /* can be retrieved by unprivileged users */
6818 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6819 NL80211_FLAG_NEED_RTNL,
6820 },
6821 {
6822 .cmd = NL80211_CMD_SET_WOWLAN,
6823 .doit = nl80211_set_wowlan,
6824 .policy = nl80211_policy,
6825 .flags = GENL_ADMIN_PERM,
6826 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6827 NL80211_FLAG_NEED_RTNL,
6828 },
Johannes Berge5497d72011-07-05 16:35:40 +02006829 {
6830 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6831 .doit = nl80211_set_rekey_data,
6832 .policy = nl80211_policy,
6833 .flags = GENL_ADMIN_PERM,
6834 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6835 NL80211_FLAG_NEED_RTNL,
6836 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03006837 {
6838 .cmd = NL80211_CMD_TDLS_MGMT,
6839 .doit = nl80211_tdls_mgmt,
6840 .policy = nl80211_policy,
6841 .flags = GENL_ADMIN_PERM,
6842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6843 NL80211_FLAG_NEED_RTNL,
6844 },
6845 {
6846 .cmd = NL80211_CMD_TDLS_OPER,
6847 .doit = nl80211_tdls_oper,
6848 .policy = nl80211_policy,
6849 .flags = GENL_ADMIN_PERM,
6850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6851 NL80211_FLAG_NEED_RTNL,
6852 },
Johannes Berg28946da2011-11-04 11:18:12 +01006853 {
6854 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6855 .doit = nl80211_register_unexpected_frame,
6856 .policy = nl80211_policy,
6857 .flags = GENL_ADMIN_PERM,
6858 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6859 NL80211_FLAG_NEED_RTNL,
6860 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01006861 {
6862 .cmd = NL80211_CMD_PROBE_CLIENT,
6863 .doit = nl80211_probe_client,
6864 .policy = nl80211_policy,
6865 .flags = GENL_ADMIN_PERM,
6866 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6867 NL80211_FLAG_NEED_RTNL,
6868 },
Johannes Berg5e760232011-11-04 11:18:17 +01006869 {
6870 .cmd = NL80211_CMD_REGISTER_BEACONS,
6871 .doit = nl80211_register_beacons,
6872 .policy = nl80211_policy,
6873 .flags = GENL_ADMIN_PERM,
6874 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6875 NL80211_FLAG_NEED_RTNL,
6876 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01006877 {
6878 .cmd = NL80211_CMD_SET_NOACK_MAP,
6879 .doit = nl80211_set_noack_map,
6880 .policy = nl80211_policy,
6881 .flags = GENL_ADMIN_PERM,
6882 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6883 NL80211_FLAG_NEED_RTNL,
6884 },
6885
Johannes Berg55682962007-09-20 13:09:35 -04006886};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006887
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006888static struct genl_multicast_group nl80211_mlme_mcgrp = {
6889 .name = "mlme",
6890};
Johannes Berg55682962007-09-20 13:09:35 -04006891
6892/* multicast groups */
6893static struct genl_multicast_group nl80211_config_mcgrp = {
6894 .name = "config",
6895};
Johannes Berg2a519312009-02-10 21:25:55 +01006896static struct genl_multicast_group nl80211_scan_mcgrp = {
6897 .name = "scan",
6898};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006899static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6900 .name = "regulatory",
6901};
Johannes Berg55682962007-09-20 13:09:35 -04006902
6903/* notification functions */
6904
6905void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6906{
6907 struct sk_buff *msg;
6908
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006910 if (!msg)
6911 return;
6912
6913 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6914 nlmsg_free(msg);
6915 return;
6916 }
6917
Johannes Berg463d0182009-07-14 00:33:35 +02006918 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6919 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006920}
6921
Johannes Berg362a4152009-05-24 16:43:15 +02006922static int nl80211_add_scan_req(struct sk_buff *msg,
6923 struct cfg80211_registered_device *rdev)
6924{
6925 struct cfg80211_scan_request *req = rdev->scan_req;
6926 struct nlattr *nest;
6927 int i;
6928
Johannes Berg667503d2009-07-07 03:56:11 +02006929 ASSERT_RDEV_LOCK(rdev);
6930
Johannes Berg362a4152009-05-24 16:43:15 +02006931 if (WARN_ON(!req))
6932 return 0;
6933
6934 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6935 if (!nest)
6936 goto nla_put_failure;
6937 for (i = 0; i < req->n_ssids; i++)
6938 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6939 nla_nest_end(msg, nest);
6940
6941 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6942 if (!nest)
6943 goto nla_put_failure;
6944 for (i = 0; i < req->n_channels; i++)
6945 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6946 nla_nest_end(msg, nest);
6947
6948 if (req->ie)
6949 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6950
6951 return 0;
6952 nla_put_failure:
6953 return -ENOBUFS;
6954}
6955
Johannes Berga538e2d2009-06-16 19:56:42 +02006956static int nl80211_send_scan_msg(struct sk_buff *msg,
6957 struct cfg80211_registered_device *rdev,
6958 struct net_device *netdev,
6959 u32 pid, u32 seq, int flags,
6960 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006961{
6962 void *hdr;
6963
6964 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6965 if (!hdr)
6966 return -1;
6967
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006968 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006969 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6970
Johannes Berg362a4152009-05-24 16:43:15 +02006971 /* ignore errors and send incomplete event anyway */
6972 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006973
6974 return genlmsg_end(msg, hdr);
6975
6976 nla_put_failure:
6977 genlmsg_cancel(msg, hdr);
6978 return -EMSGSIZE;
6979}
6980
Luciano Coelho807f8a82011-05-11 17:09:35 +03006981static int
6982nl80211_send_sched_scan_msg(struct sk_buff *msg,
6983 struct cfg80211_registered_device *rdev,
6984 struct net_device *netdev,
6985 u32 pid, u32 seq, int flags, u32 cmd)
6986{
6987 void *hdr;
6988
6989 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6990 if (!hdr)
6991 return -1;
6992
6993 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6994 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6995
6996 return genlmsg_end(msg, hdr);
6997
6998 nla_put_failure:
6999 genlmsg_cancel(msg, hdr);
7000 return -EMSGSIZE;
7001}
7002
Johannes Berga538e2d2009-06-16 19:56:42 +02007003void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7004 struct net_device *netdev)
7005{
7006 struct sk_buff *msg;
7007
7008 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7009 if (!msg)
7010 return;
7011
7012 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7013 NL80211_CMD_TRIGGER_SCAN) < 0) {
7014 nlmsg_free(msg);
7015 return;
7016 }
7017
Johannes Berg463d0182009-07-14 00:33:35 +02007018 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7019 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007020}
7021
Johannes Berg2a519312009-02-10 21:25:55 +01007022void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7023 struct net_device *netdev)
7024{
7025 struct sk_buff *msg;
7026
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007027 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007028 if (!msg)
7029 return;
7030
Johannes Berga538e2d2009-06-16 19:56:42 +02007031 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7032 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007033 nlmsg_free(msg);
7034 return;
7035 }
7036
Johannes Berg463d0182009-07-14 00:33:35 +02007037 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7038 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007039}
7040
7041void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7042 struct net_device *netdev)
7043{
7044 struct sk_buff *msg;
7045
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007047 if (!msg)
7048 return;
7049
Johannes Berga538e2d2009-06-16 19:56:42 +02007050 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7051 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007052 nlmsg_free(msg);
7053 return;
7054 }
7055
Johannes Berg463d0182009-07-14 00:33:35 +02007056 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7057 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007058}
7059
Luciano Coelho807f8a82011-05-11 17:09:35 +03007060void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7061 struct net_device *netdev)
7062{
7063 struct sk_buff *msg;
7064
7065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7066 if (!msg)
7067 return;
7068
7069 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7070 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7071 nlmsg_free(msg);
7072 return;
7073 }
7074
7075 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7076 nl80211_scan_mcgrp.id, GFP_KERNEL);
7077}
7078
7079void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7080 struct net_device *netdev, u32 cmd)
7081{
7082 struct sk_buff *msg;
7083
7084 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7085 if (!msg)
7086 return;
7087
7088 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 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
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007097/*
7098 * This can happen on global regulatory changes or device specific settings
7099 * based on custom world regulatory domains.
7100 */
7101void nl80211_send_reg_change_event(struct regulatory_request *request)
7102{
7103 struct sk_buff *msg;
7104 void *hdr;
7105
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007106 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007107 if (!msg)
7108 return;
7109
7110 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7111 if (!hdr) {
7112 nlmsg_free(msg);
7113 return;
7114 }
7115
7116 /* Userspace can always count this one always being set */
7117 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
7118
7119 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
7120 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7121 NL80211_REGDOM_TYPE_WORLD);
7122 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
7123 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7124 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
7125 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7126 request->intersect)
7127 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7128 NL80211_REGDOM_TYPE_INTERSECTION);
7129 else {
7130 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7131 NL80211_REGDOM_TYPE_COUNTRY);
7132 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
7133 }
7134
7135 if (wiphy_idx_valid(request->wiphy_idx))
7136 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
7137
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007138 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007139
Johannes Bergbc43b282009-07-25 10:54:13 +02007140 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007141 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007142 GFP_ATOMIC);
7143 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007144
7145 return;
7146
7147nla_put_failure:
7148 genlmsg_cancel(msg, hdr);
7149 nlmsg_free(msg);
7150}
7151
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007152static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7153 struct net_device *netdev,
7154 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007155 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007156{
7157 struct sk_buff *msg;
7158 void *hdr;
7159
Johannes Berge6d6e342009-07-01 21:26:47 +02007160 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007161 if (!msg)
7162 return;
7163
7164 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7165 if (!hdr) {
7166 nlmsg_free(msg);
7167 return;
7168 }
7169
7170 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7171 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7172 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7173
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007174 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007175
Johannes Berg463d0182009-07-14 00:33:35 +02007176 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7177 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007178 return;
7179
7180 nla_put_failure:
7181 genlmsg_cancel(msg, hdr);
7182 nlmsg_free(msg);
7183}
7184
7185void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007186 struct net_device *netdev, const u8 *buf,
7187 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007188{
7189 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007190 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007191}
7192
7193void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7194 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007195 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007196{
Johannes Berge6d6e342009-07-01 21:26:47 +02007197 nl80211_send_mlme_event(rdev, netdev, buf, len,
7198 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007199}
7200
Jouni Malinen53b46b82009-03-27 20:53:56 +02007201void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007202 struct net_device *netdev, const u8 *buf,
7203 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007204{
7205 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007206 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007207}
7208
Jouni Malinen53b46b82009-03-27 20:53:56 +02007209void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7210 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007211 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007212{
7213 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007214 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007215}
7216
Jouni Malinencf4e5942010-12-16 00:52:40 +02007217void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7218 struct net_device *netdev, const u8 *buf,
7219 size_t len, gfp_t gfp)
7220{
7221 nl80211_send_mlme_event(rdev, netdev, buf, len,
7222 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7223}
7224
7225void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7226 struct net_device *netdev, const u8 *buf,
7227 size_t len, gfp_t gfp)
7228{
7229 nl80211_send_mlme_event(rdev, netdev, buf, len,
7230 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7231}
7232
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007233static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7234 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007235 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007236{
7237 struct sk_buff *msg;
7238 void *hdr;
7239
Johannes Berge6d6e342009-07-01 21:26:47 +02007240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007241 if (!msg)
7242 return;
7243
7244 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7245 if (!hdr) {
7246 nlmsg_free(msg);
7247 return;
7248 }
7249
7250 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7251 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7252 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
7253 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7254
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007255 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007256
Johannes Berg463d0182009-07-14 00:33:35 +02007257 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7258 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007259 return;
7260
7261 nla_put_failure:
7262 genlmsg_cancel(msg, hdr);
7263 nlmsg_free(msg);
7264}
7265
7266void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007267 struct net_device *netdev, const u8 *addr,
7268 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007269{
7270 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007271 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007272}
7273
7274void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007275 struct net_device *netdev, const u8 *addr,
7276 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007277{
Johannes Berge6d6e342009-07-01 21:26:47 +02007278 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7279 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007280}
7281
Samuel Ortizb23aa672009-07-01 21:26:54 +02007282void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7283 struct net_device *netdev, const u8 *bssid,
7284 const u8 *req_ie, size_t req_ie_len,
7285 const u8 *resp_ie, size_t resp_ie_len,
7286 u16 status, gfp_t gfp)
7287{
7288 struct sk_buff *msg;
7289 void *hdr;
7290
7291 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7292 if (!msg)
7293 return;
7294
7295 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7296 if (!hdr) {
7297 nlmsg_free(msg);
7298 return;
7299 }
7300
7301 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7302 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7303 if (bssid)
7304 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7305 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
7306 if (req_ie)
7307 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7308 if (resp_ie)
7309 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7310
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007311 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007312
Johannes Berg463d0182009-07-14 00:33:35 +02007313 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7314 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007315 return;
7316
7317 nla_put_failure:
7318 genlmsg_cancel(msg, hdr);
7319 nlmsg_free(msg);
7320
7321}
7322
7323void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7324 struct net_device *netdev, const u8 *bssid,
7325 const u8 *req_ie, size_t req_ie_len,
7326 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7327{
7328 struct sk_buff *msg;
7329 void *hdr;
7330
7331 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7332 if (!msg)
7333 return;
7334
7335 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7336 if (!hdr) {
7337 nlmsg_free(msg);
7338 return;
7339 }
7340
7341 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7342 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7343 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7344 if (req_ie)
7345 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7346 if (resp_ie)
7347 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7348
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007349 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007350
Johannes Berg463d0182009-07-14 00:33:35 +02007351 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7352 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007353 return;
7354
7355 nla_put_failure:
7356 genlmsg_cancel(msg, hdr);
7357 nlmsg_free(msg);
7358
7359}
7360
7361void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7362 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02007363 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007364{
7365 struct sk_buff *msg;
7366 void *hdr;
7367
Johannes Berg667503d2009-07-07 03:56:11 +02007368 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007369 if (!msg)
7370 return;
7371
7372 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7373 if (!hdr) {
7374 nlmsg_free(msg);
7375 return;
7376 }
7377
7378 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7379 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7380 if (from_ap && reason)
7381 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
7382 if (from_ap)
7383 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
7384 if (ie)
7385 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
7386
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007387 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007388
Johannes Berg463d0182009-07-14 00:33:35 +02007389 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7390 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007391 return;
7392
7393 nla_put_failure:
7394 genlmsg_cancel(msg, hdr);
7395 nlmsg_free(msg);
7396
7397}
7398
Johannes Berg04a773a2009-04-19 21:24:32 +02007399void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7400 struct net_device *netdev, const u8 *bssid,
7401 gfp_t gfp)
7402{
7403 struct sk_buff *msg;
7404 void *hdr;
7405
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007407 if (!msg)
7408 return;
7409
7410 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7411 if (!hdr) {
7412 nlmsg_free(msg);
7413 return;
7414 }
7415
7416 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7417 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7418 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7419
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007420 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007421
Johannes Berg463d0182009-07-14 00:33:35 +02007422 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7423 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007424 return;
7425
7426 nla_put_failure:
7427 genlmsg_cancel(msg, hdr);
7428 nlmsg_free(msg);
7429}
7430
Javier Cardonac93b5e72011-04-07 15:08:34 -07007431void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7432 struct net_device *netdev,
7433 const u8 *macaddr, const u8* ie, u8 ie_len,
7434 gfp_t gfp)
7435{
7436 struct sk_buff *msg;
7437 void *hdr;
7438
7439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7440 if (!msg)
7441 return;
7442
7443 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7444 if (!hdr) {
7445 nlmsg_free(msg);
7446 return;
7447 }
7448
7449 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7450 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7451 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
7452 if (ie_len && ie)
7453 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
7454
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007455 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007456
7457 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7458 nl80211_mlme_mcgrp.id, gfp);
7459 return;
7460
7461 nla_put_failure:
7462 genlmsg_cancel(msg, hdr);
7463 nlmsg_free(msg);
7464}
7465
Jouni Malinena3b8b052009-03-27 21:59:49 +02007466void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7467 struct net_device *netdev, const u8 *addr,
7468 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007469 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007470{
7471 struct sk_buff *msg;
7472 void *hdr;
7473
Johannes Berge6d6e342009-07-01 21:26:47 +02007474 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007475 if (!msg)
7476 return;
7477
7478 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7479 if (!hdr) {
7480 nlmsg_free(msg);
7481 return;
7482 }
7483
7484 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7485 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7486 if (addr)
7487 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7488 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03007489 if (key_id != -1)
7490 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007491 if (tsc)
7492 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7493
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007494 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007495
Johannes Berg463d0182009-07-14 00:33:35 +02007496 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7497 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007498 return;
7499
7500 nla_put_failure:
7501 genlmsg_cancel(msg, hdr);
7502 nlmsg_free(msg);
7503}
7504
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007505void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7506 struct ieee80211_channel *channel_before,
7507 struct ieee80211_channel *channel_after)
7508{
7509 struct sk_buff *msg;
7510 void *hdr;
7511 struct nlattr *nl_freq;
7512
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007513 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007514 if (!msg)
7515 return;
7516
7517 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7518 if (!hdr) {
7519 nlmsg_free(msg);
7520 return;
7521 }
7522
7523 /*
7524 * Since we are applying the beacon hint to a wiphy we know its
7525 * wiphy_idx is valid
7526 */
7527 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7528
7529 /* Before */
7530 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7531 if (!nl_freq)
7532 goto nla_put_failure;
7533 if (nl80211_msg_put_channel(msg, channel_before))
7534 goto nla_put_failure;
7535 nla_nest_end(msg, nl_freq);
7536
7537 /* After */
7538 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7539 if (!nl_freq)
7540 goto nla_put_failure;
7541 if (nl80211_msg_put_channel(msg, channel_after))
7542 goto nla_put_failure;
7543 nla_nest_end(msg, nl_freq);
7544
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007545 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007546
Johannes Berg463d0182009-07-14 00:33:35 +02007547 rcu_read_lock();
7548 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7549 GFP_ATOMIC);
7550 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007551
7552 return;
7553
7554nla_put_failure:
7555 genlmsg_cancel(msg, hdr);
7556 nlmsg_free(msg);
7557}
7558
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007559static void nl80211_send_remain_on_chan_event(
7560 int cmd, struct cfg80211_registered_device *rdev,
7561 struct net_device *netdev, u64 cookie,
7562 struct ieee80211_channel *chan,
7563 enum nl80211_channel_type channel_type,
7564 unsigned int duration, gfp_t gfp)
7565{
7566 struct sk_buff *msg;
7567 void *hdr;
7568
7569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7570 if (!msg)
7571 return;
7572
7573 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7574 if (!hdr) {
7575 nlmsg_free(msg);
7576 return;
7577 }
7578
7579 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7580 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7581 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7582 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7583 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7584
7585 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7586 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7587
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007588 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007589
7590 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7591 nl80211_mlme_mcgrp.id, gfp);
7592 return;
7593
7594 nla_put_failure:
7595 genlmsg_cancel(msg, hdr);
7596 nlmsg_free(msg);
7597}
7598
7599void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7600 struct net_device *netdev, u64 cookie,
7601 struct ieee80211_channel *chan,
7602 enum nl80211_channel_type channel_type,
7603 unsigned int duration, gfp_t gfp)
7604{
7605 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7606 rdev, netdev, cookie, chan,
7607 channel_type, duration, gfp);
7608}
7609
7610void nl80211_send_remain_on_channel_cancel(
7611 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7612 u64 cookie, struct ieee80211_channel *chan,
7613 enum nl80211_channel_type channel_type, gfp_t gfp)
7614{
7615 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7616 rdev, netdev, cookie, chan,
7617 channel_type, 0, gfp);
7618}
7619
Johannes Berg98b62182009-12-23 13:15:44 +01007620void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7621 struct net_device *dev, const u8 *mac_addr,
7622 struct station_info *sinfo, gfp_t gfp)
7623{
7624 struct sk_buff *msg;
7625
7626 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7627 if (!msg)
7628 return;
7629
John W. Linville66266b32012-03-15 13:25:41 -04007630 if (nl80211_send_station(msg, 0, 0, 0,
7631 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007632 nlmsg_free(msg);
7633 return;
7634 }
7635
7636 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7637 nl80211_mlme_mcgrp.id, gfp);
7638}
7639
Jouni Malinenec15e682011-03-23 15:29:52 +02007640void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7641 struct net_device *dev, const u8 *mac_addr,
7642 gfp_t gfp)
7643{
7644 struct sk_buff *msg;
7645 void *hdr;
7646
7647 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7648 if (!msg)
7649 return;
7650
7651 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7652 if (!hdr) {
7653 nlmsg_free(msg);
7654 return;
7655 }
7656
7657 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7658 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7659
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007660 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007661
7662 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7663 nl80211_mlme_mcgrp.id, gfp);
7664 return;
7665
7666 nla_put_failure:
7667 genlmsg_cancel(msg, hdr);
7668 nlmsg_free(msg);
7669}
7670
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007671static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
7672 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01007673{
7674 struct wireless_dev *wdev = dev->ieee80211_ptr;
7675 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7676 struct sk_buff *msg;
7677 void *hdr;
7678 int err;
7679 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7680
7681 if (!nlpid)
7682 return false;
7683
7684 msg = nlmsg_new(100, gfp);
7685 if (!msg)
7686 return true;
7687
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007688 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01007689 if (!hdr) {
7690 nlmsg_free(msg);
7691 return true;
7692 }
7693
7694 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7695 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7696 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7697
7698 err = genlmsg_end(msg, hdr);
7699 if (err < 0) {
7700 nlmsg_free(msg);
7701 return true;
7702 }
7703
7704 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7705 return true;
7706
7707 nla_put_failure:
7708 genlmsg_cancel(msg, hdr);
7709 nlmsg_free(msg);
7710 return true;
7711}
7712
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007713bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7714{
7715 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
7716 addr, gfp);
7717}
7718
7719bool nl80211_unexpected_4addr_frame(struct net_device *dev,
7720 const u8 *addr, gfp_t gfp)
7721{
7722 return __nl80211_unexpected_frame(dev,
7723 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
7724 addr, gfp);
7725}
7726
Johannes Berg2e161f72010-08-12 15:38:38 +02007727int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7728 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01007729 int freq, int sig_dbm,
7730 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007731{
7732 struct sk_buff *msg;
7733 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02007734
7735 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7736 if (!msg)
7737 return -ENOMEM;
7738
Johannes Berg2e161f72010-08-12 15:38:38 +02007739 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007740 if (!hdr) {
7741 nlmsg_free(msg);
7742 return -ENOMEM;
7743 }
7744
7745 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7746 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7747 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
Johannes Berg804483e2012-03-05 22:18:41 +01007748 if (sig_dbm)
7749 NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
Jouni Malinen026331c2010-02-15 12:53:10 +02007750 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7751
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007752 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007753
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007754 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007755
7756 nla_put_failure:
7757 genlmsg_cancel(msg, hdr);
7758 nlmsg_free(msg);
7759 return -ENOBUFS;
7760}
7761
Johannes Berg2e161f72010-08-12 15:38:38 +02007762void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7763 struct net_device *netdev, u64 cookie,
7764 const u8 *buf, size_t len, bool ack,
7765 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007766{
7767 struct sk_buff *msg;
7768 void *hdr;
7769
7770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7771 if (!msg)
7772 return;
7773
Johannes Berg2e161f72010-08-12 15:38:38 +02007774 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02007775 if (!hdr) {
7776 nlmsg_free(msg);
7777 return;
7778 }
7779
7780 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7781 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7782 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7783 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7784 if (ack)
7785 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7786
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007787 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007788
7789 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7790 return;
7791
7792 nla_put_failure:
7793 genlmsg_cancel(msg, hdr);
7794 nlmsg_free(msg);
7795}
7796
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007797void
7798nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7799 struct net_device *netdev,
7800 enum nl80211_cqm_rssi_threshold_event rssi_event,
7801 gfp_t gfp)
7802{
7803 struct sk_buff *msg;
7804 struct nlattr *pinfoattr;
7805 void *hdr;
7806
7807 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7808 if (!msg)
7809 return;
7810
7811 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7812 if (!hdr) {
7813 nlmsg_free(msg);
7814 return;
7815 }
7816
7817 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7818 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7819
7820 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7821 if (!pinfoattr)
7822 goto nla_put_failure;
7823
7824 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7825 rssi_event);
7826
7827 nla_nest_end(msg, pinfoattr);
7828
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007829 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007830
7831 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7832 nl80211_mlme_mcgrp.id, gfp);
7833 return;
7834
7835 nla_put_failure:
7836 genlmsg_cancel(msg, hdr);
7837 nlmsg_free(msg);
7838}
7839
Johannes Berge5497d72011-07-05 16:35:40 +02007840void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7841 struct net_device *netdev, const u8 *bssid,
7842 const u8 *replay_ctr, gfp_t gfp)
7843{
7844 struct sk_buff *msg;
7845 struct nlattr *rekey_attr;
7846 void *hdr;
7847
7848 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7849 if (!msg)
7850 return;
7851
7852 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7853 if (!hdr) {
7854 nlmsg_free(msg);
7855 return;
7856 }
7857
7858 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7859 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7860 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7861
7862 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7863 if (!rekey_attr)
7864 goto nla_put_failure;
7865
7866 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7867 NL80211_REPLAY_CTR_LEN, replay_ctr);
7868
7869 nla_nest_end(msg, rekey_attr);
7870
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007871 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02007872
7873 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7874 nl80211_mlme_mcgrp.id, gfp);
7875 return;
7876
7877 nla_put_failure:
7878 genlmsg_cancel(msg, hdr);
7879 nlmsg_free(msg);
7880}
7881
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007882void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7883 struct net_device *netdev, int index,
7884 const u8 *bssid, bool preauth, gfp_t gfp)
7885{
7886 struct sk_buff *msg;
7887 struct nlattr *attr;
7888 void *hdr;
7889
7890 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7891 if (!msg)
7892 return;
7893
7894 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7895 if (!hdr) {
7896 nlmsg_free(msg);
7897 return;
7898 }
7899
7900 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7901 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7902
7903 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7904 if (!attr)
7905 goto nla_put_failure;
7906
7907 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7908 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7909 if (preauth)
7910 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7911
7912 nla_nest_end(msg, attr);
7913
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007914 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007915
7916 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7917 nl80211_mlme_mcgrp.id, gfp);
7918 return;
7919
7920 nla_put_failure:
7921 genlmsg_cancel(msg, hdr);
7922 nlmsg_free(msg);
7923}
7924
Thomas Pedersen53145262012-04-06 13:35:47 -07007925void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
7926 struct net_device *netdev, int freq,
7927 enum nl80211_channel_type type, gfp_t gfp)
7928{
7929 struct sk_buff *msg;
7930 void *hdr;
7931
7932 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7933 if (!msg)
7934 return;
7935
7936 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
7937 if (!hdr) {
7938 nlmsg_free(msg);
7939 return;
7940 }
7941
7942 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7943 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7944 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type);
7945
7946 genlmsg_end(msg, hdr);
7947
7948 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7949 nl80211_mlme_mcgrp.id, gfp);
7950 return;
7951
7952 nla_put_failure:
7953 genlmsg_cancel(msg, hdr);
7954 nlmsg_free(msg);
7955}
7956
Johannes Bergc063dbf2010-11-24 08:10:05 +01007957void
7958nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7959 struct net_device *netdev, const u8 *peer,
7960 u32 num_packets, gfp_t gfp)
7961{
7962 struct sk_buff *msg;
7963 struct nlattr *pinfoattr;
7964 void *hdr;
7965
7966 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7967 if (!msg)
7968 return;
7969
7970 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7971 if (!hdr) {
7972 nlmsg_free(msg);
7973 return;
7974 }
7975
7976 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7977 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7978 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7979
7980 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7981 if (!pinfoattr)
7982 goto nla_put_failure;
7983
7984 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7985
7986 nla_nest_end(msg, pinfoattr);
7987
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007988 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01007989
7990 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7991 nl80211_mlme_mcgrp.id, gfp);
7992 return;
7993
7994 nla_put_failure:
7995 genlmsg_cancel(msg, hdr);
7996 nlmsg_free(msg);
7997}
7998
Johannes Berg7f6cf312011-11-04 11:18:15 +01007999void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8000 u64 cookie, bool acked, gfp_t gfp)
8001{
8002 struct wireless_dev *wdev = dev->ieee80211_ptr;
8003 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8004 struct sk_buff *msg;
8005 void *hdr;
8006 int err;
8007
8008 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8009 if (!msg)
8010 return;
8011
8012 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8013 if (!hdr) {
8014 nlmsg_free(msg);
8015 return;
8016 }
8017
8018 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
8019 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
8020 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
8021 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
8022 if (acked)
8023 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
8024
8025 err = genlmsg_end(msg, hdr);
8026 if (err < 0) {
8027 nlmsg_free(msg);
8028 return;
8029 }
8030
8031 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8032 nl80211_mlme_mcgrp.id, gfp);
8033 return;
8034
8035 nla_put_failure:
8036 genlmsg_cancel(msg, hdr);
8037 nlmsg_free(msg);
8038}
8039EXPORT_SYMBOL(cfg80211_probe_status);
8040
Johannes Berg5e760232011-11-04 11:18:17 +01008041void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8042 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008043 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008044{
8045 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8046 struct sk_buff *msg;
8047 void *hdr;
8048 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8049
8050 if (!nlpid)
8051 return;
8052
8053 msg = nlmsg_new(len + 100, gfp);
8054 if (!msg)
8055 return;
8056
8057 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8058 if (!hdr) {
8059 nlmsg_free(msg);
8060 return;
8061 }
8062
8063 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
8064 if (freq)
8065 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
Johannes Berg804483e2012-03-05 22:18:41 +01008066 if (sig_dbm)
8067 NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
Johannes Berg5e760232011-11-04 11:18:17 +01008068 NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
8069
8070 genlmsg_end(msg, hdr);
8071
8072 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8073 return;
8074
8075 nla_put_failure:
8076 genlmsg_cancel(msg, hdr);
8077 nlmsg_free(msg);
8078}
8079EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8080
Jouni Malinen026331c2010-02-15 12:53:10 +02008081static int nl80211_netlink_notify(struct notifier_block * nb,
8082 unsigned long state,
8083 void *_notify)
8084{
8085 struct netlink_notify *notify = _notify;
8086 struct cfg80211_registered_device *rdev;
8087 struct wireless_dev *wdev;
8088
8089 if (state != NETLINK_URELEASE)
8090 return NOTIFY_DONE;
8091
8092 rcu_read_lock();
8093
Johannes Berg5e760232011-11-04 11:18:17 +01008094 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008095 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008096 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008097 if (rdev->ap_beacons_nlpid == notify->pid)
8098 rdev->ap_beacons_nlpid = 0;
8099 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008100
8101 rcu_read_unlock();
8102
8103 return NOTIFY_DONE;
8104}
8105
8106static struct notifier_block nl80211_netlink_notifier = {
8107 .notifier_call = nl80211_netlink_notify,
8108};
8109
Johannes Berg55682962007-09-20 13:09:35 -04008110/* initialisation/exit functions */
8111
8112int nl80211_init(void)
8113{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008114 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008115
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008116 err = genl_register_family_with_ops(&nl80211_fam,
8117 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008118 if (err)
8119 return err;
8120
Johannes Berg55682962007-09-20 13:09:35 -04008121 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8122 if (err)
8123 goto err_out;
8124
Johannes Berg2a519312009-02-10 21:25:55 +01008125 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8126 if (err)
8127 goto err_out;
8128
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008129 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8130 if (err)
8131 goto err_out;
8132
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008133 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8134 if (err)
8135 goto err_out;
8136
Johannes Bergaff89a92009-07-01 21:26:51 +02008137#ifdef CONFIG_NL80211_TESTMODE
8138 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8139 if (err)
8140 goto err_out;
8141#endif
8142
Jouni Malinen026331c2010-02-15 12:53:10 +02008143 err = netlink_register_notifier(&nl80211_netlink_notifier);
8144 if (err)
8145 goto err_out;
8146
Johannes Berg55682962007-09-20 13:09:35 -04008147 return 0;
8148 err_out:
8149 genl_unregister_family(&nl80211_fam);
8150 return err;
8151}
8152
8153void nl80211_exit(void)
8154{
Jouni Malinen026331c2010-02-15 12:53:10 +02008155 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008156 genl_unregister_family(&nl80211_fam);
8157}