blob: 5c4a720f04426e3c8a635c730927910048429fdf [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
Johannes Berga9455402012-06-15 13:32:49 +020073static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +020074__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +020075{
Johannes Berg7fee4772012-06-15 14:09:58 +020076 struct cfg80211_registered_device *rdev = NULL, *tmp;
77 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +020078
79 assert_cfg80211_lock();
80
Johannes Berg878d9ec2012-06-15 14:18:32 +020081 if (!attrs[NL80211_ATTR_WIPHY] &&
82 !attrs[NL80211_ATTR_IFINDEX])
Johannes Berg7fee4772012-06-15 14:09:58 +020083 return ERR_PTR(-EINVAL);
84
Johannes Berg878d9ec2012-06-15 14:18:32 +020085 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +020086 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +020087 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +020088
Johannes Berg878d9ec2012-06-15 14:18:32 +020089 if (attrs[NL80211_ATTR_IFINDEX]) {
90 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +020091 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +020092 if (netdev) {
93 if (netdev->ieee80211_ptr)
94 tmp = wiphy_to_dev(
95 netdev->ieee80211_ptr->wiphy);
96 else
97 tmp = NULL;
98
99 dev_put(netdev);
100
101 /* not wireless device -- return error */
102 if (!tmp)
103 return ERR_PTR(-EINVAL);
104
105 /* mismatch -- return error */
106 if (rdev && tmp != rdev)
107 return ERR_PTR(-EINVAL);
108
109 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200110 }
Johannes Berga9455402012-06-15 13:32:49 +0200111 }
112
Johannes Berg4f7eff12012-06-15 14:14:22 +0200113 if (!rdev)
114 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200115
Johannes Berg4f7eff12012-06-15 14:14:22 +0200116 if (netns != wiphy_net(&rdev->wiphy))
117 return ERR_PTR(-ENODEV);
118
119 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120}
121
122/*
123 * This function returns a pointer to the driver
124 * that the genl_info item that is passed refers to.
125 * If successful, it returns non-NULL and also locks
126 * the driver's mutex!
127 *
128 * This means that you need to call cfg80211_unlock_rdev()
129 * before being allowed to acquire &cfg80211_mutex!
130 *
131 * This is necessary because we need to lock the global
132 * mutex to get an item off the list safely, and then
133 * we lock the rdev mutex so it doesn't go away under us.
134 *
135 * We don't want to keep cfg80211_mutex locked
136 * for all the time in order to allow requests on
137 * other interfaces to go through at the same time.
138 *
139 * The result of this can be a PTR_ERR and hence must
140 * be checked with IS_ERR() for errors.
141 */
142static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200143cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200144{
145 struct cfg80211_registered_device *rdev;
146
147 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200148 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200149
150 /* if it is not an error we grab the lock on
151 * it to assure it won't be going away while
152 * we operate on it */
153 if (!IS_ERR(rdev))
154 mutex_lock(&rdev->mtx);
155
156 mutex_unlock(&cfg80211_mutex);
157
158 return rdev;
159}
160
Johannes Berg55682962007-09-20 13:09:35 -0400161/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000162static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400163 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
164 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700165 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200166 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200167 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530168 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200169 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
170 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
171 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
172 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100173 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400174
175 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
176 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
177 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100178
Eliad Pellere007b852011-11-24 18:13:56 +0200179 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
180 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100181
Johannes Bergb9454e82009-07-08 13:29:08 +0200182 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100183 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
184 .len = WLAN_MAX_KEY_LEN },
185 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
186 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
187 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200188 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200189 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100190
191 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
192 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
193 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
194 .len = IEEE80211_MAX_DATA_LEN },
195 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
196 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100197 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
198 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
199 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
200 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
201 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100202 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100203 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200204 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100205 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800206 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100207 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300208
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700209 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
210 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
211
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300212 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
213 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
214 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200215 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
216 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100217 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300218
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800219 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700220 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700221
Johannes Berg6c739412011-11-03 09:27:01 +0100222 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200223
224 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
225 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
226 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100227 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
228 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200229
230 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_SSID_LEN },
232 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200234 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300235 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300236 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300237 [NL80211_ATTR_STA_FLAGS2] = {
238 .len = sizeof(struct nl80211_sta_flag_update),
239 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300240 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300241 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
242 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200243 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
244 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
245 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200246 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100247 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100248 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
249 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100250 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
251 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200252 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200253 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
255 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200256 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200257 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300258 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200259 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300260 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
261 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200262 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900263 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
264 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100265 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100266 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100267 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200268 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700269 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300270 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200271 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200272 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300273 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300274 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
275 .len = IEEE80211_MAX_DATA_LEN },
276 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530278 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300279 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530280 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300281 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
282 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
283 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
284 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
285 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100286 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200287 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700289 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800290 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
291 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
292 .len = NL80211_HT_CAPABILITY_LEN
293 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100294 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530295 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530296 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400297};
298
Johannes Berge31b8212010-10-05 19:39:30 +0200299/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000300static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200301 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200302 [NL80211_KEY_IDX] = { .type = NLA_U8 },
303 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200304 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200305 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
306 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200307 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100308 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
309};
310
311/* policy for the key default flags */
312static const struct nla_policy
313nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
314 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
315 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200316};
317
Johannes Bergff1b6e62011-05-04 15:37:28 +0200318/* policy for WoWLAN attributes */
319static const struct nla_policy
320nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
321 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
322 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
323 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
324 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200325 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
326 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
327 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
328 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200329};
330
Johannes Berge5497d72011-07-05 16:35:40 +0200331/* policy for GTK rekey offload attributes */
332static const struct nla_policy
333nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
334 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
335 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
336 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
337};
338
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300339static const struct nla_policy
340nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200341 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300342 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700343 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344};
345
Holger Schuriga0438972009-11-11 11:30:02 +0100346/* ifidx get helper */
347static int nl80211_get_ifidx(struct netlink_callback *cb)
348{
349 int res;
350
351 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
352 nl80211_fam.attrbuf, nl80211_fam.maxattr,
353 nl80211_policy);
354 if (res)
355 return res;
356
357 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
358 return -EINVAL;
359
360 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
361 if (!res)
362 return -EINVAL;
363 return res;
364}
365
Johannes Berg67748892010-10-04 21:14:06 +0200366static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
367 struct netlink_callback *cb,
368 struct cfg80211_registered_device **rdev,
369 struct net_device **dev)
370{
371 int ifidx = cb->args[0];
372 int err;
373
374 if (!ifidx)
375 ifidx = nl80211_get_ifidx(cb);
376 if (ifidx < 0)
377 return ifidx;
378
379 cb->args[0] = ifidx;
380
381 rtnl_lock();
382
383 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
384 if (!*dev) {
385 err = -ENODEV;
386 goto out_rtnl;
387 }
388
389 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100390 if (IS_ERR(*rdev)) {
391 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200392 goto out_rtnl;
393 }
394
395 return 0;
396 out_rtnl:
397 rtnl_unlock();
398 return err;
399}
400
401static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
402{
403 cfg80211_unlock_rdev(rdev);
404 rtnl_unlock();
405}
406
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100407/* IE validation */
408static bool is_valid_ie_attr(const struct nlattr *attr)
409{
410 const u8 *pos;
411 int len;
412
413 if (!attr)
414 return true;
415
416 pos = nla_data(attr);
417 len = nla_len(attr);
418
419 while (len) {
420 u8 elemlen;
421
422 if (len < 2)
423 return false;
424 len -= 2;
425
426 elemlen = pos[1];
427 if (elemlen > len)
428 return false;
429
430 len -= elemlen;
431 pos += 2 + elemlen;
432 }
433
434 return true;
435}
436
Johannes Berg55682962007-09-20 13:09:35 -0400437/* message building helper */
438static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
439 int flags, u8 cmd)
440{
441 /* since there is no private header just add the generic one */
442 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
443}
444
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400445static int nl80211_msg_put_channel(struct sk_buff *msg,
446 struct ieee80211_channel *chan)
447{
David S. Miller9360ffd2012-03-29 04:41:26 -0400448 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
449 chan->center_freq))
450 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400451
David S. Miller9360ffd2012-03-29 04:41:26 -0400452 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
453 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
454 goto nla_put_failure;
455 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
456 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
457 goto nla_put_failure;
458 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
459 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
460 goto nla_put_failure;
461 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
462 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
463 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400464
David S. Miller9360ffd2012-03-29 04:41:26 -0400465 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
466 DBM_TO_MBM(chan->max_power)))
467 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400468
469 return 0;
470
471 nla_put_failure:
472 return -ENOBUFS;
473}
474
Johannes Berg55682962007-09-20 13:09:35 -0400475/* netlink command implementations */
476
Johannes Bergb9454e82009-07-08 13:29:08 +0200477struct key_parse {
478 struct key_params p;
479 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200480 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200481 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100482 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200483};
484
485static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
486{
487 struct nlattr *tb[NL80211_KEY_MAX + 1];
488 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
489 nl80211_key_policy);
490 if (err)
491 return err;
492
493 k->def = !!tb[NL80211_KEY_DEFAULT];
494 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
495
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100496 if (k->def) {
497 k->def_uni = true;
498 k->def_multi = true;
499 }
500 if (k->defmgmt)
501 k->def_multi = true;
502
Johannes Bergb9454e82009-07-08 13:29:08 +0200503 if (tb[NL80211_KEY_IDX])
504 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
505
506 if (tb[NL80211_KEY_DATA]) {
507 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
508 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
509 }
510
511 if (tb[NL80211_KEY_SEQ]) {
512 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
513 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
514 }
515
516 if (tb[NL80211_KEY_CIPHER])
517 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
518
Johannes Berge31b8212010-10-05 19:39:30 +0200519 if (tb[NL80211_KEY_TYPE]) {
520 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
521 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
522 return -EINVAL;
523 }
524
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100525 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
526 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100527 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
528 tb[NL80211_KEY_DEFAULT_TYPES],
529 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100530 if (err)
531 return err;
532
533 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
534 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
535 }
536
Johannes Bergb9454e82009-07-08 13:29:08 +0200537 return 0;
538}
539
540static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
541{
542 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
543 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
544 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
545 }
546
547 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
548 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
549 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
550 }
551
552 if (info->attrs[NL80211_ATTR_KEY_IDX])
553 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
554
555 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
556 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
557
558 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
559 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
560
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100561 if (k->def) {
562 k->def_uni = true;
563 k->def_multi = true;
564 }
565 if (k->defmgmt)
566 k->def_multi = true;
567
Johannes Berge31b8212010-10-05 19:39:30 +0200568 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
569 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
570 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
571 return -EINVAL;
572 }
573
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100574 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
575 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
576 int err = nla_parse_nested(
577 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
578 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
579 nl80211_key_default_policy);
580 if (err)
581 return err;
582
583 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
584 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
585 }
586
Johannes Bergb9454e82009-07-08 13:29:08 +0200587 return 0;
588}
589
590static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
591{
592 int err;
593
594 memset(k, 0, sizeof(*k));
595 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200596 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200597
598 if (info->attrs[NL80211_ATTR_KEY])
599 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
600 else
601 err = nl80211_parse_key_old(info, k);
602
603 if (err)
604 return err;
605
606 if (k->def && k->defmgmt)
607 return -EINVAL;
608
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100609 if (k->defmgmt) {
610 if (k->def_uni || !k->def_multi)
611 return -EINVAL;
612 }
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (k->idx != -1) {
615 if (k->defmgmt) {
616 if (k->idx < 4 || k->idx > 5)
617 return -EINVAL;
618 } else if (k->def) {
619 if (k->idx < 0 || k->idx > 3)
620 return -EINVAL;
621 } else {
622 if (k->idx < 0 || k->idx > 5)
623 return -EINVAL;
624 }
625 }
626
627 return 0;
628}
629
Johannes Bergfffd0932009-07-08 14:22:54 +0200630static struct cfg80211_cached_keys *
631nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
632 struct nlattr *keys)
633{
634 struct key_parse parse;
635 struct nlattr *key;
636 struct cfg80211_cached_keys *result;
637 int rem, err, def = 0;
638
639 result = kzalloc(sizeof(*result), GFP_KERNEL);
640 if (!result)
641 return ERR_PTR(-ENOMEM);
642
643 result->def = -1;
644 result->defmgmt = -1;
645
646 nla_for_each_nested(key, keys, rem) {
647 memset(&parse, 0, sizeof(parse));
648 parse.idx = -1;
649
650 err = nl80211_parse_key_new(key, &parse);
651 if (err)
652 goto error;
653 err = -EINVAL;
654 if (!parse.p.key)
655 goto error;
656 if (parse.idx < 0 || parse.idx > 4)
657 goto error;
658 if (parse.def) {
659 if (def)
660 goto error;
661 def = 1;
662 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100663 if (!parse.def_uni || !parse.def_multi)
664 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200665 } else if (parse.defmgmt)
666 goto error;
667 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200668 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200669 if (err)
670 goto error;
671 result->params[parse.idx].cipher = parse.p.cipher;
672 result->params[parse.idx].key_len = parse.p.key_len;
673 result->params[parse.idx].key = result->data[parse.idx];
674 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
675 }
676
677 return result;
678 error:
679 kfree(result);
680 return ERR_PTR(err);
681}
682
683static int nl80211_key_allowed(struct wireless_dev *wdev)
684{
685 ASSERT_WDEV_LOCK(wdev);
686
Johannes Bergfffd0932009-07-08 14:22:54 +0200687 switch (wdev->iftype) {
688 case NL80211_IFTYPE_AP:
689 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200690 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700691 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200692 break;
693 case NL80211_IFTYPE_ADHOC:
694 if (!wdev->current_bss)
695 return -ENOLINK;
696 break;
697 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200698 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200699 if (wdev->sme_state != CFG80211_SME_CONNECTED)
700 return -ENOLINK;
701 break;
702 default:
703 return -EINVAL;
704 }
705
706 return 0;
707}
708
Johannes Berg7527a782011-05-13 10:58:57 +0200709static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
710{
711 struct nlattr *nl_modes = nla_nest_start(msg, attr);
712 int i;
713
714 if (!nl_modes)
715 goto nla_put_failure;
716
717 i = 0;
718 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400719 if ((ifmodes & 1) && nla_put_flag(msg, i))
720 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200721 ifmodes >>= 1;
722 i++;
723 }
724
725 nla_nest_end(msg, nl_modes);
726 return 0;
727
728nla_put_failure:
729 return -ENOBUFS;
730}
731
732static int nl80211_put_iface_combinations(struct wiphy *wiphy,
733 struct sk_buff *msg)
734{
735 struct nlattr *nl_combis;
736 int i, j;
737
738 nl_combis = nla_nest_start(msg,
739 NL80211_ATTR_INTERFACE_COMBINATIONS);
740 if (!nl_combis)
741 goto nla_put_failure;
742
743 for (i = 0; i < wiphy->n_iface_combinations; i++) {
744 const struct ieee80211_iface_combination *c;
745 struct nlattr *nl_combi, *nl_limits;
746
747 c = &wiphy->iface_combinations[i];
748
749 nl_combi = nla_nest_start(msg, i + 1);
750 if (!nl_combi)
751 goto nla_put_failure;
752
753 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
754 if (!nl_limits)
755 goto nla_put_failure;
756
757 for (j = 0; j < c->n_limits; j++) {
758 struct nlattr *nl_limit;
759
760 nl_limit = nla_nest_start(msg, j + 1);
761 if (!nl_limit)
762 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400763 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
764 c->limits[j].max))
765 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200766 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
767 c->limits[j].types))
768 goto nla_put_failure;
769 nla_nest_end(msg, nl_limit);
770 }
771
772 nla_nest_end(msg, nl_limits);
773
David S. Miller9360ffd2012-03-29 04:41:26 -0400774 if (c->beacon_int_infra_match &&
775 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
776 goto nla_put_failure;
777 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
778 c->num_different_channels) ||
779 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
780 c->max_interfaces))
781 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200782
783 nla_nest_end(msg, nl_combi);
784 }
785
786 nla_nest_end(msg, nl_combis);
787
788 return 0;
789nla_put_failure:
790 return -ENOBUFS;
791}
792
Johannes Berg55682962007-09-20 13:09:35 -0400793static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
794 struct cfg80211_registered_device *dev)
795{
796 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100797 struct nlattr *nl_bands, *nl_band;
798 struct nlattr *nl_freqs, *nl_freq;
799 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100800 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100801 enum ieee80211_band band;
802 struct ieee80211_channel *chan;
803 struct ieee80211_rate *rate;
804 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200805 const struct ieee80211_txrx_stypes *mgmt_stypes =
806 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400807
808 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
809 if (!hdr)
810 return -1;
811
David S. Miller9360ffd2012-03-29 04:41:26 -0400812 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
813 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
814 nla_put_u32(msg, NL80211_ATTR_GENERATION,
815 cfg80211_rdev_list_generation) ||
816 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
817 dev->wiphy.retry_short) ||
818 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
819 dev->wiphy.retry_long) ||
820 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
821 dev->wiphy.frag_threshold) ||
822 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
823 dev->wiphy.rts_threshold) ||
824 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
825 dev->wiphy.coverage_class) ||
826 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
827 dev->wiphy.max_scan_ssids) ||
828 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
829 dev->wiphy.max_sched_scan_ssids) ||
830 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
831 dev->wiphy.max_scan_ie_len) ||
832 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
833 dev->wiphy.max_sched_scan_ie_len) ||
834 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
835 dev->wiphy.max_match_sets))
836 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200837
David S. Miller9360ffd2012-03-29 04:41:26 -0400838 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
839 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
840 goto nla_put_failure;
841 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
842 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
843 goto nla_put_failure;
844 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
845 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
846 goto nla_put_failure;
847 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
848 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
849 goto nla_put_failure;
850 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
851 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
852 goto nla_put_failure;
853 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
854 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
855 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200856
David S. Miller9360ffd2012-03-29 04:41:26 -0400857 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
858 sizeof(u32) * dev->wiphy.n_cipher_suites,
859 dev->wiphy.cipher_suites))
860 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100861
David S. Miller9360ffd2012-03-29 04:41:26 -0400862 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
863 dev->wiphy.max_num_pmkids))
864 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530865
David S. Miller9360ffd2012-03-29 04:41:26 -0400866 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
867 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
868 goto nla_put_failure;
Johannes Berg25e47c182009-04-02 20:14:06 +0200869
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
871 dev->wiphy.available_antennas_tx) ||
872 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
873 dev->wiphy.available_antennas_rx))
874 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100875
David S. Miller9360ffd2012-03-29 04:41:26 -0400876 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
877 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
878 dev->wiphy.probe_resp_offload))
879 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200880
Bruno Randolf7f531e02010-12-16 11:30:22 +0900881 if ((dev->wiphy.available_antennas_tx ||
882 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900883 u32 tx_ant = 0, rx_ant = 0;
884 int res;
885 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
886 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
888 tx_ant) ||
889 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
890 rx_ant))
891 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900892 }
893 }
894
Johannes Berg7527a782011-05-13 10:58:57 +0200895 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
896 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700897 goto nla_put_failure;
898
Johannes Bergee688b002008-01-24 19:38:39 +0100899 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
900 if (!nl_bands)
901 goto nla_put_failure;
902
903 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
904 if (!dev->wiphy.bands[band])
905 continue;
906
907 nl_band = nla_nest_start(msg, band);
908 if (!nl_band)
909 goto nla_put_failure;
910
Johannes Bergd51626d2008-10-09 12:20:13 +0200911 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400912 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
913 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
914 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
915 &dev->wiphy.bands[band]->ht_cap.mcs) ||
916 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
917 dev->wiphy.bands[band]->ht_cap.cap) ||
918 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
919 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
920 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
921 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
922 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200923
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000924 /* add VHT info */
925 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
926 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
927 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
928 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
929 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
930 dev->wiphy.bands[band]->vht_cap.cap)))
931 goto nla_put_failure;
932
Johannes Bergee688b002008-01-24 19:38:39 +0100933 /* add frequencies */
934 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
935 if (!nl_freqs)
936 goto nla_put_failure;
937
938 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
939 nl_freq = nla_nest_start(msg, i);
940 if (!nl_freq)
941 goto nla_put_failure;
942
943 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100944
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400945 if (nl80211_msg_put_channel(msg, chan))
946 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200947
Johannes Bergee688b002008-01-24 19:38:39 +0100948 nla_nest_end(msg, nl_freq);
949 }
950
951 nla_nest_end(msg, nl_freqs);
952
953 /* add bitrates */
954 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
955 if (!nl_rates)
956 goto nla_put_failure;
957
958 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
959 nl_rate = nla_nest_start(msg, i);
960 if (!nl_rate)
961 goto nla_put_failure;
962
963 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400964 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
965 rate->bitrate))
966 goto nla_put_failure;
967 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
968 nla_put_flag(msg,
969 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
970 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100971
972 nla_nest_end(msg, nl_rate);
973 }
974
975 nla_nest_end(msg, nl_rates);
976
977 nla_nest_end(msg, nl_band);
978 }
979 nla_nest_end(msg, nl_bands);
980
Johannes Berg8fdc6212009-03-14 09:34:01 +0100981 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
982 if (!nl_cmds)
983 goto nla_put_failure;
984
985 i = 0;
986#define CMD(op, n) \
987 do { \
988 if (dev->ops->op) { \
989 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400990 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
991 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100992 } \
993 } while (0)
994
995 CMD(add_virtual_intf, NEW_INTERFACE);
996 CMD(change_virtual_intf, SET_INTERFACE);
997 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100998 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100999 CMD(add_station, NEW_STATION);
1000 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001001 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001002 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001003 CMD(auth, AUTHENTICATE);
1004 CMD(assoc, ASSOCIATE);
1005 CMD(deauth, DEAUTHENTICATE);
1006 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001007 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001008 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001009 CMD(set_pmksa, SET_PMKSA);
1010 CMD(del_pmksa, DEL_PMKSA);
1011 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001012 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1013 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001014 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001015 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001016 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001017 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001018 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001019 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1020 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001021 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001022 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001023 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001024 i++;
1025 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1026 goto nla_put_failure;
1027 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001028 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001029 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1030 CMD(tdls_mgmt, TDLS_MGMT);
1031 CMD(tdls_oper, TDLS_OPER);
1032 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001033 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1034 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001035 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001036 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001037 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1038 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001039 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1040 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001041 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001042
Kalle Valo4745fc02011-11-17 19:06:10 +02001043#ifdef CONFIG_NL80211_TESTMODE
1044 CMD(testmode_cmd, TESTMODE);
1045#endif
1046
Johannes Berg8fdc6212009-03-14 09:34:01 +01001047#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001048
Johannes Berg6829c8782009-07-02 09:13:27 +02001049 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001050 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1052 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001053 }
1054
Johannes Berg6829c8782009-07-02 09:13:27 +02001055 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001056 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001057 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1058 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001059 }
1060
Johannes Berg8fdc6212009-03-14 09:34:01 +01001061 nla_nest_end(msg, nl_cmds);
1062
Johannes Berg7c4ef712011-11-18 15:33:48 +01001063 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001064 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1065 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1066 dev->wiphy.max_remain_on_channel_duration))
1067 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001068
David S. Miller9360ffd2012-03-29 04:41:26 -04001069 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1070 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1071 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001072
Johannes Berg2e161f72010-08-12 15:38:38 +02001073 if (mgmt_stypes) {
1074 u16 stypes;
1075 struct nlattr *nl_ftypes, *nl_ifs;
1076 enum nl80211_iftype ift;
1077
1078 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1079 if (!nl_ifs)
1080 goto nla_put_failure;
1081
1082 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1083 nl_ftypes = nla_nest_start(msg, ift);
1084 if (!nl_ftypes)
1085 goto nla_put_failure;
1086 i = 0;
1087 stypes = mgmt_stypes[ift].tx;
1088 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001089 if ((stypes & 1) &&
1090 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1091 (i << 4) | IEEE80211_FTYPE_MGMT))
1092 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001093 stypes >>= 1;
1094 i++;
1095 }
1096 nla_nest_end(msg, nl_ftypes);
1097 }
1098
Johannes Berg74b70a42010-08-24 12:15:53 +02001099 nla_nest_end(msg, nl_ifs);
1100
Johannes Berg2e161f72010-08-12 15:38:38 +02001101 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1102 if (!nl_ifs)
1103 goto nla_put_failure;
1104
1105 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1106 nl_ftypes = nla_nest_start(msg, ift);
1107 if (!nl_ftypes)
1108 goto nla_put_failure;
1109 i = 0;
1110 stypes = mgmt_stypes[ift].rx;
1111 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001112 if ((stypes & 1) &&
1113 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1114 (i << 4) | IEEE80211_FTYPE_MGMT))
1115 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001116 stypes >>= 1;
1117 i++;
1118 }
1119 nla_nest_end(msg, nl_ftypes);
1120 }
1121 nla_nest_end(msg, nl_ifs);
1122 }
1123
Johannes Bergdfb89c52012-06-27 09:23:48 +02001124#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001125 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1126 struct nlattr *nl_wowlan;
1127
1128 nl_wowlan = nla_nest_start(msg,
1129 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1130 if (!nl_wowlan)
1131 goto nla_put_failure;
1132
David S. Miller9360ffd2012-03-29 04:41:26 -04001133 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1134 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1135 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1136 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1137 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1138 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1139 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1140 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1141 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1142 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1143 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1144 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1145 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1147 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1148 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1149 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001150 if (dev->wiphy.wowlan.n_patterns) {
1151 struct nl80211_wowlan_pattern_support pat = {
1152 .max_patterns = dev->wiphy.wowlan.n_patterns,
1153 .min_pattern_len =
1154 dev->wiphy.wowlan.pattern_min_len,
1155 .max_pattern_len =
1156 dev->wiphy.wowlan.pattern_max_len,
1157 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001158 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1159 sizeof(pat), &pat))
1160 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001161 }
1162
1163 nla_nest_end(msg, nl_wowlan);
1164 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001165#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001166
Johannes Berg7527a782011-05-13 10:58:57 +02001167 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1168 dev->wiphy.software_iftypes))
1169 goto nla_put_failure;
1170
1171 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1172 goto nla_put_failure;
1173
David S. Miller9360ffd2012-03-29 04:41:26 -04001174 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1175 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1176 dev->wiphy.ap_sme_capa))
1177 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001178
David S. Miller9360ffd2012-03-29 04:41:26 -04001179 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1180 dev->wiphy.features))
1181 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001182
David S. Miller9360ffd2012-03-29 04:41:26 -04001183 if (dev->wiphy.ht_capa_mod_mask &&
1184 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1185 sizeof(*dev->wiphy.ht_capa_mod_mask),
1186 dev->wiphy.ht_capa_mod_mask))
1187 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001188
Johannes Berg55682962007-09-20 13:09:35 -04001189 return genlmsg_end(msg, hdr);
1190
1191 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001192 genlmsg_cancel(msg, hdr);
1193 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001194}
1195
1196static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1197{
1198 int idx = 0;
1199 int start = cb->args[0];
1200 struct cfg80211_registered_device *dev;
1201
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001202 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001203 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001204 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1205 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001206 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001207 continue;
1208 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1209 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001210 dev) < 0) {
1211 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001212 break;
Julius Volzb4637272008-07-08 14:02:19 +02001213 }
Johannes Berg55682962007-09-20 13:09:35 -04001214 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001215 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001216
1217 cb->args[0] = idx;
1218
1219 return skb->len;
1220}
1221
1222static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1223{
1224 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001225 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001226
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001227 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001228 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001229 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001230
Johannes Berg4c476992010-10-04 21:36:35 +02001231 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1232 nlmsg_free(msg);
1233 return -ENOBUFS;
1234 }
Johannes Berg55682962007-09-20 13:09:35 -04001235
Johannes Berg134e6372009-07-10 09:51:34 +00001236 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001237}
1238
Jouni Malinen31888482008-10-30 16:59:24 +02001239static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1240 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1241 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1242 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1243 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1244 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1245};
1246
1247static int parse_txq_params(struct nlattr *tb[],
1248 struct ieee80211_txq_params *txq_params)
1249{
Johannes Berga3304b02012-03-28 11:04:24 +02001250 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001251 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1252 !tb[NL80211_TXQ_ATTR_AIFS])
1253 return -EINVAL;
1254
Johannes Berga3304b02012-03-28 11:04:24 +02001255 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001256 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1257 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1258 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1259 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1260
Johannes Berga3304b02012-03-28 11:04:24 +02001261 if (txq_params->ac >= NL80211_NUM_ACS)
1262 return -EINVAL;
1263
Jouni Malinen31888482008-10-30 16:59:24 +02001264 return 0;
1265}
1266
Johannes Bergf444de02010-05-05 15:25:02 +02001267static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1268{
1269 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001270 * You can only set the channel explicitly for WDS interfaces,
1271 * all others have their channel managed via their respective
1272 * "establish a connection" command (connect, join, ...)
1273 *
1274 * For AP/GO and mesh mode, the channel can be set with the
1275 * channel userspace API, but is only stored and passed to the
1276 * low-level driver when the AP starts or the mesh is joined.
1277 * This is for backward compatibility, userspace can also give
1278 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001279 *
1280 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001281 * whatever else is going on, so they have their own special
1282 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001283 */
1284 return !wdev ||
1285 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001286 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001287 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1288 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001289}
1290
Johannes Bergcd6c6592012-05-10 21:27:18 +02001291static bool nl80211_valid_channel_type(struct genl_info *info,
1292 enum nl80211_channel_type *channel_type)
1293{
1294 enum nl80211_channel_type tmp;
1295
1296 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1297 return false;
1298
1299 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1300 if (tmp != NL80211_CHAN_NO_HT &&
1301 tmp != NL80211_CHAN_HT20 &&
1302 tmp != NL80211_CHAN_HT40PLUS &&
1303 tmp != NL80211_CHAN_HT40MINUS)
1304 return false;
1305
1306 if (channel_type)
1307 *channel_type = tmp;
1308
1309 return true;
1310}
1311
Johannes Bergf444de02010-05-05 15:25:02 +02001312static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1313 struct wireless_dev *wdev,
1314 struct genl_info *info)
1315{
Johannes Bergaa430da2012-05-16 23:50:18 +02001316 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001317 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1318 u32 freq;
1319 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001320 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1321
1322 if (wdev)
1323 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001324
1325 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1326 return -EINVAL;
1327
1328 if (!nl80211_can_set_dev_channel(wdev))
1329 return -EOPNOTSUPP;
1330
Johannes Bergcd6c6592012-05-10 21:27:18 +02001331 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1332 !nl80211_valid_channel_type(info, &channel_type))
1333 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001334
1335 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1336
1337 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001338 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001339 case NL80211_IFTYPE_AP:
1340 case NL80211_IFTYPE_P2P_GO:
1341 if (wdev->beacon_interval) {
1342 result = -EBUSY;
1343 break;
1344 }
1345 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1346 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1347 channel,
1348 channel_type)) {
1349 result = -EINVAL;
1350 break;
1351 }
1352 wdev->preset_chan = channel;
1353 wdev->preset_chantype = channel_type;
1354 result = 0;
1355 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001356 case NL80211_IFTYPE_MESH_POINT:
1357 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1358 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001359 case NL80211_IFTYPE_MONITOR:
1360 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1361 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001362 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001363 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001364 }
1365 mutex_unlock(&rdev->devlist_mtx);
1366
1367 return result;
1368}
1369
1370static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1371{
Johannes Berg4c476992010-10-04 21:36:35 +02001372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1373 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001374
Johannes Berg4c476992010-10-04 21:36:35 +02001375 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001376}
1377
Bill Jordane8347eb2010-10-01 13:54:28 -04001378static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1379{
Johannes Berg43b19952010-10-07 13:10:30 +02001380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1381 struct net_device *dev = info->user_ptr[1];
1382 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001383 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001384
1385 if (!info->attrs[NL80211_ATTR_MAC])
1386 return -EINVAL;
1387
Johannes Berg43b19952010-10-07 13:10:30 +02001388 if (netif_running(dev))
1389 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001390
Johannes Berg43b19952010-10-07 13:10:30 +02001391 if (!rdev->ops->set_wds_peer)
1392 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001393
Johannes Berg43b19952010-10-07 13:10:30 +02001394 if (wdev->iftype != NL80211_IFTYPE_WDS)
1395 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001396
1397 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001398 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001399}
1400
1401
Johannes Berg55682962007-09-20 13:09:35 -04001402static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1403{
1404 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001405 struct net_device *netdev = NULL;
1406 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001407 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001408 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001409 u32 changed;
1410 u8 retry_short = 0, retry_long = 0;
1411 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001412 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001413
Johannes Bergf444de02010-05-05 15:25:02 +02001414 /*
1415 * Try to find the wiphy and netdev. Normally this
1416 * function shouldn't need the netdev, but this is
1417 * done for backward compatibility -- previously
1418 * setting the channel was done per wiphy, but now
1419 * it is per netdev. Previous userland like hostapd
1420 * also passed a netdev to set_wiphy, so that it is
1421 * possible to let that go to the right netdev!
1422 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001423 mutex_lock(&cfg80211_mutex);
1424
Johannes Bergf444de02010-05-05 15:25:02 +02001425 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1426 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1427
1428 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1429 if (netdev && netdev->ieee80211_ptr) {
1430 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1431 mutex_lock(&rdev->mtx);
1432 } else
1433 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001434 }
1435
Johannes Bergf444de02010-05-05 15:25:02 +02001436 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001437 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1438 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001439 if (IS_ERR(rdev)) {
1440 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001441 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001442 }
1443 wdev = NULL;
1444 netdev = NULL;
1445 result = 0;
1446
1447 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001448 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001449 wdev = netdev->ieee80211_ptr;
1450 else
1451 wdev = NULL;
1452
1453 /*
1454 * end workaround code, by now the rdev is available
1455 * and locked, and wdev may or may not be NULL.
1456 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001457
1458 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001459 result = cfg80211_dev_rename(
1460 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001461
1462 mutex_unlock(&cfg80211_mutex);
1463
1464 if (result)
1465 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001466
Jouni Malinen31888482008-10-30 16:59:24 +02001467 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1468 struct ieee80211_txq_params txq_params;
1469 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1470
1471 if (!rdev->ops->set_txq_params) {
1472 result = -EOPNOTSUPP;
1473 goto bad_res;
1474 }
1475
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001476 if (!netdev) {
1477 result = -EINVAL;
1478 goto bad_res;
1479 }
1480
Johannes Berg133a3ff2011-11-03 14:50:13 +01001481 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1482 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1483 result = -EINVAL;
1484 goto bad_res;
1485 }
1486
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001487 if (!netif_running(netdev)) {
1488 result = -ENETDOWN;
1489 goto bad_res;
1490 }
1491
Jouni Malinen31888482008-10-30 16:59:24 +02001492 nla_for_each_nested(nl_txq_params,
1493 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1494 rem_txq_params) {
1495 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1496 nla_data(nl_txq_params),
1497 nla_len(nl_txq_params),
1498 txq_params_policy);
1499 result = parse_txq_params(tb, &txq_params);
1500 if (result)
1501 goto bad_res;
1502
1503 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001504 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001505 &txq_params);
1506 if (result)
1507 goto bad_res;
1508 }
1509 }
1510
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001511 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001512 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001513 if (result)
1514 goto bad_res;
1515 }
1516
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001517 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1518 enum nl80211_tx_power_setting type;
1519 int idx, mbm = 0;
1520
1521 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001522 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001523 goto bad_res;
1524 }
1525
1526 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1527 type = nla_get_u32(info->attrs[idx]);
1528
1529 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1530 (type != NL80211_TX_POWER_AUTOMATIC)) {
1531 result = -EINVAL;
1532 goto bad_res;
1533 }
1534
1535 if (type != NL80211_TX_POWER_AUTOMATIC) {
1536 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1537 mbm = nla_get_u32(info->attrs[idx]);
1538 }
1539
1540 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1541 if (result)
1542 goto bad_res;
1543 }
1544
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001545 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1546 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1547 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001548 if ((!rdev->wiphy.available_antennas_tx &&
1549 !rdev->wiphy.available_antennas_rx) ||
1550 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001551 result = -EOPNOTSUPP;
1552 goto bad_res;
1553 }
1554
1555 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1556 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1557
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001558 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001559 * available antenna masks, except for the "all" mask */
1560 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1561 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001562 result = -EINVAL;
1563 goto bad_res;
1564 }
1565
Bruno Randolf7f531e02010-12-16 11:30:22 +09001566 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1567 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001568
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001569 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1570 if (result)
1571 goto bad_res;
1572 }
1573
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001574 changed = 0;
1575
1576 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1577 retry_short = nla_get_u8(
1578 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1579 if (retry_short == 0) {
1580 result = -EINVAL;
1581 goto bad_res;
1582 }
1583 changed |= WIPHY_PARAM_RETRY_SHORT;
1584 }
1585
1586 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1587 retry_long = nla_get_u8(
1588 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1589 if (retry_long == 0) {
1590 result = -EINVAL;
1591 goto bad_res;
1592 }
1593 changed |= WIPHY_PARAM_RETRY_LONG;
1594 }
1595
1596 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1597 frag_threshold = nla_get_u32(
1598 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1599 if (frag_threshold < 256) {
1600 result = -EINVAL;
1601 goto bad_res;
1602 }
1603 if (frag_threshold != (u32) -1) {
1604 /*
1605 * Fragments (apart from the last one) are required to
1606 * have even length. Make the fragmentation code
1607 * simpler by stripping LSB should someone try to use
1608 * odd threshold value.
1609 */
1610 frag_threshold &= ~0x1;
1611 }
1612 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1613 }
1614
1615 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1616 rts_threshold = nla_get_u32(
1617 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1618 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1619 }
1620
Lukáš Turek81077e82009-12-21 22:50:47 +01001621 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1622 coverage_class = nla_get_u8(
1623 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1624 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1625 }
1626
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001627 if (changed) {
1628 u8 old_retry_short, old_retry_long;
1629 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001630 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001631
1632 if (!rdev->ops->set_wiphy_params) {
1633 result = -EOPNOTSUPP;
1634 goto bad_res;
1635 }
1636
1637 old_retry_short = rdev->wiphy.retry_short;
1638 old_retry_long = rdev->wiphy.retry_long;
1639 old_frag_threshold = rdev->wiphy.frag_threshold;
1640 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001641 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001642
1643 if (changed & WIPHY_PARAM_RETRY_SHORT)
1644 rdev->wiphy.retry_short = retry_short;
1645 if (changed & WIPHY_PARAM_RETRY_LONG)
1646 rdev->wiphy.retry_long = retry_long;
1647 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1648 rdev->wiphy.frag_threshold = frag_threshold;
1649 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1650 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001651 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1652 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001653
1654 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1655 if (result) {
1656 rdev->wiphy.retry_short = old_retry_short;
1657 rdev->wiphy.retry_long = old_retry_long;
1658 rdev->wiphy.frag_threshold = old_frag_threshold;
1659 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001660 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001661 }
1662 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001663
Johannes Berg306d6112008-12-08 12:39:04 +01001664 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001665 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001666 if (netdev)
1667 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001668 return result;
1669}
1670
1671
1672static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001673 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001674 struct net_device *dev)
1675{
1676 void *hdr;
1677
1678 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1679 if (!hdr)
1680 return -1;
1681
David S. Miller9360ffd2012-03-29 04:41:26 -04001682 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1683 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1684 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1685 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1686 dev->ieee80211_ptr->iftype) ||
1687 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1688 rdev->devlist_generation ^
1689 (cfg80211_rdev_list_generation << 2)))
1690 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001691
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001692 if (rdev->ops->get_channel) {
1693 struct ieee80211_channel *chan;
1694 enum nl80211_channel_type channel_type;
1695
1696 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
John W. Linville59ef43e2012-04-18 14:17:13 -04001697 if (chan &&
1698 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1699 chan->center_freq) ||
1700 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1701 channel_type)))
1702 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001703 }
1704
Johannes Berg55682962007-09-20 13:09:35 -04001705 return genlmsg_end(msg, hdr);
1706
1707 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001708 genlmsg_cancel(msg, hdr);
1709 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001710}
1711
1712static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1713{
1714 int wp_idx = 0;
1715 int if_idx = 0;
1716 int wp_start = cb->args[0];
1717 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001718 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001719 struct wireless_dev *wdev;
1720
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001721 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001722 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1723 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001724 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001725 if (wp_idx < wp_start) {
1726 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001727 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001728 }
Johannes Berg55682962007-09-20 13:09:35 -04001729 if_idx = 0;
1730
Johannes Bergf5ea9122009-08-07 16:17:38 +02001731 mutex_lock(&rdev->devlist_mtx);
1732 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001733 if (if_idx < if_start) {
1734 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001735 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001736 }
Johannes Berg55682962007-09-20 13:09:35 -04001737 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1738 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001739 rdev, wdev->netdev) < 0) {
1740 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001741 goto out;
1742 }
1743 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001744 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001745 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001746
1747 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001748 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001749 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001750 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001751
1752 cb->args[0] = wp_idx;
1753 cb->args[1] = if_idx;
1754
1755 return skb->len;
1756}
1757
1758static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1759{
1760 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001761 struct cfg80211_registered_device *dev = info->user_ptr[0];
1762 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001763
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001765 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001766 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001767
Johannes Bergd7264052009-04-19 16:23:20 +02001768 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001769 dev, netdev) < 0) {
1770 nlmsg_free(msg);
1771 return -ENOBUFS;
1772 }
Johannes Berg55682962007-09-20 13:09:35 -04001773
Johannes Berg134e6372009-07-10 09:51:34 +00001774 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001775}
1776
Michael Wu66f7ac52008-01-31 19:48:22 +01001777static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1778 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1779 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1780 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1781 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1782 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1783};
1784
1785static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1786{
1787 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1788 int flag;
1789
1790 *mntrflags = 0;
1791
1792 if (!nla)
1793 return -EINVAL;
1794
1795 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1796 nla, mntr_flags_policy))
1797 return -EINVAL;
1798
1799 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1800 if (flags[flag])
1801 *mntrflags |= (1<<flag);
1802
1803 return 0;
1804}
1805
Johannes Berg9bc383d2009-11-19 11:55:19 +01001806static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001807 struct net_device *netdev, u8 use_4addr,
1808 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001809{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001810 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001811 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001812 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001813 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001814 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001815
1816 switch (iftype) {
1817 case NL80211_IFTYPE_AP_VLAN:
1818 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1819 return 0;
1820 break;
1821 case NL80211_IFTYPE_STATION:
1822 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1823 return 0;
1824 break;
1825 default:
1826 break;
1827 }
1828
1829 return -EOPNOTSUPP;
1830}
1831
Johannes Berg55682962007-09-20 13:09:35 -04001832static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1833{
Johannes Berg4c476992010-10-04 21:36:35 +02001834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001835 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001836 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001837 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001838 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001839 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001840 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001841
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001842 memset(&params, 0, sizeof(params));
1843
Johannes Berg04a773a2009-04-19 21:24:32 +02001844 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001845
Johannes Berg723b0382008-09-16 20:22:09 +02001846 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001847 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001848 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001849 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001850 if (ntype > NL80211_IFTYPE_MAX)
1851 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001852 }
1853
Johannes Berg92ffe052008-09-16 20:39:36 +02001854 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001855 struct wireless_dev *wdev = dev->ieee80211_ptr;
1856
Johannes Berg4c476992010-10-04 21:36:35 +02001857 if (ntype != NL80211_IFTYPE_MESH_POINT)
1858 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001859 if (netif_running(dev))
1860 return -EBUSY;
1861
1862 wdev_lock(wdev);
1863 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1864 IEEE80211_MAX_MESH_ID_LEN);
1865 wdev->mesh_id_up_len =
1866 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1867 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1868 wdev->mesh_id_up_len);
1869 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001870 }
1871
Felix Fietkau8b787642009-11-10 18:53:10 +01001872 if (info->attrs[NL80211_ATTR_4ADDR]) {
1873 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1874 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001875 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001876 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001877 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001878 } else {
1879 params.use_4addr = -1;
1880 }
1881
Johannes Berg92ffe052008-09-16 20:39:36 +02001882 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001883 if (ntype != NL80211_IFTYPE_MONITOR)
1884 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001885 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1886 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001887 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001888 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001889
1890 flags = &_flags;
1891 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001892 }
Johannes Berg3b858752009-03-12 09:55:09 +01001893
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001894 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001895 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001896 else
1897 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001898
Johannes Berg9bc383d2009-11-19 11:55:19 +01001899 if (!err && params.use_4addr != -1)
1900 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1901
Johannes Berg55682962007-09-20 13:09:35 -04001902 return err;
1903}
1904
1905static int nl80211_new_interface(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];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001908 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001909 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001910 int err;
1911 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001912 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001913
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001914 memset(&params, 0, sizeof(params));
1915
Johannes Berg55682962007-09-20 13:09:35 -04001916 if (!info->attrs[NL80211_ATTR_IFNAME])
1917 return -EINVAL;
1918
1919 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1920 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1921 if (type > NL80211_IFTYPE_MAX)
1922 return -EINVAL;
1923 }
1924
Johannes Berg79c97e92009-07-07 03:56:12 +02001925 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001926 !(rdev->wiphy.interface_modes & (1 << type)))
1927 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001928
Johannes Berg9bc383d2009-11-19 11:55:19 +01001929 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001930 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001931 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001932 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001933 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001934 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001935
Michael Wu66f7ac52008-01-31 19:48:22 +01001936 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1937 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1938 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001939 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001940 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001941 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001942 if (IS_ERR(dev))
1943 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001944
Johannes Berg29cbe682010-12-03 09:20:44 +01001945 if (type == NL80211_IFTYPE_MESH_POINT &&
1946 info->attrs[NL80211_ATTR_MESH_ID]) {
1947 struct wireless_dev *wdev = dev->ieee80211_ptr;
1948
1949 wdev_lock(wdev);
1950 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1951 IEEE80211_MAX_MESH_ID_LEN);
1952 wdev->mesh_id_up_len =
1953 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1954 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1955 wdev->mesh_id_up_len);
1956 wdev_unlock(wdev);
1957 }
1958
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001959 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001960}
1961
1962static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1963{
Johannes Berg4c476992010-10-04 21:36:35 +02001964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1965 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001966
Johannes Berg4c476992010-10-04 21:36:35 +02001967 if (!rdev->ops->del_virtual_intf)
1968 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001969
Johannes Berg4c476992010-10-04 21:36:35 +02001970 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001971}
1972
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001973static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1974{
1975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1976 struct net_device *dev = info->user_ptr[1];
1977 u16 noack_map;
1978
1979 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1980 return -EINVAL;
1981
1982 if (!rdev->ops->set_noack_map)
1983 return -EOPNOTSUPP;
1984
1985 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1986
1987 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1988}
1989
Johannes Berg41ade002007-12-19 02:03:29 +01001990struct get_key_cookie {
1991 struct sk_buff *msg;
1992 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001993 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001994};
1995
1996static void get_key_callback(void *c, struct key_params *params)
1997{
Johannes Bergb9454e82009-07-08 13:29:08 +02001998 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001999 struct get_key_cookie *cookie = c;
2000
David S. Miller9360ffd2012-03-29 04:41:26 -04002001 if ((params->key &&
2002 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2003 params->key_len, params->key)) ||
2004 (params->seq &&
2005 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2006 params->seq_len, params->seq)) ||
2007 (params->cipher &&
2008 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2009 params->cipher)))
2010 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002011
Johannes Bergb9454e82009-07-08 13:29:08 +02002012 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2013 if (!key)
2014 goto nla_put_failure;
2015
David S. Miller9360ffd2012-03-29 04:41:26 -04002016 if ((params->key &&
2017 nla_put(cookie->msg, NL80211_KEY_DATA,
2018 params->key_len, params->key)) ||
2019 (params->seq &&
2020 nla_put(cookie->msg, NL80211_KEY_SEQ,
2021 params->seq_len, params->seq)) ||
2022 (params->cipher &&
2023 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2024 params->cipher)))
2025 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002026
David S. Miller9360ffd2012-03-29 04:41:26 -04002027 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2028 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002029
2030 nla_nest_end(cookie->msg, key);
2031
Johannes Berg41ade002007-12-19 02:03:29 +01002032 return;
2033 nla_put_failure:
2034 cookie->error = 1;
2035}
2036
2037static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2038{
Johannes Berg4c476992010-10-04 21:36:35 +02002039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002040 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002041 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002042 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002043 const u8 *mac_addr = NULL;
2044 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002045 struct get_key_cookie cookie = {
2046 .error = 0,
2047 };
2048 void *hdr;
2049 struct sk_buff *msg;
2050
2051 if (info->attrs[NL80211_ATTR_KEY_IDX])
2052 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2053
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002054 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002055 return -EINVAL;
2056
2057 if (info->attrs[NL80211_ATTR_MAC])
2058 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2059
Johannes Berge31b8212010-10-05 19:39:30 +02002060 pairwise = !!mac_addr;
2061 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2062 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2063 if (kt >= NUM_NL80211_KEYTYPES)
2064 return -EINVAL;
2065 if (kt != NL80211_KEYTYPE_GROUP &&
2066 kt != NL80211_KEYTYPE_PAIRWISE)
2067 return -EINVAL;
2068 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2069 }
2070
Johannes Berg4c476992010-10-04 21:36:35 +02002071 if (!rdev->ops->get_key)
2072 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002073
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002074 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002075 if (!msg)
2076 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002077
2078 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2079 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002080 if (IS_ERR(hdr))
2081 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002082
2083 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002084 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002085
David S. Miller9360ffd2012-03-29 04:41:26 -04002086 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2087 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2088 goto nla_put_failure;
2089 if (mac_addr &&
2090 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2091 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002092
Johannes Berge31b8212010-10-05 19:39:30 +02002093 if (pairwise && mac_addr &&
2094 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2095 return -ENOENT;
2096
2097 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2098 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002099
2100 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002101 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002102
2103 if (cookie.error)
2104 goto nla_put_failure;
2105
2106 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002107 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002108
2109 nla_put_failure:
2110 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002111 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002112 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002113 return err;
2114}
2115
2116static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2117{
Johannes Berg4c476992010-10-04 21:36:35 +02002118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002119 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002120 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002121 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002122
Johannes Bergb9454e82009-07-08 13:29:08 +02002123 err = nl80211_parse_key(info, &key);
2124 if (err)
2125 return err;
2126
2127 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002128 return -EINVAL;
2129
Johannes Bergb9454e82009-07-08 13:29:08 +02002130 /* only support setting default key */
2131 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002132 return -EINVAL;
2133
Johannes Bergfffd0932009-07-08 14:22:54 +02002134 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002135
2136 if (key.def) {
2137 if (!rdev->ops->set_default_key) {
2138 err = -EOPNOTSUPP;
2139 goto out;
2140 }
2141
2142 err = nl80211_key_allowed(dev->ieee80211_ptr);
2143 if (err)
2144 goto out;
2145
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002146 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2147 key.def_uni, key.def_multi);
2148
2149 if (err)
2150 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002151
Johannes Berg3d23e342009-09-29 23:27:28 +02002152#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002153 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002154#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002155 } else {
2156 if (key.def_uni || !key.def_multi) {
2157 err = -EINVAL;
2158 goto out;
2159 }
2160
2161 if (!rdev->ops->set_default_mgmt_key) {
2162 err = -EOPNOTSUPP;
2163 goto out;
2164 }
2165
2166 err = nl80211_key_allowed(dev->ieee80211_ptr);
2167 if (err)
2168 goto out;
2169
2170 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2171 dev, key.idx);
2172 if (err)
2173 goto out;
2174
2175#ifdef CONFIG_CFG80211_WEXT
2176 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2177#endif
2178 }
2179
2180 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002181 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002182
Johannes Berg41ade002007-12-19 02:03:29 +01002183 return err;
2184}
2185
2186static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2187{
Johannes Berg4c476992010-10-04 21:36:35 +02002188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002189 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002190 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002191 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002192 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002193
Johannes Bergb9454e82009-07-08 13:29:08 +02002194 err = nl80211_parse_key(info, &key);
2195 if (err)
2196 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002197
Johannes Bergb9454e82009-07-08 13:29:08 +02002198 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002199 return -EINVAL;
2200
Johannes Berg41ade002007-12-19 02:03:29 +01002201 if (info->attrs[NL80211_ATTR_MAC])
2202 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2203
Johannes Berge31b8212010-10-05 19:39:30 +02002204 if (key.type == -1) {
2205 if (mac_addr)
2206 key.type = NL80211_KEYTYPE_PAIRWISE;
2207 else
2208 key.type = NL80211_KEYTYPE_GROUP;
2209 }
2210
2211 /* for now */
2212 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2213 key.type != NL80211_KEYTYPE_GROUP)
2214 return -EINVAL;
2215
Johannes Berg4c476992010-10-04 21:36:35 +02002216 if (!rdev->ops->add_key)
2217 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002218
Johannes Berge31b8212010-10-05 19:39:30 +02002219 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2220 key.type == NL80211_KEYTYPE_PAIRWISE,
2221 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002222 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002223
2224 wdev_lock(dev->ieee80211_ptr);
2225 err = nl80211_key_allowed(dev->ieee80211_ptr);
2226 if (!err)
2227 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002228 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002229 mac_addr, &key.p);
2230 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002231
Johannes Berg41ade002007-12-19 02:03:29 +01002232 return err;
2233}
2234
2235static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2236{
Johannes Berg4c476992010-10-04 21:36:35 +02002237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002238 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002239 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002240 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002241 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002242
Johannes Bergb9454e82009-07-08 13:29:08 +02002243 err = nl80211_parse_key(info, &key);
2244 if (err)
2245 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002246
2247 if (info->attrs[NL80211_ATTR_MAC])
2248 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2249
Johannes Berge31b8212010-10-05 19:39:30 +02002250 if (key.type == -1) {
2251 if (mac_addr)
2252 key.type = NL80211_KEYTYPE_PAIRWISE;
2253 else
2254 key.type = NL80211_KEYTYPE_GROUP;
2255 }
2256
2257 /* for now */
2258 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2259 key.type != NL80211_KEYTYPE_GROUP)
2260 return -EINVAL;
2261
Johannes Berg4c476992010-10-04 21:36:35 +02002262 if (!rdev->ops->del_key)
2263 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002264
Johannes Bergfffd0932009-07-08 14:22:54 +02002265 wdev_lock(dev->ieee80211_ptr);
2266 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002267
2268 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2269 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2270 err = -ENOENT;
2271
Johannes Bergfffd0932009-07-08 14:22:54 +02002272 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002273 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2274 key.type == NL80211_KEYTYPE_PAIRWISE,
2275 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002276
Johannes Berg3d23e342009-09-29 23:27:28 +02002277#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002278 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002279 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002280 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002281 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002282 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2283 }
2284#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002285 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002286
Johannes Berg41ade002007-12-19 02:03:29 +01002287 return err;
2288}
2289
Johannes Berg88600202012-02-13 15:17:18 +01002290static int nl80211_parse_beacon(struct genl_info *info,
2291 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002292{
Johannes Berg88600202012-02-13 15:17:18 +01002293 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002294
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002295 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2296 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2297 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2298 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002299 return -EINVAL;
2300
Johannes Berg88600202012-02-13 15:17:18 +01002301 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002302
Johannes Berged1b6cc2007-12-19 02:03:32 +01002303 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002304 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2305 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2306 if (!bcn->head_len)
2307 return -EINVAL;
2308 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002309 }
2310
2311 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002312 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2313 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002314 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002315 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002316 }
2317
Johannes Berg4c476992010-10-04 21:36:35 +02002318 if (!haveinfo)
2319 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002320
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002321 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002322 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2323 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002324 }
2325
2326 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002327 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002328 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002329 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002330 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2331 }
2332
2333 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002334 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002335 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002336 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002337 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2338 }
2339
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002340 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002341 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002342 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002343 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002344 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2345 }
2346
Johannes Berg88600202012-02-13 15:17:18 +01002347 return 0;
2348}
2349
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002350static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2351 struct cfg80211_ap_settings *params)
2352{
2353 struct wireless_dev *wdev;
2354 bool ret = false;
2355
2356 mutex_lock(&rdev->devlist_mtx);
2357
2358 list_for_each_entry(wdev, &rdev->netdev_list, list) {
2359 if (wdev->iftype != NL80211_IFTYPE_AP &&
2360 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2361 continue;
2362
2363 if (!wdev->preset_chan)
2364 continue;
2365
2366 params->channel = wdev->preset_chan;
2367 params->channel_type = wdev->preset_chantype;
2368 ret = true;
2369 break;
2370 }
2371
2372 mutex_unlock(&rdev->devlist_mtx);
2373
2374 return ret;
2375}
2376
Johannes Berg88600202012-02-13 15:17:18 +01002377static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2378{
2379 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2380 struct net_device *dev = info->user_ptr[1];
2381 struct wireless_dev *wdev = dev->ieee80211_ptr;
2382 struct cfg80211_ap_settings params;
2383 int err;
2384
2385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2386 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2387 return -EOPNOTSUPP;
2388
2389 if (!rdev->ops->start_ap)
2390 return -EOPNOTSUPP;
2391
2392 if (wdev->beacon_interval)
2393 return -EALREADY;
2394
2395 memset(&params, 0, sizeof(params));
2396
2397 /* these are required for START_AP */
2398 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2399 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2400 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2401 return -EINVAL;
2402
2403 err = nl80211_parse_beacon(info, &params.beacon);
2404 if (err)
2405 return err;
2406
2407 params.beacon_interval =
2408 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2409 params.dtim_period =
2410 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2411
2412 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2413 if (err)
2414 return err;
2415
2416 /*
2417 * In theory, some of these attributes should be required here
2418 * but since they were not used when the command was originally
2419 * added, keep them optional for old user space programs to let
2420 * them continue to work with drivers that do not need the
2421 * additional information -- drivers must check!
2422 */
2423 if (info->attrs[NL80211_ATTR_SSID]) {
2424 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2425 params.ssid_len =
2426 nla_len(info->attrs[NL80211_ATTR_SSID]);
2427 if (params.ssid_len == 0 ||
2428 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2429 return -EINVAL;
2430 }
2431
2432 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2433 params.hidden_ssid = nla_get_u32(
2434 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2435 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2436 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2437 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2438 return -EINVAL;
2439 }
2440
2441 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2442
2443 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2444 params.auth_type = nla_get_u32(
2445 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2446 if (!nl80211_valid_auth_type(params.auth_type))
2447 return -EINVAL;
2448 } else
2449 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2450
2451 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2452 NL80211_MAX_NR_CIPHER_SUITES);
2453 if (err)
2454 return err;
2455
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302456 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2457 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2458 return -EOPNOTSUPP;
2459 params.inactivity_timeout = nla_get_u16(
2460 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2461 }
2462
Johannes Bergaa430da2012-05-16 23:50:18 +02002463 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2464 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2465
2466 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2467 !nl80211_valid_channel_type(info, &channel_type))
2468 return -EINVAL;
2469
2470 params.channel = rdev_freq_to_chan(rdev,
2471 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2472 channel_type);
2473 if (!params.channel)
2474 return -EINVAL;
2475 params.channel_type = channel_type;
2476 } else if (wdev->preset_chan) {
2477 params.channel = wdev->preset_chan;
2478 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002479 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002480 return -EINVAL;
2481
2482 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2483 params.channel_type))
2484 return -EINVAL;
2485
Johannes Berg88600202012-02-13 15:17:18 +01002486 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002487 if (!err) {
2488 wdev->preset_chan = params.channel;
2489 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002490 wdev->beacon_interval = params.beacon_interval;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002491 }
Johannes Berg56d18932011-05-09 18:41:15 +02002492 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002493}
2494
Johannes Berg88600202012-02-13 15:17:18 +01002495static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2496{
2497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2498 struct net_device *dev = info->user_ptr[1];
2499 struct wireless_dev *wdev = dev->ieee80211_ptr;
2500 struct cfg80211_beacon_data params;
2501 int err;
2502
2503 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2504 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2505 return -EOPNOTSUPP;
2506
2507 if (!rdev->ops->change_beacon)
2508 return -EOPNOTSUPP;
2509
2510 if (!wdev->beacon_interval)
2511 return -EINVAL;
2512
2513 err = nl80211_parse_beacon(info, &params);
2514 if (err)
2515 return err;
2516
2517 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2518}
2519
2520static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002521{
Johannes Berg4c476992010-10-04 21:36:35 +02002522 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2523 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002524 struct wireless_dev *wdev = dev->ieee80211_ptr;
2525 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002526
Johannes Berg88600202012-02-13 15:17:18 +01002527 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002528 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002529
Johannes Berg074ac8d2010-09-16 14:58:22 +02002530 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002531 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2532 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002533
Johannes Berg88600202012-02-13 15:17:18 +01002534 if (!wdev->beacon_interval)
2535 return -ENOENT;
2536
2537 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002538 if (!err)
2539 wdev->beacon_interval = 0;
2540 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002541}
2542
Johannes Berg5727ef12007-12-19 02:03:34 +01002543static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2544 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2545 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2546 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002547 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002548 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002549 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002550};
2551
Johannes Bergeccb8e82009-05-11 21:57:56 +03002552static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002553 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002554 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002555{
2556 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002557 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002558 int flag;
2559
Johannes Bergeccb8e82009-05-11 21:57:56 +03002560 /*
2561 * Try parsing the new attribute first so userspace
2562 * can specify both for older kernels.
2563 */
2564 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2565 if (nla) {
2566 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002567
Johannes Bergeccb8e82009-05-11 21:57:56 +03002568 sta_flags = nla_data(nla);
2569 params->sta_flags_mask = sta_flags->mask;
2570 params->sta_flags_set = sta_flags->set;
2571 if ((params->sta_flags_mask |
2572 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2573 return -EINVAL;
2574 return 0;
2575 }
2576
2577 /* if present, parse the old attribute */
2578
2579 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002580 if (!nla)
2581 return 0;
2582
2583 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2584 nla, sta_flags_policy))
2585 return -EINVAL;
2586
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002587 /*
2588 * Only allow certain flags for interface types so that
2589 * other attributes are silently ignored. Remember that
2590 * this is backward compatibility code with old userspace
2591 * and shouldn't be hit in other cases anyway.
2592 */
2593 switch (iftype) {
2594 case NL80211_IFTYPE_AP:
2595 case NL80211_IFTYPE_AP_VLAN:
2596 case NL80211_IFTYPE_P2P_GO:
2597 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2598 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2599 BIT(NL80211_STA_FLAG_WME) |
2600 BIT(NL80211_STA_FLAG_MFP);
2601 break;
2602 case NL80211_IFTYPE_P2P_CLIENT:
2603 case NL80211_IFTYPE_STATION:
2604 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2605 BIT(NL80211_STA_FLAG_TDLS_PEER);
2606 break;
2607 case NL80211_IFTYPE_MESH_POINT:
2608 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2609 BIT(NL80211_STA_FLAG_MFP) |
2610 BIT(NL80211_STA_FLAG_AUTHORIZED);
2611 default:
2612 return -EINVAL;
2613 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002614
Johannes Berg3383b5a2012-05-10 20:14:43 +02002615 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2616 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002617 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002618
Johannes Berg3383b5a2012-05-10 20:14:43 +02002619 /* no longer support new API additions in old API */
2620 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2621 return -EINVAL;
2622 }
2623 }
2624
Johannes Berg5727ef12007-12-19 02:03:34 +01002625 return 0;
2626}
2627
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002628static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2629 int attr)
2630{
2631 struct nlattr *rate;
2632 u16 bitrate;
2633
2634 rate = nla_nest_start(msg, attr);
2635 if (!rate)
2636 goto nla_put_failure;
2637
2638 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2639 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002640 if ((bitrate > 0 &&
2641 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2642 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2643 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2644 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2645 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2646 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2647 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2648 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002649
2650 nla_nest_end(msg, rate);
2651 return true;
2652
2653nla_put_failure:
2654 return false;
2655}
2656
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002657static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002658 int flags,
2659 struct cfg80211_registered_device *rdev,
2660 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002661 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002662{
2663 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002664 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002665
2666 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2667 if (!hdr)
2668 return -1;
2669
David S. Miller9360ffd2012-03-29 04:41:26 -04002670 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2671 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2672 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2673 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002674
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002675 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2676 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002677 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002678 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2679 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2680 sinfo->connected_time))
2681 goto nla_put_failure;
2682 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2683 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2684 sinfo->inactive_time))
2685 goto nla_put_failure;
2686 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2687 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2688 sinfo->rx_bytes))
2689 goto nla_put_failure;
2690 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2691 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2692 sinfo->tx_bytes))
2693 goto nla_put_failure;
2694 if ((sinfo->filled & STATION_INFO_LLID) &&
2695 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2696 goto nla_put_failure;
2697 if ((sinfo->filled & STATION_INFO_PLID) &&
2698 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2699 goto nla_put_failure;
2700 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2701 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2702 sinfo->plink_state))
2703 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002704 switch (rdev->wiphy.signal_type) {
2705 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002706 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2707 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2708 sinfo->signal))
2709 goto nla_put_failure;
2710 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2711 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2712 sinfo->signal_avg))
2713 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002714 break;
2715 default:
2716 break;
2717 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002718 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002719 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2720 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002721 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002722 }
2723 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2724 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2725 NL80211_STA_INFO_RX_BITRATE))
2726 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002727 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002728 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2729 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2730 sinfo->rx_packets))
2731 goto nla_put_failure;
2732 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2733 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2734 sinfo->tx_packets))
2735 goto nla_put_failure;
2736 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2737 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2738 sinfo->tx_retries))
2739 goto nla_put_failure;
2740 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2741 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2742 sinfo->tx_failed))
2743 goto nla_put_failure;
2744 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2745 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2746 sinfo->beacon_loss_count))
2747 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002748 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2749 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2750 if (!bss_param)
2751 goto nla_put_failure;
2752
David S. Miller9360ffd2012-03-29 04:41:26 -04002753 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2754 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2755 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2756 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2757 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2758 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2759 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2760 sinfo->bss_param.dtim_period) ||
2761 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2762 sinfo->bss_param.beacon_interval))
2763 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002764
2765 nla_nest_end(msg, bss_param);
2766 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002767 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2768 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2769 sizeof(struct nl80211_sta_flag_update),
2770 &sinfo->sta_flags))
2771 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002772 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2773 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2774 sinfo->t_offset))
2775 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002776 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002777
David S. Miller9360ffd2012-03-29 04:41:26 -04002778 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2779 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2780 sinfo->assoc_req_ies))
2781 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002782
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002783 return genlmsg_end(msg, hdr);
2784
2785 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002786 genlmsg_cancel(msg, hdr);
2787 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002788}
2789
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002790static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002791 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002792{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002793 struct station_info sinfo;
2794 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002795 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002796 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002797 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002798 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002799
Johannes Berg67748892010-10-04 21:14:06 +02002800 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2801 if (err)
2802 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002803
2804 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002805 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002806 goto out_err;
2807 }
2808
Johannes Bergbba95fe2008-07-29 13:22:51 +02002809 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002810 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002811 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2812 mac_addr, &sinfo);
2813 if (err == -ENOENT)
2814 break;
2815 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002816 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002817
2818 if (nl80211_send_station(skb,
2819 NETLINK_CB(cb->skb).pid,
2820 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002821 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002822 &sinfo) < 0)
2823 goto out;
2824
2825 sta_idx++;
2826 }
2827
2828
2829 out:
2830 cb->args[1] = sta_idx;
2831 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002832 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002833 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002834
2835 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002836}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002837
Johannes Berg5727ef12007-12-19 02:03:34 +01002838static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2839{
Johannes Berg4c476992010-10-04 21:36:35 +02002840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2841 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002842 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002843 struct sk_buff *msg;
2844 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002845 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002846
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002847 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002848
2849 if (!info->attrs[NL80211_ATTR_MAC])
2850 return -EINVAL;
2851
2852 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2853
Johannes Berg4c476992010-10-04 21:36:35 +02002854 if (!rdev->ops->get_station)
2855 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002856
Johannes Berg79c97e92009-07-07 03:56:12 +02002857 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002858 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002859 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002860
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002862 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002863 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002864
2865 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002866 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002867 nlmsg_free(msg);
2868 return -ENOBUFS;
2869 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002870
Johannes Berg4c476992010-10-04 21:36:35 +02002871 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002872}
2873
2874/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002875 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002876 */
Johannes Berg80b99892011-11-18 16:23:01 +01002877static struct net_device *get_vlan(struct genl_info *info,
2878 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002879{
Johannes Berg463d0182009-07-14 00:33:35 +02002880 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002881 struct net_device *v;
2882 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002883
Johannes Berg80b99892011-11-18 16:23:01 +01002884 if (!vlanattr)
2885 return NULL;
2886
2887 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2888 if (!v)
2889 return ERR_PTR(-ENODEV);
2890
2891 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2892 ret = -EINVAL;
2893 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002894 }
Johannes Berg80b99892011-11-18 16:23:01 +01002895
2896 if (!netif_running(v)) {
2897 ret = -ENETDOWN;
2898 goto error;
2899 }
2900
2901 return v;
2902 error:
2903 dev_put(v);
2904 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002905}
2906
2907static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2908{
Johannes Berg4c476992010-10-04 21:36:35 +02002909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002910 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002911 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002912 struct station_parameters params;
2913 u8 *mac_addr = NULL;
2914
2915 memset(&params, 0, sizeof(params));
2916
2917 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002918 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002919
2920 if (info->attrs[NL80211_ATTR_STA_AID])
2921 return -EINVAL;
2922
2923 if (!info->attrs[NL80211_ATTR_MAC])
2924 return -EINVAL;
2925
2926 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2927
2928 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2929 params.supported_rates =
2930 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2931 params.supported_rates_len =
2932 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2933 }
2934
2935 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2936 params.listen_interval =
2937 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2938
Jouni Malinen36aedc92008-08-25 11:58:58 +03002939 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2940 params.ht_capa =
2941 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2942
Johannes Bergbdd90d52011-12-14 12:20:27 +01002943 if (!rdev->ops->change_station)
2944 return -EOPNOTSUPP;
2945
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002946 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002947 return -EINVAL;
2948
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002949 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2950 params.plink_action =
2951 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2952
Javier Cardona9c3990a2011-05-03 16:57:11 -07002953 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2954 params.plink_state =
2955 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2956
Johannes Berga97f4422009-06-18 17:23:43 +02002957 switch (dev->ieee80211_ptr->iftype) {
2958 case NL80211_IFTYPE_AP:
2959 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002960 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002961 /* disallow mesh-specific things */
2962 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002963 return -EINVAL;
2964
2965 /* TDLS can't be set, ... */
2966 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2967 return -EINVAL;
2968 /*
2969 * ... but don't bother the driver with it. This works around
2970 * a hostapd/wpa_supplicant issue -- it always includes the
2971 * TLDS_PEER flag in the mask even for AP mode.
2972 */
2973 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2974
2975 /* accept only the listed bits */
2976 if (params.sta_flags_mask &
2977 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2978 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2979 BIT(NL80211_STA_FLAG_WME) |
2980 BIT(NL80211_STA_FLAG_MFP)))
2981 return -EINVAL;
2982
2983 /* must be last in here for error handling */
2984 params.vlan = get_vlan(info, rdev);
2985 if (IS_ERR(params.vlan))
2986 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002987 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002988 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002989 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002990 /*
2991 * Don't allow userspace to change the TDLS_PEER flag,
2992 * but silently ignore attempts to change it since we
2993 * don't have state here to verify that it doesn't try
2994 * to change the flag.
2995 */
2996 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002997 /* fall through */
2998 case NL80211_IFTYPE_ADHOC:
2999 /* disallow things sta doesn't support */
3000 if (params.plink_action)
3001 return -EINVAL;
3002 if (params.ht_capa)
3003 return -EINVAL;
3004 if (params.listen_interval >= 0)
3005 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003006 /* reject any changes other than AUTHORIZED */
3007 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3008 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003009 break;
3010 case NL80211_IFTYPE_MESH_POINT:
3011 /* disallow things mesh doesn't support */
3012 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003013 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003014 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003015 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003016 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003017 return -EINVAL;
3018 /*
3019 * No special handling for TDLS here -- the userspace
3020 * mesh code doesn't have this bug.
3021 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003022 if (params.sta_flags_mask &
3023 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003024 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003025 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003026 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003027 break;
3028 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003029 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003030 }
3031
Johannes Bergbdd90d52011-12-14 12:20:27 +01003032 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003033
Johannes Berg79c97e92009-07-07 03:56:12 +02003034 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003035
Johannes Berg5727ef12007-12-19 02:03:34 +01003036 if (params.vlan)
3037 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003038
Johannes Berg5727ef12007-12-19 02:03:34 +01003039 return err;
3040}
3041
Eliad Pellerc75786c2011-08-23 14:37:46 +03003042static struct nla_policy
3043nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3044 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3045 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3046};
3047
Johannes Berg5727ef12007-12-19 02:03:34 +01003048static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3049{
Johannes Berg4c476992010-10-04 21:36:35 +02003050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003051 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003052 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003053 struct station_parameters params;
3054 u8 *mac_addr = NULL;
3055
3056 memset(&params, 0, sizeof(params));
3057
3058 if (!info->attrs[NL80211_ATTR_MAC])
3059 return -EINVAL;
3060
Johannes Berg5727ef12007-12-19 02:03:34 +01003061 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3062 return -EINVAL;
3063
3064 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3065 return -EINVAL;
3066
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003067 if (!info->attrs[NL80211_ATTR_STA_AID])
3068 return -EINVAL;
3069
Johannes Berg5727ef12007-12-19 02:03:34 +01003070 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3071 params.supported_rates =
3072 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3073 params.supported_rates_len =
3074 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3075 params.listen_interval =
3076 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003077
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003078 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3079 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3080 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003081
Jouni Malinen36aedc92008-08-25 11:58:58 +03003082 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3083 params.ht_capa =
3084 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003085
Javier Cardona96b78df2011-04-07 15:08:33 -07003086 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3087 params.plink_action =
3088 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3089
Johannes Bergbdd90d52011-12-14 12:20:27 +01003090 if (!rdev->ops->add_station)
3091 return -EOPNOTSUPP;
3092
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003093 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003094 return -EINVAL;
3095
Johannes Bergbdd90d52011-12-14 12:20:27 +01003096 switch (dev->ieee80211_ptr->iftype) {
3097 case NL80211_IFTYPE_AP:
3098 case NL80211_IFTYPE_AP_VLAN:
3099 case NL80211_IFTYPE_P2P_GO:
3100 /* parse WME attributes if sta is WME capable */
3101 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3102 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3103 info->attrs[NL80211_ATTR_STA_WME]) {
3104 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3105 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003106
Johannes Bergbdd90d52011-12-14 12:20:27 +01003107 nla = info->attrs[NL80211_ATTR_STA_WME];
3108 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3109 nl80211_sta_wme_policy);
3110 if (err)
3111 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003112
Johannes Bergbdd90d52011-12-14 12:20:27 +01003113 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3114 params.uapsd_queues =
3115 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3116 if (params.uapsd_queues &
3117 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3118 return -EINVAL;
3119
3120 if (tb[NL80211_STA_WME_MAX_SP])
3121 params.max_sp =
3122 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3123
3124 if (params.max_sp &
3125 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3126 return -EINVAL;
3127
3128 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3129 }
3130 /* TDLS peers cannot be added */
3131 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003132 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003133 /* but don't bother the driver with it */
3134 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003135
Johannes Bergbdd90d52011-12-14 12:20:27 +01003136 /* must be last in here for error handling */
3137 params.vlan = get_vlan(info, rdev);
3138 if (IS_ERR(params.vlan))
3139 return PTR_ERR(params.vlan);
3140 break;
3141 case NL80211_IFTYPE_MESH_POINT:
3142 /* TDLS peers cannot be added */
3143 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003144 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003145 break;
3146 case NL80211_IFTYPE_STATION:
3147 /* Only TDLS peers can be added */
3148 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3149 return -EINVAL;
3150 /* Can only add if TDLS ... */
3151 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3152 return -EOPNOTSUPP;
3153 /* ... with external setup is supported */
3154 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3155 return -EOPNOTSUPP;
3156 break;
3157 default:
3158 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003159 }
3160
Johannes Bergbdd90d52011-12-14 12:20:27 +01003161 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003162
Johannes Berg79c97e92009-07-07 03:56:12 +02003163 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003164
Johannes Berg5727ef12007-12-19 02:03:34 +01003165 if (params.vlan)
3166 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003167 return err;
3168}
3169
3170static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3171{
Johannes Berg4c476992010-10-04 21:36:35 +02003172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3173 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003174 u8 *mac_addr = NULL;
3175
3176 if (info->attrs[NL80211_ATTR_MAC])
3177 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3178
Johannes Berge80cf852009-05-11 14:43:13 +02003179 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003180 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003181 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3183 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003184
Johannes Berg4c476992010-10-04 21:36:35 +02003185 if (!rdev->ops->del_station)
3186 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003187
Johannes Berg4c476992010-10-04 21:36:35 +02003188 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003189}
3190
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003191static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3192 int flags, struct net_device *dev,
3193 u8 *dst, u8 *next_hop,
3194 struct mpath_info *pinfo)
3195{
3196 void *hdr;
3197 struct nlattr *pinfoattr;
3198
3199 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3200 if (!hdr)
3201 return -1;
3202
David S. Miller9360ffd2012-03-29 04:41:26 -04003203 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3204 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3205 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3206 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3207 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003208
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003209 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3210 if (!pinfoattr)
3211 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003212 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3213 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3214 pinfo->frame_qlen))
3215 goto nla_put_failure;
3216 if (((pinfo->filled & MPATH_INFO_SN) &&
3217 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3218 ((pinfo->filled & MPATH_INFO_METRIC) &&
3219 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3220 pinfo->metric)) ||
3221 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3222 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3223 pinfo->exptime)) ||
3224 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3225 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3226 pinfo->flags)) ||
3227 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3228 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3229 pinfo->discovery_timeout)) ||
3230 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3231 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3232 pinfo->discovery_retries)))
3233 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003234
3235 nla_nest_end(msg, pinfoattr);
3236
3237 return genlmsg_end(msg, hdr);
3238
3239 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003240 genlmsg_cancel(msg, hdr);
3241 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003242}
3243
3244static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003245 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003246{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003247 struct mpath_info pinfo;
3248 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003249 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003250 u8 dst[ETH_ALEN];
3251 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003252 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003253 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003254
Johannes Berg67748892010-10-04 21:14:06 +02003255 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3256 if (err)
3257 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003258
3259 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003260 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003261 goto out_err;
3262 }
3263
Jouni Malineneec60b02009-03-20 21:21:19 +02003264 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3265 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003266 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003267 }
3268
Johannes Bergbba95fe2008-07-29 13:22:51 +02003269 while (1) {
3270 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3271 dst, next_hop, &pinfo);
3272 if (err == -ENOENT)
3273 break;
3274 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003275 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003276
3277 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3278 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3279 netdev, dst, next_hop,
3280 &pinfo) < 0)
3281 goto out;
3282
3283 path_idx++;
3284 }
3285
3286
3287 out:
3288 cb->args[1] = path_idx;
3289 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003290 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003291 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003292 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003293}
3294
3295static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3296{
Johannes Berg4c476992010-10-04 21:36:35 +02003297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003298 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003299 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003300 struct mpath_info pinfo;
3301 struct sk_buff *msg;
3302 u8 *dst = NULL;
3303 u8 next_hop[ETH_ALEN];
3304
3305 memset(&pinfo, 0, sizeof(pinfo));
3306
3307 if (!info->attrs[NL80211_ATTR_MAC])
3308 return -EINVAL;
3309
3310 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3311
Johannes Berg4c476992010-10-04 21:36:35 +02003312 if (!rdev->ops->get_mpath)
3313 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003314
Johannes Berg4c476992010-10-04 21:36:35 +02003315 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3316 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003317
Johannes Berg79c97e92009-07-07 03:56:12 +02003318 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003319 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003320 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003321
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003322 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003323 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003324 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003325
3326 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003327 dev, dst, next_hop, &pinfo) < 0) {
3328 nlmsg_free(msg);
3329 return -ENOBUFS;
3330 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003331
Johannes Berg4c476992010-10-04 21:36:35 +02003332 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003333}
3334
3335static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3336{
Johannes Berg4c476992010-10-04 21:36:35 +02003337 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3338 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003339 u8 *dst = NULL;
3340 u8 *next_hop = NULL;
3341
3342 if (!info->attrs[NL80211_ATTR_MAC])
3343 return -EINVAL;
3344
3345 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3346 return -EINVAL;
3347
3348 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3349 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3350
Johannes Berg4c476992010-10-04 21:36:35 +02003351 if (!rdev->ops->change_mpath)
3352 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003353
Johannes Berg4c476992010-10-04 21:36:35 +02003354 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3355 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003356
Johannes Berg4c476992010-10-04 21:36:35 +02003357 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003358}
Johannes Berg4c476992010-10-04 21:36:35 +02003359
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003360static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3361{
Johannes Berg4c476992010-10-04 21:36:35 +02003362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3363 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003364 u8 *dst = NULL;
3365 u8 *next_hop = NULL;
3366
3367 if (!info->attrs[NL80211_ATTR_MAC])
3368 return -EINVAL;
3369
3370 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3371 return -EINVAL;
3372
3373 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3374 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3375
Johannes Berg4c476992010-10-04 21:36:35 +02003376 if (!rdev->ops->add_mpath)
3377 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003378
Johannes Berg4c476992010-10-04 21:36:35 +02003379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3380 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003381
Johannes Berg4c476992010-10-04 21:36:35 +02003382 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003383}
3384
3385static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3386{
Johannes Berg4c476992010-10-04 21:36:35 +02003387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3388 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003389 u8 *dst = NULL;
3390
3391 if (info->attrs[NL80211_ATTR_MAC])
3392 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3393
Johannes Berg4c476992010-10-04 21:36:35 +02003394 if (!rdev->ops->del_mpath)
3395 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003396
Johannes Berg4c476992010-10-04 21:36:35 +02003397 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003398}
3399
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003400static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3401{
Johannes Berg4c476992010-10-04 21:36:35 +02003402 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3403 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003404 struct bss_parameters params;
3405
3406 memset(&params, 0, sizeof(params));
3407 /* default to not changing parameters */
3408 params.use_cts_prot = -1;
3409 params.use_short_preamble = -1;
3410 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003411 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003412 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003413
3414 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3415 params.use_cts_prot =
3416 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3417 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3418 params.use_short_preamble =
3419 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3420 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3421 params.use_short_slot_time =
3422 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003423 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3424 params.basic_rates =
3425 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3426 params.basic_rates_len =
3427 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3428 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003429 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3430 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003431 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3432 params.ht_opmode =
3433 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003434
Johannes Berg4c476992010-10-04 21:36:35 +02003435 if (!rdev->ops->change_bss)
3436 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003437
Johannes Berg074ac8d2010-09-16 14:58:22 +02003438 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003439 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3440 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003441
Johannes Berg4c476992010-10-04 21:36:35 +02003442 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003443}
3444
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003445static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003446 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3447 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3448 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3449 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3450 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3451 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3452};
3453
3454static int parse_reg_rule(struct nlattr *tb[],
3455 struct ieee80211_reg_rule *reg_rule)
3456{
3457 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3458 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3459
3460 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3461 return -EINVAL;
3462 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3463 return -EINVAL;
3464 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3465 return -EINVAL;
3466 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3467 return -EINVAL;
3468 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3469 return -EINVAL;
3470
3471 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3472
3473 freq_range->start_freq_khz =
3474 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3475 freq_range->end_freq_khz =
3476 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3477 freq_range->max_bandwidth_khz =
3478 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3479
3480 power_rule->max_eirp =
3481 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3482
3483 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3484 power_rule->max_antenna_gain =
3485 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3486
3487 return 0;
3488}
3489
3490static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3491{
3492 int r;
3493 char *data = NULL;
3494
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003495 /*
3496 * You should only get this when cfg80211 hasn't yet initialized
3497 * completely when built-in to the kernel right between the time
3498 * window between nl80211_init() and regulatory_init(), if that is
3499 * even possible.
3500 */
3501 mutex_lock(&cfg80211_mutex);
3502 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003503 mutex_unlock(&cfg80211_mutex);
3504 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003505 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003506 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003507
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003508 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3509 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003510
3511 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3512
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003513 r = regulatory_hint_user(data);
3514
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003515 return r;
3516}
3517
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003518static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003519 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003520{
Johannes Berg4c476992010-10-04 21:36:35 +02003521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003522 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003523 struct wireless_dev *wdev = dev->ieee80211_ptr;
3524 struct mesh_config cur_params;
3525 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003526 void *hdr;
3527 struct nlattr *pinfoattr;
3528 struct sk_buff *msg;
3529
Johannes Berg29cbe682010-12-03 09:20:44 +01003530 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3531 return -EOPNOTSUPP;
3532
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003533 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003534 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003535
Johannes Berg29cbe682010-12-03 09:20:44 +01003536 wdev_lock(wdev);
3537 /* If not connected, get default parameters */
3538 if (!wdev->mesh_id_len)
3539 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3540 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003541 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003542 &cur_params);
3543 wdev_unlock(wdev);
3544
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003545 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003546 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003547
3548 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003550 if (!msg)
3551 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003552 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003553 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003554 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003555 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003556 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003557 if (!pinfoattr)
3558 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003559 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3560 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3561 cur_params.dot11MeshRetryTimeout) ||
3562 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3563 cur_params.dot11MeshConfirmTimeout) ||
3564 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3565 cur_params.dot11MeshHoldingTimeout) ||
3566 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3567 cur_params.dot11MeshMaxPeerLinks) ||
3568 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3569 cur_params.dot11MeshMaxRetries) ||
3570 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3571 cur_params.dot11MeshTTL) ||
3572 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3573 cur_params.element_ttl) ||
3574 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3575 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003576 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3577 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003578 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3579 cur_params.dot11MeshHWMPmaxPREQretries) ||
3580 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3581 cur_params.path_refresh_time) ||
3582 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3583 cur_params.min_discovery_timeout) ||
3584 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3585 cur_params.dot11MeshHWMPactivePathTimeout) ||
3586 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3587 cur_params.dot11MeshHWMPpreqMinInterval) ||
3588 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3589 cur_params.dot11MeshHWMPperrMinInterval) ||
3590 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3591 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3592 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3593 cur_params.dot11MeshHWMPRootMode) ||
3594 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3595 cur_params.dot11MeshHWMPRannInterval) ||
3596 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3597 cur_params.dot11MeshGateAnnouncementProtocol) ||
3598 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3599 cur_params.dot11MeshForwarding) ||
3600 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003601 cur_params.rssi_threshold) ||
3602 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003603 cur_params.ht_opmode) ||
3604 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3605 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3606 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003607 cur_params.dot11MeshHWMProotInterval) ||
3608 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3609 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003611 nla_nest_end(msg, pinfoattr);
3612 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003613 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003614
Johannes Berg3b858752009-03-12 09:55:09 +01003615 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003616 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003617 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003618 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003619 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003620}
3621
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003622static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003623 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3624 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3625 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3626 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3627 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3628 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003629 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003630 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003631 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003632 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3633 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3634 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3635 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3636 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003637 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003638 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003639 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003640 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003641 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003642 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003643 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3644 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003645 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3646 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003647 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003648};
3649
Javier Cardonac80d5452010-12-16 17:37:49 -08003650static const struct nla_policy
3651 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003652 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003653 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3654 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003655 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003656 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003657 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003658 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003659};
3660
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003661static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003662 struct mesh_config *cfg,
3663 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003664{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003665 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003666 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003667
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003668#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3669do {\
3670 if (table[attr_num]) {\
3671 cfg->param = nla_fn(table[attr_num]); \
3672 mask |= (1 << (attr_num - 1)); \
3673 } \
3674} while (0);\
3675
3676
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003677 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003678 return -EINVAL;
3679 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003680 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003681 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003682 return -EINVAL;
3683
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003684 /* This makes sure that there aren't more than 32 mesh config
3685 * parameters (otherwise our bitfield scheme would not work.) */
3686 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3687
3688 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003690 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3691 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003693 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3694 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003696 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3697 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003698 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003699 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3700 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003702 mask, NL80211_MESHCONF_MAX_RETRIES,
3703 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003705 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003706 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003707 mask, NL80211_MESHCONF_ELEMENT_TTL,
3708 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003710 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3711 nla_get_u8);
3712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3713 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3714 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003715 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003716 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3717 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003719 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3720 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003722 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3723 nla_get_u16);
3724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3725 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3726 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003728 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3729 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003731 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3732 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003734 dot11MeshHWMPnetDiameterTraversalTime, mask,
3735 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3736 nla_get_u16);
3737 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3738 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3739 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3740 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3741 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003742 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003743 dot11MeshGateAnnouncementProtocol, mask,
3744 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3745 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003747 mask, NL80211_MESHCONF_FORWARDING,
3748 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003749 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003750 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3751 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003752 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003753 mask, NL80211_MESHCONF_HT_OPMODE,
3754 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003755 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3756 mask,
3757 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3758 nla_get_u32);
3759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3760 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3761 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003762 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3763 dot11MeshHWMPconfirmationInterval, mask,
3764 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3765 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003766 if (mask_out)
3767 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003768
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003769 return 0;
3770
3771#undef FILL_IN_MESH_PARAM_IF_SET
3772}
3773
Javier Cardonac80d5452010-12-16 17:37:49 -08003774static int nl80211_parse_mesh_setup(struct genl_info *info,
3775 struct mesh_setup *setup)
3776{
3777 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3778
3779 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3780 return -EINVAL;
3781 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3782 info->attrs[NL80211_ATTR_MESH_SETUP],
3783 nl80211_mesh_setup_params_policy))
3784 return -EINVAL;
3785
Javier Cardonad299a1f2012-03-31 11:31:33 -07003786 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3787 setup->sync_method =
3788 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3789 IEEE80211_SYNC_METHOD_VENDOR :
3790 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3791
Javier Cardonac80d5452010-12-16 17:37:49 -08003792 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3793 setup->path_sel_proto =
3794 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3795 IEEE80211_PATH_PROTOCOL_VENDOR :
3796 IEEE80211_PATH_PROTOCOL_HWMP;
3797
3798 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3799 setup->path_metric =
3800 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3801 IEEE80211_PATH_METRIC_VENDOR :
3802 IEEE80211_PATH_METRIC_AIRTIME;
3803
Javier Cardona581a8b02011-04-07 15:08:27 -07003804
3805 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003806 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003807 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003808 if (!is_valid_ie_attr(ieattr))
3809 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003810 setup->ie = nla_data(ieattr);
3811 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003812 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003813 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3814 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003815
3816 return 0;
3817}
3818
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003819static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003820 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003821{
3822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3823 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003824 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003825 struct mesh_config cfg;
3826 u32 mask;
3827 int err;
3828
Johannes Berg29cbe682010-12-03 09:20:44 +01003829 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3830 return -EOPNOTSUPP;
3831
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003832 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003833 return -EOPNOTSUPP;
3834
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003835 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003836 if (err)
3837 return err;
3838
Johannes Berg29cbe682010-12-03 09:20:44 +01003839 wdev_lock(wdev);
3840 if (!wdev->mesh_id_len)
3841 err = -ENOLINK;
3842
3843 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003844 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003845 mask, &cfg);
3846
3847 wdev_unlock(wdev);
3848
3849 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003850}
3851
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003852static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3853{
3854 struct sk_buff *msg;
3855 void *hdr = NULL;
3856 struct nlattr *nl_reg_rules;
3857 unsigned int i;
3858 int err = -EINVAL;
3859
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003860 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003861
3862 if (!cfg80211_regdomain)
3863 goto out;
3864
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003866 if (!msg) {
3867 err = -ENOBUFS;
3868 goto out;
3869 }
3870
3871 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3872 NL80211_CMD_GET_REG);
3873 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003874 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003875
David S. Miller9360ffd2012-03-29 04:41:26 -04003876 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3877 cfg80211_regdomain->alpha2) ||
3878 (cfg80211_regdomain->dfs_region &&
3879 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3880 cfg80211_regdomain->dfs_region)))
3881 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003882
3883 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3884 if (!nl_reg_rules)
3885 goto nla_put_failure;
3886
3887 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3888 struct nlattr *nl_reg_rule;
3889 const struct ieee80211_reg_rule *reg_rule;
3890 const struct ieee80211_freq_range *freq_range;
3891 const struct ieee80211_power_rule *power_rule;
3892
3893 reg_rule = &cfg80211_regdomain->reg_rules[i];
3894 freq_range = &reg_rule->freq_range;
3895 power_rule = &reg_rule->power_rule;
3896
3897 nl_reg_rule = nla_nest_start(msg, i);
3898 if (!nl_reg_rule)
3899 goto nla_put_failure;
3900
David S. Miller9360ffd2012-03-29 04:41:26 -04003901 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3902 reg_rule->flags) ||
3903 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3904 freq_range->start_freq_khz) ||
3905 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3906 freq_range->end_freq_khz) ||
3907 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3908 freq_range->max_bandwidth_khz) ||
3909 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3910 power_rule->max_antenna_gain) ||
3911 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3912 power_rule->max_eirp))
3913 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003914
3915 nla_nest_end(msg, nl_reg_rule);
3916 }
3917
3918 nla_nest_end(msg, nl_reg_rules);
3919
3920 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003921 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003922 goto out;
3923
3924nla_put_failure:
3925 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003926put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003927 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003928 err = -EMSGSIZE;
3929out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003930 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003931 return err;
3932}
3933
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003934static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3935{
3936 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3937 struct nlattr *nl_reg_rule;
3938 char *alpha2 = NULL;
3939 int rem_reg_rules = 0, r = 0;
3940 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003941 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003942 struct ieee80211_regdomain *rd = NULL;
3943
3944 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3945 return -EINVAL;
3946
3947 if (!info->attrs[NL80211_ATTR_REG_RULES])
3948 return -EINVAL;
3949
3950 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3951
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003952 if (info->attrs[NL80211_ATTR_DFS_REGION])
3953 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3954
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003955 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3956 rem_reg_rules) {
3957 num_rules++;
3958 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003959 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003960 }
3961
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003962 mutex_lock(&cfg80211_mutex);
3963
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003964 if (!reg_is_valid_request(alpha2)) {
3965 r = -EINVAL;
3966 goto bad_reg;
3967 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003968
3969 size_of_regd = sizeof(struct ieee80211_regdomain) +
3970 (num_rules * sizeof(struct ieee80211_reg_rule));
3971
3972 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003973 if (!rd) {
3974 r = -ENOMEM;
3975 goto bad_reg;
3976 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003977
3978 rd->n_reg_rules = num_rules;
3979 rd->alpha2[0] = alpha2[0];
3980 rd->alpha2[1] = alpha2[1];
3981
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003982 /*
3983 * Disable DFS master mode if the DFS region was
3984 * not supported or known on this kernel.
3985 */
3986 if (reg_supported_dfs_region(dfs_region))
3987 rd->dfs_region = dfs_region;
3988
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003989 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3990 rem_reg_rules) {
3991 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3992 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3993 reg_rule_policy);
3994 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3995 if (r)
3996 goto bad_reg;
3997
3998 rule_idx++;
3999
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004000 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4001 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004002 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004003 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004004 }
4005
4006 BUG_ON(rule_idx != num_rules);
4007
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004008 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004009
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004010 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004011
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004012 return r;
4013
Johannes Bergd2372b32008-10-24 20:32:20 +02004014 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004015 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004016 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004017 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004018}
4019
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004020static int validate_scan_freqs(struct nlattr *freqs)
4021{
4022 struct nlattr *attr1, *attr2;
4023 int n_channels = 0, tmp1, tmp2;
4024
4025 nla_for_each_nested(attr1, freqs, tmp1) {
4026 n_channels++;
4027 /*
4028 * Some hardware has a limited channel list for
4029 * scanning, and it is pretty much nonsensical
4030 * to scan for a channel twice, so disallow that
4031 * and don't require drivers to check that the
4032 * channel list they get isn't longer than what
4033 * they can scan, as long as they can scan all
4034 * the channels they registered at once.
4035 */
4036 nla_for_each_nested(attr2, freqs, tmp2)
4037 if (attr1 != attr2 &&
4038 nla_get_u32(attr1) == nla_get_u32(attr2))
4039 return 0;
4040 }
4041
4042 return n_channels;
4043}
4044
Johannes Berg2a519312009-02-10 21:25:55 +01004045static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4046{
Johannes Berg4c476992010-10-04 21:36:35 +02004047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4048 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004049 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004050 struct nlattr *attr;
4051 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004052 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004053 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004054
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004055 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4056 return -EINVAL;
4057
Johannes Berg79c97e92009-07-07 03:56:12 +02004058 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004059
Johannes Berg4c476992010-10-04 21:36:35 +02004060 if (!rdev->ops->scan)
4061 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004062
Johannes Berg4c476992010-10-04 21:36:35 +02004063 if (rdev->scan_req)
4064 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004065
4066 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004067 n_channels = validate_scan_freqs(
4068 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004069 if (!n_channels)
4070 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004071 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004072 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004073 n_channels = 0;
4074
Johannes Berg2a519312009-02-10 21:25:55 +01004075 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4076 if (wiphy->bands[band])
4077 n_channels += wiphy->bands[band]->n_channels;
4078 }
4079
4080 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4081 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4082 n_ssids++;
4083
Johannes Berg4c476992010-10-04 21:36:35 +02004084 if (n_ssids > wiphy->max_scan_ssids)
4085 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004086
Jouni Malinen70692ad2009-02-16 19:39:13 +02004087 if (info->attrs[NL80211_ATTR_IE])
4088 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4089 else
4090 ie_len = 0;
4091
Johannes Berg4c476992010-10-04 21:36:35 +02004092 if (ie_len > wiphy->max_scan_ie_len)
4093 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004094
Johannes Berg2a519312009-02-10 21:25:55 +01004095 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004096 + sizeof(*request->ssids) * n_ssids
4097 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004098 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004099 if (!request)
4100 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004101
Johannes Berg2a519312009-02-10 21:25:55 +01004102 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004103 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004104 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004105 if (ie_len) {
4106 if (request->ssids)
4107 request->ie = (void *)(request->ssids + n_ssids);
4108 else
4109 request->ie = (void *)(request->channels + n_channels);
4110 }
Johannes Berg2a519312009-02-10 21:25:55 +01004111
Johannes Berg584991d2009-11-02 13:32:03 +01004112 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004113 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4114 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004115 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004116 struct ieee80211_channel *chan;
4117
4118 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4119
4120 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004121 err = -EINVAL;
4122 goto out_free;
4123 }
Johannes Berg584991d2009-11-02 13:32:03 +01004124
4125 /* ignore disabled channels */
4126 if (chan->flags & IEEE80211_CHAN_DISABLED)
4127 continue;
4128
4129 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004130 i++;
4131 }
4132 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004133 enum ieee80211_band band;
4134
Johannes Berg2a519312009-02-10 21:25:55 +01004135 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004136 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4137 int j;
4138 if (!wiphy->bands[band])
4139 continue;
4140 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004141 struct ieee80211_channel *chan;
4142
4143 chan = &wiphy->bands[band]->channels[j];
4144
4145 if (chan->flags & IEEE80211_CHAN_DISABLED)
4146 continue;
4147
4148 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004149 i++;
4150 }
4151 }
4152 }
4153
Johannes Berg584991d2009-11-02 13:32:03 +01004154 if (!i) {
4155 err = -EINVAL;
4156 goto out_free;
4157 }
4158
4159 request->n_channels = i;
4160
Johannes Berg2a519312009-02-10 21:25:55 +01004161 i = 0;
4162 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4163 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004164 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004165 err = -EINVAL;
4166 goto out_free;
4167 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004168 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004169 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004170 i++;
4171 }
4172 }
4173
Jouni Malinen70692ad2009-02-16 19:39:13 +02004174 if (info->attrs[NL80211_ATTR_IE]) {
4175 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004176 memcpy((void *)request->ie,
4177 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004178 request->ie_len);
4179 }
4180
Johannes Berg34850ab2011-07-18 18:08:35 +02004181 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004182 if (wiphy->bands[i])
4183 request->rates[i] =
4184 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004185
4186 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4187 nla_for_each_nested(attr,
4188 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4189 tmp) {
4190 enum ieee80211_band band = nla_type(attr);
4191
Dan Carpenter84404622011-07-29 11:52:18 +03004192 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004193 err = -EINVAL;
4194 goto out_free;
4195 }
4196 err = ieee80211_get_ratemask(wiphy->bands[band],
4197 nla_data(attr),
4198 nla_len(attr),
4199 &request->rates[band]);
4200 if (err)
4201 goto out_free;
4202 }
4203 }
4204
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304205 request->no_cck =
4206 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4207
Johannes Berg463d0182009-07-14 00:33:35 +02004208 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004209 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004210
Johannes Berg79c97e92009-07-07 03:56:12 +02004211 rdev->scan_req = request;
4212 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004213
Johannes Berg463d0182009-07-14 00:33:35 +02004214 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004215 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004216 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004217 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004218 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004219 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004220 kfree(request);
4221 }
Johannes Berg3b858752009-03-12 09:55:09 +01004222
Johannes Berg2a519312009-02-10 21:25:55 +01004223 return err;
4224}
4225
Luciano Coelho807f8a82011-05-11 17:09:35 +03004226static int nl80211_start_sched_scan(struct sk_buff *skb,
4227 struct genl_info *info)
4228{
4229 struct cfg80211_sched_scan_request *request;
4230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4231 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004232 struct nlattr *attr;
4233 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004234 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004235 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004236 enum ieee80211_band band;
4237 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004238 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004239
4240 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4241 !rdev->ops->sched_scan_start)
4242 return -EOPNOTSUPP;
4243
4244 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4245 return -EINVAL;
4246
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004247 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4248 return -EINVAL;
4249
4250 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4251 if (interval == 0)
4252 return -EINVAL;
4253
Luciano Coelho807f8a82011-05-11 17:09:35 +03004254 wiphy = &rdev->wiphy;
4255
4256 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4257 n_channels = validate_scan_freqs(
4258 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4259 if (!n_channels)
4260 return -EINVAL;
4261 } else {
4262 n_channels = 0;
4263
4264 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4265 if (wiphy->bands[band])
4266 n_channels += wiphy->bands[band]->n_channels;
4267 }
4268
4269 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4270 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4271 tmp)
4272 n_ssids++;
4273
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004274 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004275 return -EINVAL;
4276
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004277 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4278 nla_for_each_nested(attr,
4279 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4280 tmp)
4281 n_match_sets++;
4282
4283 if (n_match_sets > wiphy->max_match_sets)
4284 return -EINVAL;
4285
Luciano Coelho807f8a82011-05-11 17:09:35 +03004286 if (info->attrs[NL80211_ATTR_IE])
4287 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4288 else
4289 ie_len = 0;
4290
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004291 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004292 return -EINVAL;
4293
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004294 mutex_lock(&rdev->sched_scan_mtx);
4295
4296 if (rdev->sched_scan_req) {
4297 err = -EINPROGRESS;
4298 goto out;
4299 }
4300
Luciano Coelho807f8a82011-05-11 17:09:35 +03004301 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004302 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004303 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004304 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004305 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004306 if (!request) {
4307 err = -ENOMEM;
4308 goto out;
4309 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004310
4311 if (n_ssids)
4312 request->ssids = (void *)&request->channels[n_channels];
4313 request->n_ssids = n_ssids;
4314 if (ie_len) {
4315 if (request->ssids)
4316 request->ie = (void *)(request->ssids + n_ssids);
4317 else
4318 request->ie = (void *)(request->channels + n_channels);
4319 }
4320
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004321 if (n_match_sets) {
4322 if (request->ie)
4323 request->match_sets = (void *)(request->ie + ie_len);
4324 else if (request->ssids)
4325 request->match_sets =
4326 (void *)(request->ssids + n_ssids);
4327 else
4328 request->match_sets =
4329 (void *)(request->channels + n_channels);
4330 }
4331 request->n_match_sets = n_match_sets;
4332
Luciano Coelho807f8a82011-05-11 17:09:35 +03004333 i = 0;
4334 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4335 /* user specified, bail out if channel not found */
4336 nla_for_each_nested(attr,
4337 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4338 tmp) {
4339 struct ieee80211_channel *chan;
4340
4341 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4342
4343 if (!chan) {
4344 err = -EINVAL;
4345 goto out_free;
4346 }
4347
4348 /* ignore disabled channels */
4349 if (chan->flags & IEEE80211_CHAN_DISABLED)
4350 continue;
4351
4352 request->channels[i] = chan;
4353 i++;
4354 }
4355 } else {
4356 /* all channels */
4357 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4358 int j;
4359 if (!wiphy->bands[band])
4360 continue;
4361 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4362 struct ieee80211_channel *chan;
4363
4364 chan = &wiphy->bands[band]->channels[j];
4365
4366 if (chan->flags & IEEE80211_CHAN_DISABLED)
4367 continue;
4368
4369 request->channels[i] = chan;
4370 i++;
4371 }
4372 }
4373 }
4374
4375 if (!i) {
4376 err = -EINVAL;
4377 goto out_free;
4378 }
4379
4380 request->n_channels = i;
4381
4382 i = 0;
4383 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4384 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4385 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004386 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004387 err = -EINVAL;
4388 goto out_free;
4389 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004390 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004391 memcpy(request->ssids[i].ssid, nla_data(attr),
4392 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004393 i++;
4394 }
4395 }
4396
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004397 i = 0;
4398 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4399 nla_for_each_nested(attr,
4400 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4401 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004402 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004403
4404 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4405 nla_data(attr), nla_len(attr),
4406 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004407 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004408 if (ssid) {
4409 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4410 err = -EINVAL;
4411 goto out_free;
4412 }
4413 memcpy(request->match_sets[i].ssid.ssid,
4414 nla_data(ssid), nla_len(ssid));
4415 request->match_sets[i].ssid.ssid_len =
4416 nla_len(ssid);
4417 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004418 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4419 if (rssi)
4420 request->rssi_thold = nla_get_u32(rssi);
4421 else
4422 request->rssi_thold =
4423 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004424 i++;
4425 }
4426 }
4427
Luciano Coelho807f8a82011-05-11 17:09:35 +03004428 if (info->attrs[NL80211_ATTR_IE]) {
4429 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4430 memcpy((void *)request->ie,
4431 nla_data(info->attrs[NL80211_ATTR_IE]),
4432 request->ie_len);
4433 }
4434
4435 request->dev = dev;
4436 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004437 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004438
4439 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4440 if (!err) {
4441 rdev->sched_scan_req = request;
4442 nl80211_send_sched_scan(rdev, dev,
4443 NL80211_CMD_START_SCHED_SCAN);
4444 goto out;
4445 }
4446
4447out_free:
4448 kfree(request);
4449out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004450 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004451 return err;
4452}
4453
4454static int nl80211_stop_sched_scan(struct sk_buff *skb,
4455 struct genl_info *info)
4456{
4457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004458 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004459
4460 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4461 !rdev->ops->sched_scan_stop)
4462 return -EOPNOTSUPP;
4463
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004464 mutex_lock(&rdev->sched_scan_mtx);
4465 err = __cfg80211_stop_sched_scan(rdev, false);
4466 mutex_unlock(&rdev->sched_scan_mtx);
4467
4468 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004469}
4470
Johannes Berg9720bb32011-06-21 09:45:33 +02004471static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4472 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004473 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004474 struct wireless_dev *wdev,
4475 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004476{
Johannes Berg48ab9052009-07-10 18:42:31 +02004477 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004478 void *hdr;
4479 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004480
4481 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004482
Johannes Berg9720bb32011-06-21 09:45:33 +02004483 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004484 NL80211_CMD_NEW_SCAN_RESULTS);
4485 if (!hdr)
4486 return -1;
4487
Johannes Berg9720bb32011-06-21 09:45:33 +02004488 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4489
David S. Miller9360ffd2012-03-29 04:41:26 -04004490 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4491 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4492 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004493
4494 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4495 if (!bss)
4496 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004497 if ((!is_zero_ether_addr(res->bssid) &&
4498 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4499 (res->information_elements && res->len_information_elements &&
4500 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4501 res->len_information_elements,
4502 res->information_elements)) ||
4503 (res->beacon_ies && res->len_beacon_ies &&
4504 res->beacon_ies != res->information_elements &&
4505 nla_put(msg, NL80211_BSS_BEACON_IES,
4506 res->len_beacon_ies, res->beacon_ies)))
4507 goto nla_put_failure;
4508 if (res->tsf &&
4509 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4510 goto nla_put_failure;
4511 if (res->beacon_interval &&
4512 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4513 goto nla_put_failure;
4514 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4515 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4516 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4517 jiffies_to_msecs(jiffies - intbss->ts)))
4518 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004519
Johannes Berg77965c92009-02-18 18:45:06 +01004520 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004521 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004522 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4523 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004524 break;
4525 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004526 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4527 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004528 break;
4529 default:
4530 break;
4531 }
4532
Johannes Berg48ab9052009-07-10 18:42:31 +02004533 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004534 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004535 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004536 if (intbss == wdev->current_bss &&
4537 nla_put_u32(msg, NL80211_BSS_STATUS,
4538 NL80211_BSS_STATUS_ASSOCIATED))
4539 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004540 break;
4541 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004542 if (intbss == wdev->current_bss &&
4543 nla_put_u32(msg, NL80211_BSS_STATUS,
4544 NL80211_BSS_STATUS_IBSS_JOINED))
4545 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004546 break;
4547 default:
4548 break;
4549 }
4550
Johannes Berg2a519312009-02-10 21:25:55 +01004551 nla_nest_end(msg, bss);
4552
4553 return genlmsg_end(msg, hdr);
4554
4555 nla_put_failure:
4556 genlmsg_cancel(msg, hdr);
4557 return -EMSGSIZE;
4558}
4559
4560static int nl80211_dump_scan(struct sk_buff *skb,
4561 struct netlink_callback *cb)
4562{
Johannes Berg48ab9052009-07-10 18:42:31 +02004563 struct cfg80211_registered_device *rdev;
4564 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004565 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004566 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004567 int start = cb->args[1], idx = 0;
4568 int err;
4569
Johannes Berg67748892010-10-04 21:14:06 +02004570 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4571 if (err)
4572 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004573
Johannes Berg48ab9052009-07-10 18:42:31 +02004574 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004575
Johannes Berg48ab9052009-07-10 18:42:31 +02004576 wdev_lock(wdev);
4577 spin_lock_bh(&rdev->bss_lock);
4578 cfg80211_bss_expire(rdev);
4579
Johannes Berg9720bb32011-06-21 09:45:33 +02004580 cb->seq = rdev->bss_generation;
4581
Johannes Berg48ab9052009-07-10 18:42:31 +02004582 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004583 if (++idx <= start)
4584 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004585 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004586 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004587 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004588 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004589 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004590 }
4591 }
4592
Johannes Berg48ab9052009-07-10 18:42:31 +02004593 spin_unlock_bh(&rdev->bss_lock);
4594 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004595
4596 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004597 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004598
Johannes Berg67748892010-10-04 21:14:06 +02004599 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004600}
4601
Holger Schurig61fa7132009-11-11 12:25:40 +01004602static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4603 int flags, struct net_device *dev,
4604 struct survey_info *survey)
4605{
4606 void *hdr;
4607 struct nlattr *infoattr;
4608
Holger Schurig61fa7132009-11-11 12:25:40 +01004609 hdr = nl80211hdr_put(msg, pid, seq, flags,
4610 NL80211_CMD_NEW_SURVEY_RESULTS);
4611 if (!hdr)
4612 return -ENOMEM;
4613
David S. Miller9360ffd2012-03-29 04:41:26 -04004614 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4615 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004616
4617 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4618 if (!infoattr)
4619 goto nla_put_failure;
4620
David S. Miller9360ffd2012-03-29 04:41:26 -04004621 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4622 survey->channel->center_freq))
4623 goto nla_put_failure;
4624
4625 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4626 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4627 goto nla_put_failure;
4628 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4629 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4630 goto nla_put_failure;
4631 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4632 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4633 survey->channel_time))
4634 goto nla_put_failure;
4635 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4636 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4637 survey->channel_time_busy))
4638 goto nla_put_failure;
4639 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4640 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4641 survey->channel_time_ext_busy))
4642 goto nla_put_failure;
4643 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4644 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4645 survey->channel_time_rx))
4646 goto nla_put_failure;
4647 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4648 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4649 survey->channel_time_tx))
4650 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004651
4652 nla_nest_end(msg, infoattr);
4653
4654 return genlmsg_end(msg, hdr);
4655
4656 nla_put_failure:
4657 genlmsg_cancel(msg, hdr);
4658 return -EMSGSIZE;
4659}
4660
4661static int nl80211_dump_survey(struct sk_buff *skb,
4662 struct netlink_callback *cb)
4663{
4664 struct survey_info survey;
4665 struct cfg80211_registered_device *dev;
4666 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004667 int survey_idx = cb->args[1];
4668 int res;
4669
Johannes Berg67748892010-10-04 21:14:06 +02004670 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4671 if (res)
4672 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004673
4674 if (!dev->ops->dump_survey) {
4675 res = -EOPNOTSUPP;
4676 goto out_err;
4677 }
4678
4679 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004680 struct ieee80211_channel *chan;
4681
Holger Schurig61fa7132009-11-11 12:25:40 +01004682 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4683 &survey);
4684 if (res == -ENOENT)
4685 break;
4686 if (res)
4687 goto out_err;
4688
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004689 /* Survey without a channel doesn't make sense */
4690 if (!survey.channel) {
4691 res = -EINVAL;
4692 goto out;
4693 }
4694
4695 chan = ieee80211_get_channel(&dev->wiphy,
4696 survey.channel->center_freq);
4697 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4698 survey_idx++;
4699 continue;
4700 }
4701
Holger Schurig61fa7132009-11-11 12:25:40 +01004702 if (nl80211_send_survey(skb,
4703 NETLINK_CB(cb->skb).pid,
4704 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4705 netdev,
4706 &survey) < 0)
4707 goto out;
4708 survey_idx++;
4709 }
4710
4711 out:
4712 cb->args[1] = survey_idx;
4713 res = skb->len;
4714 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004715 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004716 return res;
4717}
4718
Jouni Malinen255e7372009-03-20 21:21:17 +02004719static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4720{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004721 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004722}
4723
Samuel Ortizb23aa672009-07-01 21:26:54 +02004724static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4725{
4726 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4727 NL80211_WPA_VERSION_2));
4728}
4729
Jouni Malinen636a5d32009-03-19 13:39:22 +02004730static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4731{
Johannes Berg4c476992010-10-04 21:36:35 +02004732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4733 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004734 struct ieee80211_channel *chan;
4735 const u8 *bssid, *ssid, *ie = NULL;
4736 int err, ssid_len, ie_len = 0;
4737 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004738 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004739 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004740
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004741 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4742 return -EINVAL;
4743
4744 if (!info->attrs[NL80211_ATTR_MAC])
4745 return -EINVAL;
4746
Jouni Malinen17780922009-03-27 20:52:47 +02004747 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4748 return -EINVAL;
4749
Johannes Berg19957bb2009-07-02 17:20:43 +02004750 if (!info->attrs[NL80211_ATTR_SSID])
4751 return -EINVAL;
4752
4753 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4754 return -EINVAL;
4755
Johannes Bergfffd0932009-07-08 14:22:54 +02004756 err = nl80211_parse_key(info, &key);
4757 if (err)
4758 return err;
4759
4760 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004761 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4762 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004763 if (!key.p.key || !key.p.key_len)
4764 return -EINVAL;
4765 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4766 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4767 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4768 key.p.key_len != WLAN_KEY_LEN_WEP104))
4769 return -EINVAL;
4770 if (key.idx > 4)
4771 return -EINVAL;
4772 } else {
4773 key.p.key_len = 0;
4774 key.p.key = NULL;
4775 }
4776
Johannes Bergafea0b72010-08-10 09:46:42 +02004777 if (key.idx >= 0) {
4778 int i;
4779 bool ok = false;
4780 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4781 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4782 ok = true;
4783 break;
4784 }
4785 }
Johannes Berg4c476992010-10-04 21:36:35 +02004786 if (!ok)
4787 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004788 }
4789
Johannes Berg4c476992010-10-04 21:36:35 +02004790 if (!rdev->ops->auth)
4791 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004792
Johannes Berg074ac8d2010-09-16 14:58:22 +02004793 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004794 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4795 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004796
Johannes Berg19957bb2009-07-02 17:20:43 +02004797 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004798 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004799 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004800 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4801 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004802
Johannes Berg19957bb2009-07-02 17:20:43 +02004803 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4804 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4805
4806 if (info->attrs[NL80211_ATTR_IE]) {
4807 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4808 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4809 }
4810
4811 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004812 if (!nl80211_valid_auth_type(auth_type))
4813 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004814
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004815 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4816
Johannes Berg95de8172012-01-20 13:55:25 +01004817 /*
4818 * Since we no longer track auth state, ignore
4819 * requests to only change local state.
4820 */
4821 if (local_state_change)
4822 return 0;
4823
Johannes Berg4c476992010-10-04 21:36:35 +02004824 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4825 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004826 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004827}
4828
Johannes Bergc0692b82010-08-27 14:26:53 +03004829static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4830 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004831 struct cfg80211_crypto_settings *settings,
4832 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004833{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004834 memset(settings, 0, sizeof(*settings));
4835
Samuel Ortizb23aa672009-07-01 21:26:54 +02004836 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4837
Johannes Bergc0692b82010-08-27 14:26:53 +03004838 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4839 u16 proto;
4840 proto = nla_get_u16(
4841 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4842 settings->control_port_ethertype = cpu_to_be16(proto);
4843 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4844 proto != ETH_P_PAE)
4845 return -EINVAL;
4846 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4847 settings->control_port_no_encrypt = true;
4848 } else
4849 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4850
Samuel Ortizb23aa672009-07-01 21:26:54 +02004851 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4852 void *data;
4853 int len, i;
4854
4855 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4856 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4857 settings->n_ciphers_pairwise = len / sizeof(u32);
4858
4859 if (len % sizeof(u32))
4860 return -EINVAL;
4861
Johannes Berg3dc27d22009-07-02 21:36:37 +02004862 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004863 return -EINVAL;
4864
4865 memcpy(settings->ciphers_pairwise, data, len);
4866
4867 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004868 if (!cfg80211_supported_cipher_suite(
4869 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004870 settings->ciphers_pairwise[i]))
4871 return -EINVAL;
4872 }
4873
4874 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4875 settings->cipher_group =
4876 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004877 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4878 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004879 return -EINVAL;
4880 }
4881
4882 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4883 settings->wpa_versions =
4884 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4885 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4886 return -EINVAL;
4887 }
4888
4889 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4890 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004891 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004892
4893 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4894 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4895 settings->n_akm_suites = len / sizeof(u32);
4896
4897 if (len % sizeof(u32))
4898 return -EINVAL;
4899
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004900 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4901 return -EINVAL;
4902
Samuel Ortizb23aa672009-07-01 21:26:54 +02004903 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004904 }
4905
4906 return 0;
4907}
4908
Jouni Malinen636a5d32009-03-19 13:39:22 +02004909static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4910{
Johannes Berg4c476992010-10-04 21:36:35 +02004911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4912 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004913 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004914 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004915 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004916 int err, ssid_len, ie_len = 0;
4917 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004918 u32 flags = 0;
4919 struct ieee80211_ht_cap *ht_capa = NULL;
4920 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004921
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004922 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4923 return -EINVAL;
4924
4925 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004926 !info->attrs[NL80211_ATTR_SSID] ||
4927 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004928 return -EINVAL;
4929
Johannes Berg4c476992010-10-04 21:36:35 +02004930 if (!rdev->ops->assoc)
4931 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004932
Johannes Berg074ac8d2010-09-16 14:58:22 +02004933 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004934 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4935 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004936
Johannes Berg19957bb2009-07-02 17:20:43 +02004937 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004938
Johannes Berg19957bb2009-07-02 17:20:43 +02004939 chan = ieee80211_get_channel(&rdev->wiphy,
4940 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004941 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4942 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004943
Johannes Berg19957bb2009-07-02 17:20:43 +02004944 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4945 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004946
4947 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004948 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4949 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004950 }
4951
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004952 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004953 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004954 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004955 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004956 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004957 else if (mfp != NL80211_MFP_NO)
4958 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03004959 }
4960
Johannes Berg3e5d7642009-07-07 14:37:26 +02004961 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4962 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4963
Ben Greear7e7c8922011-11-18 11:31:59 -08004964 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4965 flags |= ASSOC_REQ_DISABLE_HT;
4966
4967 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4968 ht_capa_mask =
4969 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4970
4971 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4972 if (!ht_capa_mask)
4973 return -EINVAL;
4974 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4975 }
4976
Johannes Bergc0692b82010-08-27 14:26:53 +03004977 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004978 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004979 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4980 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004981 &crypto, flags, ht_capa,
4982 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004983
Jouni Malinen636a5d32009-03-19 13:39:22 +02004984 return err;
4985}
4986
4987static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4988{
Johannes Berg4c476992010-10-04 21:36:35 +02004989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4990 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004991 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004992 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004993 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004994 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004995
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004996 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4997 return -EINVAL;
4998
4999 if (!info->attrs[NL80211_ATTR_MAC])
5000 return -EINVAL;
5001
5002 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5003 return -EINVAL;
5004
Johannes Berg4c476992010-10-04 21:36:35 +02005005 if (!rdev->ops->deauth)
5006 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005007
Johannes Berg074ac8d2010-09-16 14:58:22 +02005008 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005009 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5010 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005011
Johannes Berg19957bb2009-07-02 17:20:43 +02005012 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005013
Johannes Berg19957bb2009-07-02 17:20:43 +02005014 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5015 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005016 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005017 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005018 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005019
5020 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005021 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5022 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005023 }
5024
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005025 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5026
Johannes Berg4c476992010-10-04 21:36:35 +02005027 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5028 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005029}
5030
5031static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5032{
Johannes Berg4c476992010-10-04 21:36:35 +02005033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5034 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005035 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005036 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005037 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005038 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005039
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005040 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5041 return -EINVAL;
5042
5043 if (!info->attrs[NL80211_ATTR_MAC])
5044 return -EINVAL;
5045
5046 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5047 return -EINVAL;
5048
Johannes Berg4c476992010-10-04 21:36:35 +02005049 if (!rdev->ops->disassoc)
5050 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005051
Johannes Berg074ac8d2010-09-16 14:58:22 +02005052 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005053 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5054 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005055
Johannes Berg19957bb2009-07-02 17:20:43 +02005056 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005057
Johannes Berg19957bb2009-07-02 17:20:43 +02005058 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5059 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005060 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005061 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005062 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005063
5064 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005065 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5066 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005067 }
5068
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005069 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5070
Johannes Berg4c476992010-10-04 21:36:35 +02005071 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5072 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005073}
5074
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005075static bool
5076nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5077 int mcast_rate[IEEE80211_NUM_BANDS],
5078 int rateval)
5079{
5080 struct wiphy *wiphy = &rdev->wiphy;
5081 bool found = false;
5082 int band, i;
5083
5084 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5085 struct ieee80211_supported_band *sband;
5086
5087 sband = wiphy->bands[band];
5088 if (!sband)
5089 continue;
5090
5091 for (i = 0; i < sband->n_bitrates; i++) {
5092 if (sband->bitrates[i].bitrate == rateval) {
5093 mcast_rate[band] = i + 1;
5094 found = true;
5095 break;
5096 }
5097 }
5098 }
5099
5100 return found;
5101}
5102
Johannes Berg04a773a2009-04-19 21:24:32 +02005103static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5104{
Johannes Berg4c476992010-10-04 21:36:35 +02005105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5106 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005107 struct cfg80211_ibss_params ibss;
5108 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005109 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005110 int err;
5111
Johannes Berg8e30bc52009-04-22 17:45:38 +02005112 memset(&ibss, 0, sizeof(ibss));
5113
Johannes Berg04a773a2009-04-19 21:24:32 +02005114 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5115 return -EINVAL;
5116
5117 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5118 !info->attrs[NL80211_ATTR_SSID] ||
5119 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5120 return -EINVAL;
5121
Johannes Berg8e30bc52009-04-22 17:45:38 +02005122 ibss.beacon_interval = 100;
5123
5124 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5125 ibss.beacon_interval =
5126 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5127 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5128 return -EINVAL;
5129 }
5130
Johannes Berg4c476992010-10-04 21:36:35 +02005131 if (!rdev->ops->join_ibss)
5132 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005133
Johannes Berg4c476992010-10-04 21:36:35 +02005134 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5135 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005136
Johannes Berg79c97e92009-07-07 03:56:12 +02005137 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005138
Johannes Berg39193492011-09-16 13:45:25 +02005139 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005140 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005141
5142 if (!is_valid_ether_addr(ibss.bssid))
5143 return -EINVAL;
5144 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005145 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5146 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5147
5148 if (info->attrs[NL80211_ATTR_IE]) {
5149 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5150 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5151 }
5152
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005153 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5154 enum nl80211_channel_type channel_type;
5155
Johannes Bergcd6c6592012-05-10 21:27:18 +02005156 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005157 return -EINVAL;
5158
5159 if (channel_type != NL80211_CHAN_NO_HT &&
5160 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5161 return -EINVAL;
5162
5163 ibss.channel_type = channel_type;
5164 } else {
5165 ibss.channel_type = NL80211_CHAN_NO_HT;
5166 }
5167
5168 ibss.channel = rdev_freq_to_chan(rdev,
5169 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5170 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005171 if (!ibss.channel ||
5172 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005173 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5174 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005175
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005176 /* Both channels should be able to initiate communication */
5177 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5178 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5179 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5180 ibss.channel_type))
5181 return -EINVAL;
5182
Johannes Berg04a773a2009-04-19 21:24:32 +02005183 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005184 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005185
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005186 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5187 u8 *rates =
5188 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5189 int n_rates =
5190 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5191 struct ieee80211_supported_band *sband =
5192 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005193
Johannes Berg34850ab2011-07-18 18:08:35 +02005194 err = ieee80211_get_ratemask(sband, rates, n_rates,
5195 &ibss.basic_rates);
5196 if (err)
5197 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005198 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005199
5200 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5201 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5202 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5203 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005204
Johannes Berg4c476992010-10-04 21:36:35 +02005205 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5206 connkeys = nl80211_parse_connkeys(rdev,
5207 info->attrs[NL80211_ATTR_KEYS]);
5208 if (IS_ERR(connkeys))
5209 return PTR_ERR(connkeys);
5210 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005211
Antonio Quartulli267335d2012-01-31 20:25:47 +01005212 ibss.control_port =
5213 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5214
Johannes Berg4c476992010-10-04 21:36:35 +02005215 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005216 if (err)
5217 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005218 return err;
5219}
5220
5221static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5222{
Johannes Berg4c476992010-10-04 21:36:35 +02005223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5224 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005225
Johannes Berg4c476992010-10-04 21:36:35 +02005226 if (!rdev->ops->leave_ibss)
5227 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005228
Johannes Berg4c476992010-10-04 21:36:35 +02005229 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5230 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005231
Johannes Berg4c476992010-10-04 21:36:35 +02005232 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005233}
5234
Johannes Bergaff89a92009-07-01 21:26:51 +02005235#ifdef CONFIG_NL80211_TESTMODE
5236static struct genl_multicast_group nl80211_testmode_mcgrp = {
5237 .name = "testmode",
5238};
5239
5240static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5241{
Johannes Berg4c476992010-10-04 21:36:35 +02005242 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005243 int err;
5244
5245 if (!info->attrs[NL80211_ATTR_TESTDATA])
5246 return -EINVAL;
5247
Johannes Bergaff89a92009-07-01 21:26:51 +02005248 err = -EOPNOTSUPP;
5249 if (rdev->ops->testmode_cmd) {
5250 rdev->testmode_info = info;
5251 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5252 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5253 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5254 rdev->testmode_info = NULL;
5255 }
5256
Johannes Bergaff89a92009-07-01 21:26:51 +02005257 return err;
5258}
5259
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005260static int nl80211_testmode_dump(struct sk_buff *skb,
5261 struct netlink_callback *cb)
5262{
Johannes Berg00918d32011-12-13 17:22:05 +01005263 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005264 int err;
5265 long phy_idx;
5266 void *data = NULL;
5267 int data_len = 0;
5268
5269 if (cb->args[0]) {
5270 /*
5271 * 0 is a valid index, but not valid for args[0],
5272 * so we need to offset by 1.
5273 */
5274 phy_idx = cb->args[0] - 1;
5275 } else {
5276 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5277 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5278 nl80211_policy);
5279 if (err)
5280 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005281
Johannes Berg2bd7e352012-06-15 14:23:16 +02005282 mutex_lock(&cfg80211_mutex);
5283 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5284 nl80211_fam.attrbuf);
5285 if (IS_ERR(rdev)) {
5286 mutex_unlock(&cfg80211_mutex);
5287 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005288 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005289 phy_idx = rdev->wiphy_idx;
5290 rdev = NULL;
5291 mutex_unlock(&cfg80211_mutex);
5292
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005293 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5294 cb->args[1] =
5295 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5296 }
5297
5298 if (cb->args[1]) {
5299 data = nla_data((void *)cb->args[1]);
5300 data_len = nla_len((void *)cb->args[1]);
5301 }
5302
5303 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005304 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5305 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005306 mutex_unlock(&cfg80211_mutex);
5307 return -ENOENT;
5308 }
Johannes Berg00918d32011-12-13 17:22:05 +01005309 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005310 mutex_unlock(&cfg80211_mutex);
5311
Johannes Berg00918d32011-12-13 17:22:05 +01005312 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005313 err = -EOPNOTSUPP;
5314 goto out_err;
5315 }
5316
5317 while (1) {
5318 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5319 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5320 NL80211_CMD_TESTMODE);
5321 struct nlattr *tmdata;
5322
David S. Miller9360ffd2012-03-29 04:41:26 -04005323 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005324 genlmsg_cancel(skb, hdr);
5325 break;
5326 }
5327
5328 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5329 if (!tmdata) {
5330 genlmsg_cancel(skb, hdr);
5331 break;
5332 }
Johannes Berg00918d32011-12-13 17:22:05 +01005333 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5334 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005335 nla_nest_end(skb, tmdata);
5336
5337 if (err == -ENOBUFS || err == -ENOENT) {
5338 genlmsg_cancel(skb, hdr);
5339 break;
5340 } else if (err) {
5341 genlmsg_cancel(skb, hdr);
5342 goto out_err;
5343 }
5344
5345 genlmsg_end(skb, hdr);
5346 }
5347
5348 err = skb->len;
5349 /* see above */
5350 cb->args[0] = phy_idx + 1;
5351 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005352 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005353 return err;
5354}
5355
Johannes Bergaff89a92009-07-01 21:26:51 +02005356static struct sk_buff *
5357__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5358 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5359{
5360 struct sk_buff *skb;
5361 void *hdr;
5362 struct nlattr *data;
5363
5364 skb = nlmsg_new(approxlen + 100, gfp);
5365 if (!skb)
5366 return NULL;
5367
5368 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5369 if (!hdr) {
5370 kfree_skb(skb);
5371 return NULL;
5372 }
5373
David S. Miller9360ffd2012-03-29 04:41:26 -04005374 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5375 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005376 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5377
5378 ((void **)skb->cb)[0] = rdev;
5379 ((void **)skb->cb)[1] = hdr;
5380 ((void **)skb->cb)[2] = data;
5381
5382 return skb;
5383
5384 nla_put_failure:
5385 kfree_skb(skb);
5386 return NULL;
5387}
5388
5389struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5390 int approxlen)
5391{
5392 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5393
5394 if (WARN_ON(!rdev->testmode_info))
5395 return NULL;
5396
5397 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5398 rdev->testmode_info->snd_pid,
5399 rdev->testmode_info->snd_seq,
5400 GFP_KERNEL);
5401}
5402EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5403
5404int cfg80211_testmode_reply(struct sk_buff *skb)
5405{
5406 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5407 void *hdr = ((void **)skb->cb)[1];
5408 struct nlattr *data = ((void **)skb->cb)[2];
5409
5410 if (WARN_ON(!rdev->testmode_info)) {
5411 kfree_skb(skb);
5412 return -EINVAL;
5413 }
5414
5415 nla_nest_end(skb, data);
5416 genlmsg_end(skb, hdr);
5417 return genlmsg_reply(skb, rdev->testmode_info);
5418}
5419EXPORT_SYMBOL(cfg80211_testmode_reply);
5420
5421struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5422 int approxlen, gfp_t gfp)
5423{
5424 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5425
5426 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5427}
5428EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5429
5430void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5431{
5432 void *hdr = ((void **)skb->cb)[1];
5433 struct nlattr *data = ((void **)skb->cb)[2];
5434
5435 nla_nest_end(skb, data);
5436 genlmsg_end(skb, hdr);
5437 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5438}
5439EXPORT_SYMBOL(cfg80211_testmode_event);
5440#endif
5441
Samuel Ortizb23aa672009-07-01 21:26:54 +02005442static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5443{
Johannes Berg4c476992010-10-04 21:36:35 +02005444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5445 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005446 struct cfg80211_connect_params connect;
5447 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005448 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005449 int err;
5450
5451 memset(&connect, 0, sizeof(connect));
5452
5453 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5454 return -EINVAL;
5455
5456 if (!info->attrs[NL80211_ATTR_SSID] ||
5457 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5458 return -EINVAL;
5459
5460 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5461 connect.auth_type =
5462 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5463 if (!nl80211_valid_auth_type(connect.auth_type))
5464 return -EINVAL;
5465 } else
5466 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5467
5468 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5469
Johannes Bergc0692b82010-08-27 14:26:53 +03005470 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005471 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005472 if (err)
5473 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005474
Johannes Berg074ac8d2010-09-16 14:58:22 +02005475 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005476 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5477 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005478
Johannes Berg79c97e92009-07-07 03:56:12 +02005479 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005480
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305481 connect.bg_scan_period = -1;
5482 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5483 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5484 connect.bg_scan_period =
5485 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5486 }
5487
Samuel Ortizb23aa672009-07-01 21:26:54 +02005488 if (info->attrs[NL80211_ATTR_MAC])
5489 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5490 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5491 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5492
5493 if (info->attrs[NL80211_ATTR_IE]) {
5494 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5495 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5496 }
5497
5498 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5499 connect.channel =
5500 ieee80211_get_channel(wiphy,
5501 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5502 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005503 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5504 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005505 }
5506
Johannes Bergfffd0932009-07-08 14:22:54 +02005507 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5508 connkeys = nl80211_parse_connkeys(rdev,
5509 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005510 if (IS_ERR(connkeys))
5511 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005512 }
5513
Ben Greear7e7c8922011-11-18 11:31:59 -08005514 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5515 connect.flags |= ASSOC_REQ_DISABLE_HT;
5516
5517 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5518 memcpy(&connect.ht_capa_mask,
5519 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5520 sizeof(connect.ht_capa_mask));
5521
5522 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5523 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5524 return -EINVAL;
5525 memcpy(&connect.ht_capa,
5526 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5527 sizeof(connect.ht_capa));
5528 }
5529
Johannes Bergfffd0932009-07-08 14:22:54 +02005530 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005531 if (err)
5532 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005533 return err;
5534}
5535
5536static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5537{
Johannes Berg4c476992010-10-04 21:36:35 +02005538 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5539 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005540 u16 reason;
5541
5542 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5543 reason = WLAN_REASON_DEAUTH_LEAVING;
5544 else
5545 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5546
5547 if (reason == 0)
5548 return -EINVAL;
5549
Johannes Berg074ac8d2010-09-16 14:58:22 +02005550 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005551 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5552 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005553
Johannes Berg4c476992010-10-04 21:36:35 +02005554 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005555}
5556
Johannes Berg463d0182009-07-14 00:33:35 +02005557static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5558{
Johannes Berg4c476992010-10-04 21:36:35 +02005559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005560 struct net *net;
5561 int err;
5562 u32 pid;
5563
5564 if (!info->attrs[NL80211_ATTR_PID])
5565 return -EINVAL;
5566
5567 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5568
Johannes Berg463d0182009-07-14 00:33:35 +02005569 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005570 if (IS_ERR(net))
5571 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005572
5573 err = 0;
5574
5575 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005576 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5577 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005578
Johannes Berg463d0182009-07-14 00:33:35 +02005579 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005580 return err;
5581}
5582
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005583static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5584{
Johannes Berg4c476992010-10-04 21:36:35 +02005585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005586 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5587 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005588 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005589 struct cfg80211_pmksa pmksa;
5590
5591 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5592
5593 if (!info->attrs[NL80211_ATTR_MAC])
5594 return -EINVAL;
5595
5596 if (!info->attrs[NL80211_ATTR_PMKID])
5597 return -EINVAL;
5598
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005599 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5600 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5601
Johannes Berg074ac8d2010-09-16 14:58:22 +02005602 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005603 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5604 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005605
5606 switch (info->genlhdr->cmd) {
5607 case NL80211_CMD_SET_PMKSA:
5608 rdev_ops = rdev->ops->set_pmksa;
5609 break;
5610 case NL80211_CMD_DEL_PMKSA:
5611 rdev_ops = rdev->ops->del_pmksa;
5612 break;
5613 default:
5614 WARN_ON(1);
5615 break;
5616 }
5617
Johannes Berg4c476992010-10-04 21:36:35 +02005618 if (!rdev_ops)
5619 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005620
Johannes Berg4c476992010-10-04 21:36:35 +02005621 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005622}
5623
5624static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5625{
Johannes Berg4c476992010-10-04 21:36:35 +02005626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5627 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005628
Johannes Berg074ac8d2010-09-16 14:58:22 +02005629 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005630 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5631 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005632
Johannes Berg4c476992010-10-04 21:36:35 +02005633 if (!rdev->ops->flush_pmksa)
5634 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005635
Johannes Berg4c476992010-10-04 21:36:35 +02005636 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005637}
5638
Arik Nemtsov109086c2011-09-28 14:12:50 +03005639static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5640{
5641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5642 struct net_device *dev = info->user_ptr[1];
5643 u8 action_code, dialog_token;
5644 u16 status_code;
5645 u8 *peer;
5646
5647 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5648 !rdev->ops->tdls_mgmt)
5649 return -EOPNOTSUPP;
5650
5651 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5652 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5653 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5654 !info->attrs[NL80211_ATTR_IE] ||
5655 !info->attrs[NL80211_ATTR_MAC])
5656 return -EINVAL;
5657
5658 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5659 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5660 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5661 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5662
5663 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5664 dialog_token, status_code,
5665 nla_data(info->attrs[NL80211_ATTR_IE]),
5666 nla_len(info->attrs[NL80211_ATTR_IE]));
5667}
5668
5669static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5670{
5671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5672 struct net_device *dev = info->user_ptr[1];
5673 enum nl80211_tdls_operation operation;
5674 u8 *peer;
5675
5676 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5677 !rdev->ops->tdls_oper)
5678 return -EOPNOTSUPP;
5679
5680 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5681 !info->attrs[NL80211_ATTR_MAC])
5682 return -EINVAL;
5683
5684 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5685 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5686
5687 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5688}
5689
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005690static int nl80211_remain_on_channel(struct sk_buff *skb,
5691 struct genl_info *info)
5692{
Johannes Berg4c476992010-10-04 21:36:35 +02005693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5694 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005695 struct ieee80211_channel *chan;
5696 struct sk_buff *msg;
5697 void *hdr;
5698 u64 cookie;
5699 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5700 u32 freq, duration;
5701 int err;
5702
5703 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5704 !info->attrs[NL80211_ATTR_DURATION])
5705 return -EINVAL;
5706
5707 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5708
Johannes Berg7c4ef712011-11-18 15:33:48 +01005709 if (!rdev->ops->remain_on_channel ||
5710 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005711 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005712
Johannes Bergebf348f2012-06-01 12:50:54 +02005713 /*
5714 * We should be on that channel for at least a minimum amount of
5715 * time (10ms) but no longer than the driver supports.
5716 */
5717 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5718 duration > rdev->wiphy.max_remain_on_channel_duration)
5719 return -EINVAL;
5720
Johannes Bergcd6c6592012-05-10 21:27:18 +02005721 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5722 !nl80211_valid_channel_type(info, &channel_type))
5723 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005724
5725 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5726 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005727 if (chan == NULL)
5728 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005729
5730 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005731 if (!msg)
5732 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005733
5734 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5735 NL80211_CMD_REMAIN_ON_CHANNEL);
5736
5737 if (IS_ERR(hdr)) {
5738 err = PTR_ERR(hdr);
5739 goto free_msg;
5740 }
5741
5742 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5743 channel_type, duration, &cookie);
5744
5745 if (err)
5746 goto free_msg;
5747
David S. Miller9360ffd2012-03-29 04:41:26 -04005748 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5749 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005750
5751 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005752
5753 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005754
5755 nla_put_failure:
5756 err = -ENOBUFS;
5757 free_msg:
5758 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005759 return err;
5760}
5761
5762static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5763 struct genl_info *info)
5764{
Johannes Berg4c476992010-10-04 21:36:35 +02005765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5766 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005767 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005768
5769 if (!info->attrs[NL80211_ATTR_COOKIE])
5770 return -EINVAL;
5771
Johannes Berg4c476992010-10-04 21:36:35 +02005772 if (!rdev->ops->cancel_remain_on_channel)
5773 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005774
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005775 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5776
Johannes Berg4c476992010-10-04 21:36:35 +02005777 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005778}
5779
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005780static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5781 u8 *rates, u8 rates_len)
5782{
5783 u8 i;
5784 u32 mask = 0;
5785
5786 for (i = 0; i < rates_len; i++) {
5787 int rate = (rates[i] & 0x7f) * 5;
5788 int ridx;
5789 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5790 struct ieee80211_rate *srate =
5791 &sband->bitrates[ridx];
5792 if (rate == srate->bitrate) {
5793 mask |= 1 << ridx;
5794 break;
5795 }
5796 }
5797 if (ridx == sband->n_bitrates)
5798 return 0; /* rate not found */
5799 }
5800
5801 return mask;
5802}
5803
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005804static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5805 u8 *rates, u8 rates_len,
5806 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5807{
5808 u8 i;
5809
5810 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5811
5812 for (i = 0; i < rates_len; i++) {
5813 int ridx, rbit;
5814
5815 ridx = rates[i] / 8;
5816 rbit = BIT(rates[i] % 8);
5817
5818 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005819 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005820 return false;
5821
5822 /* check availability */
5823 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5824 mcs[ridx] |= rbit;
5825 else
5826 return false;
5827 }
5828
5829 return true;
5830}
5831
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005832static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005833 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5834 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005835 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5836 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005837};
5838
5839static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5840 struct genl_info *info)
5841{
5842 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005844 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005845 int rem, i;
5846 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005847 struct nlattr *tx_rates;
5848 struct ieee80211_supported_band *sband;
5849
5850 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5851 return -EINVAL;
5852
Johannes Berg4c476992010-10-04 21:36:35 +02005853 if (!rdev->ops->set_bitrate_mask)
5854 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005855
5856 memset(&mask, 0, sizeof(mask));
5857 /* Default to all rates enabled */
5858 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5859 sband = rdev->wiphy.bands[i];
5860 mask.control[i].legacy =
5861 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005862 if (sband)
5863 memcpy(mask.control[i].mcs,
5864 sband->ht_cap.mcs.rx_mask,
5865 sizeof(mask.control[i].mcs));
5866 else
5867 memset(mask.control[i].mcs, 0,
5868 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005869 }
5870
5871 /*
5872 * The nested attribute uses enum nl80211_band as the index. This maps
5873 * directly to the enum ieee80211_band values used in cfg80211.
5874 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005875 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005876 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5877 {
5878 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005879 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5880 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005881 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005882 if (sband == NULL)
5883 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005884 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5885 nla_len(tx_rates), nl80211_txattr_policy);
5886 if (tb[NL80211_TXRATE_LEGACY]) {
5887 mask.control[band].legacy = rateset_to_mask(
5888 sband,
5889 nla_data(tb[NL80211_TXRATE_LEGACY]),
5890 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305891 if ((mask.control[band].legacy == 0) &&
5892 nla_len(tb[NL80211_TXRATE_LEGACY]))
5893 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005894 }
5895 if (tb[NL80211_TXRATE_MCS]) {
5896 if (!ht_rateset_to_mask(
5897 sband,
5898 nla_data(tb[NL80211_TXRATE_MCS]),
5899 nla_len(tb[NL80211_TXRATE_MCS]),
5900 mask.control[band].mcs))
5901 return -EINVAL;
5902 }
5903
5904 if (mask.control[band].legacy == 0) {
5905 /* don't allow empty legacy rates if HT
5906 * is not even supported. */
5907 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5908 return -EINVAL;
5909
5910 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5911 if (mask.control[band].mcs[i])
5912 break;
5913
5914 /* legacy and mcs rates may not be both empty */
5915 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005916 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005917 }
5918 }
5919
Johannes Berg4c476992010-10-04 21:36:35 +02005920 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005921}
5922
Johannes Berg2e161f72010-08-12 15:38:38 +02005923static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005924{
Johannes Berg4c476992010-10-04 21:36:35 +02005925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5926 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005927 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005928
5929 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5930 return -EINVAL;
5931
Johannes Berg2e161f72010-08-12 15:38:38 +02005932 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5933 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005934
Johannes Berg9d38d852010-06-09 17:20:33 +02005935 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005936 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5938 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5939 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005940 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005941 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5942 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005943
5944 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005945 if (!rdev->ops->mgmt_tx)
5946 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005947
Johannes Berg4c476992010-10-04 21:36:35 +02005948 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005949 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005950 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5951 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005952}
5953
Johannes Berg2e161f72010-08-12 15:38:38 +02005954static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005955{
Johannes Berg4c476992010-10-04 21:36:35 +02005956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5957 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005958 struct ieee80211_channel *chan;
5959 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005960 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005961 u32 freq;
5962 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005963 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005964 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005965 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005966 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005967 bool offchan, no_cck, dont_wait_for_ack;
5968
5969 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005970
5971 if (!info->attrs[NL80211_ATTR_FRAME] ||
5972 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5973 return -EINVAL;
5974
Johannes Berg4c476992010-10-04 21:36:35 +02005975 if (!rdev->ops->mgmt_tx)
5976 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005977
Johannes Berg9d38d852010-06-09 17:20:33 +02005978 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005979 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005980 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5981 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5982 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005983 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005984 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5985 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005986
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005987 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005988 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005989 return -EINVAL;
5990 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005991
5992 /*
5993 * We should wait on the channel for at least a minimum amount
5994 * of time (10ms) but no longer than the driver supports.
5995 */
5996 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5997 wait > rdev->wiphy.max_remain_on_channel_duration)
5998 return -EINVAL;
5999
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006000 }
6001
Jouni Malinen026331c2010-02-15 12:53:10 +02006002 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02006003 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02006004 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02006005 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02006006 }
6007
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006008 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6009
Johannes Berg7c4ef712011-11-18 15:33:48 +01006010 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6011 return -EINVAL;
6012
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306013 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6014
Jouni Malinen026331c2010-02-15 12:53:10 +02006015 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6016 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006017 if (chan == NULL)
6018 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006019
Johannes Berge247bd902011-11-04 11:18:21 +01006020 if (!dont_wait_for_ack) {
6021 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6022 if (!msg)
6023 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006024
Johannes Berge247bd902011-11-04 11:18:21 +01006025 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6026 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006027
Johannes Berge247bd902011-11-04 11:18:21 +01006028 if (IS_ERR(hdr)) {
6029 err = PTR_ERR(hdr);
6030 goto free_msg;
6031 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006032 }
Johannes Berge247bd902011-11-04 11:18:21 +01006033
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006034 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
6035 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006036 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6037 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006038 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006039 if (err)
6040 goto free_msg;
6041
Johannes Berge247bd902011-11-04 11:18:21 +01006042 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006043 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6044 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006045
Johannes Berge247bd902011-11-04 11:18:21 +01006046 genlmsg_end(msg, hdr);
6047 return genlmsg_reply(msg, info);
6048 }
6049
6050 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006051
6052 nla_put_failure:
6053 err = -ENOBUFS;
6054 free_msg:
6055 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006056 return err;
6057}
6058
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006059static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6060{
6061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6062 struct net_device *dev = info->user_ptr[1];
6063 u64 cookie;
6064
6065 if (!info->attrs[NL80211_ATTR_COOKIE])
6066 return -EINVAL;
6067
6068 if (!rdev->ops->mgmt_tx_cancel_wait)
6069 return -EOPNOTSUPP;
6070
6071 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6072 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6073 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6074 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6075 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6076 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6077 return -EOPNOTSUPP;
6078
6079 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6080
6081 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6082}
6083
Kalle Valoffb9eb32010-02-17 17:58:10 +02006084static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6085{
Johannes Berg4c476992010-10-04 21:36:35 +02006086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006087 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006088 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006089 u8 ps_state;
6090 bool state;
6091 int err;
6092
Johannes Berg4c476992010-10-04 21:36:35 +02006093 if (!info->attrs[NL80211_ATTR_PS_STATE])
6094 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006095
6096 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6097
Johannes Berg4c476992010-10-04 21:36:35 +02006098 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6099 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006100
6101 wdev = dev->ieee80211_ptr;
6102
Johannes Berg4c476992010-10-04 21:36:35 +02006103 if (!rdev->ops->set_power_mgmt)
6104 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006105
6106 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6107
6108 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006109 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006110
Johannes Berg4c476992010-10-04 21:36:35 +02006111 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6112 wdev->ps_timeout);
6113 if (!err)
6114 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006115 return err;
6116}
6117
6118static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6119{
Johannes Berg4c476992010-10-04 21:36:35 +02006120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006121 enum nl80211_ps_state ps_state;
6122 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006123 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006124 struct sk_buff *msg;
6125 void *hdr;
6126 int err;
6127
Kalle Valoffb9eb32010-02-17 17:58:10 +02006128 wdev = dev->ieee80211_ptr;
6129
Johannes Berg4c476992010-10-04 21:36:35 +02006130 if (!rdev->ops->set_power_mgmt)
6131 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006132
6133 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006134 if (!msg)
6135 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006136
6137 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6138 NL80211_CMD_GET_POWER_SAVE);
6139 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006140 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006141 goto free_msg;
6142 }
6143
6144 if (wdev->ps)
6145 ps_state = NL80211_PS_ENABLED;
6146 else
6147 ps_state = NL80211_PS_DISABLED;
6148
David S. Miller9360ffd2012-03-29 04:41:26 -04006149 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6150 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006151
6152 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006153 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006154
Johannes Berg4c476992010-10-04 21:36:35 +02006155 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006156 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006157 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006158 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006159 return err;
6160}
6161
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006162static struct nla_policy
6163nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6164 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6165 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6166 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6167};
6168
6169static int nl80211_set_cqm_rssi(struct genl_info *info,
6170 s32 threshold, u32 hysteresis)
6171{
Johannes Berg4c476992010-10-04 21:36:35 +02006172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006173 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006174 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006175
6176 if (threshold > 0)
6177 return -EINVAL;
6178
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006179 wdev = dev->ieee80211_ptr;
6180
Johannes Berg4c476992010-10-04 21:36:35 +02006181 if (!rdev->ops->set_cqm_rssi_config)
6182 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006183
Johannes Berg074ac8d2010-09-16 14:58:22 +02006184 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006185 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6186 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006187
Johannes Berg4c476992010-10-04 21:36:35 +02006188 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6189 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006190}
6191
6192static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6193{
6194 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6195 struct nlattr *cqm;
6196 int err;
6197
6198 cqm = info->attrs[NL80211_ATTR_CQM];
6199 if (!cqm) {
6200 err = -EINVAL;
6201 goto out;
6202 }
6203
6204 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6205 nl80211_attr_cqm_policy);
6206 if (err)
6207 goto out;
6208
6209 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6210 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6211 s32 threshold;
6212 u32 hysteresis;
6213 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6214 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6215 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6216 } else
6217 err = -EINVAL;
6218
6219out:
6220 return err;
6221}
6222
Johannes Berg29cbe682010-12-03 09:20:44 +01006223static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6224{
6225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6226 struct net_device *dev = info->user_ptr[1];
6227 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006228 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006229 int err;
6230
6231 /* start with default */
6232 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006233 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006234
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006235 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006236 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006237 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006238 if (err)
6239 return err;
6240 }
6241
6242 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6243 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6244 return -EINVAL;
6245
Javier Cardonac80d5452010-12-16 17:37:49 -08006246 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6247 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6248
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006249 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6250 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6251 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6252 return -EINVAL;
6253
Javier Cardonac80d5452010-12-16 17:37:49 -08006254 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6255 /* parse additional setup parameters if given */
6256 err = nl80211_parse_mesh_setup(info, &setup);
6257 if (err)
6258 return err;
6259 }
6260
Johannes Bergcc1d2802012-05-16 23:50:20 +02006261 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6262 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6263
6264 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6265 !nl80211_valid_channel_type(info, &channel_type))
6266 return -EINVAL;
6267
6268 setup.channel = rdev_freq_to_chan(rdev,
6269 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6270 channel_type);
6271 if (!setup.channel)
6272 return -EINVAL;
6273 setup.channel_type = channel_type;
6274 } else {
6275 /* cfg80211_join_mesh() will sort it out */
6276 setup.channel = NULL;
6277 }
6278
Javier Cardonac80d5452010-12-16 17:37:49 -08006279 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006280}
6281
6282static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6283{
6284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6285 struct net_device *dev = info->user_ptr[1];
6286
6287 return cfg80211_leave_mesh(rdev, dev);
6288}
6289
Johannes Bergdfb89c52012-06-27 09:23:48 +02006290#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006291static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6292{
6293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6294 struct sk_buff *msg;
6295 void *hdr;
6296
6297 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6298 return -EOPNOTSUPP;
6299
6300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6301 if (!msg)
6302 return -ENOMEM;
6303
6304 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6305 NL80211_CMD_GET_WOWLAN);
6306 if (!hdr)
6307 goto nla_put_failure;
6308
6309 if (rdev->wowlan) {
6310 struct nlattr *nl_wowlan;
6311
6312 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6313 if (!nl_wowlan)
6314 goto nla_put_failure;
6315
David S. Miller9360ffd2012-03-29 04:41:26 -04006316 if ((rdev->wowlan->any &&
6317 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6318 (rdev->wowlan->disconnect &&
6319 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6320 (rdev->wowlan->magic_pkt &&
6321 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6322 (rdev->wowlan->gtk_rekey_failure &&
6323 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6324 (rdev->wowlan->eap_identity_req &&
6325 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6326 (rdev->wowlan->four_way_handshake &&
6327 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6328 (rdev->wowlan->rfkill_release &&
6329 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6330 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006331 if (rdev->wowlan->n_patterns) {
6332 struct nlattr *nl_pats, *nl_pat;
6333 int i, pat_len;
6334
6335 nl_pats = nla_nest_start(msg,
6336 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6337 if (!nl_pats)
6338 goto nla_put_failure;
6339
6340 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6341 nl_pat = nla_nest_start(msg, i + 1);
6342 if (!nl_pat)
6343 goto nla_put_failure;
6344 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006345 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6346 DIV_ROUND_UP(pat_len, 8),
6347 rdev->wowlan->patterns[i].mask) ||
6348 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6349 pat_len,
6350 rdev->wowlan->patterns[i].pattern))
6351 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006352 nla_nest_end(msg, nl_pat);
6353 }
6354 nla_nest_end(msg, nl_pats);
6355 }
6356
6357 nla_nest_end(msg, nl_wowlan);
6358 }
6359
6360 genlmsg_end(msg, hdr);
6361 return genlmsg_reply(msg, info);
6362
6363nla_put_failure:
6364 nlmsg_free(msg);
6365 return -ENOBUFS;
6366}
6367
6368static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6369{
6370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6371 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6372 struct cfg80211_wowlan no_triggers = {};
6373 struct cfg80211_wowlan new_triggers = {};
6374 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6375 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006376 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006377
6378 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6379 return -EOPNOTSUPP;
6380
6381 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6382 goto no_triggers;
6383
6384 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6385 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6386 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6387 nl80211_wowlan_policy);
6388 if (err)
6389 return err;
6390
6391 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6392 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6393 return -EINVAL;
6394 new_triggers.any = true;
6395 }
6396
6397 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6398 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6399 return -EINVAL;
6400 new_triggers.disconnect = true;
6401 }
6402
6403 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6404 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6405 return -EINVAL;
6406 new_triggers.magic_pkt = true;
6407 }
6408
Johannes Berg77dbbb12011-07-13 10:48:55 +02006409 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6410 return -EINVAL;
6411
6412 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6413 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6414 return -EINVAL;
6415 new_triggers.gtk_rekey_failure = true;
6416 }
6417
6418 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6419 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6420 return -EINVAL;
6421 new_triggers.eap_identity_req = true;
6422 }
6423
6424 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6425 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6426 return -EINVAL;
6427 new_triggers.four_way_handshake = true;
6428 }
6429
6430 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6431 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6432 return -EINVAL;
6433 new_triggers.rfkill_release = true;
6434 }
6435
Johannes Bergff1b6e62011-05-04 15:37:28 +02006436 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6437 struct nlattr *pat;
6438 int n_patterns = 0;
6439 int rem, pat_len, mask_len;
6440 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6441
6442 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6443 rem)
6444 n_patterns++;
6445 if (n_patterns > wowlan->n_patterns)
6446 return -EINVAL;
6447
6448 new_triggers.patterns = kcalloc(n_patterns,
6449 sizeof(new_triggers.patterns[0]),
6450 GFP_KERNEL);
6451 if (!new_triggers.patterns)
6452 return -ENOMEM;
6453
6454 new_triggers.n_patterns = n_patterns;
6455 i = 0;
6456
6457 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6458 rem) {
6459 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6460 nla_data(pat), nla_len(pat), NULL);
6461 err = -EINVAL;
6462 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6463 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6464 goto error;
6465 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6466 mask_len = DIV_ROUND_UP(pat_len, 8);
6467 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6468 mask_len)
6469 goto error;
6470 if (pat_len > wowlan->pattern_max_len ||
6471 pat_len < wowlan->pattern_min_len)
6472 goto error;
6473
6474 new_triggers.patterns[i].mask =
6475 kmalloc(mask_len + pat_len, GFP_KERNEL);
6476 if (!new_triggers.patterns[i].mask) {
6477 err = -ENOMEM;
6478 goto error;
6479 }
6480 new_triggers.patterns[i].pattern =
6481 new_triggers.patterns[i].mask + mask_len;
6482 memcpy(new_triggers.patterns[i].mask,
6483 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6484 mask_len);
6485 new_triggers.patterns[i].pattern_len = pat_len;
6486 memcpy(new_triggers.patterns[i].pattern,
6487 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6488 pat_len);
6489 i++;
6490 }
6491 }
6492
6493 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6494 struct cfg80211_wowlan *ntrig;
6495 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6496 GFP_KERNEL);
6497 if (!ntrig) {
6498 err = -ENOMEM;
6499 goto error;
6500 }
6501 cfg80211_rdev_free_wowlan(rdev);
6502 rdev->wowlan = ntrig;
6503 } else {
6504 no_triggers:
6505 cfg80211_rdev_free_wowlan(rdev);
6506 rdev->wowlan = NULL;
6507 }
6508
Johannes Berg6d525632012-04-04 15:05:25 +02006509 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6510 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6511
Johannes Bergff1b6e62011-05-04 15:37:28 +02006512 return 0;
6513 error:
6514 for (i = 0; i < new_triggers.n_patterns; i++)
6515 kfree(new_triggers.patterns[i].mask);
6516 kfree(new_triggers.patterns);
6517 return err;
6518}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006519#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006520
Johannes Berge5497d72011-07-05 16:35:40 +02006521static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6522{
6523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6524 struct net_device *dev = info->user_ptr[1];
6525 struct wireless_dev *wdev = dev->ieee80211_ptr;
6526 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6527 struct cfg80211_gtk_rekey_data rekey_data;
6528 int err;
6529
6530 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6531 return -EINVAL;
6532
6533 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6534 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6535 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6536 nl80211_rekey_policy);
6537 if (err)
6538 return err;
6539
6540 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6541 return -ERANGE;
6542 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6543 return -ERANGE;
6544 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6545 return -ERANGE;
6546
6547 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6548 NL80211_KEK_LEN);
6549 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6550 NL80211_KCK_LEN);
6551 memcpy(rekey_data.replay_ctr,
6552 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6553 NL80211_REPLAY_CTR_LEN);
6554
6555 wdev_lock(wdev);
6556 if (!wdev->current_bss) {
6557 err = -ENOTCONN;
6558 goto out;
6559 }
6560
6561 if (!rdev->ops->set_rekey_data) {
6562 err = -EOPNOTSUPP;
6563 goto out;
6564 }
6565
6566 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6567 out:
6568 wdev_unlock(wdev);
6569 return err;
6570}
6571
Johannes Berg28946da2011-11-04 11:18:12 +01006572static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6573 struct genl_info *info)
6574{
6575 struct net_device *dev = info->user_ptr[1];
6576 struct wireless_dev *wdev = dev->ieee80211_ptr;
6577
6578 if (wdev->iftype != NL80211_IFTYPE_AP &&
6579 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6580 return -EINVAL;
6581
6582 if (wdev->ap_unexpected_nlpid)
6583 return -EBUSY;
6584
6585 wdev->ap_unexpected_nlpid = info->snd_pid;
6586 return 0;
6587}
6588
Johannes Berg7f6cf312011-11-04 11:18:15 +01006589static int nl80211_probe_client(struct sk_buff *skb,
6590 struct genl_info *info)
6591{
6592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6593 struct net_device *dev = info->user_ptr[1];
6594 struct wireless_dev *wdev = dev->ieee80211_ptr;
6595 struct sk_buff *msg;
6596 void *hdr;
6597 const u8 *addr;
6598 u64 cookie;
6599 int err;
6600
6601 if (wdev->iftype != NL80211_IFTYPE_AP &&
6602 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6603 return -EOPNOTSUPP;
6604
6605 if (!info->attrs[NL80211_ATTR_MAC])
6606 return -EINVAL;
6607
6608 if (!rdev->ops->probe_client)
6609 return -EOPNOTSUPP;
6610
6611 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6612 if (!msg)
6613 return -ENOMEM;
6614
6615 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6616 NL80211_CMD_PROBE_CLIENT);
6617
6618 if (IS_ERR(hdr)) {
6619 err = PTR_ERR(hdr);
6620 goto free_msg;
6621 }
6622
6623 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6624
6625 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6626 if (err)
6627 goto free_msg;
6628
David S. Miller9360ffd2012-03-29 04:41:26 -04006629 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6630 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006631
6632 genlmsg_end(msg, hdr);
6633
6634 return genlmsg_reply(msg, info);
6635
6636 nla_put_failure:
6637 err = -ENOBUFS;
6638 free_msg:
6639 nlmsg_free(msg);
6640 return err;
6641}
6642
Johannes Berg5e760232011-11-04 11:18:17 +01006643static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6644{
6645 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6646
6647 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6648 return -EOPNOTSUPP;
6649
6650 if (rdev->ap_beacons_nlpid)
6651 return -EBUSY;
6652
6653 rdev->ap_beacons_nlpid = info->snd_pid;
6654
6655 return 0;
6656}
6657
Johannes Berg4c476992010-10-04 21:36:35 +02006658#define NL80211_FLAG_NEED_WIPHY 0x01
6659#define NL80211_FLAG_NEED_NETDEV 0x02
6660#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006661#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6662#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6663 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006664
6665static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6666 struct genl_info *info)
6667{
6668 struct cfg80211_registered_device *rdev;
6669 struct net_device *dev;
6670 int err;
6671 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6672
6673 if (rtnl)
6674 rtnl_lock();
6675
6676 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006677 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006678 if (IS_ERR(rdev)) {
6679 if (rtnl)
6680 rtnl_unlock();
6681 return PTR_ERR(rdev);
6682 }
6683 info->user_ptr[0] = rdev;
6684 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006685 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6686 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006687 if (err) {
6688 if (rtnl)
6689 rtnl_unlock();
6690 return err;
6691 }
Johannes Berg41265712010-10-04 21:14:05 +02006692 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6693 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006694 cfg80211_unlock_rdev(rdev);
6695 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006696 if (rtnl)
6697 rtnl_unlock();
6698 return -ENETDOWN;
6699 }
Johannes Berg4c476992010-10-04 21:36:35 +02006700 info->user_ptr[0] = rdev;
6701 info->user_ptr[1] = dev;
6702 }
6703
6704 return 0;
6705}
6706
6707static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6708 struct genl_info *info)
6709{
6710 if (info->user_ptr[0])
6711 cfg80211_unlock_rdev(info->user_ptr[0]);
6712 if (info->user_ptr[1])
6713 dev_put(info->user_ptr[1]);
6714 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6715 rtnl_unlock();
6716}
6717
Johannes Berg55682962007-09-20 13:09:35 -04006718static struct genl_ops nl80211_ops[] = {
6719 {
6720 .cmd = NL80211_CMD_GET_WIPHY,
6721 .doit = nl80211_get_wiphy,
6722 .dumpit = nl80211_dump_wiphy,
6723 .policy = nl80211_policy,
6724 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006725 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006726 },
6727 {
6728 .cmd = NL80211_CMD_SET_WIPHY,
6729 .doit = nl80211_set_wiphy,
6730 .policy = nl80211_policy,
6731 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006732 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006733 },
6734 {
6735 .cmd = NL80211_CMD_GET_INTERFACE,
6736 .doit = nl80211_get_interface,
6737 .dumpit = nl80211_dump_interface,
6738 .policy = nl80211_policy,
6739 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006740 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006741 },
6742 {
6743 .cmd = NL80211_CMD_SET_INTERFACE,
6744 .doit = nl80211_set_interface,
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 Berg55682962007-09-20 13:09:35 -04006749 },
6750 {
6751 .cmd = NL80211_CMD_NEW_INTERFACE,
6752 .doit = nl80211_new_interface,
6753 .policy = nl80211_policy,
6754 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006755 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6756 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006757 },
6758 {
6759 .cmd = NL80211_CMD_DEL_INTERFACE,
6760 .doit = nl80211_del_interface,
6761 .policy = nl80211_policy,
6762 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006763 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6764 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006765 },
Johannes Berg41ade002007-12-19 02:03:29 +01006766 {
6767 .cmd = NL80211_CMD_GET_KEY,
6768 .doit = nl80211_get_key,
6769 .policy = nl80211_policy,
6770 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006772 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006773 },
6774 {
6775 .cmd = NL80211_CMD_SET_KEY,
6776 .doit = nl80211_set_key,
6777 .policy = nl80211_policy,
6778 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006779 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006780 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006781 },
6782 {
6783 .cmd = NL80211_CMD_NEW_KEY,
6784 .doit = nl80211_new_key,
6785 .policy = nl80211_policy,
6786 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006787 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006788 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006789 },
6790 {
6791 .cmd = NL80211_CMD_DEL_KEY,
6792 .doit = nl80211_del_key,
6793 .policy = nl80211_policy,
6794 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006795 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006796 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006797 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006798 {
6799 .cmd = NL80211_CMD_SET_BEACON,
6800 .policy = nl80211_policy,
6801 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006802 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006804 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006805 },
6806 {
Johannes Berg88600202012-02-13 15:17:18 +01006807 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006808 .policy = nl80211_policy,
6809 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006810 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006812 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006813 },
6814 {
Johannes Berg88600202012-02-13 15:17:18 +01006815 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006816 .policy = nl80211_policy,
6817 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006818 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006820 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006821 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006822 {
6823 .cmd = NL80211_CMD_GET_STATION,
6824 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006825 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006826 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006827 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6828 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006829 },
6830 {
6831 .cmd = NL80211_CMD_SET_STATION,
6832 .doit = nl80211_set_station,
6833 .policy = nl80211_policy,
6834 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006836 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006837 },
6838 {
6839 .cmd = NL80211_CMD_NEW_STATION,
6840 .doit = nl80211_new_station,
6841 .policy = nl80211_policy,
6842 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006844 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006845 },
6846 {
6847 .cmd = NL80211_CMD_DEL_STATION,
6848 .doit = nl80211_del_station,
6849 .policy = nl80211_policy,
6850 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006852 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006853 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006854 {
6855 .cmd = NL80211_CMD_GET_MPATH,
6856 .doit = nl80211_get_mpath,
6857 .dumpit = nl80211_dump_mpath,
6858 .policy = nl80211_policy,
6859 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006861 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006862 },
6863 {
6864 .cmd = NL80211_CMD_SET_MPATH,
6865 .doit = nl80211_set_mpath,
6866 .policy = nl80211_policy,
6867 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006869 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006870 },
6871 {
6872 .cmd = NL80211_CMD_NEW_MPATH,
6873 .doit = nl80211_new_mpath,
6874 .policy = nl80211_policy,
6875 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006876 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006877 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006878 },
6879 {
6880 .cmd = NL80211_CMD_DEL_MPATH,
6881 .doit = nl80211_del_mpath,
6882 .policy = nl80211_policy,
6883 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006884 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006885 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006886 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006887 {
6888 .cmd = NL80211_CMD_SET_BSS,
6889 .doit = nl80211_set_bss,
6890 .policy = nl80211_policy,
6891 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006892 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006893 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006894 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006895 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006896 .cmd = NL80211_CMD_GET_REG,
6897 .doit = nl80211_get_reg,
6898 .policy = nl80211_policy,
6899 /* can be retrieved by unprivileged users */
6900 },
6901 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006902 .cmd = NL80211_CMD_SET_REG,
6903 .doit = nl80211_set_reg,
6904 .policy = nl80211_policy,
6905 .flags = GENL_ADMIN_PERM,
6906 },
6907 {
6908 .cmd = NL80211_CMD_REQ_SET_REG,
6909 .doit = nl80211_req_set_reg,
6910 .policy = nl80211_policy,
6911 .flags = GENL_ADMIN_PERM,
6912 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006913 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006914 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6915 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006916 .policy = nl80211_policy,
6917 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006918 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006919 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006920 },
6921 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006922 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6923 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006924 .policy = nl80211_policy,
6925 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006926 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006927 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006928 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006929 {
Johannes Berg2a519312009-02-10 21:25:55 +01006930 .cmd = NL80211_CMD_TRIGGER_SCAN,
6931 .doit = nl80211_trigger_scan,
6932 .policy = nl80211_policy,
6933 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006934 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006935 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006936 },
6937 {
6938 .cmd = NL80211_CMD_GET_SCAN,
6939 .policy = nl80211_policy,
6940 .dumpit = nl80211_dump_scan,
6941 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006942 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006943 .cmd = NL80211_CMD_START_SCHED_SCAN,
6944 .doit = nl80211_start_sched_scan,
6945 .policy = nl80211_policy,
6946 .flags = GENL_ADMIN_PERM,
6947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6948 NL80211_FLAG_NEED_RTNL,
6949 },
6950 {
6951 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6952 .doit = nl80211_stop_sched_scan,
6953 .policy = nl80211_policy,
6954 .flags = GENL_ADMIN_PERM,
6955 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6956 NL80211_FLAG_NEED_RTNL,
6957 },
6958 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006959 .cmd = NL80211_CMD_AUTHENTICATE,
6960 .doit = nl80211_authenticate,
6961 .policy = nl80211_policy,
6962 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006964 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006965 },
6966 {
6967 .cmd = NL80211_CMD_ASSOCIATE,
6968 .doit = nl80211_associate,
6969 .policy = nl80211_policy,
6970 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006971 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006972 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006973 },
6974 {
6975 .cmd = NL80211_CMD_DEAUTHENTICATE,
6976 .doit = nl80211_deauthenticate,
6977 .policy = nl80211_policy,
6978 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006979 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006980 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006981 },
6982 {
6983 .cmd = NL80211_CMD_DISASSOCIATE,
6984 .doit = nl80211_disassociate,
6985 .policy = nl80211_policy,
6986 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006987 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006988 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006989 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006990 {
6991 .cmd = NL80211_CMD_JOIN_IBSS,
6992 .doit = nl80211_join_ibss,
6993 .policy = nl80211_policy,
6994 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006995 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006996 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006997 },
6998 {
6999 .cmd = NL80211_CMD_LEAVE_IBSS,
7000 .doit = nl80211_leave_ibss,
7001 .policy = nl80211_policy,
7002 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007004 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007005 },
Johannes Bergaff89a92009-07-01 21:26:51 +02007006#ifdef CONFIG_NL80211_TESTMODE
7007 {
7008 .cmd = NL80211_CMD_TESTMODE,
7009 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007010 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02007011 .policy = nl80211_policy,
7012 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007013 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7014 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007015 },
7016#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007017 {
7018 .cmd = NL80211_CMD_CONNECT,
7019 .doit = nl80211_connect,
7020 .policy = nl80211_policy,
7021 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007023 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007024 },
7025 {
7026 .cmd = NL80211_CMD_DISCONNECT,
7027 .doit = nl80211_disconnect,
7028 .policy = nl80211_policy,
7029 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007030 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007031 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007032 },
Johannes Berg463d0182009-07-14 00:33:35 +02007033 {
7034 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7035 .doit = nl80211_wiphy_netns,
7036 .policy = nl80211_policy,
7037 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007038 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7039 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007040 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007041 {
7042 .cmd = NL80211_CMD_GET_SURVEY,
7043 .policy = nl80211_policy,
7044 .dumpit = nl80211_dump_survey,
7045 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007046 {
7047 .cmd = NL80211_CMD_SET_PMKSA,
7048 .doit = nl80211_setdel_pmksa,
7049 .policy = nl80211_policy,
7050 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007051 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007052 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007053 },
7054 {
7055 .cmd = NL80211_CMD_DEL_PMKSA,
7056 .doit = nl80211_setdel_pmksa,
7057 .policy = nl80211_policy,
7058 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007060 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007061 },
7062 {
7063 .cmd = NL80211_CMD_FLUSH_PMKSA,
7064 .doit = nl80211_flush_pmksa,
7065 .policy = nl80211_policy,
7066 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007067 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007068 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007069 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007070 {
7071 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7072 .doit = nl80211_remain_on_channel,
7073 .policy = nl80211_policy,
7074 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007076 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007077 },
7078 {
7079 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7080 .doit = nl80211_cancel_remain_on_channel,
7081 .policy = nl80211_policy,
7082 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007084 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007085 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007086 {
7087 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7088 .doit = nl80211_set_tx_bitrate_mask,
7089 .policy = nl80211_policy,
7090 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007091 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7092 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007093 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007094 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007095 .cmd = NL80211_CMD_REGISTER_FRAME,
7096 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007097 .policy = nl80211_policy,
7098 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007099 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7100 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007101 },
7102 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007103 .cmd = NL80211_CMD_FRAME,
7104 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007105 .policy = nl80211_policy,
7106 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007107 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007108 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007109 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007110 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007111 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7112 .doit = nl80211_tx_mgmt_cancel_wait,
7113 .policy = nl80211_policy,
7114 .flags = GENL_ADMIN_PERM,
7115 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7116 NL80211_FLAG_NEED_RTNL,
7117 },
7118 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007119 .cmd = NL80211_CMD_SET_POWER_SAVE,
7120 .doit = nl80211_set_power_save,
7121 .policy = nl80211_policy,
7122 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007123 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7124 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007125 },
7126 {
7127 .cmd = NL80211_CMD_GET_POWER_SAVE,
7128 .doit = nl80211_get_power_save,
7129 .policy = nl80211_policy,
7130 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007131 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7132 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007133 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007134 {
7135 .cmd = NL80211_CMD_SET_CQM,
7136 .doit = nl80211_set_cqm,
7137 .policy = nl80211_policy,
7138 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007139 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7140 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007141 },
Johannes Bergf444de02010-05-05 15:25:02 +02007142 {
7143 .cmd = NL80211_CMD_SET_CHANNEL,
7144 .doit = nl80211_set_channel,
7145 .policy = nl80211_policy,
7146 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007147 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7148 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007149 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007150 {
7151 .cmd = NL80211_CMD_SET_WDS_PEER,
7152 .doit = nl80211_set_wds_peer,
7153 .policy = nl80211_policy,
7154 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007155 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7156 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007157 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007158 {
7159 .cmd = NL80211_CMD_JOIN_MESH,
7160 .doit = nl80211_join_mesh,
7161 .policy = nl80211_policy,
7162 .flags = GENL_ADMIN_PERM,
7163 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7164 NL80211_FLAG_NEED_RTNL,
7165 },
7166 {
7167 .cmd = NL80211_CMD_LEAVE_MESH,
7168 .doit = nl80211_leave_mesh,
7169 .policy = nl80211_policy,
7170 .flags = GENL_ADMIN_PERM,
7171 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7172 NL80211_FLAG_NEED_RTNL,
7173 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007174#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007175 {
7176 .cmd = NL80211_CMD_GET_WOWLAN,
7177 .doit = nl80211_get_wowlan,
7178 .policy = nl80211_policy,
7179 /* can be retrieved by unprivileged users */
7180 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7181 NL80211_FLAG_NEED_RTNL,
7182 },
7183 {
7184 .cmd = NL80211_CMD_SET_WOWLAN,
7185 .doit = nl80211_set_wowlan,
7186 .policy = nl80211_policy,
7187 .flags = GENL_ADMIN_PERM,
7188 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7189 NL80211_FLAG_NEED_RTNL,
7190 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007191#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007192 {
7193 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7194 .doit = nl80211_set_rekey_data,
7195 .policy = nl80211_policy,
7196 .flags = GENL_ADMIN_PERM,
7197 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7198 NL80211_FLAG_NEED_RTNL,
7199 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007200 {
7201 .cmd = NL80211_CMD_TDLS_MGMT,
7202 .doit = nl80211_tdls_mgmt,
7203 .policy = nl80211_policy,
7204 .flags = GENL_ADMIN_PERM,
7205 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7206 NL80211_FLAG_NEED_RTNL,
7207 },
7208 {
7209 .cmd = NL80211_CMD_TDLS_OPER,
7210 .doit = nl80211_tdls_oper,
7211 .policy = nl80211_policy,
7212 .flags = GENL_ADMIN_PERM,
7213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7214 NL80211_FLAG_NEED_RTNL,
7215 },
Johannes Berg28946da2011-11-04 11:18:12 +01007216 {
7217 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7218 .doit = nl80211_register_unexpected_frame,
7219 .policy = nl80211_policy,
7220 .flags = GENL_ADMIN_PERM,
7221 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7222 NL80211_FLAG_NEED_RTNL,
7223 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007224 {
7225 .cmd = NL80211_CMD_PROBE_CLIENT,
7226 .doit = nl80211_probe_client,
7227 .policy = nl80211_policy,
7228 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007230 NL80211_FLAG_NEED_RTNL,
7231 },
Johannes Berg5e760232011-11-04 11:18:17 +01007232 {
7233 .cmd = NL80211_CMD_REGISTER_BEACONS,
7234 .doit = nl80211_register_beacons,
7235 .policy = nl80211_policy,
7236 .flags = GENL_ADMIN_PERM,
7237 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7238 NL80211_FLAG_NEED_RTNL,
7239 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007240 {
7241 .cmd = NL80211_CMD_SET_NOACK_MAP,
7242 .doit = nl80211_set_noack_map,
7243 .policy = nl80211_policy,
7244 .flags = GENL_ADMIN_PERM,
7245 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7246 NL80211_FLAG_NEED_RTNL,
7247 },
7248
Johannes Berg55682962007-09-20 13:09:35 -04007249};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007250
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007251static struct genl_multicast_group nl80211_mlme_mcgrp = {
7252 .name = "mlme",
7253};
Johannes Berg55682962007-09-20 13:09:35 -04007254
7255/* multicast groups */
7256static struct genl_multicast_group nl80211_config_mcgrp = {
7257 .name = "config",
7258};
Johannes Berg2a519312009-02-10 21:25:55 +01007259static struct genl_multicast_group nl80211_scan_mcgrp = {
7260 .name = "scan",
7261};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007262static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7263 .name = "regulatory",
7264};
Johannes Berg55682962007-09-20 13:09:35 -04007265
7266/* notification functions */
7267
7268void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7269{
7270 struct sk_buff *msg;
7271
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007272 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007273 if (!msg)
7274 return;
7275
7276 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7277 nlmsg_free(msg);
7278 return;
7279 }
7280
Johannes Berg463d0182009-07-14 00:33:35 +02007281 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7282 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007283}
7284
Johannes Berg362a4152009-05-24 16:43:15 +02007285static int nl80211_add_scan_req(struct sk_buff *msg,
7286 struct cfg80211_registered_device *rdev)
7287{
7288 struct cfg80211_scan_request *req = rdev->scan_req;
7289 struct nlattr *nest;
7290 int i;
7291
Johannes Berg667503d2009-07-07 03:56:11 +02007292 ASSERT_RDEV_LOCK(rdev);
7293
Johannes Berg362a4152009-05-24 16:43:15 +02007294 if (WARN_ON(!req))
7295 return 0;
7296
7297 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7298 if (!nest)
7299 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007300 for (i = 0; i < req->n_ssids; i++) {
7301 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7302 goto nla_put_failure;
7303 }
Johannes Berg362a4152009-05-24 16:43:15 +02007304 nla_nest_end(msg, nest);
7305
7306 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7307 if (!nest)
7308 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007309 for (i = 0; i < req->n_channels; i++) {
7310 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7311 goto nla_put_failure;
7312 }
Johannes Berg362a4152009-05-24 16:43:15 +02007313 nla_nest_end(msg, nest);
7314
David S. Miller9360ffd2012-03-29 04:41:26 -04007315 if (req->ie &&
7316 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7317 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007318
7319 return 0;
7320 nla_put_failure:
7321 return -ENOBUFS;
7322}
7323
Johannes Berga538e2d2009-06-16 19:56:42 +02007324static int nl80211_send_scan_msg(struct sk_buff *msg,
7325 struct cfg80211_registered_device *rdev,
7326 struct net_device *netdev,
7327 u32 pid, u32 seq, int flags,
7328 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007329{
7330 void *hdr;
7331
7332 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7333 if (!hdr)
7334 return -1;
7335
David S. Miller9360ffd2012-03-29 04:41:26 -04007336 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7337 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7338 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007339
Johannes Berg362a4152009-05-24 16:43:15 +02007340 /* ignore errors and send incomplete event anyway */
7341 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007342
7343 return genlmsg_end(msg, hdr);
7344
7345 nla_put_failure:
7346 genlmsg_cancel(msg, hdr);
7347 return -EMSGSIZE;
7348}
7349
Luciano Coelho807f8a82011-05-11 17:09:35 +03007350static int
7351nl80211_send_sched_scan_msg(struct sk_buff *msg,
7352 struct cfg80211_registered_device *rdev,
7353 struct net_device *netdev,
7354 u32 pid, u32 seq, int flags, u32 cmd)
7355{
7356 void *hdr;
7357
7358 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7359 if (!hdr)
7360 return -1;
7361
David S. Miller9360ffd2012-03-29 04:41:26 -04007362 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7363 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7364 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007365
7366 return genlmsg_end(msg, hdr);
7367
7368 nla_put_failure:
7369 genlmsg_cancel(msg, hdr);
7370 return -EMSGSIZE;
7371}
7372
Johannes Berga538e2d2009-06-16 19:56:42 +02007373void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7374 struct net_device *netdev)
7375{
7376 struct sk_buff *msg;
7377
7378 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7379 if (!msg)
7380 return;
7381
7382 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7383 NL80211_CMD_TRIGGER_SCAN) < 0) {
7384 nlmsg_free(msg);
7385 return;
7386 }
7387
Johannes Berg463d0182009-07-14 00:33:35 +02007388 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7389 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007390}
7391
Johannes Berg2a519312009-02-10 21:25:55 +01007392void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7393 struct net_device *netdev)
7394{
7395 struct sk_buff *msg;
7396
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007397 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007398 if (!msg)
7399 return;
7400
Johannes Berga538e2d2009-06-16 19:56:42 +02007401 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7402 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007403 nlmsg_free(msg);
7404 return;
7405 }
7406
Johannes Berg463d0182009-07-14 00:33:35 +02007407 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7408 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007409}
7410
7411void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7412 struct net_device *netdev)
7413{
7414 struct sk_buff *msg;
7415
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007416 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007417 if (!msg)
7418 return;
7419
Johannes Berga538e2d2009-06-16 19:56:42 +02007420 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7421 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007422 nlmsg_free(msg);
7423 return;
7424 }
7425
Johannes Berg463d0182009-07-14 00:33:35 +02007426 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7427 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007428}
7429
Luciano Coelho807f8a82011-05-11 17:09:35 +03007430void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7431 struct net_device *netdev)
7432{
7433 struct sk_buff *msg;
7434
7435 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7436 if (!msg)
7437 return;
7438
7439 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7440 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7441 nlmsg_free(msg);
7442 return;
7443 }
7444
7445 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7446 nl80211_scan_mcgrp.id, GFP_KERNEL);
7447}
7448
7449void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7450 struct net_device *netdev, u32 cmd)
7451{
7452 struct sk_buff *msg;
7453
7454 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7455 if (!msg)
7456 return;
7457
7458 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7459 nlmsg_free(msg);
7460 return;
7461 }
7462
7463 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7464 nl80211_scan_mcgrp.id, GFP_KERNEL);
7465}
7466
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007467/*
7468 * This can happen on global regulatory changes or device specific settings
7469 * based on custom world regulatory domains.
7470 */
7471void nl80211_send_reg_change_event(struct regulatory_request *request)
7472{
7473 struct sk_buff *msg;
7474 void *hdr;
7475
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007476 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007477 if (!msg)
7478 return;
7479
7480 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7481 if (!hdr) {
7482 nlmsg_free(msg);
7483 return;
7484 }
7485
7486 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007487 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7488 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007489
David S. Miller9360ffd2012-03-29 04:41:26 -04007490 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7491 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7492 NL80211_REGDOM_TYPE_WORLD))
7493 goto nla_put_failure;
7494 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7495 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7496 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7497 goto nla_put_failure;
7498 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7499 request->intersect) {
7500 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7501 NL80211_REGDOM_TYPE_INTERSECTION))
7502 goto nla_put_failure;
7503 } else {
7504 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7505 NL80211_REGDOM_TYPE_COUNTRY) ||
7506 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7507 request->alpha2))
7508 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007509 }
7510
David S. Miller9360ffd2012-03-29 04:41:26 -04007511 if (wiphy_idx_valid(request->wiphy_idx) &&
7512 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7513 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007514
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007515 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007516
Johannes Bergbc43b282009-07-25 10:54:13 +02007517 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007518 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007519 GFP_ATOMIC);
7520 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007521
7522 return;
7523
7524nla_put_failure:
7525 genlmsg_cancel(msg, hdr);
7526 nlmsg_free(msg);
7527}
7528
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007529static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7530 struct net_device *netdev,
7531 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007532 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007533{
7534 struct sk_buff *msg;
7535 void *hdr;
7536
Johannes Berge6d6e342009-07-01 21:26:47 +02007537 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007538 if (!msg)
7539 return;
7540
7541 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7542 if (!hdr) {
7543 nlmsg_free(msg);
7544 return;
7545 }
7546
David S. Miller9360ffd2012-03-29 04:41:26 -04007547 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7548 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7549 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7550 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007551
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007552 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007553
Johannes Berg463d0182009-07-14 00:33:35 +02007554 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7555 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007556 return;
7557
7558 nla_put_failure:
7559 genlmsg_cancel(msg, hdr);
7560 nlmsg_free(msg);
7561}
7562
7563void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007564 struct net_device *netdev, const u8 *buf,
7565 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007566{
7567 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007568 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007569}
7570
7571void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7572 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007573 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007574{
Johannes Berge6d6e342009-07-01 21:26:47 +02007575 nl80211_send_mlme_event(rdev, netdev, buf, len,
7576 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007577}
7578
Jouni Malinen53b46b82009-03-27 20:53:56 +02007579void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007580 struct net_device *netdev, const u8 *buf,
7581 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007582{
7583 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007584 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007585}
7586
Jouni Malinen53b46b82009-03-27 20:53:56 +02007587void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7588 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007589 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007590{
7591 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007592 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007593}
7594
Jouni Malinencf4e5942010-12-16 00:52:40 +02007595void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7596 struct net_device *netdev, const u8 *buf,
7597 size_t len, gfp_t gfp)
7598{
7599 nl80211_send_mlme_event(rdev, netdev, buf, len,
7600 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7601}
7602
7603void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7604 struct net_device *netdev, const u8 *buf,
7605 size_t len, gfp_t gfp)
7606{
7607 nl80211_send_mlme_event(rdev, netdev, buf, len,
7608 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7609}
7610
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007611static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7612 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007613 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007614{
7615 struct sk_buff *msg;
7616 void *hdr;
7617
Johannes Berge6d6e342009-07-01 21:26:47 +02007618 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007619 if (!msg)
7620 return;
7621
7622 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7623 if (!hdr) {
7624 nlmsg_free(msg);
7625 return;
7626 }
7627
David S. Miller9360ffd2012-03-29 04:41:26 -04007628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7629 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7630 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7631 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7632 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007633
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007634 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007635
Johannes Berg463d0182009-07-14 00:33:35 +02007636 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7637 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007638 return;
7639
7640 nla_put_failure:
7641 genlmsg_cancel(msg, hdr);
7642 nlmsg_free(msg);
7643}
7644
7645void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007646 struct net_device *netdev, const u8 *addr,
7647 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007648{
7649 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007650 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007651}
7652
7653void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007654 struct net_device *netdev, const u8 *addr,
7655 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007656{
Johannes Berge6d6e342009-07-01 21:26:47 +02007657 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7658 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007659}
7660
Samuel Ortizb23aa672009-07-01 21:26:54 +02007661void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7662 struct net_device *netdev, const u8 *bssid,
7663 const u8 *req_ie, size_t req_ie_len,
7664 const u8 *resp_ie, size_t resp_ie_len,
7665 u16 status, gfp_t gfp)
7666{
7667 struct sk_buff *msg;
7668 void *hdr;
7669
7670 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7671 if (!msg)
7672 return;
7673
7674 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7675 if (!hdr) {
7676 nlmsg_free(msg);
7677 return;
7678 }
7679
David S. Miller9360ffd2012-03-29 04:41:26 -04007680 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7681 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7682 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7683 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7684 (req_ie &&
7685 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7686 (resp_ie &&
7687 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7688 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007689
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007690 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007691
Johannes Berg463d0182009-07-14 00:33:35 +02007692 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7693 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007694 return;
7695
7696 nla_put_failure:
7697 genlmsg_cancel(msg, hdr);
7698 nlmsg_free(msg);
7699
7700}
7701
7702void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7703 struct net_device *netdev, const u8 *bssid,
7704 const u8 *req_ie, size_t req_ie_len,
7705 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7706{
7707 struct sk_buff *msg;
7708 void *hdr;
7709
7710 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7711 if (!msg)
7712 return;
7713
7714 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7715 if (!hdr) {
7716 nlmsg_free(msg);
7717 return;
7718 }
7719
David S. Miller9360ffd2012-03-29 04:41:26 -04007720 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7721 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7722 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7723 (req_ie &&
7724 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7725 (resp_ie &&
7726 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7727 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007728
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007729 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007730
Johannes Berg463d0182009-07-14 00:33:35 +02007731 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7732 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007733 return;
7734
7735 nla_put_failure:
7736 genlmsg_cancel(msg, hdr);
7737 nlmsg_free(msg);
7738
7739}
7740
7741void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7742 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02007743 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007744{
7745 struct sk_buff *msg;
7746 void *hdr;
7747
Johannes Berg667503d2009-07-07 03:56:11 +02007748 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007749 if (!msg)
7750 return;
7751
7752 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7753 if (!hdr) {
7754 nlmsg_free(msg);
7755 return;
7756 }
7757
David S. Miller9360ffd2012-03-29 04:41:26 -04007758 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7759 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7760 (from_ap && reason &&
7761 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7762 (from_ap &&
7763 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7764 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7765 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007766
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007767 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007768
Johannes Berg463d0182009-07-14 00:33:35 +02007769 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7770 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007771 return;
7772
7773 nla_put_failure:
7774 genlmsg_cancel(msg, hdr);
7775 nlmsg_free(msg);
7776
7777}
7778
Johannes Berg04a773a2009-04-19 21:24:32 +02007779void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7780 struct net_device *netdev, const u8 *bssid,
7781 gfp_t gfp)
7782{
7783 struct sk_buff *msg;
7784 void *hdr;
7785
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007786 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007787 if (!msg)
7788 return;
7789
7790 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7791 if (!hdr) {
7792 nlmsg_free(msg);
7793 return;
7794 }
7795
David S. Miller9360ffd2012-03-29 04:41:26 -04007796 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7797 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7798 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7799 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007800
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007801 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007802
Johannes Berg463d0182009-07-14 00:33:35 +02007803 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7804 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007805 return;
7806
7807 nla_put_failure:
7808 genlmsg_cancel(msg, hdr);
7809 nlmsg_free(msg);
7810}
7811
Javier Cardonac93b5e72011-04-07 15:08:34 -07007812void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7813 struct net_device *netdev,
7814 const u8 *macaddr, const u8* ie, u8 ie_len,
7815 gfp_t gfp)
7816{
7817 struct sk_buff *msg;
7818 void *hdr;
7819
7820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7821 if (!msg)
7822 return;
7823
7824 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7825 if (!hdr) {
7826 nlmsg_free(msg);
7827 return;
7828 }
7829
David S. Miller9360ffd2012-03-29 04:41:26 -04007830 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7831 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7832 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7833 (ie_len && ie &&
7834 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7835 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007836
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007837 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007838
7839 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7840 nl80211_mlme_mcgrp.id, gfp);
7841 return;
7842
7843 nla_put_failure:
7844 genlmsg_cancel(msg, hdr);
7845 nlmsg_free(msg);
7846}
7847
Jouni Malinena3b8b052009-03-27 21:59:49 +02007848void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7849 struct net_device *netdev, const u8 *addr,
7850 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007851 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007852{
7853 struct sk_buff *msg;
7854 void *hdr;
7855
Johannes Berge6d6e342009-07-01 21:26:47 +02007856 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007857 if (!msg)
7858 return;
7859
7860 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7861 if (!hdr) {
7862 nlmsg_free(msg);
7863 return;
7864 }
7865
David S. Miller9360ffd2012-03-29 04:41:26 -04007866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7867 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7868 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7869 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7870 (key_id != -1 &&
7871 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7872 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7873 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007874
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007875 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007876
Johannes Berg463d0182009-07-14 00:33:35 +02007877 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7878 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007879 return;
7880
7881 nla_put_failure:
7882 genlmsg_cancel(msg, hdr);
7883 nlmsg_free(msg);
7884}
7885
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007886void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7887 struct ieee80211_channel *channel_before,
7888 struct ieee80211_channel *channel_after)
7889{
7890 struct sk_buff *msg;
7891 void *hdr;
7892 struct nlattr *nl_freq;
7893
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007894 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007895 if (!msg)
7896 return;
7897
7898 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7899 if (!hdr) {
7900 nlmsg_free(msg);
7901 return;
7902 }
7903
7904 /*
7905 * Since we are applying the beacon hint to a wiphy we know its
7906 * wiphy_idx is valid
7907 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007908 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7909 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007910
7911 /* Before */
7912 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7913 if (!nl_freq)
7914 goto nla_put_failure;
7915 if (nl80211_msg_put_channel(msg, channel_before))
7916 goto nla_put_failure;
7917 nla_nest_end(msg, nl_freq);
7918
7919 /* After */
7920 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7921 if (!nl_freq)
7922 goto nla_put_failure;
7923 if (nl80211_msg_put_channel(msg, channel_after))
7924 goto nla_put_failure;
7925 nla_nest_end(msg, nl_freq);
7926
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007927 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007928
Johannes Berg463d0182009-07-14 00:33:35 +02007929 rcu_read_lock();
7930 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7931 GFP_ATOMIC);
7932 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007933
7934 return;
7935
7936nla_put_failure:
7937 genlmsg_cancel(msg, hdr);
7938 nlmsg_free(msg);
7939}
7940
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007941static void nl80211_send_remain_on_chan_event(
7942 int cmd, struct cfg80211_registered_device *rdev,
7943 struct net_device *netdev, u64 cookie,
7944 struct ieee80211_channel *chan,
7945 enum nl80211_channel_type channel_type,
7946 unsigned int duration, gfp_t gfp)
7947{
7948 struct sk_buff *msg;
7949 void *hdr;
7950
7951 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7952 if (!msg)
7953 return;
7954
7955 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7956 if (!hdr) {
7957 nlmsg_free(msg);
7958 return;
7959 }
7960
David S. Miller9360ffd2012-03-29 04:41:26 -04007961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7962 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7963 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7964 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7965 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7966 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007967
David S. Miller9360ffd2012-03-29 04:41:26 -04007968 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7969 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7970 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007971
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007972 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007973
7974 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7975 nl80211_mlme_mcgrp.id, gfp);
7976 return;
7977
7978 nla_put_failure:
7979 genlmsg_cancel(msg, hdr);
7980 nlmsg_free(msg);
7981}
7982
7983void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7984 struct net_device *netdev, u64 cookie,
7985 struct ieee80211_channel *chan,
7986 enum nl80211_channel_type channel_type,
7987 unsigned int duration, gfp_t gfp)
7988{
7989 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7990 rdev, netdev, cookie, chan,
7991 channel_type, duration, gfp);
7992}
7993
7994void nl80211_send_remain_on_channel_cancel(
7995 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7996 u64 cookie, struct ieee80211_channel *chan,
7997 enum nl80211_channel_type channel_type, gfp_t gfp)
7998{
7999 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8000 rdev, netdev, cookie, chan,
8001 channel_type, 0, gfp);
8002}
8003
Johannes Berg98b62182009-12-23 13:15:44 +01008004void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
8005 struct net_device *dev, const u8 *mac_addr,
8006 struct station_info *sinfo, gfp_t gfp)
8007{
8008 struct sk_buff *msg;
8009
8010 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8011 if (!msg)
8012 return;
8013
John W. Linville66266b32012-03-15 13:25:41 -04008014 if (nl80211_send_station(msg, 0, 0, 0,
8015 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008016 nlmsg_free(msg);
8017 return;
8018 }
8019
8020 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8021 nl80211_mlme_mcgrp.id, gfp);
8022}
8023
Jouni Malinenec15e682011-03-23 15:29:52 +02008024void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8025 struct net_device *dev, const u8 *mac_addr,
8026 gfp_t gfp)
8027{
8028 struct sk_buff *msg;
8029 void *hdr;
8030
8031 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8032 if (!msg)
8033 return;
8034
8035 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8036 if (!hdr) {
8037 nlmsg_free(msg);
8038 return;
8039 }
8040
David S. Miller9360ffd2012-03-29 04:41:26 -04008041 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8042 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8043 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008044
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008045 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008046
8047 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8048 nl80211_mlme_mcgrp.id, gfp);
8049 return;
8050
8051 nla_put_failure:
8052 genlmsg_cancel(msg, hdr);
8053 nlmsg_free(msg);
8054}
8055
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008056static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8057 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008058{
8059 struct wireless_dev *wdev = dev->ieee80211_ptr;
8060 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8061 struct sk_buff *msg;
8062 void *hdr;
8063 int err;
8064 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8065
8066 if (!nlpid)
8067 return false;
8068
8069 msg = nlmsg_new(100, gfp);
8070 if (!msg)
8071 return true;
8072
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008073 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008074 if (!hdr) {
8075 nlmsg_free(msg);
8076 return true;
8077 }
8078
David S. Miller9360ffd2012-03-29 04:41:26 -04008079 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8080 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8081 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8082 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008083
8084 err = genlmsg_end(msg, hdr);
8085 if (err < 0) {
8086 nlmsg_free(msg);
8087 return true;
8088 }
8089
8090 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8091 return true;
8092
8093 nla_put_failure:
8094 genlmsg_cancel(msg, hdr);
8095 nlmsg_free(msg);
8096 return true;
8097}
8098
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008099bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8100{
8101 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8102 addr, gfp);
8103}
8104
8105bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8106 const u8 *addr, gfp_t gfp)
8107{
8108 return __nl80211_unexpected_frame(dev,
8109 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8110 addr, gfp);
8111}
8112
Johannes Berg2e161f72010-08-12 15:38:38 +02008113int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8114 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008115 int freq, int sig_dbm,
8116 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008117{
8118 struct sk_buff *msg;
8119 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008120
8121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8122 if (!msg)
8123 return -ENOMEM;
8124
Johannes Berg2e161f72010-08-12 15:38:38 +02008125 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008126 if (!hdr) {
8127 nlmsg_free(msg);
8128 return -ENOMEM;
8129 }
8130
David S. Miller9360ffd2012-03-29 04:41:26 -04008131 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8132 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8133 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8134 (sig_dbm &&
8135 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8136 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8137 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008138
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008139 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008140
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008141 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008142
8143 nla_put_failure:
8144 genlmsg_cancel(msg, hdr);
8145 nlmsg_free(msg);
8146 return -ENOBUFS;
8147}
8148
Johannes Berg2e161f72010-08-12 15:38:38 +02008149void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8150 struct net_device *netdev, u64 cookie,
8151 const u8 *buf, size_t len, bool ack,
8152 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008153{
8154 struct sk_buff *msg;
8155 void *hdr;
8156
8157 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8158 if (!msg)
8159 return;
8160
Johannes Berg2e161f72010-08-12 15:38:38 +02008161 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008162 if (!hdr) {
8163 nlmsg_free(msg);
8164 return;
8165 }
8166
David S. Miller9360ffd2012-03-29 04:41:26 -04008167 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8168 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8169 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8170 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8171 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8172 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008173
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008174 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008175
8176 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8177 return;
8178
8179 nla_put_failure:
8180 genlmsg_cancel(msg, hdr);
8181 nlmsg_free(msg);
8182}
8183
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008184void
8185nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8186 struct net_device *netdev,
8187 enum nl80211_cqm_rssi_threshold_event rssi_event,
8188 gfp_t gfp)
8189{
8190 struct sk_buff *msg;
8191 struct nlattr *pinfoattr;
8192 void *hdr;
8193
8194 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8195 if (!msg)
8196 return;
8197
8198 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8199 if (!hdr) {
8200 nlmsg_free(msg);
8201 return;
8202 }
8203
David S. Miller9360ffd2012-03-29 04:41:26 -04008204 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8205 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8206 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008207
8208 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8209 if (!pinfoattr)
8210 goto nla_put_failure;
8211
David S. Miller9360ffd2012-03-29 04:41:26 -04008212 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8213 rssi_event))
8214 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008215
8216 nla_nest_end(msg, pinfoattr);
8217
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008218 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008219
8220 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8221 nl80211_mlme_mcgrp.id, gfp);
8222 return;
8223
8224 nla_put_failure:
8225 genlmsg_cancel(msg, hdr);
8226 nlmsg_free(msg);
8227}
8228
Johannes Berge5497d72011-07-05 16:35:40 +02008229void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8230 struct net_device *netdev, const u8 *bssid,
8231 const u8 *replay_ctr, gfp_t gfp)
8232{
8233 struct sk_buff *msg;
8234 struct nlattr *rekey_attr;
8235 void *hdr;
8236
8237 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8238 if (!msg)
8239 return;
8240
8241 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8242 if (!hdr) {
8243 nlmsg_free(msg);
8244 return;
8245 }
8246
David S. Miller9360ffd2012-03-29 04:41:26 -04008247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8248 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8249 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8250 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008251
8252 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8253 if (!rekey_attr)
8254 goto nla_put_failure;
8255
David S. Miller9360ffd2012-03-29 04:41:26 -04008256 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8257 NL80211_REPLAY_CTR_LEN, replay_ctr))
8258 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008259
8260 nla_nest_end(msg, rekey_attr);
8261
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008262 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008263
8264 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8265 nl80211_mlme_mcgrp.id, gfp);
8266 return;
8267
8268 nla_put_failure:
8269 genlmsg_cancel(msg, hdr);
8270 nlmsg_free(msg);
8271}
8272
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008273void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8274 struct net_device *netdev, int index,
8275 const u8 *bssid, bool preauth, gfp_t gfp)
8276{
8277 struct sk_buff *msg;
8278 struct nlattr *attr;
8279 void *hdr;
8280
8281 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8282 if (!msg)
8283 return;
8284
8285 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8286 if (!hdr) {
8287 nlmsg_free(msg);
8288 return;
8289 }
8290
David S. Miller9360ffd2012-03-29 04:41:26 -04008291 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8292 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8293 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008294
8295 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8296 if (!attr)
8297 goto nla_put_failure;
8298
David S. Miller9360ffd2012-03-29 04:41:26 -04008299 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8300 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8301 (preauth &&
8302 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8303 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008304
8305 nla_nest_end(msg, attr);
8306
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008307 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008308
8309 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8310 nl80211_mlme_mcgrp.id, gfp);
8311 return;
8312
8313 nla_put_failure:
8314 genlmsg_cancel(msg, hdr);
8315 nlmsg_free(msg);
8316}
8317
Thomas Pedersen53145262012-04-06 13:35:47 -07008318void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8319 struct net_device *netdev, int freq,
8320 enum nl80211_channel_type type, gfp_t gfp)
8321{
8322 struct sk_buff *msg;
8323 void *hdr;
8324
8325 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8326 if (!msg)
8327 return;
8328
8329 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8330 if (!hdr) {
8331 nlmsg_free(msg);
8332 return;
8333 }
8334
John W. Linville7eab0f62012-04-12 14:25:14 -04008335 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8336 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8337 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8338 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008339
8340 genlmsg_end(msg, hdr);
8341
8342 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8343 nl80211_mlme_mcgrp.id, gfp);
8344 return;
8345
8346 nla_put_failure:
8347 genlmsg_cancel(msg, hdr);
8348 nlmsg_free(msg);
8349}
8350
Johannes Bergc063dbf2010-11-24 08:10:05 +01008351void
8352nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8353 struct net_device *netdev, const u8 *peer,
8354 u32 num_packets, gfp_t gfp)
8355{
8356 struct sk_buff *msg;
8357 struct nlattr *pinfoattr;
8358 void *hdr;
8359
8360 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8361 if (!msg)
8362 return;
8363
8364 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8365 if (!hdr) {
8366 nlmsg_free(msg);
8367 return;
8368 }
8369
David S. Miller9360ffd2012-03-29 04:41:26 -04008370 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8371 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8372 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8373 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008374
8375 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8376 if (!pinfoattr)
8377 goto nla_put_failure;
8378
David S. Miller9360ffd2012-03-29 04:41:26 -04008379 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8380 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008381
8382 nla_nest_end(msg, pinfoattr);
8383
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008384 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008385
8386 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8387 nl80211_mlme_mcgrp.id, gfp);
8388 return;
8389
8390 nla_put_failure:
8391 genlmsg_cancel(msg, hdr);
8392 nlmsg_free(msg);
8393}
8394
Johannes Berg7f6cf312011-11-04 11:18:15 +01008395void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8396 u64 cookie, bool acked, gfp_t gfp)
8397{
8398 struct wireless_dev *wdev = dev->ieee80211_ptr;
8399 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8400 struct sk_buff *msg;
8401 void *hdr;
8402 int err;
8403
8404 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8405 if (!msg)
8406 return;
8407
8408 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8409 if (!hdr) {
8410 nlmsg_free(msg);
8411 return;
8412 }
8413
David S. Miller9360ffd2012-03-29 04:41:26 -04008414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8415 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8416 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8417 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8418 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8419 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008420
8421 err = genlmsg_end(msg, hdr);
8422 if (err < 0) {
8423 nlmsg_free(msg);
8424 return;
8425 }
8426
8427 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8428 nl80211_mlme_mcgrp.id, gfp);
8429 return;
8430
8431 nla_put_failure:
8432 genlmsg_cancel(msg, hdr);
8433 nlmsg_free(msg);
8434}
8435EXPORT_SYMBOL(cfg80211_probe_status);
8436
Johannes Berg5e760232011-11-04 11:18:17 +01008437void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8438 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008439 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008440{
8441 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8442 struct sk_buff *msg;
8443 void *hdr;
8444 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8445
8446 if (!nlpid)
8447 return;
8448
8449 msg = nlmsg_new(len + 100, gfp);
8450 if (!msg)
8451 return;
8452
8453 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8454 if (!hdr) {
8455 nlmsg_free(msg);
8456 return;
8457 }
8458
David S. Miller9360ffd2012-03-29 04:41:26 -04008459 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8460 (freq &&
8461 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8462 (sig_dbm &&
8463 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8464 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8465 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01008466
8467 genlmsg_end(msg, hdr);
8468
8469 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8470 return;
8471
8472 nla_put_failure:
8473 genlmsg_cancel(msg, hdr);
8474 nlmsg_free(msg);
8475}
8476EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8477
Jouni Malinen026331c2010-02-15 12:53:10 +02008478static int nl80211_netlink_notify(struct notifier_block * nb,
8479 unsigned long state,
8480 void *_notify)
8481{
8482 struct netlink_notify *notify = _notify;
8483 struct cfg80211_registered_device *rdev;
8484 struct wireless_dev *wdev;
8485
8486 if (state != NETLINK_URELEASE)
8487 return NOTIFY_DONE;
8488
8489 rcu_read_lock();
8490
Johannes Berg5e760232011-11-04 11:18:17 +01008491 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008492 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008493 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008494 if (rdev->ap_beacons_nlpid == notify->pid)
8495 rdev->ap_beacons_nlpid = 0;
8496 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008497
8498 rcu_read_unlock();
8499
8500 return NOTIFY_DONE;
8501}
8502
8503static struct notifier_block nl80211_netlink_notifier = {
8504 .notifier_call = nl80211_netlink_notify,
8505};
8506
Johannes Berg55682962007-09-20 13:09:35 -04008507/* initialisation/exit functions */
8508
8509int nl80211_init(void)
8510{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008511 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008512
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008513 err = genl_register_family_with_ops(&nl80211_fam,
8514 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008515 if (err)
8516 return err;
8517
Johannes Berg55682962007-09-20 13:09:35 -04008518 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8519 if (err)
8520 goto err_out;
8521
Johannes Berg2a519312009-02-10 21:25:55 +01008522 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8523 if (err)
8524 goto err_out;
8525
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008526 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8527 if (err)
8528 goto err_out;
8529
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008530 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8531 if (err)
8532 goto err_out;
8533
Johannes Bergaff89a92009-07-01 21:26:51 +02008534#ifdef CONFIG_NL80211_TESTMODE
8535 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8536 if (err)
8537 goto err_out;
8538#endif
8539
Jouni Malinen026331c2010-02-15 12:53:10 +02008540 err = netlink_register_notifier(&nl80211_netlink_notifier);
8541 if (err)
8542 goto err_out;
8543
Johannes Berg55682962007-09-20 13:09:35 -04008544 return 0;
8545 err_out:
8546 genl_unregister_family(&nl80211_fam);
8547 return err;
8548}
8549
8550void nl80211_exit(void)
8551{
Jouni Malinen026331c2010-02-15 12:53:10 +02008552 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008553 genl_unregister_family(&nl80211_fam);
8554}