blob: 9910c3cb9a851be49187dffeed4bf4a75b310ded [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 Berg55682962007-09-20 13:09:35 -04001010 return genlmsg_end(msg, hdr);
1011
1012 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001013 genlmsg_cancel(msg, hdr);
1014 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001015}
1016
1017static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1018{
1019 int idx = 0;
1020 int start = cb->args[0];
1021 struct cfg80211_registered_device *dev;
1022
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001023 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001024 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001025 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1026 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001027 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001028 continue;
1029 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1030 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001031 dev) < 0) {
1032 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001033 break;
Julius Volzb4637272008-07-08 14:02:19 +02001034 }
Johannes Berg55682962007-09-20 13:09:35 -04001035 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001036 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001037
1038 cb->args[0] = idx;
1039
1040 return skb->len;
1041}
1042
1043static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1044{
1045 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001046 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001047
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001049 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001050 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001051
Johannes Berg4c476992010-10-04 21:36:35 +02001052 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1053 nlmsg_free(msg);
1054 return -ENOBUFS;
1055 }
Johannes Berg55682962007-09-20 13:09:35 -04001056
Johannes Berg134e6372009-07-10 09:51:34 +00001057 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001058}
1059
Jouni Malinen31888482008-10-30 16:59:24 +02001060static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1061 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1062 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1063 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1064 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1065 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1066};
1067
1068static int parse_txq_params(struct nlattr *tb[],
1069 struct ieee80211_txq_params *txq_params)
1070{
1071 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1072 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1073 !tb[NL80211_TXQ_ATTR_AIFS])
1074 return -EINVAL;
1075
1076 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1077 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1078 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1079 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1080 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1081
1082 return 0;
1083}
1084
Johannes Bergf444de02010-05-05 15:25:02 +02001085static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1086{
1087 /*
1088 * You can only set the channel explicitly for AP, mesh
1089 * and WDS type interfaces; all others have their channel
1090 * managed via their respective "establish a connection"
1091 * command (connect, join, ...)
1092 *
1093 * Monitors are special as they are normally slaved to
1094 * whatever else is going on, so they behave as though
1095 * you tried setting the wiphy channel itself.
1096 */
1097 return !wdev ||
1098 wdev->iftype == NL80211_IFTYPE_AP ||
1099 wdev->iftype == NL80211_IFTYPE_WDS ||
1100 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001101 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1102 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001103}
1104
1105static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1106 struct wireless_dev *wdev,
1107 struct genl_info *info)
1108{
1109 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1110 u32 freq;
1111 int result;
1112
1113 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1114 return -EINVAL;
1115
1116 if (!nl80211_can_set_dev_channel(wdev))
1117 return -EOPNOTSUPP;
1118
1119 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1120 channel_type = nla_get_u32(info->attrs[
1121 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1122 if (channel_type != NL80211_CHAN_NO_HT &&
1123 channel_type != NL80211_CHAN_HT20 &&
1124 channel_type != NL80211_CHAN_HT40PLUS &&
1125 channel_type != NL80211_CHAN_HT40MINUS)
1126 return -EINVAL;
1127 }
1128
1129 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1130
1131 mutex_lock(&rdev->devlist_mtx);
1132 if (wdev) {
1133 wdev_lock(wdev);
1134 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1135 wdev_unlock(wdev);
1136 } else {
1137 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1138 }
1139 mutex_unlock(&rdev->devlist_mtx);
1140
1141 return result;
1142}
1143
1144static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1145{
Johannes Berg4c476992010-10-04 21:36:35 +02001146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1147 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001148
Johannes Berg4c476992010-10-04 21:36:35 +02001149 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001150}
1151
Bill Jordane8347eb2010-10-01 13:54:28 -04001152static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1153{
Johannes Berg43b19952010-10-07 13:10:30 +02001154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1155 struct net_device *dev = info->user_ptr[1];
1156 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001157 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001158
1159 if (!info->attrs[NL80211_ATTR_MAC])
1160 return -EINVAL;
1161
Johannes Berg43b19952010-10-07 13:10:30 +02001162 if (netif_running(dev))
1163 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001164
Johannes Berg43b19952010-10-07 13:10:30 +02001165 if (!rdev->ops->set_wds_peer)
1166 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001167
Johannes Berg43b19952010-10-07 13:10:30 +02001168 if (wdev->iftype != NL80211_IFTYPE_WDS)
1169 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001170
1171 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001172 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001173}
1174
1175
Johannes Berg55682962007-09-20 13:09:35 -04001176static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1177{
1178 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001179 struct net_device *netdev = NULL;
1180 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001181 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001182 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001183 u32 changed;
1184 u8 retry_short = 0, retry_long = 0;
1185 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001186 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001187
Johannes Bergf444de02010-05-05 15:25:02 +02001188 /*
1189 * Try to find the wiphy and netdev. Normally this
1190 * function shouldn't need the netdev, but this is
1191 * done for backward compatibility -- previously
1192 * setting the channel was done per wiphy, but now
1193 * it is per netdev. Previous userland like hostapd
1194 * also passed a netdev to set_wiphy, so that it is
1195 * possible to let that go to the right netdev!
1196 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001197 mutex_lock(&cfg80211_mutex);
1198
Johannes Bergf444de02010-05-05 15:25:02 +02001199 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1200 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1201
1202 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1203 if (netdev && netdev->ieee80211_ptr) {
1204 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1205 mutex_lock(&rdev->mtx);
1206 } else
1207 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001208 }
1209
Johannes Bergf444de02010-05-05 15:25:02 +02001210 if (!netdev) {
1211 rdev = __cfg80211_rdev_from_info(info);
1212 if (IS_ERR(rdev)) {
1213 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001214 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001215 }
1216 wdev = NULL;
1217 netdev = NULL;
1218 result = 0;
1219
1220 mutex_lock(&rdev->mtx);
1221 } else if (netif_running(netdev) &&
1222 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1223 wdev = netdev->ieee80211_ptr;
1224 else
1225 wdev = NULL;
1226
1227 /*
1228 * end workaround code, by now the rdev is available
1229 * and locked, and wdev may or may not be NULL.
1230 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001231
1232 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001233 result = cfg80211_dev_rename(
1234 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001235
1236 mutex_unlock(&cfg80211_mutex);
1237
1238 if (result)
1239 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001240
Jouni Malinen31888482008-10-30 16:59:24 +02001241 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1242 struct ieee80211_txq_params txq_params;
1243 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1244
1245 if (!rdev->ops->set_txq_params) {
1246 result = -EOPNOTSUPP;
1247 goto bad_res;
1248 }
1249
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001250 if (!netdev) {
1251 result = -EINVAL;
1252 goto bad_res;
1253 }
1254
Johannes Berg133a3ff2011-11-03 14:50:13 +01001255 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1256 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1257 result = -EINVAL;
1258 goto bad_res;
1259 }
1260
Jouni Malinen31888482008-10-30 16:59:24 +02001261 nla_for_each_nested(nl_txq_params,
1262 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1263 rem_txq_params) {
1264 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1265 nla_data(nl_txq_params),
1266 nla_len(nl_txq_params),
1267 txq_params_policy);
1268 result = parse_txq_params(tb, &txq_params);
1269 if (result)
1270 goto bad_res;
1271
1272 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001273 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001274 &txq_params);
1275 if (result)
1276 goto bad_res;
1277 }
1278 }
1279
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001280 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001281 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001282 if (result)
1283 goto bad_res;
1284 }
1285
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001286 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1287 enum nl80211_tx_power_setting type;
1288 int idx, mbm = 0;
1289
1290 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001291 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001292 goto bad_res;
1293 }
1294
1295 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1296 type = nla_get_u32(info->attrs[idx]);
1297
1298 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1299 (type != NL80211_TX_POWER_AUTOMATIC)) {
1300 result = -EINVAL;
1301 goto bad_res;
1302 }
1303
1304 if (type != NL80211_TX_POWER_AUTOMATIC) {
1305 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1306 mbm = nla_get_u32(info->attrs[idx]);
1307 }
1308
1309 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1310 if (result)
1311 goto bad_res;
1312 }
1313
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001314 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1315 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1316 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001317 if ((!rdev->wiphy.available_antennas_tx &&
1318 !rdev->wiphy.available_antennas_rx) ||
1319 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001320 result = -EOPNOTSUPP;
1321 goto bad_res;
1322 }
1323
1324 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1325 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1326
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001327 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001328 * available antenna masks, except for the "all" mask */
1329 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1330 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001331 result = -EINVAL;
1332 goto bad_res;
1333 }
1334
Bruno Randolf7f531e02010-12-16 11:30:22 +09001335 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1336 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001337
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001338 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1339 if (result)
1340 goto bad_res;
1341 }
1342
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001343 changed = 0;
1344
1345 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1346 retry_short = nla_get_u8(
1347 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1348 if (retry_short == 0) {
1349 result = -EINVAL;
1350 goto bad_res;
1351 }
1352 changed |= WIPHY_PARAM_RETRY_SHORT;
1353 }
1354
1355 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1356 retry_long = nla_get_u8(
1357 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1358 if (retry_long == 0) {
1359 result = -EINVAL;
1360 goto bad_res;
1361 }
1362 changed |= WIPHY_PARAM_RETRY_LONG;
1363 }
1364
1365 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1366 frag_threshold = nla_get_u32(
1367 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1368 if (frag_threshold < 256) {
1369 result = -EINVAL;
1370 goto bad_res;
1371 }
1372 if (frag_threshold != (u32) -1) {
1373 /*
1374 * Fragments (apart from the last one) are required to
1375 * have even length. Make the fragmentation code
1376 * simpler by stripping LSB should someone try to use
1377 * odd threshold value.
1378 */
1379 frag_threshold &= ~0x1;
1380 }
1381 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1382 }
1383
1384 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1385 rts_threshold = nla_get_u32(
1386 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1387 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1388 }
1389
Lukáš Turek81077e82009-12-21 22:50:47 +01001390 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1391 coverage_class = nla_get_u8(
1392 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1393 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1394 }
1395
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001396 if (changed) {
1397 u8 old_retry_short, old_retry_long;
1398 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001399 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001400
1401 if (!rdev->ops->set_wiphy_params) {
1402 result = -EOPNOTSUPP;
1403 goto bad_res;
1404 }
1405
1406 old_retry_short = rdev->wiphy.retry_short;
1407 old_retry_long = rdev->wiphy.retry_long;
1408 old_frag_threshold = rdev->wiphy.frag_threshold;
1409 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001410 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001411
1412 if (changed & WIPHY_PARAM_RETRY_SHORT)
1413 rdev->wiphy.retry_short = retry_short;
1414 if (changed & WIPHY_PARAM_RETRY_LONG)
1415 rdev->wiphy.retry_long = retry_long;
1416 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1417 rdev->wiphy.frag_threshold = frag_threshold;
1418 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1419 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001420 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1421 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001422
1423 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1424 if (result) {
1425 rdev->wiphy.retry_short = old_retry_short;
1426 rdev->wiphy.retry_long = old_retry_long;
1427 rdev->wiphy.frag_threshold = old_frag_threshold;
1428 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001429 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001430 }
1431 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001432
Johannes Berg306d6112008-12-08 12:39:04 +01001433 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001434 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001435 if (netdev)
1436 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001437 return result;
1438}
1439
1440
1441static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001442 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001443 struct net_device *dev)
1444{
1445 void *hdr;
1446
1447 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1448 if (!hdr)
1449 return -1;
1450
1451 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001452 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001453 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001454 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001455
1456 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1457 rdev->devlist_generation ^
1458 (cfg80211_rdev_list_generation << 2));
1459
Johannes Berg55682962007-09-20 13:09:35 -04001460 return genlmsg_end(msg, hdr);
1461
1462 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001463 genlmsg_cancel(msg, hdr);
1464 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001465}
1466
1467static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1468{
1469 int wp_idx = 0;
1470 int if_idx = 0;
1471 int wp_start = cb->args[0];
1472 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001473 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001474 struct wireless_dev *wdev;
1475
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001476 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001477 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1478 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001479 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001480 if (wp_idx < wp_start) {
1481 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001482 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001483 }
Johannes Berg55682962007-09-20 13:09:35 -04001484 if_idx = 0;
1485
Johannes Bergf5ea9122009-08-07 16:17:38 +02001486 mutex_lock(&rdev->devlist_mtx);
1487 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001488 if (if_idx < if_start) {
1489 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001490 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001491 }
Johannes Berg55682962007-09-20 13:09:35 -04001492 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1493 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001494 rdev, wdev->netdev) < 0) {
1495 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001496 goto out;
1497 }
1498 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001499 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001500 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001501
1502 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001503 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001504 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001505 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001506
1507 cb->args[0] = wp_idx;
1508 cb->args[1] = if_idx;
1509
1510 return skb->len;
1511}
1512
1513static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1514{
1515 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001516 struct cfg80211_registered_device *dev = info->user_ptr[0];
1517 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001518
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001520 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001521 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001522
Johannes Bergd7264052009-04-19 16:23:20 +02001523 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001524 dev, netdev) < 0) {
1525 nlmsg_free(msg);
1526 return -ENOBUFS;
1527 }
Johannes Berg55682962007-09-20 13:09:35 -04001528
Johannes Berg134e6372009-07-10 09:51:34 +00001529 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001530}
1531
Michael Wu66f7ac52008-01-31 19:48:22 +01001532static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1533 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1534 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1535 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1536 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1537 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1538};
1539
1540static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1541{
1542 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1543 int flag;
1544
1545 *mntrflags = 0;
1546
1547 if (!nla)
1548 return -EINVAL;
1549
1550 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1551 nla, mntr_flags_policy))
1552 return -EINVAL;
1553
1554 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1555 if (flags[flag])
1556 *mntrflags |= (1<<flag);
1557
1558 return 0;
1559}
1560
Johannes Berg9bc383d2009-11-19 11:55:19 +01001561static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001562 struct net_device *netdev, u8 use_4addr,
1563 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001564{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001565 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001566 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001567 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001568 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001569 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001570
1571 switch (iftype) {
1572 case NL80211_IFTYPE_AP_VLAN:
1573 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1574 return 0;
1575 break;
1576 case NL80211_IFTYPE_STATION:
1577 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1578 return 0;
1579 break;
1580 default:
1581 break;
1582 }
1583
1584 return -EOPNOTSUPP;
1585}
1586
Johannes Berg55682962007-09-20 13:09:35 -04001587static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1588{
Johannes Berg4c476992010-10-04 21:36:35 +02001589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001590 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001591 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001592 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001593 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001594 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001595 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001596
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001597 memset(&params, 0, sizeof(params));
1598
Johannes Berg04a773a2009-04-19 21:24:32 +02001599 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001600
Johannes Berg723b0382008-09-16 20:22:09 +02001601 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001602 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001603 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001604 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001605 if (ntype > NL80211_IFTYPE_MAX)
1606 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001607 }
1608
Johannes Berg92ffe052008-09-16 20:39:36 +02001609 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001610 struct wireless_dev *wdev = dev->ieee80211_ptr;
1611
Johannes Berg4c476992010-10-04 21:36:35 +02001612 if (ntype != NL80211_IFTYPE_MESH_POINT)
1613 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001614 if (netif_running(dev))
1615 return -EBUSY;
1616
1617 wdev_lock(wdev);
1618 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1619 IEEE80211_MAX_MESH_ID_LEN);
1620 wdev->mesh_id_up_len =
1621 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1622 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1623 wdev->mesh_id_up_len);
1624 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001625 }
1626
Felix Fietkau8b787642009-11-10 18:53:10 +01001627 if (info->attrs[NL80211_ATTR_4ADDR]) {
1628 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1629 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001630 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001631 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001632 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001633 } else {
1634 params.use_4addr = -1;
1635 }
1636
Johannes Berg92ffe052008-09-16 20:39:36 +02001637 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001638 if (ntype != NL80211_IFTYPE_MONITOR)
1639 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001640 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1641 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001642 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001643 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001644
1645 flags = &_flags;
1646 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001647 }
Johannes Berg3b858752009-03-12 09:55:09 +01001648
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001649 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001650 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001651 else
1652 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001653
Johannes Berg9bc383d2009-11-19 11:55:19 +01001654 if (!err && params.use_4addr != -1)
1655 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1656
Johannes Berg55682962007-09-20 13:09:35 -04001657 return err;
1658}
1659
1660static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1661{
Johannes Berg4c476992010-10-04 21:36:35 +02001662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001663 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001664 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001665 int err;
1666 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001667 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001668
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001669 memset(&params, 0, sizeof(params));
1670
Johannes Berg55682962007-09-20 13:09:35 -04001671 if (!info->attrs[NL80211_ATTR_IFNAME])
1672 return -EINVAL;
1673
1674 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1675 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1676 if (type > NL80211_IFTYPE_MAX)
1677 return -EINVAL;
1678 }
1679
Johannes Berg79c97e92009-07-07 03:56:12 +02001680 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001681 !(rdev->wiphy.interface_modes & (1 << type)))
1682 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001683
Johannes Berg9bc383d2009-11-19 11:55:19 +01001684 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001685 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001686 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001687 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001688 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001689 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001690
Michael Wu66f7ac52008-01-31 19:48:22 +01001691 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1692 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1693 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001694 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001695 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001696 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001697 if (IS_ERR(dev))
1698 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001699
Johannes Berg29cbe682010-12-03 09:20:44 +01001700 if (type == NL80211_IFTYPE_MESH_POINT &&
1701 info->attrs[NL80211_ATTR_MESH_ID]) {
1702 struct wireless_dev *wdev = dev->ieee80211_ptr;
1703
1704 wdev_lock(wdev);
1705 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1706 IEEE80211_MAX_MESH_ID_LEN);
1707 wdev->mesh_id_up_len =
1708 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1709 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1710 wdev->mesh_id_up_len);
1711 wdev_unlock(wdev);
1712 }
1713
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001714 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001715}
1716
1717static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1718{
Johannes Berg4c476992010-10-04 21:36:35 +02001719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1720 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001721
Johannes Berg4c476992010-10-04 21:36:35 +02001722 if (!rdev->ops->del_virtual_intf)
1723 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001724
Johannes Berg4c476992010-10-04 21:36:35 +02001725 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001726}
1727
Johannes Berg41ade002007-12-19 02:03:29 +01001728struct get_key_cookie {
1729 struct sk_buff *msg;
1730 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001731 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001732};
1733
1734static void get_key_callback(void *c, struct key_params *params)
1735{
Johannes Bergb9454e82009-07-08 13:29:08 +02001736 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001737 struct get_key_cookie *cookie = c;
1738
1739 if (params->key)
1740 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1741 params->key_len, params->key);
1742
1743 if (params->seq)
1744 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1745 params->seq_len, params->seq);
1746
1747 if (params->cipher)
1748 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1749 params->cipher);
1750
Johannes Bergb9454e82009-07-08 13:29:08 +02001751 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1752 if (!key)
1753 goto nla_put_failure;
1754
1755 if (params->key)
1756 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1757 params->key_len, params->key);
1758
1759 if (params->seq)
1760 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1761 params->seq_len, params->seq);
1762
1763 if (params->cipher)
1764 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1765 params->cipher);
1766
1767 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1768
1769 nla_nest_end(cookie->msg, key);
1770
Johannes Berg41ade002007-12-19 02:03:29 +01001771 return;
1772 nla_put_failure:
1773 cookie->error = 1;
1774}
1775
1776static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1777{
Johannes Berg4c476992010-10-04 21:36:35 +02001778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001779 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001780 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001781 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001782 const u8 *mac_addr = NULL;
1783 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001784 struct get_key_cookie cookie = {
1785 .error = 0,
1786 };
1787 void *hdr;
1788 struct sk_buff *msg;
1789
1790 if (info->attrs[NL80211_ATTR_KEY_IDX])
1791 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1792
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001793 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001794 return -EINVAL;
1795
1796 if (info->attrs[NL80211_ATTR_MAC])
1797 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1798
Johannes Berge31b8212010-10-05 19:39:30 +02001799 pairwise = !!mac_addr;
1800 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1801 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1802 if (kt >= NUM_NL80211_KEYTYPES)
1803 return -EINVAL;
1804 if (kt != NL80211_KEYTYPE_GROUP &&
1805 kt != NL80211_KEYTYPE_PAIRWISE)
1806 return -EINVAL;
1807 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1808 }
1809
Johannes Berg4c476992010-10-04 21:36:35 +02001810 if (!rdev->ops->get_key)
1811 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001812
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001813 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001814 if (!msg)
1815 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001816
1817 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1818 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001819 if (IS_ERR(hdr))
1820 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001821
1822 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001823 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001824
1825 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1826 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1827 if (mac_addr)
1828 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1829
Johannes Berge31b8212010-10-05 19:39:30 +02001830 if (pairwise && mac_addr &&
1831 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1832 return -ENOENT;
1833
1834 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1835 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001836
1837 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001838 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001839
1840 if (cookie.error)
1841 goto nla_put_failure;
1842
1843 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001844 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001845
1846 nla_put_failure:
1847 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001848 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001849 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001850 return err;
1851}
1852
1853static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1854{
Johannes Berg4c476992010-10-04 21:36:35 +02001855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001856 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001857 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001858 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001859
Johannes Bergb9454e82009-07-08 13:29:08 +02001860 err = nl80211_parse_key(info, &key);
1861 if (err)
1862 return err;
1863
1864 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001865 return -EINVAL;
1866
Johannes Bergb9454e82009-07-08 13:29:08 +02001867 /* only support setting default key */
1868 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001869 return -EINVAL;
1870
Johannes Bergfffd0932009-07-08 14:22:54 +02001871 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001872
1873 if (key.def) {
1874 if (!rdev->ops->set_default_key) {
1875 err = -EOPNOTSUPP;
1876 goto out;
1877 }
1878
1879 err = nl80211_key_allowed(dev->ieee80211_ptr);
1880 if (err)
1881 goto out;
1882
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001883 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1884 key.def_uni, key.def_multi);
1885
1886 if (err)
1887 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001888
Johannes Berg3d23e342009-09-29 23:27:28 +02001889#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001890 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001891#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001892 } else {
1893 if (key.def_uni || !key.def_multi) {
1894 err = -EINVAL;
1895 goto out;
1896 }
1897
1898 if (!rdev->ops->set_default_mgmt_key) {
1899 err = -EOPNOTSUPP;
1900 goto out;
1901 }
1902
1903 err = nl80211_key_allowed(dev->ieee80211_ptr);
1904 if (err)
1905 goto out;
1906
1907 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1908 dev, key.idx);
1909 if (err)
1910 goto out;
1911
1912#ifdef CONFIG_CFG80211_WEXT
1913 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1914#endif
1915 }
1916
1917 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001918 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001919
Johannes Berg41ade002007-12-19 02:03:29 +01001920 return err;
1921}
1922
1923static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1924{
Johannes Berg4c476992010-10-04 21:36:35 +02001925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001926 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001927 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001928 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001929 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001930
Johannes Bergb9454e82009-07-08 13:29:08 +02001931 err = nl80211_parse_key(info, &key);
1932 if (err)
1933 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001934
Johannes Bergb9454e82009-07-08 13:29:08 +02001935 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001936 return -EINVAL;
1937
Johannes Berg41ade002007-12-19 02:03:29 +01001938 if (info->attrs[NL80211_ATTR_MAC])
1939 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1940
Johannes Berge31b8212010-10-05 19:39:30 +02001941 if (key.type == -1) {
1942 if (mac_addr)
1943 key.type = NL80211_KEYTYPE_PAIRWISE;
1944 else
1945 key.type = NL80211_KEYTYPE_GROUP;
1946 }
1947
1948 /* for now */
1949 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1950 key.type != NL80211_KEYTYPE_GROUP)
1951 return -EINVAL;
1952
Johannes Berg4c476992010-10-04 21:36:35 +02001953 if (!rdev->ops->add_key)
1954 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001955
Johannes Berge31b8212010-10-05 19:39:30 +02001956 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
1957 key.type == NL80211_KEYTYPE_PAIRWISE,
1958 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02001959 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001960
1961 wdev_lock(dev->ieee80211_ptr);
1962 err = nl80211_key_allowed(dev->ieee80211_ptr);
1963 if (!err)
1964 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02001965 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02001966 mac_addr, &key.p);
1967 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001968
Johannes Berg41ade002007-12-19 02:03:29 +01001969 return err;
1970}
1971
1972static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1973{
Johannes Berg4c476992010-10-04 21:36:35 +02001974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001975 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001976 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001977 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02001978 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001979
Johannes Bergb9454e82009-07-08 13:29:08 +02001980 err = nl80211_parse_key(info, &key);
1981 if (err)
1982 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001983
1984 if (info->attrs[NL80211_ATTR_MAC])
1985 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1986
Johannes Berge31b8212010-10-05 19:39:30 +02001987 if (key.type == -1) {
1988 if (mac_addr)
1989 key.type = NL80211_KEYTYPE_PAIRWISE;
1990 else
1991 key.type = NL80211_KEYTYPE_GROUP;
1992 }
1993
1994 /* for now */
1995 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
1996 key.type != NL80211_KEYTYPE_GROUP)
1997 return -EINVAL;
1998
Johannes Berg4c476992010-10-04 21:36:35 +02001999 if (!rdev->ops->del_key)
2000 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002001
Johannes Bergfffd0932009-07-08 14:22:54 +02002002 wdev_lock(dev->ieee80211_ptr);
2003 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002004
2005 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2006 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2007 err = -ENOENT;
2008
Johannes Bergfffd0932009-07-08 14:22:54 +02002009 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002010 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2011 key.type == NL80211_KEYTYPE_PAIRWISE,
2012 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002013
Johannes Berg3d23e342009-09-29 23:27:28 +02002014#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002015 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002016 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002017 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002018 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002019 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2020 }
2021#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002022 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002023
Johannes Berg41ade002007-12-19 02:03:29 +01002024 return err;
2025}
2026
Johannes Berged1b6cc2007-12-19 02:03:32 +01002027static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
2028{
2029 int (*call)(struct wiphy *wiphy, struct net_device *dev,
2030 struct beacon_parameters *info);
Johannes Berg4c476992010-10-04 21:36:35 +02002031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2032 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002033 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002034 struct beacon_parameters params;
Johannes Berg56d18932011-05-09 18:41:15 +02002035 int haveinfo = 0, err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002036
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002037 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2038 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2039 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2040 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002041 return -EINVAL;
2042
Johannes Berg074ac8d2010-09-16 14:58:22 +02002043 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002044 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2045 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002046
Johannes Berg56d18932011-05-09 18:41:15 +02002047 memset(&params, 0, sizeof(params));
2048
Johannes Berged1b6cc2007-12-19 02:03:32 +01002049 switch (info->genlhdr->cmd) {
2050 case NL80211_CMD_NEW_BEACON:
2051 /* these are required for NEW_BEACON */
2052 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2053 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
Johannes Berg4c476992010-10-04 21:36:35 +02002054 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2055 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002056
Johannes Berg56d18932011-05-09 18:41:15 +02002057 params.interval =
2058 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2059 params.dtim_period =
2060 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2061
2062 err = cfg80211_validate_beacon_int(rdev, params.interval);
2063 if (err)
2064 return err;
2065
Jouni Malinen32e9de82011-08-10 23:53:31 +03002066 /*
2067 * In theory, some of these attributes could be required for
2068 * NEW_BEACON, but since they were not used when the command was
2069 * originally added, keep them optional for old user space
2070 * programs to work with drivers that do not need the additional
2071 * information.
2072 */
2073 if (info->attrs[NL80211_ATTR_SSID]) {
2074 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2075 params.ssid_len =
2076 nla_len(info->attrs[NL80211_ATTR_SSID]);
2077 if (params.ssid_len == 0 ||
2078 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2079 return -EINVAL;
2080 }
2081
2082 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2083 params.hidden_ssid = nla_get_u32(
2084 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2085 if (params.hidden_ssid !=
2086 NL80211_HIDDEN_SSID_NOT_IN_USE &&
2087 params.hidden_ssid !=
2088 NL80211_HIDDEN_SSID_ZERO_LEN &&
2089 params.hidden_ssid !=
2090 NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2091 return -EINVAL;
2092 }
2093
Jouni Malinen5fb628e2011-08-10 23:54:35 +03002094 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2095
2096 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2097 params.auth_type = nla_get_u32(
2098 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2099 if (!nl80211_valid_auth_type(params.auth_type))
2100 return -EINVAL;
2101 } else
2102 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2103
2104 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2105 NL80211_MAX_NR_CIPHER_SUITES);
2106 if (err)
2107 return err;
2108
Johannes Berg79c97e92009-07-07 03:56:12 +02002109 call = rdev->ops->add_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002110 break;
2111 case NL80211_CMD_SET_BEACON:
Johannes Berg79c97e92009-07-07 03:56:12 +02002112 call = rdev->ops->set_beacon;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002113 break;
2114 default:
2115 WARN_ON(1);
Johannes Berg4c476992010-10-04 21:36:35 +02002116 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002117 }
2118
Johannes Berg4c476992010-10-04 21:36:35 +02002119 if (!call)
2120 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002121
Johannes Berged1b6cc2007-12-19 02:03:32 +01002122 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2123 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2124 params.head_len =
2125 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2126 haveinfo = 1;
2127 }
2128
2129 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2130 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2131 params.tail_len =
2132 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2133 haveinfo = 1;
2134 }
2135
Johannes Berg4c476992010-10-04 21:36:35 +02002136 if (!haveinfo)
2137 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002138
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002139 if (info->attrs[NL80211_ATTR_IE]) {
2140 params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2141 params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2142 }
2143
2144 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2145 params.proberesp_ies =
2146 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2147 params.proberesp_ies_len =
2148 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2149 }
2150
2151 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2152 params.assocresp_ies =
2153 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2154 params.assocresp_ies_len =
2155 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2156 }
2157
Johannes Berg56d18932011-05-09 18:41:15 +02002158 err = call(&rdev->wiphy, dev, &params);
2159 if (!err && params.interval)
2160 wdev->beacon_interval = params.interval;
2161 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002162}
2163
2164static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
2165{
Johannes Berg4c476992010-10-04 21:36:35 +02002166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2167 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002168 struct wireless_dev *wdev = dev->ieee80211_ptr;
2169 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002170
Johannes Berg4c476992010-10-04 21:36:35 +02002171 if (!rdev->ops->del_beacon)
2172 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002173
Johannes Berg074ac8d2010-09-16 14:58:22 +02002174 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002175 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2176 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002177
Johannes Berg56d18932011-05-09 18:41:15 +02002178 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
2179 if (!err)
2180 wdev->beacon_interval = 0;
2181 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002182}
2183
Johannes Berg5727ef12007-12-19 02:03:34 +01002184static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2185 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2186 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2187 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002188 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002189 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002190};
2191
Johannes Bergeccb8e82009-05-11 21:57:56 +03002192static int parse_station_flags(struct genl_info *info,
2193 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002194{
2195 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002196 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002197 int flag;
2198
Johannes Bergeccb8e82009-05-11 21:57:56 +03002199 /*
2200 * Try parsing the new attribute first so userspace
2201 * can specify both for older kernels.
2202 */
2203 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2204 if (nla) {
2205 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002206
Johannes Bergeccb8e82009-05-11 21:57:56 +03002207 sta_flags = nla_data(nla);
2208 params->sta_flags_mask = sta_flags->mask;
2209 params->sta_flags_set = sta_flags->set;
2210 if ((params->sta_flags_mask |
2211 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2212 return -EINVAL;
2213 return 0;
2214 }
2215
2216 /* if present, parse the old attribute */
2217
2218 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002219 if (!nla)
2220 return 0;
2221
2222 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2223 nla, sta_flags_policy))
2224 return -EINVAL;
2225
Johannes Bergeccb8e82009-05-11 21:57:56 +03002226 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1;
2227 params->sta_flags_mask &= ~1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002228
2229 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2230 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002231 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002232
2233 return 0;
2234}
2235
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002236static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2237 int attr)
2238{
2239 struct nlattr *rate;
2240 u16 bitrate;
2241
2242 rate = nla_nest_start(msg, attr);
2243 if (!rate)
2244 goto nla_put_failure;
2245
2246 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2247 bitrate = cfg80211_calculate_bitrate(info);
2248 if (bitrate > 0)
2249 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2250
2251 if (info->flags & RATE_INFO_FLAGS_MCS)
2252 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2253 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2254 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2255 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2256 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2257
2258 nla_nest_end(msg, rate);
2259 return true;
2260
2261nla_put_failure:
2262 return false;
2263}
2264
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002265static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2266 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002267 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002268{
2269 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002270 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002271
2272 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2273 if (!hdr)
2274 return -1;
2275
2276 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2277 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2278
Johannes Bergf5ea9122009-08-07 16:17:38 +02002279 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2280
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002281 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2282 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002283 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302284 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2285 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2286 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002287 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2288 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2289 sinfo->inactive_time);
2290 if (sinfo->filled & STATION_INFO_RX_BYTES)
2291 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2292 sinfo->rx_bytes);
2293 if (sinfo->filled & STATION_INFO_TX_BYTES)
2294 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2295 sinfo->tx_bytes);
2296 if (sinfo->filled & STATION_INFO_LLID)
2297 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2298 sinfo->llid);
2299 if (sinfo->filled & STATION_INFO_PLID)
2300 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2301 sinfo->plid);
2302 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2303 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2304 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002305 if (sinfo->filled & STATION_INFO_SIGNAL)
2306 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2307 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002308 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2309 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2310 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002311 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002312 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2313 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002314 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002315 }
2316 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2317 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2318 NL80211_STA_INFO_RX_BITRATE))
2319 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002320 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002321 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2322 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2323 sinfo->rx_packets);
2324 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2325 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2326 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002327 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2328 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2329 sinfo->tx_retries);
2330 if (sinfo->filled & STATION_INFO_TX_FAILED)
2331 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2332 sinfo->tx_failed);
Paul Stewartf4263c92011-03-31 09:25:41 -07002333 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2334 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2335 if (!bss_param)
2336 goto nla_put_failure;
2337
2338 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2339 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2340 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2341 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2342 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2343 NLA_PUT_FLAG(msg,
2344 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2345 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2346 sinfo->bss_param.dtim_period);
2347 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2348 sinfo->bss_param.beacon_interval);
2349
2350 nla_nest_end(msg, bss_param);
2351 }
Helmut Schaabb6e7532011-10-13 16:30:39 +02002352 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2353 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2354 sizeof(struct nl80211_sta_flag_update),
2355 &sinfo->sta_flags);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002356 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002357
Felix Fietkau040bdf72011-08-10 19:00:33 -06002358 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002359 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2360 sinfo->assoc_req_ies);
2361
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002362 return genlmsg_end(msg, hdr);
2363
2364 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002365 genlmsg_cancel(msg, hdr);
2366 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002367}
2368
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002369static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002370 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002371{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002372 struct station_info sinfo;
2373 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002374 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002375 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002376 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002377 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002378
Johannes Berg67748892010-10-04 21:14:06 +02002379 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2380 if (err)
2381 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002382
2383 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002384 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002385 goto out_err;
2386 }
2387
Johannes Bergbba95fe2008-07-29 13:22:51 +02002388 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002389 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002390 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2391 mac_addr, &sinfo);
2392 if (err == -ENOENT)
2393 break;
2394 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002395 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002396
2397 if (nl80211_send_station(skb,
2398 NETLINK_CB(cb->skb).pid,
2399 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2400 netdev, mac_addr,
2401 &sinfo) < 0)
2402 goto out;
2403
2404 sta_idx++;
2405 }
2406
2407
2408 out:
2409 cb->args[1] = sta_idx;
2410 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002411 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002412 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002413
2414 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002415}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002416
Johannes Berg5727ef12007-12-19 02:03:34 +01002417static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2418{
Johannes Berg4c476992010-10-04 21:36:35 +02002419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2420 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002421 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002422 struct sk_buff *msg;
2423 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002424 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002425
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002426 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002427
2428 if (!info->attrs[NL80211_ATTR_MAC])
2429 return -EINVAL;
2430
2431 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2432
Johannes Berg4c476992010-10-04 21:36:35 +02002433 if (!rdev->ops->get_station)
2434 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002435
Johannes Berg79c97e92009-07-07 03:56:12 +02002436 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002437 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002438 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002439
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002441 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002442 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002443
2444 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002445 dev, mac_addr, &sinfo) < 0) {
2446 nlmsg_free(msg);
2447 return -ENOBUFS;
2448 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002449
Johannes Berg4c476992010-10-04 21:36:35 +02002450 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002451}
2452
2453/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002454 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002455 */
Johannes Berg463d0182009-07-14 00:33:35 +02002456static int get_vlan(struct genl_info *info,
Johannes Berg5727ef12007-12-19 02:03:34 +01002457 struct cfg80211_registered_device *rdev,
2458 struct net_device **vlan)
2459{
Johannes Berg463d0182009-07-14 00:33:35 +02002460 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg5727ef12007-12-19 02:03:34 +01002461 *vlan = NULL;
2462
2463 if (vlanattr) {
Johannes Berg463d0182009-07-14 00:33:35 +02002464 *vlan = dev_get_by_index(genl_info_net(info),
2465 nla_get_u32(vlanattr));
Johannes Berg5727ef12007-12-19 02:03:34 +01002466 if (!*vlan)
2467 return -ENODEV;
2468 if (!(*vlan)->ieee80211_ptr)
2469 return -EINVAL;
2470 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
2471 return -EINVAL;
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002472 if (!netif_running(*vlan))
2473 return -ENETDOWN;
Johannes Berg5727ef12007-12-19 02:03:34 +01002474 }
2475 return 0;
2476}
2477
2478static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2479{
Johannes Berg4c476992010-10-04 21:36:35 +02002480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002481 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002482 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002483 struct station_parameters params;
2484 u8 *mac_addr = NULL;
2485
2486 memset(&params, 0, sizeof(params));
2487
2488 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002489 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002490
2491 if (info->attrs[NL80211_ATTR_STA_AID])
2492 return -EINVAL;
2493
2494 if (!info->attrs[NL80211_ATTR_MAC])
2495 return -EINVAL;
2496
2497 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2498
2499 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2500 params.supported_rates =
2501 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2502 params.supported_rates_len =
2503 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2504 }
2505
2506 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2507 params.listen_interval =
2508 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2509
Jouni Malinen36aedc92008-08-25 11:58:58 +03002510 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2511 params.ht_capa =
2512 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2513
Johannes Bergeccb8e82009-05-11 21:57:56 +03002514 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002515 return -EINVAL;
2516
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002517 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2518 params.plink_action =
2519 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2520
Javier Cardona9c3990a2011-05-03 16:57:11 -07002521 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2522 params.plink_state =
2523 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2524
Johannes Berg463d0182009-07-14 00:33:35 +02002525 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002526 if (err)
Johannes Berg034d6552009-05-27 10:35:29 +02002527 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002528
2529 /* validate settings */
2530 err = 0;
2531
2532 switch (dev->ieee80211_ptr->iftype) {
2533 case NL80211_IFTYPE_AP:
2534 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002535 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002536 /* disallow mesh-specific things */
2537 if (params.plink_action)
2538 err = -EINVAL;
2539 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002540 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002541 case NL80211_IFTYPE_STATION:
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002542 /* disallow things sta doesn't support */
Johannes Berga97f4422009-06-18 17:23:43 +02002543 if (params.plink_action)
2544 err = -EINVAL;
2545 if (params.vlan)
2546 err = -EINVAL;
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002547 if (params.supported_rates &&
2548 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berga97f4422009-06-18 17:23:43 +02002549 err = -EINVAL;
2550 if (params.ht_capa)
2551 err = -EINVAL;
2552 if (params.listen_interval >= 0)
2553 err = -EINVAL;
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002554 if (params.sta_flags_mask &
2555 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2556 BIT(NL80211_STA_FLAG_TDLS_PEER)))
2557 err = -EINVAL;
2558 /* can't change the TDLS bit */
2559 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2560 (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berga97f4422009-06-18 17:23:43 +02002561 err = -EINVAL;
2562 break;
2563 case NL80211_IFTYPE_MESH_POINT:
2564 /* disallow things mesh doesn't support */
2565 if (params.vlan)
2566 err = -EINVAL;
2567 if (params.ht_capa)
2568 err = -EINVAL;
2569 if (params.listen_interval >= 0)
2570 err = -EINVAL;
Javier Cardonab39c48f2011-04-07 15:08:30 -07002571 if (params.sta_flags_mask &
2572 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002573 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002574 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Berga97f4422009-06-18 17:23:43 +02002575 err = -EINVAL;
2576 break;
2577 default:
2578 err = -EINVAL;
Johannes Berg034d6552009-05-27 10:35:29 +02002579 }
2580
Johannes Berg5727ef12007-12-19 02:03:34 +01002581 if (err)
2582 goto out;
2583
Johannes Berg79c97e92009-07-07 03:56:12 +02002584 if (!rdev->ops->change_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002585 err = -EOPNOTSUPP;
2586 goto out;
2587 }
2588
Johannes Berg79c97e92009-07-07 03:56:12 +02002589 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002590
2591 out:
2592 if (params.vlan)
2593 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002594
Johannes Berg5727ef12007-12-19 02:03:34 +01002595 return err;
2596}
2597
Eliad Pellerc75786c2011-08-23 14:37:46 +03002598static struct nla_policy
2599nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2600 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2601 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2602};
2603
Johannes Berg5727ef12007-12-19 02:03:34 +01002604static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2605{
Johannes Berg4c476992010-10-04 21:36:35 +02002606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002607 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002608 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002609 struct station_parameters params;
2610 u8 *mac_addr = NULL;
2611
2612 memset(&params, 0, sizeof(params));
2613
2614 if (!info->attrs[NL80211_ATTR_MAC])
2615 return -EINVAL;
2616
Johannes Berg5727ef12007-12-19 02:03:34 +01002617 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2618 return -EINVAL;
2619
2620 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2621 return -EINVAL;
2622
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002623 if (!info->attrs[NL80211_ATTR_STA_AID])
2624 return -EINVAL;
2625
Johannes Berg5727ef12007-12-19 02:03:34 +01002626 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2627 params.supported_rates =
2628 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2629 params.supported_rates_len =
2630 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2631 params.listen_interval =
2632 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002633
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002634 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2635 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2636 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002637
Jouni Malinen36aedc92008-08-25 11:58:58 +03002638 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2639 params.ht_capa =
2640 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002641
Javier Cardona96b78df2011-04-07 15:08:33 -07002642 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2643 params.plink_action =
2644 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2645
Johannes Bergeccb8e82009-05-11 21:57:56 +03002646 if (parse_station_flags(info, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002647 return -EINVAL;
2648
Eliad Pellerc75786c2011-08-23 14:37:46 +03002649 /* parse WME attributes if sta is WME capable */
Eliad Pellercedb5412011-08-31 11:29:43 +03002650 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Arik Nemtsovcd329842011-09-26 09:36:42 +03002651 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
Eliad Pellerc75786c2011-08-23 14:37:46 +03002652 info->attrs[NL80211_ATTR_STA_WME]) {
2653 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2654 struct nlattr *nla;
2655
2656 nla = info->attrs[NL80211_ATTR_STA_WME];
2657 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2658 nl80211_sta_wme_policy);
2659 if (err)
2660 return err;
2661
2662 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2663 params.uapsd_queues =
2664 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
Johannes Berg4319e192011-09-07 11:50:48 +02002665 if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2666 return -EINVAL;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002667
2668 if (tb[NL80211_STA_WME_MAX_SP])
2669 params.max_sp =
2670 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
Johannes Berg4319e192011-09-07 11:50:48 +02002671
2672 if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2673 return -EINVAL;
Johannes Berg3b9ce802011-09-27 20:56:12 +02002674
2675 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002676 }
2677
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002678 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002679 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardona96b78df2011-04-07 15:08:33 -07002680 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002681 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO &&
2682 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
2683 return -EINVAL;
2684
2685 /*
2686 * Only managed stations can add TDLS peers, and only when the
2687 * wiphy supports external TDLS setup.
2688 */
2689 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION &&
2690 !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2691 (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2692 (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
Johannes Berg4c476992010-10-04 21:36:35 +02002693 return -EINVAL;
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002694
Johannes Berg463d0182009-07-14 00:33:35 +02002695 err = get_vlan(info, rdev, &params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002696 if (err)
Johannes Berge80cf852009-05-11 14:43:13 +02002697 goto out;
Johannes Berga97f4422009-06-18 17:23:43 +02002698
2699 /* validate settings */
2700 err = 0;
2701
Johannes Berg79c97e92009-07-07 03:56:12 +02002702 if (!rdev->ops->add_station) {
Johannes Berg5727ef12007-12-19 02:03:34 +01002703 err = -EOPNOTSUPP;
2704 goto out;
2705 }
2706
Johannes Berg79c97e92009-07-07 03:56:12 +02002707 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002708
2709 out:
2710 if (params.vlan)
2711 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002712 return err;
2713}
2714
2715static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2716{
Johannes Berg4c476992010-10-04 21:36:35 +02002717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2718 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002719 u8 *mac_addr = NULL;
2720
2721 if (info->attrs[NL80211_ATTR_MAC])
2722 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2723
Johannes Berge80cf852009-05-11 14:43:13 +02002724 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002725 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002726 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002727 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2728 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002729
Johannes Berg4c476992010-10-04 21:36:35 +02002730 if (!rdev->ops->del_station)
2731 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002732
Johannes Berg4c476992010-10-04 21:36:35 +02002733 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002734}
2735
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002736static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2737 int flags, struct net_device *dev,
2738 u8 *dst, u8 *next_hop,
2739 struct mpath_info *pinfo)
2740{
2741 void *hdr;
2742 struct nlattr *pinfoattr;
2743
2744 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2745 if (!hdr)
2746 return -1;
2747
2748 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2749 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2750 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2751
Johannes Bergf5ea9122009-08-07 16:17:38 +02002752 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2753
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002754 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2755 if (!pinfoattr)
2756 goto nla_put_failure;
2757 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2758 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2759 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002760 if (pinfo->filled & MPATH_INFO_SN)
2761 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2762 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002763 if (pinfo->filled & MPATH_INFO_METRIC)
2764 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2765 pinfo->metric);
2766 if (pinfo->filled & MPATH_INFO_EXPTIME)
2767 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2768 pinfo->exptime);
2769 if (pinfo->filled & MPATH_INFO_FLAGS)
2770 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2771 pinfo->flags);
2772 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2773 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2774 pinfo->discovery_timeout);
2775 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2776 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2777 pinfo->discovery_retries);
2778
2779 nla_nest_end(msg, pinfoattr);
2780
2781 return genlmsg_end(msg, hdr);
2782
2783 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002784 genlmsg_cancel(msg, hdr);
2785 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002786}
2787
2788static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002789 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002790{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002791 struct mpath_info pinfo;
2792 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002793 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002794 u8 dst[ETH_ALEN];
2795 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002796 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002797 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002798
Johannes Berg67748892010-10-04 21:14:06 +02002799 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2800 if (err)
2801 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002802
2803 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002804 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002805 goto out_err;
2806 }
2807
Jouni Malineneec60b02009-03-20 21:21:19 +02002808 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2809 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002810 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002811 }
2812
Johannes Bergbba95fe2008-07-29 13:22:51 +02002813 while (1) {
2814 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2815 dst, next_hop, &pinfo);
2816 if (err == -ENOENT)
2817 break;
2818 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002819 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002820
2821 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2822 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2823 netdev, dst, next_hop,
2824 &pinfo) < 0)
2825 goto out;
2826
2827 path_idx++;
2828 }
2829
2830
2831 out:
2832 cb->args[1] = path_idx;
2833 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002834 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002835 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002836 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002837}
2838
2839static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2840{
Johannes Berg4c476992010-10-04 21:36:35 +02002841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002842 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002843 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002844 struct mpath_info pinfo;
2845 struct sk_buff *msg;
2846 u8 *dst = NULL;
2847 u8 next_hop[ETH_ALEN];
2848
2849 memset(&pinfo, 0, sizeof(pinfo));
2850
2851 if (!info->attrs[NL80211_ATTR_MAC])
2852 return -EINVAL;
2853
2854 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2855
Johannes Berg4c476992010-10-04 21:36:35 +02002856 if (!rdev->ops->get_mpath)
2857 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002858
Johannes Berg4c476992010-10-04 21:36:35 +02002859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2860 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002861
Johannes Berg79c97e92009-07-07 03:56:12 +02002862 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002863 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002864 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002865
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002867 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002868 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002869
2870 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002871 dev, dst, next_hop, &pinfo) < 0) {
2872 nlmsg_free(msg);
2873 return -ENOBUFS;
2874 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002875
Johannes Berg4c476992010-10-04 21:36:35 +02002876 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002877}
2878
2879static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2880{
Johannes Berg4c476992010-10-04 21:36:35 +02002881 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2882 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002883 u8 *dst = NULL;
2884 u8 *next_hop = NULL;
2885
2886 if (!info->attrs[NL80211_ATTR_MAC])
2887 return -EINVAL;
2888
2889 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2890 return -EINVAL;
2891
2892 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2893 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2894
Johannes Berg4c476992010-10-04 21:36:35 +02002895 if (!rdev->ops->change_mpath)
2896 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002897
Johannes Berg4c476992010-10-04 21:36:35 +02002898 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2899 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002900
Johannes Berg4c476992010-10-04 21:36:35 +02002901 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002902}
Johannes Berg4c476992010-10-04 21:36:35 +02002903
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002904static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2905{
Johannes Berg4c476992010-10-04 21:36:35 +02002906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2907 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002908 u8 *dst = NULL;
2909 u8 *next_hop = NULL;
2910
2911 if (!info->attrs[NL80211_ATTR_MAC])
2912 return -EINVAL;
2913
2914 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2915 return -EINVAL;
2916
2917 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2918 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2919
Johannes Berg4c476992010-10-04 21:36:35 +02002920 if (!rdev->ops->add_mpath)
2921 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002922
Johannes Berg4c476992010-10-04 21:36:35 +02002923 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2924 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002925
Johannes Berg4c476992010-10-04 21:36:35 +02002926 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002927}
2928
2929static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2930{
Johannes Berg4c476992010-10-04 21:36:35 +02002931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2932 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002933 u8 *dst = NULL;
2934
2935 if (info->attrs[NL80211_ATTR_MAC])
2936 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2937
Johannes Berg4c476992010-10-04 21:36:35 +02002938 if (!rdev->ops->del_mpath)
2939 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002940
Johannes Berg4c476992010-10-04 21:36:35 +02002941 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002942}
2943
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002944static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2945{
Johannes Berg4c476992010-10-04 21:36:35 +02002946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2947 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002948 struct bss_parameters params;
2949
2950 memset(&params, 0, sizeof(params));
2951 /* default to not changing parameters */
2952 params.use_cts_prot = -1;
2953 params.use_short_preamble = -1;
2954 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002955 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01002956 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002957
2958 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2959 params.use_cts_prot =
2960 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2961 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2962 params.use_short_preamble =
2963 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2964 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2965 params.use_short_slot_time =
2966 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002967 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2968 params.basic_rates =
2969 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2970 params.basic_rates_len =
2971 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2972 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02002973 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2974 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01002975 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2976 params.ht_opmode =
2977 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002978
Johannes Berg4c476992010-10-04 21:36:35 +02002979 if (!rdev->ops->change_bss)
2980 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002981
Johannes Berg074ac8d2010-09-16 14:58:22 +02002982 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002983 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2984 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02002985
Johannes Berg4c476992010-10-04 21:36:35 +02002986 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002987}
2988
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00002989static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002990 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2991 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2992 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2993 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2994 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2995 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2996};
2997
2998static int parse_reg_rule(struct nlattr *tb[],
2999 struct ieee80211_reg_rule *reg_rule)
3000{
3001 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3002 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3003
3004 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3005 return -EINVAL;
3006 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3007 return -EINVAL;
3008 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3009 return -EINVAL;
3010 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3011 return -EINVAL;
3012 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3013 return -EINVAL;
3014
3015 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3016
3017 freq_range->start_freq_khz =
3018 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3019 freq_range->end_freq_khz =
3020 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3021 freq_range->max_bandwidth_khz =
3022 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3023
3024 power_rule->max_eirp =
3025 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3026
3027 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3028 power_rule->max_antenna_gain =
3029 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3030
3031 return 0;
3032}
3033
3034static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3035{
3036 int r;
3037 char *data = NULL;
3038
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003039 /*
3040 * You should only get this when cfg80211 hasn't yet initialized
3041 * completely when built-in to the kernel right between the time
3042 * window between nl80211_init() and regulatory_init(), if that is
3043 * even possible.
3044 */
3045 mutex_lock(&cfg80211_mutex);
3046 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003047 mutex_unlock(&cfg80211_mutex);
3048 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003049 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003050 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003051
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003052 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3053 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003054
3055 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3056
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003057 r = regulatory_hint_user(data);
3058
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003059 return r;
3060}
3061
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003062static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003063 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003064{
Johannes Berg4c476992010-10-04 21:36:35 +02003065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003066 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003067 struct wireless_dev *wdev = dev->ieee80211_ptr;
3068 struct mesh_config cur_params;
3069 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003070 void *hdr;
3071 struct nlattr *pinfoattr;
3072 struct sk_buff *msg;
3073
Johannes Berg29cbe682010-12-03 09:20:44 +01003074 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3075 return -EOPNOTSUPP;
3076
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003077 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003078 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003079
Johannes Berg29cbe682010-12-03 09:20:44 +01003080 wdev_lock(wdev);
3081 /* If not connected, get default parameters */
3082 if (!wdev->mesh_id_len)
3083 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3084 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003085 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003086 &cur_params);
3087 wdev_unlock(wdev);
3088
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003089 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003090 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003091
3092 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003093 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003094 if (!msg)
3095 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003096 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003097 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003098 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003099 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003100 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003101 if (!pinfoattr)
3102 goto nla_put_failure;
3103 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3104 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3105 cur_params.dot11MeshRetryTimeout);
3106 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3107 cur_params.dot11MeshConfirmTimeout);
3108 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3109 cur_params.dot11MeshHoldingTimeout);
3110 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3111 cur_params.dot11MeshMaxPeerLinks);
3112 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3113 cur_params.dot11MeshMaxRetries);
3114 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3115 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01003116 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3117 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003118 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3119 cur_params.auto_open_plinks);
3120 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3121 cur_params.dot11MeshHWMPmaxPREQretries);
3122 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3123 cur_params.path_refresh_time);
3124 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3125 cur_params.min_discovery_timeout);
3126 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3127 cur_params.dot11MeshHWMPactivePathTimeout);
3128 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3129 cur_params.dot11MeshHWMPpreqMinInterval);
3130 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3131 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00003132 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3133 cur_params.dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -07003134 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3135 cur_params.dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -07003136 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3137 cur_params.dot11MeshGateAnnouncementProtocol);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003138 nla_nest_end(msg, pinfoattr);
3139 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003140 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003141
Johannes Berg3b858752009-03-12 09:55:09 +01003142 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003143 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003144 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003145 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003146 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003147}
3148
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003149static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003150 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3151 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3152 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3153 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3154 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3155 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003156 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003157 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
3158
3159 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3160 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3161 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3162 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3163 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
3164 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003165 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003166 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003167 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003168};
3169
Javier Cardonac80d5452010-12-16 17:37:49 -08003170static const struct nla_policy
3171 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
3172 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3173 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003174 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003175 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08003176 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003177 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003178};
3179
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003180static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003181 struct mesh_config *cfg,
3182 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003183{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003184 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003185 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003186
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003187#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3188do {\
3189 if (table[attr_num]) {\
3190 cfg->param = nla_fn(table[attr_num]); \
3191 mask |= (1 << (attr_num - 1)); \
3192 } \
3193} while (0);\
3194
3195
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003196 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003197 return -EINVAL;
3198 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003199 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003200 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003201 return -EINVAL;
3202
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003203 /* This makes sure that there aren't more than 32 mesh config
3204 * parameters (otherwise our bitfield scheme would not work.) */
3205 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3206
3207 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003208 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3209 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3210 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3211 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3212 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3213 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3215 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3216 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3217 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3219 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3221 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3223 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3224 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3225 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3226 nla_get_u8);
3227 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3228 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3230 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3231 nla_get_u16);
3232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3233 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3234 nla_get_u32);
3235 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3236 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3237 nla_get_u16);
3238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3239 dot11MeshHWMPnetDiameterTraversalTime,
3240 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3241 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3243 dot11MeshHWMPRootMode, mask,
3244 NL80211_MESHCONF_HWMP_ROOTMODE,
3245 nla_get_u8);
Javier Cardona0507e152011-08-09 16:45:10 -07003246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3247 dot11MeshHWMPRannInterval, mask,
3248 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3249 nla_get_u16);
Javier Cardona16dd7262011-08-09 16:45:11 -07003250 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3251 dot11MeshGateAnnouncementProtocol, mask,
3252 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3253 nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003254 if (mask_out)
3255 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003256
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003257 return 0;
3258
3259#undef FILL_IN_MESH_PARAM_IF_SET
3260}
3261
Javier Cardonac80d5452010-12-16 17:37:49 -08003262static int nl80211_parse_mesh_setup(struct genl_info *info,
3263 struct mesh_setup *setup)
3264{
3265 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3266
3267 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3268 return -EINVAL;
3269 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3270 info->attrs[NL80211_ATTR_MESH_SETUP],
3271 nl80211_mesh_setup_params_policy))
3272 return -EINVAL;
3273
3274 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3275 setup->path_sel_proto =
3276 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3277 IEEE80211_PATH_PROTOCOL_VENDOR :
3278 IEEE80211_PATH_PROTOCOL_HWMP;
3279
3280 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3281 setup->path_metric =
3282 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3283 IEEE80211_PATH_METRIC_VENDOR :
3284 IEEE80211_PATH_METRIC_AIRTIME;
3285
Javier Cardona581a8b02011-04-07 15:08:27 -07003286
3287 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003288 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003289 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003290 if (!is_valid_ie_attr(ieattr))
3291 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003292 setup->ie = nla_data(ieattr);
3293 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003294 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003295 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3296 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003297
3298 return 0;
3299}
3300
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003301static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003302 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003303{
3304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3305 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003306 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003307 struct mesh_config cfg;
3308 u32 mask;
3309 int err;
3310
Johannes Berg29cbe682010-12-03 09:20:44 +01003311 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3312 return -EOPNOTSUPP;
3313
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003314 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003315 return -EOPNOTSUPP;
3316
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003317 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003318 if (err)
3319 return err;
3320
Johannes Berg29cbe682010-12-03 09:20:44 +01003321 wdev_lock(wdev);
3322 if (!wdev->mesh_id_len)
3323 err = -ENOLINK;
3324
3325 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003326 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003327 mask, &cfg);
3328
3329 wdev_unlock(wdev);
3330
3331 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003332}
3333
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003334static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3335{
3336 struct sk_buff *msg;
3337 void *hdr = NULL;
3338 struct nlattr *nl_reg_rules;
3339 unsigned int i;
3340 int err = -EINVAL;
3341
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003342 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003343
3344 if (!cfg80211_regdomain)
3345 goto out;
3346
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003347 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003348 if (!msg) {
3349 err = -ENOBUFS;
3350 goto out;
3351 }
3352
3353 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3354 NL80211_CMD_GET_REG);
3355 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003356 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003357
3358 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3359 cfg80211_regdomain->alpha2);
3360
3361 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3362 if (!nl_reg_rules)
3363 goto nla_put_failure;
3364
3365 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3366 struct nlattr *nl_reg_rule;
3367 const struct ieee80211_reg_rule *reg_rule;
3368 const struct ieee80211_freq_range *freq_range;
3369 const struct ieee80211_power_rule *power_rule;
3370
3371 reg_rule = &cfg80211_regdomain->reg_rules[i];
3372 freq_range = &reg_rule->freq_range;
3373 power_rule = &reg_rule->power_rule;
3374
3375 nl_reg_rule = nla_nest_start(msg, i);
3376 if (!nl_reg_rule)
3377 goto nla_put_failure;
3378
3379 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3380 reg_rule->flags);
3381 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3382 freq_range->start_freq_khz);
3383 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3384 freq_range->end_freq_khz);
3385 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3386 freq_range->max_bandwidth_khz);
3387 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3388 power_rule->max_antenna_gain);
3389 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3390 power_rule->max_eirp);
3391
3392 nla_nest_end(msg, nl_reg_rule);
3393 }
3394
3395 nla_nest_end(msg, nl_reg_rules);
3396
3397 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003398 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003399 goto out;
3400
3401nla_put_failure:
3402 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003403put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003404 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003405 err = -EMSGSIZE;
3406out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003407 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003408 return err;
3409}
3410
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003411static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3412{
3413 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3414 struct nlattr *nl_reg_rule;
3415 char *alpha2 = NULL;
3416 int rem_reg_rules = 0, r = 0;
3417 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3418 struct ieee80211_regdomain *rd = NULL;
3419
3420 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3421 return -EINVAL;
3422
3423 if (!info->attrs[NL80211_ATTR_REG_RULES])
3424 return -EINVAL;
3425
3426 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3427
3428 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3429 rem_reg_rules) {
3430 num_rules++;
3431 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003432 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003433 }
3434
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003435 mutex_lock(&cfg80211_mutex);
3436
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003437 if (!reg_is_valid_request(alpha2)) {
3438 r = -EINVAL;
3439 goto bad_reg;
3440 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003441
3442 size_of_regd = sizeof(struct ieee80211_regdomain) +
3443 (num_rules * sizeof(struct ieee80211_reg_rule));
3444
3445 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003446 if (!rd) {
3447 r = -ENOMEM;
3448 goto bad_reg;
3449 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003450
3451 rd->n_reg_rules = num_rules;
3452 rd->alpha2[0] = alpha2[0];
3453 rd->alpha2[1] = alpha2[1];
3454
3455 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3456 rem_reg_rules) {
3457 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3458 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3459 reg_rule_policy);
3460 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3461 if (r)
3462 goto bad_reg;
3463
3464 rule_idx++;
3465
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003466 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3467 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003468 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003469 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003470 }
3471
3472 BUG_ON(rule_idx != num_rules);
3473
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003474 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003475
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003476 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003477
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003478 return r;
3479
Johannes Bergd2372b32008-10-24 20:32:20 +02003480 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003481 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003482 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003483 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003484}
3485
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003486static int validate_scan_freqs(struct nlattr *freqs)
3487{
3488 struct nlattr *attr1, *attr2;
3489 int n_channels = 0, tmp1, tmp2;
3490
3491 nla_for_each_nested(attr1, freqs, tmp1) {
3492 n_channels++;
3493 /*
3494 * Some hardware has a limited channel list for
3495 * scanning, and it is pretty much nonsensical
3496 * to scan for a channel twice, so disallow that
3497 * and don't require drivers to check that the
3498 * channel list they get isn't longer than what
3499 * they can scan, as long as they can scan all
3500 * the channels they registered at once.
3501 */
3502 nla_for_each_nested(attr2, freqs, tmp2)
3503 if (attr1 != attr2 &&
3504 nla_get_u32(attr1) == nla_get_u32(attr2))
3505 return 0;
3506 }
3507
3508 return n_channels;
3509}
3510
Johannes Berg2a519312009-02-10 21:25:55 +01003511static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3512{
Johannes Berg4c476992010-10-04 21:36:35 +02003513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3514 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003515 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003516 struct nlattr *attr;
3517 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003518 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003519 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003520
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003521 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3522 return -EINVAL;
3523
Johannes Berg79c97e92009-07-07 03:56:12 +02003524 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003525
Johannes Berg4c476992010-10-04 21:36:35 +02003526 if (!rdev->ops->scan)
3527 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003528
Johannes Berg4c476992010-10-04 21:36:35 +02003529 if (rdev->scan_req)
3530 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003531
3532 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003533 n_channels = validate_scan_freqs(
3534 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003535 if (!n_channels)
3536 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003537 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003538 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003539 n_channels = 0;
3540
Johannes Berg2a519312009-02-10 21:25:55 +01003541 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3542 if (wiphy->bands[band])
3543 n_channels += wiphy->bands[band]->n_channels;
3544 }
3545
3546 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3547 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3548 n_ssids++;
3549
Johannes Berg4c476992010-10-04 21:36:35 +02003550 if (n_ssids > wiphy->max_scan_ssids)
3551 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003552
Jouni Malinen70692ad2009-02-16 19:39:13 +02003553 if (info->attrs[NL80211_ATTR_IE])
3554 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3555 else
3556 ie_len = 0;
3557
Johannes Berg4c476992010-10-04 21:36:35 +02003558 if (ie_len > wiphy->max_scan_ie_len)
3559 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003560
Johannes Berg2a519312009-02-10 21:25:55 +01003561 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003562 + sizeof(*request->ssids) * n_ssids
3563 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003564 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003565 if (!request)
3566 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003567
Johannes Berg2a519312009-02-10 21:25:55 +01003568 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003569 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003570 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003571 if (ie_len) {
3572 if (request->ssids)
3573 request->ie = (void *)(request->ssids + n_ssids);
3574 else
3575 request->ie = (void *)(request->channels + n_channels);
3576 }
Johannes Berg2a519312009-02-10 21:25:55 +01003577
Johannes Berg584991d2009-11-02 13:32:03 +01003578 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003579 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3580 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003581 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003582 struct ieee80211_channel *chan;
3583
3584 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3585
3586 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003587 err = -EINVAL;
3588 goto out_free;
3589 }
Johannes Berg584991d2009-11-02 13:32:03 +01003590
3591 /* ignore disabled channels */
3592 if (chan->flags & IEEE80211_CHAN_DISABLED)
3593 continue;
3594
3595 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003596 i++;
3597 }
3598 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003599 enum ieee80211_band band;
3600
Johannes Berg2a519312009-02-10 21:25:55 +01003601 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003602 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3603 int j;
3604 if (!wiphy->bands[band])
3605 continue;
3606 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003607 struct ieee80211_channel *chan;
3608
3609 chan = &wiphy->bands[band]->channels[j];
3610
3611 if (chan->flags & IEEE80211_CHAN_DISABLED)
3612 continue;
3613
3614 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003615 i++;
3616 }
3617 }
3618 }
3619
Johannes Berg584991d2009-11-02 13:32:03 +01003620 if (!i) {
3621 err = -EINVAL;
3622 goto out_free;
3623 }
3624
3625 request->n_channels = i;
3626
Johannes Berg2a519312009-02-10 21:25:55 +01003627 i = 0;
3628 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3629 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003630 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003631 err = -EINVAL;
3632 goto out_free;
3633 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003634 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003635 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003636 i++;
3637 }
3638 }
3639
Jouni Malinen70692ad2009-02-16 19:39:13 +02003640 if (info->attrs[NL80211_ATTR_IE]) {
3641 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003642 memcpy((void *)request->ie,
3643 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003644 request->ie_len);
3645 }
3646
Johannes Berg34850ab2011-07-18 18:08:35 +02003647 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003648 if (wiphy->bands[i])
3649 request->rates[i] =
3650 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003651
3652 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3653 nla_for_each_nested(attr,
3654 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3655 tmp) {
3656 enum ieee80211_band band = nla_type(attr);
3657
Dan Carpenter84404622011-07-29 11:52:18 +03003658 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003659 err = -EINVAL;
3660 goto out_free;
3661 }
3662 err = ieee80211_get_ratemask(wiphy->bands[band],
3663 nla_data(attr),
3664 nla_len(attr),
3665 &request->rates[band]);
3666 if (err)
3667 goto out_free;
3668 }
3669 }
3670
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05303671 request->no_cck =
3672 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3673
Johannes Berg463d0182009-07-14 00:33:35 +02003674 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003675 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003676
Johannes Berg79c97e92009-07-07 03:56:12 +02003677 rdev->scan_req = request;
3678 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003679
Johannes Berg463d0182009-07-14 00:33:35 +02003680 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003681 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003682 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003683 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003684 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003685 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003686 kfree(request);
3687 }
Johannes Berg3b858752009-03-12 09:55:09 +01003688
Johannes Berg2a519312009-02-10 21:25:55 +01003689 return err;
3690}
3691
Luciano Coelho807f8a82011-05-11 17:09:35 +03003692static int nl80211_start_sched_scan(struct sk_buff *skb,
3693 struct genl_info *info)
3694{
3695 struct cfg80211_sched_scan_request *request;
3696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3697 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003698 struct nlattr *attr;
3699 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003700 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003701 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003702 enum ieee80211_band band;
3703 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003704 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003705
3706 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3707 !rdev->ops->sched_scan_start)
3708 return -EOPNOTSUPP;
3709
3710 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3711 return -EINVAL;
3712
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003713 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3714 return -EINVAL;
3715
3716 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3717 if (interval == 0)
3718 return -EINVAL;
3719
Luciano Coelho807f8a82011-05-11 17:09:35 +03003720 wiphy = &rdev->wiphy;
3721
3722 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3723 n_channels = validate_scan_freqs(
3724 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3725 if (!n_channels)
3726 return -EINVAL;
3727 } else {
3728 n_channels = 0;
3729
3730 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3731 if (wiphy->bands[band])
3732 n_channels += wiphy->bands[band]->n_channels;
3733 }
3734
3735 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3736 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3737 tmp)
3738 n_ssids++;
3739
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003740 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003741 return -EINVAL;
3742
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003743 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3744 nla_for_each_nested(attr,
3745 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3746 tmp)
3747 n_match_sets++;
3748
3749 if (n_match_sets > wiphy->max_match_sets)
3750 return -EINVAL;
3751
Luciano Coelho807f8a82011-05-11 17:09:35 +03003752 if (info->attrs[NL80211_ATTR_IE])
3753 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3754 else
3755 ie_len = 0;
3756
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003757 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003758 return -EINVAL;
3759
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003760 mutex_lock(&rdev->sched_scan_mtx);
3761
3762 if (rdev->sched_scan_req) {
3763 err = -EINPROGRESS;
3764 goto out;
3765 }
3766
Luciano Coelho807f8a82011-05-11 17:09:35 +03003767 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003768 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003769 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003770 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003771 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003772 if (!request) {
3773 err = -ENOMEM;
3774 goto out;
3775 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003776
3777 if (n_ssids)
3778 request->ssids = (void *)&request->channels[n_channels];
3779 request->n_ssids = n_ssids;
3780 if (ie_len) {
3781 if (request->ssids)
3782 request->ie = (void *)(request->ssids + n_ssids);
3783 else
3784 request->ie = (void *)(request->channels + n_channels);
3785 }
3786
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003787 if (n_match_sets) {
3788 if (request->ie)
3789 request->match_sets = (void *)(request->ie + ie_len);
3790 else if (request->ssids)
3791 request->match_sets =
3792 (void *)(request->ssids + n_ssids);
3793 else
3794 request->match_sets =
3795 (void *)(request->channels + n_channels);
3796 }
3797 request->n_match_sets = n_match_sets;
3798
Luciano Coelho807f8a82011-05-11 17:09:35 +03003799 i = 0;
3800 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3801 /* user specified, bail out if channel not found */
3802 nla_for_each_nested(attr,
3803 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3804 tmp) {
3805 struct ieee80211_channel *chan;
3806
3807 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3808
3809 if (!chan) {
3810 err = -EINVAL;
3811 goto out_free;
3812 }
3813
3814 /* ignore disabled channels */
3815 if (chan->flags & IEEE80211_CHAN_DISABLED)
3816 continue;
3817
3818 request->channels[i] = chan;
3819 i++;
3820 }
3821 } else {
3822 /* all channels */
3823 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3824 int j;
3825 if (!wiphy->bands[band])
3826 continue;
3827 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3828 struct ieee80211_channel *chan;
3829
3830 chan = &wiphy->bands[band]->channels[j];
3831
3832 if (chan->flags & IEEE80211_CHAN_DISABLED)
3833 continue;
3834
3835 request->channels[i] = chan;
3836 i++;
3837 }
3838 }
3839 }
3840
3841 if (!i) {
3842 err = -EINVAL;
3843 goto out_free;
3844 }
3845
3846 request->n_channels = i;
3847
3848 i = 0;
3849 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3850 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3851 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003852 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03003853 err = -EINVAL;
3854 goto out_free;
3855 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003856 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003857 memcpy(request->ssids[i].ssid, nla_data(attr),
3858 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03003859 i++;
3860 }
3861 }
3862
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003863 i = 0;
3864 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
3865 nla_for_each_nested(attr,
3866 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3867 tmp) {
3868 struct nlattr *ssid;
3869
3870 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
3871 nla_data(attr), nla_len(attr),
3872 nl80211_match_policy);
3873 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
3874 if (ssid) {
3875 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
3876 err = -EINVAL;
3877 goto out_free;
3878 }
3879 memcpy(request->match_sets[i].ssid.ssid,
3880 nla_data(ssid), nla_len(ssid));
3881 request->match_sets[i].ssid.ssid_len =
3882 nla_len(ssid);
3883 }
3884 i++;
3885 }
3886 }
3887
Luciano Coelho807f8a82011-05-11 17:09:35 +03003888 if (info->attrs[NL80211_ATTR_IE]) {
3889 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3890 memcpy((void *)request->ie,
3891 nla_data(info->attrs[NL80211_ATTR_IE]),
3892 request->ie_len);
3893 }
3894
3895 request->dev = dev;
3896 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003897 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003898
3899 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
3900 if (!err) {
3901 rdev->sched_scan_req = request;
3902 nl80211_send_sched_scan(rdev, dev,
3903 NL80211_CMD_START_SCHED_SCAN);
3904 goto out;
3905 }
3906
3907out_free:
3908 kfree(request);
3909out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003910 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03003911 return err;
3912}
3913
3914static int nl80211_stop_sched_scan(struct sk_buff *skb,
3915 struct genl_info *info)
3916{
3917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003918 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003919
3920 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3921 !rdev->ops->sched_scan_stop)
3922 return -EOPNOTSUPP;
3923
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003924 mutex_lock(&rdev->sched_scan_mtx);
3925 err = __cfg80211_stop_sched_scan(rdev, false);
3926 mutex_unlock(&rdev->sched_scan_mtx);
3927
3928 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003929}
3930
Johannes Berg9720bb32011-06-21 09:45:33 +02003931static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3932 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003933 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02003934 struct wireless_dev *wdev,
3935 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01003936{
Johannes Berg48ab9052009-07-10 18:42:31 +02003937 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01003938 void *hdr;
3939 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02003940 int i;
3941
3942 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01003943
Johannes Berg9720bb32011-06-21 09:45:33 +02003944 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01003945 NL80211_CMD_NEW_SCAN_RESULTS);
3946 if (!hdr)
3947 return -1;
3948
Johannes Berg9720bb32011-06-21 09:45:33 +02003949 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
3950
Johannes Bergf5ea9122009-08-07 16:17:38 +02003951 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02003952 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01003953
3954 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
3955 if (!bss)
3956 goto nla_put_failure;
3957 if (!is_zero_ether_addr(res->bssid))
3958 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
3959 if (res->information_elements && res->len_information_elements)
3960 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
3961 res->len_information_elements,
3962 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02003963 if (res->beacon_ies && res->len_beacon_ies &&
3964 res->beacon_ies != res->information_elements)
3965 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
3966 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01003967 if (res->tsf)
3968 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
3969 if (res->beacon_interval)
3970 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
3971 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
3972 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02003973 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
3974 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01003975
Johannes Berg77965c92009-02-18 18:45:06 +01003976 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01003977 case CFG80211_SIGNAL_TYPE_MBM:
3978 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
3979 break;
3980 case CFG80211_SIGNAL_TYPE_UNSPEC:
3981 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
3982 break;
3983 default:
3984 break;
3985 }
3986
Johannes Berg48ab9052009-07-10 18:42:31 +02003987 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02003988 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02003989 case NL80211_IFTYPE_STATION:
3990 if (intbss == wdev->current_bss)
3991 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3992 NL80211_BSS_STATUS_ASSOCIATED);
3993 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
3994 if (intbss != wdev->auth_bsses[i])
3995 continue;
3996 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
3997 NL80211_BSS_STATUS_AUTHENTICATED);
3998 break;
3999 }
4000 break;
4001 case NL80211_IFTYPE_ADHOC:
4002 if (intbss == wdev->current_bss)
4003 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4004 NL80211_BSS_STATUS_IBSS_JOINED);
4005 break;
4006 default:
4007 break;
4008 }
4009
Johannes Berg2a519312009-02-10 21:25:55 +01004010 nla_nest_end(msg, bss);
4011
4012 return genlmsg_end(msg, hdr);
4013
4014 nla_put_failure:
4015 genlmsg_cancel(msg, hdr);
4016 return -EMSGSIZE;
4017}
4018
4019static int nl80211_dump_scan(struct sk_buff *skb,
4020 struct netlink_callback *cb)
4021{
Johannes Berg48ab9052009-07-10 18:42:31 +02004022 struct cfg80211_registered_device *rdev;
4023 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004024 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004025 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004026 int start = cb->args[1], idx = 0;
4027 int err;
4028
Johannes Berg67748892010-10-04 21:14:06 +02004029 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4030 if (err)
4031 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004032
Johannes Berg48ab9052009-07-10 18:42:31 +02004033 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004034
Johannes Berg48ab9052009-07-10 18:42:31 +02004035 wdev_lock(wdev);
4036 spin_lock_bh(&rdev->bss_lock);
4037 cfg80211_bss_expire(rdev);
4038
Johannes Berg9720bb32011-06-21 09:45:33 +02004039 cb->seq = rdev->bss_generation;
4040
Johannes Berg48ab9052009-07-10 18:42:31 +02004041 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004042 if (++idx <= start)
4043 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004044 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004045 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004046 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004047 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004048 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004049 }
4050 }
4051
Johannes Berg48ab9052009-07-10 18:42:31 +02004052 spin_unlock_bh(&rdev->bss_lock);
4053 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004054
4055 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004056 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004057
Johannes Berg67748892010-10-04 21:14:06 +02004058 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004059}
4060
Holger Schurig61fa7132009-11-11 12:25:40 +01004061static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4062 int flags, struct net_device *dev,
4063 struct survey_info *survey)
4064{
4065 void *hdr;
4066 struct nlattr *infoattr;
4067
Holger Schurig61fa7132009-11-11 12:25:40 +01004068 hdr = nl80211hdr_put(msg, pid, seq, flags,
4069 NL80211_CMD_NEW_SURVEY_RESULTS);
4070 if (!hdr)
4071 return -ENOMEM;
4072
4073 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4074
4075 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4076 if (!infoattr)
4077 goto nla_put_failure;
4078
4079 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4080 survey->channel->center_freq);
4081 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4082 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4083 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02004084 if (survey->filled & SURVEY_INFO_IN_USE)
4085 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02004086 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4087 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4088 survey->channel_time);
4089 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4090 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4091 survey->channel_time_busy);
4092 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4093 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4094 survey->channel_time_ext_busy);
4095 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4096 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4097 survey->channel_time_rx);
4098 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4099 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4100 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01004101
4102 nla_nest_end(msg, infoattr);
4103
4104 return genlmsg_end(msg, hdr);
4105
4106 nla_put_failure:
4107 genlmsg_cancel(msg, hdr);
4108 return -EMSGSIZE;
4109}
4110
4111static int nl80211_dump_survey(struct sk_buff *skb,
4112 struct netlink_callback *cb)
4113{
4114 struct survey_info survey;
4115 struct cfg80211_registered_device *dev;
4116 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004117 int survey_idx = cb->args[1];
4118 int res;
4119
Johannes Berg67748892010-10-04 21:14:06 +02004120 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4121 if (res)
4122 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004123
4124 if (!dev->ops->dump_survey) {
4125 res = -EOPNOTSUPP;
4126 goto out_err;
4127 }
4128
4129 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004130 struct ieee80211_channel *chan;
4131
Holger Schurig61fa7132009-11-11 12:25:40 +01004132 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4133 &survey);
4134 if (res == -ENOENT)
4135 break;
4136 if (res)
4137 goto out_err;
4138
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004139 /* Survey without a channel doesn't make sense */
4140 if (!survey.channel) {
4141 res = -EINVAL;
4142 goto out;
4143 }
4144
4145 chan = ieee80211_get_channel(&dev->wiphy,
4146 survey.channel->center_freq);
4147 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4148 survey_idx++;
4149 continue;
4150 }
4151
Holger Schurig61fa7132009-11-11 12:25:40 +01004152 if (nl80211_send_survey(skb,
4153 NETLINK_CB(cb->skb).pid,
4154 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4155 netdev,
4156 &survey) < 0)
4157 goto out;
4158 survey_idx++;
4159 }
4160
4161 out:
4162 cb->args[1] = survey_idx;
4163 res = skb->len;
4164 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004165 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004166 return res;
4167}
4168
Jouni Malinen255e7372009-03-20 21:21:17 +02004169static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4170{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004171 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004172}
4173
Samuel Ortizb23aa672009-07-01 21:26:54 +02004174static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4175{
4176 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4177 NL80211_WPA_VERSION_2));
4178}
4179
Jouni Malinen636a5d32009-03-19 13:39:22 +02004180static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4181{
Johannes Berg4c476992010-10-04 21:36:35 +02004182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4183 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004184 struct ieee80211_channel *chan;
4185 const u8 *bssid, *ssid, *ie = NULL;
4186 int err, ssid_len, ie_len = 0;
4187 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004188 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004189 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004190
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004191 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4192 return -EINVAL;
4193
4194 if (!info->attrs[NL80211_ATTR_MAC])
4195 return -EINVAL;
4196
Jouni Malinen17780922009-03-27 20:52:47 +02004197 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4198 return -EINVAL;
4199
Johannes Berg19957bb2009-07-02 17:20:43 +02004200 if (!info->attrs[NL80211_ATTR_SSID])
4201 return -EINVAL;
4202
4203 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4204 return -EINVAL;
4205
Johannes Bergfffd0932009-07-08 14:22:54 +02004206 err = nl80211_parse_key(info, &key);
4207 if (err)
4208 return err;
4209
4210 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004211 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4212 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004213 if (!key.p.key || !key.p.key_len)
4214 return -EINVAL;
4215 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4216 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4217 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4218 key.p.key_len != WLAN_KEY_LEN_WEP104))
4219 return -EINVAL;
4220 if (key.idx > 4)
4221 return -EINVAL;
4222 } else {
4223 key.p.key_len = 0;
4224 key.p.key = NULL;
4225 }
4226
Johannes Bergafea0b72010-08-10 09:46:42 +02004227 if (key.idx >= 0) {
4228 int i;
4229 bool ok = false;
4230 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4231 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4232 ok = true;
4233 break;
4234 }
4235 }
Johannes Berg4c476992010-10-04 21:36:35 +02004236 if (!ok)
4237 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004238 }
4239
Johannes Berg4c476992010-10-04 21:36:35 +02004240 if (!rdev->ops->auth)
4241 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004242
Johannes Berg074ac8d2010-09-16 14:58:22 +02004243 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004244 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4245 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004246
Johannes Berg19957bb2009-07-02 17:20:43 +02004247 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004248 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004249 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004250 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4251 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004252
Johannes Berg19957bb2009-07-02 17:20:43 +02004253 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4254 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4255
4256 if (info->attrs[NL80211_ATTR_IE]) {
4257 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4258 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4259 }
4260
4261 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004262 if (!nl80211_valid_auth_type(auth_type))
4263 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004264
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004265 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4266
Johannes Berg4c476992010-10-04 21:36:35 +02004267 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4268 ssid, ssid_len, ie, ie_len,
4269 key.p.key, key.p.key_len, key.idx,
4270 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004271}
4272
Johannes Bergc0692b82010-08-27 14:26:53 +03004273static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4274 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004275 struct cfg80211_crypto_settings *settings,
4276 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004277{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004278 memset(settings, 0, sizeof(*settings));
4279
Samuel Ortizb23aa672009-07-01 21:26:54 +02004280 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4281
Johannes Bergc0692b82010-08-27 14:26:53 +03004282 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4283 u16 proto;
4284 proto = nla_get_u16(
4285 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4286 settings->control_port_ethertype = cpu_to_be16(proto);
4287 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4288 proto != ETH_P_PAE)
4289 return -EINVAL;
4290 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4291 settings->control_port_no_encrypt = true;
4292 } else
4293 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4294
Samuel Ortizb23aa672009-07-01 21:26:54 +02004295 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4296 void *data;
4297 int len, i;
4298
4299 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4300 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4301 settings->n_ciphers_pairwise = len / sizeof(u32);
4302
4303 if (len % sizeof(u32))
4304 return -EINVAL;
4305
Johannes Berg3dc27d22009-07-02 21:36:37 +02004306 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004307 return -EINVAL;
4308
4309 memcpy(settings->ciphers_pairwise, data, len);
4310
4311 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004312 if (!cfg80211_supported_cipher_suite(
4313 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004314 settings->ciphers_pairwise[i]))
4315 return -EINVAL;
4316 }
4317
4318 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4319 settings->cipher_group =
4320 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004321 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4322 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004323 return -EINVAL;
4324 }
4325
4326 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4327 settings->wpa_versions =
4328 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4329 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4330 return -EINVAL;
4331 }
4332
4333 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4334 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004335 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004336
4337 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4338 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4339 settings->n_akm_suites = len / sizeof(u32);
4340
4341 if (len % sizeof(u32))
4342 return -EINVAL;
4343
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004344 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4345 return -EINVAL;
4346
Samuel Ortizb23aa672009-07-01 21:26:54 +02004347 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004348 }
4349
4350 return 0;
4351}
4352
Jouni Malinen636a5d32009-03-19 13:39:22 +02004353static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4354{
Johannes Berg4c476992010-10-04 21:36:35 +02004355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4356 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004357 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004358 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004359 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004360 int err, ssid_len, ie_len = 0;
4361 bool use_mfp = false;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004362
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004363 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4364 return -EINVAL;
4365
4366 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004367 !info->attrs[NL80211_ATTR_SSID] ||
4368 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004369 return -EINVAL;
4370
Johannes Berg4c476992010-10-04 21:36:35 +02004371 if (!rdev->ops->assoc)
4372 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004373
Johannes Berg074ac8d2010-09-16 14:58:22 +02004374 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004375 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4376 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004377
Johannes Berg19957bb2009-07-02 17:20:43 +02004378 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004379
Johannes Berg19957bb2009-07-02 17:20:43 +02004380 chan = ieee80211_get_channel(&rdev->wiphy,
4381 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004382 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4383 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004384
Johannes Berg19957bb2009-07-02 17:20:43 +02004385 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4386 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004387
4388 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004389 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4390 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004391 }
4392
Jouni Malinendc6382c2009-05-06 22:09:37 +03004393 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004394 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004395 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004396 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004397 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004398 else if (mfp != NL80211_MFP_NO)
4399 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004400 }
4401
Johannes Berg3e5d7642009-07-07 14:37:26 +02004402 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4403 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4404
Johannes Bergc0692b82010-08-27 14:26:53 +03004405 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004406 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004407 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4408 ssid, ssid_len, ie, ie_len, use_mfp,
Johannes Berg19957bb2009-07-02 17:20:43 +02004409 &crypto);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004410
Jouni Malinen636a5d32009-03-19 13:39:22 +02004411 return err;
4412}
4413
4414static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4415{
Johannes Berg4c476992010-10-04 21:36:35 +02004416 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4417 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004418 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004419 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004420 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004421 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004422
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004423 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4424 return -EINVAL;
4425
4426 if (!info->attrs[NL80211_ATTR_MAC])
4427 return -EINVAL;
4428
4429 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4430 return -EINVAL;
4431
Johannes Berg4c476992010-10-04 21:36:35 +02004432 if (!rdev->ops->deauth)
4433 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004434
Johannes Berg074ac8d2010-09-16 14:58:22 +02004435 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004436 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4437 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004438
Johannes Berg19957bb2009-07-02 17:20:43 +02004439 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004440
Johannes Berg19957bb2009-07-02 17:20:43 +02004441 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4442 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004443 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004444 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004445 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004446
4447 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004448 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4449 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004450 }
4451
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004452 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4453
Johannes Berg4c476992010-10-04 21:36:35 +02004454 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4455 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004456}
4457
4458static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4459{
Johannes Berg4c476992010-10-04 21:36:35 +02004460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4461 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004462 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004463 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004464 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004465 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004466
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004467 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4468 return -EINVAL;
4469
4470 if (!info->attrs[NL80211_ATTR_MAC])
4471 return -EINVAL;
4472
4473 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4474 return -EINVAL;
4475
Johannes Berg4c476992010-10-04 21:36:35 +02004476 if (!rdev->ops->disassoc)
4477 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004478
Johannes Berg074ac8d2010-09-16 14:58:22 +02004479 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004480 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4481 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004482
Johannes Berg19957bb2009-07-02 17:20:43 +02004483 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004484
Johannes Berg19957bb2009-07-02 17:20:43 +02004485 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4486 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004487 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004488 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004489 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004490
4491 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004492 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4493 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004494 }
4495
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004496 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4497
Johannes Berg4c476992010-10-04 21:36:35 +02004498 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4499 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004500}
4501
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004502static bool
4503nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4504 int mcast_rate[IEEE80211_NUM_BANDS],
4505 int rateval)
4506{
4507 struct wiphy *wiphy = &rdev->wiphy;
4508 bool found = false;
4509 int band, i;
4510
4511 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4512 struct ieee80211_supported_band *sband;
4513
4514 sband = wiphy->bands[band];
4515 if (!sband)
4516 continue;
4517
4518 for (i = 0; i < sband->n_bitrates; i++) {
4519 if (sband->bitrates[i].bitrate == rateval) {
4520 mcast_rate[band] = i + 1;
4521 found = true;
4522 break;
4523 }
4524 }
4525 }
4526
4527 return found;
4528}
4529
Johannes Berg04a773a2009-04-19 21:24:32 +02004530static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4531{
Johannes Berg4c476992010-10-04 21:36:35 +02004532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4533 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004534 struct cfg80211_ibss_params ibss;
4535 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004536 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004537 int err;
4538
Johannes Berg8e30bc52009-04-22 17:45:38 +02004539 memset(&ibss, 0, sizeof(ibss));
4540
Johannes Berg04a773a2009-04-19 21:24:32 +02004541 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4542 return -EINVAL;
4543
4544 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4545 !info->attrs[NL80211_ATTR_SSID] ||
4546 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4547 return -EINVAL;
4548
Johannes Berg8e30bc52009-04-22 17:45:38 +02004549 ibss.beacon_interval = 100;
4550
4551 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4552 ibss.beacon_interval =
4553 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4554 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4555 return -EINVAL;
4556 }
4557
Johannes Berg4c476992010-10-04 21:36:35 +02004558 if (!rdev->ops->join_ibss)
4559 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004560
Johannes Berg4c476992010-10-04 21:36:35 +02004561 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4562 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004563
Johannes Berg79c97e92009-07-07 03:56:12 +02004564 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004565
Johannes Berg39193492011-09-16 13:45:25 +02004566 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02004567 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02004568
4569 if (!is_valid_ether_addr(ibss.bssid))
4570 return -EINVAL;
4571 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004572 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4573 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4574
4575 if (info->attrs[NL80211_ATTR_IE]) {
4576 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4577 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4578 }
4579
4580 ibss.channel = ieee80211_get_channel(wiphy,
4581 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4582 if (!ibss.channel ||
4583 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004584 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4585 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004586
4587 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004588 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004589
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004590 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4591 u8 *rates =
4592 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4593 int n_rates =
4594 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4595 struct ieee80211_supported_band *sband =
4596 wiphy->bands[ibss.channel->band];
Johannes Berg34850ab2011-07-18 18:08:35 +02004597 int err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004598
Johannes Berg34850ab2011-07-18 18:08:35 +02004599 err = ieee80211_get_ratemask(sband, rates, n_rates,
4600 &ibss.basic_rates);
4601 if (err)
4602 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004603 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004604
4605 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4606 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4607 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4608 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004609
Johannes Berg4c476992010-10-04 21:36:35 +02004610 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4611 connkeys = nl80211_parse_connkeys(rdev,
4612 info->attrs[NL80211_ATTR_KEYS]);
4613 if (IS_ERR(connkeys))
4614 return PTR_ERR(connkeys);
4615 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004616
Johannes Berg4c476992010-10-04 21:36:35 +02004617 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004618 if (err)
4619 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004620 return err;
4621}
4622
4623static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4624{
Johannes Berg4c476992010-10-04 21:36:35 +02004625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4626 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004627
Johannes Berg4c476992010-10-04 21:36:35 +02004628 if (!rdev->ops->leave_ibss)
4629 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004630
Johannes Berg4c476992010-10-04 21:36:35 +02004631 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4632 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004633
Johannes Berg4c476992010-10-04 21:36:35 +02004634 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004635}
4636
Johannes Bergaff89a92009-07-01 21:26:51 +02004637#ifdef CONFIG_NL80211_TESTMODE
4638static struct genl_multicast_group nl80211_testmode_mcgrp = {
4639 .name = "testmode",
4640};
4641
4642static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4643{
Johannes Berg4c476992010-10-04 21:36:35 +02004644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004645 int err;
4646
4647 if (!info->attrs[NL80211_ATTR_TESTDATA])
4648 return -EINVAL;
4649
Johannes Bergaff89a92009-07-01 21:26:51 +02004650 err = -EOPNOTSUPP;
4651 if (rdev->ops->testmode_cmd) {
4652 rdev->testmode_info = info;
4653 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4654 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4655 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4656 rdev->testmode_info = NULL;
4657 }
4658
Johannes Bergaff89a92009-07-01 21:26:51 +02004659 return err;
4660}
4661
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004662static int nl80211_testmode_dump(struct sk_buff *skb,
4663 struct netlink_callback *cb)
4664{
4665 struct cfg80211_registered_device *dev;
4666 int err;
4667 long phy_idx;
4668 void *data = NULL;
4669 int data_len = 0;
4670
4671 if (cb->args[0]) {
4672 /*
4673 * 0 is a valid index, but not valid for args[0],
4674 * so we need to offset by 1.
4675 */
4676 phy_idx = cb->args[0] - 1;
4677 } else {
4678 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4679 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4680 nl80211_policy);
4681 if (err)
4682 return err;
4683 if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY])
4684 return -EINVAL;
4685 phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4686 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4687 cb->args[1] =
4688 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4689 }
4690
4691 if (cb->args[1]) {
4692 data = nla_data((void *)cb->args[1]);
4693 data_len = nla_len((void *)cb->args[1]);
4694 }
4695
4696 mutex_lock(&cfg80211_mutex);
4697 dev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4698 if (!dev) {
4699 mutex_unlock(&cfg80211_mutex);
4700 return -ENOENT;
4701 }
4702 cfg80211_lock_rdev(dev);
4703 mutex_unlock(&cfg80211_mutex);
4704
4705 if (!dev->ops->testmode_dump) {
4706 err = -EOPNOTSUPP;
4707 goto out_err;
4708 }
4709
4710 while (1) {
4711 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4712 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4713 NL80211_CMD_TESTMODE);
4714 struct nlattr *tmdata;
4715
4716 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) {
4717 genlmsg_cancel(skb, hdr);
4718 break;
4719 }
4720
4721 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4722 if (!tmdata) {
4723 genlmsg_cancel(skb, hdr);
4724 break;
4725 }
4726 err = dev->ops->testmode_dump(&dev->wiphy, skb, cb,
4727 data, data_len);
4728 nla_nest_end(skb, tmdata);
4729
4730 if (err == -ENOBUFS || err == -ENOENT) {
4731 genlmsg_cancel(skb, hdr);
4732 break;
4733 } else if (err) {
4734 genlmsg_cancel(skb, hdr);
4735 goto out_err;
4736 }
4737
4738 genlmsg_end(skb, hdr);
4739 }
4740
4741 err = skb->len;
4742 /* see above */
4743 cb->args[0] = phy_idx + 1;
4744 out_err:
4745 cfg80211_unlock_rdev(dev);
4746 return err;
4747}
4748
Johannes Bergaff89a92009-07-01 21:26:51 +02004749static struct sk_buff *
4750__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4751 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4752{
4753 struct sk_buff *skb;
4754 void *hdr;
4755 struct nlattr *data;
4756
4757 skb = nlmsg_new(approxlen + 100, gfp);
4758 if (!skb)
4759 return NULL;
4760
4761 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4762 if (!hdr) {
4763 kfree_skb(skb);
4764 return NULL;
4765 }
4766
4767 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4768 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4769
4770 ((void **)skb->cb)[0] = rdev;
4771 ((void **)skb->cb)[1] = hdr;
4772 ((void **)skb->cb)[2] = data;
4773
4774 return skb;
4775
4776 nla_put_failure:
4777 kfree_skb(skb);
4778 return NULL;
4779}
4780
4781struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4782 int approxlen)
4783{
4784 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4785
4786 if (WARN_ON(!rdev->testmode_info))
4787 return NULL;
4788
4789 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4790 rdev->testmode_info->snd_pid,
4791 rdev->testmode_info->snd_seq,
4792 GFP_KERNEL);
4793}
4794EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4795
4796int cfg80211_testmode_reply(struct sk_buff *skb)
4797{
4798 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4799 void *hdr = ((void **)skb->cb)[1];
4800 struct nlattr *data = ((void **)skb->cb)[2];
4801
4802 if (WARN_ON(!rdev->testmode_info)) {
4803 kfree_skb(skb);
4804 return -EINVAL;
4805 }
4806
4807 nla_nest_end(skb, data);
4808 genlmsg_end(skb, hdr);
4809 return genlmsg_reply(skb, rdev->testmode_info);
4810}
4811EXPORT_SYMBOL(cfg80211_testmode_reply);
4812
4813struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
4814 int approxlen, gfp_t gfp)
4815{
4816 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4817
4818 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
4819}
4820EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
4821
4822void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
4823{
4824 void *hdr = ((void **)skb->cb)[1];
4825 struct nlattr *data = ((void **)skb->cb)[2];
4826
4827 nla_nest_end(skb, data);
4828 genlmsg_end(skb, hdr);
4829 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
4830}
4831EXPORT_SYMBOL(cfg80211_testmode_event);
4832#endif
4833
Samuel Ortizb23aa672009-07-01 21:26:54 +02004834static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
4835{
Johannes Berg4c476992010-10-04 21:36:35 +02004836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4837 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004838 struct cfg80211_connect_params connect;
4839 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004840 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004841 int err;
4842
4843 memset(&connect, 0, sizeof(connect));
4844
4845 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4846 return -EINVAL;
4847
4848 if (!info->attrs[NL80211_ATTR_SSID] ||
4849 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4850 return -EINVAL;
4851
4852 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4853 connect.auth_type =
4854 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4855 if (!nl80211_valid_auth_type(connect.auth_type))
4856 return -EINVAL;
4857 } else
4858 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4859
4860 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
4861
Johannes Bergc0692b82010-08-27 14:26:53 +03004862 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004863 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004864 if (err)
4865 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004866
Johannes Berg074ac8d2010-09-16 14:58:22 +02004867 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004868 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4869 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004870
Johannes Berg79c97e92009-07-07 03:56:12 +02004871 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004872
Samuel Ortizb23aa672009-07-01 21:26:54 +02004873 if (info->attrs[NL80211_ATTR_MAC])
4874 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4875 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4876 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4877
4878 if (info->attrs[NL80211_ATTR_IE]) {
4879 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4880 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4881 }
4882
4883 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
4884 connect.channel =
4885 ieee80211_get_channel(wiphy,
4886 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4887 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02004888 connect.channel->flags & IEEE80211_CHAN_DISABLED)
4889 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004890 }
4891
Johannes Bergfffd0932009-07-08 14:22:54 +02004892 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4893 connkeys = nl80211_parse_connkeys(rdev,
4894 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02004895 if (IS_ERR(connkeys))
4896 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004897 }
4898
4899 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004900 if (err)
4901 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004902 return err;
4903}
4904
4905static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
4906{
Johannes Berg4c476992010-10-04 21:36:35 +02004907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4908 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02004909 u16 reason;
4910
4911 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4912 reason = WLAN_REASON_DEAUTH_LEAVING;
4913 else
4914 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4915
4916 if (reason == 0)
4917 return -EINVAL;
4918
Johannes Berg074ac8d2010-09-16 14:58:22 +02004919 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004920 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4921 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004922
Johannes Berg4c476992010-10-04 21:36:35 +02004923 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004924}
4925
Johannes Berg463d0182009-07-14 00:33:35 +02004926static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
4927{
Johannes Berg4c476992010-10-04 21:36:35 +02004928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02004929 struct net *net;
4930 int err;
4931 u32 pid;
4932
4933 if (!info->attrs[NL80211_ATTR_PID])
4934 return -EINVAL;
4935
4936 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
4937
Johannes Berg463d0182009-07-14 00:33:35 +02004938 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02004939 if (IS_ERR(net))
4940 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004941
4942 err = 0;
4943
4944 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02004945 if (!net_eq(wiphy_net(&rdev->wiphy), net))
4946 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02004947
Johannes Berg463d0182009-07-14 00:33:35 +02004948 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02004949 return err;
4950}
4951
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004952static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
4953{
Johannes Berg4c476992010-10-04 21:36:35 +02004954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004955 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
4956 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004957 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004958 struct cfg80211_pmksa pmksa;
4959
4960 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
4961
4962 if (!info->attrs[NL80211_ATTR_MAC])
4963 return -EINVAL;
4964
4965 if (!info->attrs[NL80211_ATTR_PMKID])
4966 return -EINVAL;
4967
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004968 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
4969 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4970
Johannes Berg074ac8d2010-09-16 14:58:22 +02004971 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004972 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4973 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004974
4975 switch (info->genlhdr->cmd) {
4976 case NL80211_CMD_SET_PMKSA:
4977 rdev_ops = rdev->ops->set_pmksa;
4978 break;
4979 case NL80211_CMD_DEL_PMKSA:
4980 rdev_ops = rdev->ops->del_pmksa;
4981 break;
4982 default:
4983 WARN_ON(1);
4984 break;
4985 }
4986
Johannes Berg4c476992010-10-04 21:36:35 +02004987 if (!rdev_ops)
4988 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004989
Johannes Berg4c476992010-10-04 21:36:35 +02004990 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004991}
4992
4993static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
4994{
Johannes Berg4c476992010-10-04 21:36:35 +02004995 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4996 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01004997
Johannes Berg074ac8d2010-09-16 14:58:22 +02004998 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004999 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5000 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005001
Johannes Berg4c476992010-10-04 21:36:35 +02005002 if (!rdev->ops->flush_pmksa)
5003 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005004
Johannes Berg4c476992010-10-04 21:36:35 +02005005 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005006}
5007
Arik Nemtsov109086c2011-09-28 14:12:50 +03005008static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5009{
5010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5011 struct net_device *dev = info->user_ptr[1];
5012 u8 action_code, dialog_token;
5013 u16 status_code;
5014 u8 *peer;
5015
5016 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5017 !rdev->ops->tdls_mgmt)
5018 return -EOPNOTSUPP;
5019
5020 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5021 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5022 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5023 !info->attrs[NL80211_ATTR_IE] ||
5024 !info->attrs[NL80211_ATTR_MAC])
5025 return -EINVAL;
5026
5027 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5028 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5029 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5030 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5031
5032 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5033 dialog_token, status_code,
5034 nla_data(info->attrs[NL80211_ATTR_IE]),
5035 nla_len(info->attrs[NL80211_ATTR_IE]));
5036}
5037
5038static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5039{
5040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5041 struct net_device *dev = info->user_ptr[1];
5042 enum nl80211_tdls_operation operation;
5043 u8 *peer;
5044
5045 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5046 !rdev->ops->tdls_oper)
5047 return -EOPNOTSUPP;
5048
5049 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5050 !info->attrs[NL80211_ATTR_MAC])
5051 return -EINVAL;
5052
5053 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5054 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5055
5056 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5057}
5058
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005059static int nl80211_remain_on_channel(struct sk_buff *skb,
5060 struct genl_info *info)
5061{
Johannes Berg4c476992010-10-04 21:36:35 +02005062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5063 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005064 struct ieee80211_channel *chan;
5065 struct sk_buff *msg;
5066 void *hdr;
5067 u64 cookie;
5068 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5069 u32 freq, duration;
5070 int err;
5071
5072 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5073 !info->attrs[NL80211_ATTR_DURATION])
5074 return -EINVAL;
5075
5076 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5077
5078 /*
5079 * We should be on that channel for at least one jiffie,
5080 * and more than 5 seconds seems excessive.
5081 */
Johannes Berga2939112010-12-14 17:54:28 +01005082 if (!duration || !msecs_to_jiffies(duration) ||
5083 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005084 return -EINVAL;
5085
Johannes Berg4c476992010-10-04 21:36:35 +02005086 if (!rdev->ops->remain_on_channel)
5087 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005088
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005089 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5090 channel_type = nla_get_u32(
5091 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5092 if (channel_type != NL80211_CHAN_NO_HT &&
5093 channel_type != NL80211_CHAN_HT20 &&
5094 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005095 channel_type != NL80211_CHAN_HT40MINUS)
5096 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005097 }
5098
5099 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5100 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005101 if (chan == NULL)
5102 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005103
5104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005105 if (!msg)
5106 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005107
5108 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5109 NL80211_CMD_REMAIN_ON_CHANNEL);
5110
5111 if (IS_ERR(hdr)) {
5112 err = PTR_ERR(hdr);
5113 goto free_msg;
5114 }
5115
5116 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5117 channel_type, duration, &cookie);
5118
5119 if (err)
5120 goto free_msg;
5121
5122 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5123
5124 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005125
5126 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005127
5128 nla_put_failure:
5129 err = -ENOBUFS;
5130 free_msg:
5131 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005132 return err;
5133}
5134
5135static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5136 struct genl_info *info)
5137{
Johannes Berg4c476992010-10-04 21:36:35 +02005138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5139 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005140 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005141
5142 if (!info->attrs[NL80211_ATTR_COOKIE])
5143 return -EINVAL;
5144
Johannes Berg4c476992010-10-04 21:36:35 +02005145 if (!rdev->ops->cancel_remain_on_channel)
5146 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005147
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005148 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5149
Johannes Berg4c476992010-10-04 21:36:35 +02005150 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005151}
5152
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005153static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5154 u8 *rates, u8 rates_len)
5155{
5156 u8 i;
5157 u32 mask = 0;
5158
5159 for (i = 0; i < rates_len; i++) {
5160 int rate = (rates[i] & 0x7f) * 5;
5161 int ridx;
5162 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5163 struct ieee80211_rate *srate =
5164 &sband->bitrates[ridx];
5165 if (rate == srate->bitrate) {
5166 mask |= 1 << ridx;
5167 break;
5168 }
5169 }
5170 if (ridx == sband->n_bitrates)
5171 return 0; /* rate not found */
5172 }
5173
5174 return mask;
5175}
5176
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005177static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005178 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5179 .len = NL80211_MAX_SUPP_RATES },
5180};
5181
5182static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5183 struct genl_info *info)
5184{
5185 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005187 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005188 int rem, i;
5189 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005190 struct nlattr *tx_rates;
5191 struct ieee80211_supported_band *sband;
5192
5193 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5194 return -EINVAL;
5195
Johannes Berg4c476992010-10-04 21:36:35 +02005196 if (!rdev->ops->set_bitrate_mask)
5197 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005198
5199 memset(&mask, 0, sizeof(mask));
5200 /* Default to all rates enabled */
5201 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5202 sband = rdev->wiphy.bands[i];
5203 mask.control[i].legacy =
5204 sband ? (1 << sband->n_bitrates) - 1 : 0;
5205 }
5206
5207 /*
5208 * The nested attribute uses enum nl80211_band as the index. This maps
5209 * directly to the enum ieee80211_band values used in cfg80211.
5210 */
5211 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5212 {
5213 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005214 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5215 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005216 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005217 if (sband == NULL)
5218 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005219 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5220 nla_len(tx_rates), nl80211_txattr_policy);
5221 if (tb[NL80211_TXRATE_LEGACY]) {
5222 mask.control[band].legacy = rateset_to_mask(
5223 sband,
5224 nla_data(tb[NL80211_TXRATE_LEGACY]),
5225 nla_len(tb[NL80211_TXRATE_LEGACY]));
Johannes Berg4c476992010-10-04 21:36:35 +02005226 if (mask.control[band].legacy == 0)
5227 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005228 }
5229 }
5230
Johannes Berg4c476992010-10-04 21:36:35 +02005231 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005232}
5233
Johannes Berg2e161f72010-08-12 15:38:38 +02005234static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005235{
Johannes Berg4c476992010-10-04 21:36:35 +02005236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5237 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005238 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005239
5240 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5241 return -EINVAL;
5242
Johannes Berg2e161f72010-08-12 15:38:38 +02005243 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5244 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005245
Johannes Berg9d38d852010-06-09 17:20:33 +02005246 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005247 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005248 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5249 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5250 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005251 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005252 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5253 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005254
5255 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005256 if (!rdev->ops->mgmt_tx)
5257 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005258
Johannes Berg4c476992010-10-04 21:36:35 +02005259 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005260 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005261 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5262 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005263}
5264
Johannes Berg2e161f72010-08-12 15:38:38 +02005265static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005266{
Johannes Berg4c476992010-10-04 21:36:35 +02005267 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5268 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005269 struct ieee80211_channel *chan;
5270 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005271 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005272 u32 freq;
5273 int err;
5274 void *hdr;
5275 u64 cookie;
5276 struct sk_buff *msg;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005277 unsigned int wait = 0;
5278 bool offchan;
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305279 bool no_cck;
Jouni Malinen026331c2010-02-15 12:53:10 +02005280
5281 if (!info->attrs[NL80211_ATTR_FRAME] ||
5282 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5283 return -EINVAL;
5284
Johannes Berg4c476992010-10-04 21:36:35 +02005285 if (!rdev->ops->mgmt_tx)
5286 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005287
Johannes Berg9d38d852010-06-09 17:20:33 +02005288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5291 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5292 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005293 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5295 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005296
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005297 if (info->attrs[NL80211_ATTR_DURATION]) {
5298 if (!rdev->ops->mgmt_tx_cancel_wait)
5299 return -EINVAL;
5300 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5301 }
5302
Jouni Malinen026331c2010-02-15 12:53:10 +02005303 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5304 channel_type = nla_get_u32(
5305 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5306 if (channel_type != NL80211_CHAN_NO_HT &&
5307 channel_type != NL80211_CHAN_HT20 &&
5308 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005309 channel_type != NL80211_CHAN_HT40MINUS)
5310 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005311 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005312 }
5313
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005314 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5315
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305316 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5317
Jouni Malinen026331c2010-02-15 12:53:10 +02005318 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5319 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005320 if (chan == NULL)
5321 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005322
5323 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005324 if (!msg)
5325 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005326
5327 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg2e161f72010-08-12 15:38:38 +02005328 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005329
5330 if (IS_ERR(hdr)) {
5331 err = PTR_ERR(hdr);
5332 goto free_msg;
5333 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005334 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5335 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005336 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5337 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305338 no_cck, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005339 if (err)
5340 goto free_msg;
5341
5342 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5343
5344 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005345 return genlmsg_reply(msg, info);
Jouni Malinen026331c2010-02-15 12:53:10 +02005346
5347 nla_put_failure:
5348 err = -ENOBUFS;
5349 free_msg:
5350 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005351 return err;
5352}
5353
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005354static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5355{
5356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5357 struct net_device *dev = info->user_ptr[1];
5358 u64 cookie;
5359
5360 if (!info->attrs[NL80211_ATTR_COOKIE])
5361 return -EINVAL;
5362
5363 if (!rdev->ops->mgmt_tx_cancel_wait)
5364 return -EOPNOTSUPP;
5365
5366 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5368 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5369 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5370 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5371 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5372 return -EOPNOTSUPP;
5373
5374 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5375
5376 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5377}
5378
Kalle Valoffb9eb32010-02-17 17:58:10 +02005379static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5380{
Johannes Berg4c476992010-10-04 21:36:35 +02005381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005382 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005383 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005384 u8 ps_state;
5385 bool state;
5386 int err;
5387
Johannes Berg4c476992010-10-04 21:36:35 +02005388 if (!info->attrs[NL80211_ATTR_PS_STATE])
5389 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005390
5391 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5392
Johannes Berg4c476992010-10-04 21:36:35 +02005393 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5394 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005395
5396 wdev = dev->ieee80211_ptr;
5397
Johannes Berg4c476992010-10-04 21:36:35 +02005398 if (!rdev->ops->set_power_mgmt)
5399 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005400
5401 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5402
5403 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005404 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005405
Johannes Berg4c476992010-10-04 21:36:35 +02005406 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5407 wdev->ps_timeout);
5408 if (!err)
5409 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005410 return err;
5411}
5412
5413static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5414{
Johannes Berg4c476992010-10-04 21:36:35 +02005415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005416 enum nl80211_ps_state ps_state;
5417 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005418 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005419 struct sk_buff *msg;
5420 void *hdr;
5421 int err;
5422
Kalle Valoffb9eb32010-02-17 17:58:10 +02005423 wdev = dev->ieee80211_ptr;
5424
Johannes Berg4c476992010-10-04 21:36:35 +02005425 if (!rdev->ops->set_power_mgmt)
5426 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005427
5428 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005429 if (!msg)
5430 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005431
5432 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5433 NL80211_CMD_GET_POWER_SAVE);
5434 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005435 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005436 goto free_msg;
5437 }
5438
5439 if (wdev->ps)
5440 ps_state = NL80211_PS_ENABLED;
5441 else
5442 ps_state = NL80211_PS_DISABLED;
5443
5444 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5445
5446 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005447 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005448
Johannes Berg4c476992010-10-04 21:36:35 +02005449 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005450 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005451 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005452 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005453 return err;
5454}
5455
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005456static struct nla_policy
5457nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5458 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5459 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5460 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5461};
5462
5463static int nl80211_set_cqm_rssi(struct genl_info *info,
5464 s32 threshold, u32 hysteresis)
5465{
Johannes Berg4c476992010-10-04 21:36:35 +02005466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005467 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005468 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005469
5470 if (threshold > 0)
5471 return -EINVAL;
5472
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005473 wdev = dev->ieee80211_ptr;
5474
Johannes Berg4c476992010-10-04 21:36:35 +02005475 if (!rdev->ops->set_cqm_rssi_config)
5476 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005477
Johannes Berg074ac8d2010-09-16 14:58:22 +02005478 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005479 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5480 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005481
Johannes Berg4c476992010-10-04 21:36:35 +02005482 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5483 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005484}
5485
5486static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5487{
5488 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5489 struct nlattr *cqm;
5490 int err;
5491
5492 cqm = info->attrs[NL80211_ATTR_CQM];
5493 if (!cqm) {
5494 err = -EINVAL;
5495 goto out;
5496 }
5497
5498 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5499 nl80211_attr_cqm_policy);
5500 if (err)
5501 goto out;
5502
5503 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5504 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5505 s32 threshold;
5506 u32 hysteresis;
5507 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5508 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5509 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5510 } else
5511 err = -EINVAL;
5512
5513out:
5514 return err;
5515}
5516
Johannes Berg29cbe682010-12-03 09:20:44 +01005517static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5518{
5519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5520 struct net_device *dev = info->user_ptr[1];
5521 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005522 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005523 int err;
5524
5525 /* start with default */
5526 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005527 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005528
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005529 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005530 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005531 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005532 if (err)
5533 return err;
5534 }
5535
5536 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5537 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5538 return -EINVAL;
5539
Javier Cardonac80d5452010-12-16 17:37:49 -08005540 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5541 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5542
5543 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5544 /* parse additional setup parameters if given */
5545 err = nl80211_parse_mesh_setup(info, &setup);
5546 if (err)
5547 return err;
5548 }
5549
5550 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005551}
5552
5553static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5554{
5555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5556 struct net_device *dev = info->user_ptr[1];
5557
5558 return cfg80211_leave_mesh(rdev, dev);
5559}
5560
Johannes Bergff1b6e62011-05-04 15:37:28 +02005561static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5562{
5563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5564 struct sk_buff *msg;
5565 void *hdr;
5566
5567 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5568 return -EOPNOTSUPP;
5569
5570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5571 if (!msg)
5572 return -ENOMEM;
5573
5574 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5575 NL80211_CMD_GET_WOWLAN);
5576 if (!hdr)
5577 goto nla_put_failure;
5578
5579 if (rdev->wowlan) {
5580 struct nlattr *nl_wowlan;
5581
5582 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5583 if (!nl_wowlan)
5584 goto nla_put_failure;
5585
5586 if (rdev->wowlan->any)
5587 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5588 if (rdev->wowlan->disconnect)
5589 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5590 if (rdev->wowlan->magic_pkt)
5591 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005592 if (rdev->wowlan->gtk_rekey_failure)
5593 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5594 if (rdev->wowlan->eap_identity_req)
5595 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5596 if (rdev->wowlan->four_way_handshake)
5597 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5598 if (rdev->wowlan->rfkill_release)
5599 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005600 if (rdev->wowlan->n_patterns) {
5601 struct nlattr *nl_pats, *nl_pat;
5602 int i, pat_len;
5603
5604 nl_pats = nla_nest_start(msg,
5605 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5606 if (!nl_pats)
5607 goto nla_put_failure;
5608
5609 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5610 nl_pat = nla_nest_start(msg, i + 1);
5611 if (!nl_pat)
5612 goto nla_put_failure;
5613 pat_len = rdev->wowlan->patterns[i].pattern_len;
5614 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5615 DIV_ROUND_UP(pat_len, 8),
5616 rdev->wowlan->patterns[i].mask);
5617 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5618 pat_len,
5619 rdev->wowlan->patterns[i].pattern);
5620 nla_nest_end(msg, nl_pat);
5621 }
5622 nla_nest_end(msg, nl_pats);
5623 }
5624
5625 nla_nest_end(msg, nl_wowlan);
5626 }
5627
5628 genlmsg_end(msg, hdr);
5629 return genlmsg_reply(msg, info);
5630
5631nla_put_failure:
5632 nlmsg_free(msg);
5633 return -ENOBUFS;
5634}
5635
5636static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5637{
5638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5639 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5640 struct cfg80211_wowlan no_triggers = {};
5641 struct cfg80211_wowlan new_triggers = {};
5642 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5643 int err, i;
5644
5645 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5646 return -EOPNOTSUPP;
5647
5648 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5649 goto no_triggers;
5650
5651 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5652 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5653 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5654 nl80211_wowlan_policy);
5655 if (err)
5656 return err;
5657
5658 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5659 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5660 return -EINVAL;
5661 new_triggers.any = true;
5662 }
5663
5664 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5665 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5666 return -EINVAL;
5667 new_triggers.disconnect = true;
5668 }
5669
5670 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5671 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5672 return -EINVAL;
5673 new_triggers.magic_pkt = true;
5674 }
5675
Johannes Berg77dbbb12011-07-13 10:48:55 +02005676 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5677 return -EINVAL;
5678
5679 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5680 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5681 return -EINVAL;
5682 new_triggers.gtk_rekey_failure = true;
5683 }
5684
5685 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5686 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5687 return -EINVAL;
5688 new_triggers.eap_identity_req = true;
5689 }
5690
5691 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5692 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5693 return -EINVAL;
5694 new_triggers.four_way_handshake = true;
5695 }
5696
5697 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5698 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5699 return -EINVAL;
5700 new_triggers.rfkill_release = true;
5701 }
5702
Johannes Bergff1b6e62011-05-04 15:37:28 +02005703 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5704 struct nlattr *pat;
5705 int n_patterns = 0;
5706 int rem, pat_len, mask_len;
5707 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5708
5709 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5710 rem)
5711 n_patterns++;
5712 if (n_patterns > wowlan->n_patterns)
5713 return -EINVAL;
5714
5715 new_triggers.patterns = kcalloc(n_patterns,
5716 sizeof(new_triggers.patterns[0]),
5717 GFP_KERNEL);
5718 if (!new_triggers.patterns)
5719 return -ENOMEM;
5720
5721 new_triggers.n_patterns = n_patterns;
5722 i = 0;
5723
5724 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5725 rem) {
5726 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5727 nla_data(pat), nla_len(pat), NULL);
5728 err = -EINVAL;
5729 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5730 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5731 goto error;
5732 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5733 mask_len = DIV_ROUND_UP(pat_len, 8);
5734 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5735 mask_len)
5736 goto error;
5737 if (pat_len > wowlan->pattern_max_len ||
5738 pat_len < wowlan->pattern_min_len)
5739 goto error;
5740
5741 new_triggers.patterns[i].mask =
5742 kmalloc(mask_len + pat_len, GFP_KERNEL);
5743 if (!new_triggers.patterns[i].mask) {
5744 err = -ENOMEM;
5745 goto error;
5746 }
5747 new_triggers.patterns[i].pattern =
5748 new_triggers.patterns[i].mask + mask_len;
5749 memcpy(new_triggers.patterns[i].mask,
5750 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5751 mask_len);
5752 new_triggers.patterns[i].pattern_len = pat_len;
5753 memcpy(new_triggers.patterns[i].pattern,
5754 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5755 pat_len);
5756 i++;
5757 }
5758 }
5759
5760 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5761 struct cfg80211_wowlan *ntrig;
5762 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
5763 GFP_KERNEL);
5764 if (!ntrig) {
5765 err = -ENOMEM;
5766 goto error;
5767 }
5768 cfg80211_rdev_free_wowlan(rdev);
5769 rdev->wowlan = ntrig;
5770 } else {
5771 no_triggers:
5772 cfg80211_rdev_free_wowlan(rdev);
5773 rdev->wowlan = NULL;
5774 }
5775
5776 return 0;
5777 error:
5778 for (i = 0; i < new_triggers.n_patterns; i++)
5779 kfree(new_triggers.patterns[i].mask);
5780 kfree(new_triggers.patterns);
5781 return err;
5782}
5783
Johannes Berge5497d72011-07-05 16:35:40 +02005784static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
5785{
5786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5787 struct net_device *dev = info->user_ptr[1];
5788 struct wireless_dev *wdev = dev->ieee80211_ptr;
5789 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
5790 struct cfg80211_gtk_rekey_data rekey_data;
5791 int err;
5792
5793 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
5794 return -EINVAL;
5795
5796 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
5797 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
5798 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
5799 nl80211_rekey_policy);
5800 if (err)
5801 return err;
5802
5803 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
5804 return -ERANGE;
5805 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
5806 return -ERANGE;
5807 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
5808 return -ERANGE;
5809
5810 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
5811 NL80211_KEK_LEN);
5812 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
5813 NL80211_KCK_LEN);
5814 memcpy(rekey_data.replay_ctr,
5815 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
5816 NL80211_REPLAY_CTR_LEN);
5817
5818 wdev_lock(wdev);
5819 if (!wdev->current_bss) {
5820 err = -ENOTCONN;
5821 goto out;
5822 }
5823
5824 if (!rdev->ops->set_rekey_data) {
5825 err = -EOPNOTSUPP;
5826 goto out;
5827 }
5828
5829 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
5830 out:
5831 wdev_unlock(wdev);
5832 return err;
5833}
5834
Johannes Berg28946da2011-11-04 11:18:12 +01005835static int nl80211_register_unexpected_frame(struct sk_buff *skb,
5836 struct genl_info *info)
5837{
5838 struct net_device *dev = info->user_ptr[1];
5839 struct wireless_dev *wdev = dev->ieee80211_ptr;
5840
5841 if (wdev->iftype != NL80211_IFTYPE_AP &&
5842 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5843 return -EINVAL;
5844
5845 if (wdev->ap_unexpected_nlpid)
5846 return -EBUSY;
5847
5848 wdev->ap_unexpected_nlpid = info->snd_pid;
5849 return 0;
5850}
5851
Johannes Berg4c476992010-10-04 21:36:35 +02005852#define NL80211_FLAG_NEED_WIPHY 0x01
5853#define NL80211_FLAG_NEED_NETDEV 0x02
5854#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02005855#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5856#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5857 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02005858
5859static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
5860 struct genl_info *info)
5861{
5862 struct cfg80211_registered_device *rdev;
5863 struct net_device *dev;
5864 int err;
5865 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
5866
5867 if (rtnl)
5868 rtnl_lock();
5869
5870 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
5871 rdev = cfg80211_get_dev_from_info(info);
5872 if (IS_ERR(rdev)) {
5873 if (rtnl)
5874 rtnl_unlock();
5875 return PTR_ERR(rdev);
5876 }
5877 info->user_ptr[0] = rdev;
5878 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
5879 err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev);
5880 if (err) {
5881 if (rtnl)
5882 rtnl_unlock();
5883 return err;
5884 }
Johannes Berg41265712010-10-04 21:14:05 +02005885 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
5886 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02005887 cfg80211_unlock_rdev(rdev);
5888 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02005889 if (rtnl)
5890 rtnl_unlock();
5891 return -ENETDOWN;
5892 }
Johannes Berg4c476992010-10-04 21:36:35 +02005893 info->user_ptr[0] = rdev;
5894 info->user_ptr[1] = dev;
5895 }
5896
5897 return 0;
5898}
5899
5900static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
5901 struct genl_info *info)
5902{
5903 if (info->user_ptr[0])
5904 cfg80211_unlock_rdev(info->user_ptr[0]);
5905 if (info->user_ptr[1])
5906 dev_put(info->user_ptr[1]);
5907 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
5908 rtnl_unlock();
5909}
5910
Johannes Berg55682962007-09-20 13:09:35 -04005911static struct genl_ops nl80211_ops[] = {
5912 {
5913 .cmd = NL80211_CMD_GET_WIPHY,
5914 .doit = nl80211_get_wiphy,
5915 .dumpit = nl80211_dump_wiphy,
5916 .policy = nl80211_policy,
5917 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005918 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04005919 },
5920 {
5921 .cmd = NL80211_CMD_SET_WIPHY,
5922 .doit = nl80211_set_wiphy,
5923 .policy = nl80211_policy,
5924 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005925 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005926 },
5927 {
5928 .cmd = NL80211_CMD_GET_INTERFACE,
5929 .doit = nl80211_get_interface,
5930 .dumpit = nl80211_dump_interface,
5931 .policy = nl80211_policy,
5932 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02005933 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04005934 },
5935 {
5936 .cmd = NL80211_CMD_SET_INTERFACE,
5937 .doit = nl80211_set_interface,
5938 .policy = nl80211_policy,
5939 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005940 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5941 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005942 },
5943 {
5944 .cmd = NL80211_CMD_NEW_INTERFACE,
5945 .doit = nl80211_new_interface,
5946 .policy = nl80211_policy,
5947 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005948 .internal_flags = NL80211_FLAG_NEED_WIPHY |
5949 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005950 },
5951 {
5952 .cmd = NL80211_CMD_DEL_INTERFACE,
5953 .doit = nl80211_del_interface,
5954 .policy = nl80211_policy,
5955 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005956 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5957 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04005958 },
Johannes Berg41ade002007-12-19 02:03:29 +01005959 {
5960 .cmd = NL80211_CMD_GET_KEY,
5961 .doit = nl80211_get_key,
5962 .policy = nl80211_policy,
5963 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02005964 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5965 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005966 },
5967 {
5968 .cmd = NL80211_CMD_SET_KEY,
5969 .doit = nl80211_set_key,
5970 .policy = nl80211_policy,
5971 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005972 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005973 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005974 },
5975 {
5976 .cmd = NL80211_CMD_NEW_KEY,
5977 .doit = nl80211_new_key,
5978 .policy = nl80211_policy,
5979 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005981 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005982 },
5983 {
5984 .cmd = NL80211_CMD_DEL_KEY,
5985 .doit = nl80211_del_key,
5986 .policy = nl80211_policy,
5987 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02005988 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02005989 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01005990 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01005991 {
5992 .cmd = NL80211_CMD_SET_BEACON,
5993 .policy = nl80211_policy,
5994 .flags = GENL_ADMIN_PERM,
5995 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02005996 .internal_flags = NL80211_FLAG_NEED_NETDEV |
5997 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01005998 },
5999 {
6000 .cmd = NL80211_CMD_NEW_BEACON,
6001 .policy = nl80211_policy,
6002 .flags = GENL_ADMIN_PERM,
6003 .doit = nl80211_addset_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006004 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6005 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006006 },
6007 {
6008 .cmd = NL80211_CMD_DEL_BEACON,
6009 .policy = nl80211_policy,
6010 .flags = GENL_ADMIN_PERM,
6011 .doit = nl80211_del_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006012 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6013 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006014 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006015 {
6016 .cmd = NL80211_CMD_GET_STATION,
6017 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006018 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006019 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006020 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6021 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006022 },
6023 {
6024 .cmd = NL80211_CMD_SET_STATION,
6025 .doit = nl80211_set_station,
6026 .policy = nl80211_policy,
6027 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006028 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6029 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006030 },
6031 {
6032 .cmd = NL80211_CMD_NEW_STATION,
6033 .doit = nl80211_new_station,
6034 .policy = nl80211_policy,
6035 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006036 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006037 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006038 },
6039 {
6040 .cmd = NL80211_CMD_DEL_STATION,
6041 .doit = nl80211_del_station,
6042 .policy = nl80211_policy,
6043 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006044 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6045 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006046 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006047 {
6048 .cmd = NL80211_CMD_GET_MPATH,
6049 .doit = nl80211_get_mpath,
6050 .dumpit = nl80211_dump_mpath,
6051 .policy = nl80211_policy,
6052 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006053 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006054 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006055 },
6056 {
6057 .cmd = NL80211_CMD_SET_MPATH,
6058 .doit = nl80211_set_mpath,
6059 .policy = nl80211_policy,
6060 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006061 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006062 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006063 },
6064 {
6065 .cmd = NL80211_CMD_NEW_MPATH,
6066 .doit = nl80211_new_mpath,
6067 .policy = nl80211_policy,
6068 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006069 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006070 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006071 },
6072 {
6073 .cmd = NL80211_CMD_DEL_MPATH,
6074 .doit = nl80211_del_mpath,
6075 .policy = nl80211_policy,
6076 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006077 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6078 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006079 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006080 {
6081 .cmd = NL80211_CMD_SET_BSS,
6082 .doit = nl80211_set_bss,
6083 .policy = nl80211_policy,
6084 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006085 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6086 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006087 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006088 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006089 .cmd = NL80211_CMD_GET_REG,
6090 .doit = nl80211_get_reg,
6091 .policy = nl80211_policy,
6092 /* can be retrieved by unprivileged users */
6093 },
6094 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006095 .cmd = NL80211_CMD_SET_REG,
6096 .doit = nl80211_set_reg,
6097 .policy = nl80211_policy,
6098 .flags = GENL_ADMIN_PERM,
6099 },
6100 {
6101 .cmd = NL80211_CMD_REQ_SET_REG,
6102 .doit = nl80211_req_set_reg,
6103 .policy = nl80211_policy,
6104 .flags = GENL_ADMIN_PERM,
6105 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006106 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006107 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6108 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006109 .policy = nl80211_policy,
6110 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006111 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6112 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006113 },
6114 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006115 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6116 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006117 .policy = nl80211_policy,
6118 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006119 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006120 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006121 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006122 {
Johannes Berg2a519312009-02-10 21:25:55 +01006123 .cmd = NL80211_CMD_TRIGGER_SCAN,
6124 .doit = nl80211_trigger_scan,
6125 .policy = nl80211_policy,
6126 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006127 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006128 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006129 },
6130 {
6131 .cmd = NL80211_CMD_GET_SCAN,
6132 .policy = nl80211_policy,
6133 .dumpit = nl80211_dump_scan,
6134 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006135 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006136 .cmd = NL80211_CMD_START_SCHED_SCAN,
6137 .doit = nl80211_start_sched_scan,
6138 .policy = nl80211_policy,
6139 .flags = GENL_ADMIN_PERM,
6140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6141 NL80211_FLAG_NEED_RTNL,
6142 },
6143 {
6144 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6145 .doit = nl80211_stop_sched_scan,
6146 .policy = nl80211_policy,
6147 .flags = GENL_ADMIN_PERM,
6148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6149 NL80211_FLAG_NEED_RTNL,
6150 },
6151 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006152 .cmd = NL80211_CMD_AUTHENTICATE,
6153 .doit = nl80211_authenticate,
6154 .policy = nl80211_policy,
6155 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006157 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006158 },
6159 {
6160 .cmd = NL80211_CMD_ASSOCIATE,
6161 .doit = nl80211_associate,
6162 .policy = nl80211_policy,
6163 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006165 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006166 },
6167 {
6168 .cmd = NL80211_CMD_DEAUTHENTICATE,
6169 .doit = nl80211_deauthenticate,
6170 .policy = nl80211_policy,
6171 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006173 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006174 },
6175 {
6176 .cmd = NL80211_CMD_DISASSOCIATE,
6177 .doit = nl80211_disassociate,
6178 .policy = nl80211_policy,
6179 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006180 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006181 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006182 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006183 {
6184 .cmd = NL80211_CMD_JOIN_IBSS,
6185 .doit = nl80211_join_ibss,
6186 .policy = nl80211_policy,
6187 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006188 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006189 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006190 },
6191 {
6192 .cmd = NL80211_CMD_LEAVE_IBSS,
6193 .doit = nl80211_leave_ibss,
6194 .policy = nl80211_policy,
6195 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006197 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006198 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006199#ifdef CONFIG_NL80211_TESTMODE
6200 {
6201 .cmd = NL80211_CMD_TESTMODE,
6202 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006203 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006204 .policy = nl80211_policy,
6205 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006206 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6207 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006208 },
6209#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006210 {
6211 .cmd = NL80211_CMD_CONNECT,
6212 .doit = nl80211_connect,
6213 .policy = nl80211_policy,
6214 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006216 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006217 },
6218 {
6219 .cmd = NL80211_CMD_DISCONNECT,
6220 .doit = nl80211_disconnect,
6221 .policy = nl80211_policy,
6222 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006224 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006225 },
Johannes Berg463d0182009-07-14 00:33:35 +02006226 {
6227 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6228 .doit = nl80211_wiphy_netns,
6229 .policy = nl80211_policy,
6230 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006231 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6232 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006233 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006234 {
6235 .cmd = NL80211_CMD_GET_SURVEY,
6236 .policy = nl80211_policy,
6237 .dumpit = nl80211_dump_survey,
6238 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006239 {
6240 .cmd = NL80211_CMD_SET_PMKSA,
6241 .doit = nl80211_setdel_pmksa,
6242 .policy = nl80211_policy,
6243 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006244 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6245 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006246 },
6247 {
6248 .cmd = NL80211_CMD_DEL_PMKSA,
6249 .doit = nl80211_setdel_pmksa,
6250 .policy = nl80211_policy,
6251 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006252 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6253 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006254 },
6255 {
6256 .cmd = NL80211_CMD_FLUSH_PMKSA,
6257 .doit = nl80211_flush_pmksa,
6258 .policy = nl80211_policy,
6259 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006260 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6261 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006262 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006263 {
6264 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6265 .doit = nl80211_remain_on_channel,
6266 .policy = nl80211_policy,
6267 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006268 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006269 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006270 },
6271 {
6272 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6273 .doit = nl80211_cancel_remain_on_channel,
6274 .policy = nl80211_policy,
6275 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006277 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006278 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006279 {
6280 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6281 .doit = nl80211_set_tx_bitrate_mask,
6282 .policy = nl80211_policy,
6283 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006284 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6285 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006286 },
Jouni Malinen026331c2010-02-15 12:53:10 +02006287 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006288 .cmd = NL80211_CMD_REGISTER_FRAME,
6289 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006290 .policy = nl80211_policy,
6291 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006292 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6293 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006294 },
6295 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006296 .cmd = NL80211_CMD_FRAME,
6297 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006298 .policy = nl80211_policy,
6299 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006300 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006301 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006302 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006303 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006304 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6305 .doit = nl80211_tx_mgmt_cancel_wait,
6306 .policy = nl80211_policy,
6307 .flags = GENL_ADMIN_PERM,
6308 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6309 NL80211_FLAG_NEED_RTNL,
6310 },
6311 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006312 .cmd = NL80211_CMD_SET_POWER_SAVE,
6313 .doit = nl80211_set_power_save,
6314 .policy = nl80211_policy,
6315 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006316 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6317 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006318 },
6319 {
6320 .cmd = NL80211_CMD_GET_POWER_SAVE,
6321 .doit = nl80211_get_power_save,
6322 .policy = nl80211_policy,
6323 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006324 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6325 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006326 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006327 {
6328 .cmd = NL80211_CMD_SET_CQM,
6329 .doit = nl80211_set_cqm,
6330 .policy = nl80211_policy,
6331 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006332 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6333 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006334 },
Johannes Bergf444de02010-05-05 15:25:02 +02006335 {
6336 .cmd = NL80211_CMD_SET_CHANNEL,
6337 .doit = nl80211_set_channel,
6338 .policy = nl80211_policy,
6339 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006340 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6341 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006342 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006343 {
6344 .cmd = NL80211_CMD_SET_WDS_PEER,
6345 .doit = nl80211_set_wds_peer,
6346 .policy = nl80211_policy,
6347 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006348 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6349 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006350 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006351 {
6352 .cmd = NL80211_CMD_JOIN_MESH,
6353 .doit = nl80211_join_mesh,
6354 .policy = nl80211_policy,
6355 .flags = GENL_ADMIN_PERM,
6356 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6357 NL80211_FLAG_NEED_RTNL,
6358 },
6359 {
6360 .cmd = NL80211_CMD_LEAVE_MESH,
6361 .doit = nl80211_leave_mesh,
6362 .policy = nl80211_policy,
6363 .flags = GENL_ADMIN_PERM,
6364 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6365 NL80211_FLAG_NEED_RTNL,
6366 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006367 {
6368 .cmd = NL80211_CMD_GET_WOWLAN,
6369 .doit = nl80211_get_wowlan,
6370 .policy = nl80211_policy,
6371 /* can be retrieved by unprivileged users */
6372 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6373 NL80211_FLAG_NEED_RTNL,
6374 },
6375 {
6376 .cmd = NL80211_CMD_SET_WOWLAN,
6377 .doit = nl80211_set_wowlan,
6378 .policy = nl80211_policy,
6379 .flags = GENL_ADMIN_PERM,
6380 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6381 NL80211_FLAG_NEED_RTNL,
6382 },
Johannes Berge5497d72011-07-05 16:35:40 +02006383 {
6384 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6385 .doit = nl80211_set_rekey_data,
6386 .policy = nl80211_policy,
6387 .flags = GENL_ADMIN_PERM,
6388 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6389 NL80211_FLAG_NEED_RTNL,
6390 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03006391 {
6392 .cmd = NL80211_CMD_TDLS_MGMT,
6393 .doit = nl80211_tdls_mgmt,
6394 .policy = nl80211_policy,
6395 .flags = GENL_ADMIN_PERM,
6396 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6397 NL80211_FLAG_NEED_RTNL,
6398 },
6399 {
6400 .cmd = NL80211_CMD_TDLS_OPER,
6401 .doit = nl80211_tdls_oper,
6402 .policy = nl80211_policy,
6403 .flags = GENL_ADMIN_PERM,
6404 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6405 NL80211_FLAG_NEED_RTNL,
6406 },
Johannes Berg28946da2011-11-04 11:18:12 +01006407 {
6408 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6409 .doit = nl80211_register_unexpected_frame,
6410 .policy = nl80211_policy,
6411 .flags = GENL_ADMIN_PERM,
6412 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6413 NL80211_FLAG_NEED_RTNL,
6414 },
Johannes Berg55682962007-09-20 13:09:35 -04006415};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006416
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006417static struct genl_multicast_group nl80211_mlme_mcgrp = {
6418 .name = "mlme",
6419};
Johannes Berg55682962007-09-20 13:09:35 -04006420
6421/* multicast groups */
6422static struct genl_multicast_group nl80211_config_mcgrp = {
6423 .name = "config",
6424};
Johannes Berg2a519312009-02-10 21:25:55 +01006425static struct genl_multicast_group nl80211_scan_mcgrp = {
6426 .name = "scan",
6427};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006428static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6429 .name = "regulatory",
6430};
Johannes Berg55682962007-09-20 13:09:35 -04006431
6432/* notification functions */
6433
6434void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6435{
6436 struct sk_buff *msg;
6437
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006439 if (!msg)
6440 return;
6441
6442 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6443 nlmsg_free(msg);
6444 return;
6445 }
6446
Johannes Berg463d0182009-07-14 00:33:35 +02006447 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6448 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006449}
6450
Johannes Berg362a4152009-05-24 16:43:15 +02006451static int nl80211_add_scan_req(struct sk_buff *msg,
6452 struct cfg80211_registered_device *rdev)
6453{
6454 struct cfg80211_scan_request *req = rdev->scan_req;
6455 struct nlattr *nest;
6456 int i;
6457
Johannes Berg667503dd2009-07-07 03:56:11 +02006458 ASSERT_RDEV_LOCK(rdev);
6459
Johannes Berg362a4152009-05-24 16:43:15 +02006460 if (WARN_ON(!req))
6461 return 0;
6462
6463 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6464 if (!nest)
6465 goto nla_put_failure;
6466 for (i = 0; i < req->n_ssids; i++)
6467 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6468 nla_nest_end(msg, nest);
6469
6470 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6471 if (!nest)
6472 goto nla_put_failure;
6473 for (i = 0; i < req->n_channels; i++)
6474 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6475 nla_nest_end(msg, nest);
6476
6477 if (req->ie)
6478 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6479
6480 return 0;
6481 nla_put_failure:
6482 return -ENOBUFS;
6483}
6484
Johannes Berga538e2d2009-06-16 19:56:42 +02006485static int nl80211_send_scan_msg(struct sk_buff *msg,
6486 struct cfg80211_registered_device *rdev,
6487 struct net_device *netdev,
6488 u32 pid, u32 seq, int flags,
6489 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006490{
6491 void *hdr;
6492
6493 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6494 if (!hdr)
6495 return -1;
6496
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006497 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006498 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6499
Johannes Berg362a4152009-05-24 16:43:15 +02006500 /* ignore errors and send incomplete event anyway */
6501 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006502
6503 return genlmsg_end(msg, hdr);
6504
6505 nla_put_failure:
6506 genlmsg_cancel(msg, hdr);
6507 return -EMSGSIZE;
6508}
6509
Luciano Coelho807f8a82011-05-11 17:09:35 +03006510static int
6511nl80211_send_sched_scan_msg(struct sk_buff *msg,
6512 struct cfg80211_registered_device *rdev,
6513 struct net_device *netdev,
6514 u32 pid, u32 seq, int flags, u32 cmd)
6515{
6516 void *hdr;
6517
6518 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6519 if (!hdr)
6520 return -1;
6521
6522 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6523 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6524
6525 return genlmsg_end(msg, hdr);
6526
6527 nla_put_failure:
6528 genlmsg_cancel(msg, hdr);
6529 return -EMSGSIZE;
6530}
6531
Johannes Berga538e2d2009-06-16 19:56:42 +02006532void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6533 struct net_device *netdev)
6534{
6535 struct sk_buff *msg;
6536
6537 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6538 if (!msg)
6539 return;
6540
6541 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6542 NL80211_CMD_TRIGGER_SCAN) < 0) {
6543 nlmsg_free(msg);
6544 return;
6545 }
6546
Johannes Berg463d0182009-07-14 00:33:35 +02006547 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6548 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006549}
6550
Johannes Berg2a519312009-02-10 21:25:55 +01006551void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6552 struct net_device *netdev)
6553{
6554 struct sk_buff *msg;
6555
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006557 if (!msg)
6558 return;
6559
Johannes Berga538e2d2009-06-16 19:56:42 +02006560 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6561 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006562 nlmsg_free(msg);
6563 return;
6564 }
6565
Johannes Berg463d0182009-07-14 00:33:35 +02006566 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6567 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006568}
6569
6570void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6571 struct net_device *netdev)
6572{
6573 struct sk_buff *msg;
6574
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006575 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006576 if (!msg)
6577 return;
6578
Johannes Berga538e2d2009-06-16 19:56:42 +02006579 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6580 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006581 nlmsg_free(msg);
6582 return;
6583 }
6584
Johannes Berg463d0182009-07-14 00:33:35 +02006585 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6586 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006587}
6588
Luciano Coelho807f8a82011-05-11 17:09:35 +03006589void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6590 struct net_device *netdev)
6591{
6592 struct sk_buff *msg;
6593
6594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6595 if (!msg)
6596 return;
6597
6598 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6599 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6600 nlmsg_free(msg);
6601 return;
6602 }
6603
6604 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6605 nl80211_scan_mcgrp.id, GFP_KERNEL);
6606}
6607
6608void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6609 struct net_device *netdev, u32 cmd)
6610{
6611 struct sk_buff *msg;
6612
6613 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6614 if (!msg)
6615 return;
6616
6617 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6618 nlmsg_free(msg);
6619 return;
6620 }
6621
6622 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6623 nl80211_scan_mcgrp.id, GFP_KERNEL);
6624}
6625
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006626/*
6627 * This can happen on global regulatory changes or device specific settings
6628 * based on custom world regulatory domains.
6629 */
6630void nl80211_send_reg_change_event(struct regulatory_request *request)
6631{
6632 struct sk_buff *msg;
6633 void *hdr;
6634
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006636 if (!msg)
6637 return;
6638
6639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6640 if (!hdr) {
6641 nlmsg_free(msg);
6642 return;
6643 }
6644
6645 /* Userspace can always count this one always being set */
6646 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6647
6648 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6649 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6650 NL80211_REGDOM_TYPE_WORLD);
6651 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6652 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6653 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6654 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6655 request->intersect)
6656 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6657 NL80211_REGDOM_TYPE_INTERSECTION);
6658 else {
6659 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6660 NL80211_REGDOM_TYPE_COUNTRY);
6661 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6662 }
6663
6664 if (wiphy_idx_valid(request->wiphy_idx))
6665 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6666
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006667 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006668
Johannes Bergbc43b282009-07-25 10:54:13 +02006669 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02006670 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02006671 GFP_ATOMIC);
6672 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006673
6674 return;
6675
6676nla_put_failure:
6677 genlmsg_cancel(msg, hdr);
6678 nlmsg_free(msg);
6679}
6680
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006681static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
6682 struct net_device *netdev,
6683 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006684 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006685{
6686 struct sk_buff *msg;
6687 void *hdr;
6688
Johannes Berge6d6e342009-07-01 21:26:47 +02006689 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006690 if (!msg)
6691 return;
6692
6693 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6694 if (!hdr) {
6695 nlmsg_free(msg);
6696 return;
6697 }
6698
6699 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6700 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6701 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
6702
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006703 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006704
Johannes Berg463d0182009-07-14 00:33:35 +02006705 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6706 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006707 return;
6708
6709 nla_put_failure:
6710 genlmsg_cancel(msg, hdr);
6711 nlmsg_free(msg);
6712}
6713
6714void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006715 struct net_device *netdev, const u8 *buf,
6716 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006717{
6718 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006719 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006720}
6721
6722void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
6723 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006724 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006725{
Johannes Berge6d6e342009-07-01 21:26:47 +02006726 nl80211_send_mlme_event(rdev, netdev, buf, len,
6727 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006728}
6729
Jouni Malinen53b46b82009-03-27 20:53:56 +02006730void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006731 struct net_device *netdev, const u8 *buf,
6732 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006733{
6734 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006735 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006736}
6737
Jouni Malinen53b46b82009-03-27 20:53:56 +02006738void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
6739 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02006740 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006741{
6742 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02006743 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006744}
6745
Jouni Malinencf4e5942010-12-16 00:52:40 +02006746void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
6747 struct net_device *netdev, const u8 *buf,
6748 size_t len, gfp_t gfp)
6749{
6750 nl80211_send_mlme_event(rdev, netdev, buf, len,
6751 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
6752}
6753
6754void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
6755 struct net_device *netdev, const u8 *buf,
6756 size_t len, gfp_t gfp)
6757{
6758 nl80211_send_mlme_event(rdev, netdev, buf, len,
6759 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
6760}
6761
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04006762static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
6763 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02006764 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006765{
6766 struct sk_buff *msg;
6767 void *hdr;
6768
Johannes Berge6d6e342009-07-01 21:26:47 +02006769 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006770 if (!msg)
6771 return;
6772
6773 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
6774 if (!hdr) {
6775 nlmsg_free(msg);
6776 return;
6777 }
6778
6779 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6780 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6781 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
6782 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
6783
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006784 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03006785
Johannes Berg463d0182009-07-14 00:33:35 +02006786 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6787 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006788 return;
6789
6790 nla_put_failure:
6791 genlmsg_cancel(msg, hdr);
6792 nlmsg_free(msg);
6793}
6794
6795void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006796 struct net_device *netdev, const u8 *addr,
6797 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006798{
6799 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02006800 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006801}
6802
6803void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02006804 struct net_device *netdev, const u8 *addr,
6805 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03006806{
Johannes Berge6d6e342009-07-01 21:26:47 +02006807 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
6808 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03006809}
6810
Samuel Ortizb23aa672009-07-01 21:26:54 +02006811void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
6812 struct net_device *netdev, const u8 *bssid,
6813 const u8 *req_ie, size_t req_ie_len,
6814 const u8 *resp_ie, size_t resp_ie_len,
6815 u16 status, gfp_t gfp)
6816{
6817 struct sk_buff *msg;
6818 void *hdr;
6819
6820 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6821 if (!msg)
6822 return;
6823
6824 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
6825 if (!hdr) {
6826 nlmsg_free(msg);
6827 return;
6828 }
6829
6830 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6831 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6832 if (bssid)
6833 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6834 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
6835 if (req_ie)
6836 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6837 if (resp_ie)
6838 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6839
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006840 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006841
Johannes Berg463d0182009-07-14 00:33:35 +02006842 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6843 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006844 return;
6845
6846 nla_put_failure:
6847 genlmsg_cancel(msg, hdr);
6848 nlmsg_free(msg);
6849
6850}
6851
6852void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
6853 struct net_device *netdev, const u8 *bssid,
6854 const u8 *req_ie, size_t req_ie_len,
6855 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
6856{
6857 struct sk_buff *msg;
6858 void *hdr;
6859
6860 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
6861 if (!msg)
6862 return;
6863
6864 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
6865 if (!hdr) {
6866 nlmsg_free(msg);
6867 return;
6868 }
6869
6870 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6871 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6872 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6873 if (req_ie)
6874 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
6875 if (resp_ie)
6876 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
6877
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006878 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006879
Johannes Berg463d0182009-07-14 00:33:35 +02006880 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6881 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006882 return;
6883
6884 nla_put_failure:
6885 genlmsg_cancel(msg, hdr);
6886 nlmsg_free(msg);
6887
6888}
6889
6890void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
6891 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02006892 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006893{
6894 struct sk_buff *msg;
6895 void *hdr;
6896
Johannes Berg667503dd2009-07-07 03:56:11 +02006897 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006898 if (!msg)
6899 return;
6900
6901 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
6902 if (!hdr) {
6903 nlmsg_free(msg);
6904 return;
6905 }
6906
6907 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6908 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6909 if (from_ap && reason)
6910 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
6911 if (from_ap)
6912 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
6913 if (ie)
6914 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
6915
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006916 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006917
Johannes Berg463d0182009-07-14 00:33:35 +02006918 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6919 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006920 return;
6921
6922 nla_put_failure:
6923 genlmsg_cancel(msg, hdr);
6924 nlmsg_free(msg);
6925
6926}
6927
Johannes Berg04a773a2009-04-19 21:24:32 +02006928void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
6929 struct net_device *netdev, const u8 *bssid,
6930 gfp_t gfp)
6931{
6932 struct sk_buff *msg;
6933 void *hdr;
6934
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006936 if (!msg)
6937 return;
6938
6939 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
6940 if (!hdr) {
6941 nlmsg_free(msg);
6942 return;
6943 }
6944
6945 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6946 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6947 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
6948
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006949 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02006950
Johannes Berg463d0182009-07-14 00:33:35 +02006951 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6952 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02006953 return;
6954
6955 nla_put_failure:
6956 genlmsg_cancel(msg, hdr);
6957 nlmsg_free(msg);
6958}
6959
Javier Cardonac93b5e72011-04-07 15:08:34 -07006960void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
6961 struct net_device *netdev,
6962 const u8 *macaddr, const u8* ie, u8 ie_len,
6963 gfp_t gfp)
6964{
6965 struct sk_buff *msg;
6966 void *hdr;
6967
6968 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
6969 if (!msg)
6970 return;
6971
6972 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
6973 if (!hdr) {
6974 nlmsg_free(msg);
6975 return;
6976 }
6977
6978 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6979 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6980 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
6981 if (ie_len && ie)
6982 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
6983
Johannes Berg3b7b72e2011-10-22 19:05:51 +02006984 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07006985
6986 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6987 nl80211_mlme_mcgrp.id, gfp);
6988 return;
6989
6990 nla_put_failure:
6991 genlmsg_cancel(msg, hdr);
6992 nlmsg_free(msg);
6993}
6994
Jouni Malinena3b8b052009-03-27 21:59:49 +02006995void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
6996 struct net_device *netdev, const u8 *addr,
6997 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02006998 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02006999{
7000 struct sk_buff *msg;
7001 void *hdr;
7002
Johannes Berge6d6e342009-07-01 21:26:47 +02007003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007004 if (!msg)
7005 return;
7006
7007 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7008 if (!hdr) {
7009 nlmsg_free(msg);
7010 return;
7011 }
7012
7013 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7014 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7015 if (addr)
7016 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7017 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03007018 if (key_id != -1)
7019 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007020 if (tsc)
7021 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7022
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007023 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007024
Johannes Berg463d0182009-07-14 00:33:35 +02007025 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7026 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007027 return;
7028
7029 nla_put_failure:
7030 genlmsg_cancel(msg, hdr);
7031 nlmsg_free(msg);
7032}
7033
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007034void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7035 struct ieee80211_channel *channel_before,
7036 struct ieee80211_channel *channel_after)
7037{
7038 struct sk_buff *msg;
7039 void *hdr;
7040 struct nlattr *nl_freq;
7041
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007043 if (!msg)
7044 return;
7045
7046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7047 if (!hdr) {
7048 nlmsg_free(msg);
7049 return;
7050 }
7051
7052 /*
7053 * Since we are applying the beacon hint to a wiphy we know its
7054 * wiphy_idx is valid
7055 */
7056 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7057
7058 /* Before */
7059 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7060 if (!nl_freq)
7061 goto nla_put_failure;
7062 if (nl80211_msg_put_channel(msg, channel_before))
7063 goto nla_put_failure;
7064 nla_nest_end(msg, nl_freq);
7065
7066 /* After */
7067 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7068 if (!nl_freq)
7069 goto nla_put_failure;
7070 if (nl80211_msg_put_channel(msg, channel_after))
7071 goto nla_put_failure;
7072 nla_nest_end(msg, nl_freq);
7073
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007074 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007075
Johannes Berg463d0182009-07-14 00:33:35 +02007076 rcu_read_lock();
7077 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7078 GFP_ATOMIC);
7079 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007080
7081 return;
7082
7083nla_put_failure:
7084 genlmsg_cancel(msg, hdr);
7085 nlmsg_free(msg);
7086}
7087
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007088static void nl80211_send_remain_on_chan_event(
7089 int cmd, struct cfg80211_registered_device *rdev,
7090 struct net_device *netdev, u64 cookie,
7091 struct ieee80211_channel *chan,
7092 enum nl80211_channel_type channel_type,
7093 unsigned int duration, gfp_t gfp)
7094{
7095 struct sk_buff *msg;
7096 void *hdr;
7097
7098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7099 if (!msg)
7100 return;
7101
7102 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7103 if (!hdr) {
7104 nlmsg_free(msg);
7105 return;
7106 }
7107
7108 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7109 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7110 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7111 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7112 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7113
7114 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7115 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7116
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007117 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007118
7119 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7120 nl80211_mlme_mcgrp.id, gfp);
7121 return;
7122
7123 nla_put_failure:
7124 genlmsg_cancel(msg, hdr);
7125 nlmsg_free(msg);
7126}
7127
7128void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7129 struct net_device *netdev, u64 cookie,
7130 struct ieee80211_channel *chan,
7131 enum nl80211_channel_type channel_type,
7132 unsigned int duration, gfp_t gfp)
7133{
7134 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7135 rdev, netdev, cookie, chan,
7136 channel_type, duration, gfp);
7137}
7138
7139void nl80211_send_remain_on_channel_cancel(
7140 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7141 u64 cookie, struct ieee80211_channel *chan,
7142 enum nl80211_channel_type channel_type, gfp_t gfp)
7143{
7144 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7145 rdev, netdev, cookie, chan,
7146 channel_type, 0, gfp);
7147}
7148
Johannes Berg98b62182009-12-23 13:15:44 +01007149void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7150 struct net_device *dev, const u8 *mac_addr,
7151 struct station_info *sinfo, gfp_t gfp)
7152{
7153 struct sk_buff *msg;
7154
7155 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7156 if (!msg)
7157 return;
7158
7159 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
7160 nlmsg_free(msg);
7161 return;
7162 }
7163
7164 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7165 nl80211_mlme_mcgrp.id, gfp);
7166}
7167
Jouni Malinenec15e682011-03-23 15:29:52 +02007168void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7169 struct net_device *dev, const u8 *mac_addr,
7170 gfp_t gfp)
7171{
7172 struct sk_buff *msg;
7173 void *hdr;
7174
7175 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7176 if (!msg)
7177 return;
7178
7179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7180 if (!hdr) {
7181 nlmsg_free(msg);
7182 return;
7183 }
7184
7185 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7186 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7187
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007188 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007189
7190 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7191 nl80211_mlme_mcgrp.id, gfp);
7192 return;
7193
7194 nla_put_failure:
7195 genlmsg_cancel(msg, hdr);
7196 nlmsg_free(msg);
7197}
7198
Johannes Berg28946da2011-11-04 11:18:12 +01007199bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7200{
7201 struct wireless_dev *wdev = dev->ieee80211_ptr;
7202 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7203 struct sk_buff *msg;
7204 void *hdr;
7205 int err;
7206 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7207
7208 if (!nlpid)
7209 return false;
7210
7211 msg = nlmsg_new(100, gfp);
7212 if (!msg)
7213 return true;
7214
7215 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UNEXPECTED_FRAME);
7216 if (!hdr) {
7217 nlmsg_free(msg);
7218 return true;
7219 }
7220
7221 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7222 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7223 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7224
7225 err = genlmsg_end(msg, hdr);
7226 if (err < 0) {
7227 nlmsg_free(msg);
7228 return true;
7229 }
7230
7231 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7232 return true;
7233
7234 nla_put_failure:
7235 genlmsg_cancel(msg, hdr);
7236 nlmsg_free(msg);
7237 return true;
7238}
7239
Johannes Berg2e161f72010-08-12 15:38:38 +02007240int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7241 struct net_device *netdev, u32 nlpid,
7242 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007243{
7244 struct sk_buff *msg;
7245 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02007246
7247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7248 if (!msg)
7249 return -ENOMEM;
7250
Johannes Berg2e161f72010-08-12 15:38:38 +02007251 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007252 if (!hdr) {
7253 nlmsg_free(msg);
7254 return -ENOMEM;
7255 }
7256
7257 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7258 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7259 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7260 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7261
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007262 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007263
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007264 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007265
7266 nla_put_failure:
7267 genlmsg_cancel(msg, hdr);
7268 nlmsg_free(msg);
7269 return -ENOBUFS;
7270}
7271
Johannes Berg2e161f72010-08-12 15:38:38 +02007272void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7273 struct net_device *netdev, u64 cookie,
7274 const u8 *buf, size_t len, bool ack,
7275 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007276{
7277 struct sk_buff *msg;
7278 void *hdr;
7279
7280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7281 if (!msg)
7282 return;
7283
Johannes Berg2e161f72010-08-12 15:38:38 +02007284 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02007285 if (!hdr) {
7286 nlmsg_free(msg);
7287 return;
7288 }
7289
7290 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7291 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7292 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7293 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7294 if (ack)
7295 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7296
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007297 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007298
7299 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7300 return;
7301
7302 nla_put_failure:
7303 genlmsg_cancel(msg, hdr);
7304 nlmsg_free(msg);
7305}
7306
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007307void
7308nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7309 struct net_device *netdev,
7310 enum nl80211_cqm_rssi_threshold_event rssi_event,
7311 gfp_t gfp)
7312{
7313 struct sk_buff *msg;
7314 struct nlattr *pinfoattr;
7315 void *hdr;
7316
7317 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7318 if (!msg)
7319 return;
7320
7321 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7322 if (!hdr) {
7323 nlmsg_free(msg);
7324 return;
7325 }
7326
7327 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7328 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7329
7330 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7331 if (!pinfoattr)
7332 goto nla_put_failure;
7333
7334 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7335 rssi_event);
7336
7337 nla_nest_end(msg, pinfoattr);
7338
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007339 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007340
7341 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7342 nl80211_mlme_mcgrp.id, gfp);
7343 return;
7344
7345 nla_put_failure:
7346 genlmsg_cancel(msg, hdr);
7347 nlmsg_free(msg);
7348}
7349
Johannes Berge5497d72011-07-05 16:35:40 +02007350void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7351 struct net_device *netdev, const u8 *bssid,
7352 const u8 *replay_ctr, gfp_t gfp)
7353{
7354 struct sk_buff *msg;
7355 struct nlattr *rekey_attr;
7356 void *hdr;
7357
7358 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7359 if (!msg)
7360 return;
7361
7362 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7363 if (!hdr) {
7364 nlmsg_free(msg);
7365 return;
7366 }
7367
7368 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7369 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7370 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7371
7372 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7373 if (!rekey_attr)
7374 goto nla_put_failure;
7375
7376 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7377 NL80211_REPLAY_CTR_LEN, replay_ctr);
7378
7379 nla_nest_end(msg, rekey_attr);
7380
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007381 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02007382
7383 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7384 nl80211_mlme_mcgrp.id, gfp);
7385 return;
7386
7387 nla_put_failure:
7388 genlmsg_cancel(msg, hdr);
7389 nlmsg_free(msg);
7390}
7391
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007392void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7393 struct net_device *netdev, int index,
7394 const u8 *bssid, bool preauth, gfp_t gfp)
7395{
7396 struct sk_buff *msg;
7397 struct nlattr *attr;
7398 void *hdr;
7399
7400 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7401 if (!msg)
7402 return;
7403
7404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7405 if (!hdr) {
7406 nlmsg_free(msg);
7407 return;
7408 }
7409
7410 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7411 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7412
7413 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7414 if (!attr)
7415 goto nla_put_failure;
7416
7417 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7418 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7419 if (preauth)
7420 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7421
7422 nla_nest_end(msg, attr);
7423
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007424 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007425
7426 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7427 nl80211_mlme_mcgrp.id, gfp);
7428 return;
7429
7430 nla_put_failure:
7431 genlmsg_cancel(msg, hdr);
7432 nlmsg_free(msg);
7433}
7434
Johannes Bergc063dbf2010-11-24 08:10:05 +01007435void
7436nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7437 struct net_device *netdev, const u8 *peer,
7438 u32 num_packets, gfp_t gfp)
7439{
7440 struct sk_buff *msg;
7441 struct nlattr *pinfoattr;
7442 void *hdr;
7443
7444 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7445 if (!msg)
7446 return;
7447
7448 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7449 if (!hdr) {
7450 nlmsg_free(msg);
7451 return;
7452 }
7453
7454 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7455 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7456 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7457
7458 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7459 if (!pinfoattr)
7460 goto nla_put_failure;
7461
7462 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7463
7464 nla_nest_end(msg, pinfoattr);
7465
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007466 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01007467
7468 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7469 nl80211_mlme_mcgrp.id, gfp);
7470 return;
7471
7472 nla_put_failure:
7473 genlmsg_cancel(msg, hdr);
7474 nlmsg_free(msg);
7475}
7476
Jouni Malinen026331c2010-02-15 12:53:10 +02007477static int nl80211_netlink_notify(struct notifier_block * nb,
7478 unsigned long state,
7479 void *_notify)
7480{
7481 struct netlink_notify *notify = _notify;
7482 struct cfg80211_registered_device *rdev;
7483 struct wireless_dev *wdev;
7484
7485 if (state != NETLINK_URELEASE)
7486 return NOTIFY_DONE;
7487
7488 rcu_read_lock();
7489
7490 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list)
7491 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02007492 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007493
7494 rcu_read_unlock();
7495
7496 return NOTIFY_DONE;
7497}
7498
7499static struct notifier_block nl80211_netlink_notifier = {
7500 .notifier_call = nl80211_netlink_notify,
7501};
7502
Johannes Berg55682962007-09-20 13:09:35 -04007503/* initialisation/exit functions */
7504
7505int nl80211_init(void)
7506{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007507 int err;
Johannes Berg55682962007-09-20 13:09:35 -04007508
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00007509 err = genl_register_family_with_ops(&nl80211_fam,
7510 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04007511 if (err)
7512 return err;
7513
Johannes Berg55682962007-09-20 13:09:35 -04007514 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7515 if (err)
7516 goto err_out;
7517
Johannes Berg2a519312009-02-10 21:25:55 +01007518 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7519 if (err)
7520 goto err_out;
7521
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007522 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7523 if (err)
7524 goto err_out;
7525
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007526 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7527 if (err)
7528 goto err_out;
7529
Johannes Bergaff89a92009-07-01 21:26:51 +02007530#ifdef CONFIG_NL80211_TESTMODE
7531 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7532 if (err)
7533 goto err_out;
7534#endif
7535
Jouni Malinen026331c2010-02-15 12:53:10 +02007536 err = netlink_register_notifier(&nl80211_netlink_notifier);
7537 if (err)
7538 goto err_out;
7539
Johannes Berg55682962007-09-20 13:09:35 -04007540 return 0;
7541 err_out:
7542 genl_unregister_family(&nl80211_fam);
7543 return err;
7544}
7545
7546void nl80211_exit(void)
7547{
Jouni Malinen026331c2010-02-15 12:53:10 +02007548 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04007549 genl_unregister_family(&nl80211_fam);
7550}