blob: 4b6afc338aac89742f28e9e145549f85ff09f523 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include "core.h"
23#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070024#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040025
Jouni Malinen5fb628e2011-08-10 23:54:35 +030026static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
30 int cipher_limit);
31
Johannes Berg4c476992010-10-04 21:36:35 +020032static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
36
Johannes Berg55682962007-09-20 13:09:35 -040037/* the netlink family */
38static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020044 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020045 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040047};
48
Johannes Berg79c97e92009-07-07 03:56:12 +020049/* internal helper: get rdev and dev */
Johannes Berg00918d32011-12-13 17:22:05 +010050static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
51 struct cfg80211_registered_device **rdev,
52 struct net_device **dev)
Johannes Berg55682962007-09-20 13:09:35 -040053{
54 int ifindex;
55
Johannes Bergbba95fe2008-07-29 13:22:51 +020056 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040057 return -EINVAL;
58
Johannes Bergbba95fe2008-07-29 13:22:51 +020059 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg00918d32011-12-13 17:22:05 +010060 *dev = dev_get_by_index(netns, ifindex);
Johannes Berg55682962007-09-20 13:09:35 -040061 if (!*dev)
62 return -ENODEV;
63
Johannes Berg00918d32011-12-13 17:22:05 +010064 *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
Johannes Berg79c97e92009-07-07 03:56:12 +020065 if (IS_ERR(*rdev)) {
Johannes Berg55682962007-09-20 13:09:35 -040066 dev_put(*dev);
Johannes Berg79c97e92009-07-07 03:56:12 +020067 return PTR_ERR(*rdev);
Johannes Berg55682962007-09-20 13:09:35 -040068 }
69
70 return 0;
71}
72
73/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000074static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -040075 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
76 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -070077 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +020078 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020079 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053080 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020081 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
82 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
83 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
84 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +010085 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -040086
87 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
88 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
89 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010090
Eliad Pellere007b852011-11-24 18:13:56 +020091 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
92 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +010093
Johannes Bergb9454e82009-07-08 13:29:08 +020094 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +010095 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
96 .len = WLAN_MAX_KEY_LEN },
97 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
98 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
99 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200100 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200101 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100102
103 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
104 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
105 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
106 .len = IEEE80211_MAX_DATA_LEN },
107 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
108 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100109 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
110 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
111 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
112 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
113 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100114 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100115 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200116 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100117 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
118 .len = IEEE80211_MAX_MESH_ID_LEN },
119 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300120
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700121 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
122 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
123
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300124 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
125 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
126 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200127 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
128 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100129 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300130
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800131 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700132 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700133
Johannes Berg6c739412011-11-03 09:27:01 +0100134 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200135
136 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
137 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
138 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100139 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
140 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200141
142 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
143 .len = IEEE80211_MAX_SSID_LEN },
144 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
145 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200146 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300147 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300148 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300149 [NL80211_ATTR_STA_FLAGS2] = {
150 .len = sizeof(struct nl80211_sta_flag_update),
151 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300152 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300153 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
154 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200155 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
156 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
157 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200158 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100159 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100160 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
161 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100162 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
163 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200164 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200165 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
166 .len = IEEE80211_MAX_DATA_LEN },
167 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200168 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200169 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300170 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200171 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300172 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
173 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200174 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900175 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
176 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100177 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100178 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100179 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200180 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700181 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300182 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200183 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200184 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300185 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300186 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
187 .len = IEEE80211_MAX_DATA_LEN },
188 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
189 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530190 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300191 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530192 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300193 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
194 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
195 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
196 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
197 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100198 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200199 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
200 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700201 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800202 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
203 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
204 .len = NL80211_HT_CAPABILITY_LEN
205 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100206 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530207 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400208};
209
Johannes Berge31b8212010-10-05 19:39:30 +0200210/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200212 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200213 [NL80211_KEY_IDX] = { .type = NLA_U8 },
214 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200215 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200216 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
217 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200218 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100219 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
220};
221
222/* policy for the key default flags */
223static const struct nla_policy
224nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
225 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
226 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200227};
228
Johannes Bergff1b6e62011-05-04 15:37:28 +0200229/* policy for WoWLAN attributes */
230static const struct nla_policy
231nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
232 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
233 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
234 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
235 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200236 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
237 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
238 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
239 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200240};
241
Johannes Berge5497d72011-07-05 16:35:40 +0200242/* policy for GTK rekey offload attributes */
243static const struct nla_policy
244nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
245 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
246 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
247 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
248};
249
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300250static const struct nla_policy
251nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
252 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_SSID_LEN },
254};
255
Holger Schuriga0438972009-11-11 11:30:02 +0100256/* ifidx get helper */
257static int nl80211_get_ifidx(struct netlink_callback *cb)
258{
259 int res;
260
261 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
262 nl80211_fam.attrbuf, nl80211_fam.maxattr,
263 nl80211_policy);
264 if (res)
265 return res;
266
267 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
268 return -EINVAL;
269
270 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
271 if (!res)
272 return -EINVAL;
273 return res;
274}
275
Johannes Berg67748892010-10-04 21:14:06 +0200276static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
277 struct netlink_callback *cb,
278 struct cfg80211_registered_device **rdev,
279 struct net_device **dev)
280{
281 int ifidx = cb->args[0];
282 int err;
283
284 if (!ifidx)
285 ifidx = nl80211_get_ifidx(cb);
286 if (ifidx < 0)
287 return ifidx;
288
289 cb->args[0] = ifidx;
290
291 rtnl_lock();
292
293 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
294 if (!*dev) {
295 err = -ENODEV;
296 goto out_rtnl;
297 }
298
299 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100300 if (IS_ERR(*rdev)) {
301 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200302 goto out_rtnl;
303 }
304
305 return 0;
306 out_rtnl:
307 rtnl_unlock();
308 return err;
309}
310
311static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
312{
313 cfg80211_unlock_rdev(rdev);
314 rtnl_unlock();
315}
316
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100317/* IE validation */
318static bool is_valid_ie_attr(const struct nlattr *attr)
319{
320 const u8 *pos;
321 int len;
322
323 if (!attr)
324 return true;
325
326 pos = nla_data(attr);
327 len = nla_len(attr);
328
329 while (len) {
330 u8 elemlen;
331
332 if (len < 2)
333 return false;
334 len -= 2;
335
336 elemlen = pos[1];
337 if (elemlen > len)
338 return false;
339
340 len -= elemlen;
341 pos += 2 + elemlen;
342 }
343
344 return true;
345}
346
Johannes Berg55682962007-09-20 13:09:35 -0400347/* message building helper */
348static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
349 int flags, u8 cmd)
350{
351 /* since there is no private header just add the generic one */
352 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
353}
354
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400355static int nl80211_msg_put_channel(struct sk_buff *msg,
356 struct ieee80211_channel *chan)
357{
358 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
359 chan->center_freq);
360
361 if (chan->flags & IEEE80211_CHAN_DISABLED)
362 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
363 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
364 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
365 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
366 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
367 if (chan->flags & IEEE80211_CHAN_RADAR)
368 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
369
370 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
371 DBM_TO_MBM(chan->max_power));
372
373 return 0;
374
375 nla_put_failure:
376 return -ENOBUFS;
377}
378
Johannes Berg55682962007-09-20 13:09:35 -0400379/* netlink command implementations */
380
Johannes Bergb9454e82009-07-08 13:29:08 +0200381struct key_parse {
382 struct key_params p;
383 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200384 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200385 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100386 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200387};
388
389static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
390{
391 struct nlattr *tb[NL80211_KEY_MAX + 1];
392 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
393 nl80211_key_policy);
394 if (err)
395 return err;
396
397 k->def = !!tb[NL80211_KEY_DEFAULT];
398 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
399
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100400 if (k->def) {
401 k->def_uni = true;
402 k->def_multi = true;
403 }
404 if (k->defmgmt)
405 k->def_multi = true;
406
Johannes Bergb9454e82009-07-08 13:29:08 +0200407 if (tb[NL80211_KEY_IDX])
408 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
409
410 if (tb[NL80211_KEY_DATA]) {
411 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
412 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
413 }
414
415 if (tb[NL80211_KEY_SEQ]) {
416 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
417 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
418 }
419
420 if (tb[NL80211_KEY_CIPHER])
421 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
422
Johannes Berge31b8212010-10-05 19:39:30 +0200423 if (tb[NL80211_KEY_TYPE]) {
424 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
425 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
426 return -EINVAL;
427 }
428
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100429 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
430 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100431 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
432 tb[NL80211_KEY_DEFAULT_TYPES],
433 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100434 if (err)
435 return err;
436
437 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
438 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
439 }
440
Johannes Bergb9454e82009-07-08 13:29:08 +0200441 return 0;
442}
443
444static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
445{
446 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
447 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
448 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
449 }
450
451 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
452 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
453 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
454 }
455
456 if (info->attrs[NL80211_ATTR_KEY_IDX])
457 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
458
459 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
460 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
461
462 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
463 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
464
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100465 if (k->def) {
466 k->def_uni = true;
467 k->def_multi = true;
468 }
469 if (k->defmgmt)
470 k->def_multi = true;
471
Johannes Berge31b8212010-10-05 19:39:30 +0200472 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
473 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
474 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
475 return -EINVAL;
476 }
477
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100478 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
479 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
480 int err = nla_parse_nested(
481 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
482 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
483 nl80211_key_default_policy);
484 if (err)
485 return err;
486
487 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
488 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
489 }
490
Johannes Bergb9454e82009-07-08 13:29:08 +0200491 return 0;
492}
493
494static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
495{
496 int err;
497
498 memset(k, 0, sizeof(*k));
499 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200500 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200501
502 if (info->attrs[NL80211_ATTR_KEY])
503 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
504 else
505 err = nl80211_parse_key_old(info, k);
506
507 if (err)
508 return err;
509
510 if (k->def && k->defmgmt)
511 return -EINVAL;
512
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100513 if (k->defmgmt) {
514 if (k->def_uni || !k->def_multi)
515 return -EINVAL;
516 }
517
Johannes Bergb9454e82009-07-08 13:29:08 +0200518 if (k->idx != -1) {
519 if (k->defmgmt) {
520 if (k->idx < 4 || k->idx > 5)
521 return -EINVAL;
522 } else if (k->def) {
523 if (k->idx < 0 || k->idx > 3)
524 return -EINVAL;
525 } else {
526 if (k->idx < 0 || k->idx > 5)
527 return -EINVAL;
528 }
529 }
530
531 return 0;
532}
533
Johannes Bergfffd0932009-07-08 14:22:54 +0200534static struct cfg80211_cached_keys *
535nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
536 struct nlattr *keys)
537{
538 struct key_parse parse;
539 struct nlattr *key;
540 struct cfg80211_cached_keys *result;
541 int rem, err, def = 0;
542
543 result = kzalloc(sizeof(*result), GFP_KERNEL);
544 if (!result)
545 return ERR_PTR(-ENOMEM);
546
547 result->def = -1;
548 result->defmgmt = -1;
549
550 nla_for_each_nested(key, keys, rem) {
551 memset(&parse, 0, sizeof(parse));
552 parse.idx = -1;
553
554 err = nl80211_parse_key_new(key, &parse);
555 if (err)
556 goto error;
557 err = -EINVAL;
558 if (!parse.p.key)
559 goto error;
560 if (parse.idx < 0 || parse.idx > 4)
561 goto error;
562 if (parse.def) {
563 if (def)
564 goto error;
565 def = 1;
566 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100567 if (!parse.def_uni || !parse.def_multi)
568 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200569 } else if (parse.defmgmt)
570 goto error;
571 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200572 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200573 if (err)
574 goto error;
575 result->params[parse.idx].cipher = parse.p.cipher;
576 result->params[parse.idx].key_len = parse.p.key_len;
577 result->params[parse.idx].key = result->data[parse.idx];
578 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
579 }
580
581 return result;
582 error:
583 kfree(result);
584 return ERR_PTR(err);
585}
586
587static int nl80211_key_allowed(struct wireless_dev *wdev)
588{
589 ASSERT_WDEV_LOCK(wdev);
590
Johannes Bergfffd0932009-07-08 14:22:54 +0200591 switch (wdev->iftype) {
592 case NL80211_IFTYPE_AP:
593 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200594 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700595 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200596 break;
597 case NL80211_IFTYPE_ADHOC:
598 if (!wdev->current_bss)
599 return -ENOLINK;
600 break;
601 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200602 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200603 if (wdev->sme_state != CFG80211_SME_CONNECTED)
604 return -ENOLINK;
605 break;
606 default:
607 return -EINVAL;
608 }
609
610 return 0;
611}
612
Johannes Berg7527a782011-05-13 10:58:57 +0200613static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
614{
615 struct nlattr *nl_modes = nla_nest_start(msg, attr);
616 int i;
617
618 if (!nl_modes)
619 goto nla_put_failure;
620
621 i = 0;
622 while (ifmodes) {
623 if (ifmodes & 1)
624 NLA_PUT_FLAG(msg, i);
625 ifmodes >>= 1;
626 i++;
627 }
628
629 nla_nest_end(msg, nl_modes);
630 return 0;
631
632nla_put_failure:
633 return -ENOBUFS;
634}
635
636static int nl80211_put_iface_combinations(struct wiphy *wiphy,
637 struct sk_buff *msg)
638{
639 struct nlattr *nl_combis;
640 int i, j;
641
642 nl_combis = nla_nest_start(msg,
643 NL80211_ATTR_INTERFACE_COMBINATIONS);
644 if (!nl_combis)
645 goto nla_put_failure;
646
647 for (i = 0; i < wiphy->n_iface_combinations; i++) {
648 const struct ieee80211_iface_combination *c;
649 struct nlattr *nl_combi, *nl_limits;
650
651 c = &wiphy->iface_combinations[i];
652
653 nl_combi = nla_nest_start(msg, i + 1);
654 if (!nl_combi)
655 goto nla_put_failure;
656
657 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
658 if (!nl_limits)
659 goto nla_put_failure;
660
661 for (j = 0; j < c->n_limits; j++) {
662 struct nlattr *nl_limit;
663
664 nl_limit = nla_nest_start(msg, j + 1);
665 if (!nl_limit)
666 goto nla_put_failure;
667 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
668 c->limits[j].max);
669 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
670 c->limits[j].types))
671 goto nla_put_failure;
672 nla_nest_end(msg, nl_limit);
673 }
674
675 nla_nest_end(msg, nl_limits);
676
677 if (c->beacon_int_infra_match)
678 NLA_PUT_FLAG(msg,
679 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
680 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
681 c->num_different_channels);
682 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
683 c->max_interfaces);
684
685 nla_nest_end(msg, nl_combi);
686 }
687
688 nla_nest_end(msg, nl_combis);
689
690 return 0;
691nla_put_failure:
692 return -ENOBUFS;
693}
694
Johannes Berg55682962007-09-20 13:09:35 -0400695static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
696 struct cfg80211_registered_device *dev)
697{
698 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100699 struct nlattr *nl_bands, *nl_band;
700 struct nlattr *nl_freqs, *nl_freq;
701 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100702 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100703 enum ieee80211_band band;
704 struct ieee80211_channel *chan;
705 struct ieee80211_rate *rate;
706 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200707 const struct ieee80211_txrx_stypes *mgmt_stypes =
708 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400709
710 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
711 if (!hdr)
712 return -1;
713
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500714 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400715 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200716
Johannes Bergf5ea9122009-08-07 16:17:38 +0200717 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
718 cfg80211_rdev_list_generation);
719
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200720 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
721 dev->wiphy.retry_short);
722 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
723 dev->wiphy.retry_long);
724 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
725 dev->wiphy.frag_threshold);
726 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
727 dev->wiphy.rts_threshold);
Lukáš Turek81077e82009-12-21 22:50:47 +0100728 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
729 dev->wiphy.coverage_class);
Johannes Berg2a519312009-02-10 21:25:55 +0100730 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
731 dev->wiphy.max_scan_ssids);
Luciano Coelho93b6aa62011-07-13 14:57:28 +0300732 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
733 dev->wiphy.max_sched_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200734 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
735 dev->wiphy.max_scan_ie_len);
Luciano Coelho5a865ba2011-07-13 14:57:29 +0300736 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
737 dev->wiphy.max_sched_scan_ie_len);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300738 NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
739 dev->wiphy.max_match_sets);
Johannes Bergee688b002008-01-24 19:38:39 +0100740
Johannes Berge31b8212010-10-05 19:39:30 +0200741 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
742 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
Javier Cardona15d5dda2011-04-07 15:08:28 -0700743 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
744 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
Eliad Pellercedb5412011-08-31 11:29:43 +0300745 if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
746 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530747 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
748 NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300749 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
750 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
751 if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
752 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530753
Johannes Berg25e47c12009-04-02 20:14:06 +0200754 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
755 sizeof(u32) * dev->wiphy.n_cipher_suites,
756 dev->wiphy.cipher_suites);
757
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100758 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
759 dev->wiphy.max_num_pmkids);
760
Johannes Bergc0692b82010-08-27 14:26:53 +0300761 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
762 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
763
Bruno Randolf39fd5de2010-12-16 11:30:28 +0900764 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
765 dev->wiphy.available_antennas_tx);
766 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
767 dev->wiphy.available_antennas_rx);
768
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200769 if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD)
770 NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
771 dev->wiphy.probe_resp_offload);
772
Bruno Randolf7f531e02010-12-16 11:30:22 +0900773 if ((dev->wiphy.available_antennas_tx ||
774 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900775 u32 tx_ant = 0, rx_ant = 0;
776 int res;
777 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
778 if (!res) {
779 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
780 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
781 }
782 }
783
Johannes Berg7527a782011-05-13 10:58:57 +0200784 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
785 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700786 goto nla_put_failure;
787
Johannes Bergee688b002008-01-24 19:38:39 +0100788 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
789 if (!nl_bands)
790 goto nla_put_failure;
791
792 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
793 if (!dev->wiphy.bands[band])
794 continue;
795
796 nl_band = nla_nest_start(msg, band);
797 if (!nl_band)
798 goto nla_put_failure;
799
Johannes Bergd51626d2008-10-09 12:20:13 +0200800 /* add HT info */
801 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
802 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
803 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
804 &dev->wiphy.bands[band]->ht_cap.mcs);
805 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
806 dev->wiphy.bands[band]->ht_cap.cap);
807 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
808 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
809 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
810 dev->wiphy.bands[band]->ht_cap.ampdu_density);
811 }
812
Johannes Bergee688b002008-01-24 19:38:39 +0100813 /* add frequencies */
814 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
815 if (!nl_freqs)
816 goto nla_put_failure;
817
818 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
819 nl_freq = nla_nest_start(msg, i);
820 if (!nl_freq)
821 goto nla_put_failure;
822
823 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100824
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400825 if (nl80211_msg_put_channel(msg, chan))
826 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200827
Johannes Bergee688b002008-01-24 19:38:39 +0100828 nla_nest_end(msg, nl_freq);
829 }
830
831 nla_nest_end(msg, nl_freqs);
832
833 /* add bitrates */
834 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
835 if (!nl_rates)
836 goto nla_put_failure;
837
838 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
839 nl_rate = nla_nest_start(msg, i);
840 if (!nl_rate)
841 goto nla_put_failure;
842
843 rate = &dev->wiphy.bands[band]->bitrates[i];
844 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
845 rate->bitrate);
846 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
847 NLA_PUT_FLAG(msg,
848 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
849
850 nla_nest_end(msg, nl_rate);
851 }
852
853 nla_nest_end(msg, nl_rates);
854
855 nla_nest_end(msg, nl_band);
856 }
857 nla_nest_end(msg, nl_bands);
858
Johannes Berg8fdc6212009-03-14 09:34:01 +0100859 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
860 if (!nl_cmds)
861 goto nla_put_failure;
862
863 i = 0;
864#define CMD(op, n) \
865 do { \
866 if (dev->ops->op) { \
867 i++; \
868 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
869 } \
870 } while (0)
871
872 CMD(add_virtual_intf, NEW_INTERFACE);
873 CMD(change_virtual_intf, SET_INTERFACE);
874 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100875 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100876 CMD(add_station, NEW_STATION);
877 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800878 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100879 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200880 CMD(auth, AUTHENTICATE);
881 CMD(assoc, ASSOCIATE);
882 CMD(deauth, DEAUTHENTICATE);
883 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200884 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100885 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100886 CMD(set_pmksa, SET_PMKSA);
887 CMD(del_pmksa, DEL_PMKSA);
888 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +0100889 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
890 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200891 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +0200892 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100893 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +0100894 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +0200895 i++;
896 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
897 }
Johannes Bergf444de02010-05-05 15:25:02 +0200898 CMD(set_channel, SET_CHANNEL);
Bill Jordane8347eb2010-10-01 13:54:28 -0400899 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +0300900 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
901 CMD(tdls_mgmt, TDLS_MGMT);
902 CMD(tdls_oper, TDLS_OPER);
903 }
Luciano Coelho807f8a82011-05-11 17:09:35 +0300904 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
905 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +0100906 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100907 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +0100908 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
909 i++;
910 NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS);
911 }
Johannes Berg8fdc6212009-03-14 09:34:01 +0100912
Kalle Valo4745fc02011-11-17 19:06:10 +0200913#ifdef CONFIG_NL80211_TESTMODE
914 CMD(testmode_cmd, TESTMODE);
915#endif
916
Johannes Berg8fdc6212009-03-14 09:34:01 +0100917#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +0200918
Johannes Berg6829c872009-07-02 09:13:27 +0200919 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200920 i++;
921 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
922 }
923
Johannes Berg6829c872009-07-02 09:13:27 +0200924 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200925 i++;
926 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
927 }
928
Johannes Berg8fdc6212009-03-14 09:34:01 +0100929 nla_nest_end(msg, nl_cmds);
930
Johannes Berg7c4ef712011-11-18 15:33:48 +0100931 if (dev->ops->remain_on_channel &&
932 dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berga2939112010-12-14 17:54:28 +0100933 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
934 dev->wiphy.max_remain_on_channel_duration);
935
Johannes Berg7c4ef712011-11-18 15:33:48 +0100936 if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100937 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
938
Johannes Berg2e161f72010-08-12 15:38:38 +0200939 if (mgmt_stypes) {
940 u16 stypes;
941 struct nlattr *nl_ftypes, *nl_ifs;
942 enum nl80211_iftype ift;
943
944 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
945 if (!nl_ifs)
946 goto nla_put_failure;
947
948 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
949 nl_ftypes = nla_nest_start(msg, ift);
950 if (!nl_ftypes)
951 goto nla_put_failure;
952 i = 0;
953 stypes = mgmt_stypes[ift].tx;
954 while (stypes) {
955 if (stypes & 1)
956 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
957 (i << 4) | IEEE80211_FTYPE_MGMT);
958 stypes >>= 1;
959 i++;
960 }
961 nla_nest_end(msg, nl_ftypes);
962 }
963
Johannes Berg74b70a42010-08-24 12:15:53 +0200964 nla_nest_end(msg, nl_ifs);
965
Johannes Berg2e161f72010-08-12 15:38:38 +0200966 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
967 if (!nl_ifs)
968 goto nla_put_failure;
969
970 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
971 nl_ftypes = nla_nest_start(msg, ift);
972 if (!nl_ftypes)
973 goto nla_put_failure;
974 i = 0;
975 stypes = mgmt_stypes[ift].rx;
976 while (stypes) {
977 if (stypes & 1)
978 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
979 (i << 4) | IEEE80211_FTYPE_MGMT);
980 stypes >>= 1;
981 i++;
982 }
983 nla_nest_end(msg, nl_ftypes);
984 }
985 nla_nest_end(msg, nl_ifs);
986 }
987
Johannes Bergff1b6e62011-05-04 15:37:28 +0200988 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
989 struct nlattr *nl_wowlan;
990
991 nl_wowlan = nla_nest_start(msg,
992 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
993 if (!nl_wowlan)
994 goto nla_put_failure;
995
996 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
997 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
998 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
999 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
1000 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
1001 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02001002 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
1003 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
1004 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
1005 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
1006 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
1007 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
1008 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
1009 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
1010 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
1011 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02001012 if (dev->wiphy.wowlan.n_patterns) {
1013 struct nl80211_wowlan_pattern_support pat = {
1014 .max_patterns = dev->wiphy.wowlan.n_patterns,
1015 .min_pattern_len =
1016 dev->wiphy.wowlan.pattern_min_len,
1017 .max_pattern_len =
1018 dev->wiphy.wowlan.pattern_max_len,
1019 };
1020 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1021 sizeof(pat), &pat);
1022 }
1023
1024 nla_nest_end(msg, nl_wowlan);
1025 }
1026
Johannes Berg7527a782011-05-13 10:58:57 +02001027 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1028 dev->wiphy.software_iftypes))
1029 goto nla_put_failure;
1030
1031 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1032 goto nla_put_failure;
1033
Johannes Berg562a7482011-11-07 12:39:33 +01001034 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
1035 NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
1036 dev->wiphy.ap_sme_capa);
1037
Johannes Berg1f074bd2011-11-06 14:13:33 +01001038 NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features);
1039
Ben Greear7e7c8922011-11-18 11:31:59 -08001040 if (dev->wiphy.ht_capa_mod_mask)
1041 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1042 sizeof(*dev->wiphy.ht_capa_mod_mask),
1043 dev->wiphy.ht_capa_mod_mask);
1044
Johannes Berg55682962007-09-20 13:09:35 -04001045 return genlmsg_end(msg, hdr);
1046
1047 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001048 genlmsg_cancel(msg, hdr);
1049 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001050}
1051
1052static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1053{
1054 int idx = 0;
1055 int start = cb->args[0];
1056 struct cfg80211_registered_device *dev;
1057
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001058 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001059 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001060 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1061 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001062 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001063 continue;
1064 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1065 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001066 dev) < 0) {
1067 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001068 break;
Julius Volzb4637272008-07-08 14:02:19 +02001069 }
Johannes Berg55682962007-09-20 13:09:35 -04001070 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001071 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001072
1073 cb->args[0] = idx;
1074
1075 return skb->len;
1076}
1077
1078static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1079{
1080 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001081 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001082
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001083 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001084 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001085 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001086
Johannes Berg4c476992010-10-04 21:36:35 +02001087 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1088 nlmsg_free(msg);
1089 return -ENOBUFS;
1090 }
Johannes Berg55682962007-09-20 13:09:35 -04001091
Johannes Berg134e6372009-07-10 09:51:34 +00001092 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001093}
1094
Jouni Malinen31888482008-10-30 16:59:24 +02001095static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1096 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1097 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1098 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1099 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1100 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1101};
1102
1103static int parse_txq_params(struct nlattr *tb[],
1104 struct ieee80211_txq_params *txq_params)
1105{
1106 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1107 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1108 !tb[NL80211_TXQ_ATTR_AIFS])
1109 return -EINVAL;
1110
1111 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1112 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1113 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1114 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1115 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1116
1117 return 0;
1118}
1119
Johannes Bergf444de02010-05-05 15:25:02 +02001120static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1121{
1122 /*
1123 * You can only set the channel explicitly for AP, mesh
1124 * and WDS type interfaces; all others have their channel
1125 * managed via their respective "establish a connection"
1126 * command (connect, join, ...)
1127 *
1128 * Monitors are special as they are normally slaved to
1129 * whatever else is going on, so they behave as though
1130 * you tried setting the wiphy channel itself.
1131 */
1132 return !wdev ||
1133 wdev->iftype == NL80211_IFTYPE_AP ||
1134 wdev->iftype == NL80211_IFTYPE_WDS ||
1135 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001136 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1137 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001138}
1139
1140static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1141 struct wireless_dev *wdev,
1142 struct genl_info *info)
1143{
1144 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1145 u32 freq;
1146 int result;
1147
1148 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1149 return -EINVAL;
1150
1151 if (!nl80211_can_set_dev_channel(wdev))
1152 return -EOPNOTSUPP;
1153
1154 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1155 channel_type = nla_get_u32(info->attrs[
1156 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1157 if (channel_type != NL80211_CHAN_NO_HT &&
1158 channel_type != NL80211_CHAN_HT20 &&
1159 channel_type != NL80211_CHAN_HT40PLUS &&
1160 channel_type != NL80211_CHAN_HT40MINUS)
1161 return -EINVAL;
1162 }
1163
1164 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1165
1166 mutex_lock(&rdev->devlist_mtx);
1167 if (wdev) {
1168 wdev_lock(wdev);
1169 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1170 wdev_unlock(wdev);
1171 } else {
1172 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1173 }
1174 mutex_unlock(&rdev->devlist_mtx);
1175
1176 return result;
1177}
1178
1179static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1180{
Johannes Berg4c476992010-10-04 21:36:35 +02001181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1182 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001183
Johannes Berg4c476992010-10-04 21:36:35 +02001184 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001185}
1186
Bill Jordane8347eb2010-10-01 13:54:28 -04001187static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1188{
Johannes Berg43b19952010-10-07 13:10:30 +02001189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1190 struct net_device *dev = info->user_ptr[1];
1191 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001192 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001193
1194 if (!info->attrs[NL80211_ATTR_MAC])
1195 return -EINVAL;
1196
Johannes Berg43b19952010-10-07 13:10:30 +02001197 if (netif_running(dev))
1198 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001199
Johannes Berg43b19952010-10-07 13:10:30 +02001200 if (!rdev->ops->set_wds_peer)
1201 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001202
Johannes Berg43b19952010-10-07 13:10:30 +02001203 if (wdev->iftype != NL80211_IFTYPE_WDS)
1204 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001205
1206 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001207 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001208}
1209
1210
Johannes Berg55682962007-09-20 13:09:35 -04001211static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1212{
1213 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001214 struct net_device *netdev = NULL;
1215 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001216 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001217 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001218 u32 changed;
1219 u8 retry_short = 0, retry_long = 0;
1220 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001221 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001222
Johannes Bergf444de02010-05-05 15:25:02 +02001223 /*
1224 * Try to find the wiphy and netdev. Normally this
1225 * function shouldn't need the netdev, but this is
1226 * done for backward compatibility -- previously
1227 * setting the channel was done per wiphy, but now
1228 * it is per netdev. Previous userland like hostapd
1229 * also passed a netdev to set_wiphy, so that it is
1230 * possible to let that go to the right netdev!
1231 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001232 mutex_lock(&cfg80211_mutex);
1233
Johannes Bergf444de02010-05-05 15:25:02 +02001234 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1235 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1236
1237 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1238 if (netdev && netdev->ieee80211_ptr) {
1239 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1240 mutex_lock(&rdev->mtx);
1241 } else
1242 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001243 }
1244
Johannes Bergf444de02010-05-05 15:25:02 +02001245 if (!netdev) {
1246 rdev = __cfg80211_rdev_from_info(info);
1247 if (IS_ERR(rdev)) {
1248 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001249 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001250 }
1251 wdev = NULL;
1252 netdev = NULL;
1253 result = 0;
1254
1255 mutex_lock(&rdev->mtx);
1256 } else if (netif_running(netdev) &&
1257 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1258 wdev = netdev->ieee80211_ptr;
1259 else
1260 wdev = NULL;
1261
1262 /*
1263 * end workaround code, by now the rdev is available
1264 * and locked, and wdev may or may not be NULL.
1265 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001266
1267 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001268 result = cfg80211_dev_rename(
1269 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001270
1271 mutex_unlock(&cfg80211_mutex);
1272
1273 if (result)
1274 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001275
Jouni Malinen31888482008-10-30 16:59:24 +02001276 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1277 struct ieee80211_txq_params txq_params;
1278 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1279
1280 if (!rdev->ops->set_txq_params) {
1281 result = -EOPNOTSUPP;
1282 goto bad_res;
1283 }
1284
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001285 if (!netdev) {
1286 result = -EINVAL;
1287 goto bad_res;
1288 }
1289
Johannes Berg133a3ff2011-11-03 14:50:13 +01001290 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1291 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1292 result = -EINVAL;
1293 goto bad_res;
1294 }
1295
Jouni Malinen31888482008-10-30 16:59:24 +02001296 nla_for_each_nested(nl_txq_params,
1297 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1298 rem_txq_params) {
1299 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1300 nla_data(nl_txq_params),
1301 nla_len(nl_txq_params),
1302 txq_params_policy);
1303 result = parse_txq_params(tb, &txq_params);
1304 if (result)
1305 goto bad_res;
1306
1307 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001308 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001309 &txq_params);
1310 if (result)
1311 goto bad_res;
1312 }
1313 }
1314
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001315 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001316 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001317 if (result)
1318 goto bad_res;
1319 }
1320
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001321 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1322 enum nl80211_tx_power_setting type;
1323 int idx, mbm = 0;
1324
1325 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001326 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001327 goto bad_res;
1328 }
1329
1330 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1331 type = nla_get_u32(info->attrs[idx]);
1332
1333 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1334 (type != NL80211_TX_POWER_AUTOMATIC)) {
1335 result = -EINVAL;
1336 goto bad_res;
1337 }
1338
1339 if (type != NL80211_TX_POWER_AUTOMATIC) {
1340 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1341 mbm = nla_get_u32(info->attrs[idx]);
1342 }
1343
1344 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1345 if (result)
1346 goto bad_res;
1347 }
1348
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001349 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1350 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1351 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001352 if ((!rdev->wiphy.available_antennas_tx &&
1353 !rdev->wiphy.available_antennas_rx) ||
1354 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001355 result = -EOPNOTSUPP;
1356 goto bad_res;
1357 }
1358
1359 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1360 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1361
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001362 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001363 * available antenna masks, except for the "all" mask */
1364 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1365 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001366 result = -EINVAL;
1367 goto bad_res;
1368 }
1369
Bruno Randolf7f531e02010-12-16 11:30:22 +09001370 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1371 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001372
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001373 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1374 if (result)
1375 goto bad_res;
1376 }
1377
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001378 changed = 0;
1379
1380 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1381 retry_short = nla_get_u8(
1382 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1383 if (retry_short == 0) {
1384 result = -EINVAL;
1385 goto bad_res;
1386 }
1387 changed |= WIPHY_PARAM_RETRY_SHORT;
1388 }
1389
1390 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1391 retry_long = nla_get_u8(
1392 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1393 if (retry_long == 0) {
1394 result = -EINVAL;
1395 goto bad_res;
1396 }
1397 changed |= WIPHY_PARAM_RETRY_LONG;
1398 }
1399
1400 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1401 frag_threshold = nla_get_u32(
1402 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1403 if (frag_threshold < 256) {
1404 result = -EINVAL;
1405 goto bad_res;
1406 }
1407 if (frag_threshold != (u32) -1) {
1408 /*
1409 * Fragments (apart from the last one) are required to
1410 * have even length. Make the fragmentation code
1411 * simpler by stripping LSB should someone try to use
1412 * odd threshold value.
1413 */
1414 frag_threshold &= ~0x1;
1415 }
1416 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1417 }
1418
1419 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1420 rts_threshold = nla_get_u32(
1421 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1422 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1423 }
1424
Lukáš Turek81077e82009-12-21 22:50:47 +01001425 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1426 coverage_class = nla_get_u8(
1427 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1428 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1429 }
1430
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001431 if (changed) {
1432 u8 old_retry_short, old_retry_long;
1433 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001434 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001435
1436 if (!rdev->ops->set_wiphy_params) {
1437 result = -EOPNOTSUPP;
1438 goto bad_res;
1439 }
1440
1441 old_retry_short = rdev->wiphy.retry_short;
1442 old_retry_long = rdev->wiphy.retry_long;
1443 old_frag_threshold = rdev->wiphy.frag_threshold;
1444 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001445 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001446
1447 if (changed & WIPHY_PARAM_RETRY_SHORT)
1448 rdev->wiphy.retry_short = retry_short;
1449 if (changed & WIPHY_PARAM_RETRY_LONG)
1450 rdev->wiphy.retry_long = retry_long;
1451 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1452 rdev->wiphy.frag_threshold = frag_threshold;
1453 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1454 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001455 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1456 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001457
1458 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1459 if (result) {
1460 rdev->wiphy.retry_short = old_retry_short;
1461 rdev->wiphy.retry_long = old_retry_long;
1462 rdev->wiphy.frag_threshold = old_frag_threshold;
1463 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001464 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001465 }
1466 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001467
Johannes Berg306d6112008-12-08 12:39:04 +01001468 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001469 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001470 if (netdev)
1471 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001472 return result;
1473}
1474
1475
1476static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001477 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001478 struct net_device *dev)
1479{
1480 void *hdr;
1481
1482 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1483 if (!hdr)
1484 return -1;
1485
1486 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +02001487 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -04001488 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +02001489 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001490
1491 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1492 rdev->devlist_generation ^
1493 (cfg80211_rdev_list_generation << 2));
1494
Johannes Berg55682962007-09-20 13:09:35 -04001495 return genlmsg_end(msg, hdr);
1496
1497 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001498 genlmsg_cancel(msg, hdr);
1499 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001500}
1501
1502static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1503{
1504 int wp_idx = 0;
1505 int if_idx = 0;
1506 int wp_start = cb->args[0];
1507 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001508 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001509 struct wireless_dev *wdev;
1510
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001511 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001512 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1513 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001514 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001515 if (wp_idx < wp_start) {
1516 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001517 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001518 }
Johannes Berg55682962007-09-20 13:09:35 -04001519 if_idx = 0;
1520
Johannes Bergf5ea9122009-08-07 16:17:38 +02001521 mutex_lock(&rdev->devlist_mtx);
1522 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001523 if (if_idx < if_start) {
1524 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001525 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001526 }
Johannes Berg55682962007-09-20 13:09:35 -04001527 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1528 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001529 rdev, wdev->netdev) < 0) {
1530 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001531 goto out;
1532 }
1533 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001534 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001535 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001536
1537 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001538 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001539 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001540 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001541
1542 cb->args[0] = wp_idx;
1543 cb->args[1] = if_idx;
1544
1545 return skb->len;
1546}
1547
1548static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1549{
1550 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001551 struct cfg80211_registered_device *dev = info->user_ptr[0];
1552 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001553
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001555 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001556 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001557
Johannes Bergd7264052009-04-19 16:23:20 +02001558 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001559 dev, netdev) < 0) {
1560 nlmsg_free(msg);
1561 return -ENOBUFS;
1562 }
Johannes Berg55682962007-09-20 13:09:35 -04001563
Johannes Berg134e6372009-07-10 09:51:34 +00001564 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001565}
1566
Michael Wu66f7ac52008-01-31 19:48:22 +01001567static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1568 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1569 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1570 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1571 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1572 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1573};
1574
1575static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1576{
1577 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1578 int flag;
1579
1580 *mntrflags = 0;
1581
1582 if (!nla)
1583 return -EINVAL;
1584
1585 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1586 nla, mntr_flags_policy))
1587 return -EINVAL;
1588
1589 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1590 if (flags[flag])
1591 *mntrflags |= (1<<flag);
1592
1593 return 0;
1594}
1595
Johannes Berg9bc383d2009-11-19 11:55:19 +01001596static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001597 struct net_device *netdev, u8 use_4addr,
1598 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001599{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001600 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001601 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001602 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001603 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001604 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001605
1606 switch (iftype) {
1607 case NL80211_IFTYPE_AP_VLAN:
1608 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1609 return 0;
1610 break;
1611 case NL80211_IFTYPE_STATION:
1612 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1613 return 0;
1614 break;
1615 default:
1616 break;
1617 }
1618
1619 return -EOPNOTSUPP;
1620}
1621
Johannes Berg55682962007-09-20 13:09:35 -04001622static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1623{
Johannes Berg4c476992010-10-04 21:36:35 +02001624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001625 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001626 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001627 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001628 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001629 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001630 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001631
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001632 memset(&params, 0, sizeof(params));
1633
Johannes Berg04a773a2009-04-19 21:24:32 +02001634 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001635
Johannes Berg723b0382008-09-16 20:22:09 +02001636 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001637 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001638 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001639 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001640 if (ntype > NL80211_IFTYPE_MAX)
1641 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001642 }
1643
Johannes Berg92ffe052008-09-16 20:39:36 +02001644 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001645 struct wireless_dev *wdev = dev->ieee80211_ptr;
1646
Johannes Berg4c476992010-10-04 21:36:35 +02001647 if (ntype != NL80211_IFTYPE_MESH_POINT)
1648 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001649 if (netif_running(dev))
1650 return -EBUSY;
1651
1652 wdev_lock(wdev);
1653 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1654 IEEE80211_MAX_MESH_ID_LEN);
1655 wdev->mesh_id_up_len =
1656 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1657 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1658 wdev->mesh_id_up_len);
1659 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001660 }
1661
Felix Fietkau8b787642009-11-10 18:53:10 +01001662 if (info->attrs[NL80211_ATTR_4ADDR]) {
1663 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1664 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001665 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001666 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001667 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001668 } else {
1669 params.use_4addr = -1;
1670 }
1671
Johannes Berg92ffe052008-09-16 20:39:36 +02001672 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001673 if (ntype != NL80211_IFTYPE_MONITOR)
1674 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001675 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1676 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001677 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001678 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001679
1680 flags = &_flags;
1681 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001682 }
Johannes Berg3b858752009-03-12 09:55:09 +01001683
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001684 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001685 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001686 else
1687 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001688
Johannes Berg9bc383d2009-11-19 11:55:19 +01001689 if (!err && params.use_4addr != -1)
1690 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1691
Johannes Berg55682962007-09-20 13:09:35 -04001692 return err;
1693}
1694
1695static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1696{
Johannes Berg4c476992010-10-04 21:36:35 +02001697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001698 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001699 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001700 int err;
1701 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001702 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001703
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001704 memset(&params, 0, sizeof(params));
1705
Johannes Berg55682962007-09-20 13:09:35 -04001706 if (!info->attrs[NL80211_ATTR_IFNAME])
1707 return -EINVAL;
1708
1709 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1710 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1711 if (type > NL80211_IFTYPE_MAX)
1712 return -EINVAL;
1713 }
1714
Johannes Berg79c97e92009-07-07 03:56:12 +02001715 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001716 !(rdev->wiphy.interface_modes & (1 << type)))
1717 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001718
Johannes Berg9bc383d2009-11-19 11:55:19 +01001719 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001720 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001721 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001722 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001723 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001724 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001725
Michael Wu66f7ac52008-01-31 19:48:22 +01001726 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1727 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1728 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001729 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001730 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001731 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001732 if (IS_ERR(dev))
1733 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001734
Johannes Berg29cbe682010-12-03 09:20:44 +01001735 if (type == NL80211_IFTYPE_MESH_POINT &&
1736 info->attrs[NL80211_ATTR_MESH_ID]) {
1737 struct wireless_dev *wdev = dev->ieee80211_ptr;
1738
1739 wdev_lock(wdev);
1740 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1741 IEEE80211_MAX_MESH_ID_LEN);
1742 wdev->mesh_id_up_len =
1743 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1744 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1745 wdev->mesh_id_up_len);
1746 wdev_unlock(wdev);
1747 }
1748
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001749 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001750}
1751
1752static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1753{
Johannes Berg4c476992010-10-04 21:36:35 +02001754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1755 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001756
Johannes Berg4c476992010-10-04 21:36:35 +02001757 if (!rdev->ops->del_virtual_intf)
1758 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001759
Johannes Berg4c476992010-10-04 21:36:35 +02001760 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001761}
1762
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001763static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1764{
1765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1766 struct net_device *dev = info->user_ptr[1];
1767 u16 noack_map;
1768
1769 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1770 return -EINVAL;
1771
1772 if (!rdev->ops->set_noack_map)
1773 return -EOPNOTSUPP;
1774
1775 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1776
1777 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1778}
1779
Johannes Berg41ade002007-12-19 02:03:29 +01001780struct get_key_cookie {
1781 struct sk_buff *msg;
1782 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001783 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001784};
1785
1786static void get_key_callback(void *c, struct key_params *params)
1787{
Johannes Bergb9454e82009-07-08 13:29:08 +02001788 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001789 struct get_key_cookie *cookie = c;
1790
1791 if (params->key)
1792 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1793 params->key_len, params->key);
1794
1795 if (params->seq)
1796 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1797 params->seq_len, params->seq);
1798
1799 if (params->cipher)
1800 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1801 params->cipher);
1802
Johannes Bergb9454e82009-07-08 13:29:08 +02001803 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1804 if (!key)
1805 goto nla_put_failure;
1806
1807 if (params->key)
1808 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1809 params->key_len, params->key);
1810
1811 if (params->seq)
1812 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1813 params->seq_len, params->seq);
1814
1815 if (params->cipher)
1816 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1817 params->cipher);
1818
1819 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1820
1821 nla_nest_end(cookie->msg, key);
1822
Johannes Berg41ade002007-12-19 02:03:29 +01001823 return;
1824 nla_put_failure:
1825 cookie->error = 1;
1826}
1827
1828static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1829{
Johannes Berg4c476992010-10-04 21:36:35 +02001830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01001831 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001832 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001833 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02001834 const u8 *mac_addr = NULL;
1835 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01001836 struct get_key_cookie cookie = {
1837 .error = 0,
1838 };
1839 void *hdr;
1840 struct sk_buff *msg;
1841
1842 if (info->attrs[NL80211_ATTR_KEY_IDX])
1843 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1844
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001845 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001846 return -EINVAL;
1847
1848 if (info->attrs[NL80211_ATTR_MAC])
1849 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1850
Johannes Berge31b8212010-10-05 19:39:30 +02001851 pairwise = !!mac_addr;
1852 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1853 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1854 if (kt >= NUM_NL80211_KEYTYPES)
1855 return -EINVAL;
1856 if (kt != NL80211_KEYTYPE_GROUP &&
1857 kt != NL80211_KEYTYPE_PAIRWISE)
1858 return -EINVAL;
1859 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1860 }
1861
Johannes Berg4c476992010-10-04 21:36:35 +02001862 if (!rdev->ops->get_key)
1863 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01001864
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02001866 if (!msg)
1867 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01001868
1869 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1870 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02001871 if (IS_ERR(hdr))
1872 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01001873
1874 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02001875 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001876
1877 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1878 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1879 if (mac_addr)
1880 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1881
Johannes Berge31b8212010-10-05 19:39:30 +02001882 if (pairwise && mac_addr &&
1883 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1884 return -ENOENT;
1885
1886 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1887 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001888
1889 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001890 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01001891
1892 if (cookie.error)
1893 goto nla_put_failure;
1894
1895 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02001896 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01001897
1898 nla_put_failure:
1899 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03001900 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01001901 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01001902 return err;
1903}
1904
1905static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1906{
Johannes Berg4c476992010-10-04 21:36:35 +02001907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02001908 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01001909 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001910 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01001911
Johannes Bergb9454e82009-07-08 13:29:08 +02001912 err = nl80211_parse_key(info, &key);
1913 if (err)
1914 return err;
1915
1916 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01001917 return -EINVAL;
1918
Johannes Bergb9454e82009-07-08 13:29:08 +02001919 /* only support setting default key */
1920 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01001921 return -EINVAL;
1922
Johannes Bergfffd0932009-07-08 14:22:54 +02001923 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001924
1925 if (key.def) {
1926 if (!rdev->ops->set_default_key) {
1927 err = -EOPNOTSUPP;
1928 goto out;
1929 }
1930
1931 err = nl80211_key_allowed(dev->ieee80211_ptr);
1932 if (err)
1933 goto out;
1934
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001935 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1936 key.def_uni, key.def_multi);
1937
1938 if (err)
1939 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02001940
Johannes Berg3d23e342009-09-29 23:27:28 +02001941#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001942 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02001943#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001944 } else {
1945 if (key.def_uni || !key.def_multi) {
1946 err = -EINVAL;
1947 goto out;
1948 }
1949
1950 if (!rdev->ops->set_default_mgmt_key) {
1951 err = -EOPNOTSUPP;
1952 goto out;
1953 }
1954
1955 err = nl80211_key_allowed(dev->ieee80211_ptr);
1956 if (err)
1957 goto out;
1958
1959 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1960 dev, key.idx);
1961 if (err)
1962 goto out;
1963
1964#ifdef CONFIG_CFG80211_WEXT
1965 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1966#endif
1967 }
1968
1969 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02001970 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01001971
Johannes Berg41ade002007-12-19 02:03:29 +01001972 return err;
1973}
1974
1975static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1976{
Johannes Berg4c476992010-10-04 21:36:35 +02001977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02001978 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02001979 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02001980 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02001981 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01001982
Johannes Bergb9454e82009-07-08 13:29:08 +02001983 err = nl80211_parse_key(info, &key);
1984 if (err)
1985 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01001986
Johannes Bergb9454e82009-07-08 13:29:08 +02001987 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01001988 return -EINVAL;
1989
Johannes Berg41ade002007-12-19 02:03:29 +01001990 if (info->attrs[NL80211_ATTR_MAC])
1991 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1992
Johannes Berge31b8212010-10-05 19:39:30 +02001993 if (key.type == -1) {
1994 if (mac_addr)
1995 key.type = NL80211_KEYTYPE_PAIRWISE;
1996 else
1997 key.type = NL80211_KEYTYPE_GROUP;
1998 }
1999
2000 /* for now */
2001 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2002 key.type != NL80211_KEYTYPE_GROUP)
2003 return -EINVAL;
2004
Johannes Berg4c476992010-10-04 21:36:35 +02002005 if (!rdev->ops->add_key)
2006 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002007
Johannes Berge31b8212010-10-05 19:39:30 +02002008 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2009 key.type == NL80211_KEYTYPE_PAIRWISE,
2010 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002011 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002012
2013 wdev_lock(dev->ieee80211_ptr);
2014 err = nl80211_key_allowed(dev->ieee80211_ptr);
2015 if (!err)
2016 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002017 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002018 mac_addr, &key.p);
2019 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002020
Johannes Berg41ade002007-12-19 02:03:29 +01002021 return err;
2022}
2023
2024static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2025{
Johannes Berg4c476992010-10-04 21:36:35 +02002026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002027 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002028 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002029 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002030 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002031
Johannes Bergb9454e82009-07-08 13:29:08 +02002032 err = nl80211_parse_key(info, &key);
2033 if (err)
2034 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002035
2036 if (info->attrs[NL80211_ATTR_MAC])
2037 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2038
Johannes Berge31b8212010-10-05 19:39:30 +02002039 if (key.type == -1) {
2040 if (mac_addr)
2041 key.type = NL80211_KEYTYPE_PAIRWISE;
2042 else
2043 key.type = NL80211_KEYTYPE_GROUP;
2044 }
2045
2046 /* for now */
2047 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2048 key.type != NL80211_KEYTYPE_GROUP)
2049 return -EINVAL;
2050
Johannes Berg4c476992010-10-04 21:36:35 +02002051 if (!rdev->ops->del_key)
2052 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002053
Johannes Bergfffd0932009-07-08 14:22:54 +02002054 wdev_lock(dev->ieee80211_ptr);
2055 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002056
2057 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2058 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2059 err = -ENOENT;
2060
Johannes Bergfffd0932009-07-08 14:22:54 +02002061 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002062 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2063 key.type == NL80211_KEYTYPE_PAIRWISE,
2064 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002065
Johannes Berg3d23e342009-09-29 23:27:28 +02002066#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002067 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002068 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002069 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002070 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002071 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2072 }
2073#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002074 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002075
Johannes Berg41ade002007-12-19 02:03:29 +01002076 return err;
2077}
2078
Johannes Berg88600202012-02-13 15:17:18 +01002079static int nl80211_parse_beacon(struct genl_info *info,
2080 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002081{
Johannes Berg88600202012-02-13 15:17:18 +01002082 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002083
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002084 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2085 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2086 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2087 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002088 return -EINVAL;
2089
Johannes Berg88600202012-02-13 15:17:18 +01002090 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002091
Johannes Berged1b6cc2007-12-19 02:03:32 +01002092 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002093 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2094 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2095 if (!bcn->head_len)
2096 return -EINVAL;
2097 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002098 }
2099
2100 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002101 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2102 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002103 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002104 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002105 }
2106
Johannes Berg4c476992010-10-04 21:36:35 +02002107 if (!haveinfo)
2108 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002109
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002110 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002111 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2112 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002113 }
2114
2115 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002116 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002117 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002118 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002119 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2120 }
2121
2122 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002123 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002124 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002125 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002126 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2127 }
2128
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002129 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002130 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002131 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002132 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002133 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2134 }
2135
Johannes Berg88600202012-02-13 15:17:18 +01002136 return 0;
2137}
2138
2139static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2140{
2141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2142 struct net_device *dev = info->user_ptr[1];
2143 struct wireless_dev *wdev = dev->ieee80211_ptr;
2144 struct cfg80211_ap_settings params;
2145 int err;
2146
2147 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2148 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2149 return -EOPNOTSUPP;
2150
2151 if (!rdev->ops->start_ap)
2152 return -EOPNOTSUPP;
2153
2154 if (wdev->beacon_interval)
2155 return -EALREADY;
2156
2157 memset(&params, 0, sizeof(params));
2158
2159 /* these are required for START_AP */
2160 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2161 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2162 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2163 return -EINVAL;
2164
2165 err = nl80211_parse_beacon(info, &params.beacon);
2166 if (err)
2167 return err;
2168
2169 params.beacon_interval =
2170 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2171 params.dtim_period =
2172 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2173
2174 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2175 if (err)
2176 return err;
2177
2178 /*
2179 * In theory, some of these attributes should be required here
2180 * but since they were not used when the command was originally
2181 * added, keep them optional for old user space programs to let
2182 * them continue to work with drivers that do not need the
2183 * additional information -- drivers must check!
2184 */
2185 if (info->attrs[NL80211_ATTR_SSID]) {
2186 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2187 params.ssid_len =
2188 nla_len(info->attrs[NL80211_ATTR_SSID]);
2189 if (params.ssid_len == 0 ||
2190 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2191 return -EINVAL;
2192 }
2193
2194 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2195 params.hidden_ssid = nla_get_u32(
2196 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2197 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2198 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2199 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2200 return -EINVAL;
2201 }
2202
2203 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2204
2205 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2206 params.auth_type = nla_get_u32(
2207 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2208 if (!nl80211_valid_auth_type(params.auth_type))
2209 return -EINVAL;
2210 } else
2211 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2212
2213 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2214 NL80211_MAX_NR_CIPHER_SUITES);
2215 if (err)
2216 return err;
2217
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302218 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2219 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2220 return -EOPNOTSUPP;
2221 params.inactivity_timeout = nla_get_u16(
2222 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2223 }
2224
Johannes Berg88600202012-02-13 15:17:18 +01002225 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2226 if (!err)
2227 wdev->beacon_interval = params.beacon_interval;
Johannes Berg56d18932011-05-09 18:41:15 +02002228 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002229}
2230
Johannes Berg88600202012-02-13 15:17:18 +01002231static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2232{
2233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2234 struct net_device *dev = info->user_ptr[1];
2235 struct wireless_dev *wdev = dev->ieee80211_ptr;
2236 struct cfg80211_beacon_data params;
2237 int err;
2238
2239 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2240 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2241 return -EOPNOTSUPP;
2242
2243 if (!rdev->ops->change_beacon)
2244 return -EOPNOTSUPP;
2245
2246 if (!wdev->beacon_interval)
2247 return -EINVAL;
2248
2249 err = nl80211_parse_beacon(info, &params);
2250 if (err)
2251 return err;
2252
2253 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2254}
2255
2256static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002257{
Johannes Berg4c476992010-10-04 21:36:35 +02002258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2259 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002260 struct wireless_dev *wdev = dev->ieee80211_ptr;
2261 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002262
Johannes Berg88600202012-02-13 15:17:18 +01002263 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002264 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002265
Johannes Berg074ac8d2010-09-16 14:58:22 +02002266 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002267 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2268 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002269
Johannes Berg88600202012-02-13 15:17:18 +01002270 if (!wdev->beacon_interval)
2271 return -ENOENT;
2272
2273 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002274 if (!err)
2275 wdev->beacon_interval = 0;
2276 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002277}
2278
Johannes Berg5727ef12007-12-19 02:03:34 +01002279static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2280 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2281 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2282 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002283 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002284 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002285 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002286};
2287
Johannes Bergeccb8e82009-05-11 21:57:56 +03002288static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002289 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002290 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002291{
2292 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002293 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002294 int flag;
2295
Johannes Bergeccb8e82009-05-11 21:57:56 +03002296 /*
2297 * Try parsing the new attribute first so userspace
2298 * can specify both for older kernels.
2299 */
2300 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2301 if (nla) {
2302 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002303
Johannes Bergeccb8e82009-05-11 21:57:56 +03002304 sta_flags = nla_data(nla);
2305 params->sta_flags_mask = sta_flags->mask;
2306 params->sta_flags_set = sta_flags->set;
2307 if ((params->sta_flags_mask |
2308 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2309 return -EINVAL;
2310 return 0;
2311 }
2312
2313 /* if present, parse the old attribute */
2314
2315 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002316 if (!nla)
2317 return 0;
2318
2319 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2320 nla, sta_flags_policy))
2321 return -EINVAL;
2322
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002323 /*
2324 * Only allow certain flags for interface types so that
2325 * other attributes are silently ignored. Remember that
2326 * this is backward compatibility code with old userspace
2327 * and shouldn't be hit in other cases anyway.
2328 */
2329 switch (iftype) {
2330 case NL80211_IFTYPE_AP:
2331 case NL80211_IFTYPE_AP_VLAN:
2332 case NL80211_IFTYPE_P2P_GO:
2333 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2334 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2335 BIT(NL80211_STA_FLAG_WME) |
2336 BIT(NL80211_STA_FLAG_MFP);
2337 break;
2338 case NL80211_IFTYPE_P2P_CLIENT:
2339 case NL80211_IFTYPE_STATION:
2340 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2341 BIT(NL80211_STA_FLAG_TDLS_PEER);
2342 break;
2343 case NL80211_IFTYPE_MESH_POINT:
2344 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2345 BIT(NL80211_STA_FLAG_MFP) |
2346 BIT(NL80211_STA_FLAG_AUTHORIZED);
2347 default:
2348 return -EINVAL;
2349 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002350
2351 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2352 if (flags[flag])
Johannes Bergeccb8e82009-05-11 21:57:56 +03002353 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002354
2355 return 0;
2356}
2357
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002358static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2359 int attr)
2360{
2361 struct nlattr *rate;
2362 u16 bitrate;
2363
2364 rate = nla_nest_start(msg, attr);
2365 if (!rate)
2366 goto nla_put_failure;
2367
2368 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2369 bitrate = cfg80211_calculate_bitrate(info);
2370 if (bitrate > 0)
2371 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2372
2373 if (info->flags & RATE_INFO_FLAGS_MCS)
2374 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2375 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2376 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2377 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2378 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2379
2380 nla_nest_end(msg, rate);
2381 return true;
2382
2383nla_put_failure:
2384 return false;
2385}
2386
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002387static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2388 int flags, struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002389 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002390{
2391 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002392 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002393
2394 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2395 if (!hdr)
2396 return -1;
2397
2398 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2399 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2400
Johannes Bergf5ea9122009-08-07 16:17:38 +02002401 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2402
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2404 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002405 goto nla_put_failure;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +05302406 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2407 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2408 sinfo->connected_time);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002409 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2410 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2411 sinfo->inactive_time);
2412 if (sinfo->filled & STATION_INFO_RX_BYTES)
2413 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2414 sinfo->rx_bytes);
2415 if (sinfo->filled & STATION_INFO_TX_BYTES)
2416 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2417 sinfo->tx_bytes);
2418 if (sinfo->filled & STATION_INFO_LLID)
2419 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2420 sinfo->llid);
2421 if (sinfo->filled & STATION_INFO_PLID)
2422 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2423 sinfo->plid);
2424 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2425 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2426 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002427 if (sinfo->filled & STATION_INFO_SIGNAL)
2428 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2429 sinfo->signal);
Bruno Randolf541a45a2010-12-02 19:12:43 +09002430 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2431 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2432 sinfo->signal_avg);
Henning Rogge420e7fa2008-12-11 22:04:19 +01002433 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002434 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2435 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002436 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002437 }
2438 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2439 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2440 NL80211_STA_INFO_RX_BITRATE))
2441 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002442 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02002443 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2444 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2445 sinfo->rx_packets);
2446 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2447 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2448 sinfo->tx_packets);
Bruno Randolfb206b4e2010-10-06 18:34:12 +09002449 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2450 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2451 sinfo->tx_retries);
2452 if (sinfo->filled & STATION_INFO_TX_FAILED)
2453 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2454 sinfo->tx_failed);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002455 if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT)
2456 NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS,
2457 sinfo->beacon_loss_count);
Paul Stewartf4263c92011-03-31 09:25:41 -07002458 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2459 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2460 if (!bss_param)
2461 goto nla_put_failure;
2462
2463 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2464 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2465 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2466 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2467 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2468 NLA_PUT_FLAG(msg,
2469 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2470 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2471 sinfo->bss_param.dtim_period);
2472 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2473 sinfo->bss_param.beacon_interval);
2474
2475 nla_nest_end(msg, bss_param);
2476 }
Helmut Schaabb6e7532011-10-13 16:30:39 +02002477 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2478 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2479 sizeof(struct nl80211_sta_flag_update),
2480 &sinfo->sta_flags);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002481 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002482
Felix Fietkau040bdf72011-08-10 19:00:33 -06002483 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002484 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2485 sinfo->assoc_req_ies);
2486
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002487 return genlmsg_end(msg, hdr);
2488
2489 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002490 genlmsg_cancel(msg, hdr);
2491 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002492}
2493
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002494static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002495 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002496{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002497 struct station_info sinfo;
2498 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002499 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002500 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002501 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002502 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002503
Johannes Berg67748892010-10-04 21:14:06 +02002504 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2505 if (err)
2506 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002507
2508 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002509 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002510 goto out_err;
2511 }
2512
Johannes Bergbba95fe2008-07-29 13:22:51 +02002513 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002514 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002515 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2516 mac_addr, &sinfo);
2517 if (err == -ENOENT)
2518 break;
2519 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002520 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002521
2522 if (nl80211_send_station(skb,
2523 NETLINK_CB(cb->skb).pid,
2524 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2525 netdev, mac_addr,
2526 &sinfo) < 0)
2527 goto out;
2528
2529 sta_idx++;
2530 }
2531
2532
2533 out:
2534 cb->args[1] = sta_idx;
2535 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002536 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002537 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002538
2539 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002540}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002541
Johannes Berg5727ef12007-12-19 02:03:34 +01002542static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2543{
Johannes Berg4c476992010-10-04 21:36:35 +02002544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2545 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002546 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002547 struct sk_buff *msg;
2548 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002549 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002550
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002551 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002552
2553 if (!info->attrs[NL80211_ATTR_MAC])
2554 return -EINVAL;
2555
2556 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2557
Johannes Berg4c476992010-10-04 21:36:35 +02002558 if (!rdev->ops->get_station)
2559 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002560
Johannes Berg79c97e92009-07-07 03:56:12 +02002561 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002562 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002563 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002564
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002565 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002566 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002567 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002568
2569 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02002570 dev, mac_addr, &sinfo) < 0) {
2571 nlmsg_free(msg);
2572 return -ENOBUFS;
2573 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002574
Johannes Berg4c476992010-10-04 21:36:35 +02002575 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002576}
2577
2578/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002579 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002580 */
Johannes Berg80b99892011-11-18 16:23:01 +01002581static struct net_device *get_vlan(struct genl_info *info,
2582 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002583{
Johannes Berg463d0182009-07-14 00:33:35 +02002584 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002585 struct net_device *v;
2586 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002587
Johannes Berg80b99892011-11-18 16:23:01 +01002588 if (!vlanattr)
2589 return NULL;
2590
2591 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2592 if (!v)
2593 return ERR_PTR(-ENODEV);
2594
2595 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2596 ret = -EINVAL;
2597 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002598 }
Johannes Berg80b99892011-11-18 16:23:01 +01002599
2600 if (!netif_running(v)) {
2601 ret = -ENETDOWN;
2602 goto error;
2603 }
2604
2605 return v;
2606 error:
2607 dev_put(v);
2608 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002609}
2610
2611static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2612{
Johannes Berg4c476992010-10-04 21:36:35 +02002613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002614 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002615 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002616 struct station_parameters params;
2617 u8 *mac_addr = NULL;
2618
2619 memset(&params, 0, sizeof(params));
2620
2621 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002622 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002623
2624 if (info->attrs[NL80211_ATTR_STA_AID])
2625 return -EINVAL;
2626
2627 if (!info->attrs[NL80211_ATTR_MAC])
2628 return -EINVAL;
2629
2630 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2631
2632 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2633 params.supported_rates =
2634 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2635 params.supported_rates_len =
2636 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2637 }
2638
2639 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2640 params.listen_interval =
2641 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2642
Jouni Malinen36aedc92008-08-25 11:58:58 +03002643 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2644 params.ht_capa =
2645 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2646
Johannes Bergbdd90d52011-12-14 12:20:27 +01002647 if (!rdev->ops->change_station)
2648 return -EOPNOTSUPP;
2649
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002650 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002651 return -EINVAL;
2652
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002653 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2654 params.plink_action =
2655 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2656
Javier Cardona9c3990a2011-05-03 16:57:11 -07002657 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2658 params.plink_state =
2659 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2660
Johannes Berga97f4422009-06-18 17:23:43 +02002661 switch (dev->ieee80211_ptr->iftype) {
2662 case NL80211_IFTYPE_AP:
2663 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002664 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002665 /* disallow mesh-specific things */
2666 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002667 return -EINVAL;
2668
2669 /* TDLS can't be set, ... */
2670 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2671 return -EINVAL;
2672 /*
2673 * ... but don't bother the driver with it. This works around
2674 * a hostapd/wpa_supplicant issue -- it always includes the
2675 * TLDS_PEER flag in the mask even for AP mode.
2676 */
2677 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2678
2679 /* accept only the listed bits */
2680 if (params.sta_flags_mask &
2681 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2682 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2683 BIT(NL80211_STA_FLAG_WME) |
2684 BIT(NL80211_STA_FLAG_MFP)))
2685 return -EINVAL;
2686
2687 /* must be last in here for error handling */
2688 params.vlan = get_vlan(info, rdev);
2689 if (IS_ERR(params.vlan))
2690 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002691 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002692 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002693 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002694 /*
2695 * Don't allow userspace to change the TDLS_PEER flag,
2696 * but silently ignore attempts to change it since we
2697 * don't have state here to verify that it doesn't try
2698 * to change the flag.
2699 */
2700 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002701 /* fall through */
2702 case NL80211_IFTYPE_ADHOC:
2703 /* disallow things sta doesn't support */
2704 if (params.plink_action)
2705 return -EINVAL;
2706 if (params.ht_capa)
2707 return -EINVAL;
2708 if (params.listen_interval >= 0)
2709 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002710 /* reject any changes other than AUTHORIZED */
2711 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2712 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002713 break;
2714 case NL80211_IFTYPE_MESH_POINT:
2715 /* disallow things mesh doesn't support */
2716 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002717 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002718 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002719 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002720 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002721 return -EINVAL;
2722 /*
2723 * No special handling for TDLS here -- the userspace
2724 * mesh code doesn't have this bug.
2725 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07002726 if (params.sta_flags_mask &
2727 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07002728 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07002729 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01002730 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002731 break;
2732 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002733 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02002734 }
2735
Johannes Bergbdd90d52011-12-14 12:20:27 +01002736 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002737
Johannes Berg79c97e92009-07-07 03:56:12 +02002738 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002739
Johannes Berg5727ef12007-12-19 02:03:34 +01002740 if (params.vlan)
2741 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01002742
Johannes Berg5727ef12007-12-19 02:03:34 +01002743 return err;
2744}
2745
Eliad Pellerc75786c2011-08-23 14:37:46 +03002746static struct nla_policy
2747nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2748 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2749 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2750};
2751
Johannes Berg5727ef12007-12-19 02:03:34 +01002752static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2753{
Johannes Berg4c476992010-10-04 21:36:35 +02002754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002755 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002756 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002757 struct station_parameters params;
2758 u8 *mac_addr = NULL;
2759
2760 memset(&params, 0, sizeof(params));
2761
2762 if (!info->attrs[NL80211_ATTR_MAC])
2763 return -EINVAL;
2764
Johannes Berg5727ef12007-12-19 02:03:34 +01002765 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2766 return -EINVAL;
2767
2768 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2769 return -EINVAL;
2770
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002771 if (!info->attrs[NL80211_ATTR_STA_AID])
2772 return -EINVAL;
2773
Johannes Berg5727ef12007-12-19 02:03:34 +01002774 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2775 params.supported_rates =
2776 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2777 params.supported_rates_len =
2778 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2779 params.listen_interval =
2780 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02002781
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02002782 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2783 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2784 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02002785
Jouni Malinen36aedc92008-08-25 11:58:58 +03002786 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2787 params.ht_capa =
2788 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01002789
Javier Cardona96b78df2011-04-07 15:08:33 -07002790 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2791 params.plink_action =
2792 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2793
Johannes Bergbdd90d52011-12-14 12:20:27 +01002794 if (!rdev->ops->add_station)
2795 return -EOPNOTSUPP;
2796
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002797 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002798 return -EINVAL;
2799
Johannes Bergbdd90d52011-12-14 12:20:27 +01002800 switch (dev->ieee80211_ptr->iftype) {
2801 case NL80211_IFTYPE_AP:
2802 case NL80211_IFTYPE_AP_VLAN:
2803 case NL80211_IFTYPE_P2P_GO:
2804 /* parse WME attributes if sta is WME capable */
2805 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2806 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
2807 info->attrs[NL80211_ATTR_STA_WME]) {
2808 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2809 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002810
Johannes Bergbdd90d52011-12-14 12:20:27 +01002811 nla = info->attrs[NL80211_ATTR_STA_WME];
2812 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2813 nl80211_sta_wme_policy);
2814 if (err)
2815 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002816
Johannes Bergbdd90d52011-12-14 12:20:27 +01002817 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2818 params.uapsd_queues =
2819 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
2820 if (params.uapsd_queues &
2821 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2822 return -EINVAL;
2823
2824 if (tb[NL80211_STA_WME_MAX_SP])
2825 params.max_sp =
2826 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
2827
2828 if (params.max_sp &
2829 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2830 return -EINVAL;
2831
2832 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
2833 }
2834 /* TDLS peers cannot be added */
2835 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02002836 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002837 /* but don't bother the driver with it */
2838 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03002839
Johannes Bergbdd90d52011-12-14 12:20:27 +01002840 /* must be last in here for error handling */
2841 params.vlan = get_vlan(info, rdev);
2842 if (IS_ERR(params.vlan))
2843 return PTR_ERR(params.vlan);
2844 break;
2845 case NL80211_IFTYPE_MESH_POINT:
2846 /* TDLS peers cannot be added */
2847 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02002848 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002849 break;
2850 case NL80211_IFTYPE_STATION:
2851 /* Only TDLS peers can be added */
2852 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2853 return -EINVAL;
2854 /* Can only add if TDLS ... */
2855 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
2856 return -EOPNOTSUPP;
2857 /* ... with external setup is supported */
2858 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
2859 return -EOPNOTSUPP;
2860 break;
2861 default:
2862 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03002863 }
2864
Johannes Bergbdd90d52011-12-14 12:20:27 +01002865 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01002866
Johannes Berg79c97e92009-07-07 03:56:12 +02002867 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01002868
Johannes Berg5727ef12007-12-19 02:03:34 +01002869 if (params.vlan)
2870 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01002871 return err;
2872}
2873
2874static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2875{
Johannes Berg4c476992010-10-04 21:36:35 +02002876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2877 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002878 u8 *mac_addr = NULL;
2879
2880 if (info->attrs[NL80211_ATTR_MAC])
2881 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2882
Johannes Berge80cf852009-05-11 14:43:13 +02002883 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02002884 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02002885 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02002886 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2887 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02002888
Johannes Berg4c476992010-10-04 21:36:35 +02002889 if (!rdev->ops->del_station)
2890 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01002891
Johannes Berg4c476992010-10-04 21:36:35 +02002892 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01002893}
2894
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002895static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2896 int flags, struct net_device *dev,
2897 u8 *dst, u8 *next_hop,
2898 struct mpath_info *pinfo)
2899{
2900 void *hdr;
2901 struct nlattr *pinfoattr;
2902
2903 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2904 if (!hdr)
2905 return -1;
2906
2907 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2908 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2909 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2910
Johannes Bergf5ea9122009-08-07 16:17:38 +02002911 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2912
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002913 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2914 if (!pinfoattr)
2915 goto nla_put_failure;
2916 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2917 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2918 pinfo->frame_qlen);
Rui Paulod19b3bf2009-11-09 23:46:55 +00002919 if (pinfo->filled & MPATH_INFO_SN)
2920 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2921 pinfo->sn);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002922 if (pinfo->filled & MPATH_INFO_METRIC)
2923 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2924 pinfo->metric);
2925 if (pinfo->filled & MPATH_INFO_EXPTIME)
2926 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2927 pinfo->exptime);
2928 if (pinfo->filled & MPATH_INFO_FLAGS)
2929 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2930 pinfo->flags);
2931 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2932 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2933 pinfo->discovery_timeout);
2934 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2935 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2936 pinfo->discovery_retries);
2937
2938 nla_nest_end(msg, pinfoattr);
2939
2940 return genlmsg_end(msg, hdr);
2941
2942 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002943 genlmsg_cancel(msg, hdr);
2944 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002945}
2946
2947static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002948 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002949{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002950 struct mpath_info pinfo;
2951 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002952 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002953 u8 dst[ETH_ALEN];
2954 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002955 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002956 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002957
Johannes Berg67748892010-10-04 21:14:06 +02002958 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2959 if (err)
2960 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002961
2962 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002963 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002964 goto out_err;
2965 }
2966
Jouni Malineneec60b02009-03-20 21:21:19 +02002967 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2968 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02002969 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02002970 }
2971
Johannes Bergbba95fe2008-07-29 13:22:51 +02002972 while (1) {
2973 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2974 dst, next_hop, &pinfo);
2975 if (err == -ENOENT)
2976 break;
2977 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002978 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002979
2980 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2981 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2982 netdev, dst, next_hop,
2983 &pinfo) < 0)
2984 goto out;
2985
2986 path_idx++;
2987 }
2988
2989
2990 out:
2991 cb->args[1] = path_idx;
2992 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002993 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002994 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002995 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002996}
2997
2998static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2999{
Johannes Berg4c476992010-10-04 21:36:35 +02003000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003001 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003002 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003003 struct mpath_info pinfo;
3004 struct sk_buff *msg;
3005 u8 *dst = NULL;
3006 u8 next_hop[ETH_ALEN];
3007
3008 memset(&pinfo, 0, sizeof(pinfo));
3009
3010 if (!info->attrs[NL80211_ATTR_MAC])
3011 return -EINVAL;
3012
3013 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3014
Johannes Berg4c476992010-10-04 21:36:35 +02003015 if (!rdev->ops->get_mpath)
3016 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003017
Johannes Berg4c476992010-10-04 21:36:35 +02003018 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3019 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003020
Johannes Berg79c97e92009-07-07 03:56:12 +02003021 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003022 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003023 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003026 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003027 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003028
3029 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003030 dev, dst, next_hop, &pinfo) < 0) {
3031 nlmsg_free(msg);
3032 return -ENOBUFS;
3033 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003034
Johannes Berg4c476992010-10-04 21:36:35 +02003035 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003036}
3037
3038static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3039{
Johannes Berg4c476992010-10-04 21:36:35 +02003040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3041 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003042 u8 *dst = NULL;
3043 u8 *next_hop = NULL;
3044
3045 if (!info->attrs[NL80211_ATTR_MAC])
3046 return -EINVAL;
3047
3048 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3049 return -EINVAL;
3050
3051 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3052 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3053
Johannes Berg4c476992010-10-04 21:36:35 +02003054 if (!rdev->ops->change_mpath)
3055 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003056
Johannes Berg4c476992010-10-04 21:36:35 +02003057 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3058 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003059
Johannes Berg4c476992010-10-04 21:36:35 +02003060 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003061}
Johannes Berg4c476992010-10-04 21:36:35 +02003062
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003063static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3064{
Johannes Berg4c476992010-10-04 21:36:35 +02003065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3066 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003067 u8 *dst = NULL;
3068 u8 *next_hop = NULL;
3069
3070 if (!info->attrs[NL80211_ATTR_MAC])
3071 return -EINVAL;
3072
3073 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3074 return -EINVAL;
3075
3076 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3077 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3078
Johannes Berg4c476992010-10-04 21:36:35 +02003079 if (!rdev->ops->add_mpath)
3080 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003081
Johannes Berg4c476992010-10-04 21:36:35 +02003082 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3083 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003084
Johannes Berg4c476992010-10-04 21:36:35 +02003085 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003086}
3087
3088static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3089{
Johannes Berg4c476992010-10-04 21:36:35 +02003090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3091 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003092 u8 *dst = NULL;
3093
3094 if (info->attrs[NL80211_ATTR_MAC])
3095 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3096
Johannes Berg4c476992010-10-04 21:36:35 +02003097 if (!rdev->ops->del_mpath)
3098 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003099
Johannes Berg4c476992010-10-04 21:36:35 +02003100 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003101}
3102
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003103static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3104{
Johannes Berg4c476992010-10-04 21:36:35 +02003105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3106 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003107 struct bss_parameters params;
3108
3109 memset(&params, 0, sizeof(params));
3110 /* default to not changing parameters */
3111 params.use_cts_prot = -1;
3112 params.use_short_preamble = -1;
3113 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003114 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003115 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003116
3117 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3118 params.use_cts_prot =
3119 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3120 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3121 params.use_short_preamble =
3122 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3123 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3124 params.use_short_slot_time =
3125 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003126 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3127 params.basic_rates =
3128 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3129 params.basic_rates_len =
3130 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3131 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003132 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3133 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003134 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3135 params.ht_opmode =
3136 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003137
Johannes Berg4c476992010-10-04 21:36:35 +02003138 if (!rdev->ops->change_bss)
3139 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003140
Johannes Berg074ac8d2010-09-16 14:58:22 +02003141 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003142 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3143 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003144
Johannes Berg4c476992010-10-04 21:36:35 +02003145 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003146}
3147
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003148static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003149 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3150 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3151 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3152 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3153 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3154 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3155};
3156
3157static int parse_reg_rule(struct nlattr *tb[],
3158 struct ieee80211_reg_rule *reg_rule)
3159{
3160 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3161 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3162
3163 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3164 return -EINVAL;
3165 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3166 return -EINVAL;
3167 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3168 return -EINVAL;
3169 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3170 return -EINVAL;
3171 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3172 return -EINVAL;
3173
3174 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3175
3176 freq_range->start_freq_khz =
3177 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3178 freq_range->end_freq_khz =
3179 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3180 freq_range->max_bandwidth_khz =
3181 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3182
3183 power_rule->max_eirp =
3184 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3185
3186 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3187 power_rule->max_antenna_gain =
3188 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3189
3190 return 0;
3191}
3192
3193static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3194{
3195 int r;
3196 char *data = NULL;
3197
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003198 /*
3199 * You should only get this when cfg80211 hasn't yet initialized
3200 * completely when built-in to the kernel right between the time
3201 * window between nl80211_init() and regulatory_init(), if that is
3202 * even possible.
3203 */
3204 mutex_lock(&cfg80211_mutex);
3205 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003206 mutex_unlock(&cfg80211_mutex);
3207 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003208 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003209 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003210
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003211 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3212 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003213
3214 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3215
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003216 r = regulatory_hint_user(data);
3217
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003218 return r;
3219}
3220
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003221static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003222 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003223{
Johannes Berg4c476992010-10-04 21:36:35 +02003224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003225 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003226 struct wireless_dev *wdev = dev->ieee80211_ptr;
3227 struct mesh_config cur_params;
3228 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003229 void *hdr;
3230 struct nlattr *pinfoattr;
3231 struct sk_buff *msg;
3232
Johannes Berg29cbe682010-12-03 09:20:44 +01003233 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3234 return -EOPNOTSUPP;
3235
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003236 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003237 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003238
Johannes Berg29cbe682010-12-03 09:20:44 +01003239 wdev_lock(wdev);
3240 /* If not connected, get default parameters */
3241 if (!wdev->mesh_id_len)
3242 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3243 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003244 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003245 &cur_params);
3246 wdev_unlock(wdev);
3247
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003248 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003249 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003250
3251 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003253 if (!msg)
3254 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003255 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003256 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003257 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003258 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003259 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003260 if (!pinfoattr)
3261 goto nla_put_failure;
3262 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3263 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3264 cur_params.dot11MeshRetryTimeout);
3265 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3266 cur_params.dot11MeshConfirmTimeout);
3267 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3268 cur_params.dot11MeshHoldingTimeout);
3269 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3270 cur_params.dot11MeshMaxPeerLinks);
3271 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3272 cur_params.dot11MeshMaxRetries);
3273 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3274 cur_params.dot11MeshTTL);
Javier Cardona45904f22010-12-03 09:20:40 +01003275 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3276 cur_params.element_ttl);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003277 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3278 cur_params.auto_open_plinks);
3279 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3280 cur_params.dot11MeshHWMPmaxPREQretries);
3281 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3282 cur_params.path_refresh_time);
3283 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3284 cur_params.min_discovery_timeout);
3285 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3286 cur_params.dot11MeshHWMPactivePathTimeout);
3287 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3288 cur_params.dot11MeshHWMPpreqMinInterval);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003289 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3290 cur_params.dot11MeshHWMPperrMinInterval);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003291 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3292 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
Rui Paulo63c57232009-11-09 23:46:57 +00003293 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3294 cur_params.dot11MeshHWMPRootMode);
Javier Cardona0507e152011-08-09 16:45:10 -07003295 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3296 cur_params.dot11MeshHWMPRannInterval);
Javier Cardona16dd7262011-08-09 16:45:11 -07003297 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3298 cur_params.dot11MeshGateAnnouncementProtocol);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003299 NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING,
3300 cur_params.dot11MeshForwarding);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003301 NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
3302 cur_params.rssi_threshold);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003303 nla_nest_end(msg, pinfoattr);
3304 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003305 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003306
Johannes Berg3b858752009-03-12 09:55:09 +01003307 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003308 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003309 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003310 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003311 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003312}
3313
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003314static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003315 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3316 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3317 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3318 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3319 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3320 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003321 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003322 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
3323
3324 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3325 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3326 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3327 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3328 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003329 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003330 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003331 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003332 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003333 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003334 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Ashok Nagarajan55335132012-02-28 17:04:08 -08003335 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32},
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003336};
3337
Javier Cardonac80d5452010-12-16 17:37:49 -08003338static const struct nla_policy
3339 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
3340 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3341 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003342 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003343 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Javier Cardonac80d5452010-12-16 17:37:49 -08003344 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003345 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003346};
3347
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003348static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003349 struct mesh_config *cfg,
3350 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003351{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003352 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003353 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003354
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003355#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3356do {\
3357 if (table[attr_num]) {\
3358 cfg->param = nla_fn(table[attr_num]); \
3359 mask |= (1 << (attr_num - 1)); \
3360 } \
3361} while (0);\
3362
3363
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003364 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003365 return -EINVAL;
3366 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003367 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003368 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003369 return -EINVAL;
3370
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003371 /* This makes sure that there aren't more than 32 mesh config
3372 * parameters (otherwise our bitfield scheme would not work.) */
3373 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3374
3375 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003376 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3377 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3379 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3380 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3381 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3382 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3383 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3384 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3385 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3386 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3387 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003388 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3389 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003390 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3391 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3392 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3393 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3394 nla_get_u8);
3395 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3396 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3397 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3398 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3399 nla_get_u16);
3400 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3401 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3402 nla_get_u32);
3403 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3404 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3405 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003406 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
3407 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3408 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3410 dot11MeshHWMPnetDiameterTraversalTime,
3411 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3412 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3414 dot11MeshHWMPRootMode, mask,
3415 NL80211_MESHCONF_HWMP_ROOTMODE,
3416 nla_get_u8);
Javier Cardona0507e152011-08-09 16:45:10 -07003417 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3418 dot11MeshHWMPRannInterval, mask,
3419 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3420 nla_get_u16);
Javier Cardona16dd7262011-08-09 16:45:11 -07003421 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3422 dot11MeshGateAnnouncementProtocol, mask,
3423 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3424 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003425 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
3426 mask, NL80211_MESHCONF_FORWARDING, nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003427 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
3428 mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003429 if (mask_out)
3430 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003431
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003432 return 0;
3433
3434#undef FILL_IN_MESH_PARAM_IF_SET
3435}
3436
Javier Cardonac80d5452010-12-16 17:37:49 -08003437static int nl80211_parse_mesh_setup(struct genl_info *info,
3438 struct mesh_setup *setup)
3439{
3440 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3441
3442 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3443 return -EINVAL;
3444 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3445 info->attrs[NL80211_ATTR_MESH_SETUP],
3446 nl80211_mesh_setup_params_policy))
3447 return -EINVAL;
3448
3449 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3450 setup->path_sel_proto =
3451 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3452 IEEE80211_PATH_PROTOCOL_VENDOR :
3453 IEEE80211_PATH_PROTOCOL_HWMP;
3454
3455 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3456 setup->path_metric =
3457 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3458 IEEE80211_PATH_METRIC_VENDOR :
3459 IEEE80211_PATH_METRIC_AIRTIME;
3460
Javier Cardona581a8b02011-04-07 15:08:27 -07003461
3462 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003463 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003464 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003465 if (!is_valid_ie_attr(ieattr))
3466 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003467 setup->ie = nla_data(ieattr);
3468 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003469 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003470 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3471 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003472
3473 return 0;
3474}
3475
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003476static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003477 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003478{
3479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3480 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003481 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003482 struct mesh_config cfg;
3483 u32 mask;
3484 int err;
3485
Johannes Berg29cbe682010-12-03 09:20:44 +01003486 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3487 return -EOPNOTSUPP;
3488
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003489 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003490 return -EOPNOTSUPP;
3491
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003492 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003493 if (err)
3494 return err;
3495
Johannes Berg29cbe682010-12-03 09:20:44 +01003496 wdev_lock(wdev);
3497 if (!wdev->mesh_id_len)
3498 err = -ENOLINK;
3499
3500 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003501 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003502 mask, &cfg);
3503
3504 wdev_unlock(wdev);
3505
3506 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003507}
3508
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003509static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3510{
3511 struct sk_buff *msg;
3512 void *hdr = NULL;
3513 struct nlattr *nl_reg_rules;
3514 unsigned int i;
3515 int err = -EINVAL;
3516
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003517 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003518
3519 if (!cfg80211_regdomain)
3520 goto out;
3521
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003522 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003523 if (!msg) {
3524 err = -ENOBUFS;
3525 goto out;
3526 }
3527
3528 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3529 NL80211_CMD_GET_REG);
3530 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003531 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003532
3533 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3534 cfg80211_regdomain->alpha2);
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003535 if (cfg80211_regdomain->dfs_region)
3536 NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
3537 cfg80211_regdomain->dfs_region);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003538
3539 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3540 if (!nl_reg_rules)
3541 goto nla_put_failure;
3542
3543 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3544 struct nlattr *nl_reg_rule;
3545 const struct ieee80211_reg_rule *reg_rule;
3546 const struct ieee80211_freq_range *freq_range;
3547 const struct ieee80211_power_rule *power_rule;
3548
3549 reg_rule = &cfg80211_regdomain->reg_rules[i];
3550 freq_range = &reg_rule->freq_range;
3551 power_rule = &reg_rule->power_rule;
3552
3553 nl_reg_rule = nla_nest_start(msg, i);
3554 if (!nl_reg_rule)
3555 goto nla_put_failure;
3556
3557 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3558 reg_rule->flags);
3559 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3560 freq_range->start_freq_khz);
3561 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3562 freq_range->end_freq_khz);
3563 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3564 freq_range->max_bandwidth_khz);
3565 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3566 power_rule->max_antenna_gain);
3567 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3568 power_rule->max_eirp);
3569
3570 nla_nest_end(msg, nl_reg_rule);
3571 }
3572
3573 nla_nest_end(msg, nl_reg_rules);
3574
3575 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003576 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003577 goto out;
3578
3579nla_put_failure:
3580 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003581put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003582 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003583 err = -EMSGSIZE;
3584out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003585 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003586 return err;
3587}
3588
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003589static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3590{
3591 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3592 struct nlattr *nl_reg_rule;
3593 char *alpha2 = NULL;
3594 int rem_reg_rules = 0, r = 0;
3595 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003596 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003597 struct ieee80211_regdomain *rd = NULL;
3598
3599 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3600 return -EINVAL;
3601
3602 if (!info->attrs[NL80211_ATTR_REG_RULES])
3603 return -EINVAL;
3604
3605 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3606
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003607 if (info->attrs[NL80211_ATTR_DFS_REGION])
3608 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3609
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003610 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3611 rem_reg_rules) {
3612 num_rules++;
3613 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003614 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003615 }
3616
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003617 mutex_lock(&cfg80211_mutex);
3618
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003619 if (!reg_is_valid_request(alpha2)) {
3620 r = -EINVAL;
3621 goto bad_reg;
3622 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003623
3624 size_of_regd = sizeof(struct ieee80211_regdomain) +
3625 (num_rules * sizeof(struct ieee80211_reg_rule));
3626
3627 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003628 if (!rd) {
3629 r = -ENOMEM;
3630 goto bad_reg;
3631 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003632
3633 rd->n_reg_rules = num_rules;
3634 rd->alpha2[0] = alpha2[0];
3635 rd->alpha2[1] = alpha2[1];
3636
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003637 /*
3638 * Disable DFS master mode if the DFS region was
3639 * not supported or known on this kernel.
3640 */
3641 if (reg_supported_dfs_region(dfs_region))
3642 rd->dfs_region = dfs_region;
3643
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003644 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3645 rem_reg_rules) {
3646 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3647 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3648 reg_rule_policy);
3649 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3650 if (r)
3651 goto bad_reg;
3652
3653 rule_idx++;
3654
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003655 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3656 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003657 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003658 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003659 }
3660
3661 BUG_ON(rule_idx != num_rules);
3662
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003663 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003664
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003665 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003666
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003667 return r;
3668
Johannes Bergd2372b32008-10-24 20:32:20 +02003669 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003670 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003671 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003672 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003673}
3674
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003675static int validate_scan_freqs(struct nlattr *freqs)
3676{
3677 struct nlattr *attr1, *attr2;
3678 int n_channels = 0, tmp1, tmp2;
3679
3680 nla_for_each_nested(attr1, freqs, tmp1) {
3681 n_channels++;
3682 /*
3683 * Some hardware has a limited channel list for
3684 * scanning, and it is pretty much nonsensical
3685 * to scan for a channel twice, so disallow that
3686 * and don't require drivers to check that the
3687 * channel list they get isn't longer than what
3688 * they can scan, as long as they can scan all
3689 * the channels they registered at once.
3690 */
3691 nla_for_each_nested(attr2, freqs, tmp2)
3692 if (attr1 != attr2 &&
3693 nla_get_u32(attr1) == nla_get_u32(attr2))
3694 return 0;
3695 }
3696
3697 return n_channels;
3698}
3699
Johannes Berg2a519312009-02-10 21:25:55 +01003700static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3701{
Johannes Berg4c476992010-10-04 21:36:35 +02003702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3703 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01003704 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01003705 struct nlattr *attr;
3706 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003707 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003708 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01003709
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003710 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3711 return -EINVAL;
3712
Johannes Berg79c97e92009-07-07 03:56:12 +02003713 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003714
Johannes Berg4c476992010-10-04 21:36:35 +02003715 if (!rdev->ops->scan)
3716 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01003717
Johannes Berg4c476992010-10-04 21:36:35 +02003718 if (rdev->scan_req)
3719 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01003720
3721 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003722 n_channels = validate_scan_freqs(
3723 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02003724 if (!n_channels)
3725 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003726 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003727 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02003728 n_channels = 0;
3729
Johannes Berg2a519312009-02-10 21:25:55 +01003730 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], tmp)
3737 n_ssids++;
3738
Johannes Berg4c476992010-10-04 21:36:35 +02003739 if (n_ssids > wiphy->max_scan_ssids)
3740 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01003741
Jouni Malinen70692ad2009-02-16 19:39:13 +02003742 if (info->attrs[NL80211_ATTR_IE])
3743 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3744 else
3745 ie_len = 0;
3746
Johannes Berg4c476992010-10-04 21:36:35 +02003747 if (ie_len > wiphy->max_scan_ie_len)
3748 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02003749
Johannes Berg2a519312009-02-10 21:25:55 +01003750 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003751 + sizeof(*request->ssids) * n_ssids
3752 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02003753 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003754 if (!request)
3755 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01003756
Johannes Berg2a519312009-02-10 21:25:55 +01003757 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02003758 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01003759 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02003760 if (ie_len) {
3761 if (request->ssids)
3762 request->ie = (void *)(request->ssids + n_ssids);
3763 else
3764 request->ie = (void *)(request->channels + n_channels);
3765 }
Johannes Berg2a519312009-02-10 21:25:55 +01003766
Johannes Berg584991d2009-11-02 13:32:03 +01003767 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01003768 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3769 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01003770 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01003771 struct ieee80211_channel *chan;
3772
3773 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3774
3775 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01003776 err = -EINVAL;
3777 goto out_free;
3778 }
Johannes Berg584991d2009-11-02 13:32:03 +01003779
3780 /* ignore disabled channels */
3781 if (chan->flags & IEEE80211_CHAN_DISABLED)
3782 continue;
3783
3784 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003785 i++;
3786 }
3787 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02003788 enum ieee80211_band band;
3789
Johannes Berg2a519312009-02-10 21:25:55 +01003790 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01003791 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3792 int j;
3793 if (!wiphy->bands[band])
3794 continue;
3795 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01003796 struct ieee80211_channel *chan;
3797
3798 chan = &wiphy->bands[band]->channels[j];
3799
3800 if (chan->flags & IEEE80211_CHAN_DISABLED)
3801 continue;
3802
3803 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01003804 i++;
3805 }
3806 }
3807 }
3808
Johannes Berg584991d2009-11-02 13:32:03 +01003809 if (!i) {
3810 err = -EINVAL;
3811 goto out_free;
3812 }
3813
3814 request->n_channels = i;
3815
Johannes Berg2a519312009-02-10 21:25:55 +01003816 i = 0;
3817 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3818 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03003819 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01003820 err = -EINVAL;
3821 goto out_free;
3822 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03003823 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01003824 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01003825 i++;
3826 }
3827 }
3828
Jouni Malinen70692ad2009-02-16 19:39:13 +02003829 if (info->attrs[NL80211_ATTR_IE]) {
3830 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02003831 memcpy((void *)request->ie,
3832 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02003833 request->ie_len);
3834 }
3835
Johannes Berg34850ab2011-07-18 18:08:35 +02003836 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02003837 if (wiphy->bands[i])
3838 request->rates[i] =
3839 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02003840
3841 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3842 nla_for_each_nested(attr,
3843 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3844 tmp) {
3845 enum ieee80211_band band = nla_type(attr);
3846
Dan Carpenter84404622011-07-29 11:52:18 +03003847 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02003848 err = -EINVAL;
3849 goto out_free;
3850 }
3851 err = ieee80211_get_ratemask(wiphy->bands[band],
3852 nla_data(attr),
3853 nla_len(attr),
3854 &request->rates[band]);
3855 if (err)
3856 goto out_free;
3857 }
3858 }
3859
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05303860 request->no_cck =
3861 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3862
Johannes Berg463d0182009-07-14 00:33:35 +02003863 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02003864 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01003865
Johannes Berg79c97e92009-07-07 03:56:12 +02003866 rdev->scan_req = request;
3867 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01003868
Johannes Berg463d0182009-07-14 00:33:35 +02003869 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02003870 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02003871 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02003872 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01003873 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02003874 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01003875 kfree(request);
3876 }
Johannes Berg3b858752009-03-12 09:55:09 +01003877
Johannes Berg2a519312009-02-10 21:25:55 +01003878 return err;
3879}
3880
Luciano Coelho807f8a82011-05-11 17:09:35 +03003881static int nl80211_start_sched_scan(struct sk_buff *skb,
3882 struct genl_info *info)
3883{
3884 struct cfg80211_sched_scan_request *request;
3885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3886 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003887 struct nlattr *attr;
3888 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003889 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003890 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03003891 enum ieee80211_band band;
3892 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003893 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03003894
3895 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3896 !rdev->ops->sched_scan_start)
3897 return -EOPNOTSUPP;
3898
3899 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3900 return -EINVAL;
3901
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03003902 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3903 return -EINVAL;
3904
3905 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3906 if (interval == 0)
3907 return -EINVAL;
3908
Luciano Coelho807f8a82011-05-11 17:09:35 +03003909 wiphy = &rdev->wiphy;
3910
3911 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3912 n_channels = validate_scan_freqs(
3913 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3914 if (!n_channels)
3915 return -EINVAL;
3916 } else {
3917 n_channels = 0;
3918
3919 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3920 if (wiphy->bands[band])
3921 n_channels += wiphy->bands[band]->n_channels;
3922 }
3923
3924 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3925 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3926 tmp)
3927 n_ssids++;
3928
Luciano Coelho93b6aa62011-07-13 14:57:28 +03003929 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003930 return -EINVAL;
3931
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003932 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3933 nla_for_each_nested(attr,
3934 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3935 tmp)
3936 n_match_sets++;
3937
3938 if (n_match_sets > wiphy->max_match_sets)
3939 return -EINVAL;
3940
Luciano Coelho807f8a82011-05-11 17:09:35 +03003941 if (info->attrs[NL80211_ATTR_IE])
3942 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3943 else
3944 ie_len = 0;
3945
Luciano Coelho5a865ba2011-07-13 14:57:29 +03003946 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03003947 return -EINVAL;
3948
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003949 mutex_lock(&rdev->sched_scan_mtx);
3950
3951 if (rdev->sched_scan_req) {
3952 err = -EINPROGRESS;
3953 goto out;
3954 }
3955
Luciano Coelho807f8a82011-05-11 17:09:35 +03003956 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003957 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003958 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03003959 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03003960 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03003961 if (!request) {
3962 err = -ENOMEM;
3963 goto out;
3964 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03003965
3966 if (n_ssids)
3967 request->ssids = (void *)&request->channels[n_channels];
3968 request->n_ssids = n_ssids;
3969 if (ie_len) {
3970 if (request->ssids)
3971 request->ie = (void *)(request->ssids + n_ssids);
3972 else
3973 request->ie = (void *)(request->channels + n_channels);
3974 }
3975
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03003976 if (n_match_sets) {
3977 if (request->ie)
3978 request->match_sets = (void *)(request->ie + ie_len);
3979 else if (request->ssids)
3980 request->match_sets =
3981 (void *)(request->ssids + n_ssids);
3982 else
3983 request->match_sets =
3984 (void *)(request->channels + n_channels);
3985 }
3986 request->n_match_sets = n_match_sets;
3987
Luciano Coelho807f8a82011-05-11 17:09:35 +03003988 i = 0;
3989 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3990 /* user specified, bail out if channel not found */
3991 nla_for_each_nested(attr,
3992 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3993 tmp) {
3994 struct ieee80211_channel *chan;
3995
3996 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3997
3998 if (!chan) {
3999 err = -EINVAL;
4000 goto out_free;
4001 }
4002
4003 /* ignore disabled channels */
4004 if (chan->flags & IEEE80211_CHAN_DISABLED)
4005 continue;
4006
4007 request->channels[i] = chan;
4008 i++;
4009 }
4010 } else {
4011 /* all channels */
4012 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4013 int j;
4014 if (!wiphy->bands[band])
4015 continue;
4016 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4017 struct ieee80211_channel *chan;
4018
4019 chan = &wiphy->bands[band]->channels[j];
4020
4021 if (chan->flags & IEEE80211_CHAN_DISABLED)
4022 continue;
4023
4024 request->channels[i] = chan;
4025 i++;
4026 }
4027 }
4028 }
4029
4030 if (!i) {
4031 err = -EINVAL;
4032 goto out_free;
4033 }
4034
4035 request->n_channels = i;
4036
4037 i = 0;
4038 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4039 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4040 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004041 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004042 err = -EINVAL;
4043 goto out_free;
4044 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004045 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004046 memcpy(request->ssids[i].ssid, nla_data(attr),
4047 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004048 i++;
4049 }
4050 }
4051
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004052 i = 0;
4053 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4054 nla_for_each_nested(attr,
4055 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4056 tmp) {
4057 struct nlattr *ssid;
4058
4059 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4060 nla_data(attr), nla_len(attr),
4061 nl80211_match_policy);
4062 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
4063 if (ssid) {
4064 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4065 err = -EINVAL;
4066 goto out_free;
4067 }
4068 memcpy(request->match_sets[i].ssid.ssid,
4069 nla_data(ssid), nla_len(ssid));
4070 request->match_sets[i].ssid.ssid_len =
4071 nla_len(ssid);
4072 }
4073 i++;
4074 }
4075 }
4076
Luciano Coelho807f8a82011-05-11 17:09:35 +03004077 if (info->attrs[NL80211_ATTR_IE]) {
4078 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4079 memcpy((void *)request->ie,
4080 nla_data(info->attrs[NL80211_ATTR_IE]),
4081 request->ie_len);
4082 }
4083
4084 request->dev = dev;
4085 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004086 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004087
4088 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4089 if (!err) {
4090 rdev->sched_scan_req = request;
4091 nl80211_send_sched_scan(rdev, dev,
4092 NL80211_CMD_START_SCHED_SCAN);
4093 goto out;
4094 }
4095
4096out_free:
4097 kfree(request);
4098out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004099 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004100 return err;
4101}
4102
4103static int nl80211_stop_sched_scan(struct sk_buff *skb,
4104 struct genl_info *info)
4105{
4106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004107 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004108
4109 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4110 !rdev->ops->sched_scan_stop)
4111 return -EOPNOTSUPP;
4112
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004113 mutex_lock(&rdev->sched_scan_mtx);
4114 err = __cfg80211_stop_sched_scan(rdev, false);
4115 mutex_unlock(&rdev->sched_scan_mtx);
4116
4117 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004118}
4119
Johannes Berg9720bb32011-06-21 09:45:33 +02004120static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4121 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004122 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004123 struct wireless_dev *wdev,
4124 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004125{
Johannes Berg48ab9052009-07-10 18:42:31 +02004126 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004127 void *hdr;
4128 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004129
4130 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004131
Johannes Berg9720bb32011-06-21 09:45:33 +02004132 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004133 NL80211_CMD_NEW_SCAN_RESULTS);
4134 if (!hdr)
4135 return -1;
4136
Johannes Berg9720bb32011-06-21 09:45:33 +02004137 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4138
Johannes Bergf5ea9122009-08-07 16:17:38 +02004139 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
Johannes Berg48ab9052009-07-10 18:42:31 +02004140 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01004141
4142 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4143 if (!bss)
4144 goto nla_put_failure;
4145 if (!is_zero_ether_addr(res->bssid))
4146 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
4147 if (res->information_elements && res->len_information_elements)
4148 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4149 res->len_information_elements,
4150 res->information_elements);
Jouni Malinen34a6edd2010-01-06 16:19:24 +02004151 if (res->beacon_ies && res->len_beacon_ies &&
4152 res->beacon_ies != res->information_elements)
4153 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
4154 res->len_beacon_ies, res->beacon_ies);
Johannes Berg2a519312009-02-10 21:25:55 +01004155 if (res->tsf)
4156 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
4157 if (res->beacon_interval)
4158 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
4159 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
4160 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
Holger Schurig7c896062009-09-24 12:21:01 +02004161 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
4162 jiffies_to_msecs(jiffies - intbss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01004163
Johannes Berg77965c92009-02-18 18:45:06 +01004164 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004165 case CFG80211_SIGNAL_TYPE_MBM:
4166 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
4167 break;
4168 case CFG80211_SIGNAL_TYPE_UNSPEC:
4169 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
4170 break;
4171 default:
4172 break;
4173 }
4174
Johannes Berg48ab9052009-07-10 18:42:31 +02004175 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004176 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004177 case NL80211_IFTYPE_STATION:
4178 if (intbss == wdev->current_bss)
4179 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4180 NL80211_BSS_STATUS_ASSOCIATED);
Johannes Berg48ab9052009-07-10 18:42:31 +02004181 break;
4182 case NL80211_IFTYPE_ADHOC:
4183 if (intbss == wdev->current_bss)
4184 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4185 NL80211_BSS_STATUS_IBSS_JOINED);
4186 break;
4187 default:
4188 break;
4189 }
4190
Johannes Berg2a519312009-02-10 21:25:55 +01004191 nla_nest_end(msg, bss);
4192
4193 return genlmsg_end(msg, hdr);
4194
4195 nla_put_failure:
4196 genlmsg_cancel(msg, hdr);
4197 return -EMSGSIZE;
4198}
4199
4200static int nl80211_dump_scan(struct sk_buff *skb,
4201 struct netlink_callback *cb)
4202{
Johannes Berg48ab9052009-07-10 18:42:31 +02004203 struct cfg80211_registered_device *rdev;
4204 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004205 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004206 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004207 int start = cb->args[1], idx = 0;
4208 int err;
4209
Johannes Berg67748892010-10-04 21:14:06 +02004210 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4211 if (err)
4212 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004213
Johannes Berg48ab9052009-07-10 18:42:31 +02004214 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004215
Johannes Berg48ab9052009-07-10 18:42:31 +02004216 wdev_lock(wdev);
4217 spin_lock_bh(&rdev->bss_lock);
4218 cfg80211_bss_expire(rdev);
4219
Johannes Berg9720bb32011-06-21 09:45:33 +02004220 cb->seq = rdev->bss_generation;
4221
Johannes Berg48ab9052009-07-10 18:42:31 +02004222 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004223 if (++idx <= start)
4224 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004225 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004226 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004227 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004228 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004229 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004230 }
4231 }
4232
Johannes Berg48ab9052009-07-10 18:42:31 +02004233 spin_unlock_bh(&rdev->bss_lock);
4234 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004235
4236 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004237 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004238
Johannes Berg67748892010-10-04 21:14:06 +02004239 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004240}
4241
Holger Schurig61fa7132009-11-11 12:25:40 +01004242static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4243 int flags, struct net_device *dev,
4244 struct survey_info *survey)
4245{
4246 void *hdr;
4247 struct nlattr *infoattr;
4248
Holger Schurig61fa7132009-11-11 12:25:40 +01004249 hdr = nl80211hdr_put(msg, pid, seq, flags,
4250 NL80211_CMD_NEW_SURVEY_RESULTS);
4251 if (!hdr)
4252 return -ENOMEM;
4253
4254 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4255
4256 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4257 if (!infoattr)
4258 goto nla_put_failure;
4259
4260 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4261 survey->channel->center_freq);
4262 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4263 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4264 survey->noise);
Felix Fietkau17e5a802010-09-29 17:15:30 +02004265 if (survey->filled & SURVEY_INFO_IN_USE)
4266 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
Felix Fietkau8610c292010-10-09 02:39:29 +02004267 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4268 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4269 survey->channel_time);
4270 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4271 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4272 survey->channel_time_busy);
4273 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4274 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4275 survey->channel_time_ext_busy);
4276 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4277 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4278 survey->channel_time_rx);
4279 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4280 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4281 survey->channel_time_tx);
Holger Schurig61fa7132009-11-11 12:25:40 +01004282
4283 nla_nest_end(msg, infoattr);
4284
4285 return genlmsg_end(msg, hdr);
4286
4287 nla_put_failure:
4288 genlmsg_cancel(msg, hdr);
4289 return -EMSGSIZE;
4290}
4291
4292static int nl80211_dump_survey(struct sk_buff *skb,
4293 struct netlink_callback *cb)
4294{
4295 struct survey_info survey;
4296 struct cfg80211_registered_device *dev;
4297 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004298 int survey_idx = cb->args[1];
4299 int res;
4300
Johannes Berg67748892010-10-04 21:14:06 +02004301 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4302 if (res)
4303 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004304
4305 if (!dev->ops->dump_survey) {
4306 res = -EOPNOTSUPP;
4307 goto out_err;
4308 }
4309
4310 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004311 struct ieee80211_channel *chan;
4312
Holger Schurig61fa7132009-11-11 12:25:40 +01004313 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4314 &survey);
4315 if (res == -ENOENT)
4316 break;
4317 if (res)
4318 goto out_err;
4319
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004320 /* Survey without a channel doesn't make sense */
4321 if (!survey.channel) {
4322 res = -EINVAL;
4323 goto out;
4324 }
4325
4326 chan = ieee80211_get_channel(&dev->wiphy,
4327 survey.channel->center_freq);
4328 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4329 survey_idx++;
4330 continue;
4331 }
4332
Holger Schurig61fa7132009-11-11 12:25:40 +01004333 if (nl80211_send_survey(skb,
4334 NETLINK_CB(cb->skb).pid,
4335 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4336 netdev,
4337 &survey) < 0)
4338 goto out;
4339 survey_idx++;
4340 }
4341
4342 out:
4343 cb->args[1] = survey_idx;
4344 res = skb->len;
4345 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004346 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004347 return res;
4348}
4349
Jouni Malinen255e7372009-03-20 21:21:17 +02004350static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4351{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004352 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004353}
4354
Samuel Ortizb23aa672009-07-01 21:26:54 +02004355static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4356{
4357 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4358 NL80211_WPA_VERSION_2));
4359}
4360
Jouni Malinen636a5d32009-03-19 13:39:22 +02004361static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4362{
Johannes Berg4c476992010-10-04 21:36:35 +02004363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4364 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004365 struct ieee80211_channel *chan;
4366 const u8 *bssid, *ssid, *ie = NULL;
4367 int err, ssid_len, ie_len = 0;
4368 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004369 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004370 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004371
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004372 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4373 return -EINVAL;
4374
4375 if (!info->attrs[NL80211_ATTR_MAC])
4376 return -EINVAL;
4377
Jouni Malinen17780922009-03-27 20:52:47 +02004378 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4379 return -EINVAL;
4380
Johannes Berg19957bb2009-07-02 17:20:43 +02004381 if (!info->attrs[NL80211_ATTR_SSID])
4382 return -EINVAL;
4383
4384 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4385 return -EINVAL;
4386
Johannes Bergfffd0932009-07-08 14:22:54 +02004387 err = nl80211_parse_key(info, &key);
4388 if (err)
4389 return err;
4390
4391 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004392 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4393 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004394 if (!key.p.key || !key.p.key_len)
4395 return -EINVAL;
4396 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4397 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4398 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4399 key.p.key_len != WLAN_KEY_LEN_WEP104))
4400 return -EINVAL;
4401 if (key.idx > 4)
4402 return -EINVAL;
4403 } else {
4404 key.p.key_len = 0;
4405 key.p.key = NULL;
4406 }
4407
Johannes Bergafea0b72010-08-10 09:46:42 +02004408 if (key.idx >= 0) {
4409 int i;
4410 bool ok = false;
4411 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4412 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4413 ok = true;
4414 break;
4415 }
4416 }
Johannes Berg4c476992010-10-04 21:36:35 +02004417 if (!ok)
4418 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004419 }
4420
Johannes Berg4c476992010-10-04 21:36:35 +02004421 if (!rdev->ops->auth)
4422 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004423
Johannes Berg074ac8d2010-09-16 14:58:22 +02004424 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004425 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4426 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004427
Johannes Berg19957bb2009-07-02 17:20:43 +02004428 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004429 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004430 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004431 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4432 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004433
Johannes Berg19957bb2009-07-02 17:20:43 +02004434 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4435 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4436
4437 if (info->attrs[NL80211_ATTR_IE]) {
4438 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4439 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4440 }
4441
4442 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004443 if (!nl80211_valid_auth_type(auth_type))
4444 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004445
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004446 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4447
Johannes Berg95de8172012-01-20 13:55:25 +01004448 /*
4449 * Since we no longer track auth state, ignore
4450 * requests to only change local state.
4451 */
4452 if (local_state_change)
4453 return 0;
4454
Johannes Berg4c476992010-10-04 21:36:35 +02004455 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4456 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004457 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004458}
4459
Johannes Bergc0692b82010-08-27 14:26:53 +03004460static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4461 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004462 struct cfg80211_crypto_settings *settings,
4463 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004464{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004465 memset(settings, 0, sizeof(*settings));
4466
Samuel Ortizb23aa672009-07-01 21:26:54 +02004467 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4468
Johannes Bergc0692b82010-08-27 14:26:53 +03004469 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4470 u16 proto;
4471 proto = nla_get_u16(
4472 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4473 settings->control_port_ethertype = cpu_to_be16(proto);
4474 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4475 proto != ETH_P_PAE)
4476 return -EINVAL;
4477 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4478 settings->control_port_no_encrypt = true;
4479 } else
4480 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4481
Samuel Ortizb23aa672009-07-01 21:26:54 +02004482 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4483 void *data;
4484 int len, i;
4485
4486 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4487 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4488 settings->n_ciphers_pairwise = len / sizeof(u32);
4489
4490 if (len % sizeof(u32))
4491 return -EINVAL;
4492
Johannes Berg3dc27d22009-07-02 21:36:37 +02004493 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004494 return -EINVAL;
4495
4496 memcpy(settings->ciphers_pairwise, data, len);
4497
4498 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004499 if (!cfg80211_supported_cipher_suite(
4500 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004501 settings->ciphers_pairwise[i]))
4502 return -EINVAL;
4503 }
4504
4505 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4506 settings->cipher_group =
4507 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004508 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4509 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004510 return -EINVAL;
4511 }
4512
4513 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4514 settings->wpa_versions =
4515 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4516 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4517 return -EINVAL;
4518 }
4519
4520 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4521 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004522 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004523
4524 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4525 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4526 settings->n_akm_suites = len / sizeof(u32);
4527
4528 if (len % sizeof(u32))
4529 return -EINVAL;
4530
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004531 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4532 return -EINVAL;
4533
Samuel Ortizb23aa672009-07-01 21:26:54 +02004534 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004535 }
4536
4537 return 0;
4538}
4539
Jouni Malinen636a5d32009-03-19 13:39:22 +02004540static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4541{
Johannes Berg4c476992010-10-04 21:36:35 +02004542 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4543 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004544 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004545 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004546 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004547 int err, ssid_len, ie_len = 0;
4548 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004549 u32 flags = 0;
4550 struct ieee80211_ht_cap *ht_capa = NULL;
4551 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004552
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004553 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4554 return -EINVAL;
4555
4556 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004557 !info->attrs[NL80211_ATTR_SSID] ||
4558 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004559 return -EINVAL;
4560
Johannes Berg4c476992010-10-04 21:36:35 +02004561 if (!rdev->ops->assoc)
4562 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004563
Johannes Berg074ac8d2010-09-16 14:58:22 +02004564 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004565 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4566 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004567
Johannes Berg19957bb2009-07-02 17:20:43 +02004568 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004569
Johannes Berg19957bb2009-07-02 17:20:43 +02004570 chan = ieee80211_get_channel(&rdev->wiphy,
4571 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004572 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4573 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004574
Johannes Berg19957bb2009-07-02 17:20:43 +02004575 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4576 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004577
4578 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004579 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4580 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004581 }
4582
Jouni Malinendc6382c2009-05-06 22:09:37 +03004583 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004584 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004585 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004586 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004587 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004588 else if (mfp != NL80211_MFP_NO)
4589 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004590 }
4591
Johannes Berg3e5d7642009-07-07 14:37:26 +02004592 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4593 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4594
Ben Greear7e7c8922011-11-18 11:31:59 -08004595 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4596 flags |= ASSOC_REQ_DISABLE_HT;
4597
4598 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4599 ht_capa_mask =
4600 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4601
4602 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4603 if (!ht_capa_mask)
4604 return -EINVAL;
4605 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4606 }
4607
Johannes Bergc0692b82010-08-27 14:26:53 +03004608 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004609 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004610 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4611 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004612 &crypto, flags, ht_capa,
4613 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004614
Jouni Malinen636a5d32009-03-19 13:39:22 +02004615 return err;
4616}
4617
4618static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4619{
Johannes Berg4c476992010-10-04 21:36:35 +02004620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4621 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004622 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004623 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004624 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004625 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004626
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004627 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4628 return -EINVAL;
4629
4630 if (!info->attrs[NL80211_ATTR_MAC])
4631 return -EINVAL;
4632
4633 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4634 return -EINVAL;
4635
Johannes Berg4c476992010-10-04 21:36:35 +02004636 if (!rdev->ops->deauth)
4637 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004638
Johannes Berg074ac8d2010-09-16 14:58:22 +02004639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004640 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4641 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004642
Johannes Berg19957bb2009-07-02 17:20:43 +02004643 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004644
Johannes Berg19957bb2009-07-02 17:20:43 +02004645 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4646 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004647 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004648 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004649 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004650
4651 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004652 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4653 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004654 }
4655
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004656 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4657
Johannes Berg4c476992010-10-04 21:36:35 +02004658 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4659 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004660}
4661
4662static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4663{
Johannes Berg4c476992010-10-04 21:36:35 +02004664 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4665 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004666 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004667 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004668 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004669 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004670
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004671 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4672 return -EINVAL;
4673
4674 if (!info->attrs[NL80211_ATTR_MAC])
4675 return -EINVAL;
4676
4677 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4678 return -EINVAL;
4679
Johannes Berg4c476992010-10-04 21:36:35 +02004680 if (!rdev->ops->disassoc)
4681 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004682
Johannes Berg074ac8d2010-09-16 14:58:22 +02004683 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004684 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4685 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004686
Johannes Berg19957bb2009-07-02 17:20:43 +02004687 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004688
Johannes Berg19957bb2009-07-02 17:20:43 +02004689 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4690 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004691 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004692 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02004693 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02004694
4695 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004696 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4697 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004698 }
4699
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004700 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4701
Johannes Berg4c476992010-10-04 21:36:35 +02004702 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4703 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004704}
4705
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004706static bool
4707nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4708 int mcast_rate[IEEE80211_NUM_BANDS],
4709 int rateval)
4710{
4711 struct wiphy *wiphy = &rdev->wiphy;
4712 bool found = false;
4713 int band, i;
4714
4715 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4716 struct ieee80211_supported_band *sband;
4717
4718 sband = wiphy->bands[band];
4719 if (!sband)
4720 continue;
4721
4722 for (i = 0; i < sband->n_bitrates; i++) {
4723 if (sband->bitrates[i].bitrate == rateval) {
4724 mcast_rate[band] = i + 1;
4725 found = true;
4726 break;
4727 }
4728 }
4729 }
4730
4731 return found;
4732}
4733
Johannes Berg04a773a2009-04-19 21:24:32 +02004734static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4735{
Johannes Berg4c476992010-10-04 21:36:35 +02004736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4737 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004738 struct cfg80211_ibss_params ibss;
4739 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02004740 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004741 int err;
4742
Johannes Berg8e30bc52009-04-22 17:45:38 +02004743 memset(&ibss, 0, sizeof(ibss));
4744
Johannes Berg04a773a2009-04-19 21:24:32 +02004745 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4746 return -EINVAL;
4747
4748 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4749 !info->attrs[NL80211_ATTR_SSID] ||
4750 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4751 return -EINVAL;
4752
Johannes Berg8e30bc52009-04-22 17:45:38 +02004753 ibss.beacon_interval = 100;
4754
4755 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4756 ibss.beacon_interval =
4757 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4758 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4759 return -EINVAL;
4760 }
4761
Johannes Berg4c476992010-10-04 21:36:35 +02004762 if (!rdev->ops->join_ibss)
4763 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004764
Johannes Berg4c476992010-10-04 21:36:35 +02004765 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4766 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004767
Johannes Berg79c97e92009-07-07 03:56:12 +02004768 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02004769
Johannes Berg39193492011-09-16 13:45:25 +02004770 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02004771 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02004772
4773 if (!is_valid_ether_addr(ibss.bssid))
4774 return -EINVAL;
4775 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004776 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4777 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4778
4779 if (info->attrs[NL80211_ATTR_IE]) {
4780 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4781 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4782 }
4783
Alexander Simon54858ee5b2011-11-30 16:56:32 +01004784 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4785 enum nl80211_channel_type channel_type;
4786
4787 channel_type = nla_get_u32(
4788 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4789 if (channel_type != NL80211_CHAN_NO_HT &&
4790 channel_type != NL80211_CHAN_HT20 &&
4791 channel_type != NL80211_CHAN_HT40MINUS &&
4792 channel_type != NL80211_CHAN_HT40PLUS)
4793 return -EINVAL;
4794
4795 if (channel_type != NL80211_CHAN_NO_HT &&
4796 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
4797 return -EINVAL;
4798
4799 ibss.channel_type = channel_type;
4800 } else {
4801 ibss.channel_type = NL80211_CHAN_NO_HT;
4802 }
4803
4804 ibss.channel = rdev_freq_to_chan(rdev,
4805 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
4806 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02004807 if (!ibss.channel ||
4808 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02004809 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4810 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02004811
Alexander Simon54858ee5b2011-11-30 16:56:32 +01004812 /* Both channels should be able to initiate communication */
4813 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
4814 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
4815 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
4816 ibss.channel_type))
4817 return -EINVAL;
4818
Johannes Berg04a773a2009-04-19 21:24:32 +02004819 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02004820 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02004821
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004822 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4823 u8 *rates =
4824 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4825 int n_rates =
4826 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4827 struct ieee80211_supported_band *sband =
4828 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004829
Johannes Berg34850ab2011-07-18 18:08:35 +02004830 err = ieee80211_get_ratemask(sband, rates, n_rates,
4831 &ibss.basic_rates);
4832 if (err)
4833 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004834 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01004835
4836 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4837 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4838 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4839 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03004840
Johannes Berg4c476992010-10-04 21:36:35 +02004841 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4842 connkeys = nl80211_parse_connkeys(rdev,
4843 info->attrs[NL80211_ATTR_KEYS]);
4844 if (IS_ERR(connkeys))
4845 return PTR_ERR(connkeys);
4846 }
Johannes Berg04a773a2009-04-19 21:24:32 +02004847
Antonio Quartulli267335d2012-01-31 20:25:47 +01004848 ibss.control_port =
4849 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
4850
Johannes Berg4c476992010-10-04 21:36:35 +02004851 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02004852 if (err)
4853 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02004854 return err;
4855}
4856
4857static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4858{
Johannes Berg4c476992010-10-04 21:36:35 +02004859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4860 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02004861
Johannes Berg4c476992010-10-04 21:36:35 +02004862 if (!rdev->ops->leave_ibss)
4863 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004864
Johannes Berg4c476992010-10-04 21:36:35 +02004865 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4866 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02004867
Johannes Berg4c476992010-10-04 21:36:35 +02004868 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02004869}
4870
Johannes Bergaff89a92009-07-01 21:26:51 +02004871#ifdef CONFIG_NL80211_TESTMODE
4872static struct genl_multicast_group nl80211_testmode_mcgrp = {
4873 .name = "testmode",
4874};
4875
4876static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4877{
Johannes Berg4c476992010-10-04 21:36:35 +02004878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02004879 int err;
4880
4881 if (!info->attrs[NL80211_ATTR_TESTDATA])
4882 return -EINVAL;
4883
Johannes Bergaff89a92009-07-01 21:26:51 +02004884 err = -EOPNOTSUPP;
4885 if (rdev->ops->testmode_cmd) {
4886 rdev->testmode_info = info;
4887 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4888 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4889 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4890 rdev->testmode_info = NULL;
4891 }
4892
Johannes Bergaff89a92009-07-01 21:26:51 +02004893 return err;
4894}
4895
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004896static int nl80211_testmode_dump(struct sk_buff *skb,
4897 struct netlink_callback *cb)
4898{
Johannes Berg00918d32011-12-13 17:22:05 +01004899 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004900 int err;
4901 long phy_idx;
4902 void *data = NULL;
4903 int data_len = 0;
4904
4905 if (cb->args[0]) {
4906 /*
4907 * 0 is a valid index, but not valid for args[0],
4908 * so we need to offset by 1.
4909 */
4910 phy_idx = cb->args[0] - 1;
4911 } else {
4912 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4913 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4914 nl80211_policy);
4915 if (err)
4916 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01004917 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
4918 phy_idx = nla_get_u32(
4919 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4920 } else {
4921 struct net_device *netdev;
4922
4923 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
4924 nl80211_fam.attrbuf,
4925 &rdev, &netdev);
4926 if (err)
4927 return err;
4928 dev_put(netdev);
4929 phy_idx = rdev->wiphy_idx;
4930 cfg80211_unlock_rdev(rdev);
4931 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004932 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4933 cb->args[1] =
4934 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4935 }
4936
4937 if (cb->args[1]) {
4938 data = nla_data((void *)cb->args[1]);
4939 data_len = nla_len((void *)cb->args[1]);
4940 }
4941
4942 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01004943 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4944 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004945 mutex_unlock(&cfg80211_mutex);
4946 return -ENOENT;
4947 }
Johannes Berg00918d32011-12-13 17:22:05 +01004948 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004949 mutex_unlock(&cfg80211_mutex);
4950
Johannes Berg00918d32011-12-13 17:22:05 +01004951 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004952 err = -EOPNOTSUPP;
4953 goto out_err;
4954 }
4955
4956 while (1) {
4957 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4958 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4959 NL80211_CMD_TESTMODE);
4960 struct nlattr *tmdata;
4961
Johannes Berg00918d32011-12-13 17:22:05 +01004962 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004963 genlmsg_cancel(skb, hdr);
4964 break;
4965 }
4966
4967 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4968 if (!tmdata) {
4969 genlmsg_cancel(skb, hdr);
4970 break;
4971 }
Johannes Berg00918d32011-12-13 17:22:05 +01004972 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
4973 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004974 nla_nest_end(skb, tmdata);
4975
4976 if (err == -ENOBUFS || err == -ENOENT) {
4977 genlmsg_cancel(skb, hdr);
4978 break;
4979 } else if (err) {
4980 genlmsg_cancel(skb, hdr);
4981 goto out_err;
4982 }
4983
4984 genlmsg_end(skb, hdr);
4985 }
4986
4987 err = skb->len;
4988 /* see above */
4989 cb->args[0] = phy_idx + 1;
4990 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01004991 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004992 return err;
4993}
4994
Johannes Bergaff89a92009-07-01 21:26:51 +02004995static struct sk_buff *
4996__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4997 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4998{
4999 struct sk_buff *skb;
5000 void *hdr;
5001 struct nlattr *data;
5002
5003 skb = nlmsg_new(approxlen + 100, gfp);
5004 if (!skb)
5005 return NULL;
5006
5007 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5008 if (!hdr) {
5009 kfree_skb(skb);
5010 return NULL;
5011 }
5012
5013 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
5014 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5015
5016 ((void **)skb->cb)[0] = rdev;
5017 ((void **)skb->cb)[1] = hdr;
5018 ((void **)skb->cb)[2] = data;
5019
5020 return skb;
5021
5022 nla_put_failure:
5023 kfree_skb(skb);
5024 return NULL;
5025}
5026
5027struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5028 int approxlen)
5029{
5030 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5031
5032 if (WARN_ON(!rdev->testmode_info))
5033 return NULL;
5034
5035 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5036 rdev->testmode_info->snd_pid,
5037 rdev->testmode_info->snd_seq,
5038 GFP_KERNEL);
5039}
5040EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5041
5042int cfg80211_testmode_reply(struct sk_buff *skb)
5043{
5044 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5045 void *hdr = ((void **)skb->cb)[1];
5046 struct nlattr *data = ((void **)skb->cb)[2];
5047
5048 if (WARN_ON(!rdev->testmode_info)) {
5049 kfree_skb(skb);
5050 return -EINVAL;
5051 }
5052
5053 nla_nest_end(skb, data);
5054 genlmsg_end(skb, hdr);
5055 return genlmsg_reply(skb, rdev->testmode_info);
5056}
5057EXPORT_SYMBOL(cfg80211_testmode_reply);
5058
5059struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5060 int approxlen, gfp_t gfp)
5061{
5062 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5063
5064 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5065}
5066EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5067
5068void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5069{
5070 void *hdr = ((void **)skb->cb)[1];
5071 struct nlattr *data = ((void **)skb->cb)[2];
5072
5073 nla_nest_end(skb, data);
5074 genlmsg_end(skb, hdr);
5075 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5076}
5077EXPORT_SYMBOL(cfg80211_testmode_event);
5078#endif
5079
Samuel Ortizb23aa672009-07-01 21:26:54 +02005080static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5081{
Johannes Berg4c476992010-10-04 21:36:35 +02005082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5083 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005084 struct cfg80211_connect_params connect;
5085 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005086 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005087 int err;
5088
5089 memset(&connect, 0, sizeof(connect));
5090
5091 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5092 return -EINVAL;
5093
5094 if (!info->attrs[NL80211_ATTR_SSID] ||
5095 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5096 return -EINVAL;
5097
5098 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5099 connect.auth_type =
5100 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5101 if (!nl80211_valid_auth_type(connect.auth_type))
5102 return -EINVAL;
5103 } else
5104 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5105
5106 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5107
Johannes Bergc0692b82010-08-27 14:26:53 +03005108 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005109 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005110 if (err)
5111 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005112
Johannes Berg074ac8d2010-09-16 14:58:22 +02005113 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005114 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5115 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005116
Johannes Berg79c97e92009-07-07 03:56:12 +02005117 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005118
Samuel Ortizb23aa672009-07-01 21:26:54 +02005119 if (info->attrs[NL80211_ATTR_MAC])
5120 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5121 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5122 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5123
5124 if (info->attrs[NL80211_ATTR_IE]) {
5125 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5126 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5127 }
5128
5129 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5130 connect.channel =
5131 ieee80211_get_channel(wiphy,
5132 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5133 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005134 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5135 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005136 }
5137
Johannes Bergfffd0932009-07-08 14:22:54 +02005138 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5139 connkeys = nl80211_parse_connkeys(rdev,
5140 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005141 if (IS_ERR(connkeys))
5142 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005143 }
5144
Ben Greear7e7c8922011-11-18 11:31:59 -08005145 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5146 connect.flags |= ASSOC_REQ_DISABLE_HT;
5147
5148 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5149 memcpy(&connect.ht_capa_mask,
5150 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5151 sizeof(connect.ht_capa_mask));
5152
5153 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5154 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5155 return -EINVAL;
5156 memcpy(&connect.ht_capa,
5157 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5158 sizeof(connect.ht_capa));
5159 }
5160
Johannes Bergfffd0932009-07-08 14:22:54 +02005161 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005162 if (err)
5163 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005164 return err;
5165}
5166
5167static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5168{
Johannes Berg4c476992010-10-04 21:36:35 +02005169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5170 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005171 u16 reason;
5172
5173 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5174 reason = WLAN_REASON_DEAUTH_LEAVING;
5175 else
5176 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5177
5178 if (reason == 0)
5179 return -EINVAL;
5180
Johannes Berg074ac8d2010-09-16 14:58:22 +02005181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5183 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005184
Johannes Berg4c476992010-10-04 21:36:35 +02005185 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005186}
5187
Johannes Berg463d0182009-07-14 00:33:35 +02005188static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5189{
Johannes Berg4c476992010-10-04 21:36:35 +02005190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005191 struct net *net;
5192 int err;
5193 u32 pid;
5194
5195 if (!info->attrs[NL80211_ATTR_PID])
5196 return -EINVAL;
5197
5198 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5199
Johannes Berg463d0182009-07-14 00:33:35 +02005200 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005201 if (IS_ERR(net))
5202 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005203
5204 err = 0;
5205
5206 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005207 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5208 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005209
Johannes Berg463d0182009-07-14 00:33:35 +02005210 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005211 return err;
5212}
5213
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005214static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5215{
Johannes Berg4c476992010-10-04 21:36:35 +02005216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005217 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5218 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005219 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005220 struct cfg80211_pmksa pmksa;
5221
5222 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5223
5224 if (!info->attrs[NL80211_ATTR_MAC])
5225 return -EINVAL;
5226
5227 if (!info->attrs[NL80211_ATTR_PMKID])
5228 return -EINVAL;
5229
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005230 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5231 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5232
Johannes Berg074ac8d2010-09-16 14:58:22 +02005233 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005234 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5235 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005236
5237 switch (info->genlhdr->cmd) {
5238 case NL80211_CMD_SET_PMKSA:
5239 rdev_ops = rdev->ops->set_pmksa;
5240 break;
5241 case NL80211_CMD_DEL_PMKSA:
5242 rdev_ops = rdev->ops->del_pmksa;
5243 break;
5244 default:
5245 WARN_ON(1);
5246 break;
5247 }
5248
Johannes Berg4c476992010-10-04 21:36:35 +02005249 if (!rdev_ops)
5250 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005251
Johannes Berg4c476992010-10-04 21:36:35 +02005252 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005253}
5254
5255static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5256{
Johannes Berg4c476992010-10-04 21:36:35 +02005257 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5258 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005259
Johannes Berg074ac8d2010-09-16 14:58:22 +02005260 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005261 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5262 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005263
Johannes Berg4c476992010-10-04 21:36:35 +02005264 if (!rdev->ops->flush_pmksa)
5265 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005266
Johannes Berg4c476992010-10-04 21:36:35 +02005267 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005268}
5269
Arik Nemtsov109086c2011-09-28 14:12:50 +03005270static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5271{
5272 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5273 struct net_device *dev = info->user_ptr[1];
5274 u8 action_code, dialog_token;
5275 u16 status_code;
5276 u8 *peer;
5277
5278 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5279 !rdev->ops->tdls_mgmt)
5280 return -EOPNOTSUPP;
5281
5282 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5283 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5284 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5285 !info->attrs[NL80211_ATTR_IE] ||
5286 !info->attrs[NL80211_ATTR_MAC])
5287 return -EINVAL;
5288
5289 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5290 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5291 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5292 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5293
5294 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5295 dialog_token, status_code,
5296 nla_data(info->attrs[NL80211_ATTR_IE]),
5297 nla_len(info->attrs[NL80211_ATTR_IE]));
5298}
5299
5300static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5301{
5302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5303 struct net_device *dev = info->user_ptr[1];
5304 enum nl80211_tdls_operation operation;
5305 u8 *peer;
5306
5307 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5308 !rdev->ops->tdls_oper)
5309 return -EOPNOTSUPP;
5310
5311 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5312 !info->attrs[NL80211_ATTR_MAC])
5313 return -EINVAL;
5314
5315 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5316 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5317
5318 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5319}
5320
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005321static int nl80211_remain_on_channel(struct sk_buff *skb,
5322 struct genl_info *info)
5323{
Johannes Berg4c476992010-10-04 21:36:35 +02005324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5325 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005326 struct ieee80211_channel *chan;
5327 struct sk_buff *msg;
5328 void *hdr;
5329 u64 cookie;
5330 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5331 u32 freq, duration;
5332 int err;
5333
5334 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5335 !info->attrs[NL80211_ATTR_DURATION])
5336 return -EINVAL;
5337
5338 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5339
5340 /*
5341 * We should be on that channel for at least one jiffie,
5342 * and more than 5 seconds seems excessive.
5343 */
Johannes Berga2939112010-12-14 17:54:28 +01005344 if (!duration || !msecs_to_jiffies(duration) ||
5345 duration > rdev->wiphy.max_remain_on_channel_duration)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005346 return -EINVAL;
5347
Johannes Berg7c4ef712011-11-18 15:33:48 +01005348 if (!rdev->ops->remain_on_channel ||
5349 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005350 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005351
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005352 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5353 channel_type = nla_get_u32(
5354 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5355 if (channel_type != NL80211_CHAN_NO_HT &&
5356 channel_type != NL80211_CHAN_HT20 &&
5357 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005358 channel_type != NL80211_CHAN_HT40MINUS)
5359 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005360 }
5361
5362 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5363 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005364 if (chan == NULL)
5365 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005366
5367 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005368 if (!msg)
5369 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005370
5371 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5372 NL80211_CMD_REMAIN_ON_CHANNEL);
5373
5374 if (IS_ERR(hdr)) {
5375 err = PTR_ERR(hdr);
5376 goto free_msg;
5377 }
5378
5379 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5380 channel_type, duration, &cookie);
5381
5382 if (err)
5383 goto free_msg;
5384
5385 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5386
5387 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005388
5389 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005390
5391 nla_put_failure:
5392 err = -ENOBUFS;
5393 free_msg:
5394 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005395 return err;
5396}
5397
5398static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5399 struct genl_info *info)
5400{
Johannes Berg4c476992010-10-04 21:36:35 +02005401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5402 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005403 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005404
5405 if (!info->attrs[NL80211_ATTR_COOKIE])
5406 return -EINVAL;
5407
Johannes Berg4c476992010-10-04 21:36:35 +02005408 if (!rdev->ops->cancel_remain_on_channel)
5409 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005410
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005411 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5412
Johannes Berg4c476992010-10-04 21:36:35 +02005413 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005414}
5415
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005416static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5417 u8 *rates, u8 rates_len)
5418{
5419 u8 i;
5420 u32 mask = 0;
5421
5422 for (i = 0; i < rates_len; i++) {
5423 int rate = (rates[i] & 0x7f) * 5;
5424 int ridx;
5425 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5426 struct ieee80211_rate *srate =
5427 &sband->bitrates[ridx];
5428 if (rate == srate->bitrate) {
5429 mask |= 1 << ridx;
5430 break;
5431 }
5432 }
5433 if (ridx == sband->n_bitrates)
5434 return 0; /* rate not found */
5435 }
5436
5437 return mask;
5438}
5439
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005440static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5441 u8 *rates, u8 rates_len,
5442 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5443{
5444 u8 i;
5445
5446 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5447
5448 for (i = 0; i < rates_len; i++) {
5449 int ridx, rbit;
5450
5451 ridx = rates[i] / 8;
5452 rbit = BIT(rates[i] % 8);
5453
5454 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005455 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005456 return false;
5457
5458 /* check availability */
5459 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5460 mcs[ridx] |= rbit;
5461 else
5462 return false;
5463 }
5464
5465 return true;
5466}
5467
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005468static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005469 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5470 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005471 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5472 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005473};
5474
5475static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5476 struct genl_info *info)
5477{
5478 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005480 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005481 int rem, i;
5482 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005483 struct nlattr *tx_rates;
5484 struct ieee80211_supported_band *sband;
5485
5486 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5487 return -EINVAL;
5488
Johannes Berg4c476992010-10-04 21:36:35 +02005489 if (!rdev->ops->set_bitrate_mask)
5490 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005491
5492 memset(&mask, 0, sizeof(mask));
5493 /* Default to all rates enabled */
5494 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5495 sband = rdev->wiphy.bands[i];
5496 mask.control[i].legacy =
5497 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005498 if (sband)
5499 memcpy(mask.control[i].mcs,
5500 sband->ht_cap.mcs.rx_mask,
5501 sizeof(mask.control[i].mcs));
5502 else
5503 memset(mask.control[i].mcs, 0,
5504 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005505 }
5506
5507 /*
5508 * The nested attribute uses enum nl80211_band as the index. This maps
5509 * directly to the enum ieee80211_band values used in cfg80211.
5510 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005511 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005512 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5513 {
5514 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005515 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5516 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005517 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005518 if (sband == NULL)
5519 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005520 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5521 nla_len(tx_rates), nl80211_txattr_policy);
5522 if (tb[NL80211_TXRATE_LEGACY]) {
5523 mask.control[band].legacy = rateset_to_mask(
5524 sband,
5525 nla_data(tb[NL80211_TXRATE_LEGACY]),
5526 nla_len(tb[NL80211_TXRATE_LEGACY]));
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005527 }
5528 if (tb[NL80211_TXRATE_MCS]) {
5529 if (!ht_rateset_to_mask(
5530 sband,
5531 nla_data(tb[NL80211_TXRATE_MCS]),
5532 nla_len(tb[NL80211_TXRATE_MCS]),
5533 mask.control[band].mcs))
5534 return -EINVAL;
5535 }
5536
5537 if (mask.control[band].legacy == 0) {
5538 /* don't allow empty legacy rates if HT
5539 * is not even supported. */
5540 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5541 return -EINVAL;
5542
5543 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5544 if (mask.control[band].mcs[i])
5545 break;
5546
5547 /* legacy and mcs rates may not be both empty */
5548 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005549 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005550 }
5551 }
5552
Johannes Berg4c476992010-10-04 21:36:35 +02005553 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005554}
5555
Johannes Berg2e161f72010-08-12 15:38:38 +02005556static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005557{
Johannes Berg4c476992010-10-04 21:36:35 +02005558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5559 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005560 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005561
5562 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5563 return -EINVAL;
5564
Johannes Berg2e161f72010-08-12 15:38:38 +02005565 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5566 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005567
Johannes Berg9d38d852010-06-09 17:20:33 +02005568 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005569 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005570 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5571 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5572 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005573 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005574 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5575 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005576
5577 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005578 if (!rdev->ops->mgmt_tx)
5579 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005580
Johannes Berg4c476992010-10-04 21:36:35 +02005581 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005582 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005583 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5584 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005585}
5586
Johannes Berg2e161f72010-08-12 15:38:38 +02005587static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005588{
Johannes Berg4c476992010-10-04 21:36:35 +02005589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5590 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005591 struct ieee80211_channel *chan;
5592 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005593 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005594 u32 freq;
5595 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005596 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005597 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005598 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005599 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005600 bool offchan, no_cck, dont_wait_for_ack;
5601
5602 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005603
5604 if (!info->attrs[NL80211_ATTR_FRAME] ||
5605 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5606 return -EINVAL;
5607
Johannes Berg4c476992010-10-04 21:36:35 +02005608 if (!rdev->ops->mgmt_tx)
5609 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005610
Johannes Berg9d38d852010-06-09 17:20:33 +02005611 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005612 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005613 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5614 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5615 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005616 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005617 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5618 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005619
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005620 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005621 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005622 return -EINVAL;
5623 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5624 }
5625
Jouni Malinen026331c2010-02-15 12:53:10 +02005626 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5627 channel_type = nla_get_u32(
5628 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5629 if (channel_type != NL80211_CHAN_NO_HT &&
5630 channel_type != NL80211_CHAN_HT20 &&
5631 channel_type != NL80211_CHAN_HT40PLUS &&
Johannes Berg4c476992010-10-04 21:36:35 +02005632 channel_type != NL80211_CHAN_HT40MINUS)
5633 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005634 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005635 }
5636
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005637 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5638
Johannes Berg7c4ef712011-11-18 15:33:48 +01005639 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5640 return -EINVAL;
5641
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305642 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5643
Jouni Malinen026331c2010-02-15 12:53:10 +02005644 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5645 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005646 if (chan == NULL)
5647 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005648
Johannes Berge247bd902011-11-04 11:18:21 +01005649 if (!dont_wait_for_ack) {
5650 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5651 if (!msg)
5652 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02005653
Johannes Berge247bd902011-11-04 11:18:21 +01005654 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5655 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02005656
Johannes Berge247bd902011-11-04 11:18:21 +01005657 if (IS_ERR(hdr)) {
5658 err = PTR_ERR(hdr);
5659 goto free_msg;
5660 }
Jouni Malinen026331c2010-02-15 12:53:10 +02005661 }
Johannes Berge247bd902011-11-04 11:18:21 +01005662
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005663 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5664 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02005665 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5666 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01005667 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005668 if (err)
5669 goto free_msg;
5670
Johannes Berge247bd902011-11-04 11:18:21 +01005671 if (msg) {
5672 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02005673
Johannes Berge247bd902011-11-04 11:18:21 +01005674 genlmsg_end(msg, hdr);
5675 return genlmsg_reply(msg, info);
5676 }
5677
5678 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02005679
5680 nla_put_failure:
5681 err = -ENOBUFS;
5682 free_msg:
5683 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02005684 return err;
5685}
5686
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005687static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5688{
5689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5690 struct net_device *dev = info->user_ptr[1];
5691 u64 cookie;
5692
5693 if (!info->attrs[NL80211_ATTR_COOKIE])
5694 return -EINVAL;
5695
5696 if (!rdev->ops->mgmt_tx_cancel_wait)
5697 return -EOPNOTSUPP;
5698
5699 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5700 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5701 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5702 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5703 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5704 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5705 return -EOPNOTSUPP;
5706
5707 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5708
5709 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5710}
5711
Kalle Valoffb9eb32010-02-17 17:58:10 +02005712static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5713{
Johannes Berg4c476992010-10-04 21:36:35 +02005714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005715 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005716 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005717 u8 ps_state;
5718 bool state;
5719 int err;
5720
Johannes Berg4c476992010-10-04 21:36:35 +02005721 if (!info->attrs[NL80211_ATTR_PS_STATE])
5722 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005723
5724 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5725
Johannes Berg4c476992010-10-04 21:36:35 +02005726 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5727 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005728
5729 wdev = dev->ieee80211_ptr;
5730
Johannes Berg4c476992010-10-04 21:36:35 +02005731 if (!rdev->ops->set_power_mgmt)
5732 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005733
5734 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5735
5736 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02005737 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005738
Johannes Berg4c476992010-10-04 21:36:35 +02005739 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5740 wdev->ps_timeout);
5741 if (!err)
5742 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005743 return err;
5744}
5745
5746static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5747{
Johannes Berg4c476992010-10-04 21:36:35 +02005748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005749 enum nl80211_ps_state ps_state;
5750 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005751 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02005752 struct sk_buff *msg;
5753 void *hdr;
5754 int err;
5755
Kalle Valoffb9eb32010-02-17 17:58:10 +02005756 wdev = dev->ieee80211_ptr;
5757
Johannes Berg4c476992010-10-04 21:36:35 +02005758 if (!rdev->ops->set_power_mgmt)
5759 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005760
5761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005762 if (!msg)
5763 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005764
5765 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5766 NL80211_CMD_GET_POWER_SAVE);
5767 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02005768 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02005769 goto free_msg;
5770 }
5771
5772 if (wdev->ps)
5773 ps_state = NL80211_PS_ENABLED;
5774 else
5775 ps_state = NL80211_PS_DISABLED;
5776
5777 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5778
5779 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005780 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005781
Johannes Berg4c476992010-10-04 21:36:35 +02005782 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005783 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005784 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02005785 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02005786 return err;
5787}
5788
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005789static struct nla_policy
5790nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5791 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5792 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5793 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5794};
5795
5796static int nl80211_set_cqm_rssi(struct genl_info *info,
5797 s32 threshold, u32 hysteresis)
5798{
Johannes Berg4c476992010-10-04 21:36:35 +02005799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005800 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02005801 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005802
5803 if (threshold > 0)
5804 return -EINVAL;
5805
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005806 wdev = dev->ieee80211_ptr;
5807
Johannes Berg4c476992010-10-04 21:36:35 +02005808 if (!rdev->ops->set_cqm_rssi_config)
5809 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005810
Johannes Berg074ac8d2010-09-16 14:58:22 +02005811 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005812 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5813 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005814
Johannes Berg4c476992010-10-04 21:36:35 +02005815 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5816 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02005817}
5818
5819static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5820{
5821 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5822 struct nlattr *cqm;
5823 int err;
5824
5825 cqm = info->attrs[NL80211_ATTR_CQM];
5826 if (!cqm) {
5827 err = -EINVAL;
5828 goto out;
5829 }
5830
5831 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5832 nl80211_attr_cqm_policy);
5833 if (err)
5834 goto out;
5835
5836 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5837 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5838 s32 threshold;
5839 u32 hysteresis;
5840 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5841 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5842 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5843 } else
5844 err = -EINVAL;
5845
5846out:
5847 return err;
5848}
5849
Johannes Berg29cbe682010-12-03 09:20:44 +01005850static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5851{
5852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5853 struct net_device *dev = info->user_ptr[1];
5854 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08005855 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01005856 int err;
5857
5858 /* start with default */
5859 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08005860 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01005861
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005862 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01005863 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005864 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01005865 if (err)
5866 return err;
5867 }
5868
5869 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5870 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5871 return -EINVAL;
5872
Javier Cardonac80d5452010-12-16 17:37:49 -08005873 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5874 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5875
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08005876 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5877 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
5878 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5879 return -EINVAL;
5880
Javier Cardonac80d5452010-12-16 17:37:49 -08005881 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5882 /* parse additional setup parameters if given */
5883 err = nl80211_parse_mesh_setup(info, &setup);
5884 if (err)
5885 return err;
5886 }
5887
5888 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005889}
5890
5891static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5892{
5893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5894 struct net_device *dev = info->user_ptr[1];
5895
5896 return cfg80211_leave_mesh(rdev, dev);
5897}
5898
Johannes Bergff1b6e62011-05-04 15:37:28 +02005899static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5900{
5901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5902 struct sk_buff *msg;
5903 void *hdr;
5904
5905 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5906 return -EOPNOTSUPP;
5907
5908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5909 if (!msg)
5910 return -ENOMEM;
5911
5912 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5913 NL80211_CMD_GET_WOWLAN);
5914 if (!hdr)
5915 goto nla_put_failure;
5916
5917 if (rdev->wowlan) {
5918 struct nlattr *nl_wowlan;
5919
5920 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5921 if (!nl_wowlan)
5922 goto nla_put_failure;
5923
5924 if (rdev->wowlan->any)
5925 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5926 if (rdev->wowlan->disconnect)
5927 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5928 if (rdev->wowlan->magic_pkt)
5929 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
Johannes Berg77dbbb12011-07-13 10:48:55 +02005930 if (rdev->wowlan->gtk_rekey_failure)
5931 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5932 if (rdev->wowlan->eap_identity_req)
5933 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5934 if (rdev->wowlan->four_way_handshake)
5935 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5936 if (rdev->wowlan->rfkill_release)
5937 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
Johannes Bergff1b6e62011-05-04 15:37:28 +02005938 if (rdev->wowlan->n_patterns) {
5939 struct nlattr *nl_pats, *nl_pat;
5940 int i, pat_len;
5941
5942 nl_pats = nla_nest_start(msg,
5943 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5944 if (!nl_pats)
5945 goto nla_put_failure;
5946
5947 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5948 nl_pat = nla_nest_start(msg, i + 1);
5949 if (!nl_pat)
5950 goto nla_put_failure;
5951 pat_len = rdev->wowlan->patterns[i].pattern_len;
5952 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5953 DIV_ROUND_UP(pat_len, 8),
5954 rdev->wowlan->patterns[i].mask);
5955 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5956 pat_len,
5957 rdev->wowlan->patterns[i].pattern);
5958 nla_nest_end(msg, nl_pat);
5959 }
5960 nla_nest_end(msg, nl_pats);
5961 }
5962
5963 nla_nest_end(msg, nl_wowlan);
5964 }
5965
5966 genlmsg_end(msg, hdr);
5967 return genlmsg_reply(msg, info);
5968
5969nla_put_failure:
5970 nlmsg_free(msg);
5971 return -ENOBUFS;
5972}
5973
5974static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5975{
5976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5977 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5978 struct cfg80211_wowlan no_triggers = {};
5979 struct cfg80211_wowlan new_triggers = {};
5980 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5981 int err, i;
5982
5983 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5984 return -EOPNOTSUPP;
5985
5986 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5987 goto no_triggers;
5988
5989 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5990 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5991 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5992 nl80211_wowlan_policy);
5993 if (err)
5994 return err;
5995
5996 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5997 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5998 return -EINVAL;
5999 new_triggers.any = true;
6000 }
6001
6002 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6003 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6004 return -EINVAL;
6005 new_triggers.disconnect = true;
6006 }
6007
6008 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6009 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6010 return -EINVAL;
6011 new_triggers.magic_pkt = true;
6012 }
6013
Johannes Berg77dbbb12011-07-13 10:48:55 +02006014 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6015 return -EINVAL;
6016
6017 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6018 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6019 return -EINVAL;
6020 new_triggers.gtk_rekey_failure = true;
6021 }
6022
6023 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6024 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6025 return -EINVAL;
6026 new_triggers.eap_identity_req = true;
6027 }
6028
6029 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6030 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6031 return -EINVAL;
6032 new_triggers.four_way_handshake = true;
6033 }
6034
6035 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6036 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6037 return -EINVAL;
6038 new_triggers.rfkill_release = true;
6039 }
6040
Johannes Bergff1b6e62011-05-04 15:37:28 +02006041 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6042 struct nlattr *pat;
6043 int n_patterns = 0;
6044 int rem, pat_len, mask_len;
6045 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6046
6047 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6048 rem)
6049 n_patterns++;
6050 if (n_patterns > wowlan->n_patterns)
6051 return -EINVAL;
6052
6053 new_triggers.patterns = kcalloc(n_patterns,
6054 sizeof(new_triggers.patterns[0]),
6055 GFP_KERNEL);
6056 if (!new_triggers.patterns)
6057 return -ENOMEM;
6058
6059 new_triggers.n_patterns = n_patterns;
6060 i = 0;
6061
6062 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6063 rem) {
6064 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6065 nla_data(pat), nla_len(pat), NULL);
6066 err = -EINVAL;
6067 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6068 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6069 goto error;
6070 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6071 mask_len = DIV_ROUND_UP(pat_len, 8);
6072 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6073 mask_len)
6074 goto error;
6075 if (pat_len > wowlan->pattern_max_len ||
6076 pat_len < wowlan->pattern_min_len)
6077 goto error;
6078
6079 new_triggers.patterns[i].mask =
6080 kmalloc(mask_len + pat_len, GFP_KERNEL);
6081 if (!new_triggers.patterns[i].mask) {
6082 err = -ENOMEM;
6083 goto error;
6084 }
6085 new_triggers.patterns[i].pattern =
6086 new_triggers.patterns[i].mask + mask_len;
6087 memcpy(new_triggers.patterns[i].mask,
6088 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6089 mask_len);
6090 new_triggers.patterns[i].pattern_len = pat_len;
6091 memcpy(new_triggers.patterns[i].pattern,
6092 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6093 pat_len);
6094 i++;
6095 }
6096 }
6097
6098 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6099 struct cfg80211_wowlan *ntrig;
6100 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6101 GFP_KERNEL);
6102 if (!ntrig) {
6103 err = -ENOMEM;
6104 goto error;
6105 }
6106 cfg80211_rdev_free_wowlan(rdev);
6107 rdev->wowlan = ntrig;
6108 } else {
6109 no_triggers:
6110 cfg80211_rdev_free_wowlan(rdev);
6111 rdev->wowlan = NULL;
6112 }
6113
6114 return 0;
6115 error:
6116 for (i = 0; i < new_triggers.n_patterns; i++)
6117 kfree(new_triggers.patterns[i].mask);
6118 kfree(new_triggers.patterns);
6119 return err;
6120}
6121
Johannes Berge5497d72011-07-05 16:35:40 +02006122static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6123{
6124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6125 struct net_device *dev = info->user_ptr[1];
6126 struct wireless_dev *wdev = dev->ieee80211_ptr;
6127 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6128 struct cfg80211_gtk_rekey_data rekey_data;
6129 int err;
6130
6131 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6132 return -EINVAL;
6133
6134 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6135 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6136 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6137 nl80211_rekey_policy);
6138 if (err)
6139 return err;
6140
6141 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6142 return -ERANGE;
6143 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6144 return -ERANGE;
6145 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6146 return -ERANGE;
6147
6148 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6149 NL80211_KEK_LEN);
6150 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6151 NL80211_KCK_LEN);
6152 memcpy(rekey_data.replay_ctr,
6153 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6154 NL80211_REPLAY_CTR_LEN);
6155
6156 wdev_lock(wdev);
6157 if (!wdev->current_bss) {
6158 err = -ENOTCONN;
6159 goto out;
6160 }
6161
6162 if (!rdev->ops->set_rekey_data) {
6163 err = -EOPNOTSUPP;
6164 goto out;
6165 }
6166
6167 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6168 out:
6169 wdev_unlock(wdev);
6170 return err;
6171}
6172
Johannes Berg28946da2011-11-04 11:18:12 +01006173static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6174 struct genl_info *info)
6175{
6176 struct net_device *dev = info->user_ptr[1];
6177 struct wireless_dev *wdev = dev->ieee80211_ptr;
6178
6179 if (wdev->iftype != NL80211_IFTYPE_AP &&
6180 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6181 return -EINVAL;
6182
6183 if (wdev->ap_unexpected_nlpid)
6184 return -EBUSY;
6185
6186 wdev->ap_unexpected_nlpid = info->snd_pid;
6187 return 0;
6188}
6189
Johannes Berg7f6cf312011-11-04 11:18:15 +01006190static int nl80211_probe_client(struct sk_buff *skb,
6191 struct genl_info *info)
6192{
6193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6194 struct net_device *dev = info->user_ptr[1];
6195 struct wireless_dev *wdev = dev->ieee80211_ptr;
6196 struct sk_buff *msg;
6197 void *hdr;
6198 const u8 *addr;
6199 u64 cookie;
6200 int err;
6201
6202 if (wdev->iftype != NL80211_IFTYPE_AP &&
6203 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6204 return -EOPNOTSUPP;
6205
6206 if (!info->attrs[NL80211_ATTR_MAC])
6207 return -EINVAL;
6208
6209 if (!rdev->ops->probe_client)
6210 return -EOPNOTSUPP;
6211
6212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6213 if (!msg)
6214 return -ENOMEM;
6215
6216 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6217 NL80211_CMD_PROBE_CLIENT);
6218
6219 if (IS_ERR(hdr)) {
6220 err = PTR_ERR(hdr);
6221 goto free_msg;
6222 }
6223
6224 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6225
6226 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6227 if (err)
6228 goto free_msg;
6229
6230 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6231
6232 genlmsg_end(msg, hdr);
6233
6234 return genlmsg_reply(msg, info);
6235
6236 nla_put_failure:
6237 err = -ENOBUFS;
6238 free_msg:
6239 nlmsg_free(msg);
6240 return err;
6241}
6242
Johannes Berg5e760232011-11-04 11:18:17 +01006243static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6244{
6245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6246
6247 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6248 return -EOPNOTSUPP;
6249
6250 if (rdev->ap_beacons_nlpid)
6251 return -EBUSY;
6252
6253 rdev->ap_beacons_nlpid = info->snd_pid;
6254
6255 return 0;
6256}
6257
Johannes Berg4c476992010-10-04 21:36:35 +02006258#define NL80211_FLAG_NEED_WIPHY 0x01
6259#define NL80211_FLAG_NEED_NETDEV 0x02
6260#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006261#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6262#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6263 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006264
6265static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6266 struct genl_info *info)
6267{
6268 struct cfg80211_registered_device *rdev;
6269 struct net_device *dev;
6270 int err;
6271 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6272
6273 if (rtnl)
6274 rtnl_lock();
6275
6276 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
6277 rdev = cfg80211_get_dev_from_info(info);
6278 if (IS_ERR(rdev)) {
6279 if (rtnl)
6280 rtnl_unlock();
6281 return PTR_ERR(rdev);
6282 }
6283 info->user_ptr[0] = rdev;
6284 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006285 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6286 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006287 if (err) {
6288 if (rtnl)
6289 rtnl_unlock();
6290 return err;
6291 }
Johannes Berg41265712010-10-04 21:14:05 +02006292 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6293 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006294 cfg80211_unlock_rdev(rdev);
6295 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006296 if (rtnl)
6297 rtnl_unlock();
6298 return -ENETDOWN;
6299 }
Johannes Berg4c476992010-10-04 21:36:35 +02006300 info->user_ptr[0] = rdev;
6301 info->user_ptr[1] = dev;
6302 }
6303
6304 return 0;
6305}
6306
6307static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6308 struct genl_info *info)
6309{
6310 if (info->user_ptr[0])
6311 cfg80211_unlock_rdev(info->user_ptr[0]);
6312 if (info->user_ptr[1])
6313 dev_put(info->user_ptr[1]);
6314 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6315 rtnl_unlock();
6316}
6317
Johannes Berg55682962007-09-20 13:09:35 -04006318static struct genl_ops nl80211_ops[] = {
6319 {
6320 .cmd = NL80211_CMD_GET_WIPHY,
6321 .doit = nl80211_get_wiphy,
6322 .dumpit = nl80211_dump_wiphy,
6323 .policy = nl80211_policy,
6324 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006325 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006326 },
6327 {
6328 .cmd = NL80211_CMD_SET_WIPHY,
6329 .doit = nl80211_set_wiphy,
6330 .policy = nl80211_policy,
6331 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006332 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006333 },
6334 {
6335 .cmd = NL80211_CMD_GET_INTERFACE,
6336 .doit = nl80211_get_interface,
6337 .dumpit = nl80211_dump_interface,
6338 .policy = nl80211_policy,
6339 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006340 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006341 },
6342 {
6343 .cmd = NL80211_CMD_SET_INTERFACE,
6344 .doit = nl80211_set_interface,
6345 .policy = nl80211_policy,
6346 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006347 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6348 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006349 },
6350 {
6351 .cmd = NL80211_CMD_NEW_INTERFACE,
6352 .doit = nl80211_new_interface,
6353 .policy = nl80211_policy,
6354 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006355 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6356 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006357 },
6358 {
6359 .cmd = NL80211_CMD_DEL_INTERFACE,
6360 .doit = nl80211_del_interface,
6361 .policy = nl80211_policy,
6362 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006363 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6364 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006365 },
Johannes Berg41ade002007-12-19 02:03:29 +01006366 {
6367 .cmd = NL80211_CMD_GET_KEY,
6368 .doit = nl80211_get_key,
6369 .policy = nl80211_policy,
6370 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006371 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6372 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006373 },
6374 {
6375 .cmd = NL80211_CMD_SET_KEY,
6376 .doit = nl80211_set_key,
6377 .policy = nl80211_policy,
6378 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006379 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006380 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006381 },
6382 {
6383 .cmd = NL80211_CMD_NEW_KEY,
6384 .doit = nl80211_new_key,
6385 .policy = nl80211_policy,
6386 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006388 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006389 },
6390 {
6391 .cmd = NL80211_CMD_DEL_KEY,
6392 .doit = nl80211_del_key,
6393 .policy = nl80211_policy,
6394 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006396 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006397 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006398 {
6399 .cmd = NL80211_CMD_SET_BEACON,
6400 .policy = nl80211_policy,
6401 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006402 .doit = nl80211_set_beacon,
Johannes Berg4c476992010-10-04 21:36:35 +02006403 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6404 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006405 },
6406 {
Johannes Berg88600202012-02-13 15:17:18 +01006407 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006408 .policy = nl80211_policy,
6409 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006410 .doit = nl80211_start_ap,
Johannes Berg4c476992010-10-04 21:36:35 +02006411 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6412 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006413 },
6414 {
Johannes Berg88600202012-02-13 15:17:18 +01006415 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006416 .policy = nl80211_policy,
6417 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006418 .doit = nl80211_stop_ap,
Johannes Berg4c476992010-10-04 21:36:35 +02006419 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6420 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006421 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006422 {
6423 .cmd = NL80211_CMD_GET_STATION,
6424 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006425 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006426 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006427 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6428 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006429 },
6430 {
6431 .cmd = NL80211_CMD_SET_STATION,
6432 .doit = nl80211_set_station,
6433 .policy = nl80211_policy,
6434 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006435 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6436 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006437 },
6438 {
6439 .cmd = NL80211_CMD_NEW_STATION,
6440 .doit = nl80211_new_station,
6441 .policy = nl80211_policy,
6442 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006444 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006445 },
6446 {
6447 .cmd = NL80211_CMD_DEL_STATION,
6448 .doit = nl80211_del_station,
6449 .policy = nl80211_policy,
6450 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006451 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6452 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006453 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006454 {
6455 .cmd = NL80211_CMD_GET_MPATH,
6456 .doit = nl80211_get_mpath,
6457 .dumpit = nl80211_dump_mpath,
6458 .policy = nl80211_policy,
6459 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006460 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006461 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006462 },
6463 {
6464 .cmd = NL80211_CMD_SET_MPATH,
6465 .doit = nl80211_set_mpath,
6466 .policy = nl80211_policy,
6467 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006468 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006469 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006470 },
6471 {
6472 .cmd = NL80211_CMD_NEW_MPATH,
6473 .doit = nl80211_new_mpath,
6474 .policy = nl80211_policy,
6475 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006477 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006478 },
6479 {
6480 .cmd = NL80211_CMD_DEL_MPATH,
6481 .doit = nl80211_del_mpath,
6482 .policy = nl80211_policy,
6483 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006484 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6485 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006486 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006487 {
6488 .cmd = NL80211_CMD_SET_BSS,
6489 .doit = nl80211_set_bss,
6490 .policy = nl80211_policy,
6491 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006492 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6493 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006494 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006495 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006496 .cmd = NL80211_CMD_GET_REG,
6497 .doit = nl80211_get_reg,
6498 .policy = nl80211_policy,
6499 /* can be retrieved by unprivileged users */
6500 },
6501 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006502 .cmd = NL80211_CMD_SET_REG,
6503 .doit = nl80211_set_reg,
6504 .policy = nl80211_policy,
6505 .flags = GENL_ADMIN_PERM,
6506 },
6507 {
6508 .cmd = NL80211_CMD_REQ_SET_REG,
6509 .doit = nl80211_req_set_reg,
6510 .policy = nl80211_policy,
6511 .flags = GENL_ADMIN_PERM,
6512 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006513 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006514 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6515 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006516 .policy = nl80211_policy,
6517 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006518 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6519 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006520 },
6521 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006522 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6523 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006524 .policy = nl80211_policy,
6525 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006526 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006527 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006528 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006529 {
Johannes Berg2a519312009-02-10 21:25:55 +01006530 .cmd = NL80211_CMD_TRIGGER_SCAN,
6531 .doit = nl80211_trigger_scan,
6532 .policy = nl80211_policy,
6533 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006534 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006535 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006536 },
6537 {
6538 .cmd = NL80211_CMD_GET_SCAN,
6539 .policy = nl80211_policy,
6540 .dumpit = nl80211_dump_scan,
6541 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006542 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006543 .cmd = NL80211_CMD_START_SCHED_SCAN,
6544 .doit = nl80211_start_sched_scan,
6545 .policy = nl80211_policy,
6546 .flags = GENL_ADMIN_PERM,
6547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6548 NL80211_FLAG_NEED_RTNL,
6549 },
6550 {
6551 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6552 .doit = nl80211_stop_sched_scan,
6553 .policy = nl80211_policy,
6554 .flags = GENL_ADMIN_PERM,
6555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6556 NL80211_FLAG_NEED_RTNL,
6557 },
6558 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006559 .cmd = NL80211_CMD_AUTHENTICATE,
6560 .doit = nl80211_authenticate,
6561 .policy = nl80211_policy,
6562 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006564 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006565 },
6566 {
6567 .cmd = NL80211_CMD_ASSOCIATE,
6568 .doit = nl80211_associate,
6569 .policy = nl80211_policy,
6570 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006571 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006572 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006573 },
6574 {
6575 .cmd = NL80211_CMD_DEAUTHENTICATE,
6576 .doit = nl80211_deauthenticate,
6577 .policy = nl80211_policy,
6578 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006580 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006581 },
6582 {
6583 .cmd = NL80211_CMD_DISASSOCIATE,
6584 .doit = nl80211_disassociate,
6585 .policy = nl80211_policy,
6586 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006587 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006588 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006589 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006590 {
6591 .cmd = NL80211_CMD_JOIN_IBSS,
6592 .doit = nl80211_join_ibss,
6593 .policy = nl80211_policy,
6594 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006595 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006596 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006597 },
6598 {
6599 .cmd = NL80211_CMD_LEAVE_IBSS,
6600 .doit = nl80211_leave_ibss,
6601 .policy = nl80211_policy,
6602 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006604 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006605 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006606#ifdef CONFIG_NL80211_TESTMODE
6607 {
6608 .cmd = NL80211_CMD_TESTMODE,
6609 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006610 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006611 .policy = nl80211_policy,
6612 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006613 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6614 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006615 },
6616#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006617 {
6618 .cmd = NL80211_CMD_CONNECT,
6619 .doit = nl80211_connect,
6620 .policy = nl80211_policy,
6621 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006623 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006624 },
6625 {
6626 .cmd = NL80211_CMD_DISCONNECT,
6627 .doit = nl80211_disconnect,
6628 .policy = nl80211_policy,
6629 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006631 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006632 },
Johannes Berg463d0182009-07-14 00:33:35 +02006633 {
6634 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6635 .doit = nl80211_wiphy_netns,
6636 .policy = nl80211_policy,
6637 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006638 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6639 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02006640 },
Holger Schurig61fa7132009-11-11 12:25:40 +01006641 {
6642 .cmd = NL80211_CMD_GET_SURVEY,
6643 .policy = nl80211_policy,
6644 .dumpit = nl80211_dump_survey,
6645 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006646 {
6647 .cmd = NL80211_CMD_SET_PMKSA,
6648 .doit = nl80211_setdel_pmksa,
6649 .policy = nl80211_policy,
6650 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006651 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6652 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006653 },
6654 {
6655 .cmd = NL80211_CMD_DEL_PMKSA,
6656 .doit = nl80211_setdel_pmksa,
6657 .policy = nl80211_policy,
6658 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006659 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6660 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006661 },
6662 {
6663 .cmd = NL80211_CMD_FLUSH_PMKSA,
6664 .doit = nl80211_flush_pmksa,
6665 .policy = nl80211_policy,
6666 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006667 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6668 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006669 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006670 {
6671 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6672 .doit = nl80211_remain_on_channel,
6673 .policy = nl80211_policy,
6674 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006675 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006676 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006677 },
6678 {
6679 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6680 .doit = nl80211_cancel_remain_on_channel,
6681 .policy = nl80211_policy,
6682 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006683 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006684 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006685 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006686 {
6687 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6688 .doit = nl80211_set_tx_bitrate_mask,
6689 .policy = nl80211_policy,
6690 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006691 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6692 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006693 },
Jouni Malinen026331c2010-02-15 12:53:10 +02006694 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006695 .cmd = NL80211_CMD_REGISTER_FRAME,
6696 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006697 .policy = nl80211_policy,
6698 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006699 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6700 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006701 },
6702 {
Johannes Berg2e161f72010-08-12 15:38:38 +02006703 .cmd = NL80211_CMD_FRAME,
6704 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02006705 .policy = nl80211_policy,
6706 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006708 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02006709 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02006710 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006711 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6712 .doit = nl80211_tx_mgmt_cancel_wait,
6713 .policy = nl80211_policy,
6714 .flags = GENL_ADMIN_PERM,
6715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6716 NL80211_FLAG_NEED_RTNL,
6717 },
6718 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02006719 .cmd = NL80211_CMD_SET_POWER_SAVE,
6720 .doit = nl80211_set_power_save,
6721 .policy = nl80211_policy,
6722 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006723 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6724 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006725 },
6726 {
6727 .cmd = NL80211_CMD_GET_POWER_SAVE,
6728 .doit = nl80211_get_power_save,
6729 .policy = nl80211_policy,
6730 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006731 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6732 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006733 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006734 {
6735 .cmd = NL80211_CMD_SET_CQM,
6736 .doit = nl80211_set_cqm,
6737 .policy = nl80211_policy,
6738 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006739 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6740 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006741 },
Johannes Bergf444de02010-05-05 15:25:02 +02006742 {
6743 .cmd = NL80211_CMD_SET_CHANNEL,
6744 .doit = nl80211_set_channel,
6745 .policy = nl80211_policy,
6746 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006747 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6748 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02006749 },
Bill Jordane8347eb2010-10-01 13:54:28 -04006750 {
6751 .cmd = NL80211_CMD_SET_WDS_PEER,
6752 .doit = nl80211_set_wds_peer,
6753 .policy = nl80211_policy,
6754 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02006755 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6756 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04006757 },
Johannes Berg29cbe682010-12-03 09:20:44 +01006758 {
6759 .cmd = NL80211_CMD_JOIN_MESH,
6760 .doit = nl80211_join_mesh,
6761 .policy = nl80211_policy,
6762 .flags = GENL_ADMIN_PERM,
6763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6764 NL80211_FLAG_NEED_RTNL,
6765 },
6766 {
6767 .cmd = NL80211_CMD_LEAVE_MESH,
6768 .doit = nl80211_leave_mesh,
6769 .policy = nl80211_policy,
6770 .flags = GENL_ADMIN_PERM,
6771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6772 NL80211_FLAG_NEED_RTNL,
6773 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02006774 {
6775 .cmd = NL80211_CMD_GET_WOWLAN,
6776 .doit = nl80211_get_wowlan,
6777 .policy = nl80211_policy,
6778 /* can be retrieved by unprivileged users */
6779 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6780 NL80211_FLAG_NEED_RTNL,
6781 },
6782 {
6783 .cmd = NL80211_CMD_SET_WOWLAN,
6784 .doit = nl80211_set_wowlan,
6785 .policy = nl80211_policy,
6786 .flags = GENL_ADMIN_PERM,
6787 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6788 NL80211_FLAG_NEED_RTNL,
6789 },
Johannes Berge5497d72011-07-05 16:35:40 +02006790 {
6791 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6792 .doit = nl80211_set_rekey_data,
6793 .policy = nl80211_policy,
6794 .flags = GENL_ADMIN_PERM,
6795 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6796 NL80211_FLAG_NEED_RTNL,
6797 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03006798 {
6799 .cmd = NL80211_CMD_TDLS_MGMT,
6800 .doit = nl80211_tdls_mgmt,
6801 .policy = nl80211_policy,
6802 .flags = GENL_ADMIN_PERM,
6803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6804 NL80211_FLAG_NEED_RTNL,
6805 },
6806 {
6807 .cmd = NL80211_CMD_TDLS_OPER,
6808 .doit = nl80211_tdls_oper,
6809 .policy = nl80211_policy,
6810 .flags = GENL_ADMIN_PERM,
6811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6812 NL80211_FLAG_NEED_RTNL,
6813 },
Johannes Berg28946da2011-11-04 11:18:12 +01006814 {
6815 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6816 .doit = nl80211_register_unexpected_frame,
6817 .policy = nl80211_policy,
6818 .flags = GENL_ADMIN_PERM,
6819 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6820 NL80211_FLAG_NEED_RTNL,
6821 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01006822 {
6823 .cmd = NL80211_CMD_PROBE_CLIENT,
6824 .doit = nl80211_probe_client,
6825 .policy = nl80211_policy,
6826 .flags = GENL_ADMIN_PERM,
6827 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6828 NL80211_FLAG_NEED_RTNL,
6829 },
Johannes Berg5e760232011-11-04 11:18:17 +01006830 {
6831 .cmd = NL80211_CMD_REGISTER_BEACONS,
6832 .doit = nl80211_register_beacons,
6833 .policy = nl80211_policy,
6834 .flags = GENL_ADMIN_PERM,
6835 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6836 NL80211_FLAG_NEED_RTNL,
6837 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01006838 {
6839 .cmd = NL80211_CMD_SET_NOACK_MAP,
6840 .doit = nl80211_set_noack_map,
6841 .policy = nl80211_policy,
6842 .flags = GENL_ADMIN_PERM,
6843 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6844 NL80211_FLAG_NEED_RTNL,
6845 },
6846
Johannes Berg55682962007-09-20 13:09:35 -04006847};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006848
Jouni Malinen6039f6d2009-03-19 13:39:21 +02006849static struct genl_multicast_group nl80211_mlme_mcgrp = {
6850 .name = "mlme",
6851};
Johannes Berg55682962007-09-20 13:09:35 -04006852
6853/* multicast groups */
6854static struct genl_multicast_group nl80211_config_mcgrp = {
6855 .name = "config",
6856};
Johannes Berg2a519312009-02-10 21:25:55 +01006857static struct genl_multicast_group nl80211_scan_mcgrp = {
6858 .name = "scan",
6859};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04006860static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6861 .name = "regulatory",
6862};
Johannes Berg55682962007-09-20 13:09:35 -04006863
6864/* notification functions */
6865
6866void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6867{
6868 struct sk_buff *msg;
6869
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006870 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006871 if (!msg)
6872 return;
6873
6874 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6875 nlmsg_free(msg);
6876 return;
6877 }
6878
Johannes Berg463d0182009-07-14 00:33:35 +02006879 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6880 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04006881}
6882
Johannes Berg362a4152009-05-24 16:43:15 +02006883static int nl80211_add_scan_req(struct sk_buff *msg,
6884 struct cfg80211_registered_device *rdev)
6885{
6886 struct cfg80211_scan_request *req = rdev->scan_req;
6887 struct nlattr *nest;
6888 int i;
6889
Johannes Berg667503dd2009-07-07 03:56:11 +02006890 ASSERT_RDEV_LOCK(rdev);
6891
Johannes Berg362a4152009-05-24 16:43:15 +02006892 if (WARN_ON(!req))
6893 return 0;
6894
6895 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6896 if (!nest)
6897 goto nla_put_failure;
6898 for (i = 0; i < req->n_ssids; i++)
6899 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6900 nla_nest_end(msg, nest);
6901
6902 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6903 if (!nest)
6904 goto nla_put_failure;
6905 for (i = 0; i < req->n_channels; i++)
6906 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6907 nla_nest_end(msg, nest);
6908
6909 if (req->ie)
6910 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6911
6912 return 0;
6913 nla_put_failure:
6914 return -ENOBUFS;
6915}
6916
Johannes Berga538e2d2009-06-16 19:56:42 +02006917static int nl80211_send_scan_msg(struct sk_buff *msg,
6918 struct cfg80211_registered_device *rdev,
6919 struct net_device *netdev,
6920 u32 pid, u32 seq, int flags,
6921 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01006922{
6923 void *hdr;
6924
6925 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6926 if (!hdr)
6927 return -1;
6928
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05006929 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01006930 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6931
Johannes Berg362a4152009-05-24 16:43:15 +02006932 /* ignore errors and send incomplete event anyway */
6933 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006934
6935 return genlmsg_end(msg, hdr);
6936
6937 nla_put_failure:
6938 genlmsg_cancel(msg, hdr);
6939 return -EMSGSIZE;
6940}
6941
Luciano Coelho807f8a82011-05-11 17:09:35 +03006942static int
6943nl80211_send_sched_scan_msg(struct sk_buff *msg,
6944 struct cfg80211_registered_device *rdev,
6945 struct net_device *netdev,
6946 u32 pid, u32 seq, int flags, u32 cmd)
6947{
6948 void *hdr;
6949
6950 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6951 if (!hdr)
6952 return -1;
6953
6954 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6955 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6956
6957 return genlmsg_end(msg, hdr);
6958
6959 nla_put_failure:
6960 genlmsg_cancel(msg, hdr);
6961 return -EMSGSIZE;
6962}
6963
Johannes Berga538e2d2009-06-16 19:56:42 +02006964void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6965 struct net_device *netdev)
6966{
6967 struct sk_buff *msg;
6968
6969 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6970 if (!msg)
6971 return;
6972
6973 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6974 NL80211_CMD_TRIGGER_SCAN) < 0) {
6975 nlmsg_free(msg);
6976 return;
6977 }
6978
Johannes Berg463d0182009-07-14 00:33:35 +02006979 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6980 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02006981}
6982
Johannes Berg2a519312009-02-10 21:25:55 +01006983void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6984 struct net_device *netdev)
6985{
6986 struct sk_buff *msg;
6987
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01006989 if (!msg)
6990 return;
6991
Johannes Berga538e2d2009-06-16 19:56:42 +02006992 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6993 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006994 nlmsg_free(msg);
6995 return;
6996 }
6997
Johannes Berg463d0182009-07-14 00:33:35 +02006998 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6999 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007000}
7001
7002void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7003 struct net_device *netdev)
7004{
7005 struct sk_buff *msg;
7006
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007007 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007008 if (!msg)
7009 return;
7010
Johannes Berga538e2d2009-06-16 19:56:42 +02007011 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7012 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007013 nlmsg_free(msg);
7014 return;
7015 }
7016
Johannes Berg463d0182009-07-14 00:33:35 +02007017 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7018 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007019}
7020
Luciano Coelho807f8a82011-05-11 17:09:35 +03007021void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7022 struct net_device *netdev)
7023{
7024 struct sk_buff *msg;
7025
7026 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7027 if (!msg)
7028 return;
7029
7030 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7031 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7032 nlmsg_free(msg);
7033 return;
7034 }
7035
7036 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7037 nl80211_scan_mcgrp.id, GFP_KERNEL);
7038}
7039
7040void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7041 struct net_device *netdev, u32 cmd)
7042{
7043 struct sk_buff *msg;
7044
7045 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7046 if (!msg)
7047 return;
7048
7049 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7050 nlmsg_free(msg);
7051 return;
7052 }
7053
7054 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7055 nl80211_scan_mcgrp.id, GFP_KERNEL);
7056}
7057
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007058/*
7059 * This can happen on global regulatory changes or device specific settings
7060 * based on custom world regulatory domains.
7061 */
7062void nl80211_send_reg_change_event(struct regulatory_request *request)
7063{
7064 struct sk_buff *msg;
7065 void *hdr;
7066
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007067 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007068 if (!msg)
7069 return;
7070
7071 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7072 if (!hdr) {
7073 nlmsg_free(msg);
7074 return;
7075 }
7076
7077 /* Userspace can always count this one always being set */
7078 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
7079
7080 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
7081 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7082 NL80211_REGDOM_TYPE_WORLD);
7083 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
7084 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7085 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
7086 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7087 request->intersect)
7088 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7089 NL80211_REGDOM_TYPE_INTERSECTION);
7090 else {
7091 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
7092 NL80211_REGDOM_TYPE_COUNTRY);
7093 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
7094 }
7095
7096 if (wiphy_idx_valid(request->wiphy_idx))
7097 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
7098
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007099 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007100
Johannes Bergbc43b282009-07-25 10:54:13 +02007101 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007102 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007103 GFP_ATOMIC);
7104 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007105
7106 return;
7107
7108nla_put_failure:
7109 genlmsg_cancel(msg, hdr);
7110 nlmsg_free(msg);
7111}
7112
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007113static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7114 struct net_device *netdev,
7115 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007116 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007117{
7118 struct sk_buff *msg;
7119 void *hdr;
7120
Johannes Berge6d6e342009-07-01 21:26:47 +02007121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007122 if (!msg)
7123 return;
7124
7125 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7126 if (!hdr) {
7127 nlmsg_free(msg);
7128 return;
7129 }
7130
7131 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7132 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7133 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7134
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007135 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007136
Johannes Berg463d0182009-07-14 00:33:35 +02007137 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7138 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007139 return;
7140
7141 nla_put_failure:
7142 genlmsg_cancel(msg, hdr);
7143 nlmsg_free(msg);
7144}
7145
7146void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007147 struct net_device *netdev, const u8 *buf,
7148 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007149{
7150 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007151 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007152}
7153
7154void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7155 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007156 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007157{
Johannes Berge6d6e342009-07-01 21:26:47 +02007158 nl80211_send_mlme_event(rdev, netdev, buf, len,
7159 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007160}
7161
Jouni Malinen53b46b82009-03-27 20:53:56 +02007162void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007163 struct net_device *netdev, const u8 *buf,
7164 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007165{
7166 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007167 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007168}
7169
Jouni Malinen53b46b82009-03-27 20:53:56 +02007170void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7171 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007172 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007173{
7174 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007175 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007176}
7177
Jouni Malinencf4e5942010-12-16 00:52:40 +02007178void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7179 struct net_device *netdev, const u8 *buf,
7180 size_t len, gfp_t gfp)
7181{
7182 nl80211_send_mlme_event(rdev, netdev, buf, len,
7183 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7184}
7185
7186void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7187 struct net_device *netdev, const u8 *buf,
7188 size_t len, gfp_t gfp)
7189{
7190 nl80211_send_mlme_event(rdev, netdev, buf, len,
7191 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7192}
7193
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007194static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7195 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007196 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007197{
7198 struct sk_buff *msg;
7199 void *hdr;
7200
Johannes Berge6d6e342009-07-01 21:26:47 +02007201 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007202 if (!msg)
7203 return;
7204
7205 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7206 if (!hdr) {
7207 nlmsg_free(msg);
7208 return;
7209 }
7210
7211 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7212 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7213 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
7214 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7215
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007216 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007217
Johannes Berg463d0182009-07-14 00:33:35 +02007218 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7219 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007220 return;
7221
7222 nla_put_failure:
7223 genlmsg_cancel(msg, hdr);
7224 nlmsg_free(msg);
7225}
7226
7227void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007228 struct net_device *netdev, const u8 *addr,
7229 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007230{
7231 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007232 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007233}
7234
7235void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007236 struct net_device *netdev, const u8 *addr,
7237 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007238{
Johannes Berge6d6e342009-07-01 21:26:47 +02007239 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7240 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007241}
7242
Samuel Ortizb23aa672009-07-01 21:26:54 +02007243void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7244 struct net_device *netdev, const u8 *bssid,
7245 const u8 *req_ie, size_t req_ie_len,
7246 const u8 *resp_ie, size_t resp_ie_len,
7247 u16 status, gfp_t gfp)
7248{
7249 struct sk_buff *msg;
7250 void *hdr;
7251
7252 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7253 if (!msg)
7254 return;
7255
7256 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7257 if (!hdr) {
7258 nlmsg_free(msg);
7259 return;
7260 }
7261
7262 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7263 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7264 if (bssid)
7265 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7266 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
7267 if (req_ie)
7268 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7269 if (resp_ie)
7270 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7271
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007272 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007273
Johannes Berg463d0182009-07-14 00:33:35 +02007274 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7275 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007276 return;
7277
7278 nla_put_failure:
7279 genlmsg_cancel(msg, hdr);
7280 nlmsg_free(msg);
7281
7282}
7283
7284void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7285 struct net_device *netdev, const u8 *bssid,
7286 const u8 *req_ie, size_t req_ie_len,
7287 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7288{
7289 struct sk_buff *msg;
7290 void *hdr;
7291
7292 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7293 if (!msg)
7294 return;
7295
7296 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7297 if (!hdr) {
7298 nlmsg_free(msg);
7299 return;
7300 }
7301
7302 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7303 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7304 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7305 if (req_ie)
7306 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7307 if (resp_ie)
7308 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7309
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007310 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007311
Johannes Berg463d0182009-07-14 00:33:35 +02007312 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7313 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007314 return;
7315
7316 nla_put_failure:
7317 genlmsg_cancel(msg, hdr);
7318 nlmsg_free(msg);
7319
7320}
7321
7322void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7323 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007324 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007325{
7326 struct sk_buff *msg;
7327 void *hdr;
7328
Johannes Berg667503dd2009-07-07 03:56:11 +02007329 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007330 if (!msg)
7331 return;
7332
7333 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7334 if (!hdr) {
7335 nlmsg_free(msg);
7336 return;
7337 }
7338
7339 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7340 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7341 if (from_ap && reason)
7342 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
7343 if (from_ap)
7344 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
7345 if (ie)
7346 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
7347
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007348 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007349
Johannes Berg463d0182009-07-14 00:33:35 +02007350 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7351 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007352 return;
7353
7354 nla_put_failure:
7355 genlmsg_cancel(msg, hdr);
7356 nlmsg_free(msg);
7357
7358}
7359
Johannes Berg04a773a2009-04-19 21:24:32 +02007360void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7361 struct net_device *netdev, const u8 *bssid,
7362 gfp_t gfp)
7363{
7364 struct sk_buff *msg;
7365 void *hdr;
7366
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007367 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007368 if (!msg)
7369 return;
7370
7371 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7372 if (!hdr) {
7373 nlmsg_free(msg);
7374 return;
7375 }
7376
7377 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7378 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7379 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7380
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007381 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007382
Johannes Berg463d0182009-07-14 00:33:35 +02007383 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7384 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007385 return;
7386
7387 nla_put_failure:
7388 genlmsg_cancel(msg, hdr);
7389 nlmsg_free(msg);
7390}
7391
Javier Cardonac93b5e72011-04-07 15:08:34 -07007392void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7393 struct net_device *netdev,
7394 const u8 *macaddr, const u8* ie, u8 ie_len,
7395 gfp_t gfp)
7396{
7397 struct sk_buff *msg;
7398 void *hdr;
7399
7400 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7401 if (!msg)
7402 return;
7403
7404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_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 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
7413 if (ie_len && ie)
7414 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
7415
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007416 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007417
7418 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7419 nl80211_mlme_mcgrp.id, gfp);
7420 return;
7421
7422 nla_put_failure:
7423 genlmsg_cancel(msg, hdr);
7424 nlmsg_free(msg);
7425}
7426
Jouni Malinena3b8b052009-03-27 21:59:49 +02007427void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7428 struct net_device *netdev, const u8 *addr,
7429 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007430 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007431{
7432 struct sk_buff *msg;
7433 void *hdr;
7434
Johannes Berge6d6e342009-07-01 21:26:47 +02007435 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007436 if (!msg)
7437 return;
7438
7439 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7440 if (!hdr) {
7441 nlmsg_free(msg);
7442 return;
7443 }
7444
7445 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7446 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7447 if (addr)
7448 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7449 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
Arik Nemtsova66b98d2011-06-23 00:00:24 +03007450 if (key_id != -1)
7451 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007452 if (tsc)
7453 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7454
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007455 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007456
Johannes Berg463d0182009-07-14 00:33:35 +02007457 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7458 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007459 return;
7460
7461 nla_put_failure:
7462 genlmsg_cancel(msg, hdr);
7463 nlmsg_free(msg);
7464}
7465
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007466void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7467 struct ieee80211_channel *channel_before,
7468 struct ieee80211_channel *channel_after)
7469{
7470 struct sk_buff *msg;
7471 void *hdr;
7472 struct nlattr *nl_freq;
7473
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007474 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007475 if (!msg)
7476 return;
7477
7478 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7479 if (!hdr) {
7480 nlmsg_free(msg);
7481 return;
7482 }
7483
7484 /*
7485 * Since we are applying the beacon hint to a wiphy we know its
7486 * wiphy_idx is valid
7487 */
7488 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7489
7490 /* Before */
7491 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7492 if (!nl_freq)
7493 goto nla_put_failure;
7494 if (nl80211_msg_put_channel(msg, channel_before))
7495 goto nla_put_failure;
7496 nla_nest_end(msg, nl_freq);
7497
7498 /* After */
7499 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7500 if (!nl_freq)
7501 goto nla_put_failure;
7502 if (nl80211_msg_put_channel(msg, channel_after))
7503 goto nla_put_failure;
7504 nla_nest_end(msg, nl_freq);
7505
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007506 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007507
Johannes Berg463d0182009-07-14 00:33:35 +02007508 rcu_read_lock();
7509 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7510 GFP_ATOMIC);
7511 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007512
7513 return;
7514
7515nla_put_failure:
7516 genlmsg_cancel(msg, hdr);
7517 nlmsg_free(msg);
7518}
7519
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007520static void nl80211_send_remain_on_chan_event(
7521 int cmd, struct cfg80211_registered_device *rdev,
7522 struct net_device *netdev, u64 cookie,
7523 struct ieee80211_channel *chan,
7524 enum nl80211_channel_type channel_type,
7525 unsigned int duration, gfp_t gfp)
7526{
7527 struct sk_buff *msg;
7528 void *hdr;
7529
7530 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7531 if (!msg)
7532 return;
7533
7534 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7535 if (!hdr) {
7536 nlmsg_free(msg);
7537 return;
7538 }
7539
7540 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7541 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7542 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7543 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7544 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7545
7546 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7547 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7548
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007549 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007550
7551 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7552 nl80211_mlme_mcgrp.id, gfp);
7553 return;
7554
7555 nla_put_failure:
7556 genlmsg_cancel(msg, hdr);
7557 nlmsg_free(msg);
7558}
7559
7560void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7561 struct net_device *netdev, u64 cookie,
7562 struct ieee80211_channel *chan,
7563 enum nl80211_channel_type channel_type,
7564 unsigned int duration, gfp_t gfp)
7565{
7566 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7567 rdev, netdev, cookie, chan,
7568 channel_type, duration, gfp);
7569}
7570
7571void nl80211_send_remain_on_channel_cancel(
7572 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7573 u64 cookie, struct ieee80211_channel *chan,
7574 enum nl80211_channel_type channel_type, gfp_t gfp)
7575{
7576 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7577 rdev, netdev, cookie, chan,
7578 channel_type, 0, gfp);
7579}
7580
Johannes Berg98b62182009-12-23 13:15:44 +01007581void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7582 struct net_device *dev, const u8 *mac_addr,
7583 struct station_info *sinfo, gfp_t gfp)
7584{
7585 struct sk_buff *msg;
7586
7587 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7588 if (!msg)
7589 return;
7590
7591 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
7592 nlmsg_free(msg);
7593 return;
7594 }
7595
7596 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7597 nl80211_mlme_mcgrp.id, gfp);
7598}
7599
Jouni Malinenec15e682011-03-23 15:29:52 +02007600void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7601 struct net_device *dev, const u8 *mac_addr,
7602 gfp_t gfp)
7603{
7604 struct sk_buff *msg;
7605 void *hdr;
7606
7607 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7608 if (!msg)
7609 return;
7610
7611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7612 if (!hdr) {
7613 nlmsg_free(msg);
7614 return;
7615 }
7616
7617 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7618 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7619
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007620 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02007621
7622 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7623 nl80211_mlme_mcgrp.id, gfp);
7624 return;
7625
7626 nla_put_failure:
7627 genlmsg_cancel(msg, hdr);
7628 nlmsg_free(msg);
7629}
7630
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007631static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
7632 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01007633{
7634 struct wireless_dev *wdev = dev->ieee80211_ptr;
7635 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7636 struct sk_buff *msg;
7637 void *hdr;
7638 int err;
7639 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7640
7641 if (!nlpid)
7642 return false;
7643
7644 msg = nlmsg_new(100, gfp);
7645 if (!msg)
7646 return true;
7647
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007648 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01007649 if (!hdr) {
7650 nlmsg_free(msg);
7651 return true;
7652 }
7653
7654 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7655 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7656 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7657
7658 err = genlmsg_end(msg, hdr);
7659 if (err < 0) {
7660 nlmsg_free(msg);
7661 return true;
7662 }
7663
7664 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7665 return true;
7666
7667 nla_put_failure:
7668 genlmsg_cancel(msg, hdr);
7669 nlmsg_free(msg);
7670 return true;
7671}
7672
Johannes Bergb92ab5d2011-11-04 11:18:19 +01007673bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7674{
7675 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
7676 addr, gfp);
7677}
7678
7679bool nl80211_unexpected_4addr_frame(struct net_device *dev,
7680 const u8 *addr, gfp_t gfp)
7681{
7682 return __nl80211_unexpected_frame(dev,
7683 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
7684 addr, gfp);
7685}
7686
Johannes Berg2e161f72010-08-12 15:38:38 +02007687int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7688 struct net_device *netdev, u32 nlpid,
7689 int freq, const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007690{
7691 struct sk_buff *msg;
7692 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02007693
7694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7695 if (!msg)
7696 return -ENOMEM;
7697
Johannes Berg2e161f72010-08-12 15:38:38 +02007698 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007699 if (!hdr) {
7700 nlmsg_free(msg);
7701 return -ENOMEM;
7702 }
7703
7704 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7705 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7706 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7707 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7708
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007709 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007710
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007711 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02007712
7713 nla_put_failure:
7714 genlmsg_cancel(msg, hdr);
7715 nlmsg_free(msg);
7716 return -ENOBUFS;
7717}
7718
Johannes Berg2e161f72010-08-12 15:38:38 +02007719void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7720 struct net_device *netdev, u64 cookie,
7721 const u8 *buf, size_t len, bool ack,
7722 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02007723{
7724 struct sk_buff *msg;
7725 void *hdr;
7726
7727 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7728 if (!msg)
7729 return;
7730
Johannes Berg2e161f72010-08-12 15:38:38 +02007731 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02007732 if (!hdr) {
7733 nlmsg_free(msg);
7734 return;
7735 }
7736
7737 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7738 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7739 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7740 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7741 if (ack)
7742 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7743
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007744 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02007745
7746 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7747 return;
7748
7749 nla_put_failure:
7750 genlmsg_cancel(msg, hdr);
7751 nlmsg_free(msg);
7752}
7753
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007754void
7755nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7756 struct net_device *netdev,
7757 enum nl80211_cqm_rssi_threshold_event rssi_event,
7758 gfp_t gfp)
7759{
7760 struct sk_buff *msg;
7761 struct nlattr *pinfoattr;
7762 void *hdr;
7763
7764 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7765 if (!msg)
7766 return;
7767
7768 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7769 if (!hdr) {
7770 nlmsg_free(msg);
7771 return;
7772 }
7773
7774 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7775 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7776
7777 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7778 if (!pinfoattr)
7779 goto nla_put_failure;
7780
7781 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7782 rssi_event);
7783
7784 nla_nest_end(msg, pinfoattr);
7785
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007786 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007787
7788 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7789 nl80211_mlme_mcgrp.id, gfp);
7790 return;
7791
7792 nla_put_failure:
7793 genlmsg_cancel(msg, hdr);
7794 nlmsg_free(msg);
7795}
7796
Johannes Berge5497d72011-07-05 16:35:40 +02007797void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7798 struct net_device *netdev, const u8 *bssid,
7799 const u8 *replay_ctr, gfp_t gfp)
7800{
7801 struct sk_buff *msg;
7802 struct nlattr *rekey_attr;
7803 void *hdr;
7804
7805 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7806 if (!msg)
7807 return;
7808
7809 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7810 if (!hdr) {
7811 nlmsg_free(msg);
7812 return;
7813 }
7814
7815 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7816 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7817 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7818
7819 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7820 if (!rekey_attr)
7821 goto nla_put_failure;
7822
7823 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7824 NL80211_REPLAY_CTR_LEN, replay_ctr);
7825
7826 nla_nest_end(msg, rekey_attr);
7827
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007828 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02007829
7830 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7831 nl80211_mlme_mcgrp.id, gfp);
7832 return;
7833
7834 nla_put_failure:
7835 genlmsg_cancel(msg, hdr);
7836 nlmsg_free(msg);
7837}
7838
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007839void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7840 struct net_device *netdev, int index,
7841 const u8 *bssid, bool preauth, gfp_t gfp)
7842{
7843 struct sk_buff *msg;
7844 struct nlattr *attr;
7845 void *hdr;
7846
7847 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7848 if (!msg)
7849 return;
7850
7851 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7852 if (!hdr) {
7853 nlmsg_free(msg);
7854 return;
7855 }
7856
7857 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7858 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7859
7860 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7861 if (!attr)
7862 goto nla_put_failure;
7863
7864 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7865 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7866 if (preauth)
7867 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7868
7869 nla_nest_end(msg, attr);
7870
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007871 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03007872
7873 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7874 nl80211_mlme_mcgrp.id, gfp);
7875 return;
7876
7877 nla_put_failure:
7878 genlmsg_cancel(msg, hdr);
7879 nlmsg_free(msg);
7880}
7881
Johannes Bergc063dbf2010-11-24 08:10:05 +01007882void
7883nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7884 struct net_device *netdev, const u8 *peer,
7885 u32 num_packets, gfp_t gfp)
7886{
7887 struct sk_buff *msg;
7888 struct nlattr *pinfoattr;
7889 void *hdr;
7890
7891 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7892 if (!msg)
7893 return;
7894
7895 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7896 if (!hdr) {
7897 nlmsg_free(msg);
7898 return;
7899 }
7900
7901 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7902 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7903 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7904
7905 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7906 if (!pinfoattr)
7907 goto nla_put_failure;
7908
7909 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7910
7911 nla_nest_end(msg, pinfoattr);
7912
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007913 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01007914
7915 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7916 nl80211_mlme_mcgrp.id, gfp);
7917 return;
7918
7919 nla_put_failure:
7920 genlmsg_cancel(msg, hdr);
7921 nlmsg_free(msg);
7922}
7923
Johannes Berg7f6cf312011-11-04 11:18:15 +01007924void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
7925 u64 cookie, bool acked, gfp_t gfp)
7926{
7927 struct wireless_dev *wdev = dev->ieee80211_ptr;
7928 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7929 struct sk_buff *msg;
7930 void *hdr;
7931 int err;
7932
7933 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7934 if (!msg)
7935 return;
7936
7937 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
7938 if (!hdr) {
7939 nlmsg_free(msg);
7940 return;
7941 }
7942
7943 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7944 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7945 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7946 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7947 if (acked)
7948 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7949
7950 err = genlmsg_end(msg, hdr);
7951 if (err < 0) {
7952 nlmsg_free(msg);
7953 return;
7954 }
7955
7956 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7957 nl80211_mlme_mcgrp.id, gfp);
7958 return;
7959
7960 nla_put_failure:
7961 genlmsg_cancel(msg, hdr);
7962 nlmsg_free(msg);
7963}
7964EXPORT_SYMBOL(cfg80211_probe_status);
7965
Johannes Berg5e760232011-11-04 11:18:17 +01007966void cfg80211_report_obss_beacon(struct wiphy *wiphy,
7967 const u8 *frame, size_t len,
7968 int freq, gfp_t gfp)
7969{
7970 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
7971 struct sk_buff *msg;
7972 void *hdr;
7973 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
7974
7975 if (!nlpid)
7976 return;
7977
7978 msg = nlmsg_new(len + 100, gfp);
7979 if (!msg)
7980 return;
7981
7982 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
7983 if (!hdr) {
7984 nlmsg_free(msg);
7985 return;
7986 }
7987
7988 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7989 if (freq)
7990 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7991 NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
7992
7993 genlmsg_end(msg, hdr);
7994
7995 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7996 return;
7997
7998 nla_put_failure:
7999 genlmsg_cancel(msg, hdr);
8000 nlmsg_free(msg);
8001}
8002EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8003
Jouni Malinen026331c2010-02-15 12:53:10 +02008004static int nl80211_netlink_notify(struct notifier_block * nb,
8005 unsigned long state,
8006 void *_notify)
8007{
8008 struct netlink_notify *notify = _notify;
8009 struct cfg80211_registered_device *rdev;
8010 struct wireless_dev *wdev;
8011
8012 if (state != NETLINK_URELEASE)
8013 return NOTIFY_DONE;
8014
8015 rcu_read_lock();
8016
Johannes Berg5e760232011-11-04 11:18:17 +01008017 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008018 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008019 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008020 if (rdev->ap_beacons_nlpid == notify->pid)
8021 rdev->ap_beacons_nlpid = 0;
8022 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008023
8024 rcu_read_unlock();
8025
8026 return NOTIFY_DONE;
8027}
8028
8029static struct notifier_block nl80211_netlink_notifier = {
8030 .notifier_call = nl80211_netlink_notify,
8031};
8032
Johannes Berg55682962007-09-20 13:09:35 -04008033/* initialisation/exit functions */
8034
8035int nl80211_init(void)
8036{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008037 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008038
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008039 err = genl_register_family_with_ops(&nl80211_fam,
8040 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008041 if (err)
8042 return err;
8043
Johannes Berg55682962007-09-20 13:09:35 -04008044 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8045 if (err)
8046 goto err_out;
8047
Johannes Berg2a519312009-02-10 21:25:55 +01008048 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8049 if (err)
8050 goto err_out;
8051
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008052 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8053 if (err)
8054 goto err_out;
8055
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008056 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8057 if (err)
8058 goto err_out;
8059
Johannes Bergaff89a92009-07-01 21:26:51 +02008060#ifdef CONFIG_NL80211_TESTMODE
8061 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8062 if (err)
8063 goto err_out;
8064#endif
8065
Jouni Malinen026331c2010-02-15 12:53:10 +02008066 err = netlink_register_notifier(&nl80211_netlink_notifier);
8067 if (err)
8068 goto err_out;
8069
Johannes Berg55682962007-09-20 13:09:35 -04008070 return 0;
8071 err_out:
8072 genl_unregister_family(&nl80211_fam);
8073 return err;
8074}
8075
8076void nl80211_exit(void)
8077{
Jouni Malinen026331c2010-02-15 12:53:10 +02008078 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008079 genl_unregister_family(&nl80211_fam);
8080}