blob: 2094c8468d78ff38b8ca40b9c3bc0c342a118990 [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 Berg55682962007-09-20 13:09:35 -0400199};
200
Johannes Berge31b8212010-10-05 19:39:30 +0200201/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000202static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200203 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200204 [NL80211_KEY_IDX] = { .type = NLA_U8 },
205 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200206 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200207 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
208 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200209 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100210 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
211};
212
213/* policy for the key default flags */
214static const struct nla_policy
215nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
216 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
217 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200218};
219
Johannes Bergff1b6e62011-05-04 15:37:28 +0200220/* policy for WoWLAN attributes */
221static const struct nla_policy
222nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
223 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
224 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
225 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
226 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200227 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
228 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
229 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
230 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200231};
232
Johannes Berge5497d72011-07-05 16:35:40 +0200233/* policy for GTK rekey offload attributes */
234static const struct nla_policy
235nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
236 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
237 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
238 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
239};
240
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300241static const struct nla_policy
242nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
243 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
244 .len = IEEE80211_MAX_SSID_LEN },
245};
246
Holger Schuriga0438972009-11-11 11:30:02 +0100247/* ifidx get helper */
248static int nl80211_get_ifidx(struct netlink_callback *cb)
249{
250 int res;
251
252 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
253 nl80211_fam.attrbuf, nl80211_fam.maxattr,
254 nl80211_policy);
255 if (res)
256 return res;
257
258 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
259 return -EINVAL;
260
261 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
262 if (!res)
263 return -EINVAL;
264 return res;
265}
266
Johannes Berg67748892010-10-04 21:14:06 +0200267static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
268 struct netlink_callback *cb,
269 struct cfg80211_registered_device **rdev,
270 struct net_device **dev)
271{
272 int ifidx = cb->args[0];
273 int err;
274
275 if (!ifidx)
276 ifidx = nl80211_get_ifidx(cb);
277 if (ifidx < 0)
278 return ifidx;
279
280 cb->args[0] = ifidx;
281
282 rtnl_lock();
283
284 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
285 if (!*dev) {
286 err = -ENODEV;
287 goto out_rtnl;
288 }
289
290 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100291 if (IS_ERR(*rdev)) {
292 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200293 goto out_rtnl;
294 }
295
296 return 0;
297 out_rtnl:
298 rtnl_unlock();
299 return err;
300}
301
302static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
303{
304 cfg80211_unlock_rdev(rdev);
305 rtnl_unlock();
306}
307
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100308/* IE validation */
309static bool is_valid_ie_attr(const struct nlattr *attr)
310{
311 const u8 *pos;
312 int len;
313
314 if (!attr)
315 return true;
316
317 pos = nla_data(attr);
318 len = nla_len(attr);
319
320 while (len) {
321 u8 elemlen;
322
323 if (len < 2)
324 return false;
325 len -= 2;
326
327 elemlen = pos[1];
328 if (elemlen > len)
329 return false;
330
331 len -= elemlen;
332 pos += 2 + elemlen;
333 }
334
335 return true;
336}
337
Johannes Berg55682962007-09-20 13:09:35 -0400338/* message building helper */
339static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
340 int flags, u8 cmd)
341{
342 /* since there is no private header just add the generic one */
343 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
344}
345
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400346static int nl80211_msg_put_channel(struct sk_buff *msg,
347 struct ieee80211_channel *chan)
348{
349 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
350 chan->center_freq);
351
352 if (chan->flags & IEEE80211_CHAN_DISABLED)
353 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
354 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
355 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
356 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
357 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
358 if (chan->flags & IEEE80211_CHAN_RADAR)
359 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
360
361 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
362 DBM_TO_MBM(chan->max_power));
363
364 return 0;
365
366 nla_put_failure:
367 return -ENOBUFS;
368}
369
Johannes Berg55682962007-09-20 13:09:35 -0400370/* netlink command implementations */
371
Johannes Bergb9454e82009-07-08 13:29:08 +0200372struct key_parse {
373 struct key_params p;
374 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200375 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200376 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100377 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200378};
379
380static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
381{
382 struct nlattr *tb[NL80211_KEY_MAX + 1];
383 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
384 nl80211_key_policy);
385 if (err)
386 return err;
387
388 k->def = !!tb[NL80211_KEY_DEFAULT];
389 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
390
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100391 if (k->def) {
392 k->def_uni = true;
393 k->def_multi = true;
394 }
395 if (k->defmgmt)
396 k->def_multi = true;
397
Johannes Bergb9454e82009-07-08 13:29:08 +0200398 if (tb[NL80211_KEY_IDX])
399 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
400
401 if (tb[NL80211_KEY_DATA]) {
402 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
403 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
404 }
405
406 if (tb[NL80211_KEY_SEQ]) {
407 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
408 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
409 }
410
411 if (tb[NL80211_KEY_CIPHER])
412 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
413
Johannes Berge31b8212010-10-05 19:39:30 +0200414 if (tb[NL80211_KEY_TYPE]) {
415 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
416 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
417 return -EINVAL;
418 }
419
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100420 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
421 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
422 int err = nla_parse_nested(kdt,
423 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
424 tb[NL80211_KEY_DEFAULT_TYPES],
425 nl80211_key_default_policy);
426 if (err)
427 return err;
428
429 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
430 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
431 }
432
Johannes Bergb9454e82009-07-08 13:29:08 +0200433 return 0;
434}
435
436static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
437{
438 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
439 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
440 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
441 }
442
443 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
444 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
445 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
446 }
447
448 if (info->attrs[NL80211_ATTR_KEY_IDX])
449 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
450
451 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
452 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
453
454 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
455 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
456
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100457 if (k->def) {
458 k->def_uni = true;
459 k->def_multi = true;
460 }
461 if (k->defmgmt)
462 k->def_multi = true;
463
Johannes Berge31b8212010-10-05 19:39:30 +0200464 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
465 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
466 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
467 return -EINVAL;
468 }
469
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100470 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
471 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
472 int err = nla_parse_nested(
473 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
474 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
475 nl80211_key_default_policy);
476 if (err)
477 return err;
478
479 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
480 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
481 }
482
Johannes Bergb9454e82009-07-08 13:29:08 +0200483 return 0;
484}
485
486static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
487{
488 int err;
489
490 memset(k, 0, sizeof(*k));
491 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200492 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200493
494 if (info->attrs[NL80211_ATTR_KEY])
495 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
496 else
497 err = nl80211_parse_key_old(info, k);
498
499 if (err)
500 return err;
501
502 if (k->def && k->defmgmt)
503 return -EINVAL;
504
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100505 if (k->defmgmt) {
506 if (k->def_uni || !k->def_multi)
507 return -EINVAL;
508 }
509
Johannes Bergb9454e82009-07-08 13:29:08 +0200510 if (k->idx != -1) {
511 if (k->defmgmt) {
512 if (k->idx < 4 || k->idx > 5)
513 return -EINVAL;
514 } else if (k->def) {
515 if (k->idx < 0 || k->idx > 3)
516 return -EINVAL;
517 } else {
518 if (k->idx < 0 || k->idx > 5)
519 return -EINVAL;
520 }
521 }
522
523 return 0;
524}
525
Johannes Bergfffd0932009-07-08 14:22:54 +0200526static struct cfg80211_cached_keys *
527nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
528 struct nlattr *keys)
529{
530 struct key_parse parse;
531 struct nlattr *key;
532 struct cfg80211_cached_keys *result;
533 int rem, err, def = 0;
534
535 result = kzalloc(sizeof(*result), GFP_KERNEL);
536 if (!result)
537 return ERR_PTR(-ENOMEM);
538
539 result->def = -1;
540 result->defmgmt = -1;
541
542 nla_for_each_nested(key, keys, rem) {
543 memset(&parse, 0, sizeof(parse));
544 parse.idx = -1;
545
546 err = nl80211_parse_key_new(key, &parse);
547 if (err)
548 goto error;
549 err = -EINVAL;
550 if (!parse.p.key)
551 goto error;
552 if (parse.idx < 0 || parse.idx > 4)
553 goto error;
554 if (parse.def) {
555 if (def)
556 goto error;
557 def = 1;
558 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100559 if (!parse.def_uni || !parse.def_multi)
560 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200561 } else if (parse.defmgmt)
562 goto error;
563 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200564 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200565 if (err)
566 goto error;
567 result->params[parse.idx].cipher = parse.p.cipher;
568 result->params[parse.idx].key_len = parse.p.key_len;
569 result->params[parse.idx].key = result->data[parse.idx];
570 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
571 }
572
573 return result;
574 error:
575 kfree(result);
576 return ERR_PTR(err);
577}
578
579static int nl80211_key_allowed(struct wireless_dev *wdev)
580{
581 ASSERT_WDEV_LOCK(wdev);
582
Johannes Bergfffd0932009-07-08 14:22:54 +0200583 switch (wdev->iftype) {
584 case NL80211_IFTYPE_AP:
585 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200586 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700587 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200588 break;
589 case NL80211_IFTYPE_ADHOC:
590 if (!wdev->current_bss)
591 return -ENOLINK;
592 break;
593 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200594 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200595 if (wdev->sme_state != CFG80211_SME_CONNECTED)
596 return -ENOLINK;
597 break;
598 default:
599 return -EINVAL;
600 }
601
602 return 0;
603}
604
Johannes Berg7527a782011-05-13 10:58:57 +0200605static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
606{
607 struct nlattr *nl_modes = nla_nest_start(msg, attr);
608 int i;
609
610 if (!nl_modes)
611 goto nla_put_failure;
612
613 i = 0;
614 while (ifmodes) {
615 if (ifmodes & 1)
616 NLA_PUT_FLAG(msg, i);
617 ifmodes >>= 1;
618 i++;
619 }
620
621 nla_nest_end(msg, nl_modes);
622 return 0;
623
624nla_put_failure:
625 return -ENOBUFS;
626}
627
628static int nl80211_put_iface_combinations(struct wiphy *wiphy,
629 struct sk_buff *msg)
630{
631 struct nlattr *nl_combis;
632 int i, j;
633
634 nl_combis = nla_nest_start(msg,
635 NL80211_ATTR_INTERFACE_COMBINATIONS);
636 if (!nl_combis)
637 goto nla_put_failure;
638
639 for (i = 0; i < wiphy->n_iface_combinations; i++) {
640 const struct ieee80211_iface_combination *c;
641 struct nlattr *nl_combi, *nl_limits;
642
643 c = &wiphy->iface_combinations[i];
644
645 nl_combi = nla_nest_start(msg, i + 1);
646 if (!nl_combi)
647 goto nla_put_failure;
648
649 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
650 if (!nl_limits)
651 goto nla_put_failure;
652
653 for (j = 0; j < c->n_limits; j++) {
654 struct nlattr *nl_limit;
655
656 nl_limit = nla_nest_start(msg, j + 1);
657 if (!nl_limit)
658 goto nla_put_failure;
659 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
660 c->limits[j].max);
661 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
662 c->limits[j].types))
663 goto nla_put_failure;
664 nla_nest_end(msg, nl_limit);
665 }
666
667 nla_nest_end(msg, nl_limits);
668
669 if (c->beacon_int_infra_match)
670 NLA_PUT_FLAG(msg,
671 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
672 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
673 c->num_different_channels);
674 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
675 c->max_interfaces);
676
677 nla_nest_end(msg, nl_combi);
678 }
679
680 nla_nest_end(msg, nl_combis);
681
682 return 0;
683nla_put_failure:
684 return -ENOBUFS;
685}
686
Johannes Berg55682962007-09-20 13:09:35 -0400687static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
688 struct cfg80211_registered_device *dev)
689{
690 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100691 struct nlattr *nl_bands, *nl_band;
692 struct nlattr *nl_freqs, *nl_freq;
693 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100694 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100695 enum ieee80211_band band;
696 struct ieee80211_channel *chan;
697 struct ieee80211_rate *rate;
698 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200699 const struct ieee80211_txrx_stypes *mgmt_stypes =
700 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400701
702 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
703 if (!hdr)
704 return -1;
705
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500706 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400707 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200708
Johannes Bergf5ea9122009-08-07 16:17:38 +0200709 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
710 cfg80211_rdev_list_generation);
711
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200712 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
713 dev->wiphy.retry_short);
714 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
715 dev->wiphy.retry_long);
716 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
717 dev->wiphy.frag_threshold);
718 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
719 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100720 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
721 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100722 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
723 dev->wiphy.max_scan_ssids);
Luciano Coelho93b6aa62011-07-13 14:57:28 +0300724 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
725 dev->wiphy.max_sched_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200726 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
727 dev->wiphy.max_scan_ie_len);
Luciano Coelho5a865ba2011-07-13 14:57:29 +0300728 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
729 dev->wiphy.max_sched_scan_ie_len);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300730 NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
731 dev->wiphy.max_match_sets);
Johannes Bergee688b002008-01-24 19:38:39 +0100732
Johannes Berge31b8212010-10-05 19:39:30 +0200733 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
734 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
Javier Cardona15d5dda2011-04-07 15:08:28 -0700735 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
736 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
Eliad Pellercedb5412011-08-31 11:29:43 +0300737 if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
738 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530739 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
740 NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300741 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
742 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
743 if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
744 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530745
Johannes Berg25e47c12009-04-02 20:14:06 +0200746 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
747 sizeof(u32) * dev->wiphy.n_cipher_suites,
748 dev->wiphy.cipher_suites);
749
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100750 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
751 dev->wiphy.max_num_pmkids);
752
Johannes Bergc0692b82010-08-27 14:26:53 +0300753 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
754 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
755
Bruno Randolf39fd5de2010-12-16 11:30:28 +0900756 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
757 dev->wiphy.available_antennas_tx);
758 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
759 dev->wiphy.available_antennas_rx);
760
Bruno Randolf7f531e02010-12-16 11:30:22 +0900761 if ((dev->wiphy.available_antennas_tx ||
762 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900763 u32 tx_ant = 0, rx_ant = 0;
764 int res;
765 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
766 if (!res) {
767 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
768 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
769 }
770 }
771
Johannes Berg7527a782011-05-13 10:58:57 +0200772 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
773 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700774 goto nla_put_failure;
775
Johannes Bergee688b002008-01-24 19:38:39 +0100776 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
777 if (!nl_bands)
778 goto nla_put_failure;
779
780 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
781 if (!dev->wiphy.bands[band])
782 continue;
783
784 nl_band = nla_nest_start(msg, band);
785 if (!nl_band)
786 goto nla_put_failure;
787
Johannes Bergd51626d2008-10-09 12:20:13 +0200788 /* add HT info */
789 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
790 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
791 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
792 &dev->wiphy.bands[band]->ht_cap.mcs);
793 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
794 dev->wiphy.bands[band]->ht_cap.cap);
795 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
796 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
797 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
798 dev->wiphy.bands[band]->ht_cap.ampdu_density);
799 }
800
Johannes Bergee688b002008-01-24 19:38:39 +0100801 /* add frequencies */
802 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
803 if (!nl_freqs)
804 goto nla_put_failure;
805
806 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
807 nl_freq = nla_nest_start(msg, i);
808 if (!nl_freq)
809 goto nla_put_failure;
810
811 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100812
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400813 if (nl80211_msg_put_channel(msg, chan))
814 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200815
Johannes Bergee688b002008-01-24 19:38:39 +0100816 nla_nest_end(msg, nl_freq);
817 }
818
819 nla_nest_end(msg, nl_freqs);
820
821 /* add bitrates */
822 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
823 if (!nl_rates)
824 goto nla_put_failure;
825
826 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
827 nl_rate = nla_nest_start(msg, i);
828 if (!nl_rate)
829 goto nla_put_failure;
830
831 rate = &dev->wiphy.bands[band]->bitrates[i];
832 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
833 rate->bitrate);
834 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
835 NLA_PUT_FLAG(msg,
836 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
837
838 nla_nest_end(msg, nl_rate);
839 }
840
841 nla_nest_end(msg, nl_rates);
842
843 nla_nest_end(msg, nl_band);
844 }
845 nla_nest_end(msg, nl_bands);
846
Johannes Berg8fdc6212009-03-14 09:34:01 +0100847 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
848 if (!nl_cmds)
849 goto nla_put_failure;
850
851 i = 0;
852#define CMD(op, n) \
853 do { \
854 if (dev->ops->op) { \
855 i++; \
856 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
857 } \
858 } while (0)
859
860 CMD(add_virtual_intf, NEW_INTERFACE);
861 CMD(change_virtual_intf, SET_INTERFACE);
862 CMD(add_key, NEW_KEY);
863 CMD(add_beacon, NEW_BEACON);
864 CMD(add_station, NEW_STATION);
865 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800866 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100867 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200868 CMD(auth, AUTHENTICATE);
869 CMD(assoc, ASSOCIATE);
870 CMD(deauth, DEAUTHENTICATE);
871 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200872 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100873 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100874 CMD(set_pmksa, SET_PMKSA);
875 CMD(del_pmksa, DEL_PMKSA);
876 CMD(flush_pmksa, FLUSH_PMKSA);
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100877 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200878 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200879 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100880 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100881 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200882 i++;
883 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
884 }
Johannes Bergf444de02010-05-05 15:25:02 +0200885 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400886 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300887 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
888 CMD(tdls_mgmt, TDLS_MGMT);
889 CMD(tdls_oper, TDLS_OPER);
890 }
Luciano Coelho807f8a82011-05-11 17:09:35 +0300891 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
892 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100893
894#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200895
Johannes Berg6829c872009-07-02 09:13:27 +0200896 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200897 i++;
898 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
899 }
900
Johannes Berg6829c872009-07-02 09:13:27 +0200901 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200902 i++;
903 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
904 }
905
Johannes Berg8fdc6212009-03-14 09:34:01 +0100906 nla_nest_end(msg, nl_cmds);
907
Johannes Berga2939112010-12-14 17:54:28 +0100908 if (dev->ops->remain_on_channel)
909 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
910 dev->wiphy.max_remain_on_channel_duration);
911
Jouni Malinend2da5872011-08-08 12:10:30 +0300912 if (dev->ops->mgmt_tx_cancel_wait)
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100913 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
914
Johannes Berg2e161f72010-08-12 15:38:38 +0200915 if (mgmt_stypes) {
916 u16 stypes;
917 struct nlattr *nl_ftypes, *nl_ifs;
918 enum nl80211_iftype ift;
919
920 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
921 if (!nl_ifs)
922 goto nla_put_failure;
923
924 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
925 nl_ftypes = nla_nest_start(msg, ift);
926 if (!nl_ftypes)
927 goto nla_put_failure;
928 i = 0;
929 stypes = mgmt_stypes[ift].tx;
930 while (stypes) {
931 if (stypes & 1)
932 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
933 (i << 4) | IEEE80211_FTYPE_MGMT);
934 stypes >>= 1;
935 i++;
936 }
937 nla_nest_end(msg, nl_ftypes);
938 }
939
Johannes Berg74b70a42010-08-24 12:15:53 +0200940 nla_nest_end(msg, nl_ifs);
941
Johannes Berg2e161f72010-08-12 15:38:38 +0200942 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
943 if (!nl_ifs)
944 goto nla_put_failure;
945
946 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
947 nl_ftypes = nla_nest_start(msg, ift);
948 if (!nl_ftypes)
949 goto nla_put_failure;
950 i = 0;
951 stypes = mgmt_stypes[ift].rx;
952 while (stypes) {
953 if (stypes & 1)
954 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
955 (i << 4) | IEEE80211_FTYPE_MGMT);
956 stypes >>= 1;
957 i++;
958 }
959 nla_nest_end(msg, nl_ftypes);
960 }
961 nla_nest_end(msg, nl_ifs);
962 }
963
Johannes Bergff1b6e62011-05-04 15:37:28 +0200964 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
965 struct nlattr *nl_wowlan;
966
967 nl_wowlan = nla_nest_start(msg,
968 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
969 if (!nl_wowlan)
970 goto nla_put_failure;
971
972 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
973 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
974 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
975 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
976 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
977 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +0200978 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
979 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
980 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
981 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
982 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
983 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
984 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
985 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
986 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
987 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +0200988 if (dev->wiphy.wowlan.n_patterns) {
989 struct nl80211_wowlan_pattern_support pat = {
990 .max_patterns = dev->wiphy.wowlan.n_patterns,
991 .min_pattern_len =
992 dev->wiphy.wowlan.pattern_min_len,
993 .max_pattern_len =
994 dev->wiphy.wowlan.pattern_max_len,
995 };
996 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
997 sizeof(pat), &pat);
998 }
999
1000 nla_nest_end(msg, nl_wowlan);
1001 }
1002
Johannes Berg7527a782011-05-13 10:58:57 +02001003 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1004 dev->wiphy.software_iftypes))
1005 goto nla_put_failure;
1006
1007 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1008 goto nla_put_failure;
1009
Johannes Berg562a7482011-11-07 12:39:33 +01001010 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
1011 NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
1012 dev->wiphy.ap_sme_capa);
1013
Johannes Berg55682962007-09-20 13:09:35 -04001014 return genlmsg_end(msg, hdr);
1015
1016 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001017 genlmsg_cancel(msg, hdr);
1018 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001019}
1020
1021static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1022{
1023 int idx = 0;
1024 int start = cb->args[0];
1025 struct cfg80211_registered_device *dev;
1026
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001027 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001028 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001029 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1030 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001031 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001032 continue;
1033 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1034 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001035 dev) < 0) {
1036 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001037 break;
Julius Volzb4637272008-07-08 14:02:19 +02001038 }
Johannes Berg55682962007-09-20 13:09:35 -04001039 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001040 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001041
1042 cb->args[0] = idx;
1043
1044 return skb->len;
1045}
1046
1047static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1048{
1049 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001050 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001051
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001053 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001054 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001055
Johannes Berg4c476992010-10-04 21:36:35 +02001056 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1057 nlmsg_free(msg);
1058 return -ENOBUFS;
1059 }
Johannes Berg55682962007-09-20 13:09:35 -04001060
Johannes Berg134e6372009-07-10 09:51:34 +00001061 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001062}
1063
Jouni Malinen31888482008-10-30 16:59:24 +02001064static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1065 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1066 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1067 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1068 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1069 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1070};
1071
1072static int parse_txq_params(struct nlattr *tb[],
1073 struct ieee80211_txq_params *txq_params)
1074{
1075 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1076 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1077 !tb[NL80211_TXQ_ATTR_AIFS])
1078 return -EINVAL;
1079
1080 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1081 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1082 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1083 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1084 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1085
1086 return 0;
1087}
1088
Johannes Bergf444de02010-05-05 15:25:02 +02001089static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1090{
1091 /*
1092 * You can only set the channel explicitly for AP, mesh
1093 * and WDS type interfaces; all others have their channel
1094 * managed via their respective "establish a connection"
1095 * command (connect, join, ...)
1096 *
1097 * Monitors are special as they are normally slaved to
1098 * whatever else is going on, so they behave as though
1099 * you tried setting the wiphy channel itself.
1100 */
1101 return !wdev ||
1102 wdev->iftype == NL80211_IFTYPE_AP ||
1103 wdev->iftype == NL80211_IFTYPE_WDS ||
1104 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001105 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1106 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001107}
1108
1109static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1110 struct wireless_dev *wdev,
1111 struct genl_info *info)
1112{
1113 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1114 u32 freq;
1115 int result;
1116
1117 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1118 return -EINVAL;
1119
1120 if (!nl80211_can_set_dev_channel(wdev))
1121 return -EOPNOTSUPP;
1122
1123 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1124 channel_type = nla_get_u32(info->attrs[
1125 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1126 if (channel_type != NL80211_CHAN_NO_HT &&
1127 channel_type != NL80211_CHAN_HT20 &&
1128 channel_type != NL80211_CHAN_HT40PLUS &&
1129 channel_type != NL80211_CHAN_HT40MINUS)
1130 return -EINVAL;
1131 }
1132
1133 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1134
1135 mutex_lock(&rdev->devlist_mtx);
1136 if (wdev) {
1137 wdev_lock(wdev);
1138 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1139 wdev_unlock(wdev);
1140 } else {
1141 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1142 }
1143 mutex_unlock(&rdev->devlist_mtx);
1144
1145 return result;
1146}
1147
1148static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1149{
Johannes Berg4c476992010-10-04 21:36:35 +02001150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1151 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001152
Johannes Berg4c476992010-10-04 21:36:35 +02001153 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001154}
1155
Bill Jordane8347eb2010-10-01 13:54:28 -04001156static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1157{
Johannes Berg43b19952010-10-07 13:10:30 +02001158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1159 struct net_device *dev = info->user_ptr[1];
1160 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001161 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001162
1163 if (!info->attrs[NL80211_ATTR_MAC])
1164 return -EINVAL;
1165
Johannes Berg43b19952010-10-07 13:10:30 +02001166 if (netif_running(dev))
1167 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001168
Johannes Berg43b19952010-10-07 13:10:30 +02001169 if (!rdev->ops->set_wds_peer)
1170 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001171
Johannes Berg43b19952010-10-07 13:10:30 +02001172 if (wdev->iftype != NL80211_IFTYPE_WDS)
1173 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001174
1175 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001176 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001177}
1178
1179
Johannes Berg55682962007-09-20 13:09:35 -04001180static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1181{
1182 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001183 struct net_device *netdev = NULL;
1184 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001185 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001186 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001187 u32 changed;
1188 u8 retry_short = 0, retry_long = 0;
1189 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001190 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001191
Johannes Bergf444de02010-05-05 15:25:02 +02001192 /*
1193 * Try to find the wiphy and netdev. Normally this
1194 * function shouldn't need the netdev, but this is
1195 * done for backward compatibility -- previously
1196 * setting the channel was done per wiphy, but now
1197 * it is per netdev. Previous userland like hostapd
1198 * also passed a netdev to set_wiphy, so that it is
1199 * possible to let that go to the right netdev!
1200 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001201 mutex_lock(&cfg80211_mutex);
1202
Johannes Bergf444de02010-05-05 15:25:02 +02001203 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1204 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1205
1206 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1207 if (netdev && netdev->ieee80211_ptr) {
1208 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1209 mutex_lock(&rdev->mtx);
1210 } else
1211 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001212 }
1213
Johannes Bergf444de02010-05-05 15:25:02 +02001214 if (!netdev) {
1215 rdev = __cfg80211_rdev_from_info(info);
1216 if (IS_ERR(rdev)) {
1217 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001218 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001219 }
1220 wdev = NULL;
1221 netdev = NULL;
1222 result = 0;
1223
1224 mutex_lock(&rdev->mtx);
1225 } else if (netif_running(netdev) &&
1226 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1227 wdev = netdev->ieee80211_ptr;
1228 else
1229 wdev = NULL;
1230
1231 /*
1232 * end workaround code, by now the rdev is available
1233 * and locked, and wdev may or may not be NULL.
1234 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001235
1236 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001237 result = cfg80211_dev_rename(
1238 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001239
1240 mutex_unlock(&cfg80211_mutex);
1241
1242 if (result)
1243 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001244
Jouni Malinen31888482008-10-30 16:59:24 +02001245 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1246 struct ieee80211_txq_params txq_params;
1247 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1248
1249 if (!rdev->ops->set_txq_params) {
1250 result = -EOPNOTSUPP;
1251 goto bad_res;
1252 }
1253
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001254 if (!netdev) {
1255 result = -EINVAL;
1256 goto bad_res;
1257 }
1258
Johannes Berg133a3ff2011-11-03 14:50:13 +01001259 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1260 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1261 result = -EINVAL;
1262 goto bad_res;
1263 }
1264
Jouni Malinen31888482008-10-30 16:59:24 +02001265 nla_for_each_nested(nl_txq_params,
1266 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1267 rem_txq_params) {
1268 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1269 nla_data(nl_txq_params),
1270 nla_len(nl_txq_params),
1271 txq_params_policy);
1272 result = parse_txq_params(tb, &txq_params);
1273 if (result)
1274 goto bad_res;
1275
1276 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001277 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001278 &txq_params);
1279 if (result)
1280 goto bad_res;
1281 }
1282 }
1283
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001284 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001285 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001286 if (result)
1287 goto bad_res;
1288 }
1289
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001290 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1291 enum nl80211_tx_power_setting type;
1292 int idx, mbm = 0;
1293
1294 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001295 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001296 goto bad_res;
1297 }
1298
1299 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1300 type = nla_get_u32(info->attrs[idx]);
1301
1302 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1303 (type != NL80211_TX_POWER_AUTOMATIC)) {
1304 result = -EINVAL;
1305 goto bad_res;
1306 }
1307
1308 if (type != NL80211_TX_POWER_AUTOMATIC) {
1309 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1310 mbm = nla_get_u32(info->attrs[idx]);
1311 }
1312
1313 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1314 if (result)
1315 goto bad_res;
1316 }
1317
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001318 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1319 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1320 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001321 if ((!rdev->wiphy.available_antennas_tx &&
1322 !rdev->wiphy.available_antennas_rx) ||
1323 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001324 result = -EOPNOTSUPP;
1325 goto bad_res;
1326 }
1327
1328 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1329 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1330
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001331 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001332 * available antenna masks, except for the "all" mask */
1333 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1334 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001335 result = -EINVAL;
1336 goto bad_res;
1337 }
1338
Bruno Randolf7f531e02010-12-16 11:30:22 +09001339 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1340 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001341
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001342 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1343 if (result)
1344 goto bad_res;
1345 }
1346
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001347 changed = 0;
1348
1349 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1350 retry_short = nla_get_u8(
1351 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1352 if (retry_short == 0) {
1353 result = -EINVAL;
1354 goto bad_res;
1355 }
1356 changed |= WIPHY_PARAM_RETRY_SHORT;
1357 }
1358
1359 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1360 retry_long = nla_get_u8(
1361 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1362 if (retry_long == 0) {
1363 result = -EINVAL;
1364 goto bad_res;
1365 }
1366 changed |= WIPHY_PARAM_RETRY_LONG;
1367 }
1368
1369 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1370 frag_threshold = nla_get_u32(
1371 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1372 if (frag_threshold < 256) {
1373 result = -EINVAL;
1374 goto bad_res;
1375 }
1376 if (frag_threshold != (u32) -1) {
1377 /*
1378 * Fragments (apart from the last one) are required to
1379 * have even length. Make the fragmentation code
1380 * simpler by stripping LSB should someone try to use
1381 * odd threshold value.
1382 */
1383 frag_threshold &= ~0x1;
1384 }
1385 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1386 }
1387
1388 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1389 rts_threshold = nla_get_u32(
1390 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1391 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1392 }
1393
Lukáš Turek81077e82009-12-21 22:50:47 +01001394 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1395 coverage_class = nla_get_u8(
1396 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1397 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1398 }
1399
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001400 if (changed) {
1401 u8 old_retry_short, old_retry_long;
1402 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001403 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001404
1405 if (!rdev->ops->set_wiphy_params) {
1406 result = -EOPNOTSUPP;
1407 goto bad_res;
1408 }
1409
1410 old_retry_short = rdev->wiphy.retry_short;
1411 old_retry_long = rdev->wiphy.retry_long;
1412 old_frag_threshold = rdev->wiphy.frag_threshold;
1413 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001414 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001415
1416 if (changed & WIPHY_PARAM_RETRY_SHORT)
1417 rdev->wiphy.retry_short = retry_short;
1418 if (changed & WIPHY_PARAM_RETRY_LONG)
1419 rdev->wiphy.retry_long = retry_long;
1420 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1421 rdev->wiphy.frag_threshold = frag_threshold;
1422 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1423 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001424 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1425 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001426
1427 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1428 if (result) {
1429 rdev->wiphy.retry_short = old_retry_short;
1430 rdev->wiphy.retry_long = old_retry_long;
1431 rdev->wiphy.frag_threshold = old_frag_threshold;
1432 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001433 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001434 }
1435 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001436
Johannes Berg306d6112008-12-08 12:39:04 +01001437 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001438 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001439 if (netdev)
1440 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001441 return result;
1442}
1443
1444
1445static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001446 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001447 struct net_device *dev)
1448{
1449 void *hdr;
1450
1451 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1452 if (!hdr)
1453 return -1;
1454
1455 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001456 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001457 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001458 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001459
1460 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1461 rdev->devlist_generation ^
1462 (cfg80211_rdev_list_generation << 2));
1463
Johannes Berg55682962007-09-20 13:09:35 -04001464 return genlmsg_end(msg, hdr);
1465
1466 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001467 genlmsg_cancel(msg, hdr);
1468 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001469}
1470
1471static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1472{
1473 int wp_idx = 0;
1474 int if_idx = 0;
1475 int wp_start = cb->args[0];
1476 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001477 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001478 struct wireless_dev *wdev;
1479
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001480 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001481 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1482 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001483 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001484 if (wp_idx < wp_start) {
1485 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001486 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001487 }
Johannes Berg55682962007-09-20 13:09:35 -04001488 if_idx = 0;
1489
Johannes Bergf5ea9122009-08-07 16:17:38 +02001490 mutex_lock(&rdev->devlist_mtx);
1491 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001492 if (if_idx < if_start) {
1493 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001494 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001495 }
Johannes Berg55682962007-09-20 13:09:35 -04001496 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1497 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001498 rdev, wdev->netdev) < 0) {
1499 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001500 goto out;
1501 }
1502 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001503 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001504 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001505
1506 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001507 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001508 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001509 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001510
1511 cb->args[0] = wp_idx;
1512 cb->args[1] = if_idx;
1513
1514 return skb->len;
1515}
1516
1517static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1518{
1519 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001520 struct cfg80211_registered_device *dev = info->user_ptr[0];
1521 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001522
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001524 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001525 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001526
Johannes Bergd7264052009-04-19 16:23:20 +02001527 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001528 dev, netdev) < 0) {
1529 nlmsg_free(msg);
1530 return -ENOBUFS;
1531 }
Johannes Berg55682962007-09-20 13:09:35 -04001532
Johannes Berg134e6372009-07-10 09:51:34 +00001533 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001534}
1535
Michael Wu66f7ac52008-01-31 19:48:22 +01001536static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1537 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1538 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1539 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1540 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1541 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1542};
1543
1544static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1545{
1546 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1547 int flag;
1548
1549 *mntrflags = 0;
1550
1551 if (!nla)
1552 return -EINVAL;
1553
1554 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1555 nla, mntr_flags_policy))
1556 return -EINVAL;
1557
1558 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1559 if (flags[flag])
1560 *mntrflags |= (1<<flag);
1561
1562 return 0;
1563}
1564
Johannes Berg9bc383d2009-11-19 11:55:19 +01001565static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001566 struct net_device *netdev, u8 use_4addr,
1567 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001568{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001569 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001570 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001571 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001572 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001573 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001574
1575 switch (iftype) {
1576 case NL80211_IFTYPE_AP_VLAN:
1577 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1578 return 0;
1579 break;
1580 case NL80211_IFTYPE_STATION:
1581 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1582 return 0;
1583 break;
1584 default:
1585 break;
1586 }
1587
1588 return -EOPNOTSUPP;
1589}
1590
Johannes Berg55682962007-09-20 13:09:35 -04001591static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1592{
Johannes Berg4c476992010-10-04 21:36:35 +02001593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001594 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001595 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001596 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001597 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001598 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001599 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001600
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001601 memset(&params, 0, sizeof(params));
1602
Johannes Berg04a773a2009-04-19 21:24:32 +02001603 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001604
Johannes Berg723b0382008-09-16 20:22:09 +02001605 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001606 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001607 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001608 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001609 if (ntype > NL80211_IFTYPE_MAX)
1610 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001611 }
1612
Johannes Berg92ffe052008-09-16 20:39:36 +02001613 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001614 struct wireless_dev *wdev = dev->ieee80211_ptr;
1615
Johannes Berg4c476992010-10-04 21:36:35 +02001616 if (ntype != NL80211_IFTYPE_MESH_POINT)
1617 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001618 if (netif_running(dev))
1619 return -EBUSY;
1620
1621 wdev_lock(wdev);
1622 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1623 IEEE80211_MAX_MESH_ID_LEN);
1624 wdev->mesh_id_up_len =
1625 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1626 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1627 wdev->mesh_id_up_len);
1628 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001629 }
1630
Felix Fietkau8b787642009-11-10 18:53:10 +01001631 if (info->attrs[NL80211_ATTR_4ADDR]) {
1632 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1633 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001634 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001635 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001636 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001637 } else {
1638 params.use_4addr = -1;
1639 }
1640
Johannes Berg92ffe052008-09-16 20:39:36 +02001641 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001642 if (ntype != NL80211_IFTYPE_MONITOR)
1643 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001644 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1645 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001646 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001647 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001648
1649 flags = &_flags;
1650 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001651 }
Johannes Berg3b858752009-03-12 09:55:09 +01001652
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001653 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001654 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001655 else
1656 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001657
Johannes Berg9bc383d2009-11-19 11:55:19 +01001658 if (!err && params.use_4addr != -1)
1659 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1660
Johannes Berg55682962007-09-20 13:09:35 -04001661 return err;
1662}
1663
1664static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1665{
Johannes Berg4c476992010-10-04 21:36:35 +02001666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001667 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001668 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001669 int err;
1670 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001671 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001672
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001673 memset(&params, 0, sizeof(params));
1674
Johannes Berg55682962007-09-20 13:09:35 -04001675 if (!info->attrs[NL80211_ATTR_IFNAME])
1676 return -EINVAL;
1677
1678 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1679 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1680 if (type > NL80211_IFTYPE_MAX)
1681 return -EINVAL;
1682 }
1683
Johannes Berg79c97e92009-07-07 03:56:12 +02001684 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001685 !(rdev->wiphy.interface_modes & (1 << type)))
1686 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001687
Johannes Berg9bc383d2009-11-19 11:55:19 +01001688 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001689 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001690 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001691 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001692 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001693 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001694
Michael Wu66f7ac52008-01-31 19:48:22 +01001695 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1696 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1697 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001698 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001699 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001700 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001701 if (IS_ERR(dev))
1702 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001703
Johannes Berg29cbe682010-12-03 09:20:44 +01001704 if (type == NL80211_IFTYPE_MESH_POINT &&
1705 info->attrs[NL80211_ATTR_MESH_ID]) {
1706 struct wireless_dev *wdev = dev->ieee80211_ptr;
1707
1708 wdev_lock(wdev);
1709 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1710 IEEE80211_MAX_MESH_ID_LEN);
1711 wdev->mesh_id_up_len =
1712 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1713 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1714 wdev->mesh_id_up_len);
1715 wdev_unlock(wdev);
1716 }
1717
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001718 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001719}
1720
1721static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1722{
Johannes Berg4c476992010-10-04 21:36:35 +02001723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1724 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001725
Johannes Berg4c476992010-10-04 21:36:35 +02001726 if (!rdev->ops->del_virtual_intf)
1727 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001728
Johannes Berg4c476992010-10-04 21:36:35 +02001729 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001730}
1731
Johannes Berg41ade002007-12-19 02:03:29 +01001732struct get_key_cookie {
1733 struct sk_buff *msg;
1734 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001735 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001736};
1737
1738static void get_key_callback(void *c, struct key_params *params)
1739{
Johannes Bergb9454e82009-07-08 13:29:08 +02001740 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001741 struct get_key_cookie *cookie = c;
1742
1743 if (params->key)
1744 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1745 params->key_len, params->key);
1746
1747 if (params->seq)
1748 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1749 params->seq_len, params->seq);
1750
1751 if (params->cipher)
1752 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1753 params->cipher);
1754
Johannes Bergb9454e82009-07-08 13:29:08 +02001755 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1756 if (!key)
1757 goto nla_put_failure;
1758
1759 if (params->key)
1760 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1761 params->key_len, params->key);
1762
1763 if (params->seq)
1764 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1765 params->seq_len, params->seq);
1766
1767 if (params->cipher)
1768 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1769 params->cipher);
1770
1771 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1772
1773 nla_nest_end(cookie->msg, key);
1774
Johannes Berg41ade002007-12-19 02:03:29 +01001775 return;
1776 nla_put_failure:
1777 cookie->error = 1;
1778}
1779
1780static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1781{
Johannes Berg4c476992010-10-04 21:36:35 +02001782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001783 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001784 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001785 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001786 const u8 *mac_addr = NULL;
1787 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001788 struct get_key_cookie cookie = {
1789 .error = 0,
1790 };
1791 void *hdr;
1792 struct sk_buff *msg;
1793
1794 if (info->attrs[NL80211_ATTR_KEY_IDX])
1795 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1796
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001797 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001798 return -EINVAL;
1799
1800 if (info->attrs[NL80211_ATTR_MAC])
1801 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1802
Johannes Berge31b8212010-10-05 19:39:30 +02001803 pairwise = !!mac_addr;
1804 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1805 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1806 if (kt >= NUM_NL80211_KEYTYPES)
1807 return -EINVAL;
1808 if (kt != NL80211_KEYTYPE_GROUP &&
1809 kt != NL80211_KEYTYPE_PAIRWISE)
1810 return -EINVAL;
1811 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1812 }
1813
Johannes Berg4c476992010-10-04 21:36:35 +02001814 if (!rdev->ops->get_key)
1815 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001816
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001817 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001818 if (!msg)
1819 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001820
1821 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1822 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001823 if (IS_ERR(hdr))
1824 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001825
1826 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001827 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001828
1829 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1830 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1831 if (mac_addr)
1832 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1833
Johannes Berge31b8212010-10-05 19:39:30 +02001834 if (pairwise && mac_addr &&
1835 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1836 return -ENOENT;
1837
1838 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1839 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001840
1841 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001842 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001843
1844 if (cookie.error)
1845 goto nla_put_failure;
1846
1847 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001848 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001849
1850 nla_put_failure:
1851 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001852 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001853 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001854 return err;
1855}
1856
1857static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1858{
Johannes Berg4c476992010-10-04 21:36:35 +02001859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001860 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001861 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001862 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001863
Johannes Bergb9454e82009-07-08 13:29:08 +02001864 err = nl80211_parse_key(info, &key);
1865 if (err)
1866 return err;
1867
1868 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001869 return -EINVAL;
1870
Johannes Bergb9454e82009-07-08 13:29:08 +02001871 /* only support setting default key */
1872 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001873 return -EINVAL;
1874
Johannes Bergfffd0932009-07-08 14:22:54 +02001875 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001876
1877 if (key.def) {
1878 if (!rdev->ops->set_default_key) {
1879 err = -EOPNOTSUPP;
1880 goto out;
1881 }
1882
1883 err = nl80211_key_allowed(dev->ieee80211_ptr);
1884 if (err)
1885 goto out;
1886
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001887 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1888 key.def_uni, key.def_multi);
1889
1890 if (err)
1891 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001892
Johannes Berg3d23e342009-09-29 23:27:28 +02001893#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001894 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001895#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001896 } else {
1897 if (key.def_uni || !key.def_multi) {
1898 err = -EINVAL;
1899 goto out;
1900 }
1901
1902 if (!rdev->ops->set_default_mgmt_key) {
1903 err = -EOPNOTSUPP;
1904 goto out;
1905 }
1906
1907 err = nl80211_key_allowed(dev->ieee80211_ptr);
1908 if (err)
1909 goto out;
1910
1911 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1912 dev, key.idx);
1913 if (err)
1914 goto out;
1915
1916#ifdef CONFIG_CFG80211_WEXT
1917 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1918#endif
1919 }
1920
1921 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001922 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001923
Johannes Berg41ade002007-12-19 02:03:29 +01001924 return err;
1925}
1926
1927static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1928{
Johannes Berg4c476992010-10-04 21:36:35 +02001929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001930 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001931 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001932 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001933 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001934
Johannes Bergb9454e82009-07-08 13:29:08 +02001935 err = nl80211_parse_key(info, &key);
1936 if (err)
1937 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001938
Johannes Bergb9454e82009-07-08 13:29:08 +02001939 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001940 return -EINVAL;
1941
Johannes Berg41ade002007-12-19 02:03:29 +01001942 if (info->attrs[NL80211_ATTR_MAC])
1943 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1944
Johannes Berge31b8212010-10-05 19:39:30 +02001945 if (key.type == -1) {
1946 if (mac_addr)
1947 key.type = NL80211_KEYTYPE_PAIRWISE;
1948 else
1949 key.type = NL80211_KEYTYPE_GROUP;
1950 }
1951
1952 /* for now */
1953 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1954 key.type != NL80211_KEYTYPE_GROUP)
1955 return -EINVAL;
1956
Johannes Berg4c476992010-10-04 21:36:35 +02001957 if (!rdev->ops->add_key)
1958 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001959
Johannes Berge31b8212010-10-05 19:39:30 +02001960 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1961 key.type == NL80211_KEYTYPE_PAIRWISE,
1962 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001963 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001964
1965 wdev_lock(dev->ieee80211_ptr);
1966 err = nl80211_key_allowed(dev->ieee80211_ptr);
1967 if (!err)
1968 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001969 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001970 mac_addr, &key.p);
1971 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001972
Johannes Berg41ade002007-12-19 02:03:29 +01001973 return err;
1974}
1975
1976static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1977{
Johannes Berg4c476992010-10-04 21:36:35 +02001978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001979 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001980 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001981 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001982 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001983
Johannes Bergb9454e82009-07-08 13:29:08 +02001984 err = nl80211_parse_key(info, &key);
1985 if (err)
1986 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001987
1988 if (info->attrs[NL80211_ATTR_MAC])
1989 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1990
Johannes Berge31b8212010-10-05 19:39:30 +02001991 if (key.type == -1) {
1992 if (mac_addr)
1993 key.type = NL80211_KEYTYPE_PAIRWISE;
1994 else
1995 key.type = NL80211_KEYTYPE_GROUP;
1996 }
1997
1998 /* for now */
1999 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2000 key.type != NL80211_KEYTYPE_GROUP)
2001 return -EINVAL;
2002
Johannes Berg4c476992010-10-04 21:36:35 +02002003 if (!rdev->ops->del_key)
2004 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002005
Johannes Bergfffd0932009-07-08 14:22:54 +02002006 wdev_lock(dev->ieee80211_ptr);
2007 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002008
2009 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2010 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2011 err = -ENOENT;
2012
Johannes Bergfffd0932009-07-08 14:22:54 +02002013 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002014 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2015 key.type == NL80211_KEYTYPE_PAIRWISE,
2016 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002017
Johannes Berg3d23e342009-09-29 23:27:28 +02002018#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002019 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002020 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002021 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002022 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002023 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2024 }
2025#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002026 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002027
Johannes Berg41ade002007-12-19 02:03:29 +01002028 return err;
2029}
2030
Johannes Berged1b6cc2007-12-19 02:03:32 +01002031static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
2032{
2033 int (*call)(struct wiphy *wiphy, struct net_device *dev,
2034 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02002035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2036 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002037 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002038 struct beacon_parameters params;
Johannes Berg56d18932011-05-09 18:41:15 +02002039 int haveinfo = 0, err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002040
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002041 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2042 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2043 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2044 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002045 return -EINVAL;
2046
Johannes Berg074ac8d2010-09-16 14:58:22 +02002047 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002048 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2049 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002050
Johannes Berg56d18932011-05-09 18:41:15 +02002051 memset(&params, 0, sizeof(params));
2052
Johannes Berged1b6cc2007-12-19 02:03:32 +01002053 switch (info->genlhdr->cmd) {
2054 case NL80211_CMD_NEW_BEACON:
2055 /* these are required for NEW_BEACON */
2056 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2057 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02002058 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2059 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002060
Johannes Berg56d18932011-05-09 18:41:15 +02002061 params.interval =
2062 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2063 params.dtim_period =
2064 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2065
2066 err = cfg80211_validate_beacon_int(rdev, params.interval);
2067 if (err)
2068 return err;
2069
Jouni Malinen32e9de82011-08-10 23:53:31 +03002070 /*
2071 * In theory, some of these attributes could be required for
2072 * NEW_BEACON, but since they were not used when the command was
2073 * originally added, keep them optional for old user space
2074 * programs to work with drivers that do not need the additional
2075 * information.
2076 */
2077 if (info->attrs[NL80211_ATTR_SSID]) {
2078 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2079 params.ssid_len =
2080 nla_len(info->attrs[NL80211_ATTR_SSID]);
2081 if (params.ssid_len == 0 ||
2082 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2083 return -EINVAL;
2084 }
2085
2086 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2087 params.hidden_ssid = nla_get_u32(
2088 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2089 if (params.hidden_ssid !=
2090 NL80211_HIDDEN_SSID_NOT_IN_USE &&
2091 params.hidden_ssid !=
2092 NL80211_HIDDEN_SSID_ZERO_LEN &&
2093 params.hidden_ssid !=
2094 NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2095 return -EINVAL;
2096 }
2097
Jouni Malinen5fb628e2011-08-10 23:54:35 +03002098 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2099
2100 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2101 params.auth_type = nla_get_u32(
2102 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2103 if (!nl80211_valid_auth_type(params.auth_type))
2104 return -EINVAL;
2105 } else
2106 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2107
2108 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2109 NL80211_MAX_NR_CIPHER_SUITES);
2110 if (err)
2111 return err;
2112
Johannes Berg79c97e92009-07-07 03:56:12 +02002113 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002114 break;
2115 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02002116 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002117 break;
2118 default:
2119 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02002120 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002121 }
2122
Johannes Berg4c476992010-10-04 21:36:35 +02002123 if (!call)
2124 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002125
Johannes Berged1b6cc2007-12-19 02:03:32 +01002126 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2127 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2128 params.head_len =
2129 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2130 haveinfo = 1;
2131 }
2132
2133 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2134 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2135 params.tail_len =
2136 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2137 haveinfo = 1;
2138 }
2139
Johannes Berg4c476992010-10-04 21:36:35 +02002140 if (!haveinfo)
2141 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002142
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002143 if (info->attrs[NL80211_ATTR_IE]) {
2144 params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2145 params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2146 }
2147
2148 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2149 params.proberesp_ies =
2150 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2151 params.proberesp_ies_len =
2152 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2153 }
2154
2155 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2156 params.assocresp_ies =
2157 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2158 params.assocresp_ies_len =
2159 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2160 }
2161
Johannes Berg56d18932011-05-09 18:41:15 +02002162 err = call(&rdev->wiphy, dev, &params);
2163 if (!err && params.interval)
2164 wdev->beacon_interval = params.interval;
2165 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002166}
2167
2168static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
2169{
Johannes Berg4c476992010-10-04 21:36:35 +02002170 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2171 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002172 struct wireless_dev *wdev = dev->ieee80211_ptr;
2173 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002174
Johannes Berg4c476992010-10-04 21:36:35 +02002175 if (!rdev->ops->del_beacon)
2176 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002177
Johannes Berg074ac8d2010-09-16 14:58:22 +02002178 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002179 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2180 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002181
Johannes Berg56d18932011-05-09 18:41:15 +02002182 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
2183 if (!err)
2184 wdev->beacon_interval = 0;
2185 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002186}
2187
Johannes Berg5727ef12007-12-19 02:03:34 +01002188static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2189 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2190 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2191 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002192 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002193 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002194};
2195
Johannes Bergeccb8e82009-05-11 21:57:56 +03002196static int parse_station_flags(struct genl_info *info,
2197 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002198{
2199 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002200 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002201 int flag;
2202
Johannes Bergeccb8e82009-05-11 21:57:56 +03002203 /*
2204 * Try parsing the new attribute first so userspace
2205 * can specify both for older kernels.
2206 */
2207 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2208 if (nla) {
2209 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002210
Johannes Bergeccb8e82009-05-11 21:57:56 +03002211 sta_flags = nla_data(nla);
2212 params->sta_flags_mask = sta_flags->mask;
2213 params->sta_flags_set = sta_flags->set;
2214 if ((params->sta_flags_mask |
2215 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2216 return -EINVAL;
2217 return 0;
2218 }
2219
2220 /* if present, parse the old attribute */
2221
2222 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002223 if (!nla)
2224 return 0;
2225
2226 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2227 nla, sta_flags_policy))
2228 return -EINVAL;
2229
Johannes Bergeccb8e82009-05-11 21:57:56 +03002230 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
2231 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002232
2233 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2234 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002235 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002236
2237 return 0;
2238}
2239
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002240static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2241 int attr)
2242{
2243 struct nlattr *rate;
2244 u16 bitrate;
2245
2246 rate = nla_nest_start(msg, attr);
2247 if (!rate)
2248 goto nla_put_failure;
2249
2250 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2251 bitrate = cfg80211_calculate_bitrate(info);
2252 if (bitrate > 0)
2253 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2254
2255 if (info->flags & RATE_INFO_FLAGS_MCS)
2256 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2257 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2258 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2259 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2260 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2261
2262 nla_nest_end(msg, rate);
2263 return true;
2264
2265nla_put_failure:
2266 return false;
2267}
2268
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002269static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2270 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002271 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002272{
2273 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002274 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002275
2276 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2277 if (!hdr)
2278 return -1;
2279
2280 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2281 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2282
Johannes Bergf5ea9122009-08-07 16:17:38 +02002283 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2284
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002285 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2286 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002287 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302288 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2289 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2290 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002291 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2292 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2293 sinfo->inactive_time);
2294 if (sinfo->filled & STATION_INFO_RX_BYTES)
2295 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2296 sinfo->rx_bytes);
2297 if (sinfo->filled & STATION_INFO_TX_BYTES)
2298 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2299 sinfo->tx_bytes);
2300 if (sinfo->filled & STATION_INFO_LLID)
2301 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2302 sinfo->llid);
2303 if (sinfo->filled & STATION_INFO_PLID)
2304 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2305 sinfo->plid);
2306 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2307 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2308 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002309 if (sinfo->filled & STATION_INFO_SIGNAL)
2310 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2311 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002312 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2313 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2314 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002315 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002316 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2317 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002318 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002319 }
2320 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2321 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2322 NL80211_STA_INFO_RX_BITRATE))
2323 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002324 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002325 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2326 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2327 sinfo->rx_packets);
2328 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2329 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2330 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002331 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2332 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2333 sinfo->tx_retries);
2334 if (sinfo->filled & STATION_INFO_TX_FAILED)
2335 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2336 sinfo->tx_failed);
Paul Stewartf4263c92011-03-31 09:25:41 -07002337 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2338 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2339 if (!bss_param)
2340 goto nla_put_failure;
2341
2342 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2343 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2344 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2345 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2346 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2347 NLA_PUT_FLAG(msg,
2348 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2349 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2350 sinfo->bss_param.dtim_period);
2351 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2352 sinfo->bss_param.beacon_interval);
2353
2354 nla_nest_end(msg, bss_param);
2355 }
Helmut Schaabb6e7532011-10-13 16:30:39 +02002356 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2357 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2358 sizeof(struct nl80211_sta_flag_update),
2359 &sinfo->sta_flags);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002360 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002361
Felix Fietkau040bdf72011-08-10 19:00:33 -06002362 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002363 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2364 sinfo->assoc_req_ies);
2365
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002366 return genlmsg_end(msg, hdr);
2367
2368 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002369 genlmsg_cancel(msg, hdr);
2370 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002371}
2372
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002373static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002374 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002375{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002376 struct station_info sinfo;
2377 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002378 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002379 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002380 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002381 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002382
Johannes Berg67748892010-10-04 21:14:06 +02002383 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2384 if (err)
2385 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002386
2387 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002388 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002389 goto out_err;
2390 }
2391
Johannes Bergbba95fe2008-07-29 13:22:51 +02002392 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002393 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002394 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2395 mac_addr, &sinfo);
2396 if (err == -ENOENT)
2397 break;
2398 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002399 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002400
2401 if (nl80211_send_station(skb,
2402 NETLINK_CB(cb->skb).pid,
2403 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2404 netdev, mac_addr,
2405 &sinfo) < 0)
2406 goto out;
2407
2408 sta_idx++;
2409 }
2410
2411
2412 out:
2413 cb->args[1] = sta_idx;
2414 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002415 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002416 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002417
2418 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002419}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002420
Johannes Berg5727ef12007-12-19 02:03:34 +01002421static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2422{
Johannes Berg4c476992010-10-04 21:36:35 +02002423 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2424 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002425 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002426 struct sk_buff *msg;
2427 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002428 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002429
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002430 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002431
2432 if (!info->attrs[NL80211_ATTR_MAC])
2433 return -EINVAL;
2434
2435 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2436
Johannes Berg4c476992010-10-04 21:36:35 +02002437 if (!rdev->ops->get_station)
2438 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002439
Johannes Berg79c97e92009-07-07 03:56:12 +02002440 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002441 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002442 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002443
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002444 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002445 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002446 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002447
2448 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002449 dev, mac_addr, &sinfo) < 0) {
2450 nlmsg_free(msg);
2451 return -ENOBUFS;
2452 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002453
Johannes Berg4c476992010-10-04 21:36:35 +02002454 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002455}
2456
2457/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002458 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002459 */
Johannes Berg463d0182009-07-14 00:33:35 +02002460static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002461 struct cfg80211_registered_device *rdev,
2462 struct net_device **vlan)
2463{
Johannes Berg463d0182009-07-14 00:33:35 +02002464 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002465 *vlan = NULL;
2466
2467 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002468 *vlan = dev_get_by_index(genl_info_net(info),
2469 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002470 if (!*vlan)
2471 return -ENODEV;
2472 if (!(*vlan)->ieee80211_ptr)
2473 return -EINVAL;
2474 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2475 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002476 if (!netif_running(*vlan))
2477 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002478 }
2479 return 0;
2480}
2481
2482static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2483{
Johannes Berg4c476992010-10-04 21:36:35 +02002484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002485 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002486 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002487 struct station_parameters params;
2488 u8 *mac_addr = NULL;
2489
2490 memset(&params, 0, sizeof(params));
2491
2492 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002493 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002494
2495 if (info->attrs[NL80211_ATTR_STA_AID])
2496 return -EINVAL;
2497
2498 if (!info->attrs[NL80211_ATTR_MAC])
2499 return -EINVAL;
2500
2501 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2502
2503 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2504 params.supported_rates =
2505 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2506 params.supported_rates_len =
2507 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2508 }
2509
2510 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2511 params.listen_interval =
2512 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2513
Jouni Malinen36aedc92008-08-25 11:58:58 +03002514 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2515 params.ht_capa =
2516 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2517
Johannes Bergeccb8e82009-05-11 21:57:56 +03002518 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002519 return -EINVAL;
2520
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002521 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2522 params.plink_action =
2523 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2524
Javier Cardona9c3990a2011-05-03 16:57:11 -07002525 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2526 params.plink_state =
2527 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2528
Johannes Berg463d0182009-07-14 00:33:35 +02002529 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002530 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002531 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002532
2533 /* validate settings */
2534 err = 0;
2535
2536 switch (dev->ieee80211_ptr->iftype) {
2537 case NL80211_IFTYPE_AP:
2538 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002539 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002540 /* disallow mesh-specific things */
2541 if (params.plink_action)
2542 err = -EINVAL;
2543 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002544 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002545 case NL80211_IFTYPE_STATION:
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002546 /* disallow things sta doesn't support */
Johannes Berga97f4422009-06-18 17:23:43 +02002547 if (params.plink_action)
2548 err = -EINVAL;
2549 if (params.vlan)
2550 err = -EINVAL;
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002551 if (params.supported_rates &&
2552 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berga97f4422009-06-18 17:23:43 +02002553 err = -EINVAL;
2554 if (params.ht_capa)
2555 err = -EINVAL;
2556 if (params.listen_interval >= 0)
2557 err = -EINVAL;
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002558 if (params.sta_flags_mask &
2559 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2560 BIT(NL80211_STA_FLAG_TDLS_PEER)))
2561 err = -EINVAL;
2562 /* can't change the TDLS bit */
2563 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2564 (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berga97f4422009-06-18 17:23:43 +02002565 err = -EINVAL;
2566 break;
2567 case NL80211_IFTYPE_MESH_POINT:
2568 /* disallow things mesh doesn't support */
2569 if (params.vlan)
2570 err = -EINVAL;
2571 if (params.ht_capa)
2572 err = -EINVAL;
2573 if (params.listen_interval >= 0)
2574 err = -EINVAL;
Javier Cardonab39c48f2011-04-07 15:08:30 -07002575 if (params.sta_flags_mask &
2576 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002577 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002578 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Berga97f4422009-06-18 17:23:43 +02002579 err = -EINVAL;
2580 break;
2581 default:
2582 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002583 }
2584
Johannes Berg5727ef12007-12-19 02:03:34 +01002585 if (err)
2586 goto out;
2587
Johannes Berg79c97e92009-07-07 03:56:12 +02002588 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002589 err = -EOPNOTSUPP;
2590 goto out;
2591 }
2592
Johannes Berg79c97e92009-07-07 03:56:12 +02002593 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002594
2595 out:
2596 if (params.vlan)
2597 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002598
Johannes Berg5727ef12007-12-19 02:03:34 +01002599 return err;
2600}
2601
Eliad Pellerc75786c2011-08-23 14:37:46 +03002602static struct nla_policy
2603nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2604 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2605 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2606};
2607
Johannes Berg5727ef12007-12-19 02:03:34 +01002608static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2609{
Johannes Berg4c476992010-10-04 21:36:35 +02002610 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002611 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002612 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002613 struct station_parameters params;
2614 u8 *mac_addr = NULL;
2615
2616 memset(&params, 0, sizeof(params));
2617
2618 if (!info->attrs[NL80211_ATTR_MAC])
2619 return -EINVAL;
2620
Johannes Berg5727ef12007-12-19 02:03:34 +01002621 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2622 return -EINVAL;
2623
2624 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2625 return -EINVAL;
2626
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002627 if (!info->attrs[NL80211_ATTR_STA_AID])
2628 return -EINVAL;
2629
Johannes Berg5727ef12007-12-19 02:03:34 +01002630 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2631 params.supported_rates =
2632 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2633 params.supported_rates_len =
2634 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2635 params.listen_interval =
2636 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002637
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002638 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2639 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2640 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002641
Jouni Malinen36aedc92008-08-25 11:58:58 +03002642 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2643 params.ht_capa =
2644 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002645
Javier Cardona96b78df2011-04-07 15:08:33 -07002646 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2647 params.plink_action =
2648 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2649
Johannes Bergeccb8e82009-05-11 21:57:56 +03002650 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002651 return -EINVAL;
2652
Eliad Pellerc75786c2011-08-23 14:37:46 +03002653 /* parse WME attributes if sta is WME capable */
Eliad Pellercedb5412011-08-31 11:29:43 +03002654 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Arik Nemtsovcd329842011-09-26 09:36:42 +03002655 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
Eliad Pellerc75786c2011-08-23 14:37:46 +03002656 info->attrs[NL80211_ATTR_STA_WME]) {
2657 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2658 struct nlattr *nla;
2659
2660 nla = info->attrs[NL80211_ATTR_STA_WME];
2661 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2662 nl80211_sta_wme_policy);
2663 if (err)
2664 return err;
2665
2666 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2667 params.uapsd_queues =
2668 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
Johannes Berg4319e192011-09-07 11:50:48 +02002669 if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2670 return -EINVAL;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002671
2672 if (tb[NL80211_STA_WME_MAX_SP])
2673 params.max_sp =
2674 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
Johannes Berg4319e192011-09-07 11:50:48 +02002675
2676 if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2677 return -EINVAL;
Johannes Berg3b9ce802011-09-27 20:56:12 +02002678
2679 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002680 }
2681
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002682 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002683 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardona96b78df2011-04-07 15:08:33 -07002684 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002685 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO &&
2686 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
2687 return -EINVAL;
2688
2689 /*
2690 * Only managed stations can add TDLS peers, and only when the
2691 * wiphy supports external TDLS setup.
2692 */
2693 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION &&
2694 !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2695 (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2696 (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
Johannes Berg4c476992010-10-04 21:36:35 +02002697 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002698
Johannes Berg463d0182009-07-14 00:33:35 +02002699 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002700 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002701 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002702
2703 /* validate settings */
2704 err = 0;
2705
Johannes Berg79c97e92009-07-07 03:56:12 +02002706 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002707 err = -EOPNOTSUPP;
2708 goto out;
2709 }
2710
Johannes Berg79c97e92009-07-07 03:56:12 +02002711 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002712
2713 out:
2714 if (params.vlan)
2715 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002716 return err;
2717}
2718
2719static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2720{
Johannes Berg4c476992010-10-04 21:36:35 +02002721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2722 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002723 u8 *mac_addr = NULL;
2724
2725 if (info->attrs[NL80211_ATTR_MAC])
2726 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2727
Johannes Berge80cf852009-05-11 14:43:13 +02002728 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002729 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002730 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002731 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2732 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002733
Johannes Berg4c476992010-10-04 21:36:35 +02002734 if (!rdev->ops->del_station)
2735 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002736
Johannes Berg4c476992010-10-04 21:36:35 +02002737 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002738}
2739
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002740static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2741 int flags, struct net_device *dev,
2742 u8 *dst, u8 *next_hop,
2743 struct mpath_info *pinfo)
2744{
2745 void *hdr;
2746 struct nlattr *pinfoattr;
2747
2748 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2749 if (!hdr)
2750 return -1;
2751
2752 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2753 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2754 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2755
Johannes Bergf5ea9122009-08-07 16:17:38 +02002756 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2757
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002758 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2759 if (!pinfoattr)
2760 goto nla_put_failure;
2761 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2762 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2763 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002764 if (pinfo->filled & MPATH_INFO_SN)
2765 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2766 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002767 if (pinfo->filled & MPATH_INFO_METRIC)
2768 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2769 pinfo->metric);
2770 if (pinfo->filled & MPATH_INFO_EXPTIME)
2771 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2772 pinfo->exptime);
2773 if (pinfo->filled & MPATH_INFO_FLAGS)
2774 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2775 pinfo->flags);
2776 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2777 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2778 pinfo->discovery_timeout);
2779 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2780 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2781 pinfo->discovery_retries);
2782
2783 nla_nest_end(msg, pinfoattr);
2784
2785 return genlmsg_end(msg, hdr);
2786
2787 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002788 genlmsg_cancel(msg, hdr);
2789 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002790}
2791
2792static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002793 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002794{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002795 struct mpath_info pinfo;
2796 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002797 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002798 u8 dst[ETH_ALEN];
2799 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002800 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002801 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002802
Johannes Berg67748892010-10-04 21:14:06 +02002803 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2804 if (err)
2805 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002806
2807 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002808 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002809 goto out_err;
2810 }
2811
Jouni Malineneec60b02009-03-20 21:21:19 +02002812 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2813 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002814 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002815 }
2816
Johannes Bergbba95fe2008-07-29 13:22:51 +02002817 while (1) {
2818 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2819 dst, next_hop, &pinfo);
2820 if (err == -ENOENT)
2821 break;
2822 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002823 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002824
2825 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2826 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2827 netdev, dst, next_hop,
2828 &pinfo) < 0)
2829 goto out;
2830
2831 path_idx++;
2832 }
2833
2834
2835 out:
2836 cb->args[1] = path_idx;
2837 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002838 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002839 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002840 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002841}
2842
2843static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2844{
Johannes Berg4c476992010-10-04 21:36:35 +02002845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002846 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002847 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002848 struct mpath_info pinfo;
2849 struct sk_buff *msg;
2850 u8 *dst = NULL;
2851 u8 next_hop[ETH_ALEN];
2852
2853 memset(&pinfo, 0, sizeof(pinfo));
2854
2855 if (!info->attrs[NL80211_ATTR_MAC])
2856 return -EINVAL;
2857
2858 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2859
Johannes Berg4c476992010-10-04 21:36:35 +02002860 if (!rdev->ops->get_mpath)
2861 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002862
Johannes Berg4c476992010-10-04 21:36:35 +02002863 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2864 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002865
Johannes Berg79c97e92009-07-07 03:56:12 +02002866 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002867 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002868 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002869
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002870 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002871 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002872 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002873
2874 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002875 dev, dst, next_hop, &pinfo) < 0) {
2876 nlmsg_free(msg);
2877 return -ENOBUFS;
2878 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002879
Johannes Berg4c476992010-10-04 21:36:35 +02002880 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002881}
2882
2883static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2884{
Johannes Berg4c476992010-10-04 21:36:35 +02002885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2886 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002887 u8 *dst = NULL;
2888 u8 *next_hop = NULL;
2889
2890 if (!info->attrs[NL80211_ATTR_MAC])
2891 return -EINVAL;
2892
2893 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2894 return -EINVAL;
2895
2896 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2897 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2898
Johannes Berg4c476992010-10-04 21:36:35 +02002899 if (!rdev->ops->change_mpath)
2900 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002901
Johannes Berg4c476992010-10-04 21:36:35 +02002902 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2903 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002904
Johannes Berg4c476992010-10-04 21:36:35 +02002905 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002906}
Johannes Berg4c476992010-10-04 21:36:35 +02002907
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002908static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2909{
Johannes Berg4c476992010-10-04 21:36:35 +02002910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2911 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002912 u8 *dst = NULL;
2913 u8 *next_hop = NULL;
2914
2915 if (!info->attrs[NL80211_ATTR_MAC])
2916 return -EINVAL;
2917
2918 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2919 return -EINVAL;
2920
2921 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2922 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2923
Johannes Berg4c476992010-10-04 21:36:35 +02002924 if (!rdev->ops->add_mpath)
2925 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002926
Johannes Berg4c476992010-10-04 21:36:35 +02002927 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2928 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002929
Johannes Berg4c476992010-10-04 21:36:35 +02002930 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002931}
2932
2933static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2934{
Johannes Berg4c476992010-10-04 21:36:35 +02002935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2936 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002937 u8 *dst = NULL;
2938
2939 if (info->attrs[NL80211_ATTR_MAC])
2940 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2941
Johannes Berg4c476992010-10-04 21:36:35 +02002942 if (!rdev->ops->del_mpath)
2943 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002944
Johannes Berg4c476992010-10-04 21:36:35 +02002945 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002946}
2947
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002948static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2949{
Johannes Berg4c476992010-10-04 21:36:35 +02002950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2951 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002952 struct bss_parameters params;
2953
2954 memset(&params, 0, sizeof(params));
2955 /* default to not changing parameters */
2956 params.use_cts_prot = -1;
2957 params.use_short_preamble = -1;
2958 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002959 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002960 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002961
2962 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2963 params.use_cts_prot =
2964 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2965 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2966 params.use_short_preamble =
2967 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2968 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2969 params.use_short_slot_time =
2970 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002971 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2972 params.basic_rates =
2973 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2974 params.basic_rates_len =
2975 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2976 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002977 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2978 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01002979 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2980 params.ht_opmode =
2981 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002982
Johannes Berg4c476992010-10-04 21:36:35 +02002983 if (!rdev->ops->change_bss)
2984 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002985
Johannes Berg074ac8d2010-09-16 14:58:22 +02002986 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002987 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2988 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002989
Johannes Berg4c476992010-10-04 21:36:35 +02002990 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002991}
2992
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002993static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002994 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2995 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2996 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2997 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2998 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2999 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3000};
3001
3002static int parse_reg_rule(struct nlattr *tb[],
3003 struct ieee80211_reg_rule *reg_rule)
3004{
3005 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3006 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3007
3008 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3009 return -EINVAL;
3010 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3011 return -EINVAL;
3012 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3013 return -EINVAL;
3014 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3015 return -EINVAL;
3016 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3017 return -EINVAL;
3018
3019 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3020
3021 freq_range->start_freq_khz =
3022 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3023 freq_range->end_freq_khz =
3024 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3025 freq_range->max_bandwidth_khz =
3026 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3027
3028 power_rule->max_eirp =
3029 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3030
3031 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3032 power_rule->max_antenna_gain =
3033 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3034
3035 return 0;
3036}
3037
3038static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3039{
3040 int r;
3041 char *data = NULL;
3042
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003043 /*
3044 * You should only get this when cfg80211 hasn't yet initialized
3045 * completely when built-in to the kernel right between the time
3046 * window between nl80211_init() and regulatory_init(), if that is
3047 * even possible.
3048 */
3049 mutex_lock(&cfg80211_mutex);
3050 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003051 mutex_unlock(&cfg80211_mutex);
3052 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003053 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003054 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003055
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003056 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3057 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003058
3059 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3060
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003061 r = regulatory_hint_user(data);
3062
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003063 return r;
3064}
3065
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003066static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003067 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003068{
Johannes Berg4c476992010-10-04 21:36:35 +02003069 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003070 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003071 struct wireless_dev *wdev = dev->ieee80211_ptr;
3072 struct mesh_config cur_params;
3073 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003074 void *hdr;
3075 struct nlattr *pinfoattr;
3076 struct sk_buff *msg;
3077
Johannes Berg29cbe682010-12-03 09:20:44 +01003078 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3079 return -EOPNOTSUPP;
3080
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003081 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003082 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003083
Johannes Berg29cbe682010-12-03 09:20:44 +01003084 wdev_lock(wdev);
3085 /* If not connected, get default parameters */
3086 if (!wdev->mesh_id_len)
3087 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3088 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003089 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003090 &cur_params);
3091 wdev_unlock(wdev);
3092
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003093 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003094 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003095
3096 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003097 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003098 if (!msg)
3099 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003100 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003101 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003102 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003103 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003104 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003105 if (!pinfoattr)
3106 goto nla_put_failure;
3107 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3108 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3109 cur_params.dot11MeshRetryTimeout);
3110 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3111 cur_params.dot11MeshConfirmTimeout);
3112 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3113 cur_params.dot11MeshHoldingTimeout);
3114 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3115 cur_params.dot11MeshMaxPeerLinks);
3116 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3117 cur_params.dot11MeshMaxRetries);
3118 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3119 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01003120 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3121 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003122 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3123 cur_params.auto_open_plinks);
3124 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3125 cur_params.dot11MeshHWMPmaxPREQretries);
3126 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3127 cur_params.path_refresh_time);
3128 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3129 cur_params.min_discovery_timeout);
3130 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3131 cur_params.dot11MeshHWMPactivePathTimeout);
3132 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3133 cur_params.dot11MeshHWMPpreqMinInterval);
3134 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3135 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00003136 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3137 cur_params.dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -07003138 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3139 cur_params.dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -07003140 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3141 cur_params.dot11MeshGateAnnouncementProtocol);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003142 nla_nest_end(msg, pinfoattr);
3143 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003144 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003145
Johannes Berg3b858752009-03-12 09:55:09 +01003146 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003147 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003148 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003149 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003150 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003151}
3152
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003153static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003154 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3155 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3156 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3157 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3158 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3159 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003160 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003161 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
3162
3163 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3164 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3165 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3166 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3167 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
3168 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003169 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003170 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003171 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003172};
3173
Javier Cardonac80d5452010-12-16 17:37:49 -08003174static const struct nla_policy
3175 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
3176 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3177 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003178 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003179 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08003180 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003181 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003182};
3183
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003184static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003185 struct mesh_config *cfg,
3186 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003187{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003188 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003189 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003190
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003191#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3192do {\
3193 if (table[attr_num]) {\
3194 cfg->param = nla_fn(table[attr_num]); \
3195 mask |= (1 << (attr_num - 1)); \
3196 } \
3197} while (0);\
3198
3199
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003200 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003201 return -EINVAL;
3202 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003203 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003204 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003205 return -EINVAL;
3206
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003207 /* This makes sure that there aren't more than 32 mesh config
3208 * parameters (otherwise our bitfield scheme would not work.) */
3209 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3210
3211 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003212 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3213 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3215 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3216 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3217 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3219 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3221 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3223 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003224 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3225 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3227 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3228 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3229 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3230 nla_get_u8);
3231 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3232 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3233 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3234 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3235 nla_get_u16);
3236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3237 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3238 nla_get_u32);
3239 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3240 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3241 nla_get_u16);
3242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3243 dot11MeshHWMPnetDiameterTraversalTime,
3244 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3245 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3247 dot11MeshHWMPRootMode, mask,
3248 NL80211_MESHCONF_HWMP_ROOTMODE,
3249 nla_get_u8);
Javier Cardona0507e152011-08-09 16:45:10 -07003250 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3251 dot11MeshHWMPRannInterval, mask,
3252 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3253 nla_get_u16);
Javier Cardona16dd7262011-08-09 16:45:11 -07003254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3255 dot11MeshGateAnnouncementProtocol, mask,
3256 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3257 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003258 if (mask_out)
3259 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003260
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003261 return 0;
3262
3263#undef FILL_IN_MESH_PARAM_IF_SET
3264}
3265
Javier Cardonac80d5452010-12-16 17:37:49 -08003266static int nl80211_parse_mesh_setup(struct genl_info *info,
3267 struct mesh_setup *setup)
3268{
3269 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3270
3271 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3272 return -EINVAL;
3273 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3274 info->attrs[NL80211_ATTR_MESH_SETUP],
3275 nl80211_mesh_setup_params_policy))
3276 return -EINVAL;
3277
3278 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3279 setup->path_sel_proto =
3280 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3281 IEEE80211_PATH_PROTOCOL_VENDOR :
3282 IEEE80211_PATH_PROTOCOL_HWMP;
3283
3284 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3285 setup->path_metric =
3286 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3287 IEEE80211_PATH_METRIC_VENDOR :
3288 IEEE80211_PATH_METRIC_AIRTIME;
3289
Javier Cardona581a8b02011-04-07 15:08:27 -07003290
3291 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003292 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003293 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003294 if (!is_valid_ie_attr(ieattr))
3295 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003296 setup->ie = nla_data(ieattr);
3297 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003298 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003299 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3300 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003301
3302 return 0;
3303}
3304
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003305static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003306 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003307{
3308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3309 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003310 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003311 struct mesh_config cfg;
3312 u32 mask;
3313 int err;
3314
Johannes Berg29cbe682010-12-03 09:20:44 +01003315 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3316 return -EOPNOTSUPP;
3317
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003318 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003319 return -EOPNOTSUPP;
3320
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003321 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003322 if (err)
3323 return err;
3324
Johannes Berg29cbe682010-12-03 09:20:44 +01003325 wdev_lock(wdev);
3326 if (!wdev->mesh_id_len)
3327 err = -ENOLINK;
3328
3329 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003330 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003331 mask, &cfg);
3332
3333 wdev_unlock(wdev);
3334
3335 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003336}
3337
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003338static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3339{
3340 struct sk_buff *msg;
3341 void *hdr = NULL;
3342 struct nlattr *nl_reg_rules;
3343 unsigned int i;
3344 int err = -EINVAL;
3345
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003346 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003347
3348 if (!cfg80211_regdomain)
3349 goto out;
3350
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003351 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003352 if (!msg) {
3353 err = -ENOBUFS;
3354 goto out;
3355 }
3356
3357 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3358 NL80211_CMD_GET_REG);
3359 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003360 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003361
3362 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3363 cfg80211_regdomain->alpha2);
3364
3365 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3366 if (!nl_reg_rules)
3367 goto nla_put_failure;
3368
3369 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3370 struct nlattr *nl_reg_rule;
3371 const struct ieee80211_reg_rule *reg_rule;
3372 const struct ieee80211_freq_range *freq_range;
3373 const struct ieee80211_power_rule *power_rule;
3374
3375 reg_rule = &cfg80211_regdomain->reg_rules[i];
3376 freq_range = &reg_rule->freq_range;
3377 power_rule = &reg_rule->power_rule;
3378
3379 nl_reg_rule = nla_nest_start(msg, i);
3380 if (!nl_reg_rule)
3381 goto nla_put_failure;
3382
3383 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3384 reg_rule->flags);
3385 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3386 freq_range->start_freq_khz);
3387 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3388 freq_range->end_freq_khz);
3389 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3390 freq_range->max_bandwidth_khz);
3391 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3392 power_rule->max_antenna_gain);
3393 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3394 power_rule->max_eirp);
3395
3396 nla_nest_end(msg, nl_reg_rule);
3397 }
3398
3399 nla_nest_end(msg, nl_reg_rules);
3400
3401 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003402 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003403 goto out;
3404
3405nla_put_failure:
3406 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003407put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003408 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003409 err = -EMSGSIZE;
3410out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003411 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003412 return err;
3413}
3414
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003415static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3416{
3417 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3418 struct nlattr *nl_reg_rule;
3419 char *alpha2 = NULL;
3420 int rem_reg_rules = 0, r = 0;
3421 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3422 struct ieee80211_regdomain *rd = NULL;
3423
3424 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3425 return -EINVAL;
3426
3427 if (!info->attrs[NL80211_ATTR_REG_RULES])
3428 return -EINVAL;
3429
3430 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3431
3432 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3433 rem_reg_rules) {
3434 num_rules++;
3435 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003436 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003437 }
3438
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003439 mutex_lock(&cfg80211_mutex);
3440
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003441 if (!reg_is_valid_request(alpha2)) {
3442 r = -EINVAL;
3443 goto bad_reg;
3444 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003445
3446 size_of_regd = sizeof(struct ieee80211_regdomain) +
3447 (num_rules * sizeof(struct ieee80211_reg_rule));
3448
3449 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003450 if (!rd) {
3451 r = -ENOMEM;
3452 goto bad_reg;
3453 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003454
3455 rd->n_reg_rules = num_rules;
3456 rd->alpha2[0] = alpha2[0];
3457 rd->alpha2[1] = alpha2[1];
3458
3459 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3460 rem_reg_rules) {
3461 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3462 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3463 reg_rule_policy);
3464 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3465 if (r)
3466 goto bad_reg;
3467
3468 rule_idx++;
3469
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003470 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3471 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003472 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003473 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003474 }
3475
3476 BUG_ON(rule_idx != num_rules);
3477
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003478 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003479
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003480 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003481
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003482 return r;
3483
Johannes Bergd2372b32008-10-24 20:32:20 +02003484 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003485 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003486 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003487 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003488}
3489
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003490static int validate_scan_freqs(struct nlattr *freqs)
3491{
3492 struct nlattr *attr1, *attr2;
3493 int n_channels = 0, tmp1, tmp2;
3494
3495 nla_for_each_nested(attr1, freqs, tmp1) {
3496 n_channels++;
3497 /*
3498 * Some hardware has a limited channel list for
3499 * scanning, and it is pretty much nonsensical
3500 * to scan for a channel twice, so disallow that
3501 * and don't require drivers to check that the
3502 * channel list they get isn't longer than what
3503 * they can scan, as long as they can scan all
3504 * the channels they registered at once.
3505 */
3506 nla_for_each_nested(attr2, freqs, tmp2)
3507 if (attr1 != attr2 &&
3508 nla_get_u32(attr1) == nla_get_u32(attr2))
3509 return 0;
3510 }
3511
3512 return n_channels;
3513}
3514
Johannes Berg2a519312009-02-10 21:25:55 +01003515static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3516{
Johannes Berg4c476992010-10-04 21:36:35 +02003517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3518 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003519 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003520 struct nlattr *attr;
3521 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003522 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003523 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003524
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003525 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3526 return -EINVAL;
3527
Johannes Berg79c97e92009-07-07 03:56:12 +02003528 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003529
Johannes Berg4c476992010-10-04 21:36:35 +02003530 if (!rdev->ops->scan)
3531 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003532
Johannes Berg4c476992010-10-04 21:36:35 +02003533 if (rdev->scan_req)
3534 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003535
3536 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003537 n_channels = validate_scan_freqs(
3538 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003539 if (!n_channels)
3540 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003541 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003542 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003543 n_channels = 0;
3544
Johannes Berg2a519312009-02-10 21:25:55 +01003545 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3546 if (wiphy->bands[band])
3547 n_channels += wiphy->bands[band]->n_channels;
3548 }
3549
3550 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3551 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3552 n_ssids++;
3553
Johannes Berg4c476992010-10-04 21:36:35 +02003554 if (n_ssids > wiphy->max_scan_ssids)
3555 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003556
Jouni Malinen70692ad2009-02-16 19:39:13 +02003557 if (info->attrs[NL80211_ATTR_IE])
3558 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3559 else
3560 ie_len = 0;
3561
Johannes Berg4c476992010-10-04 21:36:35 +02003562 if (ie_len > wiphy->max_scan_ie_len)
3563 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003564
Johannes Berg2a519312009-02-10 21:25:55 +01003565 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003566 + sizeof(*request->ssids) * n_ssids
3567 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003568 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003569 if (!request)
3570 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003571
Johannes Berg2a519312009-02-10 21:25:55 +01003572 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003573 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003574 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003575 if (ie_len) {
3576 if (request->ssids)
3577 request->ie = (void *)(request->ssids + n_ssids);
3578 else
3579 request->ie = (void *)(request->channels + n_channels);
3580 }
Johannes Berg2a519312009-02-10 21:25:55 +01003581
Johannes Berg584991d2009-11-02 13:32:03 +01003582 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003583 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3584 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003585 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003586 struct ieee80211_channel *chan;
3587
3588 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3589
3590 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003591 err = -EINVAL;
3592 goto out_free;
3593 }
Johannes Berg584991d2009-11-02 13:32:03 +01003594
3595 /* ignore disabled channels */
3596 if (chan->flags & IEEE80211_CHAN_DISABLED)
3597 continue;
3598
3599 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003600 i++;
3601 }
3602 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003603 enum ieee80211_band band;
3604
Johannes Berg2a519312009-02-10 21:25:55 +01003605 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003606 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3607 int j;
3608 if (!wiphy->bands[band])
3609 continue;
3610 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003611 struct ieee80211_channel *chan;
3612
3613 chan = &wiphy->bands[band]->channels[j];
3614
3615 if (chan->flags & IEEE80211_CHAN_DISABLED)
3616 continue;
3617
3618 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003619 i++;
3620 }
3621 }
3622 }
3623
Johannes Berg584991d2009-11-02 13:32:03 +01003624 if (!i) {
3625 err = -EINVAL;
3626 goto out_free;
3627 }
3628
3629 request->n_channels = i;
3630
Johannes Berg2a519312009-02-10 21:25:55 +01003631 i = 0;
3632 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3633 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003634 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003635 err = -EINVAL;
3636 goto out_free;
3637 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003638 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003639 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003640 i++;
3641 }
3642 }
3643
Jouni Malinen70692ad2009-02-16 19:39:13 +02003644 if (info->attrs[NL80211_ATTR_IE]) {
3645 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003646 memcpy((void *)request->ie,
3647 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003648 request->ie_len);
3649 }
3650
Johannes Berg34850ab2011-07-18 18:08:35 +02003651 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003652 if (wiphy->bands[i])
3653 request->rates[i] =
3654 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003655
3656 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3657 nla_for_each_nested(attr,
3658 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3659 tmp) {
3660 enum ieee80211_band band = nla_type(attr);
3661
Dan Carpenter84404622011-07-29 11:52:18 +03003662 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003663 err = -EINVAL;
3664 goto out_free;
3665 }
3666 err = ieee80211_get_ratemask(wiphy->bands[band],
3667 nla_data(attr),
3668 nla_len(attr),
3669 &request->rates[band]);
3670 if (err)
3671 goto out_free;
3672 }
3673 }
3674
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05303675 request->no_cck =
3676 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3677
Johannes Berg463d0182009-07-14 00:33:35 +02003678 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003679 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003680
Johannes Berg79c97e92009-07-07 03:56:12 +02003681 rdev->scan_req = request;
3682 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003683
Johannes Berg463d0182009-07-14 00:33:35 +02003684 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003685 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003686 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003687 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003688 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003689 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003690 kfree(request);
3691 }
Johannes Berg3b858752009-03-12 09:55:09 +01003692
Johannes Berg2a519312009-02-10 21:25:55 +01003693 return err;
3694}
3695
Luciano Coelho807f8a82011-05-11 17:09:35 +03003696static int nl80211_start_sched_scan(struct sk_buff *skb,
3697 struct genl_info *info)
3698{
3699 struct cfg80211_sched_scan_request *request;
3700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3701 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003702 struct nlattr *attr;
3703 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003704 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003705 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003706 enum ieee80211_band band;
3707 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003708 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003709
3710 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3711 !rdev->ops->sched_scan_start)
3712 return -EOPNOTSUPP;
3713
3714 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3715 return -EINVAL;
3716
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003717 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3718 return -EINVAL;
3719
3720 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3721 if (interval == 0)
3722 return -EINVAL;
3723
Luciano Coelho807f8a82011-05-11 17:09:35 +03003724 wiphy = &rdev->wiphy;
3725
3726 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3727 n_channels = validate_scan_freqs(
3728 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3729 if (!n_channels)
3730 return -EINVAL;
3731 } else {
3732 n_channels = 0;
3733
3734 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3735 if (wiphy->bands[band])
3736 n_channels += wiphy->bands[band]->n_channels;
3737 }
3738
3739 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3740 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3741 tmp)
3742 n_ssids++;
3743
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003744 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003745 return -EINVAL;
3746
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003747 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3748 nla_for_each_nested(attr,
3749 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3750 tmp)
3751 n_match_sets++;
3752
3753 if (n_match_sets > wiphy->max_match_sets)
3754 return -EINVAL;
3755
Luciano Coelho807f8a82011-05-11 17:09:35 +03003756 if (info->attrs[NL80211_ATTR_IE])
3757 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3758 else
3759 ie_len = 0;
3760
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003761 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003762 return -EINVAL;
3763
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003764 mutex_lock(&rdev->sched_scan_mtx);
3765
3766 if (rdev->sched_scan_req) {
3767 err = -EINPROGRESS;
3768 goto out;
3769 }
3770
Luciano Coelho807f8a82011-05-11 17:09:35 +03003771 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003772 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003773 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003774 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003775 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003776 if (!request) {
3777 err = -ENOMEM;
3778 goto out;
3779 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003780
3781 if (n_ssids)
3782 request->ssids = (void *)&request->channels[n_channels];
3783 request->n_ssids = n_ssids;
3784 if (ie_len) {
3785 if (request->ssids)
3786 request->ie = (void *)(request->ssids + n_ssids);
3787 else
3788 request->ie = (void *)(request->channels + n_channels);
3789 }
3790
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003791 if (n_match_sets) {
3792 if (request->ie)
3793 request->match_sets = (void *)(request->ie + ie_len);
3794 else if (request->ssids)
3795 request->match_sets =
3796 (void *)(request->ssids + n_ssids);
3797 else
3798 request->match_sets =
3799 (void *)(request->channels + n_channels);
3800 }
3801 request->n_match_sets = n_match_sets;
3802
Luciano Coelho807f8a82011-05-11 17:09:35 +03003803 i = 0;
3804 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3805 /* user specified, bail out if channel not found */
3806 nla_for_each_nested(attr,
3807 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3808 tmp) {
3809 struct ieee80211_channel *chan;
3810
3811 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3812
3813 if (!chan) {
3814 err = -EINVAL;
3815 goto out_free;
3816 }
3817
3818 /* ignore disabled channels */
3819 if (chan->flags & IEEE80211_CHAN_DISABLED)
3820 continue;
3821
3822 request->channels[i] = chan;
3823 i++;
3824 }
3825 } else {
3826 /* all channels */
3827 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3828 int j;
3829 if (!wiphy->bands[band])
3830 continue;
3831 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3832 struct ieee80211_channel *chan;
3833
3834 chan = &wiphy->bands[band]->channels[j];
3835
3836 if (chan->flags & IEEE80211_CHAN_DISABLED)
3837 continue;
3838
3839 request->channels[i] = chan;
3840 i++;
3841 }
3842 }
3843 }
3844
3845 if (!i) {
3846 err = -EINVAL;
3847 goto out_free;
3848 }
3849
3850 request->n_channels = i;
3851
3852 i = 0;
3853 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3854 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3855 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003856 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03003857 err = -EINVAL;
3858 goto out_free;
3859 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003860 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003861 memcpy(request->ssids[i].ssid, nla_data(attr),
3862 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03003863 i++;
3864 }
3865 }
3866
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003867 i = 0;
3868 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
3869 nla_for_each_nested(attr,
3870 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3871 tmp) {
3872 struct nlattr *ssid;
3873
3874 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
3875 nla_data(attr), nla_len(attr),
3876 nl80211_match_policy);
3877 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
3878 if (ssid) {
3879 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
3880 err = -EINVAL;
3881 goto out_free;
3882 }
3883 memcpy(request->match_sets[i].ssid.ssid,
3884 nla_data(ssid), nla_len(ssid));
3885 request->match_sets[i].ssid.ssid_len =
3886 nla_len(ssid);
3887 }
3888 i++;
3889 }
3890 }
3891
Luciano Coelho807f8a82011-05-11 17:09:35 +03003892 if (info->attrs[NL80211_ATTR_IE]) {
3893 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3894 memcpy((void *)request->ie,
3895 nla_data(info->attrs[NL80211_ATTR_IE]),
3896 request->ie_len);
3897 }
3898
3899 request->dev = dev;
3900 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003901 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003902
3903 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3904 if (!err) {
3905 rdev->sched_scan_req = request;
3906 nl80211_send_sched_scan(rdev, dev,
3907 NL80211_CMD_START_SCHED_SCAN);
3908 goto out;
3909 }
3910
3911out_free:
3912 kfree(request);
3913out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003914 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003915 return err;
3916}
3917
3918static int nl80211_stop_sched_scan(struct sk_buff *skb,
3919 struct genl_info *info)
3920{
3921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003922 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003923
3924 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3925 !rdev->ops->sched_scan_stop)
3926 return -EOPNOTSUPP;
3927
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003928 mutex_lock(&rdev->sched_scan_mtx);
3929 err = __cfg80211_stop_sched_scan(rdev, false);
3930 mutex_unlock(&rdev->sched_scan_mtx);
3931
3932 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003933}
3934
Johannes Berg9720bb32011-06-21 09:45:33 +02003935static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3936 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003937 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003938 struct wireless_dev *wdev,
3939 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003940{
Johannes Berg48ab9052009-07-10 18:42:31 +02003941 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003942 void *hdr;
3943 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003944 int i;
3945
3946 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003947
Johannes Berg9720bb32011-06-21 09:45:33 +02003948 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003949 NL80211_CMD_NEW_SCAN_RESULTS);
3950 if (!hdr)
3951 return -1;
3952
Johannes Berg9720bb32011-06-21 09:45:33 +02003953 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
3954
Johannes Bergf5ea9122009-08-07 16:17:38 +02003955 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003956 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003957
3958 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3959 if (!bss)
3960 goto nla_put_failure;
3961 if (!is_zero_ether_addr(res->bssid))
3962 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3963 if (res->information_elements && res->len_information_elements)
3964 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3965 res->len_information_elements,
3966 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003967 if (res->beacon_ies && res->len_beacon_ies &&
3968 res->beacon_ies != res->information_elements)
3969 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3970 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003971 if (res->tsf)
3972 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3973 if (res->beacon_interval)
3974 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3975 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3976 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003977 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3978 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003979
Johannes Berg77965c92009-02-18 18:45:06 +01003980 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003981 case CFG80211_SIGNAL_TYPE_MBM:
3982 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3983 break;
3984 case CFG80211_SIGNAL_TYPE_UNSPEC:
3985 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3986 break;
3987 default:
3988 break;
3989 }
3990
Johannes Berg48ab9052009-07-10 18:42:31 +02003991 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003992 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003993 case NL80211_IFTYPE_STATION:
3994 if (intbss == wdev->current_bss)
3995 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3996 NL80211_BSS_STATUS_ASSOCIATED);
3997 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3998 if (intbss != wdev->auth_bsses[i])
3999 continue;
4000 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4001 NL80211_BSS_STATUS_AUTHENTICATED);
4002 break;
4003 }
4004 break;
4005 case NL80211_IFTYPE_ADHOC:
4006 if (intbss == wdev->current_bss)
4007 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4008 NL80211_BSS_STATUS_IBSS_JOINED);
4009 break;
4010 default:
4011 break;
4012 }
4013
Johannes Berg2a519312009-02-10 21:25:55 +01004014 nla_nest_end(msg, bss);
4015
4016 return genlmsg_end(msg, hdr);
4017
4018 nla_put_failure:
4019 genlmsg_cancel(msg, hdr);
4020 return -EMSGSIZE;
4021}
4022
4023static int nl80211_dump_scan(struct sk_buff *skb,
4024 struct netlink_callback *cb)
4025{
Johannes Berg48ab9052009-07-10 18:42:31 +02004026 struct cfg80211_registered_device *rdev;
4027 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004028 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004029 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004030 int start = cb->args[1], idx = 0;
4031 int err;
4032
Johannes Berg67748892010-10-04 21:14:06 +02004033 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4034 if (err)
4035 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004036
Johannes Berg48ab9052009-07-10 18:42:31 +02004037 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004038
Johannes Berg48ab9052009-07-10 18:42:31 +02004039 wdev_lock(wdev);
4040 spin_lock_bh(&rdev->bss_lock);
4041 cfg80211_bss_expire(rdev);
4042
Johannes Berg9720bb32011-06-21 09:45:33 +02004043 cb->seq = rdev->bss_generation;
4044
Johannes Berg48ab9052009-07-10 18:42:31 +02004045 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004046 if (++idx <= start)
4047 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004048 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004049 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004050 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004051 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004052 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004053 }
4054 }
4055
Johannes Berg48ab9052009-07-10 18:42:31 +02004056 spin_unlock_bh(&rdev->bss_lock);
4057 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004058
4059 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004060 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004061
Johannes Berg67748892010-10-04 21:14:06 +02004062 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004063}
4064
Holger Schurig61fa7132009-11-11 12:25:40 +01004065static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4066 int flags, struct net_device *dev,
4067 struct survey_info *survey)
4068{
4069 void *hdr;
4070 struct nlattr *infoattr;
4071
Holger Schurig61fa7132009-11-11 12:25:40 +01004072 hdr = nl80211hdr_put(msg, pid, seq, flags,
4073 NL80211_CMD_NEW_SURVEY_RESULTS);
4074 if (!hdr)
4075 return -ENOMEM;
4076
4077 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4078
4079 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4080 if (!infoattr)
4081 goto nla_put_failure;
4082
4083 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4084 survey->channel->center_freq);
4085 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4086 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4087 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02004088 if (survey->filled & SURVEY_INFO_IN_USE)
4089 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02004090 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4091 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4092 survey->channel_time);
4093 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4094 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4095 survey->channel_time_busy);
4096 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4097 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4098 survey->channel_time_ext_busy);
4099 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4100 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4101 survey->channel_time_rx);
4102 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4103 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4104 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01004105
4106 nla_nest_end(msg, infoattr);
4107
4108 return genlmsg_end(msg, hdr);
4109
4110 nla_put_failure:
4111 genlmsg_cancel(msg, hdr);
4112 return -EMSGSIZE;
4113}
4114
4115static int nl80211_dump_survey(struct sk_buff *skb,
4116 struct netlink_callback *cb)
4117{
4118 struct survey_info survey;
4119 struct cfg80211_registered_device *dev;
4120 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004121 int survey_idx = cb->args[1];
4122 int res;
4123
Johannes Berg67748892010-10-04 21:14:06 +02004124 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4125 if (res)
4126 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004127
4128 if (!dev->ops->dump_survey) {
4129 res = -EOPNOTSUPP;
4130 goto out_err;
4131 }
4132
4133 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004134 struct ieee80211_channel *chan;
4135
Holger Schurig61fa7132009-11-11 12:25:40 +01004136 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4137 &survey);
4138 if (res == -ENOENT)
4139 break;
4140 if (res)
4141 goto out_err;
4142
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004143 /* Survey without a channel doesn't make sense */
4144 if (!survey.channel) {
4145 res = -EINVAL;
4146 goto out;
4147 }
4148
4149 chan = ieee80211_get_channel(&dev->wiphy,
4150 survey.channel->center_freq);
4151 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4152 survey_idx++;
4153 continue;
4154 }
4155
Holger Schurig61fa7132009-11-11 12:25:40 +01004156 if (nl80211_send_survey(skb,
4157 NETLINK_CB(cb->skb).pid,
4158 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4159 netdev,
4160 &survey) < 0)
4161 goto out;
4162 survey_idx++;
4163 }
4164
4165 out:
4166 cb->args[1] = survey_idx;
4167 res = skb->len;
4168 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004169 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004170 return res;
4171}
4172
Jouni Malinen255e7372009-03-20 21:21:17 +02004173static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4174{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004175 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004176}
4177
Samuel Ortizb23aa672009-07-01 21:26:54 +02004178static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4179{
4180 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4181 NL80211_WPA_VERSION_2));
4182}
4183
Jouni Malinen636a5d32009-03-19 13:39:22 +02004184static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4185{
Johannes Berg4c476992010-10-04 21:36:35 +02004186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4187 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004188 struct ieee80211_channel *chan;
4189 const u8 *bssid, *ssid, *ie = NULL;
4190 int err, ssid_len, ie_len = 0;
4191 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004192 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004193 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004194
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004195 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4196 return -EINVAL;
4197
4198 if (!info->attrs[NL80211_ATTR_MAC])
4199 return -EINVAL;
4200
Jouni Malinen17780922009-03-27 20:52:47 +02004201 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4202 return -EINVAL;
4203
Johannes Berg19957bb2009-07-02 17:20:43 +02004204 if (!info->attrs[NL80211_ATTR_SSID])
4205 return -EINVAL;
4206
4207 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4208 return -EINVAL;
4209
Johannes Bergfffd0932009-07-08 14:22:54 +02004210 err = nl80211_parse_key(info, &key);
4211 if (err)
4212 return err;
4213
4214 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004215 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4216 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004217 if (!key.p.key || !key.p.key_len)
4218 return -EINVAL;
4219 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4220 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4221 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4222 key.p.key_len != WLAN_KEY_LEN_WEP104))
4223 return -EINVAL;
4224 if (key.idx > 4)
4225 return -EINVAL;
4226 } else {
4227 key.p.key_len = 0;
4228 key.p.key = NULL;
4229 }
4230
Johannes Bergafea0b72010-08-10 09:46:42 +02004231 if (key.idx >= 0) {
4232 int i;
4233 bool ok = false;
4234 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4235 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4236 ok = true;
4237 break;
4238 }
4239 }
Johannes Berg4c476992010-10-04 21:36:35 +02004240 if (!ok)
4241 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004242 }
4243
Johannes Berg4c476992010-10-04 21:36:35 +02004244 if (!rdev->ops->auth)
4245 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004246
Johannes Berg074ac8d2010-09-16 14:58:22 +02004247 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004248 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4249 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004250
Johannes Berg19957bb2009-07-02 17:20:43 +02004251 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004252 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004253 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004254 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4255 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004256
Johannes Berg19957bb2009-07-02 17:20:43 +02004257 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4258 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4259
4260 if (info->attrs[NL80211_ATTR_IE]) {
4261 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4262 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4263 }
4264
4265 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004266 if (!nl80211_valid_auth_type(auth_type))
4267 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004268
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004269 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4270
Johannes Berg4c476992010-10-04 21:36:35 +02004271 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4272 ssid, ssid_len, ie, ie_len,
4273 key.p.key, key.p.key_len, key.idx,
4274 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004275}
4276
Johannes Bergc0692b82010-08-27 14:26:53 +03004277static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4278 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004279 struct cfg80211_crypto_settings *settings,
4280 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004281{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004282 memset(settings, 0, sizeof(*settings));
4283
Samuel Ortizb23aa672009-07-01 21:26:54 +02004284 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4285
Johannes Bergc0692b82010-08-27 14:26:53 +03004286 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4287 u16 proto;
4288 proto = nla_get_u16(
4289 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4290 settings->control_port_ethertype = cpu_to_be16(proto);
4291 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4292 proto != ETH_P_PAE)
4293 return -EINVAL;
4294 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4295 settings->control_port_no_encrypt = true;
4296 } else
4297 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4298
Samuel Ortizb23aa672009-07-01 21:26:54 +02004299 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4300 void *data;
4301 int len, i;
4302
4303 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4304 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4305 settings->n_ciphers_pairwise = len / sizeof(u32);
4306
4307 if (len % sizeof(u32))
4308 return -EINVAL;
4309
Johannes Berg3dc27d22009-07-02 21:36:37 +02004310 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004311 return -EINVAL;
4312
4313 memcpy(settings->ciphers_pairwise, data, len);
4314
4315 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004316 if (!cfg80211_supported_cipher_suite(
4317 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004318 settings->ciphers_pairwise[i]))
4319 return -EINVAL;
4320 }
4321
4322 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4323 settings->cipher_group =
4324 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004325 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4326 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004327 return -EINVAL;
4328 }
4329
4330 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4331 settings->wpa_versions =
4332 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4333 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4334 return -EINVAL;
4335 }
4336
4337 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4338 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004339 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004340
4341 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4342 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4343 settings->n_akm_suites = len / sizeof(u32);
4344
4345 if (len % sizeof(u32))
4346 return -EINVAL;
4347
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004348 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4349 return -EINVAL;
4350
Samuel Ortizb23aa672009-07-01 21:26:54 +02004351 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004352 }
4353
4354 return 0;
4355}
4356
Jouni Malinen636a5d32009-03-19 13:39:22 +02004357static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4358{
Johannes Berg4c476992010-10-04 21:36:35 +02004359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4360 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004361 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004362 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004363 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004364 int err, ssid_len, ie_len = 0;
4365 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004366
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004367 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4368 return -EINVAL;
4369
4370 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004371 !info->attrs[NL80211_ATTR_SSID] ||
4372 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004373 return -EINVAL;
4374
Johannes Berg4c476992010-10-04 21:36:35 +02004375 if (!rdev->ops->assoc)
4376 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004377
Johannes Berg074ac8d2010-09-16 14:58:22 +02004378 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004379 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4380 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004381
Johannes Berg19957bb2009-07-02 17:20:43 +02004382 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004383
Johannes Berg19957bb2009-07-02 17:20:43 +02004384 chan = ieee80211_get_channel(&rdev->wiphy,
4385 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004386 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4387 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004388
Johannes Berg19957bb2009-07-02 17:20:43 +02004389 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4390 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004391
4392 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004393 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4394 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004395 }
4396
Jouni Malinendc6382c2009-05-06 22:09:37 +03004397 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004398 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004399 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004400 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004401 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004402 else if (mfp != NL80211_MFP_NO)
4403 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004404 }
4405
Johannes Berg3e5d7642009-07-07 14:37:26 +02004406 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4407 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4408
Johannes Bergc0692b82010-08-27 14:26:53 +03004409 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004410 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004411 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4412 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02004413 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004414
Jouni Malinen636a5d32009-03-19 13:39:22 +02004415 return err;
4416}
4417
4418static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4419{
Johannes Berg4c476992010-10-04 21:36:35 +02004420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4421 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004422 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004423 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004424 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004425 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004426
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004427 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4428 return -EINVAL;
4429
4430 if (!info->attrs[NL80211_ATTR_MAC])
4431 return -EINVAL;
4432
4433 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4434 return -EINVAL;
4435
Johannes Berg4c476992010-10-04 21:36:35 +02004436 if (!rdev->ops->deauth)
4437 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004438
Johannes Berg074ac8d2010-09-16 14:58:22 +02004439 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004440 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4441 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004442
Johannes Berg19957bb2009-07-02 17:20:43 +02004443 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004444
Johannes Berg19957bb2009-07-02 17:20:43 +02004445 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4446 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004447 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004448 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004449 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004450
4451 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004452 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4453 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004454 }
4455
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004456 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4457
Johannes Berg4c476992010-10-04 21:36:35 +02004458 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4459 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004460}
4461
4462static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4463{
Johannes Berg4c476992010-10-04 21:36:35 +02004464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4465 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004466 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004467 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004468 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004469 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004470
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004471 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4472 return -EINVAL;
4473
4474 if (!info->attrs[NL80211_ATTR_MAC])
4475 return -EINVAL;
4476
4477 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4478 return -EINVAL;
4479
Johannes Berg4c476992010-10-04 21:36:35 +02004480 if (!rdev->ops->disassoc)
4481 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004482
Johannes Berg074ac8d2010-09-16 14:58:22 +02004483 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004484 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4485 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004486
Johannes Berg19957bb2009-07-02 17:20:43 +02004487 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004488
Johannes Berg19957bb2009-07-02 17:20:43 +02004489 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4490 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004491 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004492 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004493 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004494
4495 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004496 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4497 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004498 }
4499
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004500 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4501
Johannes Berg4c476992010-10-04 21:36:35 +02004502 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4503 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004504}
4505
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004506static bool
4507nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4508 int mcast_rate[IEEE80211_NUM_BANDS],
4509 int rateval)
4510{
4511 struct wiphy *wiphy = &rdev->wiphy;
4512 bool found = false;
4513 int band, i;
4514
4515 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4516 struct ieee80211_supported_band *sband;
4517
4518 sband = wiphy->bands[band];
4519 if (!sband)
4520 continue;
4521
4522 for (i = 0; i < sband->n_bitrates; i++) {
4523 if (sband->bitrates[i].bitrate == rateval) {
4524 mcast_rate[band] = i + 1;
4525 found = true;
4526 break;
4527 }
4528 }
4529 }
4530
4531 return found;
4532}
4533
Johannes Berg04a773a2009-04-19 21:24:32 +02004534static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4535{
Johannes Berg4c476992010-10-04 21:36:35 +02004536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4537 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004538 struct cfg80211_ibss_params ibss;
4539 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004540 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004541 int err;
4542
Johannes Berg8e30bc52009-04-22 17:45:38 +02004543 memset(&ibss, 0, sizeof(ibss));
4544
Johannes Berg04a773a2009-04-19 21:24:32 +02004545 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4546 return -EINVAL;
4547
4548 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4549 !info->attrs[NL80211_ATTR_SSID] ||
4550 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4551 return -EINVAL;
4552
Johannes Berg8e30bc52009-04-22 17:45:38 +02004553 ibss.beacon_interval = 100;
4554
4555 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4556 ibss.beacon_interval =
4557 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4558 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4559 return -EINVAL;
4560 }
4561
Johannes Berg4c476992010-10-04 21:36:35 +02004562 if (!rdev->ops->join_ibss)
4563 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004564
Johannes Berg4c476992010-10-04 21:36:35 +02004565 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4566 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004567
Johannes Berg79c97e92009-07-07 03:56:12 +02004568 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004569
Johannes Berg39193492011-09-16 13:45:25 +02004570 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02004571 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02004572
4573 if (!is_valid_ether_addr(ibss.bssid))
4574 return -EINVAL;
4575 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004576 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4577 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4578
4579 if (info->attrs[NL80211_ATTR_IE]) {
4580 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4581 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4582 }
4583
4584 ibss.channel = ieee80211_get_channel(wiphy,
4585 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4586 if (!ibss.channel ||
4587 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004588 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4589 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004590
4591 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004592 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004593
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004594 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4595 u8 *rates =
4596 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4597 int n_rates =
4598 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4599 struct ieee80211_supported_band *sband =
4600 wiphy->bands[ibss.channel->band];
Johannes Berg34850ab2011-07-18 18:08:35 +02004601 int err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004602
Johannes Berg34850ab2011-07-18 18:08:35 +02004603 err = ieee80211_get_ratemask(sband, rates, n_rates,
4604 &ibss.basic_rates);
4605 if (err)
4606 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004607 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004608
4609 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4610 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4611 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4612 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004613
Johannes Berg4c476992010-10-04 21:36:35 +02004614 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4615 connkeys = nl80211_parse_connkeys(rdev,
4616 info->attrs[NL80211_ATTR_KEYS]);
4617 if (IS_ERR(connkeys))
4618 return PTR_ERR(connkeys);
4619 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004620
Johannes Berg4c476992010-10-04 21:36:35 +02004621 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004622 if (err)
4623 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004624 return err;
4625}
4626
4627static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4628{
Johannes Berg4c476992010-10-04 21:36:35 +02004629 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4630 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004631
Johannes Berg4c476992010-10-04 21:36:35 +02004632 if (!rdev->ops->leave_ibss)
4633 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004634
Johannes Berg4c476992010-10-04 21:36:35 +02004635 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4636 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004637
Johannes Berg4c476992010-10-04 21:36:35 +02004638 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004639}
4640
Johannes Bergaff89a92009-07-01 21:26:51 +02004641#ifdef CONFIG_NL80211_TESTMODE
4642static struct genl_multicast_group nl80211_testmode_mcgrp = {
4643 .name = "testmode",
4644};
4645
4646static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4647{
Johannes Berg4c476992010-10-04 21:36:35 +02004648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004649 int err;
4650
4651 if (!info->attrs[NL80211_ATTR_TESTDATA])
4652 return -EINVAL;
4653
Johannes Bergaff89a92009-07-01 21:26:51 +02004654 err = -EOPNOTSUPP;
4655 if (rdev->ops->testmode_cmd) {
4656 rdev->testmode_info = info;
4657 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4658 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4659 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4660 rdev->testmode_info = NULL;
4661 }
4662
Johannes Bergaff89a92009-07-01 21:26:51 +02004663 return err;
4664}
4665
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004666static int nl80211_testmode_dump(struct sk_buff *skb,
4667 struct netlink_callback *cb)
4668{
4669 struct cfg80211_registered_device *dev;
4670 int err;
4671 long phy_idx;
4672 void *data = NULL;
4673 int data_len = 0;
4674
4675 if (cb->args[0]) {
4676 /*
4677 * 0 is a valid index, but not valid for args[0],
4678 * so we need to offset by 1.
4679 */
4680 phy_idx = cb->args[0] - 1;
4681 } else {
4682 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4683 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4684 nl80211_policy);
4685 if (err)
4686 return err;
4687 if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY])
4688 return -EINVAL;
4689 phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4690 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4691 cb->args[1] =
4692 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4693 }
4694
4695 if (cb->args[1]) {
4696 data = nla_data((void *)cb->args[1]);
4697 data_len = nla_len((void *)cb->args[1]);
4698 }
4699
4700 mutex_lock(&cfg80211_mutex);
4701 dev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4702 if (!dev) {
4703 mutex_unlock(&cfg80211_mutex);
4704 return -ENOENT;
4705 }
4706 cfg80211_lock_rdev(dev);
4707 mutex_unlock(&cfg80211_mutex);
4708
4709 if (!dev->ops->testmode_dump) {
4710 err = -EOPNOTSUPP;
4711 goto out_err;
4712 }
4713
4714 while (1) {
4715 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4716 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4717 NL80211_CMD_TESTMODE);
4718 struct nlattr *tmdata;
4719
4720 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) {
4721 genlmsg_cancel(skb, hdr);
4722 break;
4723 }
4724
4725 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4726 if (!tmdata) {
4727 genlmsg_cancel(skb, hdr);
4728 break;
4729 }
4730 err = dev->ops->testmode_dump(&dev->wiphy, skb, cb,
4731 data, data_len);
4732 nla_nest_end(skb, tmdata);
4733
4734 if (err == -ENOBUFS || err == -ENOENT) {
4735 genlmsg_cancel(skb, hdr);
4736 break;
4737 } else if (err) {
4738 genlmsg_cancel(skb, hdr);
4739 goto out_err;
4740 }
4741
4742 genlmsg_end(skb, hdr);
4743 }
4744
4745 err = skb->len;
4746 /* see above */
4747 cb->args[0] = phy_idx + 1;
4748 out_err:
4749 cfg80211_unlock_rdev(dev);
4750 return err;
4751}
4752
Johannes Bergaff89a92009-07-01 21:26:51 +02004753static struct sk_buff *
4754__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4755 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4756{
4757 struct sk_buff *skb;
4758 void *hdr;
4759 struct nlattr *data;
4760
4761 skb = nlmsg_new(approxlen + 100, gfp);
4762 if (!skb)
4763 return NULL;
4764
4765 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4766 if (!hdr) {
4767 kfree_skb(skb);
4768 return NULL;
4769 }
4770
4771 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4772 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4773
4774 ((void **)skb->cb)[0] = rdev;
4775 ((void **)skb->cb)[1] = hdr;
4776 ((void **)skb->cb)[2] = data;
4777
4778 return skb;
4779
4780 nla_put_failure:
4781 kfree_skb(skb);
4782 return NULL;
4783}
4784
4785struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4786 int approxlen)
4787{
4788 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4789
4790 if (WARN_ON(!rdev->testmode_info))
4791 return NULL;
4792
4793 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4794 rdev->testmode_info->snd_pid,
4795 rdev->testmode_info->snd_seq,
4796 GFP_KERNEL);
4797}
4798EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4799
4800int cfg80211_testmode_reply(struct sk_buff *skb)
4801{
4802 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4803 void *hdr = ((void **)skb->cb)[1];
4804 struct nlattr *data = ((void **)skb->cb)[2];
4805
4806 if (WARN_ON(!rdev->testmode_info)) {
4807 kfree_skb(skb);
4808 return -EINVAL;
4809 }
4810
4811 nla_nest_end(skb, data);
4812 genlmsg_end(skb, hdr);
4813 return genlmsg_reply(skb, rdev->testmode_info);
4814}
4815EXPORT_SYMBOL(cfg80211_testmode_reply);
4816
4817struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4818 int approxlen, gfp_t gfp)
4819{
4820 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4821
4822 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4823}
4824EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4825
4826void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4827{
4828 void *hdr = ((void **)skb->cb)[1];
4829 struct nlattr *data = ((void **)skb->cb)[2];
4830
4831 nla_nest_end(skb, data);
4832 genlmsg_end(skb, hdr);
4833 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4834}
4835EXPORT_SYMBOL(cfg80211_testmode_event);
4836#endif
4837
Samuel Ortizb23aa672009-07-01 21:26:54 +02004838static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4839{
Johannes Berg4c476992010-10-04 21:36:35 +02004840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4841 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004842 struct cfg80211_connect_params connect;
4843 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004844 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004845 int err;
4846
4847 memset(&connect, 0, sizeof(connect));
4848
4849 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4850 return -EINVAL;
4851
4852 if (!info->attrs[NL80211_ATTR_SSID] ||
4853 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4854 return -EINVAL;
4855
4856 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4857 connect.auth_type =
4858 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4859 if (!nl80211_valid_auth_type(connect.auth_type))
4860 return -EINVAL;
4861 } else
4862 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4863
4864 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4865
Johannes Bergc0692b82010-08-27 14:26:53 +03004866 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004867 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004868 if (err)
4869 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004870
Johannes Berg074ac8d2010-09-16 14:58:22 +02004871 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004872 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4873 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004874
Johannes Berg79c97e92009-07-07 03:56:12 +02004875 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004876
Samuel Ortizb23aa672009-07-01 21:26:54 +02004877 if (info->attrs[NL80211_ATTR_MAC])
4878 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4879 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4880 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4881
4882 if (info->attrs[NL80211_ATTR_IE]) {
4883 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4884 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4885 }
4886
4887 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4888 connect.channel =
4889 ieee80211_get_channel(wiphy,
4890 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4891 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004892 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4893 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004894 }
4895
Johannes Bergfffd0932009-07-08 14:22:54 +02004896 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4897 connkeys = nl80211_parse_connkeys(rdev,
4898 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004899 if (IS_ERR(connkeys))
4900 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004901 }
4902
4903 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004904 if (err)
4905 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004906 return err;
4907}
4908
4909static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4910{
Johannes Berg4c476992010-10-04 21:36:35 +02004911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4912 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004913 u16 reason;
4914
4915 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4916 reason = WLAN_REASON_DEAUTH_LEAVING;
4917 else
4918 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4919
4920 if (reason == 0)
4921 return -EINVAL;
4922
Johannes Berg074ac8d2010-09-16 14:58:22 +02004923 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004924 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4925 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004926
Johannes Berg4c476992010-10-04 21:36:35 +02004927 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004928}
4929
Johannes Berg463d0182009-07-14 00:33:35 +02004930static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4931{
Johannes Berg4c476992010-10-04 21:36:35 +02004932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004933 struct net *net;
4934 int err;
4935 u32 pid;
4936
4937 if (!info->attrs[NL80211_ATTR_PID])
4938 return -EINVAL;
4939
4940 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4941
Johannes Berg463d0182009-07-14 00:33:35 +02004942 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004943 if (IS_ERR(net))
4944 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004945
4946 err = 0;
4947
4948 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004949 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4950 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004951
Johannes Berg463d0182009-07-14 00:33:35 +02004952 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004953 return err;
4954}
4955
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004956static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4957{
Johannes Berg4c476992010-10-04 21:36:35 +02004958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004959 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4960 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004961 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004962 struct cfg80211_pmksa pmksa;
4963
4964 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4965
4966 if (!info->attrs[NL80211_ATTR_MAC])
4967 return -EINVAL;
4968
4969 if (!info->attrs[NL80211_ATTR_PMKID])
4970 return -EINVAL;
4971
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004972 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4973 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4974
Johannes Berg074ac8d2010-09-16 14:58:22 +02004975 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004976 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4977 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004978
4979 switch (info->genlhdr->cmd) {
4980 case NL80211_CMD_SET_PMKSA:
4981 rdev_ops = rdev->ops->set_pmksa;
4982 break;
4983 case NL80211_CMD_DEL_PMKSA:
4984 rdev_ops = rdev->ops->del_pmksa;
4985 break;
4986 default:
4987 WARN_ON(1);
4988 break;
4989 }
4990
Johannes Berg4c476992010-10-04 21:36:35 +02004991 if (!rdev_ops)
4992 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004993
Johannes Berg4c476992010-10-04 21:36:35 +02004994 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004995}
4996
4997static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4998{
Johannes Berg4c476992010-10-04 21:36:35 +02004999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5000 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005001
Johannes Berg074ac8d2010-09-16 14:58:22 +02005002 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005003 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5004 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005005
Johannes Berg4c476992010-10-04 21:36:35 +02005006 if (!rdev->ops->flush_pmksa)
5007 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005008
Johannes Berg4c476992010-10-04 21:36:35 +02005009 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005010}
5011
Arik Nemtsov109086c2011-09-28 14:12:50 +03005012static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5013{
5014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5015 struct net_device *dev = info->user_ptr[1];
5016 u8 action_code, dialog_token;
5017 u16 status_code;
5018 u8 *peer;
5019
5020 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5021 !rdev->ops->tdls_mgmt)
5022 return -EOPNOTSUPP;
5023
5024 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5025 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5026 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5027 !info->attrs[NL80211_ATTR_IE] ||
5028 !info->attrs[NL80211_ATTR_MAC])
5029 return -EINVAL;
5030
5031 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5032 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5033 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5034 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5035
5036 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5037 dialog_token, status_code,
5038 nla_data(info->attrs[NL80211_ATTR_IE]),
5039 nla_len(info->attrs[NL80211_ATTR_IE]));
5040}
5041
5042static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5043{
5044 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5045 struct net_device *dev = info->user_ptr[1];
5046 enum nl80211_tdls_operation operation;
5047 u8 *peer;
5048
5049 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5050 !rdev->ops->tdls_oper)
5051 return -EOPNOTSUPP;
5052
5053 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5054 !info->attrs[NL80211_ATTR_MAC])
5055 return -EINVAL;
5056
5057 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5058 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5059
5060 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5061}
5062
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005063static int nl80211_remain_on_channel(struct sk_buff *skb,
5064 struct genl_info *info)
5065{
Johannes Berg4c476992010-10-04 21:36:35 +02005066 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5067 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005068 struct ieee80211_channel *chan;
5069 struct sk_buff *msg;
5070 void *hdr;
5071 u64 cookie;
5072 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5073 u32 freq, duration;
5074 int err;
5075
5076 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5077 !info->attrs[NL80211_ATTR_DURATION])
5078 return -EINVAL;
5079
5080 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5081
5082 /*
5083 * We should be on that channel for at least one jiffie,
5084 * and more than 5 seconds seems excessive.
5085 */
Johannes Berga2939112010-12-14 17:54:28 +01005086 if (!duration || !msecs_to_jiffies(duration) ||
5087 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005088 return -EINVAL;
5089
Johannes Berg4c476992010-10-04 21:36:35 +02005090 if (!rdev->ops->remain_on_channel)
5091 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005092
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005093 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5094 channel_type = nla_get_u32(
5095 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5096 if (channel_type != NL80211_CHAN_NO_HT &&
5097 channel_type != NL80211_CHAN_HT20 &&
5098 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005099 channel_type != NL80211_CHAN_HT40MINUS)
5100 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005101 }
5102
5103 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5104 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005105 if (chan == NULL)
5106 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005107
5108 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005109 if (!msg)
5110 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005111
5112 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5113 NL80211_CMD_REMAIN_ON_CHANNEL);
5114
5115 if (IS_ERR(hdr)) {
5116 err = PTR_ERR(hdr);
5117 goto free_msg;
5118 }
5119
5120 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5121 channel_type, duration, &cookie);
5122
5123 if (err)
5124 goto free_msg;
5125
5126 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5127
5128 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005129
5130 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005131
5132 nla_put_failure:
5133 err = -ENOBUFS;
5134 free_msg:
5135 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005136 return err;
5137}
5138
5139static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5140 struct genl_info *info)
5141{
Johannes Berg4c476992010-10-04 21:36:35 +02005142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5143 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005144 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005145
5146 if (!info->attrs[NL80211_ATTR_COOKIE])
5147 return -EINVAL;
5148
Johannes Berg4c476992010-10-04 21:36:35 +02005149 if (!rdev->ops->cancel_remain_on_channel)
5150 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005151
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005152 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5153
Johannes Berg4c476992010-10-04 21:36:35 +02005154 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005155}
5156
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005157static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5158 u8 *rates, u8 rates_len)
5159{
5160 u8 i;
5161 u32 mask = 0;
5162
5163 for (i = 0; i < rates_len; i++) {
5164 int rate = (rates[i] & 0x7f) * 5;
5165 int ridx;
5166 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5167 struct ieee80211_rate *srate =
5168 &sband->bitrates[ridx];
5169 if (rate == srate->bitrate) {
5170 mask |= 1 << ridx;
5171 break;
5172 }
5173 }
5174 if (ridx == sband->n_bitrates)
5175 return 0; /* rate not found */
5176 }
5177
5178 return mask;
5179}
5180
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005181static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005182 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5183 .len = NL80211_MAX_SUPP_RATES },
5184};
5185
5186static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5187 struct genl_info *info)
5188{
5189 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005191 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005192 int rem, i;
5193 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005194 struct nlattr *tx_rates;
5195 struct ieee80211_supported_band *sband;
5196
5197 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5198 return -EINVAL;
5199
Johannes Berg4c476992010-10-04 21:36:35 +02005200 if (!rdev->ops->set_bitrate_mask)
5201 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005202
5203 memset(&mask, 0, sizeof(mask));
5204 /* Default to all rates enabled */
5205 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5206 sband = rdev->wiphy.bands[i];
5207 mask.control[i].legacy =
5208 sband ? (1 << sband->n_bitrates) - 1 : 0;
5209 }
5210
5211 /*
5212 * The nested attribute uses enum nl80211_band as the index. This maps
5213 * directly to the enum ieee80211_band values used in cfg80211.
5214 */
5215 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5216 {
5217 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005218 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5219 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005220 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005221 if (sband == NULL)
5222 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005223 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5224 nla_len(tx_rates), nl80211_txattr_policy);
5225 if (tb[NL80211_TXRATE_LEGACY]) {
5226 mask.control[band].legacy = rateset_to_mask(
5227 sband,
5228 nla_data(tb[NL80211_TXRATE_LEGACY]),
5229 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02005230 if (mask.control[band].legacy == 0)
5231 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005232 }
5233 }
5234
Johannes Berg4c476992010-10-04 21:36:35 +02005235 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005236}
5237
Johannes Berg2e161f72010-08-12 15:38:38 +02005238static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005239{
Johannes Berg4c476992010-10-04 21:36:35 +02005240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5241 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005242 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005243
5244 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5245 return -EINVAL;
5246
Johannes Berg2e161f72010-08-12 15:38:38 +02005247 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5248 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005249
Johannes Berg9d38d852010-06-09 17:20:33 +02005250 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005251 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005252 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5253 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5254 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005255 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005256 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5257 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005258
5259 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005260 if (!rdev->ops->mgmt_tx)
5261 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005262
Johannes Berg4c476992010-10-04 21:36:35 +02005263 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005264 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005265 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5266 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005267}
5268
Johannes Berg2e161f72010-08-12 15:38:38 +02005269static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005270{
Johannes Berg4c476992010-10-04 21:36:35 +02005271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5272 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005273 struct ieee80211_channel *chan;
5274 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005275 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005276 u32 freq;
5277 int err;
5278 void *hdr;
5279 u64 cookie;
5280 struct sk_buff *msg;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005281 unsigned int wait = 0;
5282 bool offchan;
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305283 bool no_cck;
Jouni Malinen026331c2010-02-15 12:53:10 +02005284
5285 if (!info->attrs[NL80211_ATTR_FRAME] ||
5286 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5287 return -EINVAL;
5288
Johannes Berg4c476992010-10-04 21:36:35 +02005289 if (!rdev->ops->mgmt_tx)
5290 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005291
Johannes Berg9d38d852010-06-09 17:20:33 +02005292 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005293 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5295 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005297 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005298 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5299 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005300
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005301 if (info->attrs[NL80211_ATTR_DURATION]) {
5302 if (!rdev->ops->mgmt_tx_cancel_wait)
5303 return -EINVAL;
5304 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5305 }
5306
Jouni Malinen026331c2010-02-15 12:53:10 +02005307 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5308 channel_type = nla_get_u32(
5309 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5310 if (channel_type != NL80211_CHAN_NO_HT &&
5311 channel_type != NL80211_CHAN_HT20 &&
5312 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005313 channel_type != NL80211_CHAN_HT40MINUS)
5314 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005315 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005316 }
5317
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005318 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5319
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305320 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5321
Jouni Malinen026331c2010-02-15 12:53:10 +02005322 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5323 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005324 if (chan == NULL)
5325 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005326
5327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005328 if (!msg)
5329 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005330
5331 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02005332 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005333
5334 if (IS_ERR(hdr)) {
5335 err = PTR_ERR(hdr);
5336 goto free_msg;
5337 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005338 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5339 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005340 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5341 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305342 no_cck, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005343 if (err)
5344 goto free_msg;
5345
5346 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5347
5348 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005349 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02005350
5351 nla_put_failure:
5352 err = -ENOBUFS;
5353 free_msg:
5354 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005355 return err;
5356}
5357
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005358static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5359{
5360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5361 struct net_device *dev = info->user_ptr[1];
5362 u64 cookie;
5363
5364 if (!info->attrs[NL80211_ATTR_COOKIE])
5365 return -EINVAL;
5366
5367 if (!rdev->ops->mgmt_tx_cancel_wait)
5368 return -EOPNOTSUPP;
5369
5370 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5371 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5373 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5374 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5375 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5376 return -EOPNOTSUPP;
5377
5378 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5379
5380 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5381}
5382
Kalle Valoffb9eb32010-02-17 17:58:10 +02005383static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5384{
Johannes Berg4c476992010-10-04 21:36:35 +02005385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005386 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005387 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005388 u8 ps_state;
5389 bool state;
5390 int err;
5391
Johannes Berg4c476992010-10-04 21:36:35 +02005392 if (!info->attrs[NL80211_ATTR_PS_STATE])
5393 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005394
5395 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5396
Johannes Berg4c476992010-10-04 21:36:35 +02005397 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5398 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005399
5400 wdev = dev->ieee80211_ptr;
5401
Johannes Berg4c476992010-10-04 21:36:35 +02005402 if (!rdev->ops->set_power_mgmt)
5403 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005404
5405 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5406
5407 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005408 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005409
Johannes Berg4c476992010-10-04 21:36:35 +02005410 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5411 wdev->ps_timeout);
5412 if (!err)
5413 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005414 return err;
5415}
5416
5417static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5418{
Johannes Berg4c476992010-10-04 21:36:35 +02005419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005420 enum nl80211_ps_state ps_state;
5421 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005422 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005423 struct sk_buff *msg;
5424 void *hdr;
5425 int err;
5426
Kalle Valoffb9eb32010-02-17 17:58:10 +02005427 wdev = dev->ieee80211_ptr;
5428
Johannes Berg4c476992010-10-04 21:36:35 +02005429 if (!rdev->ops->set_power_mgmt)
5430 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005431
5432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005433 if (!msg)
5434 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005435
5436 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5437 NL80211_CMD_GET_POWER_SAVE);
5438 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005439 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005440 goto free_msg;
5441 }
5442
5443 if (wdev->ps)
5444 ps_state = NL80211_PS_ENABLED;
5445 else
5446 ps_state = NL80211_PS_DISABLED;
5447
5448 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5449
5450 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005451 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005452
Johannes Berg4c476992010-10-04 21:36:35 +02005453 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005454 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005455 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005456 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005457 return err;
5458}
5459
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005460static struct nla_policy
5461nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5462 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5463 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5464 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5465};
5466
5467static int nl80211_set_cqm_rssi(struct genl_info *info,
5468 s32 threshold, u32 hysteresis)
5469{
Johannes Berg4c476992010-10-04 21:36:35 +02005470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005471 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005472 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005473
5474 if (threshold > 0)
5475 return -EINVAL;
5476
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005477 wdev = dev->ieee80211_ptr;
5478
Johannes Berg4c476992010-10-04 21:36:35 +02005479 if (!rdev->ops->set_cqm_rssi_config)
5480 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005481
Johannes Berg074ac8d2010-09-16 14:58:22 +02005482 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005483 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5484 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005485
Johannes Berg4c476992010-10-04 21:36:35 +02005486 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5487 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005488}
5489
5490static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5491{
5492 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5493 struct nlattr *cqm;
5494 int err;
5495
5496 cqm = info->attrs[NL80211_ATTR_CQM];
5497 if (!cqm) {
5498 err = -EINVAL;
5499 goto out;
5500 }
5501
5502 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5503 nl80211_attr_cqm_policy);
5504 if (err)
5505 goto out;
5506
5507 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5508 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5509 s32 threshold;
5510 u32 hysteresis;
5511 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5512 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5513 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5514 } else
5515 err = -EINVAL;
5516
5517out:
5518 return err;
5519}
5520
Johannes Berg29cbe682010-12-03 09:20:44 +01005521static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5522{
5523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5524 struct net_device *dev = info->user_ptr[1];
5525 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005526 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005527 int err;
5528
5529 /* start with default */
5530 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005531 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005532
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005533 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005534 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005535 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005536 if (err)
5537 return err;
5538 }
5539
5540 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5541 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5542 return -EINVAL;
5543
Javier Cardonac80d5452010-12-16 17:37:49 -08005544 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5545 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5546
5547 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5548 /* parse additional setup parameters if given */
5549 err = nl80211_parse_mesh_setup(info, &setup);
5550 if (err)
5551 return err;
5552 }
5553
5554 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005555}
5556
5557static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5558{
5559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5560 struct net_device *dev = info->user_ptr[1];
5561
5562 return cfg80211_leave_mesh(rdev, dev);
5563}
5564
Johannes Bergff1b6e62011-05-04 15:37:28 +02005565static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5566{
5567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5568 struct sk_buff *msg;
5569 void *hdr;
5570
5571 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5572 return -EOPNOTSUPP;
5573
5574 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5575 if (!msg)
5576 return -ENOMEM;
5577
5578 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5579 NL80211_CMD_GET_WOWLAN);
5580 if (!hdr)
5581 goto nla_put_failure;
5582
5583 if (rdev->wowlan) {
5584 struct nlattr *nl_wowlan;
5585
5586 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5587 if (!nl_wowlan)
5588 goto nla_put_failure;
5589
5590 if (rdev->wowlan->any)
5591 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5592 if (rdev->wowlan->disconnect)
5593 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5594 if (rdev->wowlan->magic_pkt)
5595 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005596 if (rdev->wowlan->gtk_rekey_failure)
5597 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5598 if (rdev->wowlan->eap_identity_req)
5599 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5600 if (rdev->wowlan->four_way_handshake)
5601 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5602 if (rdev->wowlan->rfkill_release)
5603 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005604 if (rdev->wowlan->n_patterns) {
5605 struct nlattr *nl_pats, *nl_pat;
5606 int i, pat_len;
5607
5608 nl_pats = nla_nest_start(msg,
5609 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5610 if (!nl_pats)
5611 goto nla_put_failure;
5612
5613 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5614 nl_pat = nla_nest_start(msg, i + 1);
5615 if (!nl_pat)
5616 goto nla_put_failure;
5617 pat_len = rdev->wowlan->patterns[i].pattern_len;
5618 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5619 DIV_ROUND_UP(pat_len, 8),
5620 rdev->wowlan->patterns[i].mask);
5621 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5622 pat_len,
5623 rdev->wowlan->patterns[i].pattern);
5624 nla_nest_end(msg, nl_pat);
5625 }
5626 nla_nest_end(msg, nl_pats);
5627 }
5628
5629 nla_nest_end(msg, nl_wowlan);
5630 }
5631
5632 genlmsg_end(msg, hdr);
5633 return genlmsg_reply(msg, info);
5634
5635nla_put_failure:
5636 nlmsg_free(msg);
5637 return -ENOBUFS;
5638}
5639
5640static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5641{
5642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5643 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5644 struct cfg80211_wowlan no_triggers = {};
5645 struct cfg80211_wowlan new_triggers = {};
5646 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5647 int err, i;
5648
5649 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5650 return -EOPNOTSUPP;
5651
5652 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5653 goto no_triggers;
5654
5655 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5656 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5657 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5658 nl80211_wowlan_policy);
5659 if (err)
5660 return err;
5661
5662 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5663 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5664 return -EINVAL;
5665 new_triggers.any = true;
5666 }
5667
5668 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5669 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5670 return -EINVAL;
5671 new_triggers.disconnect = true;
5672 }
5673
5674 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5675 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5676 return -EINVAL;
5677 new_triggers.magic_pkt = true;
5678 }
5679
Johannes Berg77dbbb12011-07-13 10:48:55 +02005680 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5681 return -EINVAL;
5682
5683 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5684 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5685 return -EINVAL;
5686 new_triggers.gtk_rekey_failure = true;
5687 }
5688
5689 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5690 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5691 return -EINVAL;
5692 new_triggers.eap_identity_req = true;
5693 }
5694
5695 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5696 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5697 return -EINVAL;
5698 new_triggers.four_way_handshake = true;
5699 }
5700
5701 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5702 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5703 return -EINVAL;
5704 new_triggers.rfkill_release = true;
5705 }
5706
Johannes Bergff1b6e62011-05-04 15:37:28 +02005707 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5708 struct nlattr *pat;
5709 int n_patterns = 0;
5710 int rem, pat_len, mask_len;
5711 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5712
5713 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5714 rem)
5715 n_patterns++;
5716 if (n_patterns > wowlan->n_patterns)
5717 return -EINVAL;
5718
5719 new_triggers.patterns = kcalloc(n_patterns,
5720 sizeof(new_triggers.patterns[0]),
5721 GFP_KERNEL);
5722 if (!new_triggers.patterns)
5723 return -ENOMEM;
5724
5725 new_triggers.n_patterns = n_patterns;
5726 i = 0;
5727
5728 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5729 rem) {
5730 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5731 nla_data(pat), nla_len(pat), NULL);
5732 err = -EINVAL;
5733 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5734 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5735 goto error;
5736 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5737 mask_len = DIV_ROUND_UP(pat_len, 8);
5738 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5739 mask_len)
5740 goto error;
5741 if (pat_len > wowlan->pattern_max_len ||
5742 pat_len < wowlan->pattern_min_len)
5743 goto error;
5744
5745 new_triggers.patterns[i].mask =
5746 kmalloc(mask_len + pat_len, GFP_KERNEL);
5747 if (!new_triggers.patterns[i].mask) {
5748 err = -ENOMEM;
5749 goto error;
5750 }
5751 new_triggers.patterns[i].pattern =
5752 new_triggers.patterns[i].mask + mask_len;
5753 memcpy(new_triggers.patterns[i].mask,
5754 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5755 mask_len);
5756 new_triggers.patterns[i].pattern_len = pat_len;
5757 memcpy(new_triggers.patterns[i].pattern,
5758 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5759 pat_len);
5760 i++;
5761 }
5762 }
5763
5764 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5765 struct cfg80211_wowlan *ntrig;
5766 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5767 GFP_KERNEL);
5768 if (!ntrig) {
5769 err = -ENOMEM;
5770 goto error;
5771 }
5772 cfg80211_rdev_free_wowlan(rdev);
5773 rdev->wowlan = ntrig;
5774 } else {
5775 no_triggers:
5776 cfg80211_rdev_free_wowlan(rdev);
5777 rdev->wowlan = NULL;
5778 }
5779
5780 return 0;
5781 error:
5782 for (i = 0; i < new_triggers.n_patterns; i++)
5783 kfree(new_triggers.patterns[i].mask);
5784 kfree(new_triggers.patterns);
5785 return err;
5786}
5787
Johannes Berge5497d72011-07-05 16:35:40 +02005788static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
5789{
5790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5791 struct net_device *dev = info->user_ptr[1];
5792 struct wireless_dev *wdev = dev->ieee80211_ptr;
5793 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
5794 struct cfg80211_gtk_rekey_data rekey_data;
5795 int err;
5796
5797 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
5798 return -EINVAL;
5799
5800 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
5801 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
5802 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
5803 nl80211_rekey_policy);
5804 if (err)
5805 return err;
5806
5807 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
5808 return -ERANGE;
5809 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
5810 return -ERANGE;
5811 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
5812 return -ERANGE;
5813
5814 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
5815 NL80211_KEK_LEN);
5816 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
5817 NL80211_KCK_LEN);
5818 memcpy(rekey_data.replay_ctr,
5819 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
5820 NL80211_REPLAY_CTR_LEN);
5821
5822 wdev_lock(wdev);
5823 if (!wdev->current_bss) {
5824 err = -ENOTCONN;
5825 goto out;
5826 }
5827
5828 if (!rdev->ops->set_rekey_data) {
5829 err = -EOPNOTSUPP;
5830 goto out;
5831 }
5832
5833 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
5834 out:
5835 wdev_unlock(wdev);
5836 return err;
5837}
5838
Johannes Berg28946da2011-11-04 11:18:12 +01005839static int nl80211_register_unexpected_frame(struct sk_buff *skb,
5840 struct genl_info *info)
5841{
5842 struct net_device *dev = info->user_ptr[1];
5843 struct wireless_dev *wdev = dev->ieee80211_ptr;
5844
5845 if (wdev->iftype != NL80211_IFTYPE_AP &&
5846 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5847 return -EINVAL;
5848
5849 if (wdev->ap_unexpected_nlpid)
5850 return -EBUSY;
5851
5852 wdev->ap_unexpected_nlpid = info->snd_pid;
5853 return 0;
5854}
5855
Johannes Berg4c476992010-10-04 21:36:35 +02005856#define NL80211_FLAG_NEED_WIPHY 0x01
5857#define NL80211_FLAG_NEED_NETDEV 0x02
5858#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02005859#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5860#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5861 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02005862
5863static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5864 struct genl_info *info)
5865{
5866 struct cfg80211_registered_device *rdev;
5867 struct net_device *dev;
5868 int err;
5869 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5870
5871 if (rtnl)
5872 rtnl_lock();
5873
5874 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5875 rdev = cfg80211_get_dev_from_info(info);
5876 if (IS_ERR(rdev)) {
5877 if (rtnl)
5878 rtnl_unlock();
5879 return PTR_ERR(rdev);
5880 }
5881 info->user_ptr[0] = rdev;
5882 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5883 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5884 if (err) {
5885 if (rtnl)
5886 rtnl_unlock();
5887 return err;
5888 }
Johannes Berg41265712010-10-04 21:14:05 +02005889 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
5890 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02005891 cfg80211_unlock_rdev(rdev);
5892 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02005893 if (rtnl)
5894 rtnl_unlock();
5895 return -ENETDOWN;
5896 }
Johannes Berg4c476992010-10-04 21:36:35 +02005897 info->user_ptr[0] = rdev;
5898 info->user_ptr[1] = dev;
5899 }
5900
5901 return 0;
5902}
5903
5904static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
5905 struct genl_info *info)
5906{
5907 if (info->user_ptr[0])
5908 cfg80211_unlock_rdev(info->user_ptr[0]);
5909 if (info->user_ptr[1])
5910 dev_put(info->user_ptr[1]);
5911 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
5912 rtnl_unlock();
5913}
5914
Johannes Berg55682962007-09-20 13:09:35 -04005915static struct genl_ops nl80211_ops[] = {
5916 {
5917 .cmd = NL80211_CMD_GET_WIPHY,
5918 .doit = nl80211_get_wiphy,
5919 .dumpit = nl80211_dump_wiphy,
5920 .policy = nl80211_policy,
5921 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005922 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04005923 },
5924 {
5925 .cmd = NL80211_CMD_SET_WIPHY,
5926 .doit = nl80211_set_wiphy,
5927 .policy = nl80211_policy,
5928 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005929 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005930 },
5931 {
5932 .cmd = NL80211_CMD_GET_INTERFACE,
5933 .doit = nl80211_get_interface,
5934 .dumpit = nl80211_dump_interface,
5935 .policy = nl80211_policy,
5936 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005937 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04005938 },
5939 {
5940 .cmd = NL80211_CMD_SET_INTERFACE,
5941 .doit = nl80211_set_interface,
5942 .policy = nl80211_policy,
5943 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005944 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5945 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005946 },
5947 {
5948 .cmd = NL80211_CMD_NEW_INTERFACE,
5949 .doit = nl80211_new_interface,
5950 .policy = nl80211_policy,
5951 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005952 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5953 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005954 },
5955 {
5956 .cmd = NL80211_CMD_DEL_INTERFACE,
5957 .doit = nl80211_del_interface,
5958 .policy = nl80211_policy,
5959 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005960 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5961 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005962 },
Johannes Berg41ade002007-12-19 02:03:29 +01005963 {
5964 .cmd = NL80211_CMD_GET_KEY,
5965 .doit = nl80211_get_key,
5966 .policy = nl80211_policy,
5967 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005968 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5969 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005970 },
5971 {
5972 .cmd = NL80211_CMD_SET_KEY,
5973 .doit = nl80211_set_key,
5974 .policy = nl80211_policy,
5975 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005976 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005977 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005978 },
5979 {
5980 .cmd = NL80211_CMD_NEW_KEY,
5981 .doit = nl80211_new_key,
5982 .policy = nl80211_policy,
5983 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005985 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005986 },
5987 {
5988 .cmd = NL80211_CMD_DEL_KEY,
5989 .doit = nl80211_del_key,
5990 .policy = nl80211_policy,
5991 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005993 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005994 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01005995 {
5996 .cmd = NL80211_CMD_SET_BEACON,
5997 .policy = nl80211_policy,
5998 .flags = GENL_ADMIN_PERM,
5999 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006000 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6001 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006002 },
6003 {
6004 .cmd = NL80211_CMD_NEW_BEACON,
6005 .policy = nl80211_policy,
6006 .flags = GENL_ADMIN_PERM,
6007 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006008 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6009 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006010 },
6011 {
6012 .cmd = NL80211_CMD_DEL_BEACON,
6013 .policy = nl80211_policy,
6014 .flags = GENL_ADMIN_PERM,
6015 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006016 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6017 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006018 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006019 {
6020 .cmd = NL80211_CMD_GET_STATION,
6021 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006022 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006023 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006024 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6025 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006026 },
6027 {
6028 .cmd = NL80211_CMD_SET_STATION,
6029 .doit = nl80211_set_station,
6030 .policy = nl80211_policy,
6031 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006032 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6033 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006034 },
6035 {
6036 .cmd = NL80211_CMD_NEW_STATION,
6037 .doit = nl80211_new_station,
6038 .policy = nl80211_policy,
6039 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006041 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006042 },
6043 {
6044 .cmd = NL80211_CMD_DEL_STATION,
6045 .doit = nl80211_del_station,
6046 .policy = nl80211_policy,
6047 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006048 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6049 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006050 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006051 {
6052 .cmd = NL80211_CMD_GET_MPATH,
6053 .doit = nl80211_get_mpath,
6054 .dumpit = nl80211_dump_mpath,
6055 .policy = nl80211_policy,
6056 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006058 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006059 },
6060 {
6061 .cmd = NL80211_CMD_SET_MPATH,
6062 .doit = nl80211_set_mpath,
6063 .policy = nl80211_policy,
6064 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006066 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006067 },
6068 {
6069 .cmd = NL80211_CMD_NEW_MPATH,
6070 .doit = nl80211_new_mpath,
6071 .policy = nl80211_policy,
6072 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006073 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006074 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006075 },
6076 {
6077 .cmd = NL80211_CMD_DEL_MPATH,
6078 .doit = nl80211_del_mpath,
6079 .policy = nl80211_policy,
6080 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006081 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6082 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006083 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006084 {
6085 .cmd = NL80211_CMD_SET_BSS,
6086 .doit = nl80211_set_bss,
6087 .policy = nl80211_policy,
6088 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006089 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6090 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006091 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006092 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006093 .cmd = NL80211_CMD_GET_REG,
6094 .doit = nl80211_get_reg,
6095 .policy = nl80211_policy,
6096 /* can be retrieved by unprivileged users */
6097 },
6098 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006099 .cmd = NL80211_CMD_SET_REG,
6100 .doit = nl80211_set_reg,
6101 .policy = nl80211_policy,
6102 .flags = GENL_ADMIN_PERM,
6103 },
6104 {
6105 .cmd = NL80211_CMD_REQ_SET_REG,
6106 .doit = nl80211_req_set_reg,
6107 .policy = nl80211_policy,
6108 .flags = GENL_ADMIN_PERM,
6109 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006110 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006111 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6112 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006113 .policy = nl80211_policy,
6114 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006115 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6116 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006117 },
6118 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006119 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6120 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006121 .policy = nl80211_policy,
6122 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006123 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006124 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006125 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006126 {
Johannes Berg2a519312009-02-10 21:25:55 +01006127 .cmd = NL80211_CMD_TRIGGER_SCAN,
6128 .doit = nl80211_trigger_scan,
6129 .policy = nl80211_policy,
6130 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006131 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006132 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006133 },
6134 {
6135 .cmd = NL80211_CMD_GET_SCAN,
6136 .policy = nl80211_policy,
6137 .dumpit = nl80211_dump_scan,
6138 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006139 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006140 .cmd = NL80211_CMD_START_SCHED_SCAN,
6141 .doit = nl80211_start_sched_scan,
6142 .policy = nl80211_policy,
6143 .flags = GENL_ADMIN_PERM,
6144 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6145 NL80211_FLAG_NEED_RTNL,
6146 },
6147 {
6148 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6149 .doit = nl80211_stop_sched_scan,
6150 .policy = nl80211_policy,
6151 .flags = GENL_ADMIN_PERM,
6152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6153 NL80211_FLAG_NEED_RTNL,
6154 },
6155 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006156 .cmd = NL80211_CMD_AUTHENTICATE,
6157 .doit = nl80211_authenticate,
6158 .policy = nl80211_policy,
6159 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006161 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006162 },
6163 {
6164 .cmd = NL80211_CMD_ASSOCIATE,
6165 .doit = nl80211_associate,
6166 .policy = nl80211_policy,
6167 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006168 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006169 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006170 },
6171 {
6172 .cmd = NL80211_CMD_DEAUTHENTICATE,
6173 .doit = nl80211_deauthenticate,
6174 .policy = nl80211_policy,
6175 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006177 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006178 },
6179 {
6180 .cmd = NL80211_CMD_DISASSOCIATE,
6181 .doit = nl80211_disassociate,
6182 .policy = nl80211_policy,
6183 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006185 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006186 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006187 {
6188 .cmd = NL80211_CMD_JOIN_IBSS,
6189 .doit = nl80211_join_ibss,
6190 .policy = nl80211_policy,
6191 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006193 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006194 },
6195 {
6196 .cmd = NL80211_CMD_LEAVE_IBSS,
6197 .doit = nl80211_leave_ibss,
6198 .policy = nl80211_policy,
6199 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006201 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006202 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006203#ifdef CONFIG_NL80211_TESTMODE
6204 {
6205 .cmd = NL80211_CMD_TESTMODE,
6206 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006207 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006208 .policy = nl80211_policy,
6209 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006210 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6211 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006212 },
6213#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006214 {
6215 .cmd = NL80211_CMD_CONNECT,
6216 .doit = nl80211_connect,
6217 .policy = nl80211_policy,
6218 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006220 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006221 },
6222 {
6223 .cmd = NL80211_CMD_DISCONNECT,
6224 .doit = nl80211_disconnect,
6225 .policy = nl80211_policy,
6226 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006227 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006228 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006229 },
Johannes Berg463d0182009-07-14 00:33:35 +02006230 {
6231 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6232 .doit = nl80211_wiphy_netns,
6233 .policy = nl80211_policy,
6234 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006235 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6236 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006237 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006238 {
6239 .cmd = NL80211_CMD_GET_SURVEY,
6240 .policy = nl80211_policy,
6241 .dumpit = nl80211_dump_survey,
6242 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006243 {
6244 .cmd = NL80211_CMD_SET_PMKSA,
6245 .doit = nl80211_setdel_pmksa,
6246 .policy = nl80211_policy,
6247 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006248 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6249 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006250 },
6251 {
6252 .cmd = NL80211_CMD_DEL_PMKSA,
6253 .doit = nl80211_setdel_pmksa,
6254 .policy = nl80211_policy,
6255 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006256 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6257 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006258 },
6259 {
6260 .cmd = NL80211_CMD_FLUSH_PMKSA,
6261 .doit = nl80211_flush_pmksa,
6262 .policy = nl80211_policy,
6263 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006264 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6265 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006266 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006267 {
6268 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6269 .doit = nl80211_remain_on_channel,
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 Malinen9588bbd2009-12-23 13:15:41 +01006274 },
6275 {
6276 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6277 .doit = nl80211_cancel_remain_on_channel,
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 Malinen9588bbd2009-12-23 13:15:41 +01006282 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006283 {
6284 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6285 .doit = nl80211_set_tx_bitrate_mask,
6286 .policy = nl80211_policy,
6287 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006288 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6289 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006290 },
Jouni Malinen026331c2010-02-15 12:53:10 +02006291 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006292 .cmd = NL80211_CMD_REGISTER_FRAME,
6293 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006294 .policy = nl80211_policy,
6295 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006296 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6297 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006298 },
6299 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006300 .cmd = NL80211_CMD_FRAME,
6301 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006302 .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,
Jouni Malinen026331c2010-02-15 12:53:10 +02006306 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006307 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006308 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6309 .doit = nl80211_tx_mgmt_cancel_wait,
6310 .policy = nl80211_policy,
6311 .flags = GENL_ADMIN_PERM,
6312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6313 NL80211_FLAG_NEED_RTNL,
6314 },
6315 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006316 .cmd = NL80211_CMD_SET_POWER_SAVE,
6317 .doit = nl80211_set_power_save,
6318 .policy = nl80211_policy,
6319 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006320 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6321 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006322 },
6323 {
6324 .cmd = NL80211_CMD_GET_POWER_SAVE,
6325 .doit = nl80211_get_power_save,
6326 .policy = nl80211_policy,
6327 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006328 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6329 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006330 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006331 {
6332 .cmd = NL80211_CMD_SET_CQM,
6333 .doit = nl80211_set_cqm,
6334 .policy = nl80211_policy,
6335 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006336 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6337 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006338 },
Johannes Bergf444de02010-05-05 15:25:02 +02006339 {
6340 .cmd = NL80211_CMD_SET_CHANNEL,
6341 .doit = nl80211_set_channel,
6342 .policy = nl80211_policy,
6343 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006344 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6345 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006346 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006347 {
6348 .cmd = NL80211_CMD_SET_WDS_PEER,
6349 .doit = nl80211_set_wds_peer,
6350 .policy = nl80211_policy,
6351 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006352 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6353 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006354 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006355 {
6356 .cmd = NL80211_CMD_JOIN_MESH,
6357 .doit = nl80211_join_mesh,
6358 .policy = nl80211_policy,
6359 .flags = GENL_ADMIN_PERM,
6360 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6361 NL80211_FLAG_NEED_RTNL,
6362 },
6363 {
6364 .cmd = NL80211_CMD_LEAVE_MESH,
6365 .doit = nl80211_leave_mesh,
6366 .policy = nl80211_policy,
6367 .flags = GENL_ADMIN_PERM,
6368 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6369 NL80211_FLAG_NEED_RTNL,
6370 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006371 {
6372 .cmd = NL80211_CMD_GET_WOWLAN,
6373 .doit = nl80211_get_wowlan,
6374 .policy = nl80211_policy,
6375 /* can be retrieved by unprivileged users */
6376 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6377 NL80211_FLAG_NEED_RTNL,
6378 },
6379 {
6380 .cmd = NL80211_CMD_SET_WOWLAN,
6381 .doit = nl80211_set_wowlan,
6382 .policy = nl80211_policy,
6383 .flags = GENL_ADMIN_PERM,
6384 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6385 NL80211_FLAG_NEED_RTNL,
6386 },
Johannes Berge5497d72011-07-05 16:35:40 +02006387 {
6388 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6389 .doit = nl80211_set_rekey_data,
6390 .policy = nl80211_policy,
6391 .flags = GENL_ADMIN_PERM,
6392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6393 NL80211_FLAG_NEED_RTNL,
6394 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03006395 {
6396 .cmd = NL80211_CMD_TDLS_MGMT,
6397 .doit = nl80211_tdls_mgmt,
6398 .policy = nl80211_policy,
6399 .flags = GENL_ADMIN_PERM,
6400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6401 NL80211_FLAG_NEED_RTNL,
6402 },
6403 {
6404 .cmd = NL80211_CMD_TDLS_OPER,
6405 .doit = nl80211_tdls_oper,
6406 .policy = nl80211_policy,
6407 .flags = GENL_ADMIN_PERM,
6408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6409 NL80211_FLAG_NEED_RTNL,
6410 },
Johannes Berg28946da2011-11-04 11:18:12 +01006411 {
6412 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6413 .doit = nl80211_register_unexpected_frame,
6414 .policy = nl80211_policy,
6415 .flags = GENL_ADMIN_PERM,
6416 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6417 NL80211_FLAG_NEED_RTNL,
6418 },
Johannes Berg55682962007-09-20 13:09:35 -04006419};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006420
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006421static struct genl_multicast_group nl80211_mlme_mcgrp = {
6422 .name = "mlme",
6423};
Johannes Berg55682962007-09-20 13:09:35 -04006424
6425/* multicast groups */
6426static struct genl_multicast_group nl80211_config_mcgrp = {
6427 .name = "config",
6428};
Johannes Berg2a519312009-02-10 21:25:55 +01006429static struct genl_multicast_group nl80211_scan_mcgrp = {
6430 .name = "scan",
6431};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006432static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6433 .name = "regulatory",
6434};
Johannes Berg55682962007-09-20 13:09:35 -04006435
6436/* notification functions */
6437
6438void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6439{
6440 struct sk_buff *msg;
6441
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006443 if (!msg)
6444 return;
6445
6446 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6447 nlmsg_free(msg);
6448 return;
6449 }
6450
Johannes Berg463d0182009-07-14 00:33:35 +02006451 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6452 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006453}
6454
Johannes Berg362a4152009-05-24 16:43:15 +02006455static int nl80211_add_scan_req(struct sk_buff *msg,
6456 struct cfg80211_registered_device *rdev)
6457{
6458 struct cfg80211_scan_request *req = rdev->scan_req;
6459 struct nlattr *nest;
6460 int i;
6461
Johannes Berg667503dd2009-07-07 03:56:11 +02006462 ASSERT_RDEV_LOCK(rdev);
6463
Johannes Berg362a4152009-05-24 16:43:15 +02006464 if (WARN_ON(!req))
6465 return 0;
6466
6467 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6468 if (!nest)
6469 goto nla_put_failure;
6470 for (i = 0; i < req->n_ssids; i++)
6471 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6472 nla_nest_end(msg, nest);
6473
6474 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6475 if (!nest)
6476 goto nla_put_failure;
6477 for (i = 0; i < req->n_channels; i++)
6478 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6479 nla_nest_end(msg, nest);
6480
6481 if (req->ie)
6482 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6483
6484 return 0;
6485 nla_put_failure:
6486 return -ENOBUFS;
6487}
6488
Johannes Berga538e2d2009-06-16 19:56:42 +02006489static int nl80211_send_scan_msg(struct sk_buff *msg,
6490 struct cfg80211_registered_device *rdev,
6491 struct net_device *netdev,
6492 u32 pid, u32 seq, int flags,
6493 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006494{
6495 void *hdr;
6496
6497 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6498 if (!hdr)
6499 return -1;
6500
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006501 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006502 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6503
Johannes Berg362a4152009-05-24 16:43:15 +02006504 /* ignore errors and send incomplete event anyway */
6505 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006506
6507 return genlmsg_end(msg, hdr);
6508
6509 nla_put_failure:
6510 genlmsg_cancel(msg, hdr);
6511 return -EMSGSIZE;
6512}
6513
Luciano Coelho807f8a82011-05-11 17:09:35 +03006514static int
6515nl80211_send_sched_scan_msg(struct sk_buff *msg,
6516 struct cfg80211_registered_device *rdev,
6517 struct net_device *netdev,
6518 u32 pid, u32 seq, int flags, u32 cmd)
6519{
6520 void *hdr;
6521
6522 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6523 if (!hdr)
6524 return -1;
6525
6526 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6527 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6528
6529 return genlmsg_end(msg, hdr);
6530
6531 nla_put_failure:
6532 genlmsg_cancel(msg, hdr);
6533 return -EMSGSIZE;
6534}
6535
Johannes Berga538e2d2009-06-16 19:56:42 +02006536void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6537 struct net_device *netdev)
6538{
6539 struct sk_buff *msg;
6540
6541 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6542 if (!msg)
6543 return;
6544
6545 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6546 NL80211_CMD_TRIGGER_SCAN) < 0) {
6547 nlmsg_free(msg);
6548 return;
6549 }
6550
Johannes Berg463d0182009-07-14 00:33:35 +02006551 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6552 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006553}
6554
Johannes Berg2a519312009-02-10 21:25:55 +01006555void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6556 struct net_device *netdev)
6557{
6558 struct sk_buff *msg;
6559
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006561 if (!msg)
6562 return;
6563
Johannes Berga538e2d2009-06-16 19:56:42 +02006564 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6565 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006566 nlmsg_free(msg);
6567 return;
6568 }
6569
Johannes Berg463d0182009-07-14 00:33:35 +02006570 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6571 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006572}
6573
6574void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6575 struct net_device *netdev)
6576{
6577 struct sk_buff *msg;
6578
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006580 if (!msg)
6581 return;
6582
Johannes Berga538e2d2009-06-16 19:56:42 +02006583 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6584 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006585 nlmsg_free(msg);
6586 return;
6587 }
6588
Johannes Berg463d0182009-07-14 00:33:35 +02006589 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6590 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006591}
6592
Luciano Coelho807f8a82011-05-11 17:09:35 +03006593void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6594 struct net_device *netdev)
6595{
6596 struct sk_buff *msg;
6597
6598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6599 if (!msg)
6600 return;
6601
6602 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6603 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6604 nlmsg_free(msg);
6605 return;
6606 }
6607
6608 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6609 nl80211_scan_mcgrp.id, GFP_KERNEL);
6610}
6611
6612void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6613 struct net_device *netdev, u32 cmd)
6614{
6615 struct sk_buff *msg;
6616
6617 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6618 if (!msg)
6619 return;
6620
6621 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6622 nlmsg_free(msg);
6623 return;
6624 }
6625
6626 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6627 nl80211_scan_mcgrp.id, GFP_KERNEL);
6628}
6629
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006630/*
6631 * This can happen on global regulatory changes or device specific settings
6632 * based on custom world regulatory domains.
6633 */
6634void nl80211_send_reg_change_event(struct regulatory_request *request)
6635{
6636 struct sk_buff *msg;
6637 void *hdr;
6638
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006639 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006640 if (!msg)
6641 return;
6642
6643 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6644 if (!hdr) {
6645 nlmsg_free(msg);
6646 return;
6647 }
6648
6649 /* Userspace can always count this one always being set */
6650 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6651
6652 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6653 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6654 NL80211_REGDOM_TYPE_WORLD);
6655 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6656 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6657 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6658 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6659 request->intersect)
6660 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6661 NL80211_REGDOM_TYPE_INTERSECTION);
6662 else {
6663 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6664 NL80211_REGDOM_TYPE_COUNTRY);
6665 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6666 }
6667
6668 if (wiphy_idx_valid(request->wiphy_idx))
6669 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6670
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006671 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006672
Johannes Bergbc43b282009-07-25 10:54:13 +02006673 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02006674 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02006675 GFP_ATOMIC);
6676 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006677
6678 return;
6679
6680nla_put_failure:
6681 genlmsg_cancel(msg, hdr);
6682 nlmsg_free(msg);
6683}
6684
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006685static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
6686 struct net_device *netdev,
6687 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006688 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006689{
6690 struct sk_buff *msg;
6691 void *hdr;
6692
Johannes Berge6d6e342009-07-01 21:26:47 +02006693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006694 if (!msg)
6695 return;
6696
6697 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6698 if (!hdr) {
6699 nlmsg_free(msg);
6700 return;
6701 }
6702
6703 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6704 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6705 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6706
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006707 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006708
Johannes Berg463d0182009-07-14 00:33:35 +02006709 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6710 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006711 return;
6712
6713 nla_put_failure:
6714 genlmsg_cancel(msg, hdr);
6715 nlmsg_free(msg);
6716}
6717
6718void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006719 struct net_device *netdev, const u8 *buf,
6720 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006721{
6722 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006723 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006724}
6725
6726void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
6727 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006728 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006729{
Johannes Berge6d6e342009-07-01 21:26:47 +02006730 nl80211_send_mlme_event(rdev, netdev, buf, len,
6731 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006732}
6733
Jouni Malinen53b46b82009-03-27 20:53:56 +02006734void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006735 struct net_device *netdev, const u8 *buf,
6736 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006737{
6738 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006739 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006740}
6741
Jouni Malinen53b46b82009-03-27 20:53:56 +02006742void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
6743 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006744 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006745{
6746 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006747 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006748}
6749
Jouni Malinencf4e5942010-12-16 00:52:40 +02006750void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6751 struct net_device *netdev, const u8 *buf,
6752 size_t len, gfp_t gfp)
6753{
6754 nl80211_send_mlme_event(rdev, netdev, buf, len,
6755 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6756}
6757
6758void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6759 struct net_device *netdev, const u8 *buf,
6760 size_t len, gfp_t gfp)
6761{
6762 nl80211_send_mlme_event(rdev, netdev, buf, len,
6763 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6764}
6765
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04006766static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
6767 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02006768 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006769{
6770 struct sk_buff *msg;
6771 void *hdr;
6772
Johannes Berge6d6e342009-07-01 21:26:47 +02006773 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006774 if (!msg)
6775 return;
6776
6777 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6778 if (!hdr) {
6779 nlmsg_free(msg);
6780 return;
6781 }
6782
6783 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6784 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6785 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
6786 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6787
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006788 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03006789
Johannes Berg463d0182009-07-14 00:33:35 +02006790 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6791 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006792 return;
6793
6794 nla_put_failure:
6795 genlmsg_cancel(msg, hdr);
6796 nlmsg_free(msg);
6797}
6798
6799void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006800 struct net_device *netdev, const u8 *addr,
6801 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006802{
6803 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02006804 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006805}
6806
6807void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006808 struct net_device *netdev, const u8 *addr,
6809 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006810{
Johannes Berge6d6e342009-07-01 21:26:47 +02006811 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
6812 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006813}
6814
Samuel Ortizb23aa672009-07-01 21:26:54 +02006815void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
6816 struct net_device *netdev, const u8 *bssid,
6817 const u8 *req_ie, size_t req_ie_len,
6818 const u8 *resp_ie, size_t resp_ie_len,
6819 u16 status, gfp_t gfp)
6820{
6821 struct sk_buff *msg;
6822 void *hdr;
6823
6824 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6825 if (!msg)
6826 return;
6827
6828 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
6829 if (!hdr) {
6830 nlmsg_free(msg);
6831 return;
6832 }
6833
6834 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6835 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6836 if (bssid)
6837 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6838 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
6839 if (req_ie)
6840 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6841 if (resp_ie)
6842 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6843
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006844 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006845
Johannes Berg463d0182009-07-14 00:33:35 +02006846 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6847 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006848 return;
6849
6850 nla_put_failure:
6851 genlmsg_cancel(msg, hdr);
6852 nlmsg_free(msg);
6853
6854}
6855
6856void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
6857 struct net_device *netdev, const u8 *bssid,
6858 const u8 *req_ie, size_t req_ie_len,
6859 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
6860{
6861 struct sk_buff *msg;
6862 void *hdr;
6863
6864 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6865 if (!msg)
6866 return;
6867
6868 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
6869 if (!hdr) {
6870 nlmsg_free(msg);
6871 return;
6872 }
6873
6874 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6875 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6876 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6877 if (req_ie)
6878 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6879 if (resp_ie)
6880 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6881
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006882 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006883
Johannes Berg463d0182009-07-14 00:33:35 +02006884 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6885 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006886 return;
6887
6888 nla_put_failure:
6889 genlmsg_cancel(msg, hdr);
6890 nlmsg_free(msg);
6891
6892}
6893
6894void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
6895 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02006896 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006897{
6898 struct sk_buff *msg;
6899 void *hdr;
6900
Johannes Berg667503dd2009-07-07 03:56:11 +02006901 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006902 if (!msg)
6903 return;
6904
6905 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
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 if (from_ap && reason)
6914 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
6915 if (from_ap)
6916 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
6917 if (ie)
6918 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
6919
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006920 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006921
Johannes Berg463d0182009-07-14 00:33:35 +02006922 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6923 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006924 return;
6925
6926 nla_put_failure:
6927 genlmsg_cancel(msg, hdr);
6928 nlmsg_free(msg);
6929
6930}
6931
Johannes Berg04a773a2009-04-19 21:24:32 +02006932void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
6933 struct net_device *netdev, const u8 *bssid,
6934 gfp_t gfp)
6935{
6936 struct sk_buff *msg;
6937 void *hdr;
6938
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006940 if (!msg)
6941 return;
6942
6943 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
6944 if (!hdr) {
6945 nlmsg_free(msg);
6946 return;
6947 }
6948
6949 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6950 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6951 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6952
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006953 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02006954
Johannes Berg463d0182009-07-14 00:33:35 +02006955 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6956 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006957 return;
6958
6959 nla_put_failure:
6960 genlmsg_cancel(msg, hdr);
6961 nlmsg_free(msg);
6962}
6963
Javier Cardonac93b5e72011-04-07 15:08:34 -07006964void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
6965 struct net_device *netdev,
6966 const u8 *macaddr, const u8* ie, u8 ie_len,
6967 gfp_t gfp)
6968{
6969 struct sk_buff *msg;
6970 void *hdr;
6971
6972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6973 if (!msg)
6974 return;
6975
6976 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
6977 if (!hdr) {
6978 nlmsg_free(msg);
6979 return;
6980 }
6981
6982 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6983 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6984 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
6985 if (ie_len && ie)
6986 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
6987
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006988 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07006989
6990 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6991 nl80211_mlme_mcgrp.id, gfp);
6992 return;
6993
6994 nla_put_failure:
6995 genlmsg_cancel(msg, hdr);
6996 nlmsg_free(msg);
6997}
6998
Jouni Malinena3b8b052009-03-27 21:59:49 +02006999void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7000 struct net_device *netdev, const u8 *addr,
7001 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007002 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007003{
7004 struct sk_buff *msg;
7005 void *hdr;
7006
Johannes Berge6d6e342009-07-01 21:26:47 +02007007 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007008 if (!msg)
7009 return;
7010
7011 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7012 if (!hdr) {
7013 nlmsg_free(msg);
7014 return;
7015 }
7016
7017 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7018 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7019 if (addr)
7020 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7021 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03007022 if (key_id != -1)
7023 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007024 if (tsc)
7025 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7026
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007027 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007028
Johannes Berg463d0182009-07-14 00:33:35 +02007029 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7030 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007031 return;
7032
7033 nla_put_failure:
7034 genlmsg_cancel(msg, hdr);
7035 nlmsg_free(msg);
7036}
7037
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007038void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7039 struct ieee80211_channel *channel_before,
7040 struct ieee80211_channel *channel_after)
7041{
7042 struct sk_buff *msg;
7043 void *hdr;
7044 struct nlattr *nl_freq;
7045
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007047 if (!msg)
7048 return;
7049
7050 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7051 if (!hdr) {
7052 nlmsg_free(msg);
7053 return;
7054 }
7055
7056 /*
7057 * Since we are applying the beacon hint to a wiphy we know its
7058 * wiphy_idx is valid
7059 */
7060 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7061
7062 /* Before */
7063 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7064 if (!nl_freq)
7065 goto nla_put_failure;
7066 if (nl80211_msg_put_channel(msg, channel_before))
7067 goto nla_put_failure;
7068 nla_nest_end(msg, nl_freq);
7069
7070 /* After */
7071 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7072 if (!nl_freq)
7073 goto nla_put_failure;
7074 if (nl80211_msg_put_channel(msg, channel_after))
7075 goto nla_put_failure;
7076 nla_nest_end(msg, nl_freq);
7077
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007078 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007079
Johannes Berg463d0182009-07-14 00:33:35 +02007080 rcu_read_lock();
7081 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7082 GFP_ATOMIC);
7083 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007084
7085 return;
7086
7087nla_put_failure:
7088 genlmsg_cancel(msg, hdr);
7089 nlmsg_free(msg);
7090}
7091
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007092static void nl80211_send_remain_on_chan_event(
7093 int cmd, struct cfg80211_registered_device *rdev,
7094 struct net_device *netdev, u64 cookie,
7095 struct ieee80211_channel *chan,
7096 enum nl80211_channel_type channel_type,
7097 unsigned int duration, gfp_t gfp)
7098{
7099 struct sk_buff *msg;
7100 void *hdr;
7101
7102 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7103 if (!msg)
7104 return;
7105
7106 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7107 if (!hdr) {
7108 nlmsg_free(msg);
7109 return;
7110 }
7111
7112 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7113 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7114 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7115 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7116 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7117
7118 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7119 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7120
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007121 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007122
7123 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7124 nl80211_mlme_mcgrp.id, gfp);
7125 return;
7126
7127 nla_put_failure:
7128 genlmsg_cancel(msg, hdr);
7129 nlmsg_free(msg);
7130}
7131
7132void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7133 struct net_device *netdev, u64 cookie,
7134 struct ieee80211_channel *chan,
7135 enum nl80211_channel_type channel_type,
7136 unsigned int duration, gfp_t gfp)
7137{
7138 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7139 rdev, netdev, cookie, chan,
7140 channel_type, duration, gfp);
7141}
7142
7143void nl80211_send_remain_on_channel_cancel(
7144 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7145 u64 cookie, struct ieee80211_channel *chan,
7146 enum nl80211_channel_type channel_type, gfp_t gfp)
7147{
7148 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7149 rdev, netdev, cookie, chan,
7150 channel_type, 0, gfp);
7151}
7152
Johannes Berg98b62182009-12-23 13:15:44 +01007153void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7154 struct net_device *dev, const u8 *mac_addr,
7155 struct station_info *sinfo, gfp_t gfp)
7156{
7157 struct sk_buff *msg;
7158
7159 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7160 if (!msg)
7161 return;
7162
7163 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
7164 nlmsg_free(msg);
7165 return;
7166 }
7167
7168 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7169 nl80211_mlme_mcgrp.id, gfp);
7170}
7171
Jouni Malinenec15e682011-03-23 15:29:52 +02007172void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7173 struct net_device *dev, const u8 *mac_addr,
7174 gfp_t gfp)
7175{
7176 struct sk_buff *msg;
7177 void *hdr;
7178
7179 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7180 if (!msg)
7181 return;
7182
7183 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7184 if (!hdr) {
7185 nlmsg_free(msg);
7186 return;
7187 }
7188
7189 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7190 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7191
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007192 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007193
7194 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7195 nl80211_mlme_mcgrp.id, gfp);
7196 return;
7197
7198 nla_put_failure:
7199 genlmsg_cancel(msg, hdr);
7200 nlmsg_free(msg);
7201}
7202
Johannes Berg28946da2011-11-04 11:18:12 +01007203bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7204{
7205 struct wireless_dev *wdev = dev->ieee80211_ptr;
7206 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7207 struct sk_buff *msg;
7208 void *hdr;
7209 int err;
7210 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7211
7212 if (!nlpid)
7213 return false;
7214
7215 msg = nlmsg_new(100, gfp);
7216 if (!msg)
7217 return true;
7218
7219 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UNEXPECTED_FRAME);
7220 if (!hdr) {
7221 nlmsg_free(msg);
7222 return true;
7223 }
7224
7225 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7226 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7227 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7228
7229 err = genlmsg_end(msg, hdr);
7230 if (err < 0) {
7231 nlmsg_free(msg);
7232 return true;
7233 }
7234
7235 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7236 return true;
7237
7238 nla_put_failure:
7239 genlmsg_cancel(msg, hdr);
7240 nlmsg_free(msg);
7241 return true;
7242}
7243
Johannes Berg2e161f72010-08-12 15:38:38 +02007244int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7245 struct net_device *netdev, u32 nlpid,
7246 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007247{
7248 struct sk_buff *msg;
7249 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02007250
7251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7252 if (!msg)
7253 return -ENOMEM;
7254
Johannes Berg2e161f72010-08-12 15:38:38 +02007255 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007256 if (!hdr) {
7257 nlmsg_free(msg);
7258 return -ENOMEM;
7259 }
7260
7261 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7262 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7263 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7264 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7265
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007266 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007267
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007268 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007269
7270 nla_put_failure:
7271 genlmsg_cancel(msg, hdr);
7272 nlmsg_free(msg);
7273 return -ENOBUFS;
7274}
7275
Johannes Berg2e161f72010-08-12 15:38:38 +02007276void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7277 struct net_device *netdev, u64 cookie,
7278 const u8 *buf, size_t len, bool ack,
7279 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007280{
7281 struct sk_buff *msg;
7282 void *hdr;
7283
7284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7285 if (!msg)
7286 return;
7287
Johannes Berg2e161f72010-08-12 15:38:38 +02007288 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02007289 if (!hdr) {
7290 nlmsg_free(msg);
7291 return;
7292 }
7293
7294 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7295 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7296 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7297 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7298 if (ack)
7299 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7300
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007301 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007302
7303 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7304 return;
7305
7306 nla_put_failure:
7307 genlmsg_cancel(msg, hdr);
7308 nlmsg_free(msg);
7309}
7310
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007311void
7312nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7313 struct net_device *netdev,
7314 enum nl80211_cqm_rssi_threshold_event rssi_event,
7315 gfp_t gfp)
7316{
7317 struct sk_buff *msg;
7318 struct nlattr *pinfoattr;
7319 void *hdr;
7320
7321 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7322 if (!msg)
7323 return;
7324
7325 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7326 if (!hdr) {
7327 nlmsg_free(msg);
7328 return;
7329 }
7330
7331 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7332 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7333
7334 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7335 if (!pinfoattr)
7336 goto nla_put_failure;
7337
7338 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7339 rssi_event);
7340
7341 nla_nest_end(msg, pinfoattr);
7342
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007343 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007344
7345 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7346 nl80211_mlme_mcgrp.id, gfp);
7347 return;
7348
7349 nla_put_failure:
7350 genlmsg_cancel(msg, hdr);
7351 nlmsg_free(msg);
7352}
7353
Johannes Berge5497d72011-07-05 16:35:40 +02007354void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7355 struct net_device *netdev, const u8 *bssid,
7356 const u8 *replay_ctr, gfp_t gfp)
7357{
7358 struct sk_buff *msg;
7359 struct nlattr *rekey_attr;
7360 void *hdr;
7361
7362 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7363 if (!msg)
7364 return;
7365
7366 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7367 if (!hdr) {
7368 nlmsg_free(msg);
7369 return;
7370 }
7371
7372 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7373 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7374 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7375
7376 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7377 if (!rekey_attr)
7378 goto nla_put_failure;
7379
7380 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7381 NL80211_REPLAY_CTR_LEN, replay_ctr);
7382
7383 nla_nest_end(msg, rekey_attr);
7384
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007385 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02007386
7387 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7388 nl80211_mlme_mcgrp.id, gfp);
7389 return;
7390
7391 nla_put_failure:
7392 genlmsg_cancel(msg, hdr);
7393 nlmsg_free(msg);
7394}
7395
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007396void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7397 struct net_device *netdev, int index,
7398 const u8 *bssid, bool preauth, gfp_t gfp)
7399{
7400 struct sk_buff *msg;
7401 struct nlattr *attr;
7402 void *hdr;
7403
7404 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7405 if (!msg)
7406 return;
7407
7408 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7409 if (!hdr) {
7410 nlmsg_free(msg);
7411 return;
7412 }
7413
7414 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7415 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7416
7417 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7418 if (!attr)
7419 goto nla_put_failure;
7420
7421 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7422 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7423 if (preauth)
7424 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7425
7426 nla_nest_end(msg, attr);
7427
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007428 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007429
7430 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7431 nl80211_mlme_mcgrp.id, gfp);
7432 return;
7433
7434 nla_put_failure:
7435 genlmsg_cancel(msg, hdr);
7436 nlmsg_free(msg);
7437}
7438
Johannes Bergc063dbf2010-11-24 08:10:05 +01007439void
7440nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7441 struct net_device *netdev, const u8 *peer,
7442 u32 num_packets, gfp_t gfp)
7443{
7444 struct sk_buff *msg;
7445 struct nlattr *pinfoattr;
7446 void *hdr;
7447
7448 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7449 if (!msg)
7450 return;
7451
7452 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7453 if (!hdr) {
7454 nlmsg_free(msg);
7455 return;
7456 }
7457
7458 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7459 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7460 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7461
7462 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7463 if (!pinfoattr)
7464 goto nla_put_failure;
7465
7466 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7467
7468 nla_nest_end(msg, pinfoattr);
7469
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007470 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01007471
7472 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7473 nl80211_mlme_mcgrp.id, gfp);
7474 return;
7475
7476 nla_put_failure:
7477 genlmsg_cancel(msg, hdr);
7478 nlmsg_free(msg);
7479}
7480
Jouni Malinen026331c2010-02-15 12:53:10 +02007481static int nl80211_netlink_notify(struct notifier_block * nb,
7482 unsigned long state,
7483 void *_notify)
7484{
7485 struct netlink_notify *notify = _notify;
7486 struct cfg80211_registered_device *rdev;
7487 struct wireless_dev *wdev;
7488
7489 if (state != NETLINK_URELEASE)
7490 return NOTIFY_DONE;
7491
7492 rcu_read_lock();
7493
7494 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
7495 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02007496 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007497
7498 rcu_read_unlock();
7499
7500 return NOTIFY_DONE;
7501}
7502
7503static struct notifier_block nl80211_netlink_notifier = {
7504 .notifier_call = nl80211_netlink_notify,
7505};
7506
Johannes Berg55682962007-09-20 13:09:35 -04007507/* initialisation/exit functions */
7508
7509int nl80211_init(void)
7510{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007511 int err;
Johannes Berg55682962007-09-20 13:09:35 -04007512
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007513 err = genl_register_family_with_ops(&nl80211_fam,
7514 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04007515 if (err)
7516 return err;
7517
Johannes Berg55682962007-09-20 13:09:35 -04007518 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7519 if (err)
7520 goto err_out;
7521
Johannes Berg2a519312009-02-10 21:25:55 +01007522 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7523 if (err)
7524 goto err_out;
7525
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007526 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7527 if (err)
7528 goto err_out;
7529
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007530 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7531 if (err)
7532 goto err_out;
7533
Johannes Bergaff89a92009-07-01 21:26:51 +02007534#ifdef CONFIG_NL80211_TESTMODE
7535 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7536 if (err)
7537 goto err_out;
7538#endif
7539
Jouni Malinen026331c2010-02-15 12:53:10 +02007540 err = netlink_register_notifier(&nl80211_netlink_notifier);
7541 if (err)
7542 goto err_out;
7543
Johannes Berg55682962007-09-20 13:09:35 -04007544 return 0;
7545 err_out:
7546 genl_unregister_family(&nl80211_fam);
7547 return err;
7548}
7549
7550void nl80211_exit(void)
7551{
Jouni Malinen026331c2010-02-15 12:53:10 +02007552 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04007553 genl_unregister_family(&nl80211_fam);
7554}