blob: 50482e129263f746891211d2d4ff5540d7e8979c [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 Berg463d0182009-07-14 00:33:35 +020050static int get_rdev_dev_by_info_ifindex(struct genl_info *info,
Johannes Berg79c97e92009-07-07 03:56:12 +020051 struct cfg80211_registered_device **rdev,
Johannes Berg55682962007-09-20 13:09:35 -040052 struct net_device **dev)
53{
Johannes Berg463d0182009-07-14 00:33:35 +020054 struct nlattr **attrs = info->attrs;
Johannes Berg55682962007-09-20 13:09:35 -040055 int ifindex;
56
Johannes Bergbba95fe2008-07-29 13:22:51 +020057 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040058 return -EINVAL;
59
Johannes Bergbba95fe2008-07-29 13:22:51 +020060 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg463d0182009-07-14 00:33:35 +020061 *dev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040062 if (!*dev)
63 return -ENODEV;
64
Johannes Berg463d0182009-07-14 00:33:35 +020065 *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020066 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040067 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020068 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040069 }
70
71 return 0;
72}
73
74/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000075static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -040076 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
77 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -070078 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +020079 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020080 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053081 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020082 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
83 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
84 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
85 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +010086 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -040087
88 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
89 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
90 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010091
92 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg3e5d7642009-07-07 14:37:26 +020093 [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +010094
Johannes Bergb9454e82009-07-08 13:29:08 +020095 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +010096 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
97 .len = WLAN_MAX_KEY_LEN },
98 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
99 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
100 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200101 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200102 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100103
104 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
105 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
106 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
107 .len = IEEE80211_MAX_DATA_LEN },
108 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
109 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100110 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
111 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
112 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
113 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
114 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100115 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100116 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200117 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100118 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
119 .len = IEEE80211_MAX_MESH_ID_LEN },
120 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300121
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700122 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
123 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
124
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300125 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
126 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
127 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200128 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
129 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100130 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300131
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800132 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700133 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700134
Johannes Berg6c739412011-11-03 09:27:01 +0100135 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200136
137 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
138 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
139 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100140 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
141 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200142
143 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
144 .len = IEEE80211_MAX_SSID_LEN },
145 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
146 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200147 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300148 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300149 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300150 [NL80211_ATTR_STA_FLAGS2] = {
151 .len = sizeof(struct nl80211_sta_flag_update),
152 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300153 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300154 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
155 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200156 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
157 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
158 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200159 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100160 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100161 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
162 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100163 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
164 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200165 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200166 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
167 .len = IEEE80211_MAX_DATA_LEN },
168 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200169 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200170 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300171 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200172 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300173 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
174 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200175 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900176 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
177 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100178 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100179 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100180 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200181 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700182 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300183 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200184 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200185 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300186 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300187 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
188 .len = IEEE80211_MAX_DATA_LEN },
189 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
190 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530191 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300192 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530193 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300194 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
195 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
196 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
197 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
198 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100199 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200200 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
201 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700202 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400203};
204
Johannes Berge31b8212010-10-05 19:39:30 +0200205/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000206static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200207 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200208 [NL80211_KEY_IDX] = { .type = NLA_U8 },
209 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200210 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200211 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
212 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200213 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100214 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
215};
216
217/* policy for the key default flags */
218static const struct nla_policy
219nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
220 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
221 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200222};
223
Johannes Bergff1b6e62011-05-04 15:37:28 +0200224/* policy for WoWLAN attributes */
225static const struct nla_policy
226nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
227 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
228 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
229 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
230 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200231 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
232 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
233 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
234 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200235};
236
Johannes Berge5497d72011-07-05 16:35:40 +0200237/* policy for GTK rekey offload attributes */
238static const struct nla_policy
239nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
240 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
241 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
242 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
243};
244
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300245static const struct nla_policy
246nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
247 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_SSID_LEN },
249};
250
Holger Schuriga0438972009-11-11 11:30:02 +0100251/* ifidx get helper */
252static int nl80211_get_ifidx(struct netlink_callback *cb)
253{
254 int res;
255
256 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
257 nl80211_fam.attrbuf, nl80211_fam.maxattr,
258 nl80211_policy);
259 if (res)
260 return res;
261
262 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
263 return -EINVAL;
264
265 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
266 if (!res)
267 return -EINVAL;
268 return res;
269}
270
Johannes Berg67748892010-10-04 21:14:06 +0200271static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
272 struct netlink_callback *cb,
273 struct cfg80211_registered_device **rdev,
274 struct net_device **dev)
275{
276 int ifidx = cb->args[0];
277 int err;
278
279 if (!ifidx)
280 ifidx = nl80211_get_ifidx(cb);
281 if (ifidx < 0)
282 return ifidx;
283
284 cb->args[0] = ifidx;
285
286 rtnl_lock();
287
288 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
289 if (!*dev) {
290 err = -ENODEV;
291 goto out_rtnl;
292 }
293
294 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100295 if (IS_ERR(*rdev)) {
296 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200297 goto out_rtnl;
298 }
299
300 return 0;
301 out_rtnl:
302 rtnl_unlock();
303 return err;
304}
305
306static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
307{
308 cfg80211_unlock_rdev(rdev);
309 rtnl_unlock();
310}
311
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100312/* IE validation */
313static bool is_valid_ie_attr(const struct nlattr *attr)
314{
315 const u8 *pos;
316 int len;
317
318 if (!attr)
319 return true;
320
321 pos = nla_data(attr);
322 len = nla_len(attr);
323
324 while (len) {
325 u8 elemlen;
326
327 if (len < 2)
328 return false;
329 len -= 2;
330
331 elemlen = pos[1];
332 if (elemlen > len)
333 return false;
334
335 len -= elemlen;
336 pos += 2 + elemlen;
337 }
338
339 return true;
340}
341
Johannes Berg55682962007-09-20 13:09:35 -0400342/* message building helper */
343static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
344 int flags, u8 cmd)
345{
346 /* since there is no private header just add the generic one */
347 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
348}
349
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400350static int nl80211_msg_put_channel(struct sk_buff *msg,
351 struct ieee80211_channel *chan)
352{
353 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
354 chan->center_freq);
355
356 if (chan->flags & IEEE80211_CHAN_DISABLED)
357 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
358 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
359 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
360 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
361 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
362 if (chan->flags & IEEE80211_CHAN_RADAR)
363 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
364
365 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
366 DBM_TO_MBM(chan->max_power));
367
368 return 0;
369
370 nla_put_failure:
371 return -ENOBUFS;
372}
373
Johannes Berg55682962007-09-20 13:09:35 -0400374/* netlink command implementations */
375
Johannes Bergb9454e82009-07-08 13:29:08 +0200376struct key_parse {
377 struct key_params p;
378 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200379 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200380 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100381 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200382};
383
384static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
385{
386 struct nlattr *tb[NL80211_KEY_MAX + 1];
387 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
388 nl80211_key_policy);
389 if (err)
390 return err;
391
392 k->def = !!tb[NL80211_KEY_DEFAULT];
393 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
394
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100395 if (k->def) {
396 k->def_uni = true;
397 k->def_multi = true;
398 }
399 if (k->defmgmt)
400 k->def_multi = true;
401
Johannes Bergb9454e82009-07-08 13:29:08 +0200402 if (tb[NL80211_KEY_IDX])
403 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
404
405 if (tb[NL80211_KEY_DATA]) {
406 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
407 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
408 }
409
410 if (tb[NL80211_KEY_SEQ]) {
411 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
412 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
413 }
414
415 if (tb[NL80211_KEY_CIPHER])
416 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
417
Johannes Berge31b8212010-10-05 19:39:30 +0200418 if (tb[NL80211_KEY_TYPE]) {
419 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
420 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
421 return -EINVAL;
422 }
423
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100424 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
425 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
426 int err = nla_parse_nested(kdt,
427 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
428 tb[NL80211_KEY_DEFAULT_TYPES],
429 nl80211_key_default_policy);
430 if (err)
431 return err;
432
433 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
434 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
435 }
436
Johannes Bergb9454e82009-07-08 13:29:08 +0200437 return 0;
438}
439
440static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
441{
442 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
443 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
444 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
445 }
446
447 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
448 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
449 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
450 }
451
452 if (info->attrs[NL80211_ATTR_KEY_IDX])
453 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
454
455 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
456 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
457
458 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
459 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
460
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100461 if (k->def) {
462 k->def_uni = true;
463 k->def_multi = true;
464 }
465 if (k->defmgmt)
466 k->def_multi = true;
467
Johannes Berge31b8212010-10-05 19:39:30 +0200468 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
469 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
470 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
471 return -EINVAL;
472 }
473
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100474 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
475 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
476 int err = nla_parse_nested(
477 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
478 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
479 nl80211_key_default_policy);
480 if (err)
481 return err;
482
483 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
484 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
485 }
486
Johannes Bergb9454e82009-07-08 13:29:08 +0200487 return 0;
488}
489
490static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
491{
492 int err;
493
494 memset(k, 0, sizeof(*k));
495 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200496 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200497
498 if (info->attrs[NL80211_ATTR_KEY])
499 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
500 else
501 err = nl80211_parse_key_old(info, k);
502
503 if (err)
504 return err;
505
506 if (k->def && k->defmgmt)
507 return -EINVAL;
508
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100509 if (k->defmgmt) {
510 if (k->def_uni || !k->def_multi)
511 return -EINVAL;
512 }
513
Johannes Bergb9454e82009-07-08 13:29:08 +0200514 if (k->idx != -1) {
515 if (k->defmgmt) {
516 if (k->idx < 4 || k->idx > 5)
517 return -EINVAL;
518 } else if (k->def) {
519 if (k->idx < 0 || k->idx > 3)
520 return -EINVAL;
521 } else {
522 if (k->idx < 0 || k->idx > 5)
523 return -EINVAL;
524 }
525 }
526
527 return 0;
528}
529
Johannes Bergfffd0932009-07-08 14:22:54 +0200530static struct cfg80211_cached_keys *
531nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
532 struct nlattr *keys)
533{
534 struct key_parse parse;
535 struct nlattr *key;
536 struct cfg80211_cached_keys *result;
537 int rem, err, def = 0;
538
539 result = kzalloc(sizeof(*result), GFP_KERNEL);
540 if (!result)
541 return ERR_PTR(-ENOMEM);
542
543 result->def = -1;
544 result->defmgmt = -1;
545
546 nla_for_each_nested(key, keys, rem) {
547 memset(&parse, 0, sizeof(parse));
548 parse.idx = -1;
549
550 err = nl80211_parse_key_new(key, &parse);
551 if (err)
552 goto error;
553 err = -EINVAL;
554 if (!parse.p.key)
555 goto error;
556 if (parse.idx < 0 || parse.idx > 4)
557 goto error;
558 if (parse.def) {
559 if (def)
560 goto error;
561 def = 1;
562 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100563 if (!parse.def_uni || !parse.def_multi)
564 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200565 } else if (parse.defmgmt)
566 goto error;
567 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200568 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200569 if (err)
570 goto error;
571 result->params[parse.idx].cipher = parse.p.cipher;
572 result->params[parse.idx].key_len = parse.p.key_len;
573 result->params[parse.idx].key = result->data[parse.idx];
574 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
575 }
576
577 return result;
578 error:
579 kfree(result);
580 return ERR_PTR(err);
581}
582
583static int nl80211_key_allowed(struct wireless_dev *wdev)
584{
585 ASSERT_WDEV_LOCK(wdev);
586
Johannes Bergfffd0932009-07-08 14:22:54 +0200587 switch (wdev->iftype) {
588 case NL80211_IFTYPE_AP:
589 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200590 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700591 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200592 break;
593 case NL80211_IFTYPE_ADHOC:
594 if (!wdev->current_bss)
595 return -ENOLINK;
596 break;
597 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200598 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200599 if (wdev->sme_state != CFG80211_SME_CONNECTED)
600 return -ENOLINK;
601 break;
602 default:
603 return -EINVAL;
604 }
605
606 return 0;
607}
608
Johannes Berg7527a782011-05-13 10:58:57 +0200609static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
610{
611 struct nlattr *nl_modes = nla_nest_start(msg, attr);
612 int i;
613
614 if (!nl_modes)
615 goto nla_put_failure;
616
617 i = 0;
618 while (ifmodes) {
619 if (ifmodes & 1)
620 NLA_PUT_FLAG(msg, i);
621 ifmodes >>= 1;
622 i++;
623 }
624
625 nla_nest_end(msg, nl_modes);
626 return 0;
627
628nla_put_failure:
629 return -ENOBUFS;
630}
631
632static int nl80211_put_iface_combinations(struct wiphy *wiphy,
633 struct sk_buff *msg)
634{
635 struct nlattr *nl_combis;
636 int i, j;
637
638 nl_combis = nla_nest_start(msg,
639 NL80211_ATTR_INTERFACE_COMBINATIONS);
640 if (!nl_combis)
641 goto nla_put_failure;
642
643 for (i = 0; i < wiphy->n_iface_combinations; i++) {
644 const struct ieee80211_iface_combination *c;
645 struct nlattr *nl_combi, *nl_limits;
646
647 c = &wiphy->iface_combinations[i];
648
649 nl_combi = nla_nest_start(msg, i + 1);
650 if (!nl_combi)
651 goto nla_put_failure;
652
653 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
654 if (!nl_limits)
655 goto nla_put_failure;
656
657 for (j = 0; j < c->n_limits; j++) {
658 struct nlattr *nl_limit;
659
660 nl_limit = nla_nest_start(msg, j + 1);
661 if (!nl_limit)
662 goto nla_put_failure;
663 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
664 c->limits[j].max);
665 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
666 c->limits[j].types))
667 goto nla_put_failure;
668 nla_nest_end(msg, nl_limit);
669 }
670
671 nla_nest_end(msg, nl_limits);
672
673 if (c->beacon_int_infra_match)
674 NLA_PUT_FLAG(msg,
675 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
676 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
677 c->num_different_channels);
678 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
679 c->max_interfaces);
680
681 nla_nest_end(msg, nl_combi);
682 }
683
684 nla_nest_end(msg, nl_combis);
685
686 return 0;
687nla_put_failure:
688 return -ENOBUFS;
689}
690
Johannes Berg55682962007-09-20 13:09:35 -0400691static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
692 struct cfg80211_registered_device *dev)
693{
694 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100695 struct nlattr *nl_bands, *nl_band;
696 struct nlattr *nl_freqs, *nl_freq;
697 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100698 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100699 enum ieee80211_band band;
700 struct ieee80211_channel *chan;
701 struct ieee80211_rate *rate;
702 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200703 const struct ieee80211_txrx_stypes *mgmt_stypes =
704 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400705
706 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
707 if (!hdr)
708 return -1;
709
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500710 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400711 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200712
Johannes Bergf5ea9122009-08-07 16:17:38 +0200713 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
714 cfg80211_rdev_list_generation);
715
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200716 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
717 dev->wiphy.retry_short);
718 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
719 dev->wiphy.retry_long);
720 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
721 dev->wiphy.frag_threshold);
722 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
723 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100724 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
725 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100726 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
727 dev->wiphy.max_scan_ssids);
Luciano Coelho93b6aa62011-07-13 14:57:28 +0300728 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
729 dev->wiphy.max_sched_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200730 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
731 dev->wiphy.max_scan_ie_len);
Luciano Coelho5a865ba2011-07-13 14:57:29 +0300732 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
733 dev->wiphy.max_sched_scan_ie_len);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300734 NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
735 dev->wiphy.max_match_sets);
Johannes Bergee688b002008-01-24 19:38:39 +0100736
Johannes Berge31b8212010-10-05 19:39:30 +0200737 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
738 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
Javier Cardona15d5dda2011-04-07 15:08:28 -0700739 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
740 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
Eliad Pellercedb5412011-08-31 11:29:43 +0300741 if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
742 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530743 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
744 NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300745 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
746 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
747 if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
748 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530749
Johannes Berg25e47c12009-04-02 20:14:06 +0200750 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
751 sizeof(u32) * dev->wiphy.n_cipher_suites,
752 dev->wiphy.cipher_suites);
753
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100754 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
755 dev->wiphy.max_num_pmkids);
756
Johannes Bergc0692b82010-08-27 14:26:53 +0300757 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
758 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
759
Bruno Randolf39fd5de2010-12-16 11:30:28 +0900760 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
761 dev->wiphy.available_antennas_tx);
762 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
763 dev->wiphy.available_antennas_rx);
764
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200765 if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD)
766 NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
767 dev->wiphy.probe_resp_offload);
768
Bruno Randolf7f531e02010-12-16 11:30:22 +0900769 if ((dev->wiphy.available_antennas_tx ||
770 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900771 u32 tx_ant = 0, rx_ant = 0;
772 int res;
773 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
774 if (!res) {
775 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
776 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
777 }
778 }
779
Johannes Berg7527a782011-05-13 10:58:57 +0200780 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
781 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700782 goto nla_put_failure;
783
Johannes Bergee688b002008-01-24 19:38:39 +0100784 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
785 if (!nl_bands)
786 goto nla_put_failure;
787
788 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
789 if (!dev->wiphy.bands[band])
790 continue;
791
792 nl_band = nla_nest_start(msg, band);
793 if (!nl_band)
794 goto nla_put_failure;
795
Johannes Bergd51626d2008-10-09 12:20:13 +0200796 /* add HT info */
797 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
798 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
799 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
800 &dev->wiphy.bands[band]->ht_cap.mcs);
801 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
802 dev->wiphy.bands[band]->ht_cap.cap);
803 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
804 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
805 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
806 dev->wiphy.bands[band]->ht_cap.ampdu_density);
807 }
808
Johannes Bergee688b002008-01-24 19:38:39 +0100809 /* add frequencies */
810 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
811 if (!nl_freqs)
812 goto nla_put_failure;
813
814 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
815 nl_freq = nla_nest_start(msg, i);
816 if (!nl_freq)
817 goto nla_put_failure;
818
819 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100820
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400821 if (nl80211_msg_put_channel(msg, chan))
822 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200823
Johannes Bergee688b002008-01-24 19:38:39 +0100824 nla_nest_end(msg, nl_freq);
825 }
826
827 nla_nest_end(msg, nl_freqs);
828
829 /* add bitrates */
830 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
831 if (!nl_rates)
832 goto nla_put_failure;
833
834 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
835 nl_rate = nla_nest_start(msg, i);
836 if (!nl_rate)
837 goto nla_put_failure;
838
839 rate = &dev->wiphy.bands[band]->bitrates[i];
840 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
841 rate->bitrate);
842 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
843 NLA_PUT_FLAG(msg,
844 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
845
846 nla_nest_end(msg, nl_rate);
847 }
848
849 nla_nest_end(msg, nl_rates);
850
851 nla_nest_end(msg, nl_band);
852 }
853 nla_nest_end(msg, nl_bands);
854
Johannes Berg8fdc6212009-03-14 09:34:01 +0100855 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
856 if (!nl_cmds)
857 goto nla_put_failure;
858
859 i = 0;
860#define CMD(op, n) \
861 do { \
862 if (dev->ops->op) { \
863 i++; \
864 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
865 } \
866 } while (0)
867
868 CMD(add_virtual_intf, NEW_INTERFACE);
869 CMD(change_virtual_intf, SET_INTERFACE);
870 CMD(add_key, NEW_KEY);
871 CMD(add_beacon, NEW_BEACON);
872 CMD(add_station, NEW_STATION);
873 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800874 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100875 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200876 CMD(auth, AUTHENTICATE);
877 CMD(assoc, ASSOCIATE);
878 CMD(deauth, DEAUTHENTICATE);
879 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200880 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100881 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100882 CMD(set_pmksa, SET_PMKSA);
883 CMD(del_pmksa, DEL_PMKSA);
884 CMD(flush_pmksa, FLUSH_PMKSA);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100885 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200886 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200887 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100888 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100889 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200890 i++;
891 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
892 }
Johannes Bergf444de02010-05-05 15:25:02 +0200893 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400894 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300895 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
896 CMD(tdls_mgmt, TDLS_MGMT);
897 CMD(tdls_oper, TDLS_OPER);
898 }
Luciano Coelho807f8a82011-05-11 17:09:35 +0300899 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
900 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +0100901 CMD(probe_client, PROBE_CLIENT);
Johannes Berg5e760232011-11-04 11:18:17 +0100902 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
903 i++;
904 NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS);
905 }
Johannes Berg8fdc6212009-03-14 09:34:01 +0100906
907#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200908
Johannes Berg6829c872009-07-02 09:13:27 +0200909 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200910 i++;
911 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
912 }
913
Johannes Berg6829c872009-07-02 09:13:27 +0200914 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200915 i++;
916 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
917 }
918
Johannes Berg8fdc6212009-03-14 09:34:01 +0100919 nla_nest_end(msg, nl_cmds);
920
Johannes Berga2939112010-12-14 17:54:28 +0100921 if (dev->ops->remain_on_channel)
922 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
923 dev->wiphy.max_remain_on_channel_duration);
924
Jouni Malinend2da5872011-08-08 12:10:30 +0300925 if (dev->ops->mgmt_tx_cancel_wait)
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100926 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
927
Johannes Berg2e161f72010-08-12 15:38:38 +0200928 if (mgmt_stypes) {
929 u16 stypes;
930 struct nlattr *nl_ftypes, *nl_ifs;
931 enum nl80211_iftype ift;
932
933 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
934 if (!nl_ifs)
935 goto nla_put_failure;
936
937 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
938 nl_ftypes = nla_nest_start(msg, ift);
939 if (!nl_ftypes)
940 goto nla_put_failure;
941 i = 0;
942 stypes = mgmt_stypes[ift].tx;
943 while (stypes) {
944 if (stypes & 1)
945 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
946 (i << 4) | IEEE80211_FTYPE_MGMT);
947 stypes >>= 1;
948 i++;
949 }
950 nla_nest_end(msg, nl_ftypes);
951 }
952
Johannes Berg74b70a42010-08-24 12:15:53 +0200953 nla_nest_end(msg, nl_ifs);
954
Johannes Berg2e161f72010-08-12 15:38:38 +0200955 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
956 if (!nl_ifs)
957 goto nla_put_failure;
958
959 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
960 nl_ftypes = nla_nest_start(msg, ift);
961 if (!nl_ftypes)
962 goto nla_put_failure;
963 i = 0;
964 stypes = mgmt_stypes[ift].rx;
965 while (stypes) {
966 if (stypes & 1)
967 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
968 (i << 4) | IEEE80211_FTYPE_MGMT);
969 stypes >>= 1;
970 i++;
971 }
972 nla_nest_end(msg, nl_ftypes);
973 }
974 nla_nest_end(msg, nl_ifs);
975 }
976
Johannes Bergff1b6e62011-05-04 15:37:28 +0200977 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
978 struct nlattr *nl_wowlan;
979
980 nl_wowlan = nla_nest_start(msg,
981 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
982 if (!nl_wowlan)
983 goto nla_put_failure;
984
985 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
986 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
987 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
988 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
989 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
990 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +0200991 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
992 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
993 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
994 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
995 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
996 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
997 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
998 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
999 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
1000 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02001001 if (dev->wiphy.wowlan.n_patterns) {
1002 struct nl80211_wowlan_pattern_support pat = {
1003 .max_patterns = dev->wiphy.wowlan.n_patterns,
1004 .min_pattern_len =
1005 dev->wiphy.wowlan.pattern_min_len,
1006 .max_pattern_len =
1007 dev->wiphy.wowlan.pattern_max_len,
1008 };
1009 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1010 sizeof(pat), &pat);
1011 }
1012
1013 nla_nest_end(msg, nl_wowlan);
1014 }
1015
Johannes Berg7527a782011-05-13 10:58:57 +02001016 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1017 dev->wiphy.software_iftypes))
1018 goto nla_put_failure;
1019
1020 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1021 goto nla_put_failure;
1022
Johannes Berg562a7482011-11-07 12:39:33 +01001023 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
1024 NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
1025 dev->wiphy.ap_sme_capa);
1026
Johannes Berg1f074bd2011-11-06 14:13:33 +01001027 NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features);
1028
Johannes Berg55682962007-09-20 13:09:35 -04001029 return genlmsg_end(msg, hdr);
1030
1031 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001032 genlmsg_cancel(msg, hdr);
1033 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001034}
1035
1036static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1037{
1038 int idx = 0;
1039 int start = cb->args[0];
1040 struct cfg80211_registered_device *dev;
1041
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001042 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001043 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001044 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1045 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001046 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001047 continue;
1048 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1049 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001050 dev) < 0) {
1051 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001052 break;
Julius Volzb4637272008-07-08 14:02:19 +02001053 }
Johannes Berg55682962007-09-20 13:09:35 -04001054 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001055 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001056
1057 cb->args[0] = idx;
1058
1059 return skb->len;
1060}
1061
1062static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1063{
1064 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001065 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001066
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001067 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001068 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001069 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001070
Johannes Berg4c476992010-10-04 21:36:35 +02001071 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1072 nlmsg_free(msg);
1073 return -ENOBUFS;
1074 }
Johannes Berg55682962007-09-20 13:09:35 -04001075
Johannes Berg134e6372009-07-10 09:51:34 +00001076 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001077}
1078
Jouni Malinen31888482008-10-30 16:59:24 +02001079static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1080 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1081 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1082 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1083 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1084 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1085};
1086
1087static int parse_txq_params(struct nlattr *tb[],
1088 struct ieee80211_txq_params *txq_params)
1089{
1090 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1091 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1092 !tb[NL80211_TXQ_ATTR_AIFS])
1093 return -EINVAL;
1094
1095 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1096 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1097 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1098 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1099 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1100
1101 return 0;
1102}
1103
Johannes Bergf444de02010-05-05 15:25:02 +02001104static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1105{
1106 /*
1107 * You can only set the channel explicitly for AP, mesh
1108 * and WDS type interfaces; all others have their channel
1109 * managed via their respective "establish a connection"
1110 * command (connect, join, ...)
1111 *
1112 * Monitors are special as they are normally slaved to
1113 * whatever else is going on, so they behave as though
1114 * you tried setting the wiphy channel itself.
1115 */
1116 return !wdev ||
1117 wdev->iftype == NL80211_IFTYPE_AP ||
1118 wdev->iftype == NL80211_IFTYPE_WDS ||
1119 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001120 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1121 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001122}
1123
1124static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1125 struct wireless_dev *wdev,
1126 struct genl_info *info)
1127{
1128 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1129 u32 freq;
1130 int result;
1131
1132 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1133 return -EINVAL;
1134
1135 if (!nl80211_can_set_dev_channel(wdev))
1136 return -EOPNOTSUPP;
1137
1138 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1139 channel_type = nla_get_u32(info->attrs[
1140 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1141 if (channel_type != NL80211_CHAN_NO_HT &&
1142 channel_type != NL80211_CHAN_HT20 &&
1143 channel_type != NL80211_CHAN_HT40PLUS &&
1144 channel_type != NL80211_CHAN_HT40MINUS)
1145 return -EINVAL;
1146 }
1147
1148 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1149
1150 mutex_lock(&rdev->devlist_mtx);
1151 if (wdev) {
1152 wdev_lock(wdev);
1153 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1154 wdev_unlock(wdev);
1155 } else {
1156 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1157 }
1158 mutex_unlock(&rdev->devlist_mtx);
1159
1160 return result;
1161}
1162
1163static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1164{
Johannes Berg4c476992010-10-04 21:36:35 +02001165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1166 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001167
Johannes Berg4c476992010-10-04 21:36:35 +02001168 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001169}
1170
Bill Jordane8347eb2010-10-01 13:54:28 -04001171static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1172{
Johannes Berg43b19952010-10-07 13:10:30 +02001173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1174 struct net_device *dev = info->user_ptr[1];
1175 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001176 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001177
1178 if (!info->attrs[NL80211_ATTR_MAC])
1179 return -EINVAL;
1180
Johannes Berg43b19952010-10-07 13:10:30 +02001181 if (netif_running(dev))
1182 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001183
Johannes Berg43b19952010-10-07 13:10:30 +02001184 if (!rdev->ops->set_wds_peer)
1185 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001186
Johannes Berg43b19952010-10-07 13:10:30 +02001187 if (wdev->iftype != NL80211_IFTYPE_WDS)
1188 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001189
1190 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001191 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001192}
1193
1194
Johannes Berg55682962007-09-20 13:09:35 -04001195static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1196{
1197 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001198 struct net_device *netdev = NULL;
1199 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001200 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001201 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001202 u32 changed;
1203 u8 retry_short = 0, retry_long = 0;
1204 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001205 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001206
Johannes Bergf444de02010-05-05 15:25:02 +02001207 /*
1208 * Try to find the wiphy and netdev. Normally this
1209 * function shouldn't need the netdev, but this is
1210 * done for backward compatibility -- previously
1211 * setting the channel was done per wiphy, but now
1212 * it is per netdev. Previous userland like hostapd
1213 * also passed a netdev to set_wiphy, so that it is
1214 * possible to let that go to the right netdev!
1215 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001216 mutex_lock(&cfg80211_mutex);
1217
Johannes Bergf444de02010-05-05 15:25:02 +02001218 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1219 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1220
1221 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1222 if (netdev && netdev->ieee80211_ptr) {
1223 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1224 mutex_lock(&rdev->mtx);
1225 } else
1226 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001227 }
1228
Johannes Bergf444de02010-05-05 15:25:02 +02001229 if (!netdev) {
1230 rdev = __cfg80211_rdev_from_info(info);
1231 if (IS_ERR(rdev)) {
1232 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001233 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001234 }
1235 wdev = NULL;
1236 netdev = NULL;
1237 result = 0;
1238
1239 mutex_lock(&rdev->mtx);
1240 } else if (netif_running(netdev) &&
1241 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1242 wdev = netdev->ieee80211_ptr;
1243 else
1244 wdev = NULL;
1245
1246 /*
1247 * end workaround code, by now the rdev is available
1248 * and locked, and wdev may or may not be NULL.
1249 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001250
1251 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001252 result = cfg80211_dev_rename(
1253 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001254
1255 mutex_unlock(&cfg80211_mutex);
1256
1257 if (result)
1258 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001259
Jouni Malinen31888482008-10-30 16:59:24 +02001260 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1261 struct ieee80211_txq_params txq_params;
1262 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1263
1264 if (!rdev->ops->set_txq_params) {
1265 result = -EOPNOTSUPP;
1266 goto bad_res;
1267 }
1268
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001269 if (!netdev) {
1270 result = -EINVAL;
1271 goto bad_res;
1272 }
1273
Johannes Berg133a3ff2011-11-03 14:50:13 +01001274 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1275 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1276 result = -EINVAL;
1277 goto bad_res;
1278 }
1279
Jouni Malinen31888482008-10-30 16:59:24 +02001280 nla_for_each_nested(nl_txq_params,
1281 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1282 rem_txq_params) {
1283 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1284 nla_data(nl_txq_params),
1285 nla_len(nl_txq_params),
1286 txq_params_policy);
1287 result = parse_txq_params(tb, &txq_params);
1288 if (result)
1289 goto bad_res;
1290
1291 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001292 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001293 &txq_params);
1294 if (result)
1295 goto bad_res;
1296 }
1297 }
1298
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001299 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001300 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001301 if (result)
1302 goto bad_res;
1303 }
1304
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001305 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1306 enum nl80211_tx_power_setting type;
1307 int idx, mbm = 0;
1308
1309 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001310 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001311 goto bad_res;
1312 }
1313
1314 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1315 type = nla_get_u32(info->attrs[idx]);
1316
1317 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1318 (type != NL80211_TX_POWER_AUTOMATIC)) {
1319 result = -EINVAL;
1320 goto bad_res;
1321 }
1322
1323 if (type != NL80211_TX_POWER_AUTOMATIC) {
1324 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1325 mbm = nla_get_u32(info->attrs[idx]);
1326 }
1327
1328 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1329 if (result)
1330 goto bad_res;
1331 }
1332
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001333 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1334 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1335 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001336 if ((!rdev->wiphy.available_antennas_tx &&
1337 !rdev->wiphy.available_antennas_rx) ||
1338 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001339 result = -EOPNOTSUPP;
1340 goto bad_res;
1341 }
1342
1343 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1344 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1345
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001346 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001347 * available antenna masks, except for the "all" mask */
1348 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1349 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001350 result = -EINVAL;
1351 goto bad_res;
1352 }
1353
Bruno Randolf7f531e02010-12-16 11:30:22 +09001354 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1355 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001356
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001357 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1358 if (result)
1359 goto bad_res;
1360 }
1361
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001362 changed = 0;
1363
1364 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1365 retry_short = nla_get_u8(
1366 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1367 if (retry_short == 0) {
1368 result = -EINVAL;
1369 goto bad_res;
1370 }
1371 changed |= WIPHY_PARAM_RETRY_SHORT;
1372 }
1373
1374 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1375 retry_long = nla_get_u8(
1376 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1377 if (retry_long == 0) {
1378 result = -EINVAL;
1379 goto bad_res;
1380 }
1381 changed |= WIPHY_PARAM_RETRY_LONG;
1382 }
1383
1384 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1385 frag_threshold = nla_get_u32(
1386 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1387 if (frag_threshold < 256) {
1388 result = -EINVAL;
1389 goto bad_res;
1390 }
1391 if (frag_threshold != (u32) -1) {
1392 /*
1393 * Fragments (apart from the last one) are required to
1394 * have even length. Make the fragmentation code
1395 * simpler by stripping LSB should someone try to use
1396 * odd threshold value.
1397 */
1398 frag_threshold &= ~0x1;
1399 }
1400 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1401 }
1402
1403 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1404 rts_threshold = nla_get_u32(
1405 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1406 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1407 }
1408
Lukáš Turek81077e82009-12-21 22:50:47 +01001409 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1410 coverage_class = nla_get_u8(
1411 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1412 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1413 }
1414
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001415 if (changed) {
1416 u8 old_retry_short, old_retry_long;
1417 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001418 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001419
1420 if (!rdev->ops->set_wiphy_params) {
1421 result = -EOPNOTSUPP;
1422 goto bad_res;
1423 }
1424
1425 old_retry_short = rdev->wiphy.retry_short;
1426 old_retry_long = rdev->wiphy.retry_long;
1427 old_frag_threshold = rdev->wiphy.frag_threshold;
1428 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001429 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001430
1431 if (changed & WIPHY_PARAM_RETRY_SHORT)
1432 rdev->wiphy.retry_short = retry_short;
1433 if (changed & WIPHY_PARAM_RETRY_LONG)
1434 rdev->wiphy.retry_long = retry_long;
1435 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1436 rdev->wiphy.frag_threshold = frag_threshold;
1437 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1438 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001439 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1440 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001441
1442 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1443 if (result) {
1444 rdev->wiphy.retry_short = old_retry_short;
1445 rdev->wiphy.retry_long = old_retry_long;
1446 rdev->wiphy.frag_threshold = old_frag_threshold;
1447 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001448 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001449 }
1450 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001451
Johannes Berg306d6112008-12-08 12:39:04 +01001452 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001453 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001454 if (netdev)
1455 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001456 return result;
1457}
1458
1459
1460static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001461 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001462 struct net_device *dev)
1463{
1464 void *hdr;
1465
1466 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1467 if (!hdr)
1468 return -1;
1469
1470 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001471 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001472 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001473 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001474
1475 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1476 rdev->devlist_generation ^
1477 (cfg80211_rdev_list_generation << 2));
1478
Johannes Berg55682962007-09-20 13:09:35 -04001479 return genlmsg_end(msg, hdr);
1480
1481 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001482 genlmsg_cancel(msg, hdr);
1483 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001484}
1485
1486static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1487{
1488 int wp_idx = 0;
1489 int if_idx = 0;
1490 int wp_start = cb->args[0];
1491 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001492 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001493 struct wireless_dev *wdev;
1494
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001495 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001496 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1497 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001498 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001499 if (wp_idx < wp_start) {
1500 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001501 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001502 }
Johannes Berg55682962007-09-20 13:09:35 -04001503 if_idx = 0;
1504
Johannes Bergf5ea9122009-08-07 16:17:38 +02001505 mutex_lock(&rdev->devlist_mtx);
1506 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001507 if (if_idx < if_start) {
1508 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001509 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001510 }
Johannes Berg55682962007-09-20 13:09:35 -04001511 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1512 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001513 rdev, wdev->netdev) < 0) {
1514 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001515 goto out;
1516 }
1517 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001518 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001519 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001520
1521 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001522 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001523 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001524 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001525
1526 cb->args[0] = wp_idx;
1527 cb->args[1] = if_idx;
1528
1529 return skb->len;
1530}
1531
1532static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1533{
1534 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001535 struct cfg80211_registered_device *dev = info->user_ptr[0];
1536 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001537
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001538 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001539 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001540 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001541
Johannes Bergd7264052009-04-19 16:23:20 +02001542 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001543 dev, netdev) < 0) {
1544 nlmsg_free(msg);
1545 return -ENOBUFS;
1546 }
Johannes Berg55682962007-09-20 13:09:35 -04001547
Johannes Berg134e6372009-07-10 09:51:34 +00001548 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001549}
1550
Michael Wu66f7ac52008-01-31 19:48:22 +01001551static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1552 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1553 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1554 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1555 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1556 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1557};
1558
1559static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1560{
1561 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1562 int flag;
1563
1564 *mntrflags = 0;
1565
1566 if (!nla)
1567 return -EINVAL;
1568
1569 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1570 nla, mntr_flags_policy))
1571 return -EINVAL;
1572
1573 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1574 if (flags[flag])
1575 *mntrflags |= (1<<flag);
1576
1577 return 0;
1578}
1579
Johannes Berg9bc383d2009-11-19 11:55:19 +01001580static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001581 struct net_device *netdev, u8 use_4addr,
1582 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001583{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001584 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001585 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001586 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001587 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001588 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001589
1590 switch (iftype) {
1591 case NL80211_IFTYPE_AP_VLAN:
1592 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1593 return 0;
1594 break;
1595 case NL80211_IFTYPE_STATION:
1596 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1597 return 0;
1598 break;
1599 default:
1600 break;
1601 }
1602
1603 return -EOPNOTSUPP;
1604}
1605
Johannes Berg55682962007-09-20 13:09:35 -04001606static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1607{
Johannes Berg4c476992010-10-04 21:36:35 +02001608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001609 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001610 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001611 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001612 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001613 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001614 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001615
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001616 memset(&params, 0, sizeof(params));
1617
Johannes Berg04a773a2009-04-19 21:24:32 +02001618 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001619
Johannes Berg723b0382008-09-16 20:22:09 +02001620 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001621 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001622 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001623 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001624 if (ntype > NL80211_IFTYPE_MAX)
1625 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001626 }
1627
Johannes Berg92ffe052008-09-16 20:39:36 +02001628 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001629 struct wireless_dev *wdev = dev->ieee80211_ptr;
1630
Johannes Berg4c476992010-10-04 21:36:35 +02001631 if (ntype != NL80211_IFTYPE_MESH_POINT)
1632 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001633 if (netif_running(dev))
1634 return -EBUSY;
1635
1636 wdev_lock(wdev);
1637 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1638 IEEE80211_MAX_MESH_ID_LEN);
1639 wdev->mesh_id_up_len =
1640 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1641 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1642 wdev->mesh_id_up_len);
1643 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001644 }
1645
Felix Fietkau8b787642009-11-10 18:53:10 +01001646 if (info->attrs[NL80211_ATTR_4ADDR]) {
1647 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1648 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001649 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001650 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001651 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001652 } else {
1653 params.use_4addr = -1;
1654 }
1655
Johannes Berg92ffe052008-09-16 20:39:36 +02001656 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001657 if (ntype != NL80211_IFTYPE_MONITOR)
1658 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001659 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1660 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001661 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001662 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001663
1664 flags = &_flags;
1665 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001666 }
Johannes Berg3b858752009-03-12 09:55:09 +01001667
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001668 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001669 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001670 else
1671 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001672
Johannes Berg9bc383d2009-11-19 11:55:19 +01001673 if (!err && params.use_4addr != -1)
1674 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1675
Johannes Berg55682962007-09-20 13:09:35 -04001676 return err;
1677}
1678
1679static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1680{
Johannes Berg4c476992010-10-04 21:36:35 +02001681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001682 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001683 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001684 int err;
1685 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001686 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001687
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001688 memset(&params, 0, sizeof(params));
1689
Johannes Berg55682962007-09-20 13:09:35 -04001690 if (!info->attrs[NL80211_ATTR_IFNAME])
1691 return -EINVAL;
1692
1693 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1694 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1695 if (type > NL80211_IFTYPE_MAX)
1696 return -EINVAL;
1697 }
1698
Johannes Berg79c97e92009-07-07 03:56:12 +02001699 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001700 !(rdev->wiphy.interface_modes & (1 << type)))
1701 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001702
Johannes Berg9bc383d2009-11-19 11:55:19 +01001703 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001704 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001705 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001706 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001707 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001708 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001709
Michael Wu66f7ac52008-01-31 19:48:22 +01001710 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1711 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1712 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001713 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001714 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001715 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001716 if (IS_ERR(dev))
1717 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001718
Johannes Berg29cbe682010-12-03 09:20:44 +01001719 if (type == NL80211_IFTYPE_MESH_POINT &&
1720 info->attrs[NL80211_ATTR_MESH_ID]) {
1721 struct wireless_dev *wdev = dev->ieee80211_ptr;
1722
1723 wdev_lock(wdev);
1724 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1725 IEEE80211_MAX_MESH_ID_LEN);
1726 wdev->mesh_id_up_len =
1727 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1728 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1729 wdev->mesh_id_up_len);
1730 wdev_unlock(wdev);
1731 }
1732
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001733 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001734}
1735
1736static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1737{
Johannes Berg4c476992010-10-04 21:36:35 +02001738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1739 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001740
Johannes Berg4c476992010-10-04 21:36:35 +02001741 if (!rdev->ops->del_virtual_intf)
1742 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001743
Johannes Berg4c476992010-10-04 21:36:35 +02001744 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001745}
1746
Johannes Berg41ade002007-12-19 02:03:29 +01001747struct get_key_cookie {
1748 struct sk_buff *msg;
1749 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001750 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001751};
1752
1753static void get_key_callback(void *c, struct key_params *params)
1754{
Johannes Bergb9454e82009-07-08 13:29:08 +02001755 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001756 struct get_key_cookie *cookie = c;
1757
1758 if (params->key)
1759 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1760 params->key_len, params->key);
1761
1762 if (params->seq)
1763 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1764 params->seq_len, params->seq);
1765
1766 if (params->cipher)
1767 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1768 params->cipher);
1769
Johannes Bergb9454e82009-07-08 13:29:08 +02001770 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1771 if (!key)
1772 goto nla_put_failure;
1773
1774 if (params->key)
1775 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1776 params->key_len, params->key);
1777
1778 if (params->seq)
1779 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1780 params->seq_len, params->seq);
1781
1782 if (params->cipher)
1783 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1784 params->cipher);
1785
1786 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1787
1788 nla_nest_end(cookie->msg, key);
1789
Johannes Berg41ade002007-12-19 02:03:29 +01001790 return;
1791 nla_put_failure:
1792 cookie->error = 1;
1793}
1794
1795static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1796{
Johannes Berg4c476992010-10-04 21:36:35 +02001797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001798 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001799 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001800 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001801 const u8 *mac_addr = NULL;
1802 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001803 struct get_key_cookie cookie = {
1804 .error = 0,
1805 };
1806 void *hdr;
1807 struct sk_buff *msg;
1808
1809 if (info->attrs[NL80211_ATTR_KEY_IDX])
1810 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1811
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001812 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001813 return -EINVAL;
1814
1815 if (info->attrs[NL80211_ATTR_MAC])
1816 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1817
Johannes Berge31b8212010-10-05 19:39:30 +02001818 pairwise = !!mac_addr;
1819 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1820 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1821 if (kt >= NUM_NL80211_KEYTYPES)
1822 return -EINVAL;
1823 if (kt != NL80211_KEYTYPE_GROUP &&
1824 kt != NL80211_KEYTYPE_PAIRWISE)
1825 return -EINVAL;
1826 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1827 }
1828
Johannes Berg4c476992010-10-04 21:36:35 +02001829 if (!rdev->ops->get_key)
1830 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001831
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001832 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001833 if (!msg)
1834 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001835
1836 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1837 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001838 if (IS_ERR(hdr))
1839 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001840
1841 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001842 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001843
1844 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1845 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1846 if (mac_addr)
1847 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1848
Johannes Berge31b8212010-10-05 19:39:30 +02001849 if (pairwise && mac_addr &&
1850 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1851 return -ENOENT;
1852
1853 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1854 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001855
1856 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001857 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001858
1859 if (cookie.error)
1860 goto nla_put_failure;
1861
1862 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001863 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001864
1865 nla_put_failure:
1866 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001867 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001868 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001869 return err;
1870}
1871
1872static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1873{
Johannes Berg4c476992010-10-04 21:36:35 +02001874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001875 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001876 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001877 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001878
Johannes Bergb9454e82009-07-08 13:29:08 +02001879 err = nl80211_parse_key(info, &key);
1880 if (err)
1881 return err;
1882
1883 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001884 return -EINVAL;
1885
Johannes Bergb9454e82009-07-08 13:29:08 +02001886 /* only support setting default key */
1887 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001888 return -EINVAL;
1889
Johannes Bergfffd0932009-07-08 14:22:54 +02001890 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001891
1892 if (key.def) {
1893 if (!rdev->ops->set_default_key) {
1894 err = -EOPNOTSUPP;
1895 goto out;
1896 }
1897
1898 err = nl80211_key_allowed(dev->ieee80211_ptr);
1899 if (err)
1900 goto out;
1901
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001902 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1903 key.def_uni, key.def_multi);
1904
1905 if (err)
1906 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001907
Johannes Berg3d23e342009-09-29 23:27:28 +02001908#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001909 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001910#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001911 } else {
1912 if (key.def_uni || !key.def_multi) {
1913 err = -EINVAL;
1914 goto out;
1915 }
1916
1917 if (!rdev->ops->set_default_mgmt_key) {
1918 err = -EOPNOTSUPP;
1919 goto out;
1920 }
1921
1922 err = nl80211_key_allowed(dev->ieee80211_ptr);
1923 if (err)
1924 goto out;
1925
1926 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1927 dev, key.idx);
1928 if (err)
1929 goto out;
1930
1931#ifdef CONFIG_CFG80211_WEXT
1932 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1933#endif
1934 }
1935
1936 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001937 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001938
Johannes Berg41ade002007-12-19 02:03:29 +01001939 return err;
1940}
1941
1942static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1943{
Johannes Berg4c476992010-10-04 21:36:35 +02001944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001945 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001946 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001947 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001948 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001949
Johannes Bergb9454e82009-07-08 13:29:08 +02001950 err = nl80211_parse_key(info, &key);
1951 if (err)
1952 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001953
Johannes Bergb9454e82009-07-08 13:29:08 +02001954 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001955 return -EINVAL;
1956
Johannes Berg41ade002007-12-19 02:03:29 +01001957 if (info->attrs[NL80211_ATTR_MAC])
1958 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1959
Johannes Berge31b8212010-10-05 19:39:30 +02001960 if (key.type == -1) {
1961 if (mac_addr)
1962 key.type = NL80211_KEYTYPE_PAIRWISE;
1963 else
1964 key.type = NL80211_KEYTYPE_GROUP;
1965 }
1966
1967 /* for now */
1968 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1969 key.type != NL80211_KEYTYPE_GROUP)
1970 return -EINVAL;
1971
Johannes Berg4c476992010-10-04 21:36:35 +02001972 if (!rdev->ops->add_key)
1973 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001974
Johannes Berge31b8212010-10-05 19:39:30 +02001975 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1976 key.type == NL80211_KEYTYPE_PAIRWISE,
1977 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001978 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001979
1980 wdev_lock(dev->ieee80211_ptr);
1981 err = nl80211_key_allowed(dev->ieee80211_ptr);
1982 if (!err)
1983 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001984 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001985 mac_addr, &key.p);
1986 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001987
Johannes Berg41ade002007-12-19 02:03:29 +01001988 return err;
1989}
1990
1991static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1992{
Johannes Berg4c476992010-10-04 21:36:35 +02001993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001994 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001995 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001996 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001997 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001998
Johannes Bergb9454e82009-07-08 13:29:08 +02001999 err = nl80211_parse_key(info, &key);
2000 if (err)
2001 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002002
2003 if (info->attrs[NL80211_ATTR_MAC])
2004 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2005
Johannes Berge31b8212010-10-05 19:39:30 +02002006 if (key.type == -1) {
2007 if (mac_addr)
2008 key.type = NL80211_KEYTYPE_PAIRWISE;
2009 else
2010 key.type = NL80211_KEYTYPE_GROUP;
2011 }
2012
2013 /* for now */
2014 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2015 key.type != NL80211_KEYTYPE_GROUP)
2016 return -EINVAL;
2017
Johannes Berg4c476992010-10-04 21:36:35 +02002018 if (!rdev->ops->del_key)
2019 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002020
Johannes Bergfffd0932009-07-08 14:22:54 +02002021 wdev_lock(dev->ieee80211_ptr);
2022 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002023
2024 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2025 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2026 err = -ENOENT;
2027
Johannes Bergfffd0932009-07-08 14:22:54 +02002028 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002029 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2030 key.type == NL80211_KEYTYPE_PAIRWISE,
2031 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002032
Johannes Berg3d23e342009-09-29 23:27:28 +02002033#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002034 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002035 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002036 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002037 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002038 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2039 }
2040#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002041 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002042
Johannes Berg41ade002007-12-19 02:03:29 +01002043 return err;
2044}
2045
Johannes Berged1b6cc2007-12-19 02:03:32 +01002046static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
2047{
2048 int (*call)(struct wiphy *wiphy, struct net_device *dev,
2049 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02002050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2051 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002052 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002053 struct beacon_parameters params;
Johannes Berg56d18932011-05-09 18:41:15 +02002054 int haveinfo = 0, err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002055
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002056 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2057 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2058 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2059 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002060 return -EINVAL;
2061
Johannes Berg074ac8d2010-09-16 14:58:22 +02002062 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002063 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2064 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002065
Johannes Berg56d18932011-05-09 18:41:15 +02002066 memset(&params, 0, sizeof(params));
2067
Johannes Berged1b6cc2007-12-19 02:03:32 +01002068 switch (info->genlhdr->cmd) {
2069 case NL80211_CMD_NEW_BEACON:
2070 /* these are required for NEW_BEACON */
2071 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2072 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02002073 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2074 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002075
Johannes Berg56d18932011-05-09 18:41:15 +02002076 params.interval =
2077 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2078 params.dtim_period =
2079 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2080
2081 err = cfg80211_validate_beacon_int(rdev, params.interval);
2082 if (err)
2083 return err;
2084
Jouni Malinen32e9de82011-08-10 23:53:31 +03002085 /*
2086 * In theory, some of these attributes could be required for
2087 * NEW_BEACON, but since they were not used when the command was
2088 * originally added, keep them optional for old user space
2089 * programs to work with drivers that do not need the additional
2090 * information.
2091 */
2092 if (info->attrs[NL80211_ATTR_SSID]) {
2093 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2094 params.ssid_len =
2095 nla_len(info->attrs[NL80211_ATTR_SSID]);
2096 if (params.ssid_len == 0 ||
2097 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2098 return -EINVAL;
2099 }
2100
2101 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2102 params.hidden_ssid = nla_get_u32(
2103 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2104 if (params.hidden_ssid !=
2105 NL80211_HIDDEN_SSID_NOT_IN_USE &&
2106 params.hidden_ssid !=
2107 NL80211_HIDDEN_SSID_ZERO_LEN &&
2108 params.hidden_ssid !=
2109 NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2110 return -EINVAL;
2111 }
2112
Jouni Malinen5fb628e2011-08-10 23:54:35 +03002113 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2114
2115 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2116 params.auth_type = nla_get_u32(
2117 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2118 if (!nl80211_valid_auth_type(params.auth_type))
2119 return -EINVAL;
2120 } else
2121 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2122
2123 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2124 NL80211_MAX_NR_CIPHER_SUITES);
2125 if (err)
2126 return err;
2127
Johannes Berg79c97e92009-07-07 03:56:12 +02002128 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002129 break;
2130 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02002131 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002132 break;
2133 default:
2134 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02002135 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002136 }
2137
Johannes Berg4c476992010-10-04 21:36:35 +02002138 if (!call)
2139 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002140
Johannes Berged1b6cc2007-12-19 02:03:32 +01002141 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2142 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2143 params.head_len =
2144 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2145 haveinfo = 1;
2146 }
2147
2148 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2149 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2150 params.tail_len =
2151 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2152 haveinfo = 1;
2153 }
2154
Johannes Berg4c476992010-10-04 21:36:35 +02002155 if (!haveinfo)
2156 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002157
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002158 if (info->attrs[NL80211_ATTR_IE]) {
2159 params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2160 params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2161 }
2162
2163 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2164 params.proberesp_ies =
2165 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2166 params.proberesp_ies_len =
2167 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2168 }
2169
2170 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2171 params.assocresp_ies =
2172 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2173 params.assocresp_ies_len =
2174 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2175 }
2176
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002177 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
2178 params.probe_resp =
2179 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
2180 params.probe_resp_len =
2181 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2182 }
2183
Johannes Berg56d18932011-05-09 18:41:15 +02002184 err = call(&rdev->wiphy, dev, &params);
2185 if (!err && params.interval)
2186 wdev->beacon_interval = params.interval;
2187 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002188}
2189
2190static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
2191{
Johannes Berg4c476992010-10-04 21:36:35 +02002192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2193 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002194 struct wireless_dev *wdev = dev->ieee80211_ptr;
2195 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002196
Johannes Berg4c476992010-10-04 21:36:35 +02002197 if (!rdev->ops->del_beacon)
2198 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002199
Johannes Berg074ac8d2010-09-16 14:58:22 +02002200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2202 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002203
Johannes Berg56d18932011-05-09 18:41:15 +02002204 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
2205 if (!err)
2206 wdev->beacon_interval = 0;
2207 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002208}
2209
Johannes Berg5727ef12007-12-19 02:03:34 +01002210static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2211 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2212 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2213 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002214 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002215 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002216};
2217
Johannes Bergeccb8e82009-05-11 21:57:56 +03002218static int parse_station_flags(struct genl_info *info,
2219 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002220{
2221 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002222 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002223 int flag;
2224
Johannes Bergeccb8e82009-05-11 21:57:56 +03002225 /*
2226 * Try parsing the new attribute first so userspace
2227 * can specify both for older kernels.
2228 */
2229 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2230 if (nla) {
2231 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002232
Johannes Bergeccb8e82009-05-11 21:57:56 +03002233 sta_flags = nla_data(nla);
2234 params->sta_flags_mask = sta_flags->mask;
2235 params->sta_flags_set = sta_flags->set;
2236 if ((params->sta_flags_mask |
2237 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2238 return -EINVAL;
2239 return 0;
2240 }
2241
2242 /* if present, parse the old attribute */
2243
2244 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002245 if (!nla)
2246 return 0;
2247
2248 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2249 nla, sta_flags_policy))
2250 return -EINVAL;
2251
Johannes Bergeccb8e82009-05-11 21:57:56 +03002252 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
2253 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002254
2255 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2256 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002257 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002258
2259 return 0;
2260}
2261
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002262static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2263 int attr)
2264{
2265 struct nlattr *rate;
2266 u16 bitrate;
2267
2268 rate = nla_nest_start(msg, attr);
2269 if (!rate)
2270 goto nla_put_failure;
2271
2272 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2273 bitrate = cfg80211_calculate_bitrate(info);
2274 if (bitrate > 0)
2275 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2276
2277 if (info->flags & RATE_INFO_FLAGS_MCS)
2278 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2279 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2280 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2281 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2282 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2283
2284 nla_nest_end(msg, rate);
2285 return true;
2286
2287nla_put_failure:
2288 return false;
2289}
2290
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002291static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2292 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002293 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002294{
2295 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002296 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002297
2298 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2299 if (!hdr)
2300 return -1;
2301
2302 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2303 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2304
Johannes Bergf5ea9122009-08-07 16:17:38 +02002305 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2306
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002307 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2308 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002309 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302310 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2311 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2312 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002313 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2314 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2315 sinfo->inactive_time);
2316 if (sinfo->filled & STATION_INFO_RX_BYTES)
2317 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2318 sinfo->rx_bytes);
2319 if (sinfo->filled & STATION_INFO_TX_BYTES)
2320 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2321 sinfo->tx_bytes);
2322 if (sinfo->filled & STATION_INFO_LLID)
2323 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2324 sinfo->llid);
2325 if (sinfo->filled & STATION_INFO_PLID)
2326 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2327 sinfo->plid);
2328 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2329 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2330 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002331 if (sinfo->filled & STATION_INFO_SIGNAL)
2332 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2333 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002334 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2335 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2336 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002337 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002338 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2339 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002340 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002341 }
2342 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2343 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2344 NL80211_STA_INFO_RX_BITRATE))
2345 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002346 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002347 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2348 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2349 sinfo->rx_packets);
2350 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2351 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2352 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002353 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2354 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2355 sinfo->tx_retries);
2356 if (sinfo->filled & STATION_INFO_TX_FAILED)
2357 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2358 sinfo->tx_failed);
Paul Stewartf4263c92011-03-31 09:25:41 -07002359 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2360 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2361 if (!bss_param)
2362 goto nla_put_failure;
2363
2364 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2365 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2366 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2367 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2368 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2369 NLA_PUT_FLAG(msg,
2370 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2371 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2372 sinfo->bss_param.dtim_period);
2373 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2374 sinfo->bss_param.beacon_interval);
2375
2376 nla_nest_end(msg, bss_param);
2377 }
Helmut Schaabb6e7532011-10-13 16:30:39 +02002378 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2379 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2380 sizeof(struct nl80211_sta_flag_update),
2381 &sinfo->sta_flags);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002382 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002383
Felix Fietkau040bdf72011-08-10 19:00:33 -06002384 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002385 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2386 sinfo->assoc_req_ies);
2387
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002388 return genlmsg_end(msg, hdr);
2389
2390 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002391 genlmsg_cancel(msg, hdr);
2392 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002393}
2394
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002395static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002396 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002397{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002398 struct station_info sinfo;
2399 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002400 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002401 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002402 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002404
Johannes Berg67748892010-10-04 21:14:06 +02002405 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2406 if (err)
2407 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002408
2409 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002410 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002411 goto out_err;
2412 }
2413
Johannes Bergbba95fe2008-07-29 13:22:51 +02002414 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002415 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002416 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2417 mac_addr, &sinfo);
2418 if (err == -ENOENT)
2419 break;
2420 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002421 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002422
2423 if (nl80211_send_station(skb,
2424 NETLINK_CB(cb->skb).pid,
2425 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2426 netdev, mac_addr,
2427 &sinfo) < 0)
2428 goto out;
2429
2430 sta_idx++;
2431 }
2432
2433
2434 out:
2435 cb->args[1] = sta_idx;
2436 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002437 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002438 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002439
2440 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002441}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002442
Johannes Berg5727ef12007-12-19 02:03:34 +01002443static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2444{
Johannes Berg4c476992010-10-04 21:36:35 +02002445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2446 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002447 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002448 struct sk_buff *msg;
2449 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002450 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002451
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002452 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002453
2454 if (!info->attrs[NL80211_ATTR_MAC])
2455 return -EINVAL;
2456
2457 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2458
Johannes Berg4c476992010-10-04 21:36:35 +02002459 if (!rdev->ops->get_station)
2460 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002461
Johannes Berg79c97e92009-07-07 03:56:12 +02002462 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002463 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002464 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002465
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002467 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002468 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002469
2470 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002471 dev, mac_addr, &sinfo) < 0) {
2472 nlmsg_free(msg);
2473 return -ENOBUFS;
2474 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002475
Johannes Berg4c476992010-10-04 21:36:35 +02002476 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002477}
2478
2479/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002480 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002481 */
Johannes Berg463d0182009-07-14 00:33:35 +02002482static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002483 struct cfg80211_registered_device *rdev,
2484 struct net_device **vlan)
2485{
Johannes Berg463d0182009-07-14 00:33:35 +02002486 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002487 *vlan = NULL;
2488
2489 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002490 *vlan = dev_get_by_index(genl_info_net(info),
2491 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002492 if (!*vlan)
2493 return -ENODEV;
2494 if (!(*vlan)->ieee80211_ptr)
2495 return -EINVAL;
2496 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2497 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002498 if (!netif_running(*vlan))
2499 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002500 }
2501 return 0;
2502}
2503
2504static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2505{
Johannes Berg4c476992010-10-04 21:36:35 +02002506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002507 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002508 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002509 struct station_parameters params;
2510 u8 *mac_addr = NULL;
2511
2512 memset(&params, 0, sizeof(params));
2513
2514 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002515 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002516
2517 if (info->attrs[NL80211_ATTR_STA_AID])
2518 return -EINVAL;
2519
2520 if (!info->attrs[NL80211_ATTR_MAC])
2521 return -EINVAL;
2522
2523 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2524
2525 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2526 params.supported_rates =
2527 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2528 params.supported_rates_len =
2529 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2530 }
2531
2532 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2533 params.listen_interval =
2534 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2535
Jouni Malinen36aedc92008-08-25 11:58:58 +03002536 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2537 params.ht_capa =
2538 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2539
Johannes Bergeccb8e82009-05-11 21:57:56 +03002540 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002541 return -EINVAL;
2542
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002543 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2544 params.plink_action =
2545 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2546
Javier Cardona9c3990a2011-05-03 16:57:11 -07002547 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2548 params.plink_state =
2549 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2550
Johannes Berg463d0182009-07-14 00:33:35 +02002551 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002552 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002553 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002554
2555 /* validate settings */
2556 err = 0;
2557
2558 switch (dev->ieee80211_ptr->iftype) {
2559 case NL80211_IFTYPE_AP:
2560 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002561 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002562 /* disallow mesh-specific things */
2563 if (params.plink_action)
2564 err = -EINVAL;
2565 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002566 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002567 case NL80211_IFTYPE_STATION:
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002568 /* disallow things sta doesn't support */
Johannes Berga97f4422009-06-18 17:23:43 +02002569 if (params.plink_action)
2570 err = -EINVAL;
2571 if (params.vlan)
2572 err = -EINVAL;
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002573 if (params.supported_rates &&
2574 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berga97f4422009-06-18 17:23:43 +02002575 err = -EINVAL;
2576 if (params.ht_capa)
2577 err = -EINVAL;
2578 if (params.listen_interval >= 0)
2579 err = -EINVAL;
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002580 if (params.sta_flags_mask &
2581 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2582 BIT(NL80211_STA_FLAG_TDLS_PEER)))
2583 err = -EINVAL;
2584 /* can't change the TDLS bit */
2585 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2586 (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berga97f4422009-06-18 17:23:43 +02002587 err = -EINVAL;
2588 break;
2589 case NL80211_IFTYPE_MESH_POINT:
2590 /* disallow things mesh doesn't support */
2591 if (params.vlan)
2592 err = -EINVAL;
2593 if (params.ht_capa)
2594 err = -EINVAL;
2595 if (params.listen_interval >= 0)
2596 err = -EINVAL;
Javier Cardonab39c48f2011-04-07 15:08:30 -07002597 if (params.sta_flags_mask &
2598 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002599 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002600 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Berga97f4422009-06-18 17:23:43 +02002601 err = -EINVAL;
2602 break;
2603 default:
2604 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002605 }
2606
Johannes Berg5727ef12007-12-19 02:03:34 +01002607 if (err)
2608 goto out;
2609
Johannes Berg79c97e92009-07-07 03:56:12 +02002610 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002611 err = -EOPNOTSUPP;
2612 goto out;
2613 }
2614
Johannes Berg79c97e92009-07-07 03:56:12 +02002615 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002616
2617 out:
2618 if (params.vlan)
2619 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002620
Johannes Berg5727ef12007-12-19 02:03:34 +01002621 return err;
2622}
2623
Eliad Pellerc75786c2011-08-23 14:37:46 +03002624static struct nla_policy
2625nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2626 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2627 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2628};
2629
Johannes Berg5727ef12007-12-19 02:03:34 +01002630static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2631{
Johannes Berg4c476992010-10-04 21:36:35 +02002632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002633 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002634 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002635 struct station_parameters params;
2636 u8 *mac_addr = NULL;
2637
2638 memset(&params, 0, sizeof(params));
2639
2640 if (!info->attrs[NL80211_ATTR_MAC])
2641 return -EINVAL;
2642
Johannes Berg5727ef12007-12-19 02:03:34 +01002643 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2644 return -EINVAL;
2645
2646 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2647 return -EINVAL;
2648
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002649 if (!info->attrs[NL80211_ATTR_STA_AID])
2650 return -EINVAL;
2651
Johannes Berg5727ef12007-12-19 02:03:34 +01002652 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2653 params.supported_rates =
2654 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2655 params.supported_rates_len =
2656 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2657 params.listen_interval =
2658 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002659
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002660 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2661 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2662 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002663
Jouni Malinen36aedc92008-08-25 11:58:58 +03002664 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2665 params.ht_capa =
2666 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002667
Javier Cardona96b78df2011-04-07 15:08:33 -07002668 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2669 params.plink_action =
2670 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2671
Johannes Bergeccb8e82009-05-11 21:57:56 +03002672 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002673 return -EINVAL;
2674
Eliad Pellerc75786c2011-08-23 14:37:46 +03002675 /* parse WME attributes if sta is WME capable */
Eliad Pellercedb5412011-08-31 11:29:43 +03002676 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Arik Nemtsovcd329842011-09-26 09:36:42 +03002677 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
Eliad Pellerc75786c2011-08-23 14:37:46 +03002678 info->attrs[NL80211_ATTR_STA_WME]) {
2679 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2680 struct nlattr *nla;
2681
2682 nla = info->attrs[NL80211_ATTR_STA_WME];
2683 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2684 nl80211_sta_wme_policy);
2685 if (err)
2686 return err;
2687
2688 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2689 params.uapsd_queues =
2690 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
Johannes Berg4319e192011-09-07 11:50:48 +02002691 if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2692 return -EINVAL;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002693
2694 if (tb[NL80211_STA_WME_MAX_SP])
2695 params.max_sp =
2696 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
Johannes Berg4319e192011-09-07 11:50:48 +02002697
2698 if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2699 return -EINVAL;
Johannes Berg3b9ce802011-09-27 20:56:12 +02002700
2701 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002702 }
2703
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002704 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002705 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardona96b78df2011-04-07 15:08:33 -07002706 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002707 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO &&
2708 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
2709 return -EINVAL;
2710
2711 /*
2712 * Only managed stations can add TDLS peers, and only when the
2713 * wiphy supports external TDLS setup.
2714 */
2715 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION &&
2716 !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2717 (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2718 (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
Johannes Berg4c476992010-10-04 21:36:35 +02002719 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002720
Johannes Berg463d0182009-07-14 00:33:35 +02002721 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002722 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002723 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002724
2725 /* validate settings */
2726 err = 0;
2727
Johannes Berg79c97e92009-07-07 03:56:12 +02002728 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002729 err = -EOPNOTSUPP;
2730 goto out;
2731 }
2732
Johannes Berg79c97e92009-07-07 03:56:12 +02002733 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002734
2735 out:
2736 if (params.vlan)
2737 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002738 return err;
2739}
2740
2741static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2742{
Johannes Berg4c476992010-10-04 21:36:35 +02002743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2744 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002745 u8 *mac_addr = NULL;
2746
2747 if (info->attrs[NL80211_ATTR_MAC])
2748 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2749
Johannes Berge80cf852009-05-11 14:43:13 +02002750 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002751 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002752 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002753 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2754 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002755
Johannes Berg4c476992010-10-04 21:36:35 +02002756 if (!rdev->ops->del_station)
2757 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002758
Johannes Berg4c476992010-10-04 21:36:35 +02002759 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002760}
2761
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002762static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2763 int flags, struct net_device *dev,
2764 u8 *dst, u8 *next_hop,
2765 struct mpath_info *pinfo)
2766{
2767 void *hdr;
2768 struct nlattr *pinfoattr;
2769
2770 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2771 if (!hdr)
2772 return -1;
2773
2774 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2775 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2776 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2777
Johannes Bergf5ea9122009-08-07 16:17:38 +02002778 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2779
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002780 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2781 if (!pinfoattr)
2782 goto nla_put_failure;
2783 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2784 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2785 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002786 if (pinfo->filled & MPATH_INFO_SN)
2787 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2788 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002789 if (pinfo->filled & MPATH_INFO_METRIC)
2790 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2791 pinfo->metric);
2792 if (pinfo->filled & MPATH_INFO_EXPTIME)
2793 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2794 pinfo->exptime);
2795 if (pinfo->filled & MPATH_INFO_FLAGS)
2796 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2797 pinfo->flags);
2798 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2799 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2800 pinfo->discovery_timeout);
2801 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2802 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2803 pinfo->discovery_retries);
2804
2805 nla_nest_end(msg, pinfoattr);
2806
2807 return genlmsg_end(msg, hdr);
2808
2809 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002810 genlmsg_cancel(msg, hdr);
2811 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002812}
2813
2814static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002815 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002816{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002817 struct mpath_info pinfo;
2818 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002819 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002820 u8 dst[ETH_ALEN];
2821 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002822 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002823 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002824
Johannes Berg67748892010-10-04 21:14:06 +02002825 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2826 if (err)
2827 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002828
2829 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002830 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002831 goto out_err;
2832 }
2833
Jouni Malineneec60b02009-03-20 21:21:19 +02002834 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2835 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002836 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002837 }
2838
Johannes Bergbba95fe2008-07-29 13:22:51 +02002839 while (1) {
2840 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2841 dst, next_hop, &pinfo);
2842 if (err == -ENOENT)
2843 break;
2844 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002845 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002846
2847 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2848 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2849 netdev, dst, next_hop,
2850 &pinfo) < 0)
2851 goto out;
2852
2853 path_idx++;
2854 }
2855
2856
2857 out:
2858 cb->args[1] = path_idx;
2859 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002860 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002861 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002862 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002863}
2864
2865static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2866{
Johannes Berg4c476992010-10-04 21:36:35 +02002867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002868 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002869 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002870 struct mpath_info pinfo;
2871 struct sk_buff *msg;
2872 u8 *dst = NULL;
2873 u8 next_hop[ETH_ALEN];
2874
2875 memset(&pinfo, 0, sizeof(pinfo));
2876
2877 if (!info->attrs[NL80211_ATTR_MAC])
2878 return -EINVAL;
2879
2880 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2881
Johannes Berg4c476992010-10-04 21:36:35 +02002882 if (!rdev->ops->get_mpath)
2883 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002884
Johannes Berg4c476992010-10-04 21:36:35 +02002885 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2886 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002887
Johannes Berg79c97e92009-07-07 03:56:12 +02002888 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002889 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002890 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002891
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002892 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002893 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002894 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002895
2896 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002897 dev, dst, next_hop, &pinfo) < 0) {
2898 nlmsg_free(msg);
2899 return -ENOBUFS;
2900 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002901
Johannes Berg4c476992010-10-04 21:36:35 +02002902 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002903}
2904
2905static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2906{
Johannes Berg4c476992010-10-04 21:36:35 +02002907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2908 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002909 u8 *dst = NULL;
2910 u8 *next_hop = NULL;
2911
2912 if (!info->attrs[NL80211_ATTR_MAC])
2913 return -EINVAL;
2914
2915 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2916 return -EINVAL;
2917
2918 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2919 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2920
Johannes Berg4c476992010-10-04 21:36:35 +02002921 if (!rdev->ops->change_mpath)
2922 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002923
Johannes Berg4c476992010-10-04 21:36:35 +02002924 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2925 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002926
Johannes Berg4c476992010-10-04 21:36:35 +02002927 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002928}
Johannes Berg4c476992010-10-04 21:36:35 +02002929
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002930static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2931{
Johannes Berg4c476992010-10-04 21:36:35 +02002932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2933 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002934 u8 *dst = NULL;
2935 u8 *next_hop = NULL;
2936
2937 if (!info->attrs[NL80211_ATTR_MAC])
2938 return -EINVAL;
2939
2940 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2941 return -EINVAL;
2942
2943 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2944 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2945
Johannes Berg4c476992010-10-04 21:36:35 +02002946 if (!rdev->ops->add_mpath)
2947 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002948
Johannes Berg4c476992010-10-04 21:36:35 +02002949 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2950 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002951
Johannes Berg4c476992010-10-04 21:36:35 +02002952 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002953}
2954
2955static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2956{
Johannes Berg4c476992010-10-04 21:36:35 +02002957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2958 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002959 u8 *dst = NULL;
2960
2961 if (info->attrs[NL80211_ATTR_MAC])
2962 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2963
Johannes Berg4c476992010-10-04 21:36:35 +02002964 if (!rdev->ops->del_mpath)
2965 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002966
Johannes Berg4c476992010-10-04 21:36:35 +02002967 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002968}
2969
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002970static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2971{
Johannes Berg4c476992010-10-04 21:36:35 +02002972 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2973 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002974 struct bss_parameters params;
2975
2976 memset(&params, 0, sizeof(params));
2977 /* default to not changing parameters */
2978 params.use_cts_prot = -1;
2979 params.use_short_preamble = -1;
2980 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002981 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002982 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002983
2984 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2985 params.use_cts_prot =
2986 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2987 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2988 params.use_short_preamble =
2989 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2990 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2991 params.use_short_slot_time =
2992 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002993 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2994 params.basic_rates =
2995 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2996 params.basic_rates_len =
2997 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2998 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002999 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3000 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003001 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3002 params.ht_opmode =
3003 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003004
Johannes Berg4c476992010-10-04 21:36:35 +02003005 if (!rdev->ops->change_bss)
3006 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003007
Johannes Berg074ac8d2010-09-16 14:58:22 +02003008 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003009 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3010 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003011
Johannes Berg4c476992010-10-04 21:36:35 +02003012 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003013}
3014
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003015static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003016 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3017 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3018 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3019 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3020 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3021 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3022};
3023
3024static int parse_reg_rule(struct nlattr *tb[],
3025 struct ieee80211_reg_rule *reg_rule)
3026{
3027 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3028 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3029
3030 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3031 return -EINVAL;
3032 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3033 return -EINVAL;
3034 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3035 return -EINVAL;
3036 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3037 return -EINVAL;
3038 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3039 return -EINVAL;
3040
3041 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3042
3043 freq_range->start_freq_khz =
3044 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3045 freq_range->end_freq_khz =
3046 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3047 freq_range->max_bandwidth_khz =
3048 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3049
3050 power_rule->max_eirp =
3051 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3052
3053 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3054 power_rule->max_antenna_gain =
3055 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3056
3057 return 0;
3058}
3059
3060static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3061{
3062 int r;
3063 char *data = NULL;
3064
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003065 /*
3066 * You should only get this when cfg80211 hasn't yet initialized
3067 * completely when built-in to the kernel right between the time
3068 * window between nl80211_init() and regulatory_init(), if that is
3069 * even possible.
3070 */
3071 mutex_lock(&cfg80211_mutex);
3072 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003073 mutex_unlock(&cfg80211_mutex);
3074 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003075 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003076 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003077
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003078 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3079 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003080
3081 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3082
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003083 r = regulatory_hint_user(data);
3084
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003085 return r;
3086}
3087
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003088static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003089 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003090{
Johannes Berg4c476992010-10-04 21:36:35 +02003091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003092 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003093 struct wireless_dev *wdev = dev->ieee80211_ptr;
3094 struct mesh_config cur_params;
3095 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003096 void *hdr;
3097 struct nlattr *pinfoattr;
3098 struct sk_buff *msg;
3099
Johannes Berg29cbe682010-12-03 09:20:44 +01003100 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3101 return -EOPNOTSUPP;
3102
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003103 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003104 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003105
Johannes Berg29cbe682010-12-03 09:20:44 +01003106 wdev_lock(wdev);
3107 /* If not connected, get default parameters */
3108 if (!wdev->mesh_id_len)
3109 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3110 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003111 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003112 &cur_params);
3113 wdev_unlock(wdev);
3114
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003115 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003116 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003117
3118 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003119 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003120 if (!msg)
3121 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003122 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003123 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003124 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003125 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003126 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003127 if (!pinfoattr)
3128 goto nla_put_failure;
3129 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3130 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3131 cur_params.dot11MeshRetryTimeout);
3132 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3133 cur_params.dot11MeshConfirmTimeout);
3134 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3135 cur_params.dot11MeshHoldingTimeout);
3136 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3137 cur_params.dot11MeshMaxPeerLinks);
3138 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3139 cur_params.dot11MeshMaxRetries);
3140 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3141 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01003142 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3143 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003144 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3145 cur_params.auto_open_plinks);
3146 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3147 cur_params.dot11MeshHWMPmaxPREQretries);
3148 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3149 cur_params.path_refresh_time);
3150 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3151 cur_params.min_discovery_timeout);
3152 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3153 cur_params.dot11MeshHWMPactivePathTimeout);
3154 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3155 cur_params.dot11MeshHWMPpreqMinInterval);
3156 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3157 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00003158 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3159 cur_params.dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -07003160 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3161 cur_params.dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -07003162 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3163 cur_params.dot11MeshGateAnnouncementProtocol);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003164 nla_nest_end(msg, pinfoattr);
3165 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003166 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003167
Johannes Berg3b858752009-03-12 09:55:09 +01003168 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003169 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003170 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003171 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003172 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003173}
3174
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003175static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003176 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3177 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3178 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3179 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3180 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3181 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003182 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003183 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
3184
3185 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3186 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3187 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3188 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3189 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
3190 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003191 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003192 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003193 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003194};
3195
Javier Cardonac80d5452010-12-16 17:37:49 -08003196static const struct nla_policy
3197 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
3198 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3199 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003200 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003201 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08003202 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003203 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003204};
3205
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003206static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003207 struct mesh_config *cfg,
3208 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003209{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003210 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003211 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003212
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003213#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3214do {\
3215 if (table[attr_num]) {\
3216 cfg->param = nla_fn(table[attr_num]); \
3217 mask |= (1 << (attr_num - 1)); \
3218 } \
3219} while (0);\
3220
3221
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003222 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003223 return -EINVAL;
3224 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003225 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003226 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003227 return -EINVAL;
3228
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003229 /* This makes sure that there aren't more than 32 mesh config
3230 * parameters (otherwise our bitfield scheme would not work.) */
3231 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3232
3233 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003234 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3235 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3237 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3239 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3240 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3241 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3243 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3245 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3247 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003248 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3249 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3250 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3251 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3252 nla_get_u8);
3253 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3254 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3255 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3256 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3257 nla_get_u16);
3258 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3259 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3260 nla_get_u32);
3261 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3262 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3263 nla_get_u16);
3264 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3265 dot11MeshHWMPnetDiameterTraversalTime,
3266 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3267 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003268 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3269 dot11MeshHWMPRootMode, mask,
3270 NL80211_MESHCONF_HWMP_ROOTMODE,
3271 nla_get_u8);
Javier Cardona0507e152011-08-09 16:45:10 -07003272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3273 dot11MeshHWMPRannInterval, mask,
3274 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3275 nla_get_u16);
Javier Cardona16dd7262011-08-09 16:45:11 -07003276 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3277 dot11MeshGateAnnouncementProtocol, mask,
3278 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3279 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003280 if (mask_out)
3281 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003282
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003283 return 0;
3284
3285#undef FILL_IN_MESH_PARAM_IF_SET
3286}
3287
Javier Cardonac80d5452010-12-16 17:37:49 -08003288static int nl80211_parse_mesh_setup(struct genl_info *info,
3289 struct mesh_setup *setup)
3290{
3291 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3292
3293 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3294 return -EINVAL;
3295 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3296 info->attrs[NL80211_ATTR_MESH_SETUP],
3297 nl80211_mesh_setup_params_policy))
3298 return -EINVAL;
3299
3300 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3301 setup->path_sel_proto =
3302 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3303 IEEE80211_PATH_PROTOCOL_VENDOR :
3304 IEEE80211_PATH_PROTOCOL_HWMP;
3305
3306 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3307 setup->path_metric =
3308 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3309 IEEE80211_PATH_METRIC_VENDOR :
3310 IEEE80211_PATH_METRIC_AIRTIME;
3311
Javier Cardona581a8b02011-04-07 15:08:27 -07003312
3313 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003314 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003315 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003316 if (!is_valid_ie_attr(ieattr))
3317 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003318 setup->ie = nla_data(ieattr);
3319 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003320 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003321 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3322 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003323
3324 return 0;
3325}
3326
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003327static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003328 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003329{
3330 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3331 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003332 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003333 struct mesh_config cfg;
3334 u32 mask;
3335 int err;
3336
Johannes Berg29cbe682010-12-03 09:20:44 +01003337 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3338 return -EOPNOTSUPP;
3339
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003340 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003341 return -EOPNOTSUPP;
3342
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003343 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003344 if (err)
3345 return err;
3346
Johannes Berg29cbe682010-12-03 09:20:44 +01003347 wdev_lock(wdev);
3348 if (!wdev->mesh_id_len)
3349 err = -ENOLINK;
3350
3351 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003352 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003353 mask, &cfg);
3354
3355 wdev_unlock(wdev);
3356
3357 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003358}
3359
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003360static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3361{
3362 struct sk_buff *msg;
3363 void *hdr = NULL;
3364 struct nlattr *nl_reg_rules;
3365 unsigned int i;
3366 int err = -EINVAL;
3367
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003368 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003369
3370 if (!cfg80211_regdomain)
3371 goto out;
3372
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003374 if (!msg) {
3375 err = -ENOBUFS;
3376 goto out;
3377 }
3378
3379 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3380 NL80211_CMD_GET_REG);
3381 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003382 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003383
3384 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3385 cfg80211_regdomain->alpha2);
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003386 if (cfg80211_regdomain->dfs_region)
3387 NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
3388 cfg80211_regdomain->dfs_region);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003389
3390 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3391 if (!nl_reg_rules)
3392 goto nla_put_failure;
3393
3394 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3395 struct nlattr *nl_reg_rule;
3396 const struct ieee80211_reg_rule *reg_rule;
3397 const struct ieee80211_freq_range *freq_range;
3398 const struct ieee80211_power_rule *power_rule;
3399
3400 reg_rule = &cfg80211_regdomain->reg_rules[i];
3401 freq_range = &reg_rule->freq_range;
3402 power_rule = &reg_rule->power_rule;
3403
3404 nl_reg_rule = nla_nest_start(msg, i);
3405 if (!nl_reg_rule)
3406 goto nla_put_failure;
3407
3408 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3409 reg_rule->flags);
3410 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3411 freq_range->start_freq_khz);
3412 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3413 freq_range->end_freq_khz);
3414 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3415 freq_range->max_bandwidth_khz);
3416 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3417 power_rule->max_antenna_gain);
3418 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3419 power_rule->max_eirp);
3420
3421 nla_nest_end(msg, nl_reg_rule);
3422 }
3423
3424 nla_nest_end(msg, nl_reg_rules);
3425
3426 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003427 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003428 goto out;
3429
3430nla_put_failure:
3431 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003432put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003433 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003434 err = -EMSGSIZE;
3435out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003436 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003437 return err;
3438}
3439
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003440static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3441{
3442 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3443 struct nlattr *nl_reg_rule;
3444 char *alpha2 = NULL;
3445 int rem_reg_rules = 0, r = 0;
3446 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003447 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003448 struct ieee80211_regdomain *rd = NULL;
3449
3450 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3451 return -EINVAL;
3452
3453 if (!info->attrs[NL80211_ATTR_REG_RULES])
3454 return -EINVAL;
3455
3456 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3457
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003458 if (info->attrs[NL80211_ATTR_DFS_REGION])
3459 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3460
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003461 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3462 rem_reg_rules) {
3463 num_rules++;
3464 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003465 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003466 }
3467
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003468 mutex_lock(&cfg80211_mutex);
3469
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003470 if (!reg_is_valid_request(alpha2)) {
3471 r = -EINVAL;
3472 goto bad_reg;
3473 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003474
3475 size_of_regd = sizeof(struct ieee80211_regdomain) +
3476 (num_rules * sizeof(struct ieee80211_reg_rule));
3477
3478 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003479 if (!rd) {
3480 r = -ENOMEM;
3481 goto bad_reg;
3482 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003483
3484 rd->n_reg_rules = num_rules;
3485 rd->alpha2[0] = alpha2[0];
3486 rd->alpha2[1] = alpha2[1];
3487
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003488 /*
3489 * Disable DFS master mode if the DFS region was
3490 * not supported or known on this kernel.
3491 */
3492 if (reg_supported_dfs_region(dfs_region))
3493 rd->dfs_region = dfs_region;
3494
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003495 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3496 rem_reg_rules) {
3497 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3498 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3499 reg_rule_policy);
3500 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3501 if (r)
3502 goto bad_reg;
3503
3504 rule_idx++;
3505
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003506 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3507 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003508 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003509 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003510 }
3511
3512 BUG_ON(rule_idx != num_rules);
3513
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003514 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003515
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003516 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003517
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003518 return r;
3519
Johannes Bergd2372b32008-10-24 20:32:20 +02003520 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003521 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003522 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003523 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003524}
3525
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003526static int validate_scan_freqs(struct nlattr *freqs)
3527{
3528 struct nlattr *attr1, *attr2;
3529 int n_channels = 0, tmp1, tmp2;
3530
3531 nla_for_each_nested(attr1, freqs, tmp1) {
3532 n_channels++;
3533 /*
3534 * Some hardware has a limited channel list for
3535 * scanning, and it is pretty much nonsensical
3536 * to scan for a channel twice, so disallow that
3537 * and don't require drivers to check that the
3538 * channel list they get isn't longer than what
3539 * they can scan, as long as they can scan all
3540 * the channels they registered at once.
3541 */
3542 nla_for_each_nested(attr2, freqs, tmp2)
3543 if (attr1 != attr2 &&
3544 nla_get_u32(attr1) == nla_get_u32(attr2))
3545 return 0;
3546 }
3547
3548 return n_channels;
3549}
3550
Johannes Berg2a519312009-02-10 21:25:55 +01003551static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3552{
Johannes Berg4c476992010-10-04 21:36:35 +02003553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3554 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003555 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003556 struct nlattr *attr;
3557 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003558 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003559 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003560
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003561 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3562 return -EINVAL;
3563
Johannes Berg79c97e92009-07-07 03:56:12 +02003564 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003565
Johannes Berg4c476992010-10-04 21:36:35 +02003566 if (!rdev->ops->scan)
3567 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003568
Johannes Berg4c476992010-10-04 21:36:35 +02003569 if (rdev->scan_req)
3570 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003571
3572 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003573 n_channels = validate_scan_freqs(
3574 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003575 if (!n_channels)
3576 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003577 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003578 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003579 n_channels = 0;
3580
Johannes Berg2a519312009-02-10 21:25:55 +01003581 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3582 if (wiphy->bands[band])
3583 n_channels += wiphy->bands[band]->n_channels;
3584 }
3585
3586 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3587 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3588 n_ssids++;
3589
Johannes Berg4c476992010-10-04 21:36:35 +02003590 if (n_ssids > wiphy->max_scan_ssids)
3591 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003592
Jouni Malinen70692ad2009-02-16 19:39:13 +02003593 if (info->attrs[NL80211_ATTR_IE])
3594 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3595 else
3596 ie_len = 0;
3597
Johannes Berg4c476992010-10-04 21:36:35 +02003598 if (ie_len > wiphy->max_scan_ie_len)
3599 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003600
Johannes Berg2a519312009-02-10 21:25:55 +01003601 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003602 + sizeof(*request->ssids) * n_ssids
3603 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003604 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003605 if (!request)
3606 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003607
Johannes Berg2a519312009-02-10 21:25:55 +01003608 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003609 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003610 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003611 if (ie_len) {
3612 if (request->ssids)
3613 request->ie = (void *)(request->ssids + n_ssids);
3614 else
3615 request->ie = (void *)(request->channels + n_channels);
3616 }
Johannes Berg2a519312009-02-10 21:25:55 +01003617
Johannes Berg584991d2009-11-02 13:32:03 +01003618 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003619 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3620 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003621 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003622 struct ieee80211_channel *chan;
3623
3624 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3625
3626 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003627 err = -EINVAL;
3628 goto out_free;
3629 }
Johannes Berg584991d2009-11-02 13:32:03 +01003630
3631 /* ignore disabled channels */
3632 if (chan->flags & IEEE80211_CHAN_DISABLED)
3633 continue;
3634
3635 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003636 i++;
3637 }
3638 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003639 enum ieee80211_band band;
3640
Johannes Berg2a519312009-02-10 21:25:55 +01003641 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003642 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3643 int j;
3644 if (!wiphy->bands[band])
3645 continue;
3646 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003647 struct ieee80211_channel *chan;
3648
3649 chan = &wiphy->bands[band]->channels[j];
3650
3651 if (chan->flags & IEEE80211_CHAN_DISABLED)
3652 continue;
3653
3654 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003655 i++;
3656 }
3657 }
3658 }
3659
Johannes Berg584991d2009-11-02 13:32:03 +01003660 if (!i) {
3661 err = -EINVAL;
3662 goto out_free;
3663 }
3664
3665 request->n_channels = i;
3666
Johannes Berg2a519312009-02-10 21:25:55 +01003667 i = 0;
3668 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3669 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003670 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003671 err = -EINVAL;
3672 goto out_free;
3673 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003674 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003675 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003676 i++;
3677 }
3678 }
3679
Jouni Malinen70692ad2009-02-16 19:39:13 +02003680 if (info->attrs[NL80211_ATTR_IE]) {
3681 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003682 memcpy((void *)request->ie,
3683 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003684 request->ie_len);
3685 }
3686
Johannes Berg34850ab2011-07-18 18:08:35 +02003687 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003688 if (wiphy->bands[i])
3689 request->rates[i] =
3690 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003691
3692 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3693 nla_for_each_nested(attr,
3694 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3695 tmp) {
3696 enum ieee80211_band band = nla_type(attr);
3697
Dan Carpenter84404622011-07-29 11:52:18 +03003698 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003699 err = -EINVAL;
3700 goto out_free;
3701 }
3702 err = ieee80211_get_ratemask(wiphy->bands[band],
3703 nla_data(attr),
3704 nla_len(attr),
3705 &request->rates[band]);
3706 if (err)
3707 goto out_free;
3708 }
3709 }
3710
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05303711 request->no_cck =
3712 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3713
Johannes Berg463d0182009-07-14 00:33:35 +02003714 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003715 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003716
Johannes Berg79c97e92009-07-07 03:56:12 +02003717 rdev->scan_req = request;
3718 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003719
Johannes Berg463d0182009-07-14 00:33:35 +02003720 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003721 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003722 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003723 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003724 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003725 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003726 kfree(request);
3727 }
Johannes Berg3b858752009-03-12 09:55:09 +01003728
Johannes Berg2a519312009-02-10 21:25:55 +01003729 return err;
3730}
3731
Luciano Coelho807f8a82011-05-11 17:09:35 +03003732static int nl80211_start_sched_scan(struct sk_buff *skb,
3733 struct genl_info *info)
3734{
3735 struct cfg80211_sched_scan_request *request;
3736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3737 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003738 struct nlattr *attr;
3739 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003740 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003741 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003742 enum ieee80211_band band;
3743 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003744 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003745
3746 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3747 !rdev->ops->sched_scan_start)
3748 return -EOPNOTSUPP;
3749
3750 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3751 return -EINVAL;
3752
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003753 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3754 return -EINVAL;
3755
3756 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3757 if (interval == 0)
3758 return -EINVAL;
3759
Luciano Coelho807f8a82011-05-11 17:09:35 +03003760 wiphy = &rdev->wiphy;
3761
3762 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3763 n_channels = validate_scan_freqs(
3764 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3765 if (!n_channels)
3766 return -EINVAL;
3767 } else {
3768 n_channels = 0;
3769
3770 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3771 if (wiphy->bands[band])
3772 n_channels += wiphy->bands[band]->n_channels;
3773 }
3774
3775 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3776 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3777 tmp)
3778 n_ssids++;
3779
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003780 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003781 return -EINVAL;
3782
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003783 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3784 nla_for_each_nested(attr,
3785 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3786 tmp)
3787 n_match_sets++;
3788
3789 if (n_match_sets > wiphy->max_match_sets)
3790 return -EINVAL;
3791
Luciano Coelho807f8a82011-05-11 17:09:35 +03003792 if (info->attrs[NL80211_ATTR_IE])
3793 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3794 else
3795 ie_len = 0;
3796
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003797 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003798 return -EINVAL;
3799
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003800 mutex_lock(&rdev->sched_scan_mtx);
3801
3802 if (rdev->sched_scan_req) {
3803 err = -EINPROGRESS;
3804 goto out;
3805 }
3806
Luciano Coelho807f8a82011-05-11 17:09:35 +03003807 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003808 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003809 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003810 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003811 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003812 if (!request) {
3813 err = -ENOMEM;
3814 goto out;
3815 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003816
3817 if (n_ssids)
3818 request->ssids = (void *)&request->channels[n_channels];
3819 request->n_ssids = n_ssids;
3820 if (ie_len) {
3821 if (request->ssids)
3822 request->ie = (void *)(request->ssids + n_ssids);
3823 else
3824 request->ie = (void *)(request->channels + n_channels);
3825 }
3826
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003827 if (n_match_sets) {
3828 if (request->ie)
3829 request->match_sets = (void *)(request->ie + ie_len);
3830 else if (request->ssids)
3831 request->match_sets =
3832 (void *)(request->ssids + n_ssids);
3833 else
3834 request->match_sets =
3835 (void *)(request->channels + n_channels);
3836 }
3837 request->n_match_sets = n_match_sets;
3838
Luciano Coelho807f8a82011-05-11 17:09:35 +03003839 i = 0;
3840 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3841 /* user specified, bail out if channel not found */
3842 nla_for_each_nested(attr,
3843 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3844 tmp) {
3845 struct ieee80211_channel *chan;
3846
3847 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3848
3849 if (!chan) {
3850 err = -EINVAL;
3851 goto out_free;
3852 }
3853
3854 /* ignore disabled channels */
3855 if (chan->flags & IEEE80211_CHAN_DISABLED)
3856 continue;
3857
3858 request->channels[i] = chan;
3859 i++;
3860 }
3861 } else {
3862 /* all channels */
3863 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3864 int j;
3865 if (!wiphy->bands[band])
3866 continue;
3867 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3868 struct ieee80211_channel *chan;
3869
3870 chan = &wiphy->bands[band]->channels[j];
3871
3872 if (chan->flags & IEEE80211_CHAN_DISABLED)
3873 continue;
3874
3875 request->channels[i] = chan;
3876 i++;
3877 }
3878 }
3879 }
3880
3881 if (!i) {
3882 err = -EINVAL;
3883 goto out_free;
3884 }
3885
3886 request->n_channels = i;
3887
3888 i = 0;
3889 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3890 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3891 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003892 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03003893 err = -EINVAL;
3894 goto out_free;
3895 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003896 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003897 memcpy(request->ssids[i].ssid, nla_data(attr),
3898 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03003899 i++;
3900 }
3901 }
3902
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003903 i = 0;
3904 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
3905 nla_for_each_nested(attr,
3906 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3907 tmp) {
3908 struct nlattr *ssid;
3909
3910 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
3911 nla_data(attr), nla_len(attr),
3912 nl80211_match_policy);
3913 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
3914 if (ssid) {
3915 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
3916 err = -EINVAL;
3917 goto out_free;
3918 }
3919 memcpy(request->match_sets[i].ssid.ssid,
3920 nla_data(ssid), nla_len(ssid));
3921 request->match_sets[i].ssid.ssid_len =
3922 nla_len(ssid);
3923 }
3924 i++;
3925 }
3926 }
3927
Luciano Coelho807f8a82011-05-11 17:09:35 +03003928 if (info->attrs[NL80211_ATTR_IE]) {
3929 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3930 memcpy((void *)request->ie,
3931 nla_data(info->attrs[NL80211_ATTR_IE]),
3932 request->ie_len);
3933 }
3934
3935 request->dev = dev;
3936 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003937 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003938
3939 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3940 if (!err) {
3941 rdev->sched_scan_req = request;
3942 nl80211_send_sched_scan(rdev, dev,
3943 NL80211_CMD_START_SCHED_SCAN);
3944 goto out;
3945 }
3946
3947out_free:
3948 kfree(request);
3949out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003950 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003951 return err;
3952}
3953
3954static int nl80211_stop_sched_scan(struct sk_buff *skb,
3955 struct genl_info *info)
3956{
3957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003958 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003959
3960 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3961 !rdev->ops->sched_scan_stop)
3962 return -EOPNOTSUPP;
3963
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003964 mutex_lock(&rdev->sched_scan_mtx);
3965 err = __cfg80211_stop_sched_scan(rdev, false);
3966 mutex_unlock(&rdev->sched_scan_mtx);
3967
3968 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003969}
3970
Johannes Berg9720bb32011-06-21 09:45:33 +02003971static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3972 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003973 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003974 struct wireless_dev *wdev,
3975 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003976{
Johannes Berg48ab9052009-07-10 18:42:31 +02003977 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003978 void *hdr;
3979 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003980 int i;
3981
3982 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003983
Johannes Berg9720bb32011-06-21 09:45:33 +02003984 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003985 NL80211_CMD_NEW_SCAN_RESULTS);
3986 if (!hdr)
3987 return -1;
3988
Johannes Berg9720bb32011-06-21 09:45:33 +02003989 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
3990
Johannes Bergf5ea9122009-08-07 16:17:38 +02003991 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003992 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003993
3994 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3995 if (!bss)
3996 goto nla_put_failure;
3997 if (!is_zero_ether_addr(res->bssid))
3998 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3999 if (res->information_elements && res->len_information_elements)
4000 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4001 res->len_information_elements,
4002 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02004003 if (res->beacon_ies && res->len_beacon_ies &&
4004 res->beacon_ies != res->information_elements)
4005 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
4006 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01004007 if (res->tsf)
4008 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
4009 if (res->beacon_interval)
4010 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
4011 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
4012 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02004013 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
4014 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01004015
Johannes Berg77965c92009-02-18 18:45:06 +01004016 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004017 case CFG80211_SIGNAL_TYPE_MBM:
4018 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
4019 break;
4020 case CFG80211_SIGNAL_TYPE_UNSPEC:
4021 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
4022 break;
4023 default:
4024 break;
4025 }
4026
Johannes Berg48ab9052009-07-10 18:42:31 +02004027 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004028 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004029 case NL80211_IFTYPE_STATION:
4030 if (intbss == wdev->current_bss)
4031 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4032 NL80211_BSS_STATUS_ASSOCIATED);
4033 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
4034 if (intbss != wdev->auth_bsses[i])
4035 continue;
4036 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4037 NL80211_BSS_STATUS_AUTHENTICATED);
4038 break;
4039 }
4040 break;
4041 case NL80211_IFTYPE_ADHOC:
4042 if (intbss == wdev->current_bss)
4043 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4044 NL80211_BSS_STATUS_IBSS_JOINED);
4045 break;
4046 default:
4047 break;
4048 }
4049
Johannes Berg2a519312009-02-10 21:25:55 +01004050 nla_nest_end(msg, bss);
4051
4052 return genlmsg_end(msg, hdr);
4053
4054 nla_put_failure:
4055 genlmsg_cancel(msg, hdr);
4056 return -EMSGSIZE;
4057}
4058
4059static int nl80211_dump_scan(struct sk_buff *skb,
4060 struct netlink_callback *cb)
4061{
Johannes Berg48ab9052009-07-10 18:42:31 +02004062 struct cfg80211_registered_device *rdev;
4063 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004064 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004065 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004066 int start = cb->args[1], idx = 0;
4067 int err;
4068
Johannes Berg67748892010-10-04 21:14:06 +02004069 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4070 if (err)
4071 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004072
Johannes Berg48ab9052009-07-10 18:42:31 +02004073 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004074
Johannes Berg48ab9052009-07-10 18:42:31 +02004075 wdev_lock(wdev);
4076 spin_lock_bh(&rdev->bss_lock);
4077 cfg80211_bss_expire(rdev);
4078
Johannes Berg9720bb32011-06-21 09:45:33 +02004079 cb->seq = rdev->bss_generation;
4080
Johannes Berg48ab9052009-07-10 18:42:31 +02004081 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004082 if (++idx <= start)
4083 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004084 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004085 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004086 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004087 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004088 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004089 }
4090 }
4091
Johannes Berg48ab9052009-07-10 18:42:31 +02004092 spin_unlock_bh(&rdev->bss_lock);
4093 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004094
4095 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004096 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004097
Johannes Berg67748892010-10-04 21:14:06 +02004098 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004099}
4100
Holger Schurig61fa7132009-11-11 12:25:40 +01004101static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4102 int flags, struct net_device *dev,
4103 struct survey_info *survey)
4104{
4105 void *hdr;
4106 struct nlattr *infoattr;
4107
Holger Schurig61fa7132009-11-11 12:25:40 +01004108 hdr = nl80211hdr_put(msg, pid, seq, flags,
4109 NL80211_CMD_NEW_SURVEY_RESULTS);
4110 if (!hdr)
4111 return -ENOMEM;
4112
4113 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4114
4115 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4116 if (!infoattr)
4117 goto nla_put_failure;
4118
4119 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4120 survey->channel->center_freq);
4121 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4122 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4123 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02004124 if (survey->filled & SURVEY_INFO_IN_USE)
4125 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02004126 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4127 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4128 survey->channel_time);
4129 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4130 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4131 survey->channel_time_busy);
4132 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4133 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4134 survey->channel_time_ext_busy);
4135 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4136 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4137 survey->channel_time_rx);
4138 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4139 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4140 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01004141
4142 nla_nest_end(msg, infoattr);
4143
4144 return genlmsg_end(msg, hdr);
4145
4146 nla_put_failure:
4147 genlmsg_cancel(msg, hdr);
4148 return -EMSGSIZE;
4149}
4150
4151static int nl80211_dump_survey(struct sk_buff *skb,
4152 struct netlink_callback *cb)
4153{
4154 struct survey_info survey;
4155 struct cfg80211_registered_device *dev;
4156 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004157 int survey_idx = cb->args[1];
4158 int res;
4159
Johannes Berg67748892010-10-04 21:14:06 +02004160 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4161 if (res)
4162 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004163
4164 if (!dev->ops->dump_survey) {
4165 res = -EOPNOTSUPP;
4166 goto out_err;
4167 }
4168
4169 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004170 struct ieee80211_channel *chan;
4171
Holger Schurig61fa7132009-11-11 12:25:40 +01004172 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4173 &survey);
4174 if (res == -ENOENT)
4175 break;
4176 if (res)
4177 goto out_err;
4178
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004179 /* Survey without a channel doesn't make sense */
4180 if (!survey.channel) {
4181 res = -EINVAL;
4182 goto out;
4183 }
4184
4185 chan = ieee80211_get_channel(&dev->wiphy,
4186 survey.channel->center_freq);
4187 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4188 survey_idx++;
4189 continue;
4190 }
4191
Holger Schurig61fa7132009-11-11 12:25:40 +01004192 if (nl80211_send_survey(skb,
4193 NETLINK_CB(cb->skb).pid,
4194 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4195 netdev,
4196 &survey) < 0)
4197 goto out;
4198 survey_idx++;
4199 }
4200
4201 out:
4202 cb->args[1] = survey_idx;
4203 res = skb->len;
4204 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004205 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004206 return res;
4207}
4208
Jouni Malinen255e7372009-03-20 21:21:17 +02004209static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4210{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004211 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004212}
4213
Samuel Ortizb23aa672009-07-01 21:26:54 +02004214static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4215{
4216 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4217 NL80211_WPA_VERSION_2));
4218}
4219
Jouni Malinen636a5d32009-03-19 13:39:22 +02004220static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4221{
Johannes Berg4c476992010-10-04 21:36:35 +02004222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4223 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004224 struct ieee80211_channel *chan;
4225 const u8 *bssid, *ssid, *ie = NULL;
4226 int err, ssid_len, ie_len = 0;
4227 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004228 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004229 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004230
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004231 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4232 return -EINVAL;
4233
4234 if (!info->attrs[NL80211_ATTR_MAC])
4235 return -EINVAL;
4236
Jouni Malinen17780922009-03-27 20:52:47 +02004237 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4238 return -EINVAL;
4239
Johannes Berg19957bb2009-07-02 17:20:43 +02004240 if (!info->attrs[NL80211_ATTR_SSID])
4241 return -EINVAL;
4242
4243 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4244 return -EINVAL;
4245
Johannes Bergfffd0932009-07-08 14:22:54 +02004246 err = nl80211_parse_key(info, &key);
4247 if (err)
4248 return err;
4249
4250 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004251 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4252 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004253 if (!key.p.key || !key.p.key_len)
4254 return -EINVAL;
4255 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4256 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4257 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4258 key.p.key_len != WLAN_KEY_LEN_WEP104))
4259 return -EINVAL;
4260 if (key.idx > 4)
4261 return -EINVAL;
4262 } else {
4263 key.p.key_len = 0;
4264 key.p.key = NULL;
4265 }
4266
Johannes Bergafea0b72010-08-10 09:46:42 +02004267 if (key.idx >= 0) {
4268 int i;
4269 bool ok = false;
4270 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4271 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4272 ok = true;
4273 break;
4274 }
4275 }
Johannes Berg4c476992010-10-04 21:36:35 +02004276 if (!ok)
4277 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004278 }
4279
Johannes Berg4c476992010-10-04 21:36:35 +02004280 if (!rdev->ops->auth)
4281 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004282
Johannes Berg074ac8d2010-09-16 14:58:22 +02004283 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004284 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4285 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004286
Johannes Berg19957bb2009-07-02 17:20:43 +02004287 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004288 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004289 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004290 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4291 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004292
Johannes Berg19957bb2009-07-02 17:20:43 +02004293 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4294 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4295
4296 if (info->attrs[NL80211_ATTR_IE]) {
4297 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4298 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4299 }
4300
4301 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004302 if (!nl80211_valid_auth_type(auth_type))
4303 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004304
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004305 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4306
Johannes Berg4c476992010-10-04 21:36:35 +02004307 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4308 ssid, ssid_len, ie, ie_len,
4309 key.p.key, key.p.key_len, key.idx,
4310 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004311}
4312
Johannes Bergc0692b82010-08-27 14:26:53 +03004313static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4314 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004315 struct cfg80211_crypto_settings *settings,
4316 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004317{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004318 memset(settings, 0, sizeof(*settings));
4319
Samuel Ortizb23aa672009-07-01 21:26:54 +02004320 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4321
Johannes Bergc0692b82010-08-27 14:26:53 +03004322 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4323 u16 proto;
4324 proto = nla_get_u16(
4325 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4326 settings->control_port_ethertype = cpu_to_be16(proto);
4327 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4328 proto != ETH_P_PAE)
4329 return -EINVAL;
4330 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4331 settings->control_port_no_encrypt = true;
4332 } else
4333 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4334
Samuel Ortizb23aa672009-07-01 21:26:54 +02004335 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4336 void *data;
4337 int len, i;
4338
4339 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4340 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4341 settings->n_ciphers_pairwise = len / sizeof(u32);
4342
4343 if (len % sizeof(u32))
4344 return -EINVAL;
4345
Johannes Berg3dc27d22009-07-02 21:36:37 +02004346 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004347 return -EINVAL;
4348
4349 memcpy(settings->ciphers_pairwise, data, len);
4350
4351 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004352 if (!cfg80211_supported_cipher_suite(
4353 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004354 settings->ciphers_pairwise[i]))
4355 return -EINVAL;
4356 }
4357
4358 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4359 settings->cipher_group =
4360 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004361 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4362 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004363 return -EINVAL;
4364 }
4365
4366 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4367 settings->wpa_versions =
4368 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4369 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4370 return -EINVAL;
4371 }
4372
4373 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4374 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004375 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004376
4377 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4378 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4379 settings->n_akm_suites = len / sizeof(u32);
4380
4381 if (len % sizeof(u32))
4382 return -EINVAL;
4383
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004384 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4385 return -EINVAL;
4386
Samuel Ortizb23aa672009-07-01 21:26:54 +02004387 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004388 }
4389
4390 return 0;
4391}
4392
Jouni Malinen636a5d32009-03-19 13:39:22 +02004393static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4394{
Johannes Berg4c476992010-10-04 21:36:35 +02004395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4396 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004397 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004398 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004399 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004400 int err, ssid_len, ie_len = 0;
4401 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004402
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004403 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4404 return -EINVAL;
4405
4406 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004407 !info->attrs[NL80211_ATTR_SSID] ||
4408 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004409 return -EINVAL;
4410
Johannes Berg4c476992010-10-04 21:36:35 +02004411 if (!rdev->ops->assoc)
4412 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004413
Johannes Berg074ac8d2010-09-16 14:58:22 +02004414 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004415 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4416 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004417
Johannes Berg19957bb2009-07-02 17:20:43 +02004418 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004419
Johannes Berg19957bb2009-07-02 17:20:43 +02004420 chan = ieee80211_get_channel(&rdev->wiphy,
4421 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004422 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4423 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004424
Johannes Berg19957bb2009-07-02 17:20:43 +02004425 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4426 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004427
4428 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004429 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4430 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004431 }
4432
Jouni Malinendc6382c2009-05-06 22:09:37 +03004433 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004434 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004435 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004436 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004437 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004438 else if (mfp != NL80211_MFP_NO)
4439 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004440 }
4441
Johannes Berg3e5d7642009-07-07 14:37:26 +02004442 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4443 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4444
Johannes Bergc0692b82010-08-27 14:26:53 +03004445 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004446 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004447 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4448 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02004449 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004450
Jouni Malinen636a5d32009-03-19 13:39:22 +02004451 return err;
4452}
4453
4454static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4455{
Johannes Berg4c476992010-10-04 21:36:35 +02004456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4457 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004458 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004459 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004460 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004461 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004462
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004463 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4464 return -EINVAL;
4465
4466 if (!info->attrs[NL80211_ATTR_MAC])
4467 return -EINVAL;
4468
4469 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4470 return -EINVAL;
4471
Johannes Berg4c476992010-10-04 21:36:35 +02004472 if (!rdev->ops->deauth)
4473 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004474
Johannes Berg074ac8d2010-09-16 14:58:22 +02004475 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004476 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4477 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004478
Johannes Berg19957bb2009-07-02 17:20:43 +02004479 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004480
Johannes Berg19957bb2009-07-02 17:20:43 +02004481 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4482 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004483 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004484 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004485 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004486
4487 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004488 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4489 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004490 }
4491
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004492 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4493
Johannes Berg4c476992010-10-04 21:36:35 +02004494 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4495 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004496}
4497
4498static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4499{
Johannes Berg4c476992010-10-04 21:36:35 +02004500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4501 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004502 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004503 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004504 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004505 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004506
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004507 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4508 return -EINVAL;
4509
4510 if (!info->attrs[NL80211_ATTR_MAC])
4511 return -EINVAL;
4512
4513 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4514 return -EINVAL;
4515
Johannes Berg4c476992010-10-04 21:36:35 +02004516 if (!rdev->ops->disassoc)
4517 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004518
Johannes Berg074ac8d2010-09-16 14:58:22 +02004519 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004520 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4521 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004522
Johannes Berg19957bb2009-07-02 17:20:43 +02004523 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004524
Johannes Berg19957bb2009-07-02 17:20:43 +02004525 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4526 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004527 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004528 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004529 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004530
4531 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004532 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4533 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004534 }
4535
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004536 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4537
Johannes Berg4c476992010-10-04 21:36:35 +02004538 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4539 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004540}
4541
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004542static bool
4543nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4544 int mcast_rate[IEEE80211_NUM_BANDS],
4545 int rateval)
4546{
4547 struct wiphy *wiphy = &rdev->wiphy;
4548 bool found = false;
4549 int band, i;
4550
4551 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4552 struct ieee80211_supported_band *sband;
4553
4554 sband = wiphy->bands[band];
4555 if (!sband)
4556 continue;
4557
4558 for (i = 0; i < sband->n_bitrates; i++) {
4559 if (sband->bitrates[i].bitrate == rateval) {
4560 mcast_rate[band] = i + 1;
4561 found = true;
4562 break;
4563 }
4564 }
4565 }
4566
4567 return found;
4568}
4569
Johannes Berg04a773a2009-04-19 21:24:32 +02004570static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4571{
Johannes Berg4c476992010-10-04 21:36:35 +02004572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4573 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004574 struct cfg80211_ibss_params ibss;
4575 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004576 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004577 int err;
4578
Johannes Berg8e30bc52009-04-22 17:45:38 +02004579 memset(&ibss, 0, sizeof(ibss));
4580
Johannes Berg04a773a2009-04-19 21:24:32 +02004581 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4582 return -EINVAL;
4583
4584 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4585 !info->attrs[NL80211_ATTR_SSID] ||
4586 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4587 return -EINVAL;
4588
Johannes Berg8e30bc52009-04-22 17:45:38 +02004589 ibss.beacon_interval = 100;
4590
4591 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4592 ibss.beacon_interval =
4593 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4594 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4595 return -EINVAL;
4596 }
4597
Johannes Berg4c476992010-10-04 21:36:35 +02004598 if (!rdev->ops->join_ibss)
4599 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004600
Johannes Berg4c476992010-10-04 21:36:35 +02004601 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4602 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004603
Johannes Berg79c97e92009-07-07 03:56:12 +02004604 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004605
Johannes Berg39193492011-09-16 13:45:25 +02004606 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02004607 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02004608
4609 if (!is_valid_ether_addr(ibss.bssid))
4610 return -EINVAL;
4611 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004612 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4613 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4614
4615 if (info->attrs[NL80211_ATTR_IE]) {
4616 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4617 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4618 }
4619
4620 ibss.channel = ieee80211_get_channel(wiphy,
4621 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4622 if (!ibss.channel ||
4623 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004624 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4625 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004626
4627 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004628 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004629
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004630 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4631 u8 *rates =
4632 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4633 int n_rates =
4634 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4635 struct ieee80211_supported_band *sband =
4636 wiphy->bands[ibss.channel->band];
Johannes Berg34850ab2011-07-18 18:08:35 +02004637 int err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004638
Johannes Berg34850ab2011-07-18 18:08:35 +02004639 err = ieee80211_get_ratemask(sband, rates, n_rates,
4640 &ibss.basic_rates);
4641 if (err)
4642 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004643 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004644
4645 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4646 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4647 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4648 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004649
Johannes Berg4c476992010-10-04 21:36:35 +02004650 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4651 connkeys = nl80211_parse_connkeys(rdev,
4652 info->attrs[NL80211_ATTR_KEYS]);
4653 if (IS_ERR(connkeys))
4654 return PTR_ERR(connkeys);
4655 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004656
Johannes Berg4c476992010-10-04 21:36:35 +02004657 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004658 if (err)
4659 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004660 return err;
4661}
4662
4663static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4664{
Johannes Berg4c476992010-10-04 21:36:35 +02004665 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4666 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004667
Johannes Berg4c476992010-10-04 21:36:35 +02004668 if (!rdev->ops->leave_ibss)
4669 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004670
Johannes Berg4c476992010-10-04 21:36:35 +02004671 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4672 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004673
Johannes Berg4c476992010-10-04 21:36:35 +02004674 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004675}
4676
Johannes Bergaff89a92009-07-01 21:26:51 +02004677#ifdef CONFIG_NL80211_TESTMODE
4678static struct genl_multicast_group nl80211_testmode_mcgrp = {
4679 .name = "testmode",
4680};
4681
4682static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4683{
Johannes Berg4c476992010-10-04 21:36:35 +02004684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004685 int err;
4686
4687 if (!info->attrs[NL80211_ATTR_TESTDATA])
4688 return -EINVAL;
4689
Johannes Bergaff89a92009-07-01 21:26:51 +02004690 err = -EOPNOTSUPP;
4691 if (rdev->ops->testmode_cmd) {
4692 rdev->testmode_info = info;
4693 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4694 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4695 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4696 rdev->testmode_info = NULL;
4697 }
4698
Johannes Bergaff89a92009-07-01 21:26:51 +02004699 return err;
4700}
4701
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004702static int nl80211_testmode_dump(struct sk_buff *skb,
4703 struct netlink_callback *cb)
4704{
4705 struct cfg80211_registered_device *dev;
4706 int err;
4707 long phy_idx;
4708 void *data = NULL;
4709 int data_len = 0;
4710
4711 if (cb->args[0]) {
4712 /*
4713 * 0 is a valid index, but not valid for args[0],
4714 * so we need to offset by 1.
4715 */
4716 phy_idx = cb->args[0] - 1;
4717 } else {
4718 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4719 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4720 nl80211_policy);
4721 if (err)
4722 return err;
4723 if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY])
4724 return -EINVAL;
4725 phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4726 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4727 cb->args[1] =
4728 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4729 }
4730
4731 if (cb->args[1]) {
4732 data = nla_data((void *)cb->args[1]);
4733 data_len = nla_len((void *)cb->args[1]);
4734 }
4735
4736 mutex_lock(&cfg80211_mutex);
4737 dev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4738 if (!dev) {
4739 mutex_unlock(&cfg80211_mutex);
4740 return -ENOENT;
4741 }
4742 cfg80211_lock_rdev(dev);
4743 mutex_unlock(&cfg80211_mutex);
4744
4745 if (!dev->ops->testmode_dump) {
4746 err = -EOPNOTSUPP;
4747 goto out_err;
4748 }
4749
4750 while (1) {
4751 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4752 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4753 NL80211_CMD_TESTMODE);
4754 struct nlattr *tmdata;
4755
4756 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) {
4757 genlmsg_cancel(skb, hdr);
4758 break;
4759 }
4760
4761 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4762 if (!tmdata) {
4763 genlmsg_cancel(skb, hdr);
4764 break;
4765 }
4766 err = dev->ops->testmode_dump(&dev->wiphy, skb, cb,
4767 data, data_len);
4768 nla_nest_end(skb, tmdata);
4769
4770 if (err == -ENOBUFS || err == -ENOENT) {
4771 genlmsg_cancel(skb, hdr);
4772 break;
4773 } else if (err) {
4774 genlmsg_cancel(skb, hdr);
4775 goto out_err;
4776 }
4777
4778 genlmsg_end(skb, hdr);
4779 }
4780
4781 err = skb->len;
4782 /* see above */
4783 cb->args[0] = phy_idx + 1;
4784 out_err:
4785 cfg80211_unlock_rdev(dev);
4786 return err;
4787}
4788
Johannes Bergaff89a92009-07-01 21:26:51 +02004789static struct sk_buff *
4790__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4791 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4792{
4793 struct sk_buff *skb;
4794 void *hdr;
4795 struct nlattr *data;
4796
4797 skb = nlmsg_new(approxlen + 100, gfp);
4798 if (!skb)
4799 return NULL;
4800
4801 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4802 if (!hdr) {
4803 kfree_skb(skb);
4804 return NULL;
4805 }
4806
4807 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4808 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4809
4810 ((void **)skb->cb)[0] = rdev;
4811 ((void **)skb->cb)[1] = hdr;
4812 ((void **)skb->cb)[2] = data;
4813
4814 return skb;
4815
4816 nla_put_failure:
4817 kfree_skb(skb);
4818 return NULL;
4819}
4820
4821struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4822 int approxlen)
4823{
4824 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4825
4826 if (WARN_ON(!rdev->testmode_info))
4827 return NULL;
4828
4829 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4830 rdev->testmode_info->snd_pid,
4831 rdev->testmode_info->snd_seq,
4832 GFP_KERNEL);
4833}
4834EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4835
4836int cfg80211_testmode_reply(struct sk_buff *skb)
4837{
4838 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4839 void *hdr = ((void **)skb->cb)[1];
4840 struct nlattr *data = ((void **)skb->cb)[2];
4841
4842 if (WARN_ON(!rdev->testmode_info)) {
4843 kfree_skb(skb);
4844 return -EINVAL;
4845 }
4846
4847 nla_nest_end(skb, data);
4848 genlmsg_end(skb, hdr);
4849 return genlmsg_reply(skb, rdev->testmode_info);
4850}
4851EXPORT_SYMBOL(cfg80211_testmode_reply);
4852
4853struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4854 int approxlen, gfp_t gfp)
4855{
4856 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4857
4858 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4859}
4860EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4861
4862void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4863{
4864 void *hdr = ((void **)skb->cb)[1];
4865 struct nlattr *data = ((void **)skb->cb)[2];
4866
4867 nla_nest_end(skb, data);
4868 genlmsg_end(skb, hdr);
4869 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4870}
4871EXPORT_SYMBOL(cfg80211_testmode_event);
4872#endif
4873
Samuel Ortizb23aa672009-07-01 21:26:54 +02004874static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4875{
Johannes Berg4c476992010-10-04 21:36:35 +02004876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4877 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004878 struct cfg80211_connect_params connect;
4879 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004880 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004881 int err;
4882
4883 memset(&connect, 0, sizeof(connect));
4884
4885 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4886 return -EINVAL;
4887
4888 if (!info->attrs[NL80211_ATTR_SSID] ||
4889 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4890 return -EINVAL;
4891
4892 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4893 connect.auth_type =
4894 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4895 if (!nl80211_valid_auth_type(connect.auth_type))
4896 return -EINVAL;
4897 } else
4898 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4899
4900 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4901
Johannes Bergc0692b82010-08-27 14:26:53 +03004902 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004903 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004904 if (err)
4905 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004906
Johannes Berg074ac8d2010-09-16 14:58:22 +02004907 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004908 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4909 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004910
Johannes Berg79c97e92009-07-07 03:56:12 +02004911 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004912
Samuel Ortizb23aa672009-07-01 21:26:54 +02004913 if (info->attrs[NL80211_ATTR_MAC])
4914 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4915 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4916 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4917
4918 if (info->attrs[NL80211_ATTR_IE]) {
4919 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4920 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4921 }
4922
4923 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4924 connect.channel =
4925 ieee80211_get_channel(wiphy,
4926 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4927 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004928 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4929 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004930 }
4931
Johannes Bergfffd0932009-07-08 14:22:54 +02004932 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4933 connkeys = nl80211_parse_connkeys(rdev,
4934 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004935 if (IS_ERR(connkeys))
4936 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004937 }
4938
4939 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004940 if (err)
4941 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004942 return err;
4943}
4944
4945static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4946{
Johannes Berg4c476992010-10-04 21:36:35 +02004947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4948 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004949 u16 reason;
4950
4951 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4952 reason = WLAN_REASON_DEAUTH_LEAVING;
4953 else
4954 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4955
4956 if (reason == 0)
4957 return -EINVAL;
4958
Johannes Berg074ac8d2010-09-16 14:58:22 +02004959 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004960 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4961 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004962
Johannes Berg4c476992010-10-04 21:36:35 +02004963 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004964}
4965
Johannes Berg463d0182009-07-14 00:33:35 +02004966static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4967{
Johannes Berg4c476992010-10-04 21:36:35 +02004968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004969 struct net *net;
4970 int err;
4971 u32 pid;
4972
4973 if (!info->attrs[NL80211_ATTR_PID])
4974 return -EINVAL;
4975
4976 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4977
Johannes Berg463d0182009-07-14 00:33:35 +02004978 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004979 if (IS_ERR(net))
4980 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004981
4982 err = 0;
4983
4984 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004985 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4986 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004987
Johannes Berg463d0182009-07-14 00:33:35 +02004988 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004989 return err;
4990}
4991
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004992static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4993{
Johannes Berg4c476992010-10-04 21:36:35 +02004994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004995 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4996 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004997 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004998 struct cfg80211_pmksa pmksa;
4999
5000 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5001
5002 if (!info->attrs[NL80211_ATTR_MAC])
5003 return -EINVAL;
5004
5005 if (!info->attrs[NL80211_ATTR_PMKID])
5006 return -EINVAL;
5007
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005008 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5009 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5010
Johannes Berg074ac8d2010-09-16 14:58:22 +02005011 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005012 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5013 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005014
5015 switch (info->genlhdr->cmd) {
5016 case NL80211_CMD_SET_PMKSA:
5017 rdev_ops = rdev->ops->set_pmksa;
5018 break;
5019 case NL80211_CMD_DEL_PMKSA:
5020 rdev_ops = rdev->ops->del_pmksa;
5021 break;
5022 default:
5023 WARN_ON(1);
5024 break;
5025 }
5026
Johannes Berg4c476992010-10-04 21:36:35 +02005027 if (!rdev_ops)
5028 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005029
Johannes Berg4c476992010-10-04 21:36:35 +02005030 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005031}
5032
5033static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5034{
Johannes Berg4c476992010-10-04 21:36:35 +02005035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5036 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005037
Johannes Berg074ac8d2010-09-16 14:58:22 +02005038 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005039 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5040 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005041
Johannes Berg4c476992010-10-04 21:36:35 +02005042 if (!rdev->ops->flush_pmksa)
5043 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005044
Johannes Berg4c476992010-10-04 21:36:35 +02005045 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005046}
5047
Arik Nemtsov109086c2011-09-28 14:12:50 +03005048static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5049{
5050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5051 struct net_device *dev = info->user_ptr[1];
5052 u8 action_code, dialog_token;
5053 u16 status_code;
5054 u8 *peer;
5055
5056 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5057 !rdev->ops->tdls_mgmt)
5058 return -EOPNOTSUPP;
5059
5060 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5061 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5062 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5063 !info->attrs[NL80211_ATTR_IE] ||
5064 !info->attrs[NL80211_ATTR_MAC])
5065 return -EINVAL;
5066
5067 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5068 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5069 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5070 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5071
5072 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5073 dialog_token, status_code,
5074 nla_data(info->attrs[NL80211_ATTR_IE]),
5075 nla_len(info->attrs[NL80211_ATTR_IE]));
5076}
5077
5078static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5079{
5080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5081 struct net_device *dev = info->user_ptr[1];
5082 enum nl80211_tdls_operation operation;
5083 u8 *peer;
5084
5085 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5086 !rdev->ops->tdls_oper)
5087 return -EOPNOTSUPP;
5088
5089 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5090 !info->attrs[NL80211_ATTR_MAC])
5091 return -EINVAL;
5092
5093 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5094 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5095
5096 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5097}
5098
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005099static int nl80211_remain_on_channel(struct sk_buff *skb,
5100 struct genl_info *info)
5101{
Johannes Berg4c476992010-10-04 21:36:35 +02005102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5103 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005104 struct ieee80211_channel *chan;
5105 struct sk_buff *msg;
5106 void *hdr;
5107 u64 cookie;
5108 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5109 u32 freq, duration;
5110 int err;
5111
5112 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5113 !info->attrs[NL80211_ATTR_DURATION])
5114 return -EINVAL;
5115
5116 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5117
5118 /*
5119 * We should be on that channel for at least one jiffie,
5120 * and more than 5 seconds seems excessive.
5121 */
Johannes Berga2939112010-12-14 17:54:28 +01005122 if (!duration || !msecs_to_jiffies(duration) ||
5123 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005124 return -EINVAL;
5125
Johannes Berg4c476992010-10-04 21:36:35 +02005126 if (!rdev->ops->remain_on_channel)
5127 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005128
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005129 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5130 channel_type = nla_get_u32(
5131 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5132 if (channel_type != NL80211_CHAN_NO_HT &&
5133 channel_type != NL80211_CHAN_HT20 &&
5134 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005135 channel_type != NL80211_CHAN_HT40MINUS)
5136 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005137 }
5138
5139 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5140 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005141 if (chan == NULL)
5142 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005143
5144 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005145 if (!msg)
5146 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005147
5148 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5149 NL80211_CMD_REMAIN_ON_CHANNEL);
5150
5151 if (IS_ERR(hdr)) {
5152 err = PTR_ERR(hdr);
5153 goto free_msg;
5154 }
5155
5156 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5157 channel_type, duration, &cookie);
5158
5159 if (err)
5160 goto free_msg;
5161
5162 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5163
5164 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005165
5166 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005167
5168 nla_put_failure:
5169 err = -ENOBUFS;
5170 free_msg:
5171 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005172 return err;
5173}
5174
5175static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5176 struct genl_info *info)
5177{
Johannes Berg4c476992010-10-04 21:36:35 +02005178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5179 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005180 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005181
5182 if (!info->attrs[NL80211_ATTR_COOKIE])
5183 return -EINVAL;
5184
Johannes Berg4c476992010-10-04 21:36:35 +02005185 if (!rdev->ops->cancel_remain_on_channel)
5186 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005187
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005188 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5189
Johannes Berg4c476992010-10-04 21:36:35 +02005190 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005191}
5192
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005193static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5194 u8 *rates, u8 rates_len)
5195{
5196 u8 i;
5197 u32 mask = 0;
5198
5199 for (i = 0; i < rates_len; i++) {
5200 int rate = (rates[i] & 0x7f) * 5;
5201 int ridx;
5202 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5203 struct ieee80211_rate *srate =
5204 &sband->bitrates[ridx];
5205 if (rate == srate->bitrate) {
5206 mask |= 1 << ridx;
5207 break;
5208 }
5209 }
5210 if (ridx == sband->n_bitrates)
5211 return 0; /* rate not found */
5212 }
5213
5214 return mask;
5215}
5216
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005217static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005218 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5219 .len = NL80211_MAX_SUPP_RATES },
5220};
5221
5222static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5223 struct genl_info *info)
5224{
5225 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005227 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005228 int rem, i;
5229 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005230 struct nlattr *tx_rates;
5231 struct ieee80211_supported_band *sband;
5232
5233 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5234 return -EINVAL;
5235
Johannes Berg4c476992010-10-04 21:36:35 +02005236 if (!rdev->ops->set_bitrate_mask)
5237 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005238
5239 memset(&mask, 0, sizeof(mask));
5240 /* Default to all rates enabled */
5241 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5242 sband = rdev->wiphy.bands[i];
5243 mask.control[i].legacy =
5244 sband ? (1 << sband->n_bitrates) - 1 : 0;
5245 }
5246
5247 /*
5248 * The nested attribute uses enum nl80211_band as the index. This maps
5249 * directly to the enum ieee80211_band values used in cfg80211.
5250 */
5251 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5252 {
5253 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005254 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5255 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005256 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005257 if (sband == NULL)
5258 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005259 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5260 nla_len(tx_rates), nl80211_txattr_policy);
5261 if (tb[NL80211_TXRATE_LEGACY]) {
5262 mask.control[band].legacy = rateset_to_mask(
5263 sband,
5264 nla_data(tb[NL80211_TXRATE_LEGACY]),
5265 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02005266 if (mask.control[band].legacy == 0)
5267 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005268 }
5269 }
5270
Johannes Berg4c476992010-10-04 21:36:35 +02005271 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005272}
5273
Johannes Berg2e161f72010-08-12 15:38:38 +02005274static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005275{
Johannes Berg4c476992010-10-04 21:36:35 +02005276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5277 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005278 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005279
5280 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5281 return -EINVAL;
5282
Johannes Berg2e161f72010-08-12 15:38:38 +02005283 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5284 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005285
Johannes Berg9d38d852010-06-09 17:20:33 +02005286 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005287 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005288 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005291 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005292 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5293 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005294
5295 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005296 if (!rdev->ops->mgmt_tx)
5297 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005298
Johannes Berg4c476992010-10-04 21:36:35 +02005299 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005300 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005301 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5302 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005303}
5304
Johannes Berg2e161f72010-08-12 15:38:38 +02005305static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005306{
Johannes Berg4c476992010-10-04 21:36:35 +02005307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5308 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005309 struct ieee80211_channel *chan;
5310 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005311 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005312 u32 freq;
5313 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005314 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005315 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005316 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005317 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005318 bool offchan, no_cck, dont_wait_for_ack;
5319
5320 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005321
5322 if (!info->attrs[NL80211_ATTR_FRAME] ||
5323 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5324 return -EINVAL;
5325
Johannes Berg4c476992010-10-04 21:36:35 +02005326 if (!rdev->ops->mgmt_tx)
5327 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005328
Johannes Berg9d38d852010-06-09 17:20:33 +02005329 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005330 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005331 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5332 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5333 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005334 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005335 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5336 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005337
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005338 if (info->attrs[NL80211_ATTR_DURATION]) {
5339 if (!rdev->ops->mgmt_tx_cancel_wait)
5340 return -EINVAL;
5341 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5342 }
5343
Jouni Malinen026331c2010-02-15 12:53:10 +02005344 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5345 channel_type = nla_get_u32(
5346 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5347 if (channel_type != NL80211_CHAN_NO_HT &&
5348 channel_type != NL80211_CHAN_HT20 &&
5349 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005350 channel_type != NL80211_CHAN_HT40MINUS)
5351 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005352 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005353 }
5354
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005355 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5356
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305357 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5358
Jouni Malinen026331c2010-02-15 12:53:10 +02005359 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5360 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005361 if (chan == NULL)
5362 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005363
Johannes Berge247bd902011-11-04 11:18:21 +01005364 if (!dont_wait_for_ack) {
5365 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5366 if (!msg)
5367 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005368
Johannes Berge247bd902011-11-04 11:18:21 +01005369 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5370 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005371
Johannes Berge247bd902011-11-04 11:18:21 +01005372 if (IS_ERR(hdr)) {
5373 err = PTR_ERR(hdr);
5374 goto free_msg;
5375 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005376 }
Johannes Berge247bd902011-11-04 11:18:21 +01005377
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005378 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5379 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005380 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5381 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005382 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005383 if (err)
5384 goto free_msg;
5385
Johannes Berge247bd902011-11-04 11:18:21 +01005386 if (msg) {
5387 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005388
Johannes Berge247bd902011-11-04 11:18:21 +01005389 genlmsg_end(msg, hdr);
5390 return genlmsg_reply(msg, info);
5391 }
5392
5393 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02005394
5395 nla_put_failure:
5396 err = -ENOBUFS;
5397 free_msg:
5398 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005399 return err;
5400}
5401
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005402static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5403{
5404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5405 struct net_device *dev = info->user_ptr[1];
5406 u64 cookie;
5407
5408 if (!info->attrs[NL80211_ATTR_COOKIE])
5409 return -EINVAL;
5410
5411 if (!rdev->ops->mgmt_tx_cancel_wait)
5412 return -EOPNOTSUPP;
5413
5414 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5415 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5416 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5417 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5418 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5419 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5420 return -EOPNOTSUPP;
5421
5422 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5423
5424 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5425}
5426
Kalle Valoffb9eb32010-02-17 17:58:10 +02005427static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5428{
Johannes Berg4c476992010-10-04 21:36:35 +02005429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005430 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005431 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005432 u8 ps_state;
5433 bool state;
5434 int err;
5435
Johannes Berg4c476992010-10-04 21:36:35 +02005436 if (!info->attrs[NL80211_ATTR_PS_STATE])
5437 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005438
5439 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5440
Johannes Berg4c476992010-10-04 21:36:35 +02005441 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5442 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005443
5444 wdev = dev->ieee80211_ptr;
5445
Johannes Berg4c476992010-10-04 21:36:35 +02005446 if (!rdev->ops->set_power_mgmt)
5447 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005448
5449 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5450
5451 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005452 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005453
Johannes Berg4c476992010-10-04 21:36:35 +02005454 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5455 wdev->ps_timeout);
5456 if (!err)
5457 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005458 return err;
5459}
5460
5461static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5462{
Johannes Berg4c476992010-10-04 21:36:35 +02005463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005464 enum nl80211_ps_state ps_state;
5465 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005466 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005467 struct sk_buff *msg;
5468 void *hdr;
5469 int err;
5470
Kalle Valoffb9eb32010-02-17 17:58:10 +02005471 wdev = dev->ieee80211_ptr;
5472
Johannes Berg4c476992010-10-04 21:36:35 +02005473 if (!rdev->ops->set_power_mgmt)
5474 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005475
5476 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005477 if (!msg)
5478 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005479
5480 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5481 NL80211_CMD_GET_POWER_SAVE);
5482 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005483 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005484 goto free_msg;
5485 }
5486
5487 if (wdev->ps)
5488 ps_state = NL80211_PS_ENABLED;
5489 else
5490 ps_state = NL80211_PS_DISABLED;
5491
5492 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5493
5494 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005495 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005496
Johannes Berg4c476992010-10-04 21:36:35 +02005497 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005498 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005499 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005500 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005501 return err;
5502}
5503
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005504static struct nla_policy
5505nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5506 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5507 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5508 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5509};
5510
5511static int nl80211_set_cqm_rssi(struct genl_info *info,
5512 s32 threshold, u32 hysteresis)
5513{
Johannes Berg4c476992010-10-04 21:36:35 +02005514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005515 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005516 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005517
5518 if (threshold > 0)
5519 return -EINVAL;
5520
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005521 wdev = dev->ieee80211_ptr;
5522
Johannes Berg4c476992010-10-04 21:36:35 +02005523 if (!rdev->ops->set_cqm_rssi_config)
5524 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005525
Johannes Berg074ac8d2010-09-16 14:58:22 +02005526 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005527 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5528 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005529
Johannes Berg4c476992010-10-04 21:36:35 +02005530 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5531 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005532}
5533
5534static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5535{
5536 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5537 struct nlattr *cqm;
5538 int err;
5539
5540 cqm = info->attrs[NL80211_ATTR_CQM];
5541 if (!cqm) {
5542 err = -EINVAL;
5543 goto out;
5544 }
5545
5546 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5547 nl80211_attr_cqm_policy);
5548 if (err)
5549 goto out;
5550
5551 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5552 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5553 s32 threshold;
5554 u32 hysteresis;
5555 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5556 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5557 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5558 } else
5559 err = -EINVAL;
5560
5561out:
5562 return err;
5563}
5564
Johannes Berg29cbe682010-12-03 09:20:44 +01005565static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5566{
5567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5568 struct net_device *dev = info->user_ptr[1];
5569 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005570 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005571 int err;
5572
5573 /* start with default */
5574 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005575 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005576
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005577 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005578 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005579 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005580 if (err)
5581 return err;
5582 }
5583
5584 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5585 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5586 return -EINVAL;
5587
Javier Cardonac80d5452010-12-16 17:37:49 -08005588 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5589 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5590
5591 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5592 /* parse additional setup parameters if given */
5593 err = nl80211_parse_mesh_setup(info, &setup);
5594 if (err)
5595 return err;
5596 }
5597
5598 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005599}
5600
5601static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5602{
5603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5604 struct net_device *dev = info->user_ptr[1];
5605
5606 return cfg80211_leave_mesh(rdev, dev);
5607}
5608
Johannes Bergff1b6e62011-05-04 15:37:28 +02005609static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5610{
5611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5612 struct sk_buff *msg;
5613 void *hdr;
5614
5615 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5616 return -EOPNOTSUPP;
5617
5618 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5619 if (!msg)
5620 return -ENOMEM;
5621
5622 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5623 NL80211_CMD_GET_WOWLAN);
5624 if (!hdr)
5625 goto nla_put_failure;
5626
5627 if (rdev->wowlan) {
5628 struct nlattr *nl_wowlan;
5629
5630 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5631 if (!nl_wowlan)
5632 goto nla_put_failure;
5633
5634 if (rdev->wowlan->any)
5635 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5636 if (rdev->wowlan->disconnect)
5637 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5638 if (rdev->wowlan->magic_pkt)
5639 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005640 if (rdev->wowlan->gtk_rekey_failure)
5641 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5642 if (rdev->wowlan->eap_identity_req)
5643 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5644 if (rdev->wowlan->four_way_handshake)
5645 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5646 if (rdev->wowlan->rfkill_release)
5647 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005648 if (rdev->wowlan->n_patterns) {
5649 struct nlattr *nl_pats, *nl_pat;
5650 int i, pat_len;
5651
5652 nl_pats = nla_nest_start(msg,
5653 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5654 if (!nl_pats)
5655 goto nla_put_failure;
5656
5657 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5658 nl_pat = nla_nest_start(msg, i + 1);
5659 if (!nl_pat)
5660 goto nla_put_failure;
5661 pat_len = rdev->wowlan->patterns[i].pattern_len;
5662 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5663 DIV_ROUND_UP(pat_len, 8),
5664 rdev->wowlan->patterns[i].mask);
5665 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5666 pat_len,
5667 rdev->wowlan->patterns[i].pattern);
5668 nla_nest_end(msg, nl_pat);
5669 }
5670 nla_nest_end(msg, nl_pats);
5671 }
5672
5673 nla_nest_end(msg, nl_wowlan);
5674 }
5675
5676 genlmsg_end(msg, hdr);
5677 return genlmsg_reply(msg, info);
5678
5679nla_put_failure:
5680 nlmsg_free(msg);
5681 return -ENOBUFS;
5682}
5683
5684static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5685{
5686 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5687 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5688 struct cfg80211_wowlan no_triggers = {};
5689 struct cfg80211_wowlan new_triggers = {};
5690 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5691 int err, i;
5692
5693 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5694 return -EOPNOTSUPP;
5695
5696 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5697 goto no_triggers;
5698
5699 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5700 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5701 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5702 nl80211_wowlan_policy);
5703 if (err)
5704 return err;
5705
5706 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5707 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5708 return -EINVAL;
5709 new_triggers.any = true;
5710 }
5711
5712 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5713 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5714 return -EINVAL;
5715 new_triggers.disconnect = true;
5716 }
5717
5718 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5719 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5720 return -EINVAL;
5721 new_triggers.magic_pkt = true;
5722 }
5723
Johannes Berg77dbbb12011-07-13 10:48:55 +02005724 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5725 return -EINVAL;
5726
5727 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5728 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5729 return -EINVAL;
5730 new_triggers.gtk_rekey_failure = true;
5731 }
5732
5733 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5734 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5735 return -EINVAL;
5736 new_triggers.eap_identity_req = true;
5737 }
5738
5739 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5740 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5741 return -EINVAL;
5742 new_triggers.four_way_handshake = true;
5743 }
5744
5745 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5746 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5747 return -EINVAL;
5748 new_triggers.rfkill_release = true;
5749 }
5750
Johannes Bergff1b6e62011-05-04 15:37:28 +02005751 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5752 struct nlattr *pat;
5753 int n_patterns = 0;
5754 int rem, pat_len, mask_len;
5755 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5756
5757 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5758 rem)
5759 n_patterns++;
5760 if (n_patterns > wowlan->n_patterns)
5761 return -EINVAL;
5762
5763 new_triggers.patterns = kcalloc(n_patterns,
5764 sizeof(new_triggers.patterns[0]),
5765 GFP_KERNEL);
5766 if (!new_triggers.patterns)
5767 return -ENOMEM;
5768
5769 new_triggers.n_patterns = n_patterns;
5770 i = 0;
5771
5772 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5773 rem) {
5774 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5775 nla_data(pat), nla_len(pat), NULL);
5776 err = -EINVAL;
5777 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5778 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5779 goto error;
5780 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5781 mask_len = DIV_ROUND_UP(pat_len, 8);
5782 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5783 mask_len)
5784 goto error;
5785 if (pat_len > wowlan->pattern_max_len ||
5786 pat_len < wowlan->pattern_min_len)
5787 goto error;
5788
5789 new_triggers.patterns[i].mask =
5790 kmalloc(mask_len + pat_len, GFP_KERNEL);
5791 if (!new_triggers.patterns[i].mask) {
5792 err = -ENOMEM;
5793 goto error;
5794 }
5795 new_triggers.patterns[i].pattern =
5796 new_triggers.patterns[i].mask + mask_len;
5797 memcpy(new_triggers.patterns[i].mask,
5798 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5799 mask_len);
5800 new_triggers.patterns[i].pattern_len = pat_len;
5801 memcpy(new_triggers.patterns[i].pattern,
5802 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5803 pat_len);
5804 i++;
5805 }
5806 }
5807
5808 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5809 struct cfg80211_wowlan *ntrig;
5810 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5811 GFP_KERNEL);
5812 if (!ntrig) {
5813 err = -ENOMEM;
5814 goto error;
5815 }
5816 cfg80211_rdev_free_wowlan(rdev);
5817 rdev->wowlan = ntrig;
5818 } else {
5819 no_triggers:
5820 cfg80211_rdev_free_wowlan(rdev);
5821 rdev->wowlan = NULL;
5822 }
5823
5824 return 0;
5825 error:
5826 for (i = 0; i < new_triggers.n_patterns; i++)
5827 kfree(new_triggers.patterns[i].mask);
5828 kfree(new_triggers.patterns);
5829 return err;
5830}
5831
Johannes Berge5497d72011-07-05 16:35:40 +02005832static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
5833{
5834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5835 struct net_device *dev = info->user_ptr[1];
5836 struct wireless_dev *wdev = dev->ieee80211_ptr;
5837 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
5838 struct cfg80211_gtk_rekey_data rekey_data;
5839 int err;
5840
5841 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
5842 return -EINVAL;
5843
5844 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
5845 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
5846 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
5847 nl80211_rekey_policy);
5848 if (err)
5849 return err;
5850
5851 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
5852 return -ERANGE;
5853 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
5854 return -ERANGE;
5855 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
5856 return -ERANGE;
5857
5858 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
5859 NL80211_KEK_LEN);
5860 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
5861 NL80211_KCK_LEN);
5862 memcpy(rekey_data.replay_ctr,
5863 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
5864 NL80211_REPLAY_CTR_LEN);
5865
5866 wdev_lock(wdev);
5867 if (!wdev->current_bss) {
5868 err = -ENOTCONN;
5869 goto out;
5870 }
5871
5872 if (!rdev->ops->set_rekey_data) {
5873 err = -EOPNOTSUPP;
5874 goto out;
5875 }
5876
5877 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
5878 out:
5879 wdev_unlock(wdev);
5880 return err;
5881}
5882
Johannes Berg28946da2011-11-04 11:18:12 +01005883static int nl80211_register_unexpected_frame(struct sk_buff *skb,
5884 struct genl_info *info)
5885{
5886 struct net_device *dev = info->user_ptr[1];
5887 struct wireless_dev *wdev = dev->ieee80211_ptr;
5888
5889 if (wdev->iftype != NL80211_IFTYPE_AP &&
5890 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5891 return -EINVAL;
5892
5893 if (wdev->ap_unexpected_nlpid)
5894 return -EBUSY;
5895
5896 wdev->ap_unexpected_nlpid = info->snd_pid;
5897 return 0;
5898}
5899
Johannes Berg7f6cf312011-11-04 11:18:15 +01005900static int nl80211_probe_client(struct sk_buff *skb,
5901 struct genl_info *info)
5902{
5903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5904 struct net_device *dev = info->user_ptr[1];
5905 struct wireless_dev *wdev = dev->ieee80211_ptr;
5906 struct sk_buff *msg;
5907 void *hdr;
5908 const u8 *addr;
5909 u64 cookie;
5910 int err;
5911
5912 if (wdev->iftype != NL80211_IFTYPE_AP &&
5913 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5914 return -EOPNOTSUPP;
5915
5916 if (!info->attrs[NL80211_ATTR_MAC])
5917 return -EINVAL;
5918
5919 if (!rdev->ops->probe_client)
5920 return -EOPNOTSUPP;
5921
5922 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5923 if (!msg)
5924 return -ENOMEM;
5925
5926 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5927 NL80211_CMD_PROBE_CLIENT);
5928
5929 if (IS_ERR(hdr)) {
5930 err = PTR_ERR(hdr);
5931 goto free_msg;
5932 }
5933
5934 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5935
5936 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
5937 if (err)
5938 goto free_msg;
5939
5940 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5941
5942 genlmsg_end(msg, hdr);
5943
5944 return genlmsg_reply(msg, info);
5945
5946 nla_put_failure:
5947 err = -ENOBUFS;
5948 free_msg:
5949 nlmsg_free(msg);
5950 return err;
5951}
5952
Johannes Berg5e760232011-11-04 11:18:17 +01005953static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
5954{
5955 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5956
5957 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
5958 return -EOPNOTSUPP;
5959
5960 if (rdev->ap_beacons_nlpid)
5961 return -EBUSY;
5962
5963 rdev->ap_beacons_nlpid = info->snd_pid;
5964
5965 return 0;
5966}
5967
Johannes Berg4c476992010-10-04 21:36:35 +02005968#define NL80211_FLAG_NEED_WIPHY 0x01
5969#define NL80211_FLAG_NEED_NETDEV 0x02
5970#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02005971#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5972#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5973 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02005974
5975static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5976 struct genl_info *info)
5977{
5978 struct cfg80211_registered_device *rdev;
5979 struct net_device *dev;
5980 int err;
5981 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5982
5983 if (rtnl)
5984 rtnl_lock();
5985
5986 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5987 rdev = cfg80211_get_dev_from_info(info);
5988 if (IS_ERR(rdev)) {
5989 if (rtnl)
5990 rtnl_unlock();
5991 return PTR_ERR(rdev);
5992 }
5993 info->user_ptr[0] = rdev;
5994 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5995 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5996 if (err) {
5997 if (rtnl)
5998 rtnl_unlock();
5999 return err;
6000 }
Johannes Berg41265712010-10-04 21:14:05 +02006001 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6002 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006003 cfg80211_unlock_rdev(rdev);
6004 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006005 if (rtnl)
6006 rtnl_unlock();
6007 return -ENETDOWN;
6008 }
Johannes Berg4c476992010-10-04 21:36:35 +02006009 info->user_ptr[0] = rdev;
6010 info->user_ptr[1] = dev;
6011 }
6012
6013 return 0;
6014}
6015
6016static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6017 struct genl_info *info)
6018{
6019 if (info->user_ptr[0])
6020 cfg80211_unlock_rdev(info->user_ptr[0]);
6021 if (info->user_ptr[1])
6022 dev_put(info->user_ptr[1]);
6023 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6024 rtnl_unlock();
6025}
6026
Johannes Berg55682962007-09-20 13:09:35 -04006027static struct genl_ops nl80211_ops[] = {
6028 {
6029 .cmd = NL80211_CMD_GET_WIPHY,
6030 .doit = nl80211_get_wiphy,
6031 .dumpit = nl80211_dump_wiphy,
6032 .policy = nl80211_policy,
6033 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006034 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006035 },
6036 {
6037 .cmd = NL80211_CMD_SET_WIPHY,
6038 .doit = nl80211_set_wiphy,
6039 .policy = nl80211_policy,
6040 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006041 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006042 },
6043 {
6044 .cmd = NL80211_CMD_GET_INTERFACE,
6045 .doit = nl80211_get_interface,
6046 .dumpit = nl80211_dump_interface,
6047 .policy = nl80211_policy,
6048 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006049 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006050 },
6051 {
6052 .cmd = NL80211_CMD_SET_INTERFACE,
6053 .doit = nl80211_set_interface,
6054 .policy = nl80211_policy,
6055 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006056 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6057 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006058 },
6059 {
6060 .cmd = NL80211_CMD_NEW_INTERFACE,
6061 .doit = nl80211_new_interface,
6062 .policy = nl80211_policy,
6063 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006064 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6065 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006066 },
6067 {
6068 .cmd = NL80211_CMD_DEL_INTERFACE,
6069 .doit = nl80211_del_interface,
6070 .policy = nl80211_policy,
6071 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006072 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6073 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006074 },
Johannes Berg41ade002007-12-19 02:03:29 +01006075 {
6076 .cmd = NL80211_CMD_GET_KEY,
6077 .doit = nl80211_get_key,
6078 .policy = nl80211_policy,
6079 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006080 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6081 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006082 },
6083 {
6084 .cmd = NL80211_CMD_SET_KEY,
6085 .doit = nl80211_set_key,
6086 .policy = nl80211_policy,
6087 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006089 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006090 },
6091 {
6092 .cmd = NL80211_CMD_NEW_KEY,
6093 .doit = nl80211_new_key,
6094 .policy = nl80211_policy,
6095 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006097 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006098 },
6099 {
6100 .cmd = NL80211_CMD_DEL_KEY,
6101 .doit = nl80211_del_key,
6102 .policy = nl80211_policy,
6103 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006105 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006106 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006107 {
6108 .cmd = NL80211_CMD_SET_BEACON,
6109 .policy = nl80211_policy,
6110 .flags = GENL_ADMIN_PERM,
6111 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006112 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6113 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006114 },
6115 {
6116 .cmd = NL80211_CMD_NEW_BEACON,
6117 .policy = nl80211_policy,
6118 .flags = GENL_ADMIN_PERM,
6119 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006120 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6121 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006122 },
6123 {
6124 .cmd = NL80211_CMD_DEL_BEACON,
6125 .policy = nl80211_policy,
6126 .flags = GENL_ADMIN_PERM,
6127 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006128 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6129 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006130 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006131 {
6132 .cmd = NL80211_CMD_GET_STATION,
6133 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006134 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006135 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006136 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6137 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006138 },
6139 {
6140 .cmd = NL80211_CMD_SET_STATION,
6141 .doit = nl80211_set_station,
6142 .policy = nl80211_policy,
6143 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006144 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6145 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006146 },
6147 {
6148 .cmd = NL80211_CMD_NEW_STATION,
6149 .doit = nl80211_new_station,
6150 .policy = nl80211_policy,
6151 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006153 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006154 },
6155 {
6156 .cmd = NL80211_CMD_DEL_STATION,
6157 .doit = nl80211_del_station,
6158 .policy = nl80211_policy,
6159 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006160 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6161 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006162 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006163 {
6164 .cmd = NL80211_CMD_GET_MPATH,
6165 .doit = nl80211_get_mpath,
6166 .dumpit = nl80211_dump_mpath,
6167 .policy = nl80211_policy,
6168 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006169 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006170 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006171 },
6172 {
6173 .cmd = NL80211_CMD_SET_MPATH,
6174 .doit = nl80211_set_mpath,
6175 .policy = nl80211_policy,
6176 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006177 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006178 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006179 },
6180 {
6181 .cmd = NL80211_CMD_NEW_MPATH,
6182 .doit = nl80211_new_mpath,
6183 .policy = nl80211_policy,
6184 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006185 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006186 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006187 },
6188 {
6189 .cmd = NL80211_CMD_DEL_MPATH,
6190 .doit = nl80211_del_mpath,
6191 .policy = nl80211_policy,
6192 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006193 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6194 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006195 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006196 {
6197 .cmd = NL80211_CMD_SET_BSS,
6198 .doit = nl80211_set_bss,
6199 .policy = nl80211_policy,
6200 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006201 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6202 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006203 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006204 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006205 .cmd = NL80211_CMD_GET_REG,
6206 .doit = nl80211_get_reg,
6207 .policy = nl80211_policy,
6208 /* can be retrieved by unprivileged users */
6209 },
6210 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006211 .cmd = NL80211_CMD_SET_REG,
6212 .doit = nl80211_set_reg,
6213 .policy = nl80211_policy,
6214 .flags = GENL_ADMIN_PERM,
6215 },
6216 {
6217 .cmd = NL80211_CMD_REQ_SET_REG,
6218 .doit = nl80211_req_set_reg,
6219 .policy = nl80211_policy,
6220 .flags = GENL_ADMIN_PERM,
6221 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006222 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006223 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6224 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006225 .policy = nl80211_policy,
6226 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006227 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6228 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006229 },
6230 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006231 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6232 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006233 .policy = nl80211_policy,
6234 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006235 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006236 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006237 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006238 {
Johannes Berg2a519312009-02-10 21:25:55 +01006239 .cmd = NL80211_CMD_TRIGGER_SCAN,
6240 .doit = nl80211_trigger_scan,
6241 .policy = nl80211_policy,
6242 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006243 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006244 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006245 },
6246 {
6247 .cmd = NL80211_CMD_GET_SCAN,
6248 .policy = nl80211_policy,
6249 .dumpit = nl80211_dump_scan,
6250 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006251 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006252 .cmd = NL80211_CMD_START_SCHED_SCAN,
6253 .doit = nl80211_start_sched_scan,
6254 .policy = nl80211_policy,
6255 .flags = GENL_ADMIN_PERM,
6256 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6257 NL80211_FLAG_NEED_RTNL,
6258 },
6259 {
6260 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6261 .doit = nl80211_stop_sched_scan,
6262 .policy = nl80211_policy,
6263 .flags = GENL_ADMIN_PERM,
6264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6265 NL80211_FLAG_NEED_RTNL,
6266 },
6267 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006268 .cmd = NL80211_CMD_AUTHENTICATE,
6269 .doit = nl80211_authenticate,
6270 .policy = nl80211_policy,
6271 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006272 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006273 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006274 },
6275 {
6276 .cmd = NL80211_CMD_ASSOCIATE,
6277 .doit = nl80211_associate,
6278 .policy = nl80211_policy,
6279 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006280 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006281 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006282 },
6283 {
6284 .cmd = NL80211_CMD_DEAUTHENTICATE,
6285 .doit = nl80211_deauthenticate,
6286 .policy = nl80211_policy,
6287 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006288 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006289 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006290 },
6291 {
6292 .cmd = NL80211_CMD_DISASSOCIATE,
6293 .doit = nl80211_disassociate,
6294 .policy = nl80211_policy,
6295 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006296 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006297 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006298 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006299 {
6300 .cmd = NL80211_CMD_JOIN_IBSS,
6301 .doit = nl80211_join_ibss,
6302 .policy = nl80211_policy,
6303 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006304 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006305 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006306 },
6307 {
6308 .cmd = NL80211_CMD_LEAVE_IBSS,
6309 .doit = nl80211_leave_ibss,
6310 .policy = nl80211_policy,
6311 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006313 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006314 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006315#ifdef CONFIG_NL80211_TESTMODE
6316 {
6317 .cmd = NL80211_CMD_TESTMODE,
6318 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006319 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006320 .policy = nl80211_policy,
6321 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006322 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6323 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006324 },
6325#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006326 {
6327 .cmd = NL80211_CMD_CONNECT,
6328 .doit = nl80211_connect,
6329 .policy = nl80211_policy,
6330 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006332 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006333 },
6334 {
6335 .cmd = NL80211_CMD_DISCONNECT,
6336 .doit = nl80211_disconnect,
6337 .policy = nl80211_policy,
6338 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006340 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006341 },
Johannes Berg463d0182009-07-14 00:33:35 +02006342 {
6343 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6344 .doit = nl80211_wiphy_netns,
6345 .policy = nl80211_policy,
6346 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006347 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6348 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006349 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006350 {
6351 .cmd = NL80211_CMD_GET_SURVEY,
6352 .policy = nl80211_policy,
6353 .dumpit = nl80211_dump_survey,
6354 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006355 {
6356 .cmd = NL80211_CMD_SET_PMKSA,
6357 .doit = nl80211_setdel_pmksa,
6358 .policy = nl80211_policy,
6359 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006360 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6361 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006362 },
6363 {
6364 .cmd = NL80211_CMD_DEL_PMKSA,
6365 .doit = nl80211_setdel_pmksa,
6366 .policy = nl80211_policy,
6367 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006368 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6369 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006370 },
6371 {
6372 .cmd = NL80211_CMD_FLUSH_PMKSA,
6373 .doit = nl80211_flush_pmksa,
6374 .policy = nl80211_policy,
6375 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006376 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6377 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006378 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006379 {
6380 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6381 .doit = nl80211_remain_on_channel,
6382 .policy = nl80211_policy,
6383 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006385 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006386 },
6387 {
6388 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6389 .doit = nl80211_cancel_remain_on_channel,
6390 .policy = nl80211_policy,
6391 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006393 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006394 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006395 {
6396 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6397 .doit = nl80211_set_tx_bitrate_mask,
6398 .policy = nl80211_policy,
6399 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006400 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6401 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006402 },
Jouni Malinen026331c2010-02-15 12:53:10 +02006403 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006404 .cmd = NL80211_CMD_REGISTER_FRAME,
6405 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006406 .policy = nl80211_policy,
6407 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006408 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6409 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006410 },
6411 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006412 .cmd = NL80211_CMD_FRAME,
6413 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006414 .policy = nl80211_policy,
6415 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006416 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006417 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006418 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006419 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006420 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6421 .doit = nl80211_tx_mgmt_cancel_wait,
6422 .policy = nl80211_policy,
6423 .flags = GENL_ADMIN_PERM,
6424 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6425 NL80211_FLAG_NEED_RTNL,
6426 },
6427 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006428 .cmd = NL80211_CMD_SET_POWER_SAVE,
6429 .doit = nl80211_set_power_save,
6430 .policy = nl80211_policy,
6431 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006432 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6433 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006434 },
6435 {
6436 .cmd = NL80211_CMD_GET_POWER_SAVE,
6437 .doit = nl80211_get_power_save,
6438 .policy = nl80211_policy,
6439 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006440 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6441 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006442 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006443 {
6444 .cmd = NL80211_CMD_SET_CQM,
6445 .doit = nl80211_set_cqm,
6446 .policy = nl80211_policy,
6447 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006448 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6449 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006450 },
Johannes Bergf444de02010-05-05 15:25:02 +02006451 {
6452 .cmd = NL80211_CMD_SET_CHANNEL,
6453 .doit = nl80211_set_channel,
6454 .policy = nl80211_policy,
6455 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006456 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6457 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006458 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006459 {
6460 .cmd = NL80211_CMD_SET_WDS_PEER,
6461 .doit = nl80211_set_wds_peer,
6462 .policy = nl80211_policy,
6463 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006464 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6465 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006466 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006467 {
6468 .cmd = NL80211_CMD_JOIN_MESH,
6469 .doit = nl80211_join_mesh,
6470 .policy = nl80211_policy,
6471 .flags = GENL_ADMIN_PERM,
6472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6473 NL80211_FLAG_NEED_RTNL,
6474 },
6475 {
6476 .cmd = NL80211_CMD_LEAVE_MESH,
6477 .doit = nl80211_leave_mesh,
6478 .policy = nl80211_policy,
6479 .flags = GENL_ADMIN_PERM,
6480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6481 NL80211_FLAG_NEED_RTNL,
6482 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006483 {
6484 .cmd = NL80211_CMD_GET_WOWLAN,
6485 .doit = nl80211_get_wowlan,
6486 .policy = nl80211_policy,
6487 /* can be retrieved by unprivileged users */
6488 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6489 NL80211_FLAG_NEED_RTNL,
6490 },
6491 {
6492 .cmd = NL80211_CMD_SET_WOWLAN,
6493 .doit = nl80211_set_wowlan,
6494 .policy = nl80211_policy,
6495 .flags = GENL_ADMIN_PERM,
6496 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6497 NL80211_FLAG_NEED_RTNL,
6498 },
Johannes Berge5497d72011-07-05 16:35:40 +02006499 {
6500 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6501 .doit = nl80211_set_rekey_data,
6502 .policy = nl80211_policy,
6503 .flags = GENL_ADMIN_PERM,
6504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6505 NL80211_FLAG_NEED_RTNL,
6506 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03006507 {
6508 .cmd = NL80211_CMD_TDLS_MGMT,
6509 .doit = nl80211_tdls_mgmt,
6510 .policy = nl80211_policy,
6511 .flags = GENL_ADMIN_PERM,
6512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6513 NL80211_FLAG_NEED_RTNL,
6514 },
6515 {
6516 .cmd = NL80211_CMD_TDLS_OPER,
6517 .doit = nl80211_tdls_oper,
6518 .policy = nl80211_policy,
6519 .flags = GENL_ADMIN_PERM,
6520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6521 NL80211_FLAG_NEED_RTNL,
6522 },
Johannes Berg28946da2011-11-04 11:18:12 +01006523 {
6524 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6525 .doit = nl80211_register_unexpected_frame,
6526 .policy = nl80211_policy,
6527 .flags = GENL_ADMIN_PERM,
6528 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6529 NL80211_FLAG_NEED_RTNL,
6530 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01006531 {
6532 .cmd = NL80211_CMD_PROBE_CLIENT,
6533 .doit = nl80211_probe_client,
6534 .policy = nl80211_policy,
6535 .flags = GENL_ADMIN_PERM,
6536 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6537 NL80211_FLAG_NEED_RTNL,
6538 },
Johannes Berg5e760232011-11-04 11:18:17 +01006539 {
6540 .cmd = NL80211_CMD_REGISTER_BEACONS,
6541 .doit = nl80211_register_beacons,
6542 .policy = nl80211_policy,
6543 .flags = GENL_ADMIN_PERM,
6544 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6545 NL80211_FLAG_NEED_RTNL,
6546 },
Johannes Berg55682962007-09-20 13:09:35 -04006547};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006548
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006549static struct genl_multicast_group nl80211_mlme_mcgrp = {
6550 .name = "mlme",
6551};
Johannes Berg55682962007-09-20 13:09:35 -04006552
6553/* multicast groups */
6554static struct genl_multicast_group nl80211_config_mcgrp = {
6555 .name = "config",
6556};
Johannes Berg2a519312009-02-10 21:25:55 +01006557static struct genl_multicast_group nl80211_scan_mcgrp = {
6558 .name = "scan",
6559};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006560static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6561 .name = "regulatory",
6562};
Johannes Berg55682962007-09-20 13:09:35 -04006563
6564/* notification functions */
6565
6566void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6567{
6568 struct sk_buff *msg;
6569
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006571 if (!msg)
6572 return;
6573
6574 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6575 nlmsg_free(msg);
6576 return;
6577 }
6578
Johannes Berg463d0182009-07-14 00:33:35 +02006579 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6580 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006581}
6582
Johannes Berg362a4152009-05-24 16:43:15 +02006583static int nl80211_add_scan_req(struct sk_buff *msg,
6584 struct cfg80211_registered_device *rdev)
6585{
6586 struct cfg80211_scan_request *req = rdev->scan_req;
6587 struct nlattr *nest;
6588 int i;
6589
Johannes Berg667503dd2009-07-07 03:56:11 +02006590 ASSERT_RDEV_LOCK(rdev);
6591
Johannes Berg362a4152009-05-24 16:43:15 +02006592 if (WARN_ON(!req))
6593 return 0;
6594
6595 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6596 if (!nest)
6597 goto nla_put_failure;
6598 for (i = 0; i < req->n_ssids; i++)
6599 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6600 nla_nest_end(msg, nest);
6601
6602 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6603 if (!nest)
6604 goto nla_put_failure;
6605 for (i = 0; i < req->n_channels; i++)
6606 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6607 nla_nest_end(msg, nest);
6608
6609 if (req->ie)
6610 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6611
6612 return 0;
6613 nla_put_failure:
6614 return -ENOBUFS;
6615}
6616
Johannes Berga538e2d2009-06-16 19:56:42 +02006617static int nl80211_send_scan_msg(struct sk_buff *msg,
6618 struct cfg80211_registered_device *rdev,
6619 struct net_device *netdev,
6620 u32 pid, u32 seq, int flags,
6621 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006622{
6623 void *hdr;
6624
6625 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6626 if (!hdr)
6627 return -1;
6628
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006629 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006630 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6631
Johannes Berg362a4152009-05-24 16:43:15 +02006632 /* ignore errors and send incomplete event anyway */
6633 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006634
6635 return genlmsg_end(msg, hdr);
6636
6637 nla_put_failure:
6638 genlmsg_cancel(msg, hdr);
6639 return -EMSGSIZE;
6640}
6641
Luciano Coelho807f8a82011-05-11 17:09:35 +03006642static int
6643nl80211_send_sched_scan_msg(struct sk_buff *msg,
6644 struct cfg80211_registered_device *rdev,
6645 struct net_device *netdev,
6646 u32 pid, u32 seq, int flags, u32 cmd)
6647{
6648 void *hdr;
6649
6650 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6651 if (!hdr)
6652 return -1;
6653
6654 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6655 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6656
6657 return genlmsg_end(msg, hdr);
6658
6659 nla_put_failure:
6660 genlmsg_cancel(msg, hdr);
6661 return -EMSGSIZE;
6662}
6663
Johannes Berga538e2d2009-06-16 19:56:42 +02006664void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6665 struct net_device *netdev)
6666{
6667 struct sk_buff *msg;
6668
6669 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6670 if (!msg)
6671 return;
6672
6673 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6674 NL80211_CMD_TRIGGER_SCAN) < 0) {
6675 nlmsg_free(msg);
6676 return;
6677 }
6678
Johannes Berg463d0182009-07-14 00:33:35 +02006679 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6680 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006681}
6682
Johannes Berg2a519312009-02-10 21:25:55 +01006683void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6684 struct net_device *netdev)
6685{
6686 struct sk_buff *msg;
6687
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006688 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006689 if (!msg)
6690 return;
6691
Johannes Berga538e2d2009-06-16 19:56:42 +02006692 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6693 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006694 nlmsg_free(msg);
6695 return;
6696 }
6697
Johannes Berg463d0182009-07-14 00:33:35 +02006698 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6699 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006700}
6701
6702void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6703 struct net_device *netdev)
6704{
6705 struct sk_buff *msg;
6706
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006707 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006708 if (!msg)
6709 return;
6710
Johannes Berga538e2d2009-06-16 19:56:42 +02006711 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6712 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006713 nlmsg_free(msg);
6714 return;
6715 }
6716
Johannes Berg463d0182009-07-14 00:33:35 +02006717 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6718 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006719}
6720
Luciano Coelho807f8a82011-05-11 17:09:35 +03006721void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6722 struct net_device *netdev)
6723{
6724 struct sk_buff *msg;
6725
6726 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6727 if (!msg)
6728 return;
6729
6730 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6731 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6732 nlmsg_free(msg);
6733 return;
6734 }
6735
6736 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6737 nl80211_scan_mcgrp.id, GFP_KERNEL);
6738}
6739
6740void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6741 struct net_device *netdev, u32 cmd)
6742{
6743 struct sk_buff *msg;
6744
6745 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6746 if (!msg)
6747 return;
6748
6749 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6750 nlmsg_free(msg);
6751 return;
6752 }
6753
6754 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6755 nl80211_scan_mcgrp.id, GFP_KERNEL);
6756}
6757
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006758/*
6759 * This can happen on global regulatory changes or device specific settings
6760 * based on custom world regulatory domains.
6761 */
6762void nl80211_send_reg_change_event(struct regulatory_request *request)
6763{
6764 struct sk_buff *msg;
6765 void *hdr;
6766
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006768 if (!msg)
6769 return;
6770
6771 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6772 if (!hdr) {
6773 nlmsg_free(msg);
6774 return;
6775 }
6776
6777 /* Userspace can always count this one always being set */
6778 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6779
6780 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6781 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6782 NL80211_REGDOM_TYPE_WORLD);
6783 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6784 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6785 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6786 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6787 request->intersect)
6788 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6789 NL80211_REGDOM_TYPE_INTERSECTION);
6790 else {
6791 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6792 NL80211_REGDOM_TYPE_COUNTRY);
6793 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6794 }
6795
6796 if (wiphy_idx_valid(request->wiphy_idx))
6797 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6798
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006799 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006800
Johannes Bergbc43b282009-07-25 10:54:13 +02006801 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02006802 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02006803 GFP_ATOMIC);
6804 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006805
6806 return;
6807
6808nla_put_failure:
6809 genlmsg_cancel(msg, hdr);
6810 nlmsg_free(msg);
6811}
6812
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006813static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
6814 struct net_device *netdev,
6815 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006816 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006817{
6818 struct sk_buff *msg;
6819 void *hdr;
6820
Johannes Berge6d6e342009-07-01 21:26:47 +02006821 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006822 if (!msg)
6823 return;
6824
6825 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6826 if (!hdr) {
6827 nlmsg_free(msg);
6828 return;
6829 }
6830
6831 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6832 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6833 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6834
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006835 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006836
Johannes Berg463d0182009-07-14 00:33:35 +02006837 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6838 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006839 return;
6840
6841 nla_put_failure:
6842 genlmsg_cancel(msg, hdr);
6843 nlmsg_free(msg);
6844}
6845
6846void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006847 struct net_device *netdev, const u8 *buf,
6848 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006849{
6850 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006851 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006852}
6853
6854void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
6855 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006856 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006857{
Johannes Berge6d6e342009-07-01 21:26:47 +02006858 nl80211_send_mlme_event(rdev, netdev, buf, len,
6859 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006860}
6861
Jouni Malinen53b46b82009-03-27 20:53:56 +02006862void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006863 struct net_device *netdev, const u8 *buf,
6864 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006865{
6866 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006867 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006868}
6869
Jouni Malinen53b46b82009-03-27 20:53:56 +02006870void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
6871 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006872 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006873{
6874 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006875 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006876}
6877
Jouni Malinencf4e5942010-12-16 00:52:40 +02006878void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6879 struct net_device *netdev, const u8 *buf,
6880 size_t len, gfp_t gfp)
6881{
6882 nl80211_send_mlme_event(rdev, netdev, buf, len,
6883 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6884}
6885
6886void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6887 struct net_device *netdev, const u8 *buf,
6888 size_t len, gfp_t gfp)
6889{
6890 nl80211_send_mlme_event(rdev, netdev, buf, len,
6891 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6892}
6893
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04006894static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
6895 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02006896 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006897{
6898 struct sk_buff *msg;
6899 void *hdr;
6900
Johannes Berge6d6e342009-07-01 21:26:47 +02006901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006902 if (!msg)
6903 return;
6904
6905 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6906 if (!hdr) {
6907 nlmsg_free(msg);
6908 return;
6909 }
6910
6911 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6912 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6913 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
6914 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6915
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006916 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03006917
Johannes Berg463d0182009-07-14 00:33:35 +02006918 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6919 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006920 return;
6921
6922 nla_put_failure:
6923 genlmsg_cancel(msg, hdr);
6924 nlmsg_free(msg);
6925}
6926
6927void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006928 struct net_device *netdev, const u8 *addr,
6929 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006930{
6931 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02006932 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006933}
6934
6935void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006936 struct net_device *netdev, const u8 *addr,
6937 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006938{
Johannes Berge6d6e342009-07-01 21:26:47 +02006939 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
6940 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006941}
6942
Samuel Ortizb23aa672009-07-01 21:26:54 +02006943void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
6944 struct net_device *netdev, const u8 *bssid,
6945 const u8 *req_ie, size_t req_ie_len,
6946 const u8 *resp_ie, size_t resp_ie_len,
6947 u16 status, gfp_t gfp)
6948{
6949 struct sk_buff *msg;
6950 void *hdr;
6951
6952 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6953 if (!msg)
6954 return;
6955
6956 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
6957 if (!hdr) {
6958 nlmsg_free(msg);
6959 return;
6960 }
6961
6962 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6963 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6964 if (bssid)
6965 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6966 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
6967 if (req_ie)
6968 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6969 if (resp_ie)
6970 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6971
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006972 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006973
Johannes Berg463d0182009-07-14 00:33:35 +02006974 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6975 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006976 return;
6977
6978 nla_put_failure:
6979 genlmsg_cancel(msg, hdr);
6980 nlmsg_free(msg);
6981
6982}
6983
6984void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
6985 struct net_device *netdev, const u8 *bssid,
6986 const u8 *req_ie, size_t req_ie_len,
6987 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
6988{
6989 struct sk_buff *msg;
6990 void *hdr;
6991
6992 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6993 if (!msg)
6994 return;
6995
6996 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
6997 if (!hdr) {
6998 nlmsg_free(msg);
6999 return;
7000 }
7001
7002 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7003 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7004 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7005 if (req_ie)
7006 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7007 if (resp_ie)
7008 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7009
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007010 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007011
Johannes Berg463d0182009-07-14 00:33:35 +02007012 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7013 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007014 return;
7015
7016 nla_put_failure:
7017 genlmsg_cancel(msg, hdr);
7018 nlmsg_free(msg);
7019
7020}
7021
7022void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7023 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007024 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007025{
7026 struct sk_buff *msg;
7027 void *hdr;
7028
Johannes Berg667503dd2009-07-07 03:56:11 +02007029 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007030 if (!msg)
7031 return;
7032
7033 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7034 if (!hdr) {
7035 nlmsg_free(msg);
7036 return;
7037 }
7038
7039 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7040 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7041 if (from_ap && reason)
7042 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
7043 if (from_ap)
7044 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
7045 if (ie)
7046 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
7047
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007048 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007049
Johannes Berg463d0182009-07-14 00:33:35 +02007050 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7051 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007052 return;
7053
7054 nla_put_failure:
7055 genlmsg_cancel(msg, hdr);
7056 nlmsg_free(msg);
7057
7058}
7059
Johannes Berg04a773a2009-04-19 21:24:32 +02007060void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7061 struct net_device *netdev, const u8 *bssid,
7062 gfp_t gfp)
7063{
7064 struct sk_buff *msg;
7065 void *hdr;
7066
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007067 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007068 if (!msg)
7069 return;
7070
7071 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7072 if (!hdr) {
7073 nlmsg_free(msg);
7074 return;
7075 }
7076
7077 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7078 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7079 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7080
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007081 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007082
Johannes Berg463d0182009-07-14 00:33:35 +02007083 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7084 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007085 return;
7086
7087 nla_put_failure:
7088 genlmsg_cancel(msg, hdr);
7089 nlmsg_free(msg);
7090}
7091
Javier Cardonac93b5e72011-04-07 15:08:34 -07007092void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7093 struct net_device *netdev,
7094 const u8 *macaddr, const u8* ie, u8 ie_len,
7095 gfp_t gfp)
7096{
7097 struct sk_buff *msg;
7098 void *hdr;
7099
7100 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7101 if (!msg)
7102 return;
7103
7104 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7105 if (!hdr) {
7106 nlmsg_free(msg);
7107 return;
7108 }
7109
7110 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7111 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7112 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
7113 if (ie_len && ie)
7114 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
7115
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007116 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007117
7118 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7119 nl80211_mlme_mcgrp.id, gfp);
7120 return;
7121
7122 nla_put_failure:
7123 genlmsg_cancel(msg, hdr);
7124 nlmsg_free(msg);
7125}
7126
Jouni Malinena3b8b052009-03-27 21:59:49 +02007127void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7128 struct net_device *netdev, const u8 *addr,
7129 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007130 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007131{
7132 struct sk_buff *msg;
7133 void *hdr;
7134
Johannes Berge6d6e342009-07-01 21:26:47 +02007135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007136 if (!msg)
7137 return;
7138
7139 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7140 if (!hdr) {
7141 nlmsg_free(msg);
7142 return;
7143 }
7144
7145 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7146 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7147 if (addr)
7148 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7149 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03007150 if (key_id != -1)
7151 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007152 if (tsc)
7153 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7154
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007155 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007156
Johannes Berg463d0182009-07-14 00:33:35 +02007157 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7158 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007159 return;
7160
7161 nla_put_failure:
7162 genlmsg_cancel(msg, hdr);
7163 nlmsg_free(msg);
7164}
7165
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007166void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7167 struct ieee80211_channel *channel_before,
7168 struct ieee80211_channel *channel_after)
7169{
7170 struct sk_buff *msg;
7171 void *hdr;
7172 struct nlattr *nl_freq;
7173
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007175 if (!msg)
7176 return;
7177
7178 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7179 if (!hdr) {
7180 nlmsg_free(msg);
7181 return;
7182 }
7183
7184 /*
7185 * Since we are applying the beacon hint to a wiphy we know its
7186 * wiphy_idx is valid
7187 */
7188 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7189
7190 /* Before */
7191 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7192 if (!nl_freq)
7193 goto nla_put_failure;
7194 if (nl80211_msg_put_channel(msg, channel_before))
7195 goto nla_put_failure;
7196 nla_nest_end(msg, nl_freq);
7197
7198 /* After */
7199 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7200 if (!nl_freq)
7201 goto nla_put_failure;
7202 if (nl80211_msg_put_channel(msg, channel_after))
7203 goto nla_put_failure;
7204 nla_nest_end(msg, nl_freq);
7205
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007206 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007207
Johannes Berg463d0182009-07-14 00:33:35 +02007208 rcu_read_lock();
7209 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7210 GFP_ATOMIC);
7211 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007212
7213 return;
7214
7215nla_put_failure:
7216 genlmsg_cancel(msg, hdr);
7217 nlmsg_free(msg);
7218}
7219
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007220static void nl80211_send_remain_on_chan_event(
7221 int cmd, struct cfg80211_registered_device *rdev,
7222 struct net_device *netdev, u64 cookie,
7223 struct ieee80211_channel *chan,
7224 enum nl80211_channel_type channel_type,
7225 unsigned int duration, gfp_t gfp)
7226{
7227 struct sk_buff *msg;
7228 void *hdr;
7229
7230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7231 if (!msg)
7232 return;
7233
7234 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7235 if (!hdr) {
7236 nlmsg_free(msg);
7237 return;
7238 }
7239
7240 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7241 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7242 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7243 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7244 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7245
7246 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7247 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7248
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007249 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007250
7251 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7252 nl80211_mlme_mcgrp.id, gfp);
7253 return;
7254
7255 nla_put_failure:
7256 genlmsg_cancel(msg, hdr);
7257 nlmsg_free(msg);
7258}
7259
7260void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7261 struct net_device *netdev, u64 cookie,
7262 struct ieee80211_channel *chan,
7263 enum nl80211_channel_type channel_type,
7264 unsigned int duration, gfp_t gfp)
7265{
7266 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7267 rdev, netdev, cookie, chan,
7268 channel_type, duration, gfp);
7269}
7270
7271void nl80211_send_remain_on_channel_cancel(
7272 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7273 u64 cookie, struct ieee80211_channel *chan,
7274 enum nl80211_channel_type channel_type, gfp_t gfp)
7275{
7276 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7277 rdev, netdev, cookie, chan,
7278 channel_type, 0, gfp);
7279}
7280
Johannes Berg98b62182009-12-23 13:15:44 +01007281void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7282 struct net_device *dev, const u8 *mac_addr,
7283 struct station_info *sinfo, gfp_t gfp)
7284{
7285 struct sk_buff *msg;
7286
7287 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7288 if (!msg)
7289 return;
7290
7291 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
7292 nlmsg_free(msg);
7293 return;
7294 }
7295
7296 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7297 nl80211_mlme_mcgrp.id, gfp);
7298}
7299
Jouni Malinenec15e682011-03-23 15:29:52 +02007300void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7301 struct net_device *dev, const u8 *mac_addr,
7302 gfp_t gfp)
7303{
7304 struct sk_buff *msg;
7305 void *hdr;
7306
7307 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7308 if (!msg)
7309 return;
7310
7311 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7312 if (!hdr) {
7313 nlmsg_free(msg);
7314 return;
7315 }
7316
7317 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7318 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7319
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007320 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007321
7322 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7323 nl80211_mlme_mcgrp.id, gfp);
7324 return;
7325
7326 nla_put_failure:
7327 genlmsg_cancel(msg, hdr);
7328 nlmsg_free(msg);
7329}
7330
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007331static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
7332 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01007333{
7334 struct wireless_dev *wdev = dev->ieee80211_ptr;
7335 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7336 struct sk_buff *msg;
7337 void *hdr;
7338 int err;
7339 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7340
7341 if (!nlpid)
7342 return false;
7343
7344 msg = nlmsg_new(100, gfp);
7345 if (!msg)
7346 return true;
7347
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007348 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01007349 if (!hdr) {
7350 nlmsg_free(msg);
7351 return true;
7352 }
7353
7354 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7355 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7356 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7357
7358 err = genlmsg_end(msg, hdr);
7359 if (err < 0) {
7360 nlmsg_free(msg);
7361 return true;
7362 }
7363
7364 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7365 return true;
7366
7367 nla_put_failure:
7368 genlmsg_cancel(msg, hdr);
7369 nlmsg_free(msg);
7370 return true;
7371}
7372
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007373bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7374{
7375 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
7376 addr, gfp);
7377}
7378
7379bool nl80211_unexpected_4addr_frame(struct net_device *dev,
7380 const u8 *addr, gfp_t gfp)
7381{
7382 return __nl80211_unexpected_frame(dev,
7383 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
7384 addr, gfp);
7385}
7386
Johannes Berg2e161f72010-08-12 15:38:38 +02007387int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7388 struct net_device *netdev, u32 nlpid,
7389 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007390{
7391 struct sk_buff *msg;
7392 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02007393
7394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7395 if (!msg)
7396 return -ENOMEM;
7397
Johannes Berg2e161f72010-08-12 15:38:38 +02007398 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007399 if (!hdr) {
7400 nlmsg_free(msg);
7401 return -ENOMEM;
7402 }
7403
7404 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7405 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7406 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7407 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7408
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007409 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007410
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007411 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007412
7413 nla_put_failure:
7414 genlmsg_cancel(msg, hdr);
7415 nlmsg_free(msg);
7416 return -ENOBUFS;
7417}
7418
Johannes Berg2e161f72010-08-12 15:38:38 +02007419void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7420 struct net_device *netdev, u64 cookie,
7421 const u8 *buf, size_t len, bool ack,
7422 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007423{
7424 struct sk_buff *msg;
7425 void *hdr;
7426
7427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7428 if (!msg)
7429 return;
7430
Johannes Berg2e161f72010-08-12 15:38:38 +02007431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02007432 if (!hdr) {
7433 nlmsg_free(msg);
7434 return;
7435 }
7436
7437 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7438 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7439 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7440 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7441 if (ack)
7442 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7443
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007444 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007445
7446 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7447 return;
7448
7449 nla_put_failure:
7450 genlmsg_cancel(msg, hdr);
7451 nlmsg_free(msg);
7452}
7453
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007454void
7455nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7456 struct net_device *netdev,
7457 enum nl80211_cqm_rssi_threshold_event rssi_event,
7458 gfp_t gfp)
7459{
7460 struct sk_buff *msg;
7461 struct nlattr *pinfoattr;
7462 void *hdr;
7463
7464 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7465 if (!msg)
7466 return;
7467
7468 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7469 if (!hdr) {
7470 nlmsg_free(msg);
7471 return;
7472 }
7473
7474 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7475 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7476
7477 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7478 if (!pinfoattr)
7479 goto nla_put_failure;
7480
7481 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7482 rssi_event);
7483
7484 nla_nest_end(msg, pinfoattr);
7485
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007486 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007487
7488 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7489 nl80211_mlme_mcgrp.id, gfp);
7490 return;
7491
7492 nla_put_failure:
7493 genlmsg_cancel(msg, hdr);
7494 nlmsg_free(msg);
7495}
7496
Johannes Berge5497d72011-07-05 16:35:40 +02007497void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7498 struct net_device *netdev, const u8 *bssid,
7499 const u8 *replay_ctr, gfp_t gfp)
7500{
7501 struct sk_buff *msg;
7502 struct nlattr *rekey_attr;
7503 void *hdr;
7504
7505 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7506 if (!msg)
7507 return;
7508
7509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7510 if (!hdr) {
7511 nlmsg_free(msg);
7512 return;
7513 }
7514
7515 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7516 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7517 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7518
7519 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7520 if (!rekey_attr)
7521 goto nla_put_failure;
7522
7523 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7524 NL80211_REPLAY_CTR_LEN, replay_ctr);
7525
7526 nla_nest_end(msg, rekey_attr);
7527
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007528 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02007529
7530 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7531 nl80211_mlme_mcgrp.id, gfp);
7532 return;
7533
7534 nla_put_failure:
7535 genlmsg_cancel(msg, hdr);
7536 nlmsg_free(msg);
7537}
7538
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007539void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7540 struct net_device *netdev, int index,
7541 const u8 *bssid, bool preauth, gfp_t gfp)
7542{
7543 struct sk_buff *msg;
7544 struct nlattr *attr;
7545 void *hdr;
7546
7547 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7548 if (!msg)
7549 return;
7550
7551 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7552 if (!hdr) {
7553 nlmsg_free(msg);
7554 return;
7555 }
7556
7557 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7558 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7559
7560 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7561 if (!attr)
7562 goto nla_put_failure;
7563
7564 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7565 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7566 if (preauth)
7567 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7568
7569 nla_nest_end(msg, attr);
7570
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007571 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007572
7573 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7574 nl80211_mlme_mcgrp.id, gfp);
7575 return;
7576
7577 nla_put_failure:
7578 genlmsg_cancel(msg, hdr);
7579 nlmsg_free(msg);
7580}
7581
Johannes Bergc063dbf2010-11-24 08:10:05 +01007582void
7583nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7584 struct net_device *netdev, const u8 *peer,
7585 u32 num_packets, gfp_t gfp)
7586{
7587 struct sk_buff *msg;
7588 struct nlattr *pinfoattr;
7589 void *hdr;
7590
7591 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7592 if (!msg)
7593 return;
7594
7595 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7596 if (!hdr) {
7597 nlmsg_free(msg);
7598 return;
7599 }
7600
7601 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7602 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7603 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7604
7605 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7606 if (!pinfoattr)
7607 goto nla_put_failure;
7608
7609 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7610
7611 nla_nest_end(msg, pinfoattr);
7612
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007613 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01007614
7615 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7616 nl80211_mlme_mcgrp.id, gfp);
7617 return;
7618
7619 nla_put_failure:
7620 genlmsg_cancel(msg, hdr);
7621 nlmsg_free(msg);
7622}
7623
Johannes Berg7f6cf312011-11-04 11:18:15 +01007624void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
7625 u64 cookie, bool acked, gfp_t gfp)
7626{
7627 struct wireless_dev *wdev = dev->ieee80211_ptr;
7628 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7629 struct sk_buff *msg;
7630 void *hdr;
7631 int err;
7632
7633 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7634 if (!msg)
7635 return;
7636
7637 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
7638 if (!hdr) {
7639 nlmsg_free(msg);
7640 return;
7641 }
7642
7643 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7644 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7645 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7646 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7647 if (acked)
7648 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7649
7650 err = genlmsg_end(msg, hdr);
7651 if (err < 0) {
7652 nlmsg_free(msg);
7653 return;
7654 }
7655
7656 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7657 nl80211_mlme_mcgrp.id, gfp);
7658 return;
7659
7660 nla_put_failure:
7661 genlmsg_cancel(msg, hdr);
7662 nlmsg_free(msg);
7663}
7664EXPORT_SYMBOL(cfg80211_probe_status);
7665
Johannes Berg5e760232011-11-04 11:18:17 +01007666void cfg80211_report_obss_beacon(struct wiphy *wiphy,
7667 const u8 *frame, size_t len,
7668 int freq, gfp_t gfp)
7669{
7670 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
7671 struct sk_buff *msg;
7672 void *hdr;
7673 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
7674
7675 if (!nlpid)
7676 return;
7677
7678 msg = nlmsg_new(len + 100, gfp);
7679 if (!msg)
7680 return;
7681
7682 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
7683 if (!hdr) {
7684 nlmsg_free(msg);
7685 return;
7686 }
7687
7688 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7689 if (freq)
7690 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7691 NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
7692
7693 genlmsg_end(msg, hdr);
7694
7695 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7696 return;
7697
7698 nla_put_failure:
7699 genlmsg_cancel(msg, hdr);
7700 nlmsg_free(msg);
7701}
7702EXPORT_SYMBOL(cfg80211_report_obss_beacon);
7703
Jouni Malinen026331c2010-02-15 12:53:10 +02007704static int nl80211_netlink_notify(struct notifier_block * nb,
7705 unsigned long state,
7706 void *_notify)
7707{
7708 struct netlink_notify *notify = _notify;
7709 struct cfg80211_registered_device *rdev;
7710 struct wireless_dev *wdev;
7711
7712 if (state != NETLINK_URELEASE)
7713 return NOTIFY_DONE;
7714
7715 rcu_read_lock();
7716
Johannes Berg5e760232011-11-04 11:18:17 +01007717 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02007718 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02007719 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01007720 if (rdev->ap_beacons_nlpid == notify->pid)
7721 rdev->ap_beacons_nlpid = 0;
7722 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007723
7724 rcu_read_unlock();
7725
7726 return NOTIFY_DONE;
7727}
7728
7729static struct notifier_block nl80211_netlink_notifier = {
7730 .notifier_call = nl80211_netlink_notify,
7731};
7732
Johannes Berg55682962007-09-20 13:09:35 -04007733/* initialisation/exit functions */
7734
7735int nl80211_init(void)
7736{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007737 int err;
Johannes Berg55682962007-09-20 13:09:35 -04007738
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007739 err = genl_register_family_with_ops(&nl80211_fam,
7740 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04007741 if (err)
7742 return err;
7743
Johannes Berg55682962007-09-20 13:09:35 -04007744 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7745 if (err)
7746 goto err_out;
7747
Johannes Berg2a519312009-02-10 21:25:55 +01007748 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7749 if (err)
7750 goto err_out;
7751
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007752 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7753 if (err)
7754 goto err_out;
7755
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007756 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7757 if (err)
7758 goto err_out;
7759
Johannes Bergaff89a92009-07-01 21:26:51 +02007760#ifdef CONFIG_NL80211_TESTMODE
7761 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7762 if (err)
7763 goto err_out;
7764#endif
7765
Jouni Malinen026331c2010-02-15 12:53:10 +02007766 err = netlink_register_notifier(&nl80211_netlink_notifier);
7767 if (err)
7768 goto err_out;
7769
Johannes Berg55682962007-09-20 13:09:35 -04007770 return 0;
7771 err_out:
7772 genl_unregister_family(&nl80211_fam);
7773 return err;
7774}
7775
7776void nl80211_exit(void)
7777{
Jouni Malinen026331c2010-02-15 12:53:10 +02007778 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04007779 genl_unregister_family(&nl80211_fam);
7780}