blob: 888fadc4d63e68a595a9e1764ab898e7a46c08af [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 Malinendc6382c2009-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 },
343};
344
Holger Schuriga0438972009-11-11 11:30:02 +0100345/* ifidx get helper */
346static int nl80211_get_ifidx(struct netlink_callback *cb)
347{
348 int res;
349
350 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
351 nl80211_fam.attrbuf, nl80211_fam.maxattr,
352 nl80211_policy);
353 if (res)
354 return res;
355
356 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
357 return -EINVAL;
358
359 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
360 if (!res)
361 return -EINVAL;
362 return res;
363}
364
Johannes Berg67748892010-10-04 21:14:06 +0200365static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
366 struct netlink_callback *cb,
367 struct cfg80211_registered_device **rdev,
368 struct net_device **dev)
369{
370 int ifidx = cb->args[0];
371 int err;
372
373 if (!ifidx)
374 ifidx = nl80211_get_ifidx(cb);
375 if (ifidx < 0)
376 return ifidx;
377
378 cb->args[0] = ifidx;
379
380 rtnl_lock();
381
382 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
383 if (!*dev) {
384 err = -ENODEV;
385 goto out_rtnl;
386 }
387
388 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100389 if (IS_ERR(*rdev)) {
390 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200391 goto out_rtnl;
392 }
393
394 return 0;
395 out_rtnl:
396 rtnl_unlock();
397 return err;
398}
399
400static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
401{
402 cfg80211_unlock_rdev(rdev);
403 rtnl_unlock();
404}
405
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100406/* IE validation */
407static bool is_valid_ie_attr(const struct nlattr *attr)
408{
409 const u8 *pos;
410 int len;
411
412 if (!attr)
413 return true;
414
415 pos = nla_data(attr);
416 len = nla_len(attr);
417
418 while (len) {
419 u8 elemlen;
420
421 if (len < 2)
422 return false;
423 len -= 2;
424
425 elemlen = pos[1];
426 if (elemlen > len)
427 return false;
428
429 len -= elemlen;
430 pos += 2 + elemlen;
431 }
432
433 return true;
434}
435
Johannes Berg55682962007-09-20 13:09:35 -0400436/* message building helper */
437static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
438 int flags, u8 cmd)
439{
440 /* since there is no private header just add the generic one */
441 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
442}
443
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400444static int nl80211_msg_put_channel(struct sk_buff *msg,
445 struct ieee80211_channel *chan)
446{
David S. Miller9360ffd2012-03-29 04:41:26 -0400447 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
448 chan->center_freq))
449 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400450
David S. Miller9360ffd2012-03-29 04:41:26 -0400451 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
452 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
453 goto nla_put_failure;
454 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
455 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
456 goto nla_put_failure;
457 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
458 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
459 goto nla_put_failure;
460 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
461 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
462 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400463
David S. Miller9360ffd2012-03-29 04:41:26 -0400464 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
465 DBM_TO_MBM(chan->max_power)))
466 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400467
468 return 0;
469
470 nla_put_failure:
471 return -ENOBUFS;
472}
473
Johannes Berg55682962007-09-20 13:09:35 -0400474/* netlink command implementations */
475
Johannes Bergb9454e82009-07-08 13:29:08 +0200476struct key_parse {
477 struct key_params p;
478 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200479 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200480 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100481 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200482};
483
484static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
485{
486 struct nlattr *tb[NL80211_KEY_MAX + 1];
487 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
488 nl80211_key_policy);
489 if (err)
490 return err;
491
492 k->def = !!tb[NL80211_KEY_DEFAULT];
493 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
494
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100495 if (k->def) {
496 k->def_uni = true;
497 k->def_multi = true;
498 }
499 if (k->defmgmt)
500 k->def_multi = true;
501
Johannes Bergb9454e82009-07-08 13:29:08 +0200502 if (tb[NL80211_KEY_IDX])
503 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
504
505 if (tb[NL80211_KEY_DATA]) {
506 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
507 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
508 }
509
510 if (tb[NL80211_KEY_SEQ]) {
511 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
512 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
513 }
514
515 if (tb[NL80211_KEY_CIPHER])
516 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
517
Johannes Berge31b8212010-10-05 19:39:30 +0200518 if (tb[NL80211_KEY_TYPE]) {
519 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
520 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
521 return -EINVAL;
522 }
523
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100524 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
525 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100526 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
527 tb[NL80211_KEY_DEFAULT_TYPES],
528 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100529 if (err)
530 return err;
531
532 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
533 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
534 }
535
Johannes Bergb9454e82009-07-08 13:29:08 +0200536 return 0;
537}
538
539static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
540{
541 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
542 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
543 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
544 }
545
546 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
547 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
548 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
549 }
550
551 if (info->attrs[NL80211_ATTR_KEY_IDX])
552 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
553
554 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
555 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
556
557 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
558 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
559
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100560 if (k->def) {
561 k->def_uni = true;
562 k->def_multi = true;
563 }
564 if (k->defmgmt)
565 k->def_multi = true;
566
Johannes Berge31b8212010-10-05 19:39:30 +0200567 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
568 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
569 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
570 return -EINVAL;
571 }
572
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100573 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
574 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
575 int err = nla_parse_nested(
576 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
577 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
578 nl80211_key_default_policy);
579 if (err)
580 return err;
581
582 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
583 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
584 }
585
Johannes Bergb9454e82009-07-08 13:29:08 +0200586 return 0;
587}
588
589static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
590{
591 int err;
592
593 memset(k, 0, sizeof(*k));
594 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200595 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200596
597 if (info->attrs[NL80211_ATTR_KEY])
598 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
599 else
600 err = nl80211_parse_key_old(info, k);
601
602 if (err)
603 return err;
604
605 if (k->def && k->defmgmt)
606 return -EINVAL;
607
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100608 if (k->defmgmt) {
609 if (k->def_uni || !k->def_multi)
610 return -EINVAL;
611 }
612
Johannes Bergb9454e82009-07-08 13:29:08 +0200613 if (k->idx != -1) {
614 if (k->defmgmt) {
615 if (k->idx < 4 || k->idx > 5)
616 return -EINVAL;
617 } else if (k->def) {
618 if (k->idx < 0 || k->idx > 3)
619 return -EINVAL;
620 } else {
621 if (k->idx < 0 || k->idx > 5)
622 return -EINVAL;
623 }
624 }
625
626 return 0;
627}
628
Johannes Bergfffd0932009-07-08 14:22:54 +0200629static struct cfg80211_cached_keys *
630nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
631 struct nlattr *keys)
632{
633 struct key_parse parse;
634 struct nlattr *key;
635 struct cfg80211_cached_keys *result;
636 int rem, err, def = 0;
637
638 result = kzalloc(sizeof(*result), GFP_KERNEL);
639 if (!result)
640 return ERR_PTR(-ENOMEM);
641
642 result->def = -1;
643 result->defmgmt = -1;
644
645 nla_for_each_nested(key, keys, rem) {
646 memset(&parse, 0, sizeof(parse));
647 parse.idx = -1;
648
649 err = nl80211_parse_key_new(key, &parse);
650 if (err)
651 goto error;
652 err = -EINVAL;
653 if (!parse.p.key)
654 goto error;
655 if (parse.idx < 0 || parse.idx > 4)
656 goto error;
657 if (parse.def) {
658 if (def)
659 goto error;
660 def = 1;
661 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100662 if (!parse.def_uni || !parse.def_multi)
663 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200664 } else if (parse.defmgmt)
665 goto error;
666 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200667 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200668 if (err)
669 goto error;
670 result->params[parse.idx].cipher = parse.p.cipher;
671 result->params[parse.idx].key_len = parse.p.key_len;
672 result->params[parse.idx].key = result->data[parse.idx];
673 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
674 }
675
676 return result;
677 error:
678 kfree(result);
679 return ERR_PTR(err);
680}
681
682static int nl80211_key_allowed(struct wireless_dev *wdev)
683{
684 ASSERT_WDEV_LOCK(wdev);
685
Johannes Bergfffd0932009-07-08 14:22:54 +0200686 switch (wdev->iftype) {
687 case NL80211_IFTYPE_AP:
688 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200689 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700690 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200691 break;
692 case NL80211_IFTYPE_ADHOC:
693 if (!wdev->current_bss)
694 return -ENOLINK;
695 break;
696 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200697 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200698 if (wdev->sme_state != CFG80211_SME_CONNECTED)
699 return -ENOLINK;
700 break;
701 default:
702 return -EINVAL;
703 }
704
705 return 0;
706}
707
Johannes Berg7527a782011-05-13 10:58:57 +0200708static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
709{
710 struct nlattr *nl_modes = nla_nest_start(msg, attr);
711 int i;
712
713 if (!nl_modes)
714 goto nla_put_failure;
715
716 i = 0;
717 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400718 if ((ifmodes & 1) && nla_put_flag(msg, i))
719 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200720 ifmodes >>= 1;
721 i++;
722 }
723
724 nla_nest_end(msg, nl_modes);
725 return 0;
726
727nla_put_failure:
728 return -ENOBUFS;
729}
730
731static int nl80211_put_iface_combinations(struct wiphy *wiphy,
732 struct sk_buff *msg)
733{
734 struct nlattr *nl_combis;
735 int i, j;
736
737 nl_combis = nla_nest_start(msg,
738 NL80211_ATTR_INTERFACE_COMBINATIONS);
739 if (!nl_combis)
740 goto nla_put_failure;
741
742 for (i = 0; i < wiphy->n_iface_combinations; i++) {
743 const struct ieee80211_iface_combination *c;
744 struct nlattr *nl_combi, *nl_limits;
745
746 c = &wiphy->iface_combinations[i];
747
748 nl_combi = nla_nest_start(msg, i + 1);
749 if (!nl_combi)
750 goto nla_put_failure;
751
752 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
753 if (!nl_limits)
754 goto nla_put_failure;
755
756 for (j = 0; j < c->n_limits; j++) {
757 struct nlattr *nl_limit;
758
759 nl_limit = nla_nest_start(msg, j + 1);
760 if (!nl_limit)
761 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400762 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
763 c->limits[j].max))
764 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200765 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
766 c->limits[j].types))
767 goto nla_put_failure;
768 nla_nest_end(msg, nl_limit);
769 }
770
771 nla_nest_end(msg, nl_limits);
772
David S. Miller9360ffd2012-03-29 04:41:26 -0400773 if (c->beacon_int_infra_match &&
774 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
775 goto nla_put_failure;
776 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
777 c->num_different_channels) ||
778 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
779 c->max_interfaces))
780 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200781
782 nla_nest_end(msg, nl_combi);
783 }
784
785 nla_nest_end(msg, nl_combis);
786
787 return 0;
788nla_put_failure:
789 return -ENOBUFS;
790}
791
Johannes Berg55682962007-09-20 13:09:35 -0400792static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
793 struct cfg80211_registered_device *dev)
794{
795 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100796 struct nlattr *nl_bands, *nl_band;
797 struct nlattr *nl_freqs, *nl_freq;
798 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100799 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100800 enum ieee80211_band band;
801 struct ieee80211_channel *chan;
802 struct ieee80211_rate *rate;
803 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200804 const struct ieee80211_txrx_stypes *mgmt_stypes =
805 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400806
807 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
808 if (!hdr)
809 return -1;
810
David S. Miller9360ffd2012-03-29 04:41:26 -0400811 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
812 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
813 nla_put_u32(msg, NL80211_ATTR_GENERATION,
814 cfg80211_rdev_list_generation) ||
815 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
816 dev->wiphy.retry_short) ||
817 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
818 dev->wiphy.retry_long) ||
819 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
820 dev->wiphy.frag_threshold) ||
821 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
822 dev->wiphy.rts_threshold) ||
823 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
824 dev->wiphy.coverage_class) ||
825 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
826 dev->wiphy.max_scan_ssids) ||
827 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
828 dev->wiphy.max_sched_scan_ssids) ||
829 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
830 dev->wiphy.max_scan_ie_len) ||
831 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
832 dev->wiphy.max_sched_scan_ie_len) ||
833 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
834 dev->wiphy.max_match_sets))
835 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200836
David S. Miller9360ffd2012-03-29 04:41:26 -0400837 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
838 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
839 goto nla_put_failure;
840 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
841 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
842 goto nla_put_failure;
843 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
844 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
845 goto nla_put_failure;
846 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
847 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
848 goto nla_put_failure;
849 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
850 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
851 goto nla_put_failure;
852 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
853 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
854 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200855
David S. Miller9360ffd2012-03-29 04:41:26 -0400856 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
857 sizeof(u32) * dev->wiphy.n_cipher_suites,
858 dev->wiphy.cipher_suites))
859 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100860
David S. Miller9360ffd2012-03-29 04:41:26 -0400861 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
862 dev->wiphy.max_num_pmkids))
863 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530864
David S. Miller9360ffd2012-03-29 04:41:26 -0400865 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
866 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
867 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200868
David S. Miller9360ffd2012-03-29 04:41:26 -0400869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
870 dev->wiphy.available_antennas_tx) ||
871 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
872 dev->wiphy.available_antennas_rx))
873 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100874
David S. Miller9360ffd2012-03-29 04:41:26 -0400875 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
876 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
877 dev->wiphy.probe_resp_offload))
878 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200879
Bruno Randolf7f531e02010-12-16 11:30:22 +0900880 if ((dev->wiphy.available_antennas_tx ||
881 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900882 u32 tx_ant = 0, rx_ant = 0;
883 int res;
884 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
885 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
887 tx_ant) ||
888 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
889 rx_ant))
890 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900891 }
892 }
893
Johannes Berg7527a782011-05-13 10:58:57 +0200894 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
895 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700896 goto nla_put_failure;
897
Johannes Bergee688b002008-01-24 19:38:39 +0100898 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
899 if (!nl_bands)
900 goto nla_put_failure;
901
902 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
903 if (!dev->wiphy.bands[band])
904 continue;
905
906 nl_band = nla_nest_start(msg, band);
907 if (!nl_band)
908 goto nla_put_failure;
909
Johannes Bergd51626d2008-10-09 12:20:13 +0200910 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400911 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
912 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
913 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
914 &dev->wiphy.bands[band]->ht_cap.mcs) ||
915 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
916 dev->wiphy.bands[band]->ht_cap.cap) ||
917 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
918 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
919 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
920 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
921 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200922
Johannes Bergee688b002008-01-24 19:38:39 +0100923 /* add frequencies */
924 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
925 if (!nl_freqs)
926 goto nla_put_failure;
927
928 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
929 nl_freq = nla_nest_start(msg, i);
930 if (!nl_freq)
931 goto nla_put_failure;
932
933 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100934
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400935 if (nl80211_msg_put_channel(msg, chan))
936 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200937
Johannes Bergee688b002008-01-24 19:38:39 +0100938 nla_nest_end(msg, nl_freq);
939 }
940
941 nla_nest_end(msg, nl_freqs);
942
943 /* add bitrates */
944 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
945 if (!nl_rates)
946 goto nla_put_failure;
947
948 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
949 nl_rate = nla_nest_start(msg, i);
950 if (!nl_rate)
951 goto nla_put_failure;
952
953 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400954 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
955 rate->bitrate))
956 goto nla_put_failure;
957 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
958 nla_put_flag(msg,
959 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
960 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100961
962 nla_nest_end(msg, nl_rate);
963 }
964
965 nla_nest_end(msg, nl_rates);
966
967 nla_nest_end(msg, nl_band);
968 }
969 nla_nest_end(msg, nl_bands);
970
Johannes Berg8fdc6212009-03-14 09:34:01 +0100971 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
972 if (!nl_cmds)
973 goto nla_put_failure;
974
975 i = 0;
976#define CMD(op, n) \
977 do { \
978 if (dev->ops->op) { \
979 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400980 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
981 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100982 } \
983 } while (0)
984
985 CMD(add_virtual_intf, NEW_INTERFACE);
986 CMD(change_virtual_intf, SET_INTERFACE);
987 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100988 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100989 CMD(add_station, NEW_STATION);
990 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800991 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100992 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200993 CMD(auth, AUTHENTICATE);
994 CMD(assoc, ASSOCIATE);
995 CMD(deauth, DEAUTHENTICATE);
996 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200997 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +0100998 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100999 CMD(set_pmksa, SET_PMKSA);
1000 CMD(del_pmksa, DEL_PMKSA);
1001 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001002 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1003 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001004 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001005 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001006 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001007 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001008 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001009 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1010 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001011 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001012 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001013 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001014 i++;
1015 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1016 goto nla_put_failure;
1017 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001018 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001019 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1020 CMD(tdls_mgmt, TDLS_MGMT);
1021 CMD(tdls_oper, TDLS_OPER);
1022 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001023 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1024 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001025 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001026 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001027 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1028 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001029 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1030 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001031 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001032
Kalle Valo4745fc02011-11-17 19:06:10 +02001033#ifdef CONFIG_NL80211_TESTMODE
1034 CMD(testmode_cmd, TESTMODE);
1035#endif
1036
Johannes Berg8fdc6212009-03-14 09:34:01 +01001037#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001038
Johannes Berg6829c872009-07-02 09:13:27 +02001039 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001040 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001041 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1042 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001043 }
1044
Johannes Berg6829c872009-07-02 09:13:27 +02001045 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001046 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001047 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1048 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001049 }
1050
Johannes Berg8fdc6212009-03-14 09:34:01 +01001051 nla_nest_end(msg, nl_cmds);
1052
Johannes Berg7c4ef712011-11-18 15:33:48 +01001053 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001054 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1055 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1056 dev->wiphy.max_remain_on_channel_duration))
1057 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001058
David S. Miller9360ffd2012-03-29 04:41:26 -04001059 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1060 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1061 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001062
Johannes Berg2e161f72010-08-12 15:38:38 +02001063 if (mgmt_stypes) {
1064 u16 stypes;
1065 struct nlattr *nl_ftypes, *nl_ifs;
1066 enum nl80211_iftype ift;
1067
1068 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1069 if (!nl_ifs)
1070 goto nla_put_failure;
1071
1072 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1073 nl_ftypes = nla_nest_start(msg, ift);
1074 if (!nl_ftypes)
1075 goto nla_put_failure;
1076 i = 0;
1077 stypes = mgmt_stypes[ift].tx;
1078 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001079 if ((stypes & 1) &&
1080 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1081 (i << 4) | IEEE80211_FTYPE_MGMT))
1082 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001083 stypes >>= 1;
1084 i++;
1085 }
1086 nla_nest_end(msg, nl_ftypes);
1087 }
1088
Johannes Berg74b70a42010-08-24 12:15:53 +02001089 nla_nest_end(msg, nl_ifs);
1090
Johannes Berg2e161f72010-08-12 15:38:38 +02001091 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1092 if (!nl_ifs)
1093 goto nla_put_failure;
1094
1095 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1096 nl_ftypes = nla_nest_start(msg, ift);
1097 if (!nl_ftypes)
1098 goto nla_put_failure;
1099 i = 0;
1100 stypes = mgmt_stypes[ift].rx;
1101 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001102 if ((stypes & 1) &&
1103 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1104 (i << 4) | IEEE80211_FTYPE_MGMT))
1105 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001106 stypes >>= 1;
1107 i++;
1108 }
1109 nla_nest_end(msg, nl_ftypes);
1110 }
1111 nla_nest_end(msg, nl_ifs);
1112 }
1113
Johannes Bergff1b6e62011-05-04 15:37:28 +02001114 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1115 struct nlattr *nl_wowlan;
1116
1117 nl_wowlan = nla_nest_start(msg,
1118 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1119 if (!nl_wowlan)
1120 goto nla_put_failure;
1121
David S. Miller9360ffd2012-03-29 04:41:26 -04001122 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1123 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1124 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1125 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1126 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1127 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1128 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1129 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1130 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1131 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1132 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1134 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1135 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1136 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1138 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001139 if (dev->wiphy.wowlan.n_patterns) {
1140 struct nl80211_wowlan_pattern_support pat = {
1141 .max_patterns = dev->wiphy.wowlan.n_patterns,
1142 .min_pattern_len =
1143 dev->wiphy.wowlan.pattern_min_len,
1144 .max_pattern_len =
1145 dev->wiphy.wowlan.pattern_max_len,
1146 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1148 sizeof(pat), &pat))
1149 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001150 }
1151
1152 nla_nest_end(msg, nl_wowlan);
1153 }
1154
Johannes Berg7527a782011-05-13 10:58:57 +02001155 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1156 dev->wiphy.software_iftypes))
1157 goto nla_put_failure;
1158
1159 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1160 goto nla_put_failure;
1161
David S. Miller9360ffd2012-03-29 04:41:26 -04001162 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1163 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1164 dev->wiphy.ap_sme_capa))
1165 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001166
David S. Miller9360ffd2012-03-29 04:41:26 -04001167 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1168 dev->wiphy.features))
1169 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001170
David S. Miller9360ffd2012-03-29 04:41:26 -04001171 if (dev->wiphy.ht_capa_mod_mask &&
1172 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1173 sizeof(*dev->wiphy.ht_capa_mod_mask),
1174 dev->wiphy.ht_capa_mod_mask))
1175 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001176
Johannes Berg55682962007-09-20 13:09:35 -04001177 return genlmsg_end(msg, hdr);
1178
1179 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001180 genlmsg_cancel(msg, hdr);
1181 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001182}
1183
1184static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1185{
1186 int idx = 0;
1187 int start = cb->args[0];
1188 struct cfg80211_registered_device *dev;
1189
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001190 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001191 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001192 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1193 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001194 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001195 continue;
1196 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1197 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001198 dev) < 0) {
1199 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001200 break;
Julius Volzb4637272008-07-08 14:02:19 +02001201 }
Johannes Berg55682962007-09-20 13:09:35 -04001202 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001203 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001204
1205 cb->args[0] = idx;
1206
1207 return skb->len;
1208}
1209
1210static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1211{
1212 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001213 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001214
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001215 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001216 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001217 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001218
Johannes Berg4c476992010-10-04 21:36:35 +02001219 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1220 nlmsg_free(msg);
1221 return -ENOBUFS;
1222 }
Johannes Berg55682962007-09-20 13:09:35 -04001223
Johannes Berg134e6372009-07-10 09:51:34 +00001224 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001225}
1226
Jouni Malinen31888482008-10-30 16:59:24 +02001227static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1228 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1229 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1230 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1231 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1232 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1233};
1234
1235static int parse_txq_params(struct nlattr *tb[],
1236 struct ieee80211_txq_params *txq_params)
1237{
Johannes Berga3304b02012-03-28 11:04:24 +02001238 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001239 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1240 !tb[NL80211_TXQ_ATTR_AIFS])
1241 return -EINVAL;
1242
Johannes Berga3304b02012-03-28 11:04:24 +02001243 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001244 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1245 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1246 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1247 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1248
Johannes Berga3304b02012-03-28 11:04:24 +02001249 if (txq_params->ac >= NL80211_NUM_ACS)
1250 return -EINVAL;
1251
Jouni Malinen31888482008-10-30 16:59:24 +02001252 return 0;
1253}
1254
Johannes Bergf444de02010-05-05 15:25:02 +02001255static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1256{
1257 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001258 * You can only set the channel explicitly for WDS interfaces,
1259 * all others have their channel managed via their respective
1260 * "establish a connection" command (connect, join, ...)
1261 *
1262 * For AP/GO and mesh mode, the channel can be set with the
1263 * channel userspace API, but is only stored and passed to the
1264 * low-level driver when the AP starts or the mesh is joined.
1265 * This is for backward compatibility, userspace can also give
1266 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001267 *
1268 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001269 * whatever else is going on, so they have their own special
1270 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001271 */
1272 return !wdev ||
1273 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001274 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001275 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1276 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001277}
1278
Johannes Bergcd6c6592012-05-10 21:27:18 +02001279static bool nl80211_valid_channel_type(struct genl_info *info,
1280 enum nl80211_channel_type *channel_type)
1281{
1282 enum nl80211_channel_type tmp;
1283
1284 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1285 return false;
1286
1287 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1288 if (tmp != NL80211_CHAN_NO_HT &&
1289 tmp != NL80211_CHAN_HT20 &&
1290 tmp != NL80211_CHAN_HT40PLUS &&
1291 tmp != NL80211_CHAN_HT40MINUS)
1292 return false;
1293
1294 if (channel_type)
1295 *channel_type = tmp;
1296
1297 return true;
1298}
1299
Johannes Bergf444de02010-05-05 15:25:02 +02001300static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1301 struct wireless_dev *wdev,
1302 struct genl_info *info)
1303{
Johannes Bergaa430da2012-05-16 23:50:18 +02001304 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001305 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1306 u32 freq;
1307 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001308 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1309
1310 if (wdev)
1311 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001312
1313 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1314 return -EINVAL;
1315
1316 if (!nl80211_can_set_dev_channel(wdev))
1317 return -EOPNOTSUPP;
1318
Johannes Bergcd6c6592012-05-10 21:27:18 +02001319 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1320 !nl80211_valid_channel_type(info, &channel_type))
1321 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001322
1323 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1324
1325 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001326 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001327 case NL80211_IFTYPE_AP:
1328 case NL80211_IFTYPE_P2P_GO:
1329 if (wdev->beacon_interval) {
1330 result = -EBUSY;
1331 break;
1332 }
1333 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1334 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1335 channel,
1336 channel_type)) {
1337 result = -EINVAL;
1338 break;
1339 }
1340 wdev->preset_chan = channel;
1341 wdev->preset_chantype = channel_type;
1342 result = 0;
1343 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001344 case NL80211_IFTYPE_MESH_POINT:
1345 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1346 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001347 case NL80211_IFTYPE_MONITOR:
1348 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1349 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001350 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001351 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001352 }
1353 mutex_unlock(&rdev->devlist_mtx);
1354
1355 return result;
1356}
1357
1358static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1359{
Johannes Berg4c476992010-10-04 21:36:35 +02001360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1361 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001362
Johannes Berg4c476992010-10-04 21:36:35 +02001363 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001364}
1365
Bill Jordane8347eb2010-10-01 13:54:28 -04001366static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1367{
Johannes Berg43b19952010-10-07 13:10:30 +02001368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1369 struct net_device *dev = info->user_ptr[1];
1370 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001371 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001372
1373 if (!info->attrs[NL80211_ATTR_MAC])
1374 return -EINVAL;
1375
Johannes Berg43b19952010-10-07 13:10:30 +02001376 if (netif_running(dev))
1377 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001378
Johannes Berg43b19952010-10-07 13:10:30 +02001379 if (!rdev->ops->set_wds_peer)
1380 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001381
Johannes Berg43b19952010-10-07 13:10:30 +02001382 if (wdev->iftype != NL80211_IFTYPE_WDS)
1383 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001384
1385 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001386 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001387}
1388
1389
Johannes Berg55682962007-09-20 13:09:35 -04001390static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1391{
1392 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001393 struct net_device *netdev = NULL;
1394 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001395 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001396 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001397 u32 changed;
1398 u8 retry_short = 0, retry_long = 0;
1399 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001400 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001401
Johannes Bergf444de02010-05-05 15:25:02 +02001402 /*
1403 * Try to find the wiphy and netdev. Normally this
1404 * function shouldn't need the netdev, but this is
1405 * done for backward compatibility -- previously
1406 * setting the channel was done per wiphy, but now
1407 * it is per netdev. Previous userland like hostapd
1408 * also passed a netdev to set_wiphy, so that it is
1409 * possible to let that go to the right netdev!
1410 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001411 mutex_lock(&cfg80211_mutex);
1412
Johannes Bergf444de02010-05-05 15:25:02 +02001413 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1414 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1415
1416 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1417 if (netdev && netdev->ieee80211_ptr) {
1418 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1419 mutex_lock(&rdev->mtx);
1420 } else
1421 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001422 }
1423
Johannes Bergf444de02010-05-05 15:25:02 +02001424 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001425 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1426 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001427 if (IS_ERR(rdev)) {
1428 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001429 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001430 }
1431 wdev = NULL;
1432 netdev = NULL;
1433 result = 0;
1434
1435 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001436 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001437 wdev = netdev->ieee80211_ptr;
1438 else
1439 wdev = NULL;
1440
1441 /*
1442 * end workaround code, by now the rdev is available
1443 * and locked, and wdev may or may not be NULL.
1444 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001445
1446 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001447 result = cfg80211_dev_rename(
1448 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001449
1450 mutex_unlock(&cfg80211_mutex);
1451
1452 if (result)
1453 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001454
Jouni Malinen31888482008-10-30 16:59:24 +02001455 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1456 struct ieee80211_txq_params txq_params;
1457 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1458
1459 if (!rdev->ops->set_txq_params) {
1460 result = -EOPNOTSUPP;
1461 goto bad_res;
1462 }
1463
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001464 if (!netdev) {
1465 result = -EINVAL;
1466 goto bad_res;
1467 }
1468
Johannes Berg133a3ff2011-11-03 14:50:13 +01001469 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1470 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1471 result = -EINVAL;
1472 goto bad_res;
1473 }
1474
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001475 if (!netif_running(netdev)) {
1476 result = -ENETDOWN;
1477 goto bad_res;
1478 }
1479
Jouni Malinen31888482008-10-30 16:59:24 +02001480 nla_for_each_nested(nl_txq_params,
1481 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1482 rem_txq_params) {
1483 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1484 nla_data(nl_txq_params),
1485 nla_len(nl_txq_params),
1486 txq_params_policy);
1487 result = parse_txq_params(tb, &txq_params);
1488 if (result)
1489 goto bad_res;
1490
1491 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001492 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001493 &txq_params);
1494 if (result)
1495 goto bad_res;
1496 }
1497 }
1498
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001499 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001500 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001501 if (result)
1502 goto bad_res;
1503 }
1504
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001505 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1506 enum nl80211_tx_power_setting type;
1507 int idx, mbm = 0;
1508
1509 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001510 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001511 goto bad_res;
1512 }
1513
1514 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1515 type = nla_get_u32(info->attrs[idx]);
1516
1517 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1518 (type != NL80211_TX_POWER_AUTOMATIC)) {
1519 result = -EINVAL;
1520 goto bad_res;
1521 }
1522
1523 if (type != NL80211_TX_POWER_AUTOMATIC) {
1524 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1525 mbm = nla_get_u32(info->attrs[idx]);
1526 }
1527
1528 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1529 if (result)
1530 goto bad_res;
1531 }
1532
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001533 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1534 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1535 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001536 if ((!rdev->wiphy.available_antennas_tx &&
1537 !rdev->wiphy.available_antennas_rx) ||
1538 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001539 result = -EOPNOTSUPP;
1540 goto bad_res;
1541 }
1542
1543 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1544 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1545
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001546 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001547 * available antenna masks, except for the "all" mask */
1548 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1549 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001550 result = -EINVAL;
1551 goto bad_res;
1552 }
1553
Bruno Randolf7f531e02010-12-16 11:30:22 +09001554 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1555 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001556
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001557 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1558 if (result)
1559 goto bad_res;
1560 }
1561
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001562 changed = 0;
1563
1564 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1565 retry_short = nla_get_u8(
1566 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1567 if (retry_short == 0) {
1568 result = -EINVAL;
1569 goto bad_res;
1570 }
1571 changed |= WIPHY_PARAM_RETRY_SHORT;
1572 }
1573
1574 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1575 retry_long = nla_get_u8(
1576 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1577 if (retry_long == 0) {
1578 result = -EINVAL;
1579 goto bad_res;
1580 }
1581 changed |= WIPHY_PARAM_RETRY_LONG;
1582 }
1583
1584 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1585 frag_threshold = nla_get_u32(
1586 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1587 if (frag_threshold < 256) {
1588 result = -EINVAL;
1589 goto bad_res;
1590 }
1591 if (frag_threshold != (u32) -1) {
1592 /*
1593 * Fragments (apart from the last one) are required to
1594 * have even length. Make the fragmentation code
1595 * simpler by stripping LSB should someone try to use
1596 * odd threshold value.
1597 */
1598 frag_threshold &= ~0x1;
1599 }
1600 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1601 }
1602
1603 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1604 rts_threshold = nla_get_u32(
1605 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1606 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1607 }
1608
Lukáš Turek81077e82009-12-21 22:50:47 +01001609 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1610 coverage_class = nla_get_u8(
1611 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1612 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1613 }
1614
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001615 if (changed) {
1616 u8 old_retry_short, old_retry_long;
1617 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001618 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001619
1620 if (!rdev->ops->set_wiphy_params) {
1621 result = -EOPNOTSUPP;
1622 goto bad_res;
1623 }
1624
1625 old_retry_short = rdev->wiphy.retry_short;
1626 old_retry_long = rdev->wiphy.retry_long;
1627 old_frag_threshold = rdev->wiphy.frag_threshold;
1628 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001629 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001630
1631 if (changed & WIPHY_PARAM_RETRY_SHORT)
1632 rdev->wiphy.retry_short = retry_short;
1633 if (changed & WIPHY_PARAM_RETRY_LONG)
1634 rdev->wiphy.retry_long = retry_long;
1635 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1636 rdev->wiphy.frag_threshold = frag_threshold;
1637 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1638 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001639 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1640 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001641
1642 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1643 if (result) {
1644 rdev->wiphy.retry_short = old_retry_short;
1645 rdev->wiphy.retry_long = old_retry_long;
1646 rdev->wiphy.frag_threshold = old_frag_threshold;
1647 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001648 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001649 }
1650 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001651
Johannes Berg306d6112008-12-08 12:39:04 +01001652 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001653 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001654 if (netdev)
1655 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001656 return result;
1657}
1658
1659
1660static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001661 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001662 struct net_device *dev)
1663{
1664 void *hdr;
1665
1666 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1667 if (!hdr)
1668 return -1;
1669
David S. Miller9360ffd2012-03-29 04:41:26 -04001670 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1671 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1672 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1673 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1674 dev->ieee80211_ptr->iftype) ||
1675 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1676 rdev->devlist_generation ^
1677 (cfg80211_rdev_list_generation << 2)))
1678 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001679
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001680 if (rdev->ops->get_channel) {
1681 struct ieee80211_channel *chan;
1682 enum nl80211_channel_type channel_type;
1683
1684 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
John W. Linville59ef43e2012-04-18 14:17:13 -04001685 if (chan &&
1686 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1687 chan->center_freq) ||
1688 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1689 channel_type)))
1690 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001691 }
1692
Johannes Berg55682962007-09-20 13:09:35 -04001693 return genlmsg_end(msg, hdr);
1694
1695 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001696 genlmsg_cancel(msg, hdr);
1697 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001698}
1699
1700static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1701{
1702 int wp_idx = 0;
1703 int if_idx = 0;
1704 int wp_start = cb->args[0];
1705 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001706 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001707 struct wireless_dev *wdev;
1708
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001709 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001710 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1711 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001712 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001713 if (wp_idx < wp_start) {
1714 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001715 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001716 }
Johannes Berg55682962007-09-20 13:09:35 -04001717 if_idx = 0;
1718
Johannes Bergf5ea9122009-08-07 16:17:38 +02001719 mutex_lock(&rdev->devlist_mtx);
1720 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001721 if (if_idx < if_start) {
1722 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001723 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001724 }
Johannes Berg55682962007-09-20 13:09:35 -04001725 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1726 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001727 rdev, wdev->netdev) < 0) {
1728 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001729 goto out;
1730 }
1731 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001732 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001733 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001734
1735 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001736 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001737 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001738 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001739
1740 cb->args[0] = wp_idx;
1741 cb->args[1] = if_idx;
1742
1743 return skb->len;
1744}
1745
1746static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1747{
1748 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001749 struct cfg80211_registered_device *dev = info->user_ptr[0];
1750 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001751
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001753 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001754 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001755
Johannes Bergd7264052009-04-19 16:23:20 +02001756 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001757 dev, netdev) < 0) {
1758 nlmsg_free(msg);
1759 return -ENOBUFS;
1760 }
Johannes Berg55682962007-09-20 13:09:35 -04001761
Johannes Berg134e6372009-07-10 09:51:34 +00001762 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001763}
1764
Michael Wu66f7ac52008-01-31 19:48:22 +01001765static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1766 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1767 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1768 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1769 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1770 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1771};
1772
1773static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1774{
1775 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1776 int flag;
1777
1778 *mntrflags = 0;
1779
1780 if (!nla)
1781 return -EINVAL;
1782
1783 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1784 nla, mntr_flags_policy))
1785 return -EINVAL;
1786
1787 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1788 if (flags[flag])
1789 *mntrflags |= (1<<flag);
1790
1791 return 0;
1792}
1793
Johannes Berg9bc383d2009-11-19 11:55:19 +01001794static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001795 struct net_device *netdev, u8 use_4addr,
1796 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001797{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001798 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001799 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001800 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001801 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001802 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001803
1804 switch (iftype) {
1805 case NL80211_IFTYPE_AP_VLAN:
1806 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1807 return 0;
1808 break;
1809 case NL80211_IFTYPE_STATION:
1810 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1811 return 0;
1812 break;
1813 default:
1814 break;
1815 }
1816
1817 return -EOPNOTSUPP;
1818}
1819
Johannes Berg55682962007-09-20 13:09:35 -04001820static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1821{
Johannes Berg4c476992010-10-04 21:36:35 +02001822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001823 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001824 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001825 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001826 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001827 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001828 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001829
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001830 memset(&params, 0, sizeof(params));
1831
Johannes Berg04a773a2009-04-19 21:24:32 +02001832 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001833
Johannes Berg723b0382008-09-16 20:22:09 +02001834 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001835 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001836 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001837 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001838 if (ntype > NL80211_IFTYPE_MAX)
1839 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001840 }
1841
Johannes Berg92ffe052008-09-16 20:39:36 +02001842 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001843 struct wireless_dev *wdev = dev->ieee80211_ptr;
1844
Johannes Berg4c476992010-10-04 21:36:35 +02001845 if (ntype != NL80211_IFTYPE_MESH_POINT)
1846 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001847 if (netif_running(dev))
1848 return -EBUSY;
1849
1850 wdev_lock(wdev);
1851 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1852 IEEE80211_MAX_MESH_ID_LEN);
1853 wdev->mesh_id_up_len =
1854 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1855 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1856 wdev->mesh_id_up_len);
1857 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001858 }
1859
Felix Fietkau8b787642009-11-10 18:53:10 +01001860 if (info->attrs[NL80211_ATTR_4ADDR]) {
1861 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1862 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001863 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001864 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001865 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001866 } else {
1867 params.use_4addr = -1;
1868 }
1869
Johannes Berg92ffe052008-09-16 20:39:36 +02001870 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001871 if (ntype != NL80211_IFTYPE_MONITOR)
1872 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001873 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1874 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001875 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001876 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001877
1878 flags = &_flags;
1879 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001880 }
Johannes Berg3b858752009-03-12 09:55:09 +01001881
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001882 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001883 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001884 else
1885 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001886
Johannes Berg9bc383d2009-11-19 11:55:19 +01001887 if (!err && params.use_4addr != -1)
1888 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1889
Johannes Berg55682962007-09-20 13:09:35 -04001890 return err;
1891}
1892
1893static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1894{
Johannes Berg4c476992010-10-04 21:36:35 +02001895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001896 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001897 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001898 int err;
1899 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001900 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001901
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001902 memset(&params, 0, sizeof(params));
1903
Johannes Berg55682962007-09-20 13:09:35 -04001904 if (!info->attrs[NL80211_ATTR_IFNAME])
1905 return -EINVAL;
1906
1907 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1908 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1909 if (type > NL80211_IFTYPE_MAX)
1910 return -EINVAL;
1911 }
1912
Johannes Berg79c97e92009-07-07 03:56:12 +02001913 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001914 !(rdev->wiphy.interface_modes & (1 << type)))
1915 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001916
Johannes Berg9bc383d2009-11-19 11:55:19 +01001917 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001918 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001919 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001920 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001921 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001922 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001923
Michael Wu66f7ac52008-01-31 19:48:22 +01001924 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1925 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1926 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001927 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001928 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001929 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001930 if (IS_ERR(dev))
1931 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001932
Johannes Berg29cbe682010-12-03 09:20:44 +01001933 if (type == NL80211_IFTYPE_MESH_POINT &&
1934 info->attrs[NL80211_ATTR_MESH_ID]) {
1935 struct wireless_dev *wdev = dev->ieee80211_ptr;
1936
1937 wdev_lock(wdev);
1938 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1939 IEEE80211_MAX_MESH_ID_LEN);
1940 wdev->mesh_id_up_len =
1941 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1942 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1943 wdev->mesh_id_up_len);
1944 wdev_unlock(wdev);
1945 }
1946
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001947 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001948}
1949
1950static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1951{
Johannes Berg4c476992010-10-04 21:36:35 +02001952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1953 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001954
Johannes Berg4c476992010-10-04 21:36:35 +02001955 if (!rdev->ops->del_virtual_intf)
1956 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001957
Johannes Berg4c476992010-10-04 21:36:35 +02001958 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001959}
1960
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001961static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1962{
1963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1964 struct net_device *dev = info->user_ptr[1];
1965 u16 noack_map;
1966
1967 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1968 return -EINVAL;
1969
1970 if (!rdev->ops->set_noack_map)
1971 return -EOPNOTSUPP;
1972
1973 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1974
1975 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1976}
1977
Johannes Berg41ade002007-12-19 02:03:29 +01001978struct get_key_cookie {
1979 struct sk_buff *msg;
1980 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001981 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001982};
1983
1984static void get_key_callback(void *c, struct key_params *params)
1985{
Johannes Bergb9454e82009-07-08 13:29:08 +02001986 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001987 struct get_key_cookie *cookie = c;
1988
David S. Miller9360ffd2012-03-29 04:41:26 -04001989 if ((params->key &&
1990 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
1991 params->key_len, params->key)) ||
1992 (params->seq &&
1993 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
1994 params->seq_len, params->seq)) ||
1995 (params->cipher &&
1996 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1997 params->cipher)))
1998 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01001999
Johannes Bergb9454e82009-07-08 13:29:08 +02002000 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2001 if (!key)
2002 goto nla_put_failure;
2003
David S. Miller9360ffd2012-03-29 04:41:26 -04002004 if ((params->key &&
2005 nla_put(cookie->msg, NL80211_KEY_DATA,
2006 params->key_len, params->key)) ||
2007 (params->seq &&
2008 nla_put(cookie->msg, NL80211_KEY_SEQ,
2009 params->seq_len, params->seq)) ||
2010 (params->cipher &&
2011 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2012 params->cipher)))
2013 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002014
David S. Miller9360ffd2012-03-29 04:41:26 -04002015 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2016 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002017
2018 nla_nest_end(cookie->msg, key);
2019
Johannes Berg41ade002007-12-19 02:03:29 +01002020 return;
2021 nla_put_failure:
2022 cookie->error = 1;
2023}
2024
2025static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2026{
Johannes Berg4c476992010-10-04 21:36:35 +02002027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002028 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002029 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002030 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002031 const u8 *mac_addr = NULL;
2032 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002033 struct get_key_cookie cookie = {
2034 .error = 0,
2035 };
2036 void *hdr;
2037 struct sk_buff *msg;
2038
2039 if (info->attrs[NL80211_ATTR_KEY_IDX])
2040 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2041
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002042 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002043 return -EINVAL;
2044
2045 if (info->attrs[NL80211_ATTR_MAC])
2046 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2047
Johannes Berge31b8212010-10-05 19:39:30 +02002048 pairwise = !!mac_addr;
2049 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2050 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2051 if (kt >= NUM_NL80211_KEYTYPES)
2052 return -EINVAL;
2053 if (kt != NL80211_KEYTYPE_GROUP &&
2054 kt != NL80211_KEYTYPE_PAIRWISE)
2055 return -EINVAL;
2056 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2057 }
2058
Johannes Berg4c476992010-10-04 21:36:35 +02002059 if (!rdev->ops->get_key)
2060 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002061
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002062 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002063 if (!msg)
2064 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002065
2066 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2067 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002068 if (IS_ERR(hdr))
2069 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002070
2071 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002072 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002073
David S. Miller9360ffd2012-03-29 04:41:26 -04002074 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2075 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2076 goto nla_put_failure;
2077 if (mac_addr &&
2078 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2079 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002080
Johannes Berge31b8212010-10-05 19:39:30 +02002081 if (pairwise && mac_addr &&
2082 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2083 return -ENOENT;
2084
2085 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2086 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002087
2088 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002089 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002090
2091 if (cookie.error)
2092 goto nla_put_failure;
2093
2094 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002095 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002096
2097 nla_put_failure:
2098 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002099 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002100 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002101 return err;
2102}
2103
2104static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2105{
Johannes Berg4c476992010-10-04 21:36:35 +02002106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002107 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002108 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002109 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002110
Johannes Bergb9454e82009-07-08 13:29:08 +02002111 err = nl80211_parse_key(info, &key);
2112 if (err)
2113 return err;
2114
2115 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002116 return -EINVAL;
2117
Johannes Bergb9454e82009-07-08 13:29:08 +02002118 /* only support setting default key */
2119 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002120 return -EINVAL;
2121
Johannes Bergfffd0932009-07-08 14:22:54 +02002122 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002123
2124 if (key.def) {
2125 if (!rdev->ops->set_default_key) {
2126 err = -EOPNOTSUPP;
2127 goto out;
2128 }
2129
2130 err = nl80211_key_allowed(dev->ieee80211_ptr);
2131 if (err)
2132 goto out;
2133
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002134 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2135 key.def_uni, key.def_multi);
2136
2137 if (err)
2138 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002139
Johannes Berg3d23e342009-09-29 23:27:28 +02002140#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002141 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002142#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002143 } else {
2144 if (key.def_uni || !key.def_multi) {
2145 err = -EINVAL;
2146 goto out;
2147 }
2148
2149 if (!rdev->ops->set_default_mgmt_key) {
2150 err = -EOPNOTSUPP;
2151 goto out;
2152 }
2153
2154 err = nl80211_key_allowed(dev->ieee80211_ptr);
2155 if (err)
2156 goto out;
2157
2158 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2159 dev, key.idx);
2160 if (err)
2161 goto out;
2162
2163#ifdef CONFIG_CFG80211_WEXT
2164 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2165#endif
2166 }
2167
2168 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002169 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002170
Johannes Berg41ade002007-12-19 02:03:29 +01002171 return err;
2172}
2173
2174static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2175{
Johannes Berg4c476992010-10-04 21:36:35 +02002176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002177 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002178 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002179 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002180 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002181
Johannes Bergb9454e82009-07-08 13:29:08 +02002182 err = nl80211_parse_key(info, &key);
2183 if (err)
2184 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002185
Johannes Bergb9454e82009-07-08 13:29:08 +02002186 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002187 return -EINVAL;
2188
Johannes Berg41ade002007-12-19 02:03:29 +01002189 if (info->attrs[NL80211_ATTR_MAC])
2190 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2191
Johannes Berge31b8212010-10-05 19:39:30 +02002192 if (key.type == -1) {
2193 if (mac_addr)
2194 key.type = NL80211_KEYTYPE_PAIRWISE;
2195 else
2196 key.type = NL80211_KEYTYPE_GROUP;
2197 }
2198
2199 /* for now */
2200 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2201 key.type != NL80211_KEYTYPE_GROUP)
2202 return -EINVAL;
2203
Johannes Berg4c476992010-10-04 21:36:35 +02002204 if (!rdev->ops->add_key)
2205 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002206
Johannes Berge31b8212010-10-05 19:39:30 +02002207 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2208 key.type == NL80211_KEYTYPE_PAIRWISE,
2209 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002210 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002211
2212 wdev_lock(dev->ieee80211_ptr);
2213 err = nl80211_key_allowed(dev->ieee80211_ptr);
2214 if (!err)
2215 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002216 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002217 mac_addr, &key.p);
2218 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002219
Johannes Berg41ade002007-12-19 02:03:29 +01002220 return err;
2221}
2222
2223static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2224{
Johannes Berg4c476992010-10-04 21:36:35 +02002225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002226 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002227 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002228 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002229 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002230
Johannes Bergb9454e82009-07-08 13:29:08 +02002231 err = nl80211_parse_key(info, &key);
2232 if (err)
2233 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002234
2235 if (info->attrs[NL80211_ATTR_MAC])
2236 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2237
Johannes Berge31b8212010-10-05 19:39:30 +02002238 if (key.type == -1) {
2239 if (mac_addr)
2240 key.type = NL80211_KEYTYPE_PAIRWISE;
2241 else
2242 key.type = NL80211_KEYTYPE_GROUP;
2243 }
2244
2245 /* for now */
2246 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2247 key.type != NL80211_KEYTYPE_GROUP)
2248 return -EINVAL;
2249
Johannes Berg4c476992010-10-04 21:36:35 +02002250 if (!rdev->ops->del_key)
2251 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002252
Johannes Bergfffd0932009-07-08 14:22:54 +02002253 wdev_lock(dev->ieee80211_ptr);
2254 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002255
2256 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2257 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2258 err = -ENOENT;
2259
Johannes Bergfffd0932009-07-08 14:22:54 +02002260 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002261 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2262 key.type == NL80211_KEYTYPE_PAIRWISE,
2263 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002264
Johannes Berg3d23e342009-09-29 23:27:28 +02002265#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002266 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002267 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002268 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002269 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002270 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2271 }
2272#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002273 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002274
Johannes Berg41ade002007-12-19 02:03:29 +01002275 return err;
2276}
2277
Johannes Berg88600202012-02-13 15:17:18 +01002278static int nl80211_parse_beacon(struct genl_info *info,
2279 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002280{
Johannes Berg88600202012-02-13 15:17:18 +01002281 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002282
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002283 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2284 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2285 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2286 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002287 return -EINVAL;
2288
Johannes Berg88600202012-02-13 15:17:18 +01002289 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002290
Johannes Berged1b6cc2007-12-19 02:03:32 +01002291 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002292 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2293 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2294 if (!bcn->head_len)
2295 return -EINVAL;
2296 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002297 }
2298
2299 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002300 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2301 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002302 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002303 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002304 }
2305
Johannes Berg4c476992010-10-04 21:36:35 +02002306 if (!haveinfo)
2307 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002308
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002309 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002310 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2311 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002312 }
2313
2314 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002315 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002316 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002317 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002318 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2319 }
2320
2321 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002322 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002323 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002324 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002325 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2326 }
2327
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002328 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002329 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002330 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002331 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002332 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2333 }
2334
Johannes Berg88600202012-02-13 15:17:18 +01002335 return 0;
2336}
2337
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002338static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2339 struct cfg80211_ap_settings *params)
2340{
2341 struct wireless_dev *wdev;
2342 bool ret = false;
2343
2344 mutex_lock(&rdev->devlist_mtx);
2345
2346 list_for_each_entry(wdev, &rdev->netdev_list, list) {
2347 if (wdev->iftype != NL80211_IFTYPE_AP &&
2348 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2349 continue;
2350
2351 if (!wdev->preset_chan)
2352 continue;
2353
2354 params->channel = wdev->preset_chan;
2355 params->channel_type = wdev->preset_chantype;
2356 ret = true;
2357 break;
2358 }
2359
2360 mutex_unlock(&rdev->devlist_mtx);
2361
2362 return ret;
2363}
2364
Johannes Berg88600202012-02-13 15:17:18 +01002365static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2366{
2367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2368 struct net_device *dev = info->user_ptr[1];
2369 struct wireless_dev *wdev = dev->ieee80211_ptr;
2370 struct cfg80211_ap_settings params;
2371 int err;
2372
2373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2374 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2375 return -EOPNOTSUPP;
2376
2377 if (!rdev->ops->start_ap)
2378 return -EOPNOTSUPP;
2379
2380 if (wdev->beacon_interval)
2381 return -EALREADY;
2382
2383 memset(&params, 0, sizeof(params));
2384
2385 /* these are required for START_AP */
2386 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2387 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2388 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2389 return -EINVAL;
2390
2391 err = nl80211_parse_beacon(info, &params.beacon);
2392 if (err)
2393 return err;
2394
2395 params.beacon_interval =
2396 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2397 params.dtim_period =
2398 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2399
2400 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2401 if (err)
2402 return err;
2403
2404 /*
2405 * In theory, some of these attributes should be required here
2406 * but since they were not used when the command was originally
2407 * added, keep them optional for old user space programs to let
2408 * them continue to work with drivers that do not need the
2409 * additional information -- drivers must check!
2410 */
2411 if (info->attrs[NL80211_ATTR_SSID]) {
2412 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2413 params.ssid_len =
2414 nla_len(info->attrs[NL80211_ATTR_SSID]);
2415 if (params.ssid_len == 0 ||
2416 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2417 return -EINVAL;
2418 }
2419
2420 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2421 params.hidden_ssid = nla_get_u32(
2422 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2423 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2424 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2425 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2426 return -EINVAL;
2427 }
2428
2429 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2430
2431 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2432 params.auth_type = nla_get_u32(
2433 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2434 if (!nl80211_valid_auth_type(params.auth_type))
2435 return -EINVAL;
2436 } else
2437 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2438
2439 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2440 NL80211_MAX_NR_CIPHER_SUITES);
2441 if (err)
2442 return err;
2443
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302444 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2445 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2446 return -EOPNOTSUPP;
2447 params.inactivity_timeout = nla_get_u16(
2448 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2449 }
2450
Johannes Bergaa430da2012-05-16 23:50:18 +02002451 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2452 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2453
2454 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2455 !nl80211_valid_channel_type(info, &channel_type))
2456 return -EINVAL;
2457
2458 params.channel = rdev_freq_to_chan(rdev,
2459 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2460 channel_type);
2461 if (!params.channel)
2462 return -EINVAL;
2463 params.channel_type = channel_type;
2464 } else if (wdev->preset_chan) {
2465 params.channel = wdev->preset_chan;
2466 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002467 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002468 return -EINVAL;
2469
2470 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2471 params.channel_type))
2472 return -EINVAL;
2473
Johannes Berg88600202012-02-13 15:17:18 +01002474 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002475 if (!err) {
2476 wdev->preset_chan = params.channel;
2477 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002478 wdev->beacon_interval = params.beacon_interval;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002479 }
Johannes Berg56d18932011-05-09 18:41:15 +02002480 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002481}
2482
Johannes Berg88600202012-02-13 15:17:18 +01002483static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2484{
2485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2486 struct net_device *dev = info->user_ptr[1];
2487 struct wireless_dev *wdev = dev->ieee80211_ptr;
2488 struct cfg80211_beacon_data params;
2489 int err;
2490
2491 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2492 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2493 return -EOPNOTSUPP;
2494
2495 if (!rdev->ops->change_beacon)
2496 return -EOPNOTSUPP;
2497
2498 if (!wdev->beacon_interval)
2499 return -EINVAL;
2500
2501 err = nl80211_parse_beacon(info, &params);
2502 if (err)
2503 return err;
2504
2505 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2506}
2507
2508static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002509{
Johannes Berg4c476992010-10-04 21:36:35 +02002510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2511 struct net_device *dev = info->user_ptr[1];
Johannes Berg56d18932011-05-09 18:41:15 +02002512 struct wireless_dev *wdev = dev->ieee80211_ptr;
2513 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002514
Johannes Berg88600202012-02-13 15:17:18 +01002515 if (!rdev->ops->stop_ap)
Johannes Berg4c476992010-10-04 21:36:35 +02002516 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002517
Johannes Berg074ac8d2010-09-16 14:58:22 +02002518 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02002519 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2520 return -EOPNOTSUPP;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002521
Johannes Berg88600202012-02-13 15:17:18 +01002522 if (!wdev->beacon_interval)
2523 return -ENOENT;
2524
2525 err = rdev->ops->stop_ap(&rdev->wiphy, dev);
Johannes Berg56d18932011-05-09 18:41:15 +02002526 if (!err)
2527 wdev->beacon_interval = 0;
2528 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002529}
2530
Johannes Berg5727ef12007-12-19 02:03:34 +01002531static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2532 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2533 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2534 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002535 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002536 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002537 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002538};
2539
Johannes Bergeccb8e82009-05-11 21:57:56 +03002540static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002541 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002542 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002543{
2544 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002545 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002546 int flag;
2547
Johannes Bergeccb8e82009-05-11 21:57:56 +03002548 /*
2549 * Try parsing the new attribute first so userspace
2550 * can specify both for older kernels.
2551 */
2552 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2553 if (nla) {
2554 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002555
Johannes Bergeccb8e82009-05-11 21:57:56 +03002556 sta_flags = nla_data(nla);
2557 params->sta_flags_mask = sta_flags->mask;
2558 params->sta_flags_set = sta_flags->set;
2559 if ((params->sta_flags_mask |
2560 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2561 return -EINVAL;
2562 return 0;
2563 }
2564
2565 /* if present, parse the old attribute */
2566
2567 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002568 if (!nla)
2569 return 0;
2570
2571 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2572 nla, sta_flags_policy))
2573 return -EINVAL;
2574
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002575 /*
2576 * Only allow certain flags for interface types so that
2577 * other attributes are silently ignored. Remember that
2578 * this is backward compatibility code with old userspace
2579 * and shouldn't be hit in other cases anyway.
2580 */
2581 switch (iftype) {
2582 case NL80211_IFTYPE_AP:
2583 case NL80211_IFTYPE_AP_VLAN:
2584 case NL80211_IFTYPE_P2P_GO:
2585 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2586 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2587 BIT(NL80211_STA_FLAG_WME) |
2588 BIT(NL80211_STA_FLAG_MFP);
2589 break;
2590 case NL80211_IFTYPE_P2P_CLIENT:
2591 case NL80211_IFTYPE_STATION:
2592 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2593 BIT(NL80211_STA_FLAG_TDLS_PEER);
2594 break;
2595 case NL80211_IFTYPE_MESH_POINT:
2596 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2597 BIT(NL80211_STA_FLAG_MFP) |
2598 BIT(NL80211_STA_FLAG_AUTHORIZED);
2599 default:
2600 return -EINVAL;
2601 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002602
Johannes Berg3383b5a2012-05-10 20:14:43 +02002603 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2604 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002605 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002606
Johannes Berg3383b5a2012-05-10 20:14:43 +02002607 /* no longer support new API additions in old API */
2608 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2609 return -EINVAL;
2610 }
2611 }
2612
Johannes Berg5727ef12007-12-19 02:03:34 +01002613 return 0;
2614}
2615
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002616static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2617 int attr)
2618{
2619 struct nlattr *rate;
2620 u16 bitrate;
2621
2622 rate = nla_nest_start(msg, attr);
2623 if (!rate)
2624 goto nla_put_failure;
2625
2626 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2627 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002628 if ((bitrate > 0 &&
2629 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2630 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2631 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2632 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2633 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2634 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2635 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2636 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002637
2638 nla_nest_end(msg, rate);
2639 return true;
2640
2641nla_put_failure:
2642 return false;
2643}
2644
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002645static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002646 int flags,
2647 struct cfg80211_registered_device *rdev,
2648 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002649 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002650{
2651 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002652 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002653
2654 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2655 if (!hdr)
2656 return -1;
2657
David S. Miller9360ffd2012-03-29 04:41:26 -04002658 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2659 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2660 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2661 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002662
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002663 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2664 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002665 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002666 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2667 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2668 sinfo->connected_time))
2669 goto nla_put_failure;
2670 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2671 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2672 sinfo->inactive_time))
2673 goto nla_put_failure;
2674 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2675 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2676 sinfo->rx_bytes))
2677 goto nla_put_failure;
2678 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2679 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2680 sinfo->tx_bytes))
2681 goto nla_put_failure;
2682 if ((sinfo->filled & STATION_INFO_LLID) &&
2683 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2684 goto nla_put_failure;
2685 if ((sinfo->filled & STATION_INFO_PLID) &&
2686 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2687 goto nla_put_failure;
2688 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2689 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2690 sinfo->plink_state))
2691 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002692 switch (rdev->wiphy.signal_type) {
2693 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002694 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2695 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2696 sinfo->signal))
2697 goto nla_put_failure;
2698 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2699 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2700 sinfo->signal_avg))
2701 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002702 break;
2703 default:
2704 break;
2705 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002706 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002707 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2708 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002709 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002710 }
2711 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2712 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2713 NL80211_STA_INFO_RX_BITRATE))
2714 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002715 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002716 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2717 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2718 sinfo->rx_packets))
2719 goto nla_put_failure;
2720 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2721 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2722 sinfo->tx_packets))
2723 goto nla_put_failure;
2724 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2725 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2726 sinfo->tx_retries))
2727 goto nla_put_failure;
2728 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2729 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2730 sinfo->tx_failed))
2731 goto nla_put_failure;
2732 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2733 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2734 sinfo->beacon_loss_count))
2735 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002736 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2737 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2738 if (!bss_param)
2739 goto nla_put_failure;
2740
David S. Miller9360ffd2012-03-29 04:41:26 -04002741 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2742 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2743 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2744 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2745 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2746 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2747 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2748 sinfo->bss_param.dtim_period) ||
2749 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2750 sinfo->bss_param.beacon_interval))
2751 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002752
2753 nla_nest_end(msg, bss_param);
2754 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002755 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2756 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2757 sizeof(struct nl80211_sta_flag_update),
2758 &sinfo->sta_flags))
2759 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002760 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2761 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2762 sinfo->t_offset))
2763 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002764 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002765
David S. Miller9360ffd2012-03-29 04:41:26 -04002766 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2767 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2768 sinfo->assoc_req_ies))
2769 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002770
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002771 return genlmsg_end(msg, hdr);
2772
2773 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002774 genlmsg_cancel(msg, hdr);
2775 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002776}
2777
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002778static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002779 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002780{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002781 struct station_info sinfo;
2782 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002783 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002784 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002785 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002786 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002787
Johannes Berg67748892010-10-04 21:14:06 +02002788 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2789 if (err)
2790 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002791
2792 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002793 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002794 goto out_err;
2795 }
2796
Johannes Bergbba95fe2008-07-29 13:22:51 +02002797 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002798 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002799 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2800 mac_addr, &sinfo);
2801 if (err == -ENOENT)
2802 break;
2803 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002804 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002805
2806 if (nl80211_send_station(skb,
2807 NETLINK_CB(cb->skb).pid,
2808 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002809 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002810 &sinfo) < 0)
2811 goto out;
2812
2813 sta_idx++;
2814 }
2815
2816
2817 out:
2818 cb->args[1] = sta_idx;
2819 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002820 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002821 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002822
2823 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002824}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002825
Johannes Berg5727ef12007-12-19 02:03:34 +01002826static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2827{
Johannes Berg4c476992010-10-04 21:36:35 +02002828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2829 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002830 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002831 struct sk_buff *msg;
2832 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002833 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002834
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002835 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002836
2837 if (!info->attrs[NL80211_ATTR_MAC])
2838 return -EINVAL;
2839
2840 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2841
Johannes Berg4c476992010-10-04 21:36:35 +02002842 if (!rdev->ops->get_station)
2843 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002844
Johannes Berg79c97e92009-07-07 03:56:12 +02002845 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002846 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002847 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002848
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002849 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002850 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002851 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002852
2853 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002854 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002855 nlmsg_free(msg);
2856 return -ENOBUFS;
2857 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002858
Johannes Berg4c476992010-10-04 21:36:35 +02002859 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002860}
2861
2862/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002863 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002864 */
Johannes Berg80b99892011-11-18 16:23:01 +01002865static struct net_device *get_vlan(struct genl_info *info,
2866 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002867{
Johannes Berg463d0182009-07-14 00:33:35 +02002868 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002869 struct net_device *v;
2870 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002871
Johannes Berg80b99892011-11-18 16:23:01 +01002872 if (!vlanattr)
2873 return NULL;
2874
2875 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2876 if (!v)
2877 return ERR_PTR(-ENODEV);
2878
2879 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2880 ret = -EINVAL;
2881 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002882 }
Johannes Berg80b99892011-11-18 16:23:01 +01002883
2884 if (!netif_running(v)) {
2885 ret = -ENETDOWN;
2886 goto error;
2887 }
2888
2889 return v;
2890 error:
2891 dev_put(v);
2892 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002893}
2894
2895static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2896{
Johannes Berg4c476992010-10-04 21:36:35 +02002897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002898 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002899 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002900 struct station_parameters params;
2901 u8 *mac_addr = NULL;
2902
2903 memset(&params, 0, sizeof(params));
2904
2905 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002906 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002907
2908 if (info->attrs[NL80211_ATTR_STA_AID])
2909 return -EINVAL;
2910
2911 if (!info->attrs[NL80211_ATTR_MAC])
2912 return -EINVAL;
2913
2914 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2915
2916 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2917 params.supported_rates =
2918 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2919 params.supported_rates_len =
2920 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2921 }
2922
2923 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2924 params.listen_interval =
2925 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2926
Jouni Malinen36aedc92008-08-25 11:58:58 +03002927 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2928 params.ht_capa =
2929 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2930
Johannes Bergbdd90d52011-12-14 12:20:27 +01002931 if (!rdev->ops->change_station)
2932 return -EOPNOTSUPP;
2933
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002934 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002935 return -EINVAL;
2936
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002937 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2938 params.plink_action =
2939 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2940
Javier Cardona9c3990a2011-05-03 16:57:11 -07002941 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2942 params.plink_state =
2943 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2944
Johannes Berga97f4422009-06-18 17:23:43 +02002945 switch (dev->ieee80211_ptr->iftype) {
2946 case NL80211_IFTYPE_AP:
2947 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002948 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002949 /* disallow mesh-specific things */
2950 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002951 return -EINVAL;
2952
2953 /* TDLS can't be set, ... */
2954 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2955 return -EINVAL;
2956 /*
2957 * ... but don't bother the driver with it. This works around
2958 * a hostapd/wpa_supplicant issue -- it always includes the
2959 * TLDS_PEER flag in the mask even for AP mode.
2960 */
2961 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2962
2963 /* accept only the listed bits */
2964 if (params.sta_flags_mask &
2965 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2966 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2967 BIT(NL80211_STA_FLAG_WME) |
2968 BIT(NL80211_STA_FLAG_MFP)))
2969 return -EINVAL;
2970
2971 /* must be last in here for error handling */
2972 params.vlan = get_vlan(info, rdev);
2973 if (IS_ERR(params.vlan))
2974 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002975 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002976 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002977 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002978 /*
2979 * Don't allow userspace to change the TDLS_PEER flag,
2980 * but silently ignore attempts to change it since we
2981 * don't have state here to verify that it doesn't try
2982 * to change the flag.
2983 */
2984 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002985 /* fall through */
2986 case NL80211_IFTYPE_ADHOC:
2987 /* disallow things sta doesn't support */
2988 if (params.plink_action)
2989 return -EINVAL;
2990 if (params.ht_capa)
2991 return -EINVAL;
2992 if (params.listen_interval >= 0)
2993 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002994 /* reject any changes other than AUTHORIZED */
2995 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2996 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002997 break;
2998 case NL80211_IFTYPE_MESH_POINT:
2999 /* disallow things mesh doesn't support */
3000 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003001 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003002 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003003 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003004 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003005 return -EINVAL;
3006 /*
3007 * No special handling for TDLS here -- the userspace
3008 * mesh code doesn't have this bug.
3009 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003010 if (params.sta_flags_mask &
3011 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003012 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003013 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003014 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003015 break;
3016 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003017 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003018 }
3019
Johannes Bergbdd90d52011-12-14 12:20:27 +01003020 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003021
Johannes Berg79c97e92009-07-07 03:56:12 +02003022 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003023
Johannes Berg5727ef12007-12-19 02:03:34 +01003024 if (params.vlan)
3025 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003026
Johannes Berg5727ef12007-12-19 02:03:34 +01003027 return err;
3028}
3029
Eliad Pellerc75786c2011-08-23 14:37:46 +03003030static struct nla_policy
3031nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3032 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3033 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3034};
3035
Johannes Berg5727ef12007-12-19 02:03:34 +01003036static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3037{
Johannes Berg4c476992010-10-04 21:36:35 +02003038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003039 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003040 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003041 struct station_parameters params;
3042 u8 *mac_addr = NULL;
3043
3044 memset(&params, 0, sizeof(params));
3045
3046 if (!info->attrs[NL80211_ATTR_MAC])
3047 return -EINVAL;
3048
Johannes Berg5727ef12007-12-19 02:03:34 +01003049 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3050 return -EINVAL;
3051
3052 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3053 return -EINVAL;
3054
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003055 if (!info->attrs[NL80211_ATTR_STA_AID])
3056 return -EINVAL;
3057
Johannes Berg5727ef12007-12-19 02:03:34 +01003058 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3059 params.supported_rates =
3060 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3061 params.supported_rates_len =
3062 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3063 params.listen_interval =
3064 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003065
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003066 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3067 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3068 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003069
Jouni Malinen36aedc92008-08-25 11:58:58 +03003070 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3071 params.ht_capa =
3072 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003073
Javier Cardona96b78df2011-04-07 15:08:33 -07003074 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3075 params.plink_action =
3076 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3077
Johannes Bergbdd90d52011-12-14 12:20:27 +01003078 if (!rdev->ops->add_station)
3079 return -EOPNOTSUPP;
3080
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003081 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003082 return -EINVAL;
3083
Johannes Bergbdd90d52011-12-14 12:20:27 +01003084 switch (dev->ieee80211_ptr->iftype) {
3085 case NL80211_IFTYPE_AP:
3086 case NL80211_IFTYPE_AP_VLAN:
3087 case NL80211_IFTYPE_P2P_GO:
3088 /* parse WME attributes if sta is WME capable */
3089 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3090 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3091 info->attrs[NL80211_ATTR_STA_WME]) {
3092 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3093 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003094
Johannes Bergbdd90d52011-12-14 12:20:27 +01003095 nla = info->attrs[NL80211_ATTR_STA_WME];
3096 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3097 nl80211_sta_wme_policy);
3098 if (err)
3099 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003100
Johannes Bergbdd90d52011-12-14 12:20:27 +01003101 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3102 params.uapsd_queues =
3103 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3104 if (params.uapsd_queues &
3105 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3106 return -EINVAL;
3107
3108 if (tb[NL80211_STA_WME_MAX_SP])
3109 params.max_sp =
3110 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3111
3112 if (params.max_sp &
3113 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3114 return -EINVAL;
3115
3116 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3117 }
3118 /* TDLS peers cannot be added */
3119 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003120 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003121 /* but don't bother the driver with it */
3122 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003123
Johannes Bergbdd90d52011-12-14 12:20:27 +01003124 /* must be last in here for error handling */
3125 params.vlan = get_vlan(info, rdev);
3126 if (IS_ERR(params.vlan))
3127 return PTR_ERR(params.vlan);
3128 break;
3129 case NL80211_IFTYPE_MESH_POINT:
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 break;
3134 case NL80211_IFTYPE_STATION:
3135 /* Only TDLS peers can be added */
3136 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3137 return -EINVAL;
3138 /* Can only add if TDLS ... */
3139 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3140 return -EOPNOTSUPP;
3141 /* ... with external setup is supported */
3142 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3143 return -EOPNOTSUPP;
3144 break;
3145 default:
3146 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003147 }
3148
Johannes Bergbdd90d52011-12-14 12:20:27 +01003149 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003150
Johannes Berg79c97e92009-07-07 03:56:12 +02003151 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003152
Johannes Berg5727ef12007-12-19 02:03:34 +01003153 if (params.vlan)
3154 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003155 return err;
3156}
3157
3158static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3159{
Johannes Berg4c476992010-10-04 21:36:35 +02003160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3161 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003162 u8 *mac_addr = NULL;
3163
3164 if (info->attrs[NL80211_ATTR_MAC])
3165 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3166
Johannes Berge80cf852009-05-11 14:43:13 +02003167 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003168 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003169 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003170 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3171 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003172
Johannes Berg4c476992010-10-04 21:36:35 +02003173 if (!rdev->ops->del_station)
3174 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003175
Johannes Berg4c476992010-10-04 21:36:35 +02003176 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003177}
3178
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003179static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3180 int flags, struct net_device *dev,
3181 u8 *dst, u8 *next_hop,
3182 struct mpath_info *pinfo)
3183{
3184 void *hdr;
3185 struct nlattr *pinfoattr;
3186
3187 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3188 if (!hdr)
3189 return -1;
3190
David S. Miller9360ffd2012-03-29 04:41:26 -04003191 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3192 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3193 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3194 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3195 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003196
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003197 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3198 if (!pinfoattr)
3199 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003200 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3201 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3202 pinfo->frame_qlen))
3203 goto nla_put_failure;
3204 if (((pinfo->filled & MPATH_INFO_SN) &&
3205 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3206 ((pinfo->filled & MPATH_INFO_METRIC) &&
3207 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3208 pinfo->metric)) ||
3209 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3210 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3211 pinfo->exptime)) ||
3212 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3213 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3214 pinfo->flags)) ||
3215 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3216 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3217 pinfo->discovery_timeout)) ||
3218 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3219 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3220 pinfo->discovery_retries)))
3221 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003222
3223 nla_nest_end(msg, pinfoattr);
3224
3225 return genlmsg_end(msg, hdr);
3226
3227 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003228 genlmsg_cancel(msg, hdr);
3229 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003230}
3231
3232static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003233 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003234{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003235 struct mpath_info pinfo;
3236 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003237 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003238 u8 dst[ETH_ALEN];
3239 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003240 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003241 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003242
Johannes Berg67748892010-10-04 21:14:06 +02003243 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3244 if (err)
3245 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003246
3247 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003248 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003249 goto out_err;
3250 }
3251
Jouni Malineneec60b02009-03-20 21:21:19 +02003252 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3253 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003254 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003255 }
3256
Johannes Bergbba95fe2008-07-29 13:22:51 +02003257 while (1) {
3258 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3259 dst, next_hop, &pinfo);
3260 if (err == -ENOENT)
3261 break;
3262 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003263 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003264
3265 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3266 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3267 netdev, dst, next_hop,
3268 &pinfo) < 0)
3269 goto out;
3270
3271 path_idx++;
3272 }
3273
3274
3275 out:
3276 cb->args[1] = path_idx;
3277 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003278 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003279 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003280 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003281}
3282
3283static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3284{
Johannes Berg4c476992010-10-04 21:36:35 +02003285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003286 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003287 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003288 struct mpath_info pinfo;
3289 struct sk_buff *msg;
3290 u8 *dst = NULL;
3291 u8 next_hop[ETH_ALEN];
3292
3293 memset(&pinfo, 0, sizeof(pinfo));
3294
3295 if (!info->attrs[NL80211_ATTR_MAC])
3296 return -EINVAL;
3297
3298 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3299
Johannes Berg4c476992010-10-04 21:36:35 +02003300 if (!rdev->ops->get_mpath)
3301 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003302
Johannes Berg4c476992010-10-04 21:36:35 +02003303 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3304 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003305
Johannes Berg79c97e92009-07-07 03:56:12 +02003306 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003307 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003308 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003309
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003310 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003311 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003312 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003313
3314 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003315 dev, dst, next_hop, &pinfo) < 0) {
3316 nlmsg_free(msg);
3317 return -ENOBUFS;
3318 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003319
Johannes Berg4c476992010-10-04 21:36:35 +02003320 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003321}
3322
3323static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3324{
Johannes Berg4c476992010-10-04 21:36:35 +02003325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3326 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003327 u8 *dst = NULL;
3328 u8 *next_hop = NULL;
3329
3330 if (!info->attrs[NL80211_ATTR_MAC])
3331 return -EINVAL;
3332
3333 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3334 return -EINVAL;
3335
3336 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3337 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3338
Johannes Berg4c476992010-10-04 21:36:35 +02003339 if (!rdev->ops->change_mpath)
3340 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003341
Johannes Berg4c476992010-10-04 21:36:35 +02003342 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3343 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003344
Johannes Berg4c476992010-10-04 21:36:35 +02003345 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003346}
Johannes Berg4c476992010-10-04 21:36:35 +02003347
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003348static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3349{
Johannes Berg4c476992010-10-04 21:36:35 +02003350 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3351 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003352 u8 *dst = NULL;
3353 u8 *next_hop = NULL;
3354
3355 if (!info->attrs[NL80211_ATTR_MAC])
3356 return -EINVAL;
3357
3358 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3359 return -EINVAL;
3360
3361 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3362 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3363
Johannes Berg4c476992010-10-04 21:36:35 +02003364 if (!rdev->ops->add_mpath)
3365 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003366
Johannes Berg4c476992010-10-04 21:36:35 +02003367 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3368 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003369
Johannes Berg4c476992010-10-04 21:36:35 +02003370 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003371}
3372
3373static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3374{
Johannes Berg4c476992010-10-04 21:36:35 +02003375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3376 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003377 u8 *dst = NULL;
3378
3379 if (info->attrs[NL80211_ATTR_MAC])
3380 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3381
Johannes Berg4c476992010-10-04 21:36:35 +02003382 if (!rdev->ops->del_mpath)
3383 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003384
Johannes Berg4c476992010-10-04 21:36:35 +02003385 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003386}
3387
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003388static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3389{
Johannes Berg4c476992010-10-04 21:36:35 +02003390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3391 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003392 struct bss_parameters params;
3393
3394 memset(&params, 0, sizeof(params));
3395 /* default to not changing parameters */
3396 params.use_cts_prot = -1;
3397 params.use_short_preamble = -1;
3398 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003399 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003400 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003401
3402 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3403 params.use_cts_prot =
3404 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3405 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3406 params.use_short_preamble =
3407 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3408 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3409 params.use_short_slot_time =
3410 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003411 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3412 params.basic_rates =
3413 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3414 params.basic_rates_len =
3415 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3416 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003417 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3418 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003419 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3420 params.ht_opmode =
3421 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003422
Johannes Berg4c476992010-10-04 21:36:35 +02003423 if (!rdev->ops->change_bss)
3424 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003425
Johannes Berg074ac8d2010-09-16 14:58:22 +02003426 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003427 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3428 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003429
Johannes Berg4c476992010-10-04 21:36:35 +02003430 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003431}
3432
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003433static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003434 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3435 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3436 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3437 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3438 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3439 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3440};
3441
3442static int parse_reg_rule(struct nlattr *tb[],
3443 struct ieee80211_reg_rule *reg_rule)
3444{
3445 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3446 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3447
3448 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3449 return -EINVAL;
3450 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3451 return -EINVAL;
3452 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3453 return -EINVAL;
3454 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3455 return -EINVAL;
3456 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3457 return -EINVAL;
3458
3459 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3460
3461 freq_range->start_freq_khz =
3462 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3463 freq_range->end_freq_khz =
3464 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3465 freq_range->max_bandwidth_khz =
3466 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3467
3468 power_rule->max_eirp =
3469 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3470
3471 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3472 power_rule->max_antenna_gain =
3473 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3474
3475 return 0;
3476}
3477
3478static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3479{
3480 int r;
3481 char *data = NULL;
3482
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003483 /*
3484 * You should only get this when cfg80211 hasn't yet initialized
3485 * completely when built-in to the kernel right between the time
3486 * window between nl80211_init() and regulatory_init(), if that is
3487 * even possible.
3488 */
3489 mutex_lock(&cfg80211_mutex);
3490 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003491 mutex_unlock(&cfg80211_mutex);
3492 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003493 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003494 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003495
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003496 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3497 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003498
3499 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3500
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003501 r = regulatory_hint_user(data);
3502
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003503 return r;
3504}
3505
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003506static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003507 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003508{
Johannes Berg4c476992010-10-04 21:36:35 +02003509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003510 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003511 struct wireless_dev *wdev = dev->ieee80211_ptr;
3512 struct mesh_config cur_params;
3513 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003514 void *hdr;
3515 struct nlattr *pinfoattr;
3516 struct sk_buff *msg;
3517
Johannes Berg29cbe682010-12-03 09:20:44 +01003518 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3519 return -EOPNOTSUPP;
3520
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003521 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003522 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003523
Johannes Berg29cbe682010-12-03 09:20:44 +01003524 wdev_lock(wdev);
3525 /* If not connected, get default parameters */
3526 if (!wdev->mesh_id_len)
3527 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3528 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003529 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003530 &cur_params);
3531 wdev_unlock(wdev);
3532
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003533 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003534 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003535
3536 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003537 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003538 if (!msg)
3539 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003540 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003541 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003542 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003543 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003544 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003545 if (!pinfoattr)
3546 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003547 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3548 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3549 cur_params.dot11MeshRetryTimeout) ||
3550 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3551 cur_params.dot11MeshConfirmTimeout) ||
3552 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3553 cur_params.dot11MeshHoldingTimeout) ||
3554 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3555 cur_params.dot11MeshMaxPeerLinks) ||
3556 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3557 cur_params.dot11MeshMaxRetries) ||
3558 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3559 cur_params.dot11MeshTTL) ||
3560 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3561 cur_params.element_ttl) ||
3562 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3563 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003564 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3565 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003566 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3567 cur_params.dot11MeshHWMPmaxPREQretries) ||
3568 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3569 cur_params.path_refresh_time) ||
3570 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3571 cur_params.min_discovery_timeout) ||
3572 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3573 cur_params.dot11MeshHWMPactivePathTimeout) ||
3574 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3575 cur_params.dot11MeshHWMPpreqMinInterval) ||
3576 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3577 cur_params.dot11MeshHWMPperrMinInterval) ||
3578 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3579 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3580 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3581 cur_params.dot11MeshHWMPRootMode) ||
3582 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3583 cur_params.dot11MeshHWMPRannInterval) ||
3584 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3585 cur_params.dot11MeshGateAnnouncementProtocol) ||
3586 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3587 cur_params.dot11MeshForwarding) ||
3588 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003589 cur_params.rssi_threshold) ||
3590 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003591 cur_params.ht_opmode) ||
3592 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3593 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3594 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003595 cur_params.dot11MeshHWMProotInterval) ||
3596 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3597 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003598 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003599 nla_nest_end(msg, pinfoattr);
3600 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003601 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003602
Johannes Berg3b858752009-03-12 09:55:09 +01003603 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003604 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003605 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003606 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003607 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003608}
3609
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003610static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003611 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3612 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3613 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3614 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3615 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3616 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003617 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003618 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003619 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003620 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3621 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3622 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3623 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3624 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003625 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003626 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003627 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003628 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003629 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003630 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003631 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3632 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003633 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3634 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003635 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003636};
3637
Javier Cardonac80d5452010-12-16 17:37:49 -08003638static const struct nla_policy
3639 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003640 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003641 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3642 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003643 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003644 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003645 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003646 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003647};
3648
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003649static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003650 struct mesh_config *cfg,
3651 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003652{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003653 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003654 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003655
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003656#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3657do {\
3658 if (table[attr_num]) {\
3659 cfg->param = nla_fn(table[attr_num]); \
3660 mask |= (1 << (attr_num - 1)); \
3661 } \
3662} while (0);\
3663
3664
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003665 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003666 return -EINVAL;
3667 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003668 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003669 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003670 return -EINVAL;
3671
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003672 /* This makes sure that there aren't more than 32 mesh config
3673 * parameters (otherwise our bitfield scheme would not work.) */
3674 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3675
3676 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003677 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003678 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3679 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003680 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003681 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3682 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003683 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003684 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3685 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003686 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003687 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3688 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003690 mask, NL80211_MESHCONF_MAX_RETRIES,
3691 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003693 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003694 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003695 mask, NL80211_MESHCONF_ELEMENT_TTL,
3696 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003698 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3699 nla_get_u8);
3700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3701 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3702 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003704 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3705 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003706 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003707 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3708 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003710 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3711 nla_get_u16);
3712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3713 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3714 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003715 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003716 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3717 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003719 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3720 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003722 dot11MeshHWMPnetDiameterTraversalTime, mask,
3723 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3724 nla_get_u16);
3725 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3726 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3728 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3729 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003731 dot11MeshGateAnnouncementProtocol, mask,
3732 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3733 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003734 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003735 mask, NL80211_MESHCONF_FORWARDING,
3736 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003737 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003738 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3739 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003741 mask, NL80211_MESHCONF_HT_OPMODE,
3742 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3744 mask,
3745 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3746 nla_get_u32);
3747 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3748 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3749 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003750 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3751 dot11MeshHWMPconfirmationInterval, mask,
3752 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3753 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003754 if (mask_out)
3755 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003756
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003757 return 0;
3758
3759#undef FILL_IN_MESH_PARAM_IF_SET
3760}
3761
Javier Cardonac80d5452010-12-16 17:37:49 -08003762static int nl80211_parse_mesh_setup(struct genl_info *info,
3763 struct mesh_setup *setup)
3764{
3765 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3766
3767 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3768 return -EINVAL;
3769 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3770 info->attrs[NL80211_ATTR_MESH_SETUP],
3771 nl80211_mesh_setup_params_policy))
3772 return -EINVAL;
3773
Javier Cardonad299a1f2012-03-31 11:31:33 -07003774 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3775 setup->sync_method =
3776 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3777 IEEE80211_SYNC_METHOD_VENDOR :
3778 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3779
Javier Cardonac80d5452010-12-16 17:37:49 -08003780 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3781 setup->path_sel_proto =
3782 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3783 IEEE80211_PATH_PROTOCOL_VENDOR :
3784 IEEE80211_PATH_PROTOCOL_HWMP;
3785
3786 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3787 setup->path_metric =
3788 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3789 IEEE80211_PATH_METRIC_VENDOR :
3790 IEEE80211_PATH_METRIC_AIRTIME;
3791
Javier Cardona581a8b02011-04-07 15:08:27 -07003792
3793 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003794 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003795 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003796 if (!is_valid_ie_attr(ieattr))
3797 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003798 setup->ie = nla_data(ieattr);
3799 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003800 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003801 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3802 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003803
3804 return 0;
3805}
3806
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003807static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003808 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003809{
3810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3811 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003812 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003813 struct mesh_config cfg;
3814 u32 mask;
3815 int err;
3816
Johannes Berg29cbe682010-12-03 09:20:44 +01003817 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3818 return -EOPNOTSUPP;
3819
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003820 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003821 return -EOPNOTSUPP;
3822
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003823 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003824 if (err)
3825 return err;
3826
Johannes Berg29cbe682010-12-03 09:20:44 +01003827 wdev_lock(wdev);
3828 if (!wdev->mesh_id_len)
3829 err = -ENOLINK;
3830
3831 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003832 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003833 mask, &cfg);
3834
3835 wdev_unlock(wdev);
3836
3837 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003838}
3839
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003840static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3841{
3842 struct sk_buff *msg;
3843 void *hdr = NULL;
3844 struct nlattr *nl_reg_rules;
3845 unsigned int i;
3846 int err = -EINVAL;
3847
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003848 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003849
3850 if (!cfg80211_regdomain)
3851 goto out;
3852
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003854 if (!msg) {
3855 err = -ENOBUFS;
3856 goto out;
3857 }
3858
3859 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3860 NL80211_CMD_GET_REG);
3861 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003862 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003863
David S. Miller9360ffd2012-03-29 04:41:26 -04003864 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3865 cfg80211_regdomain->alpha2) ||
3866 (cfg80211_regdomain->dfs_region &&
3867 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3868 cfg80211_regdomain->dfs_region)))
3869 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003870
3871 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3872 if (!nl_reg_rules)
3873 goto nla_put_failure;
3874
3875 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3876 struct nlattr *nl_reg_rule;
3877 const struct ieee80211_reg_rule *reg_rule;
3878 const struct ieee80211_freq_range *freq_range;
3879 const struct ieee80211_power_rule *power_rule;
3880
3881 reg_rule = &cfg80211_regdomain->reg_rules[i];
3882 freq_range = &reg_rule->freq_range;
3883 power_rule = &reg_rule->power_rule;
3884
3885 nl_reg_rule = nla_nest_start(msg, i);
3886 if (!nl_reg_rule)
3887 goto nla_put_failure;
3888
David S. Miller9360ffd2012-03-29 04:41:26 -04003889 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3890 reg_rule->flags) ||
3891 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3892 freq_range->start_freq_khz) ||
3893 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3894 freq_range->end_freq_khz) ||
3895 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3896 freq_range->max_bandwidth_khz) ||
3897 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3898 power_rule->max_antenna_gain) ||
3899 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3900 power_rule->max_eirp))
3901 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003902
3903 nla_nest_end(msg, nl_reg_rule);
3904 }
3905
3906 nla_nest_end(msg, nl_reg_rules);
3907
3908 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003909 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003910 goto out;
3911
3912nla_put_failure:
3913 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003914put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003915 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003916 err = -EMSGSIZE;
3917out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003918 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003919 return err;
3920}
3921
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003922static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3923{
3924 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3925 struct nlattr *nl_reg_rule;
3926 char *alpha2 = NULL;
3927 int rem_reg_rules = 0, r = 0;
3928 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003929 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003930 struct ieee80211_regdomain *rd = NULL;
3931
3932 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3933 return -EINVAL;
3934
3935 if (!info->attrs[NL80211_ATTR_REG_RULES])
3936 return -EINVAL;
3937
3938 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3939
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003940 if (info->attrs[NL80211_ATTR_DFS_REGION])
3941 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3942
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003943 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3944 rem_reg_rules) {
3945 num_rules++;
3946 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003947 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003948 }
3949
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003950 mutex_lock(&cfg80211_mutex);
3951
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003952 if (!reg_is_valid_request(alpha2)) {
3953 r = -EINVAL;
3954 goto bad_reg;
3955 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003956
3957 size_of_regd = sizeof(struct ieee80211_regdomain) +
3958 (num_rules * sizeof(struct ieee80211_reg_rule));
3959
3960 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003961 if (!rd) {
3962 r = -ENOMEM;
3963 goto bad_reg;
3964 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003965
3966 rd->n_reg_rules = num_rules;
3967 rd->alpha2[0] = alpha2[0];
3968 rd->alpha2[1] = alpha2[1];
3969
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003970 /*
3971 * Disable DFS master mode if the DFS region was
3972 * not supported or known on this kernel.
3973 */
3974 if (reg_supported_dfs_region(dfs_region))
3975 rd->dfs_region = dfs_region;
3976
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003977 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3978 rem_reg_rules) {
3979 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3980 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3981 reg_rule_policy);
3982 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3983 if (r)
3984 goto bad_reg;
3985
3986 rule_idx++;
3987
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003988 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3989 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003990 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003991 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003992 }
3993
3994 BUG_ON(rule_idx != num_rules);
3995
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003996 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003997
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003998 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003999
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004000 return r;
4001
Johannes Bergd2372b32008-10-24 20:32:20 +02004002 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004003 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004004 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004005 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004006}
4007
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004008static int validate_scan_freqs(struct nlattr *freqs)
4009{
4010 struct nlattr *attr1, *attr2;
4011 int n_channels = 0, tmp1, tmp2;
4012
4013 nla_for_each_nested(attr1, freqs, tmp1) {
4014 n_channels++;
4015 /*
4016 * Some hardware has a limited channel list for
4017 * scanning, and it is pretty much nonsensical
4018 * to scan for a channel twice, so disallow that
4019 * and don't require drivers to check that the
4020 * channel list they get isn't longer than what
4021 * they can scan, as long as they can scan all
4022 * the channels they registered at once.
4023 */
4024 nla_for_each_nested(attr2, freqs, tmp2)
4025 if (attr1 != attr2 &&
4026 nla_get_u32(attr1) == nla_get_u32(attr2))
4027 return 0;
4028 }
4029
4030 return n_channels;
4031}
4032
Johannes Berg2a519312009-02-10 21:25:55 +01004033static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4034{
Johannes Berg4c476992010-10-04 21:36:35 +02004035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4036 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004037 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004038 struct nlattr *attr;
4039 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004040 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004041 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004042
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004043 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4044 return -EINVAL;
4045
Johannes Berg79c97e92009-07-07 03:56:12 +02004046 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004047
Johannes Berg4c476992010-10-04 21:36:35 +02004048 if (!rdev->ops->scan)
4049 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004050
Johannes Berg4c476992010-10-04 21:36:35 +02004051 if (rdev->scan_req)
4052 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004053
4054 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004055 n_channels = validate_scan_freqs(
4056 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004057 if (!n_channels)
4058 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004059 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004060 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004061 n_channels = 0;
4062
Johannes Berg2a519312009-02-10 21:25:55 +01004063 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4064 if (wiphy->bands[band])
4065 n_channels += wiphy->bands[band]->n_channels;
4066 }
4067
4068 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4069 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4070 n_ssids++;
4071
Johannes Berg4c476992010-10-04 21:36:35 +02004072 if (n_ssids > wiphy->max_scan_ssids)
4073 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004074
Jouni Malinen70692ad2009-02-16 19:39:13 +02004075 if (info->attrs[NL80211_ATTR_IE])
4076 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4077 else
4078 ie_len = 0;
4079
Johannes Berg4c476992010-10-04 21:36:35 +02004080 if (ie_len > wiphy->max_scan_ie_len)
4081 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004082
Johannes Berg2a519312009-02-10 21:25:55 +01004083 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004084 + sizeof(*request->ssids) * n_ssids
4085 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004086 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004087 if (!request)
4088 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004089
Johannes Berg2a519312009-02-10 21:25:55 +01004090 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004091 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004092 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004093 if (ie_len) {
4094 if (request->ssids)
4095 request->ie = (void *)(request->ssids + n_ssids);
4096 else
4097 request->ie = (void *)(request->channels + n_channels);
4098 }
Johannes Berg2a519312009-02-10 21:25:55 +01004099
Johannes Berg584991d2009-11-02 13:32:03 +01004100 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004101 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4102 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004103 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004104 struct ieee80211_channel *chan;
4105
4106 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4107
4108 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004109 err = -EINVAL;
4110 goto out_free;
4111 }
Johannes Berg584991d2009-11-02 13:32:03 +01004112
4113 /* ignore disabled channels */
4114 if (chan->flags & IEEE80211_CHAN_DISABLED)
4115 continue;
4116
4117 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004118 i++;
4119 }
4120 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004121 enum ieee80211_band band;
4122
Johannes Berg2a519312009-02-10 21:25:55 +01004123 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004124 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4125 int j;
4126 if (!wiphy->bands[band])
4127 continue;
4128 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004129 struct ieee80211_channel *chan;
4130
4131 chan = &wiphy->bands[band]->channels[j];
4132
4133 if (chan->flags & IEEE80211_CHAN_DISABLED)
4134 continue;
4135
4136 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004137 i++;
4138 }
4139 }
4140 }
4141
Johannes Berg584991d2009-11-02 13:32:03 +01004142 if (!i) {
4143 err = -EINVAL;
4144 goto out_free;
4145 }
4146
4147 request->n_channels = i;
4148
Johannes Berg2a519312009-02-10 21:25:55 +01004149 i = 0;
4150 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4151 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004152 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004153 err = -EINVAL;
4154 goto out_free;
4155 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004156 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004157 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004158 i++;
4159 }
4160 }
4161
Jouni Malinen70692ad2009-02-16 19:39:13 +02004162 if (info->attrs[NL80211_ATTR_IE]) {
4163 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004164 memcpy((void *)request->ie,
4165 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004166 request->ie_len);
4167 }
4168
Johannes Berg34850ab2011-07-18 18:08:35 +02004169 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004170 if (wiphy->bands[i])
4171 request->rates[i] =
4172 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004173
4174 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4175 nla_for_each_nested(attr,
4176 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4177 tmp) {
4178 enum ieee80211_band band = nla_type(attr);
4179
Dan Carpenter84404622011-07-29 11:52:18 +03004180 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004181 err = -EINVAL;
4182 goto out_free;
4183 }
4184 err = ieee80211_get_ratemask(wiphy->bands[band],
4185 nla_data(attr),
4186 nla_len(attr),
4187 &request->rates[band]);
4188 if (err)
4189 goto out_free;
4190 }
4191 }
4192
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304193 request->no_cck =
4194 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4195
Johannes Berg463d0182009-07-14 00:33:35 +02004196 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004197 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004198
Johannes Berg79c97e92009-07-07 03:56:12 +02004199 rdev->scan_req = request;
4200 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004201
Johannes Berg463d0182009-07-14 00:33:35 +02004202 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004203 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004204 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004205 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004206 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004207 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004208 kfree(request);
4209 }
Johannes Berg3b858752009-03-12 09:55:09 +01004210
Johannes Berg2a519312009-02-10 21:25:55 +01004211 return err;
4212}
4213
Luciano Coelho807f8a82011-05-11 17:09:35 +03004214static int nl80211_start_sched_scan(struct sk_buff *skb,
4215 struct genl_info *info)
4216{
4217 struct cfg80211_sched_scan_request *request;
4218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4219 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004220 struct nlattr *attr;
4221 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004222 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004223 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004224 enum ieee80211_band band;
4225 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004226 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004227
4228 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4229 !rdev->ops->sched_scan_start)
4230 return -EOPNOTSUPP;
4231
4232 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4233 return -EINVAL;
4234
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004235 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4236 return -EINVAL;
4237
4238 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4239 if (interval == 0)
4240 return -EINVAL;
4241
Luciano Coelho807f8a82011-05-11 17:09:35 +03004242 wiphy = &rdev->wiphy;
4243
4244 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4245 n_channels = validate_scan_freqs(
4246 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4247 if (!n_channels)
4248 return -EINVAL;
4249 } else {
4250 n_channels = 0;
4251
4252 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4253 if (wiphy->bands[band])
4254 n_channels += wiphy->bands[band]->n_channels;
4255 }
4256
4257 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4258 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4259 tmp)
4260 n_ssids++;
4261
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004262 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004263 return -EINVAL;
4264
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004265 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4266 nla_for_each_nested(attr,
4267 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4268 tmp)
4269 n_match_sets++;
4270
4271 if (n_match_sets > wiphy->max_match_sets)
4272 return -EINVAL;
4273
Luciano Coelho807f8a82011-05-11 17:09:35 +03004274 if (info->attrs[NL80211_ATTR_IE])
4275 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4276 else
4277 ie_len = 0;
4278
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004279 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004280 return -EINVAL;
4281
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004282 mutex_lock(&rdev->sched_scan_mtx);
4283
4284 if (rdev->sched_scan_req) {
4285 err = -EINPROGRESS;
4286 goto out;
4287 }
4288
Luciano Coelho807f8a82011-05-11 17:09:35 +03004289 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004290 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004291 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004292 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004293 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004294 if (!request) {
4295 err = -ENOMEM;
4296 goto out;
4297 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004298
4299 if (n_ssids)
4300 request->ssids = (void *)&request->channels[n_channels];
4301 request->n_ssids = n_ssids;
4302 if (ie_len) {
4303 if (request->ssids)
4304 request->ie = (void *)(request->ssids + n_ssids);
4305 else
4306 request->ie = (void *)(request->channels + n_channels);
4307 }
4308
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004309 if (n_match_sets) {
4310 if (request->ie)
4311 request->match_sets = (void *)(request->ie + ie_len);
4312 else if (request->ssids)
4313 request->match_sets =
4314 (void *)(request->ssids + n_ssids);
4315 else
4316 request->match_sets =
4317 (void *)(request->channels + n_channels);
4318 }
4319 request->n_match_sets = n_match_sets;
4320
Luciano Coelho807f8a82011-05-11 17:09:35 +03004321 i = 0;
4322 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4323 /* user specified, bail out if channel not found */
4324 nla_for_each_nested(attr,
4325 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4326 tmp) {
4327 struct ieee80211_channel *chan;
4328
4329 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4330
4331 if (!chan) {
4332 err = -EINVAL;
4333 goto out_free;
4334 }
4335
4336 /* ignore disabled channels */
4337 if (chan->flags & IEEE80211_CHAN_DISABLED)
4338 continue;
4339
4340 request->channels[i] = chan;
4341 i++;
4342 }
4343 } else {
4344 /* all channels */
4345 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4346 int j;
4347 if (!wiphy->bands[band])
4348 continue;
4349 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4350 struct ieee80211_channel *chan;
4351
4352 chan = &wiphy->bands[band]->channels[j];
4353
4354 if (chan->flags & IEEE80211_CHAN_DISABLED)
4355 continue;
4356
4357 request->channels[i] = chan;
4358 i++;
4359 }
4360 }
4361 }
4362
4363 if (!i) {
4364 err = -EINVAL;
4365 goto out_free;
4366 }
4367
4368 request->n_channels = i;
4369
4370 i = 0;
4371 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4372 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4373 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004374 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004375 err = -EINVAL;
4376 goto out_free;
4377 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004378 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004379 memcpy(request->ssids[i].ssid, nla_data(attr),
4380 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004381 i++;
4382 }
4383 }
4384
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004385 i = 0;
4386 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4387 nla_for_each_nested(attr,
4388 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4389 tmp) {
4390 struct nlattr *ssid;
4391
4392 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4393 nla_data(attr), nla_len(attr),
4394 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004395 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004396 if (ssid) {
4397 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4398 err = -EINVAL;
4399 goto out_free;
4400 }
4401 memcpy(request->match_sets[i].ssid.ssid,
4402 nla_data(ssid), nla_len(ssid));
4403 request->match_sets[i].ssid.ssid_len =
4404 nla_len(ssid);
4405 }
4406 i++;
4407 }
4408 }
4409
Luciano Coelho807f8a82011-05-11 17:09:35 +03004410 if (info->attrs[NL80211_ATTR_IE]) {
4411 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4412 memcpy((void *)request->ie,
4413 nla_data(info->attrs[NL80211_ATTR_IE]),
4414 request->ie_len);
4415 }
4416
4417 request->dev = dev;
4418 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004419 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004420
4421 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4422 if (!err) {
4423 rdev->sched_scan_req = request;
4424 nl80211_send_sched_scan(rdev, dev,
4425 NL80211_CMD_START_SCHED_SCAN);
4426 goto out;
4427 }
4428
4429out_free:
4430 kfree(request);
4431out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004432 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004433 return err;
4434}
4435
4436static int nl80211_stop_sched_scan(struct sk_buff *skb,
4437 struct genl_info *info)
4438{
4439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004440 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004441
4442 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4443 !rdev->ops->sched_scan_stop)
4444 return -EOPNOTSUPP;
4445
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004446 mutex_lock(&rdev->sched_scan_mtx);
4447 err = __cfg80211_stop_sched_scan(rdev, false);
4448 mutex_unlock(&rdev->sched_scan_mtx);
4449
4450 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004451}
4452
Johannes Berg9720bb32011-06-21 09:45:33 +02004453static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4454 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004455 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004456 struct wireless_dev *wdev,
4457 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004458{
Johannes Berg48ab9052009-07-10 18:42:31 +02004459 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004460 void *hdr;
4461 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004462
4463 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004464
Johannes Berg9720bb32011-06-21 09:45:33 +02004465 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004466 NL80211_CMD_NEW_SCAN_RESULTS);
4467 if (!hdr)
4468 return -1;
4469
Johannes Berg9720bb32011-06-21 09:45:33 +02004470 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4471
David S. Miller9360ffd2012-03-29 04:41:26 -04004472 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4473 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4474 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004475
4476 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4477 if (!bss)
4478 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004479 if ((!is_zero_ether_addr(res->bssid) &&
4480 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4481 (res->information_elements && res->len_information_elements &&
4482 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4483 res->len_information_elements,
4484 res->information_elements)) ||
4485 (res->beacon_ies && res->len_beacon_ies &&
4486 res->beacon_ies != res->information_elements &&
4487 nla_put(msg, NL80211_BSS_BEACON_IES,
4488 res->len_beacon_ies, res->beacon_ies)))
4489 goto nla_put_failure;
4490 if (res->tsf &&
4491 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4492 goto nla_put_failure;
4493 if (res->beacon_interval &&
4494 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4495 goto nla_put_failure;
4496 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4497 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4498 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4499 jiffies_to_msecs(jiffies - intbss->ts)))
4500 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004501
Johannes Berg77965c92009-02-18 18:45:06 +01004502 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004503 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004504 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4505 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004506 break;
4507 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004508 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4509 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004510 break;
4511 default:
4512 break;
4513 }
4514
Johannes Berg48ab9052009-07-10 18:42:31 +02004515 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004516 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004517 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004518 if (intbss == wdev->current_bss &&
4519 nla_put_u32(msg, NL80211_BSS_STATUS,
4520 NL80211_BSS_STATUS_ASSOCIATED))
4521 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004522 break;
4523 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004524 if (intbss == wdev->current_bss &&
4525 nla_put_u32(msg, NL80211_BSS_STATUS,
4526 NL80211_BSS_STATUS_IBSS_JOINED))
4527 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004528 break;
4529 default:
4530 break;
4531 }
4532
Johannes Berg2a519312009-02-10 21:25:55 +01004533 nla_nest_end(msg, bss);
4534
4535 return genlmsg_end(msg, hdr);
4536
4537 nla_put_failure:
4538 genlmsg_cancel(msg, hdr);
4539 return -EMSGSIZE;
4540}
4541
4542static int nl80211_dump_scan(struct sk_buff *skb,
4543 struct netlink_callback *cb)
4544{
Johannes Berg48ab9052009-07-10 18:42:31 +02004545 struct cfg80211_registered_device *rdev;
4546 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004547 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004548 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004549 int start = cb->args[1], idx = 0;
4550 int err;
4551
Johannes Berg67748892010-10-04 21:14:06 +02004552 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4553 if (err)
4554 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004555
Johannes Berg48ab9052009-07-10 18:42:31 +02004556 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004557
Johannes Berg48ab9052009-07-10 18:42:31 +02004558 wdev_lock(wdev);
4559 spin_lock_bh(&rdev->bss_lock);
4560 cfg80211_bss_expire(rdev);
4561
Johannes Berg9720bb32011-06-21 09:45:33 +02004562 cb->seq = rdev->bss_generation;
4563
Johannes Berg48ab9052009-07-10 18:42:31 +02004564 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004565 if (++idx <= start)
4566 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004567 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004568 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004569 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004570 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004571 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004572 }
4573 }
4574
Johannes Berg48ab9052009-07-10 18:42:31 +02004575 spin_unlock_bh(&rdev->bss_lock);
4576 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004577
4578 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004579 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004580
Johannes Berg67748892010-10-04 21:14:06 +02004581 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004582}
4583
Holger Schurig61fa7132009-11-11 12:25:40 +01004584static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4585 int flags, struct net_device *dev,
4586 struct survey_info *survey)
4587{
4588 void *hdr;
4589 struct nlattr *infoattr;
4590
Holger Schurig61fa7132009-11-11 12:25:40 +01004591 hdr = nl80211hdr_put(msg, pid, seq, flags,
4592 NL80211_CMD_NEW_SURVEY_RESULTS);
4593 if (!hdr)
4594 return -ENOMEM;
4595
David S. Miller9360ffd2012-03-29 04:41:26 -04004596 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4597 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004598
4599 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4600 if (!infoattr)
4601 goto nla_put_failure;
4602
David S. Miller9360ffd2012-03-29 04:41:26 -04004603 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4604 survey->channel->center_freq))
4605 goto nla_put_failure;
4606
4607 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4608 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4609 goto nla_put_failure;
4610 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4611 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4612 goto nla_put_failure;
4613 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4614 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4615 survey->channel_time))
4616 goto nla_put_failure;
4617 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4618 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4619 survey->channel_time_busy))
4620 goto nla_put_failure;
4621 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4622 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4623 survey->channel_time_ext_busy))
4624 goto nla_put_failure;
4625 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4626 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4627 survey->channel_time_rx))
4628 goto nla_put_failure;
4629 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4630 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4631 survey->channel_time_tx))
4632 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004633
4634 nla_nest_end(msg, infoattr);
4635
4636 return genlmsg_end(msg, hdr);
4637
4638 nla_put_failure:
4639 genlmsg_cancel(msg, hdr);
4640 return -EMSGSIZE;
4641}
4642
4643static int nl80211_dump_survey(struct sk_buff *skb,
4644 struct netlink_callback *cb)
4645{
4646 struct survey_info survey;
4647 struct cfg80211_registered_device *dev;
4648 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004649 int survey_idx = cb->args[1];
4650 int res;
4651
Johannes Berg67748892010-10-04 21:14:06 +02004652 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4653 if (res)
4654 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004655
4656 if (!dev->ops->dump_survey) {
4657 res = -EOPNOTSUPP;
4658 goto out_err;
4659 }
4660
4661 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004662 struct ieee80211_channel *chan;
4663
Holger Schurig61fa7132009-11-11 12:25:40 +01004664 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4665 &survey);
4666 if (res == -ENOENT)
4667 break;
4668 if (res)
4669 goto out_err;
4670
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004671 /* Survey without a channel doesn't make sense */
4672 if (!survey.channel) {
4673 res = -EINVAL;
4674 goto out;
4675 }
4676
4677 chan = ieee80211_get_channel(&dev->wiphy,
4678 survey.channel->center_freq);
4679 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4680 survey_idx++;
4681 continue;
4682 }
4683
Holger Schurig61fa7132009-11-11 12:25:40 +01004684 if (nl80211_send_survey(skb,
4685 NETLINK_CB(cb->skb).pid,
4686 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4687 netdev,
4688 &survey) < 0)
4689 goto out;
4690 survey_idx++;
4691 }
4692
4693 out:
4694 cb->args[1] = survey_idx;
4695 res = skb->len;
4696 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004697 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004698 return res;
4699}
4700
Jouni Malinen255e7372009-03-20 21:21:17 +02004701static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4702{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004703 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004704}
4705
Samuel Ortizb23aa672009-07-01 21:26:54 +02004706static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4707{
4708 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4709 NL80211_WPA_VERSION_2));
4710}
4711
Jouni Malinen636a5d32009-03-19 13:39:22 +02004712static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4713{
Johannes Berg4c476992010-10-04 21:36:35 +02004714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4715 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004716 struct ieee80211_channel *chan;
4717 const u8 *bssid, *ssid, *ie = NULL;
4718 int err, ssid_len, ie_len = 0;
4719 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004720 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004721 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004722
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004723 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4724 return -EINVAL;
4725
4726 if (!info->attrs[NL80211_ATTR_MAC])
4727 return -EINVAL;
4728
Jouni Malinen17780922009-03-27 20:52:47 +02004729 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4730 return -EINVAL;
4731
Johannes Berg19957bb2009-07-02 17:20:43 +02004732 if (!info->attrs[NL80211_ATTR_SSID])
4733 return -EINVAL;
4734
4735 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4736 return -EINVAL;
4737
Johannes Bergfffd0932009-07-08 14:22:54 +02004738 err = nl80211_parse_key(info, &key);
4739 if (err)
4740 return err;
4741
4742 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004743 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4744 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004745 if (!key.p.key || !key.p.key_len)
4746 return -EINVAL;
4747 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4748 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4749 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4750 key.p.key_len != WLAN_KEY_LEN_WEP104))
4751 return -EINVAL;
4752 if (key.idx > 4)
4753 return -EINVAL;
4754 } else {
4755 key.p.key_len = 0;
4756 key.p.key = NULL;
4757 }
4758
Johannes Bergafea0b72010-08-10 09:46:42 +02004759 if (key.idx >= 0) {
4760 int i;
4761 bool ok = false;
4762 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4763 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4764 ok = true;
4765 break;
4766 }
4767 }
Johannes Berg4c476992010-10-04 21:36:35 +02004768 if (!ok)
4769 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004770 }
4771
Johannes Berg4c476992010-10-04 21:36:35 +02004772 if (!rdev->ops->auth)
4773 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004774
Johannes Berg074ac8d2010-09-16 14:58:22 +02004775 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004776 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4777 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004778
Johannes Berg19957bb2009-07-02 17:20:43 +02004779 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004780 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004781 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004782 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4783 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004784
Johannes Berg19957bb2009-07-02 17:20:43 +02004785 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4786 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4787
4788 if (info->attrs[NL80211_ATTR_IE]) {
4789 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4790 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4791 }
4792
4793 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004794 if (!nl80211_valid_auth_type(auth_type))
4795 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004796
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004797 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4798
Johannes Berg95de8172012-01-20 13:55:25 +01004799 /*
4800 * Since we no longer track auth state, ignore
4801 * requests to only change local state.
4802 */
4803 if (local_state_change)
4804 return 0;
4805
Johannes Berg4c476992010-10-04 21:36:35 +02004806 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4807 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004808 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004809}
4810
Johannes Bergc0692b82010-08-27 14:26:53 +03004811static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4812 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004813 struct cfg80211_crypto_settings *settings,
4814 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004815{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004816 memset(settings, 0, sizeof(*settings));
4817
Samuel Ortizb23aa672009-07-01 21:26:54 +02004818 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4819
Johannes Bergc0692b82010-08-27 14:26:53 +03004820 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4821 u16 proto;
4822 proto = nla_get_u16(
4823 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4824 settings->control_port_ethertype = cpu_to_be16(proto);
4825 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4826 proto != ETH_P_PAE)
4827 return -EINVAL;
4828 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4829 settings->control_port_no_encrypt = true;
4830 } else
4831 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4832
Samuel Ortizb23aa672009-07-01 21:26:54 +02004833 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4834 void *data;
4835 int len, i;
4836
4837 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4838 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4839 settings->n_ciphers_pairwise = len / sizeof(u32);
4840
4841 if (len % sizeof(u32))
4842 return -EINVAL;
4843
Johannes Berg3dc27d22009-07-02 21:36:37 +02004844 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004845 return -EINVAL;
4846
4847 memcpy(settings->ciphers_pairwise, data, len);
4848
4849 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004850 if (!cfg80211_supported_cipher_suite(
4851 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004852 settings->ciphers_pairwise[i]))
4853 return -EINVAL;
4854 }
4855
4856 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4857 settings->cipher_group =
4858 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004859 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4860 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004861 return -EINVAL;
4862 }
4863
4864 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4865 settings->wpa_versions =
4866 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4867 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4868 return -EINVAL;
4869 }
4870
4871 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4872 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004873 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004874
4875 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4876 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4877 settings->n_akm_suites = len / sizeof(u32);
4878
4879 if (len % sizeof(u32))
4880 return -EINVAL;
4881
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004882 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4883 return -EINVAL;
4884
Samuel Ortizb23aa672009-07-01 21:26:54 +02004885 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004886 }
4887
4888 return 0;
4889}
4890
Jouni Malinen636a5d32009-03-19 13:39:22 +02004891static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4892{
Johannes Berg4c476992010-10-04 21:36:35 +02004893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4894 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004895 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004896 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004897 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004898 int err, ssid_len, ie_len = 0;
4899 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004900 u32 flags = 0;
4901 struct ieee80211_ht_cap *ht_capa = NULL;
4902 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004903
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004904 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4905 return -EINVAL;
4906
4907 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004908 !info->attrs[NL80211_ATTR_SSID] ||
4909 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004910 return -EINVAL;
4911
Johannes Berg4c476992010-10-04 21:36:35 +02004912 if (!rdev->ops->assoc)
4913 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004914
Johannes Berg074ac8d2010-09-16 14:58:22 +02004915 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004916 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4917 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004918
Johannes Berg19957bb2009-07-02 17:20:43 +02004919 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004920
Johannes Berg19957bb2009-07-02 17:20:43 +02004921 chan = ieee80211_get_channel(&rdev->wiphy,
4922 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004923 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4924 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004925
Johannes Berg19957bb2009-07-02 17:20:43 +02004926 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4927 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004928
4929 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004930 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4931 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004932 }
4933
Jouni Malinendc6382c2009-05-06 22:09:37 +03004934 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004935 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004936 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004937 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004938 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004939 else if (mfp != NL80211_MFP_NO)
4940 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004941 }
4942
Johannes Berg3e5d7642009-07-07 14:37:26 +02004943 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4944 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4945
Ben Greear7e7c8922011-11-18 11:31:59 -08004946 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4947 flags |= ASSOC_REQ_DISABLE_HT;
4948
4949 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4950 ht_capa_mask =
4951 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4952
4953 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4954 if (!ht_capa_mask)
4955 return -EINVAL;
4956 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4957 }
4958
Johannes Bergc0692b82010-08-27 14:26:53 +03004959 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004960 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004961 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4962 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004963 &crypto, flags, ht_capa,
4964 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004965
Jouni Malinen636a5d32009-03-19 13:39:22 +02004966 return err;
4967}
4968
4969static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4970{
Johannes Berg4c476992010-10-04 21:36:35 +02004971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4972 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004973 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004974 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004975 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004976 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004977
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004978 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4979 return -EINVAL;
4980
4981 if (!info->attrs[NL80211_ATTR_MAC])
4982 return -EINVAL;
4983
4984 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4985 return -EINVAL;
4986
Johannes Berg4c476992010-10-04 21:36:35 +02004987 if (!rdev->ops->deauth)
4988 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004989
Johannes Berg074ac8d2010-09-16 14:58:22 +02004990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004991 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4992 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004993
Johannes Berg19957bb2009-07-02 17:20:43 +02004994 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004995
Johannes Berg19957bb2009-07-02 17:20:43 +02004996 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4997 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004998 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02004999 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005000 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005001
5002 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005003 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5004 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005005 }
5006
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005007 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5008
Johannes Berg4c476992010-10-04 21:36:35 +02005009 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5010 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005011}
5012
5013static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5014{
Johannes Berg4c476992010-10-04 21:36:35 +02005015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5016 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005017 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005018 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005019 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005020 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005021
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005022 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5023 return -EINVAL;
5024
5025 if (!info->attrs[NL80211_ATTR_MAC])
5026 return -EINVAL;
5027
5028 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5029 return -EINVAL;
5030
Johannes Berg4c476992010-10-04 21:36:35 +02005031 if (!rdev->ops->disassoc)
5032 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005033
Johannes Berg074ac8d2010-09-16 14:58:22 +02005034 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005035 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5036 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005037
Johannes Berg19957bb2009-07-02 17:20:43 +02005038 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005039
Johannes Berg19957bb2009-07-02 17:20:43 +02005040 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5041 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005042 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005043 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005044 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005045
5046 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005047 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5048 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005049 }
5050
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005051 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5052
Johannes Berg4c476992010-10-04 21:36:35 +02005053 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5054 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005055}
5056
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005057static bool
5058nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5059 int mcast_rate[IEEE80211_NUM_BANDS],
5060 int rateval)
5061{
5062 struct wiphy *wiphy = &rdev->wiphy;
5063 bool found = false;
5064 int band, i;
5065
5066 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5067 struct ieee80211_supported_band *sband;
5068
5069 sband = wiphy->bands[band];
5070 if (!sband)
5071 continue;
5072
5073 for (i = 0; i < sband->n_bitrates; i++) {
5074 if (sband->bitrates[i].bitrate == rateval) {
5075 mcast_rate[band] = i + 1;
5076 found = true;
5077 break;
5078 }
5079 }
5080 }
5081
5082 return found;
5083}
5084
Johannes Berg04a773a2009-04-19 21:24:32 +02005085static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5086{
Johannes Berg4c476992010-10-04 21:36:35 +02005087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5088 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005089 struct cfg80211_ibss_params ibss;
5090 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005091 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005092 int err;
5093
Johannes Berg8e30bc52009-04-22 17:45:38 +02005094 memset(&ibss, 0, sizeof(ibss));
5095
Johannes Berg04a773a2009-04-19 21:24:32 +02005096 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5097 return -EINVAL;
5098
5099 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5100 !info->attrs[NL80211_ATTR_SSID] ||
5101 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5102 return -EINVAL;
5103
Johannes Berg8e30bc52009-04-22 17:45:38 +02005104 ibss.beacon_interval = 100;
5105
5106 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5107 ibss.beacon_interval =
5108 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5109 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5110 return -EINVAL;
5111 }
5112
Johannes Berg4c476992010-10-04 21:36:35 +02005113 if (!rdev->ops->join_ibss)
5114 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005115
Johannes Berg4c476992010-10-04 21:36:35 +02005116 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5117 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005118
Johannes Berg79c97e92009-07-07 03:56:12 +02005119 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005120
Johannes Berg39193492011-09-16 13:45:25 +02005121 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005122 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005123
5124 if (!is_valid_ether_addr(ibss.bssid))
5125 return -EINVAL;
5126 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005127 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5128 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5129
5130 if (info->attrs[NL80211_ATTR_IE]) {
5131 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5132 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5133 }
5134
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005135 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5136 enum nl80211_channel_type channel_type;
5137
Johannes Bergcd6c6592012-05-10 21:27:18 +02005138 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005139 return -EINVAL;
5140
5141 if (channel_type != NL80211_CHAN_NO_HT &&
5142 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5143 return -EINVAL;
5144
5145 ibss.channel_type = channel_type;
5146 } else {
5147 ibss.channel_type = NL80211_CHAN_NO_HT;
5148 }
5149
5150 ibss.channel = rdev_freq_to_chan(rdev,
5151 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5152 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005153 if (!ibss.channel ||
5154 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005155 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5156 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005157
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005158 /* Both channels should be able to initiate communication */
5159 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5160 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5161 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5162 ibss.channel_type))
5163 return -EINVAL;
5164
Johannes Berg04a773a2009-04-19 21:24:32 +02005165 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005166 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005167
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005168 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5169 u8 *rates =
5170 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5171 int n_rates =
5172 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5173 struct ieee80211_supported_band *sband =
5174 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005175
Johannes Berg34850ab2011-07-18 18:08:35 +02005176 err = ieee80211_get_ratemask(sband, rates, n_rates,
5177 &ibss.basic_rates);
5178 if (err)
5179 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005180 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005181
5182 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5183 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5184 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5185 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005186
Johannes Berg4c476992010-10-04 21:36:35 +02005187 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5188 connkeys = nl80211_parse_connkeys(rdev,
5189 info->attrs[NL80211_ATTR_KEYS]);
5190 if (IS_ERR(connkeys))
5191 return PTR_ERR(connkeys);
5192 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005193
Antonio Quartulli267335d2012-01-31 20:25:47 +01005194 ibss.control_port =
5195 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5196
Johannes Berg4c476992010-10-04 21:36:35 +02005197 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005198 if (err)
5199 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005200 return err;
5201}
5202
5203static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5204{
Johannes Berg4c476992010-10-04 21:36:35 +02005205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5206 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005207
Johannes Berg4c476992010-10-04 21:36:35 +02005208 if (!rdev->ops->leave_ibss)
5209 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005210
Johannes Berg4c476992010-10-04 21:36:35 +02005211 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5212 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005213
Johannes Berg4c476992010-10-04 21:36:35 +02005214 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005215}
5216
Johannes Bergaff89a92009-07-01 21:26:51 +02005217#ifdef CONFIG_NL80211_TESTMODE
5218static struct genl_multicast_group nl80211_testmode_mcgrp = {
5219 .name = "testmode",
5220};
5221
5222static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5223{
Johannes Berg4c476992010-10-04 21:36:35 +02005224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005225 int err;
5226
5227 if (!info->attrs[NL80211_ATTR_TESTDATA])
5228 return -EINVAL;
5229
Johannes Bergaff89a92009-07-01 21:26:51 +02005230 err = -EOPNOTSUPP;
5231 if (rdev->ops->testmode_cmd) {
5232 rdev->testmode_info = info;
5233 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5234 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5235 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5236 rdev->testmode_info = NULL;
5237 }
5238
Johannes Bergaff89a92009-07-01 21:26:51 +02005239 return err;
5240}
5241
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005242static int nl80211_testmode_dump(struct sk_buff *skb,
5243 struct netlink_callback *cb)
5244{
Johannes Berg00918d32011-12-13 17:22:05 +01005245 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005246 int err;
5247 long phy_idx;
5248 void *data = NULL;
5249 int data_len = 0;
5250
5251 if (cb->args[0]) {
5252 /*
5253 * 0 is a valid index, but not valid for args[0],
5254 * so we need to offset by 1.
5255 */
5256 phy_idx = cb->args[0] - 1;
5257 } else {
5258 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5259 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5260 nl80211_policy);
5261 if (err)
5262 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005263
Johannes Berg2bd7e352012-06-15 14:23:16 +02005264 mutex_lock(&cfg80211_mutex);
5265 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5266 nl80211_fam.attrbuf);
5267 if (IS_ERR(rdev)) {
5268 mutex_unlock(&cfg80211_mutex);
5269 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005270 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005271 phy_idx = rdev->wiphy_idx;
5272 rdev = NULL;
5273 mutex_unlock(&cfg80211_mutex);
5274
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005275 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5276 cb->args[1] =
5277 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5278 }
5279
5280 if (cb->args[1]) {
5281 data = nla_data((void *)cb->args[1]);
5282 data_len = nla_len((void *)cb->args[1]);
5283 }
5284
5285 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005286 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5287 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005288 mutex_unlock(&cfg80211_mutex);
5289 return -ENOENT;
5290 }
Johannes Berg00918d32011-12-13 17:22:05 +01005291 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005292 mutex_unlock(&cfg80211_mutex);
5293
Johannes Berg00918d32011-12-13 17:22:05 +01005294 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005295 err = -EOPNOTSUPP;
5296 goto out_err;
5297 }
5298
5299 while (1) {
5300 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5301 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5302 NL80211_CMD_TESTMODE);
5303 struct nlattr *tmdata;
5304
David S. Miller9360ffd2012-03-29 04:41:26 -04005305 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005306 genlmsg_cancel(skb, hdr);
5307 break;
5308 }
5309
5310 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5311 if (!tmdata) {
5312 genlmsg_cancel(skb, hdr);
5313 break;
5314 }
Johannes Berg00918d32011-12-13 17:22:05 +01005315 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5316 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005317 nla_nest_end(skb, tmdata);
5318
5319 if (err == -ENOBUFS || err == -ENOENT) {
5320 genlmsg_cancel(skb, hdr);
5321 break;
5322 } else if (err) {
5323 genlmsg_cancel(skb, hdr);
5324 goto out_err;
5325 }
5326
5327 genlmsg_end(skb, hdr);
5328 }
5329
5330 err = skb->len;
5331 /* see above */
5332 cb->args[0] = phy_idx + 1;
5333 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005334 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005335 return err;
5336}
5337
Johannes Bergaff89a92009-07-01 21:26:51 +02005338static struct sk_buff *
5339__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5340 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5341{
5342 struct sk_buff *skb;
5343 void *hdr;
5344 struct nlattr *data;
5345
5346 skb = nlmsg_new(approxlen + 100, gfp);
5347 if (!skb)
5348 return NULL;
5349
5350 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5351 if (!hdr) {
5352 kfree_skb(skb);
5353 return NULL;
5354 }
5355
David S. Miller9360ffd2012-03-29 04:41:26 -04005356 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5357 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005358 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5359
5360 ((void **)skb->cb)[0] = rdev;
5361 ((void **)skb->cb)[1] = hdr;
5362 ((void **)skb->cb)[2] = data;
5363
5364 return skb;
5365
5366 nla_put_failure:
5367 kfree_skb(skb);
5368 return NULL;
5369}
5370
5371struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5372 int approxlen)
5373{
5374 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5375
5376 if (WARN_ON(!rdev->testmode_info))
5377 return NULL;
5378
5379 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5380 rdev->testmode_info->snd_pid,
5381 rdev->testmode_info->snd_seq,
5382 GFP_KERNEL);
5383}
5384EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5385
5386int cfg80211_testmode_reply(struct sk_buff *skb)
5387{
5388 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5389 void *hdr = ((void **)skb->cb)[1];
5390 struct nlattr *data = ((void **)skb->cb)[2];
5391
5392 if (WARN_ON(!rdev->testmode_info)) {
5393 kfree_skb(skb);
5394 return -EINVAL;
5395 }
5396
5397 nla_nest_end(skb, data);
5398 genlmsg_end(skb, hdr);
5399 return genlmsg_reply(skb, rdev->testmode_info);
5400}
5401EXPORT_SYMBOL(cfg80211_testmode_reply);
5402
5403struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5404 int approxlen, gfp_t gfp)
5405{
5406 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5407
5408 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5409}
5410EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5411
5412void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5413{
5414 void *hdr = ((void **)skb->cb)[1];
5415 struct nlattr *data = ((void **)skb->cb)[2];
5416
5417 nla_nest_end(skb, data);
5418 genlmsg_end(skb, hdr);
5419 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5420}
5421EXPORT_SYMBOL(cfg80211_testmode_event);
5422#endif
5423
Samuel Ortizb23aa672009-07-01 21:26:54 +02005424static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5425{
Johannes Berg4c476992010-10-04 21:36:35 +02005426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5427 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005428 struct cfg80211_connect_params connect;
5429 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005430 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005431 int err;
5432
5433 memset(&connect, 0, sizeof(connect));
5434
5435 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5436 return -EINVAL;
5437
5438 if (!info->attrs[NL80211_ATTR_SSID] ||
5439 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5440 return -EINVAL;
5441
5442 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5443 connect.auth_type =
5444 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5445 if (!nl80211_valid_auth_type(connect.auth_type))
5446 return -EINVAL;
5447 } else
5448 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5449
5450 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5451
Johannes Bergc0692b82010-08-27 14:26:53 +03005452 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005453 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005454 if (err)
5455 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005456
Johannes Berg074ac8d2010-09-16 14:58:22 +02005457 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005458 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5459 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005460
Johannes Berg79c97e92009-07-07 03:56:12 +02005461 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005462
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305463 connect.bg_scan_period = -1;
5464 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5465 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5466 connect.bg_scan_period =
5467 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5468 }
5469
Samuel Ortizb23aa672009-07-01 21:26:54 +02005470 if (info->attrs[NL80211_ATTR_MAC])
5471 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5472 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5473 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5474
5475 if (info->attrs[NL80211_ATTR_IE]) {
5476 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5477 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5478 }
5479
5480 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5481 connect.channel =
5482 ieee80211_get_channel(wiphy,
5483 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5484 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005485 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5486 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005487 }
5488
Johannes Bergfffd0932009-07-08 14:22:54 +02005489 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5490 connkeys = nl80211_parse_connkeys(rdev,
5491 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005492 if (IS_ERR(connkeys))
5493 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005494 }
5495
Ben Greear7e7c8922011-11-18 11:31:59 -08005496 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5497 connect.flags |= ASSOC_REQ_DISABLE_HT;
5498
5499 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5500 memcpy(&connect.ht_capa_mask,
5501 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5502 sizeof(connect.ht_capa_mask));
5503
5504 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5505 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5506 return -EINVAL;
5507 memcpy(&connect.ht_capa,
5508 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5509 sizeof(connect.ht_capa));
5510 }
5511
Johannes Bergfffd0932009-07-08 14:22:54 +02005512 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005513 if (err)
5514 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005515 return err;
5516}
5517
5518static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5519{
Johannes Berg4c476992010-10-04 21:36:35 +02005520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5521 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005522 u16 reason;
5523
5524 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5525 reason = WLAN_REASON_DEAUTH_LEAVING;
5526 else
5527 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5528
5529 if (reason == 0)
5530 return -EINVAL;
5531
Johannes Berg074ac8d2010-09-16 14:58:22 +02005532 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005533 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5534 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005535
Johannes Berg4c476992010-10-04 21:36:35 +02005536 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005537}
5538
Johannes Berg463d0182009-07-14 00:33:35 +02005539static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5540{
Johannes Berg4c476992010-10-04 21:36:35 +02005541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005542 struct net *net;
5543 int err;
5544 u32 pid;
5545
5546 if (!info->attrs[NL80211_ATTR_PID])
5547 return -EINVAL;
5548
5549 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5550
Johannes Berg463d0182009-07-14 00:33:35 +02005551 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005552 if (IS_ERR(net))
5553 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005554
5555 err = 0;
5556
5557 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005558 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5559 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005560
Johannes Berg463d0182009-07-14 00:33:35 +02005561 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005562 return err;
5563}
5564
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005565static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5566{
Johannes Berg4c476992010-10-04 21:36:35 +02005567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005568 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5569 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005570 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005571 struct cfg80211_pmksa pmksa;
5572
5573 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5574
5575 if (!info->attrs[NL80211_ATTR_MAC])
5576 return -EINVAL;
5577
5578 if (!info->attrs[NL80211_ATTR_PMKID])
5579 return -EINVAL;
5580
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005581 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5582 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5583
Johannes Berg074ac8d2010-09-16 14:58:22 +02005584 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005585 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5586 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005587
5588 switch (info->genlhdr->cmd) {
5589 case NL80211_CMD_SET_PMKSA:
5590 rdev_ops = rdev->ops->set_pmksa;
5591 break;
5592 case NL80211_CMD_DEL_PMKSA:
5593 rdev_ops = rdev->ops->del_pmksa;
5594 break;
5595 default:
5596 WARN_ON(1);
5597 break;
5598 }
5599
Johannes Berg4c476992010-10-04 21:36:35 +02005600 if (!rdev_ops)
5601 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005602
Johannes Berg4c476992010-10-04 21:36:35 +02005603 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005604}
5605
5606static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5607{
Johannes Berg4c476992010-10-04 21:36:35 +02005608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5609 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005610
Johannes Berg074ac8d2010-09-16 14:58:22 +02005611 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005612 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5613 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005614
Johannes Berg4c476992010-10-04 21:36:35 +02005615 if (!rdev->ops->flush_pmksa)
5616 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005617
Johannes Berg4c476992010-10-04 21:36:35 +02005618 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005619}
5620
Arik Nemtsov109086c2011-09-28 14:12:50 +03005621static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5622{
5623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5624 struct net_device *dev = info->user_ptr[1];
5625 u8 action_code, dialog_token;
5626 u16 status_code;
5627 u8 *peer;
5628
5629 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5630 !rdev->ops->tdls_mgmt)
5631 return -EOPNOTSUPP;
5632
5633 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5634 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5635 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5636 !info->attrs[NL80211_ATTR_IE] ||
5637 !info->attrs[NL80211_ATTR_MAC])
5638 return -EINVAL;
5639
5640 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5641 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5642 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5643 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5644
5645 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5646 dialog_token, status_code,
5647 nla_data(info->attrs[NL80211_ATTR_IE]),
5648 nla_len(info->attrs[NL80211_ATTR_IE]));
5649}
5650
5651static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5652{
5653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5654 struct net_device *dev = info->user_ptr[1];
5655 enum nl80211_tdls_operation operation;
5656 u8 *peer;
5657
5658 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5659 !rdev->ops->tdls_oper)
5660 return -EOPNOTSUPP;
5661
5662 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5663 !info->attrs[NL80211_ATTR_MAC])
5664 return -EINVAL;
5665
5666 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5667 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5668
5669 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5670}
5671
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005672static int nl80211_remain_on_channel(struct sk_buff *skb,
5673 struct genl_info *info)
5674{
Johannes Berg4c476992010-10-04 21:36:35 +02005675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5676 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005677 struct ieee80211_channel *chan;
5678 struct sk_buff *msg;
5679 void *hdr;
5680 u64 cookie;
5681 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5682 u32 freq, duration;
5683 int err;
5684
5685 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5686 !info->attrs[NL80211_ATTR_DURATION])
5687 return -EINVAL;
5688
5689 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5690
Johannes Berg7c4ef712011-11-18 15:33:48 +01005691 if (!rdev->ops->remain_on_channel ||
5692 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005693 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005694
Johannes Bergebf348f2012-06-01 12:50:54 +02005695 /*
5696 * We should be on that channel for at least a minimum amount of
5697 * time (10ms) but no longer than the driver supports.
5698 */
5699 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5700 duration > rdev->wiphy.max_remain_on_channel_duration)
5701 return -EINVAL;
5702
Johannes Bergcd6c6592012-05-10 21:27:18 +02005703 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5704 !nl80211_valid_channel_type(info, &channel_type))
5705 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005706
5707 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5708 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005709 if (chan == NULL)
5710 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005711
5712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005713 if (!msg)
5714 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005715
5716 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5717 NL80211_CMD_REMAIN_ON_CHANNEL);
5718
5719 if (IS_ERR(hdr)) {
5720 err = PTR_ERR(hdr);
5721 goto free_msg;
5722 }
5723
5724 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5725 channel_type, duration, &cookie);
5726
5727 if (err)
5728 goto free_msg;
5729
David S. Miller9360ffd2012-03-29 04:41:26 -04005730 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5731 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005732
5733 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005734
5735 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005736
5737 nla_put_failure:
5738 err = -ENOBUFS;
5739 free_msg:
5740 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005741 return err;
5742}
5743
5744static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5745 struct genl_info *info)
5746{
Johannes Berg4c476992010-10-04 21:36:35 +02005747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5748 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005749 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005750
5751 if (!info->attrs[NL80211_ATTR_COOKIE])
5752 return -EINVAL;
5753
Johannes Berg4c476992010-10-04 21:36:35 +02005754 if (!rdev->ops->cancel_remain_on_channel)
5755 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005756
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005757 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5758
Johannes Berg4c476992010-10-04 21:36:35 +02005759 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005760}
5761
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005762static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5763 u8 *rates, u8 rates_len)
5764{
5765 u8 i;
5766 u32 mask = 0;
5767
5768 for (i = 0; i < rates_len; i++) {
5769 int rate = (rates[i] & 0x7f) * 5;
5770 int ridx;
5771 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5772 struct ieee80211_rate *srate =
5773 &sband->bitrates[ridx];
5774 if (rate == srate->bitrate) {
5775 mask |= 1 << ridx;
5776 break;
5777 }
5778 }
5779 if (ridx == sband->n_bitrates)
5780 return 0; /* rate not found */
5781 }
5782
5783 return mask;
5784}
5785
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005786static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5787 u8 *rates, u8 rates_len,
5788 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5789{
5790 u8 i;
5791
5792 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5793
5794 for (i = 0; i < rates_len; i++) {
5795 int ridx, rbit;
5796
5797 ridx = rates[i] / 8;
5798 rbit = BIT(rates[i] % 8);
5799
5800 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005801 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005802 return false;
5803
5804 /* check availability */
5805 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5806 mcs[ridx] |= rbit;
5807 else
5808 return false;
5809 }
5810
5811 return true;
5812}
5813
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005814static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005815 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5816 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005817 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5818 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005819};
5820
5821static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5822 struct genl_info *info)
5823{
5824 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005825 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005826 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005827 int rem, i;
5828 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005829 struct nlattr *tx_rates;
5830 struct ieee80211_supported_band *sband;
5831
5832 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5833 return -EINVAL;
5834
Johannes Berg4c476992010-10-04 21:36:35 +02005835 if (!rdev->ops->set_bitrate_mask)
5836 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005837
5838 memset(&mask, 0, sizeof(mask));
5839 /* Default to all rates enabled */
5840 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5841 sband = rdev->wiphy.bands[i];
5842 mask.control[i].legacy =
5843 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005844 if (sband)
5845 memcpy(mask.control[i].mcs,
5846 sband->ht_cap.mcs.rx_mask,
5847 sizeof(mask.control[i].mcs));
5848 else
5849 memset(mask.control[i].mcs, 0,
5850 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005851 }
5852
5853 /*
5854 * The nested attribute uses enum nl80211_band as the index. This maps
5855 * directly to the enum ieee80211_band values used in cfg80211.
5856 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005857 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005858 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5859 {
5860 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005861 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5862 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005863 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005864 if (sband == NULL)
5865 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005866 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5867 nla_len(tx_rates), nl80211_txattr_policy);
5868 if (tb[NL80211_TXRATE_LEGACY]) {
5869 mask.control[band].legacy = rateset_to_mask(
5870 sband,
5871 nla_data(tb[NL80211_TXRATE_LEGACY]),
5872 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305873 if ((mask.control[band].legacy == 0) &&
5874 nla_len(tb[NL80211_TXRATE_LEGACY]))
5875 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005876 }
5877 if (tb[NL80211_TXRATE_MCS]) {
5878 if (!ht_rateset_to_mask(
5879 sband,
5880 nla_data(tb[NL80211_TXRATE_MCS]),
5881 nla_len(tb[NL80211_TXRATE_MCS]),
5882 mask.control[band].mcs))
5883 return -EINVAL;
5884 }
5885
5886 if (mask.control[band].legacy == 0) {
5887 /* don't allow empty legacy rates if HT
5888 * is not even supported. */
5889 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5890 return -EINVAL;
5891
5892 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5893 if (mask.control[band].mcs[i])
5894 break;
5895
5896 /* legacy and mcs rates may not be both empty */
5897 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005898 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005899 }
5900 }
5901
Johannes Berg4c476992010-10-04 21:36:35 +02005902 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005903}
5904
Johannes Berg2e161f72010-08-12 15:38:38 +02005905static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005906{
Johannes Berg4c476992010-10-04 21:36:35 +02005907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5908 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005909 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005910
5911 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5912 return -EINVAL;
5913
Johannes Berg2e161f72010-08-12 15:38:38 +02005914 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5915 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005916
Johannes Berg9d38d852010-06-09 17:20:33 +02005917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005919 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5920 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5921 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005922 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005923 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5924 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005925
5926 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005927 if (!rdev->ops->mgmt_tx)
5928 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005929
Johannes Berg4c476992010-10-04 21:36:35 +02005930 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005931 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005932 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5933 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005934}
5935
Johannes Berg2e161f72010-08-12 15:38:38 +02005936static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005937{
Johannes Berg4c476992010-10-04 21:36:35 +02005938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5939 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005940 struct ieee80211_channel *chan;
5941 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005942 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005943 u32 freq;
5944 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005945 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005946 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005947 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005948 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005949 bool offchan, no_cck, dont_wait_for_ack;
5950
5951 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005952
5953 if (!info->attrs[NL80211_ATTR_FRAME] ||
5954 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5955 return -EINVAL;
5956
Johannes Berg4c476992010-10-04 21:36:35 +02005957 if (!rdev->ops->mgmt_tx)
5958 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005959
Johannes Berg9d38d852010-06-09 17:20:33 +02005960 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005961 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005962 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5963 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005965 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005966 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5967 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005968
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005969 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005970 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005971 return -EINVAL;
5972 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005973
5974 /*
5975 * We should wait on the channel for at least a minimum amount
5976 * of time (10ms) but no longer than the driver supports.
5977 */
5978 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5979 wait > rdev->wiphy.max_remain_on_channel_duration)
5980 return -EINVAL;
5981
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005982 }
5983
Jouni Malinen026331c2010-02-15 12:53:10 +02005984 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005985 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005986 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005987 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005988 }
5989
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005990 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5991
Johannes Berg7c4ef712011-11-18 15:33:48 +01005992 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5993 return -EINVAL;
5994
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305995 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5996
Jouni Malinen026331c2010-02-15 12:53:10 +02005997 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5998 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005999 if (chan == NULL)
6000 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006001
Johannes Berge247bd902011-11-04 11:18:21 +01006002 if (!dont_wait_for_ack) {
6003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6004 if (!msg)
6005 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006006
Johannes Berge247bd902011-11-04 11:18:21 +01006007 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6008 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006009
Johannes Berge247bd902011-11-04 11:18:21 +01006010 if (IS_ERR(hdr)) {
6011 err = PTR_ERR(hdr);
6012 goto free_msg;
6013 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006014 }
Johannes Berge247bd902011-11-04 11:18:21 +01006015
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006016 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
6017 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006018 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6019 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006020 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006021 if (err)
6022 goto free_msg;
6023
Johannes Berge247bd902011-11-04 11:18:21 +01006024 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006025 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6026 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006027
Johannes Berge247bd902011-11-04 11:18:21 +01006028 genlmsg_end(msg, hdr);
6029 return genlmsg_reply(msg, info);
6030 }
6031
6032 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006033
6034 nla_put_failure:
6035 err = -ENOBUFS;
6036 free_msg:
6037 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006038 return err;
6039}
6040
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006041static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6042{
6043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6044 struct net_device *dev = info->user_ptr[1];
6045 u64 cookie;
6046
6047 if (!info->attrs[NL80211_ATTR_COOKIE])
6048 return -EINVAL;
6049
6050 if (!rdev->ops->mgmt_tx_cancel_wait)
6051 return -EOPNOTSUPP;
6052
6053 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6054 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6055 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6056 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6057 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6058 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6059 return -EOPNOTSUPP;
6060
6061 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6062
6063 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6064}
6065
Kalle Valoffb9eb32010-02-17 17:58:10 +02006066static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6067{
Johannes Berg4c476992010-10-04 21:36:35 +02006068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006069 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006070 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006071 u8 ps_state;
6072 bool state;
6073 int err;
6074
Johannes Berg4c476992010-10-04 21:36:35 +02006075 if (!info->attrs[NL80211_ATTR_PS_STATE])
6076 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006077
6078 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6079
Johannes Berg4c476992010-10-04 21:36:35 +02006080 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6081 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006082
6083 wdev = dev->ieee80211_ptr;
6084
Johannes Berg4c476992010-10-04 21:36:35 +02006085 if (!rdev->ops->set_power_mgmt)
6086 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006087
6088 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6089
6090 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006091 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006092
Johannes Berg4c476992010-10-04 21:36:35 +02006093 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6094 wdev->ps_timeout);
6095 if (!err)
6096 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006097 return err;
6098}
6099
6100static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6101{
Johannes Berg4c476992010-10-04 21:36:35 +02006102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006103 enum nl80211_ps_state ps_state;
6104 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006105 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006106 struct sk_buff *msg;
6107 void *hdr;
6108 int err;
6109
Kalle Valoffb9eb32010-02-17 17:58:10 +02006110 wdev = dev->ieee80211_ptr;
6111
Johannes Berg4c476992010-10-04 21:36:35 +02006112 if (!rdev->ops->set_power_mgmt)
6113 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006114
6115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006116 if (!msg)
6117 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006118
6119 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6120 NL80211_CMD_GET_POWER_SAVE);
6121 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006122 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006123 goto free_msg;
6124 }
6125
6126 if (wdev->ps)
6127 ps_state = NL80211_PS_ENABLED;
6128 else
6129 ps_state = NL80211_PS_DISABLED;
6130
David S. Miller9360ffd2012-03-29 04:41:26 -04006131 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6132 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006133
6134 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006135 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006136
Johannes Berg4c476992010-10-04 21:36:35 +02006137 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006138 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006139 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006140 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006141 return err;
6142}
6143
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006144static struct nla_policy
6145nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6146 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6147 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6148 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6149};
6150
6151static int nl80211_set_cqm_rssi(struct genl_info *info,
6152 s32 threshold, u32 hysteresis)
6153{
Johannes Berg4c476992010-10-04 21:36:35 +02006154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006155 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006156 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006157
6158 if (threshold > 0)
6159 return -EINVAL;
6160
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006161 wdev = dev->ieee80211_ptr;
6162
Johannes Berg4c476992010-10-04 21:36:35 +02006163 if (!rdev->ops->set_cqm_rssi_config)
6164 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006165
Johannes Berg074ac8d2010-09-16 14:58:22 +02006166 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006167 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6168 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006169
Johannes Berg4c476992010-10-04 21:36:35 +02006170 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6171 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006172}
6173
6174static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6175{
6176 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6177 struct nlattr *cqm;
6178 int err;
6179
6180 cqm = info->attrs[NL80211_ATTR_CQM];
6181 if (!cqm) {
6182 err = -EINVAL;
6183 goto out;
6184 }
6185
6186 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6187 nl80211_attr_cqm_policy);
6188 if (err)
6189 goto out;
6190
6191 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6192 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6193 s32 threshold;
6194 u32 hysteresis;
6195 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6196 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6197 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6198 } else
6199 err = -EINVAL;
6200
6201out:
6202 return err;
6203}
6204
Johannes Berg29cbe682010-12-03 09:20:44 +01006205static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6206{
6207 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6208 struct net_device *dev = info->user_ptr[1];
6209 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006210 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006211 int err;
6212
6213 /* start with default */
6214 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006215 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006216
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006217 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006218 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006219 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006220 if (err)
6221 return err;
6222 }
6223
6224 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6225 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6226 return -EINVAL;
6227
Javier Cardonac80d5452010-12-16 17:37:49 -08006228 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6229 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6230
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006231 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6232 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6233 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6234 return -EINVAL;
6235
Javier Cardonac80d5452010-12-16 17:37:49 -08006236 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6237 /* parse additional setup parameters if given */
6238 err = nl80211_parse_mesh_setup(info, &setup);
6239 if (err)
6240 return err;
6241 }
6242
Johannes Bergcc1d2802012-05-16 23:50:20 +02006243 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6244 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6245
6246 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6247 !nl80211_valid_channel_type(info, &channel_type))
6248 return -EINVAL;
6249
6250 setup.channel = rdev_freq_to_chan(rdev,
6251 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6252 channel_type);
6253 if (!setup.channel)
6254 return -EINVAL;
6255 setup.channel_type = channel_type;
6256 } else {
6257 /* cfg80211_join_mesh() will sort it out */
6258 setup.channel = NULL;
6259 }
6260
Javier Cardonac80d5452010-12-16 17:37:49 -08006261 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006262}
6263
6264static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6265{
6266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6267 struct net_device *dev = info->user_ptr[1];
6268
6269 return cfg80211_leave_mesh(rdev, dev);
6270}
6271
Johannes Bergff1b6e62011-05-04 15:37:28 +02006272static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6273{
6274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6275 struct sk_buff *msg;
6276 void *hdr;
6277
6278 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6279 return -EOPNOTSUPP;
6280
6281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6282 if (!msg)
6283 return -ENOMEM;
6284
6285 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6286 NL80211_CMD_GET_WOWLAN);
6287 if (!hdr)
6288 goto nla_put_failure;
6289
6290 if (rdev->wowlan) {
6291 struct nlattr *nl_wowlan;
6292
6293 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6294 if (!nl_wowlan)
6295 goto nla_put_failure;
6296
David S. Miller9360ffd2012-03-29 04:41:26 -04006297 if ((rdev->wowlan->any &&
6298 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6299 (rdev->wowlan->disconnect &&
6300 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6301 (rdev->wowlan->magic_pkt &&
6302 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6303 (rdev->wowlan->gtk_rekey_failure &&
6304 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6305 (rdev->wowlan->eap_identity_req &&
6306 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6307 (rdev->wowlan->four_way_handshake &&
6308 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6309 (rdev->wowlan->rfkill_release &&
6310 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6311 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006312 if (rdev->wowlan->n_patterns) {
6313 struct nlattr *nl_pats, *nl_pat;
6314 int i, pat_len;
6315
6316 nl_pats = nla_nest_start(msg,
6317 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6318 if (!nl_pats)
6319 goto nla_put_failure;
6320
6321 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6322 nl_pat = nla_nest_start(msg, i + 1);
6323 if (!nl_pat)
6324 goto nla_put_failure;
6325 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006326 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6327 DIV_ROUND_UP(pat_len, 8),
6328 rdev->wowlan->patterns[i].mask) ||
6329 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6330 pat_len,
6331 rdev->wowlan->patterns[i].pattern))
6332 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006333 nla_nest_end(msg, nl_pat);
6334 }
6335 nla_nest_end(msg, nl_pats);
6336 }
6337
6338 nla_nest_end(msg, nl_wowlan);
6339 }
6340
6341 genlmsg_end(msg, hdr);
6342 return genlmsg_reply(msg, info);
6343
6344nla_put_failure:
6345 nlmsg_free(msg);
6346 return -ENOBUFS;
6347}
6348
6349static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6350{
6351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6352 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6353 struct cfg80211_wowlan no_triggers = {};
6354 struct cfg80211_wowlan new_triggers = {};
6355 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6356 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006357 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006358
6359 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6360 return -EOPNOTSUPP;
6361
6362 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6363 goto no_triggers;
6364
6365 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6366 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6367 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6368 nl80211_wowlan_policy);
6369 if (err)
6370 return err;
6371
6372 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6373 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6374 return -EINVAL;
6375 new_triggers.any = true;
6376 }
6377
6378 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6379 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6380 return -EINVAL;
6381 new_triggers.disconnect = true;
6382 }
6383
6384 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6385 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6386 return -EINVAL;
6387 new_triggers.magic_pkt = true;
6388 }
6389
Johannes Berg77dbbb12011-07-13 10:48:55 +02006390 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6391 return -EINVAL;
6392
6393 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6394 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6395 return -EINVAL;
6396 new_triggers.gtk_rekey_failure = true;
6397 }
6398
6399 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6400 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6401 return -EINVAL;
6402 new_triggers.eap_identity_req = true;
6403 }
6404
6405 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6406 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6407 return -EINVAL;
6408 new_triggers.four_way_handshake = true;
6409 }
6410
6411 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6412 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6413 return -EINVAL;
6414 new_triggers.rfkill_release = true;
6415 }
6416
Johannes Bergff1b6e62011-05-04 15:37:28 +02006417 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6418 struct nlattr *pat;
6419 int n_patterns = 0;
6420 int rem, pat_len, mask_len;
6421 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6422
6423 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6424 rem)
6425 n_patterns++;
6426 if (n_patterns > wowlan->n_patterns)
6427 return -EINVAL;
6428
6429 new_triggers.patterns = kcalloc(n_patterns,
6430 sizeof(new_triggers.patterns[0]),
6431 GFP_KERNEL);
6432 if (!new_triggers.patterns)
6433 return -ENOMEM;
6434
6435 new_triggers.n_patterns = n_patterns;
6436 i = 0;
6437
6438 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6439 rem) {
6440 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6441 nla_data(pat), nla_len(pat), NULL);
6442 err = -EINVAL;
6443 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6444 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6445 goto error;
6446 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6447 mask_len = DIV_ROUND_UP(pat_len, 8);
6448 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6449 mask_len)
6450 goto error;
6451 if (pat_len > wowlan->pattern_max_len ||
6452 pat_len < wowlan->pattern_min_len)
6453 goto error;
6454
6455 new_triggers.patterns[i].mask =
6456 kmalloc(mask_len + pat_len, GFP_KERNEL);
6457 if (!new_triggers.patterns[i].mask) {
6458 err = -ENOMEM;
6459 goto error;
6460 }
6461 new_triggers.patterns[i].pattern =
6462 new_triggers.patterns[i].mask + mask_len;
6463 memcpy(new_triggers.patterns[i].mask,
6464 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6465 mask_len);
6466 new_triggers.patterns[i].pattern_len = pat_len;
6467 memcpy(new_triggers.patterns[i].pattern,
6468 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6469 pat_len);
6470 i++;
6471 }
6472 }
6473
6474 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6475 struct cfg80211_wowlan *ntrig;
6476 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6477 GFP_KERNEL);
6478 if (!ntrig) {
6479 err = -ENOMEM;
6480 goto error;
6481 }
6482 cfg80211_rdev_free_wowlan(rdev);
6483 rdev->wowlan = ntrig;
6484 } else {
6485 no_triggers:
6486 cfg80211_rdev_free_wowlan(rdev);
6487 rdev->wowlan = NULL;
6488 }
6489
Johannes Berg6d525632012-04-04 15:05:25 +02006490 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6491 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6492
Johannes Bergff1b6e62011-05-04 15:37:28 +02006493 return 0;
6494 error:
6495 for (i = 0; i < new_triggers.n_patterns; i++)
6496 kfree(new_triggers.patterns[i].mask);
6497 kfree(new_triggers.patterns);
6498 return err;
6499}
6500
Johannes Berge5497d72011-07-05 16:35:40 +02006501static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6502{
6503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6504 struct net_device *dev = info->user_ptr[1];
6505 struct wireless_dev *wdev = dev->ieee80211_ptr;
6506 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6507 struct cfg80211_gtk_rekey_data rekey_data;
6508 int err;
6509
6510 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6511 return -EINVAL;
6512
6513 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6514 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6515 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6516 nl80211_rekey_policy);
6517 if (err)
6518 return err;
6519
6520 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6521 return -ERANGE;
6522 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6523 return -ERANGE;
6524 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6525 return -ERANGE;
6526
6527 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6528 NL80211_KEK_LEN);
6529 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6530 NL80211_KCK_LEN);
6531 memcpy(rekey_data.replay_ctr,
6532 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6533 NL80211_REPLAY_CTR_LEN);
6534
6535 wdev_lock(wdev);
6536 if (!wdev->current_bss) {
6537 err = -ENOTCONN;
6538 goto out;
6539 }
6540
6541 if (!rdev->ops->set_rekey_data) {
6542 err = -EOPNOTSUPP;
6543 goto out;
6544 }
6545
6546 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6547 out:
6548 wdev_unlock(wdev);
6549 return err;
6550}
6551
Johannes Berg28946da2011-11-04 11:18:12 +01006552static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6553 struct genl_info *info)
6554{
6555 struct net_device *dev = info->user_ptr[1];
6556 struct wireless_dev *wdev = dev->ieee80211_ptr;
6557
6558 if (wdev->iftype != NL80211_IFTYPE_AP &&
6559 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6560 return -EINVAL;
6561
6562 if (wdev->ap_unexpected_nlpid)
6563 return -EBUSY;
6564
6565 wdev->ap_unexpected_nlpid = info->snd_pid;
6566 return 0;
6567}
6568
Johannes Berg7f6cf312011-11-04 11:18:15 +01006569static int nl80211_probe_client(struct sk_buff *skb,
6570 struct genl_info *info)
6571{
6572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6573 struct net_device *dev = info->user_ptr[1];
6574 struct wireless_dev *wdev = dev->ieee80211_ptr;
6575 struct sk_buff *msg;
6576 void *hdr;
6577 const u8 *addr;
6578 u64 cookie;
6579 int err;
6580
6581 if (wdev->iftype != NL80211_IFTYPE_AP &&
6582 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6583 return -EOPNOTSUPP;
6584
6585 if (!info->attrs[NL80211_ATTR_MAC])
6586 return -EINVAL;
6587
6588 if (!rdev->ops->probe_client)
6589 return -EOPNOTSUPP;
6590
6591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6592 if (!msg)
6593 return -ENOMEM;
6594
6595 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6596 NL80211_CMD_PROBE_CLIENT);
6597
6598 if (IS_ERR(hdr)) {
6599 err = PTR_ERR(hdr);
6600 goto free_msg;
6601 }
6602
6603 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6604
6605 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6606 if (err)
6607 goto free_msg;
6608
David S. Miller9360ffd2012-03-29 04:41:26 -04006609 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6610 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006611
6612 genlmsg_end(msg, hdr);
6613
6614 return genlmsg_reply(msg, info);
6615
6616 nla_put_failure:
6617 err = -ENOBUFS;
6618 free_msg:
6619 nlmsg_free(msg);
6620 return err;
6621}
6622
Johannes Berg5e760232011-11-04 11:18:17 +01006623static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6624{
6625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6626
6627 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6628 return -EOPNOTSUPP;
6629
6630 if (rdev->ap_beacons_nlpid)
6631 return -EBUSY;
6632
6633 rdev->ap_beacons_nlpid = info->snd_pid;
6634
6635 return 0;
6636}
6637
Johannes Berg4c476992010-10-04 21:36:35 +02006638#define NL80211_FLAG_NEED_WIPHY 0x01
6639#define NL80211_FLAG_NEED_NETDEV 0x02
6640#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006641#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6642#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6643 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006644
6645static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6646 struct genl_info *info)
6647{
6648 struct cfg80211_registered_device *rdev;
6649 struct net_device *dev;
6650 int err;
6651 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6652
6653 if (rtnl)
6654 rtnl_lock();
6655
6656 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006657 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006658 if (IS_ERR(rdev)) {
6659 if (rtnl)
6660 rtnl_unlock();
6661 return PTR_ERR(rdev);
6662 }
6663 info->user_ptr[0] = rdev;
6664 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006665 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6666 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006667 if (err) {
6668 if (rtnl)
6669 rtnl_unlock();
6670 return err;
6671 }
Johannes Berg41265712010-10-04 21:14:05 +02006672 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6673 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006674 cfg80211_unlock_rdev(rdev);
6675 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006676 if (rtnl)
6677 rtnl_unlock();
6678 return -ENETDOWN;
6679 }
Johannes Berg4c476992010-10-04 21:36:35 +02006680 info->user_ptr[0] = rdev;
6681 info->user_ptr[1] = dev;
6682 }
6683
6684 return 0;
6685}
6686
6687static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6688 struct genl_info *info)
6689{
6690 if (info->user_ptr[0])
6691 cfg80211_unlock_rdev(info->user_ptr[0]);
6692 if (info->user_ptr[1])
6693 dev_put(info->user_ptr[1]);
6694 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6695 rtnl_unlock();
6696}
6697
Johannes Berg55682962007-09-20 13:09:35 -04006698static struct genl_ops nl80211_ops[] = {
6699 {
6700 .cmd = NL80211_CMD_GET_WIPHY,
6701 .doit = nl80211_get_wiphy,
6702 .dumpit = nl80211_dump_wiphy,
6703 .policy = nl80211_policy,
6704 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006705 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006706 },
6707 {
6708 .cmd = NL80211_CMD_SET_WIPHY,
6709 .doit = nl80211_set_wiphy,
6710 .policy = nl80211_policy,
6711 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006712 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006713 },
6714 {
6715 .cmd = NL80211_CMD_GET_INTERFACE,
6716 .doit = nl80211_get_interface,
6717 .dumpit = nl80211_dump_interface,
6718 .policy = nl80211_policy,
6719 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006720 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006721 },
6722 {
6723 .cmd = NL80211_CMD_SET_INTERFACE,
6724 .doit = nl80211_set_interface,
6725 .policy = nl80211_policy,
6726 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006727 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6728 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006729 },
6730 {
6731 .cmd = NL80211_CMD_NEW_INTERFACE,
6732 .doit = nl80211_new_interface,
6733 .policy = nl80211_policy,
6734 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006735 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6736 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006737 },
6738 {
6739 .cmd = NL80211_CMD_DEL_INTERFACE,
6740 .doit = nl80211_del_interface,
6741 .policy = nl80211_policy,
6742 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006743 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6744 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006745 },
Johannes Berg41ade002007-12-19 02:03:29 +01006746 {
6747 .cmd = NL80211_CMD_GET_KEY,
6748 .doit = nl80211_get_key,
6749 .policy = nl80211_policy,
6750 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006751 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006752 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006753 },
6754 {
6755 .cmd = NL80211_CMD_SET_KEY,
6756 .doit = nl80211_set_key,
6757 .policy = nl80211_policy,
6758 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006759 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006760 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006761 },
6762 {
6763 .cmd = NL80211_CMD_NEW_KEY,
6764 .doit = nl80211_new_key,
6765 .policy = nl80211_policy,
6766 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006768 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006769 },
6770 {
6771 .cmd = NL80211_CMD_DEL_KEY,
6772 .doit = nl80211_del_key,
6773 .policy = nl80211_policy,
6774 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006775 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006776 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006777 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006778 {
6779 .cmd = NL80211_CMD_SET_BEACON,
6780 .policy = nl80211_policy,
6781 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006782 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006783 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006784 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006785 },
6786 {
Johannes Berg88600202012-02-13 15:17:18 +01006787 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006788 .policy = nl80211_policy,
6789 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006790 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006791 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006792 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006793 },
6794 {
Johannes Berg88600202012-02-13 15:17:18 +01006795 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006796 .policy = nl80211_policy,
6797 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006798 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006799 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006800 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006801 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006802 {
6803 .cmd = NL80211_CMD_GET_STATION,
6804 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006805 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006806 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006807 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6808 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006809 },
6810 {
6811 .cmd = NL80211_CMD_SET_STATION,
6812 .doit = nl80211_set_station,
6813 .policy = nl80211_policy,
6814 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006815 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006816 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006817 },
6818 {
6819 .cmd = NL80211_CMD_NEW_STATION,
6820 .doit = nl80211_new_station,
6821 .policy = nl80211_policy,
6822 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006824 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006825 },
6826 {
6827 .cmd = NL80211_CMD_DEL_STATION,
6828 .doit = nl80211_del_station,
6829 .policy = nl80211_policy,
6830 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006831 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006832 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006833 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006834 {
6835 .cmd = NL80211_CMD_GET_MPATH,
6836 .doit = nl80211_get_mpath,
6837 .dumpit = nl80211_dump_mpath,
6838 .policy = nl80211_policy,
6839 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006840 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006841 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006842 },
6843 {
6844 .cmd = NL80211_CMD_SET_MPATH,
6845 .doit = nl80211_set_mpath,
6846 .policy = nl80211_policy,
6847 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006849 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006850 },
6851 {
6852 .cmd = NL80211_CMD_NEW_MPATH,
6853 .doit = nl80211_new_mpath,
6854 .policy = nl80211_policy,
6855 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006856 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006857 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006858 },
6859 {
6860 .cmd = NL80211_CMD_DEL_MPATH,
6861 .doit = nl80211_del_mpath,
6862 .policy = nl80211_policy,
6863 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006864 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006865 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006866 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006867 {
6868 .cmd = NL80211_CMD_SET_BSS,
6869 .doit = nl80211_set_bss,
6870 .policy = nl80211_policy,
6871 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006872 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006873 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006874 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006875 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006876 .cmd = NL80211_CMD_GET_REG,
6877 .doit = nl80211_get_reg,
6878 .policy = nl80211_policy,
6879 /* can be retrieved by unprivileged users */
6880 },
6881 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006882 .cmd = NL80211_CMD_SET_REG,
6883 .doit = nl80211_set_reg,
6884 .policy = nl80211_policy,
6885 .flags = GENL_ADMIN_PERM,
6886 },
6887 {
6888 .cmd = NL80211_CMD_REQ_SET_REG,
6889 .doit = nl80211_req_set_reg,
6890 .policy = nl80211_policy,
6891 .flags = GENL_ADMIN_PERM,
6892 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006893 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006894 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6895 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006896 .policy = nl80211_policy,
6897 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006898 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006899 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006900 },
6901 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006902 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6903 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006904 .policy = nl80211_policy,
6905 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006906 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006907 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006908 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006909 {
Johannes Berg2a519312009-02-10 21:25:55 +01006910 .cmd = NL80211_CMD_TRIGGER_SCAN,
6911 .doit = nl80211_trigger_scan,
6912 .policy = nl80211_policy,
6913 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006914 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006915 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006916 },
6917 {
6918 .cmd = NL80211_CMD_GET_SCAN,
6919 .policy = nl80211_policy,
6920 .dumpit = nl80211_dump_scan,
6921 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006922 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006923 .cmd = NL80211_CMD_START_SCHED_SCAN,
6924 .doit = nl80211_start_sched_scan,
6925 .policy = nl80211_policy,
6926 .flags = GENL_ADMIN_PERM,
6927 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6928 NL80211_FLAG_NEED_RTNL,
6929 },
6930 {
6931 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6932 .doit = nl80211_stop_sched_scan,
6933 .policy = nl80211_policy,
6934 .flags = GENL_ADMIN_PERM,
6935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6936 NL80211_FLAG_NEED_RTNL,
6937 },
6938 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006939 .cmd = NL80211_CMD_AUTHENTICATE,
6940 .doit = nl80211_authenticate,
6941 .policy = nl80211_policy,
6942 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006943 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006944 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006945 },
6946 {
6947 .cmd = NL80211_CMD_ASSOCIATE,
6948 .doit = nl80211_associate,
6949 .policy = nl80211_policy,
6950 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006951 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006952 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006953 },
6954 {
6955 .cmd = NL80211_CMD_DEAUTHENTICATE,
6956 .doit = nl80211_deauthenticate,
6957 .policy = nl80211_policy,
6958 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006960 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006961 },
6962 {
6963 .cmd = NL80211_CMD_DISASSOCIATE,
6964 .doit = nl80211_disassociate,
6965 .policy = nl80211_policy,
6966 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006968 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006969 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006970 {
6971 .cmd = NL80211_CMD_JOIN_IBSS,
6972 .doit = nl80211_join_ibss,
6973 .policy = nl80211_policy,
6974 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006976 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006977 },
6978 {
6979 .cmd = NL80211_CMD_LEAVE_IBSS,
6980 .doit = nl80211_leave_ibss,
6981 .policy = nl80211_policy,
6982 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006984 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006985 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006986#ifdef CONFIG_NL80211_TESTMODE
6987 {
6988 .cmd = NL80211_CMD_TESTMODE,
6989 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006990 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006991 .policy = nl80211_policy,
6992 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006993 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6994 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02006995 },
6996#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02006997 {
6998 .cmd = NL80211_CMD_CONNECT,
6999 .doit = nl80211_connect,
7000 .policy = nl80211_policy,
7001 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007003 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007004 },
7005 {
7006 .cmd = NL80211_CMD_DISCONNECT,
7007 .doit = nl80211_disconnect,
7008 .policy = nl80211_policy,
7009 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007010 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007011 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007012 },
Johannes Berg463d0182009-07-14 00:33:35 +02007013 {
7014 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7015 .doit = nl80211_wiphy_netns,
7016 .policy = nl80211_policy,
7017 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007018 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7019 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007020 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007021 {
7022 .cmd = NL80211_CMD_GET_SURVEY,
7023 .policy = nl80211_policy,
7024 .dumpit = nl80211_dump_survey,
7025 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007026 {
7027 .cmd = NL80211_CMD_SET_PMKSA,
7028 .doit = nl80211_setdel_pmksa,
7029 .policy = nl80211_policy,
7030 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007032 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007033 },
7034 {
7035 .cmd = NL80211_CMD_DEL_PMKSA,
7036 .doit = nl80211_setdel_pmksa,
7037 .policy = nl80211_policy,
7038 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007040 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007041 },
7042 {
7043 .cmd = NL80211_CMD_FLUSH_PMKSA,
7044 .doit = nl80211_flush_pmksa,
7045 .policy = nl80211_policy,
7046 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007048 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007049 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007050 {
7051 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7052 .doit = nl80211_remain_on_channel,
7053 .policy = nl80211_policy,
7054 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007056 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007057 },
7058 {
7059 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7060 .doit = nl80211_cancel_remain_on_channel,
7061 .policy = nl80211_policy,
7062 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007064 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007065 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007066 {
7067 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7068 .doit = nl80211_set_tx_bitrate_mask,
7069 .policy = nl80211_policy,
7070 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007071 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7072 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007073 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007074 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007075 .cmd = NL80211_CMD_REGISTER_FRAME,
7076 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007077 .policy = nl80211_policy,
7078 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007079 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7080 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007081 },
7082 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007083 .cmd = NL80211_CMD_FRAME,
7084 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007085 .policy = nl80211_policy,
7086 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007088 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007089 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007090 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007091 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7092 .doit = nl80211_tx_mgmt_cancel_wait,
7093 .policy = nl80211_policy,
7094 .flags = GENL_ADMIN_PERM,
7095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7096 NL80211_FLAG_NEED_RTNL,
7097 },
7098 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007099 .cmd = NL80211_CMD_SET_POWER_SAVE,
7100 .doit = nl80211_set_power_save,
7101 .policy = nl80211_policy,
7102 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007103 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7104 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007105 },
7106 {
7107 .cmd = NL80211_CMD_GET_POWER_SAVE,
7108 .doit = nl80211_get_power_save,
7109 .policy = nl80211_policy,
7110 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007111 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7112 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007113 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007114 {
7115 .cmd = NL80211_CMD_SET_CQM,
7116 .doit = nl80211_set_cqm,
7117 .policy = nl80211_policy,
7118 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007119 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7120 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007121 },
Johannes Bergf444de02010-05-05 15:25:02 +02007122 {
7123 .cmd = NL80211_CMD_SET_CHANNEL,
7124 .doit = nl80211_set_channel,
7125 .policy = nl80211_policy,
7126 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007127 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7128 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007129 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007130 {
7131 .cmd = NL80211_CMD_SET_WDS_PEER,
7132 .doit = nl80211_set_wds_peer,
7133 .policy = nl80211_policy,
7134 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007135 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7136 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007137 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007138 {
7139 .cmd = NL80211_CMD_JOIN_MESH,
7140 .doit = nl80211_join_mesh,
7141 .policy = nl80211_policy,
7142 .flags = GENL_ADMIN_PERM,
7143 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7144 NL80211_FLAG_NEED_RTNL,
7145 },
7146 {
7147 .cmd = NL80211_CMD_LEAVE_MESH,
7148 .doit = nl80211_leave_mesh,
7149 .policy = nl80211_policy,
7150 .flags = GENL_ADMIN_PERM,
7151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7152 NL80211_FLAG_NEED_RTNL,
7153 },
Johannes Bergff1b6e62011-05-04 15:37:28 +02007154 {
7155 .cmd = NL80211_CMD_GET_WOWLAN,
7156 .doit = nl80211_get_wowlan,
7157 .policy = nl80211_policy,
7158 /* can be retrieved by unprivileged users */
7159 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7160 NL80211_FLAG_NEED_RTNL,
7161 },
7162 {
7163 .cmd = NL80211_CMD_SET_WOWLAN,
7164 .doit = nl80211_set_wowlan,
7165 .policy = nl80211_policy,
7166 .flags = GENL_ADMIN_PERM,
7167 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7168 NL80211_FLAG_NEED_RTNL,
7169 },
Johannes Berge5497d72011-07-05 16:35:40 +02007170 {
7171 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7172 .doit = nl80211_set_rekey_data,
7173 .policy = nl80211_policy,
7174 .flags = GENL_ADMIN_PERM,
7175 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7176 NL80211_FLAG_NEED_RTNL,
7177 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007178 {
7179 .cmd = NL80211_CMD_TDLS_MGMT,
7180 .doit = nl80211_tdls_mgmt,
7181 .policy = nl80211_policy,
7182 .flags = GENL_ADMIN_PERM,
7183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7184 NL80211_FLAG_NEED_RTNL,
7185 },
7186 {
7187 .cmd = NL80211_CMD_TDLS_OPER,
7188 .doit = nl80211_tdls_oper,
7189 .policy = nl80211_policy,
7190 .flags = GENL_ADMIN_PERM,
7191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7192 NL80211_FLAG_NEED_RTNL,
7193 },
Johannes Berg28946da2011-11-04 11:18:12 +01007194 {
7195 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7196 .doit = nl80211_register_unexpected_frame,
7197 .policy = nl80211_policy,
7198 .flags = GENL_ADMIN_PERM,
7199 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7200 NL80211_FLAG_NEED_RTNL,
7201 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007202 {
7203 .cmd = NL80211_CMD_PROBE_CLIENT,
7204 .doit = nl80211_probe_client,
7205 .policy = nl80211_policy,
7206 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007207 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007208 NL80211_FLAG_NEED_RTNL,
7209 },
Johannes Berg5e760232011-11-04 11:18:17 +01007210 {
7211 .cmd = NL80211_CMD_REGISTER_BEACONS,
7212 .doit = nl80211_register_beacons,
7213 .policy = nl80211_policy,
7214 .flags = GENL_ADMIN_PERM,
7215 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7216 NL80211_FLAG_NEED_RTNL,
7217 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007218 {
7219 .cmd = NL80211_CMD_SET_NOACK_MAP,
7220 .doit = nl80211_set_noack_map,
7221 .policy = nl80211_policy,
7222 .flags = GENL_ADMIN_PERM,
7223 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7224 NL80211_FLAG_NEED_RTNL,
7225 },
7226
Johannes Berg55682962007-09-20 13:09:35 -04007227};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007228
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007229static struct genl_multicast_group nl80211_mlme_mcgrp = {
7230 .name = "mlme",
7231};
Johannes Berg55682962007-09-20 13:09:35 -04007232
7233/* multicast groups */
7234static struct genl_multicast_group nl80211_config_mcgrp = {
7235 .name = "config",
7236};
Johannes Berg2a519312009-02-10 21:25:55 +01007237static struct genl_multicast_group nl80211_scan_mcgrp = {
7238 .name = "scan",
7239};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007240static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7241 .name = "regulatory",
7242};
Johannes Berg55682962007-09-20 13:09:35 -04007243
7244/* notification functions */
7245
7246void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7247{
7248 struct sk_buff *msg;
7249
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007251 if (!msg)
7252 return;
7253
7254 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7255 nlmsg_free(msg);
7256 return;
7257 }
7258
Johannes Berg463d0182009-07-14 00:33:35 +02007259 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7260 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007261}
7262
Johannes Berg362a4152009-05-24 16:43:15 +02007263static int nl80211_add_scan_req(struct sk_buff *msg,
7264 struct cfg80211_registered_device *rdev)
7265{
7266 struct cfg80211_scan_request *req = rdev->scan_req;
7267 struct nlattr *nest;
7268 int i;
7269
Johannes Berg667503dd2009-07-07 03:56:11 +02007270 ASSERT_RDEV_LOCK(rdev);
7271
Johannes Berg362a4152009-05-24 16:43:15 +02007272 if (WARN_ON(!req))
7273 return 0;
7274
7275 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7276 if (!nest)
7277 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007278 for (i = 0; i < req->n_ssids; i++) {
7279 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7280 goto nla_put_failure;
7281 }
Johannes Berg362a4152009-05-24 16:43:15 +02007282 nla_nest_end(msg, nest);
7283
7284 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7285 if (!nest)
7286 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007287 for (i = 0; i < req->n_channels; i++) {
7288 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7289 goto nla_put_failure;
7290 }
Johannes Berg362a4152009-05-24 16:43:15 +02007291 nla_nest_end(msg, nest);
7292
David S. Miller9360ffd2012-03-29 04:41:26 -04007293 if (req->ie &&
7294 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7295 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007296
7297 return 0;
7298 nla_put_failure:
7299 return -ENOBUFS;
7300}
7301
Johannes Berga538e2d2009-06-16 19:56:42 +02007302static int nl80211_send_scan_msg(struct sk_buff *msg,
7303 struct cfg80211_registered_device *rdev,
7304 struct net_device *netdev,
7305 u32 pid, u32 seq, int flags,
7306 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007307{
7308 void *hdr;
7309
7310 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7311 if (!hdr)
7312 return -1;
7313
David S. Miller9360ffd2012-03-29 04:41:26 -04007314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7316 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007317
Johannes Berg362a4152009-05-24 16:43:15 +02007318 /* ignore errors and send incomplete event anyway */
7319 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007320
7321 return genlmsg_end(msg, hdr);
7322
7323 nla_put_failure:
7324 genlmsg_cancel(msg, hdr);
7325 return -EMSGSIZE;
7326}
7327
Luciano Coelho807f8a82011-05-11 17:09:35 +03007328static int
7329nl80211_send_sched_scan_msg(struct sk_buff *msg,
7330 struct cfg80211_registered_device *rdev,
7331 struct net_device *netdev,
7332 u32 pid, u32 seq, int flags, u32 cmd)
7333{
7334 void *hdr;
7335
7336 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7337 if (!hdr)
7338 return -1;
7339
David S. Miller9360ffd2012-03-29 04:41:26 -04007340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7341 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7342 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007343
7344 return genlmsg_end(msg, hdr);
7345
7346 nla_put_failure:
7347 genlmsg_cancel(msg, hdr);
7348 return -EMSGSIZE;
7349}
7350
Johannes Berga538e2d2009-06-16 19:56:42 +02007351void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7352 struct net_device *netdev)
7353{
7354 struct sk_buff *msg;
7355
7356 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7357 if (!msg)
7358 return;
7359
7360 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7361 NL80211_CMD_TRIGGER_SCAN) < 0) {
7362 nlmsg_free(msg);
7363 return;
7364 }
7365
Johannes Berg463d0182009-07-14 00:33:35 +02007366 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7367 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007368}
7369
Johannes Berg2a519312009-02-10 21:25:55 +01007370void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7371 struct net_device *netdev)
7372{
7373 struct sk_buff *msg;
7374
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007375 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007376 if (!msg)
7377 return;
7378
Johannes Berga538e2d2009-06-16 19:56:42 +02007379 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7380 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007381 nlmsg_free(msg);
7382 return;
7383 }
7384
Johannes Berg463d0182009-07-14 00:33:35 +02007385 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7386 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007387}
7388
7389void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7390 struct net_device *netdev)
7391{
7392 struct sk_buff *msg;
7393
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007395 if (!msg)
7396 return;
7397
Johannes Berga538e2d2009-06-16 19:56:42 +02007398 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7399 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007400 nlmsg_free(msg);
7401 return;
7402 }
7403
Johannes Berg463d0182009-07-14 00:33:35 +02007404 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7405 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007406}
7407
Luciano Coelho807f8a82011-05-11 17:09:35 +03007408void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7409 struct net_device *netdev)
7410{
7411 struct sk_buff *msg;
7412
7413 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7414 if (!msg)
7415 return;
7416
7417 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7418 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7419 nlmsg_free(msg);
7420 return;
7421 }
7422
7423 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7424 nl80211_scan_mcgrp.id, GFP_KERNEL);
7425}
7426
7427void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7428 struct net_device *netdev, u32 cmd)
7429{
7430 struct sk_buff *msg;
7431
7432 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7433 if (!msg)
7434 return;
7435
7436 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7437 nlmsg_free(msg);
7438 return;
7439 }
7440
7441 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7442 nl80211_scan_mcgrp.id, GFP_KERNEL);
7443}
7444
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007445/*
7446 * This can happen on global regulatory changes or device specific settings
7447 * based on custom world regulatory domains.
7448 */
7449void nl80211_send_reg_change_event(struct regulatory_request *request)
7450{
7451 struct sk_buff *msg;
7452 void *hdr;
7453
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007454 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007455 if (!msg)
7456 return;
7457
7458 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7459 if (!hdr) {
7460 nlmsg_free(msg);
7461 return;
7462 }
7463
7464 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007465 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7466 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007467
David S. Miller9360ffd2012-03-29 04:41:26 -04007468 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7469 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7470 NL80211_REGDOM_TYPE_WORLD))
7471 goto nla_put_failure;
7472 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7473 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7474 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7475 goto nla_put_failure;
7476 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7477 request->intersect) {
7478 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7479 NL80211_REGDOM_TYPE_INTERSECTION))
7480 goto nla_put_failure;
7481 } else {
7482 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7483 NL80211_REGDOM_TYPE_COUNTRY) ||
7484 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7485 request->alpha2))
7486 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007487 }
7488
David S. Miller9360ffd2012-03-29 04:41:26 -04007489 if (wiphy_idx_valid(request->wiphy_idx) &&
7490 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7491 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007492
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007493 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007494
Johannes Bergbc43b282009-07-25 10:54:13 +02007495 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007496 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007497 GFP_ATOMIC);
7498 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007499
7500 return;
7501
7502nla_put_failure:
7503 genlmsg_cancel(msg, hdr);
7504 nlmsg_free(msg);
7505}
7506
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007507static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7508 struct net_device *netdev,
7509 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007510 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007511{
7512 struct sk_buff *msg;
7513 void *hdr;
7514
Johannes Berge6d6e342009-07-01 21:26:47 +02007515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007516 if (!msg)
7517 return;
7518
7519 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7520 if (!hdr) {
7521 nlmsg_free(msg);
7522 return;
7523 }
7524
David S. Miller9360ffd2012-03-29 04:41:26 -04007525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7526 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7527 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7528 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007529
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007530 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007531
Johannes Berg463d0182009-07-14 00:33:35 +02007532 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7533 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007534 return;
7535
7536 nla_put_failure:
7537 genlmsg_cancel(msg, hdr);
7538 nlmsg_free(msg);
7539}
7540
7541void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007542 struct net_device *netdev, const u8 *buf,
7543 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007544{
7545 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007546 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007547}
7548
7549void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7550 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007551 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007552{
Johannes Berge6d6e342009-07-01 21:26:47 +02007553 nl80211_send_mlme_event(rdev, netdev, buf, len,
7554 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007555}
7556
Jouni Malinen53b46b82009-03-27 20:53:56 +02007557void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007558 struct net_device *netdev, const u8 *buf,
7559 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007560{
7561 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007562 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007563}
7564
Jouni Malinen53b46b82009-03-27 20:53:56 +02007565void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7566 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007567 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007568{
7569 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007570 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007571}
7572
Jouni Malinencf4e5942010-12-16 00:52:40 +02007573void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7574 struct net_device *netdev, const u8 *buf,
7575 size_t len, gfp_t gfp)
7576{
7577 nl80211_send_mlme_event(rdev, netdev, buf, len,
7578 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7579}
7580
7581void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7582 struct net_device *netdev, const u8 *buf,
7583 size_t len, gfp_t gfp)
7584{
7585 nl80211_send_mlme_event(rdev, netdev, buf, len,
7586 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7587}
7588
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007589static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7590 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007591 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007592{
7593 struct sk_buff *msg;
7594 void *hdr;
7595
Johannes Berge6d6e342009-07-01 21:26:47 +02007596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007597 if (!msg)
7598 return;
7599
7600 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7601 if (!hdr) {
7602 nlmsg_free(msg);
7603 return;
7604 }
7605
David S. Miller9360ffd2012-03-29 04:41:26 -04007606 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7607 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7608 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7609 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7610 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007611
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007612 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007613
Johannes Berg463d0182009-07-14 00:33:35 +02007614 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7615 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007616 return;
7617
7618 nla_put_failure:
7619 genlmsg_cancel(msg, hdr);
7620 nlmsg_free(msg);
7621}
7622
7623void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007624 struct net_device *netdev, const u8 *addr,
7625 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007626{
7627 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007628 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007629}
7630
7631void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007632 struct net_device *netdev, const u8 *addr,
7633 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007634{
Johannes Berge6d6e342009-07-01 21:26:47 +02007635 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7636 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007637}
7638
Samuel Ortizb23aa672009-07-01 21:26:54 +02007639void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7640 struct net_device *netdev, const u8 *bssid,
7641 const u8 *req_ie, size_t req_ie_len,
7642 const u8 *resp_ie, size_t resp_ie_len,
7643 u16 status, gfp_t gfp)
7644{
7645 struct sk_buff *msg;
7646 void *hdr;
7647
7648 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7649 if (!msg)
7650 return;
7651
7652 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7653 if (!hdr) {
7654 nlmsg_free(msg);
7655 return;
7656 }
7657
David S. Miller9360ffd2012-03-29 04:41:26 -04007658 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7659 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7660 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7661 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7662 (req_ie &&
7663 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7664 (resp_ie &&
7665 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7666 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007667
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007668 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007669
Johannes Berg463d0182009-07-14 00:33:35 +02007670 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7671 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007672 return;
7673
7674 nla_put_failure:
7675 genlmsg_cancel(msg, hdr);
7676 nlmsg_free(msg);
7677
7678}
7679
7680void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7681 struct net_device *netdev, const u8 *bssid,
7682 const u8 *req_ie, size_t req_ie_len,
7683 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7684{
7685 struct sk_buff *msg;
7686 void *hdr;
7687
7688 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7689 if (!msg)
7690 return;
7691
7692 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7693 if (!hdr) {
7694 nlmsg_free(msg);
7695 return;
7696 }
7697
David S. Miller9360ffd2012-03-29 04:41:26 -04007698 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7699 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7700 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7701 (req_ie &&
7702 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7703 (resp_ie &&
7704 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7705 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007706
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007707 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007708
Johannes Berg463d0182009-07-14 00:33:35 +02007709 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7710 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007711 return;
7712
7713 nla_put_failure:
7714 genlmsg_cancel(msg, hdr);
7715 nlmsg_free(msg);
7716
7717}
7718
7719void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7720 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007721 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007722{
7723 struct sk_buff *msg;
7724 void *hdr;
7725
Johannes Berg667503dd2009-07-07 03:56:11 +02007726 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007727 if (!msg)
7728 return;
7729
7730 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7731 if (!hdr) {
7732 nlmsg_free(msg);
7733 return;
7734 }
7735
David S. Miller9360ffd2012-03-29 04:41:26 -04007736 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7737 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7738 (from_ap && reason &&
7739 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7740 (from_ap &&
7741 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7742 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7743 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007744
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007745 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007746
Johannes Berg463d0182009-07-14 00:33:35 +02007747 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7748 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007749 return;
7750
7751 nla_put_failure:
7752 genlmsg_cancel(msg, hdr);
7753 nlmsg_free(msg);
7754
7755}
7756
Johannes Berg04a773a2009-04-19 21:24:32 +02007757void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7758 struct net_device *netdev, const u8 *bssid,
7759 gfp_t gfp)
7760{
7761 struct sk_buff *msg;
7762 void *hdr;
7763
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007765 if (!msg)
7766 return;
7767
7768 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7769 if (!hdr) {
7770 nlmsg_free(msg);
7771 return;
7772 }
7773
David S. Miller9360ffd2012-03-29 04:41:26 -04007774 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7775 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7776 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7777 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007778
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007779 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007780
Johannes Berg463d0182009-07-14 00:33:35 +02007781 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7782 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007783 return;
7784
7785 nla_put_failure:
7786 genlmsg_cancel(msg, hdr);
7787 nlmsg_free(msg);
7788}
7789
Javier Cardonac93b5e72011-04-07 15:08:34 -07007790void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7791 struct net_device *netdev,
7792 const u8 *macaddr, const u8* ie, u8 ie_len,
7793 gfp_t gfp)
7794{
7795 struct sk_buff *msg;
7796 void *hdr;
7797
7798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7799 if (!msg)
7800 return;
7801
7802 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7803 if (!hdr) {
7804 nlmsg_free(msg);
7805 return;
7806 }
7807
David S. Miller9360ffd2012-03-29 04:41:26 -04007808 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7809 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7810 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7811 (ie_len && ie &&
7812 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7813 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007814
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007815 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007816
7817 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7818 nl80211_mlme_mcgrp.id, gfp);
7819 return;
7820
7821 nla_put_failure:
7822 genlmsg_cancel(msg, hdr);
7823 nlmsg_free(msg);
7824}
7825
Jouni Malinena3b8b052009-03-27 21:59:49 +02007826void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7827 struct net_device *netdev, const u8 *addr,
7828 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007829 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007830{
7831 struct sk_buff *msg;
7832 void *hdr;
7833
Johannes Berge6d6e342009-07-01 21:26:47 +02007834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007835 if (!msg)
7836 return;
7837
7838 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7839 if (!hdr) {
7840 nlmsg_free(msg);
7841 return;
7842 }
7843
David S. Miller9360ffd2012-03-29 04:41:26 -04007844 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7845 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7846 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7847 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7848 (key_id != -1 &&
7849 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7850 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7851 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007852
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007853 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007854
Johannes Berg463d0182009-07-14 00:33:35 +02007855 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7856 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007857 return;
7858
7859 nla_put_failure:
7860 genlmsg_cancel(msg, hdr);
7861 nlmsg_free(msg);
7862}
7863
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007864void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7865 struct ieee80211_channel *channel_before,
7866 struct ieee80211_channel *channel_after)
7867{
7868 struct sk_buff *msg;
7869 void *hdr;
7870 struct nlattr *nl_freq;
7871
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007872 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007873 if (!msg)
7874 return;
7875
7876 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7877 if (!hdr) {
7878 nlmsg_free(msg);
7879 return;
7880 }
7881
7882 /*
7883 * Since we are applying the beacon hint to a wiphy we know its
7884 * wiphy_idx is valid
7885 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7887 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007888
7889 /* Before */
7890 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7891 if (!nl_freq)
7892 goto nla_put_failure;
7893 if (nl80211_msg_put_channel(msg, channel_before))
7894 goto nla_put_failure;
7895 nla_nest_end(msg, nl_freq);
7896
7897 /* After */
7898 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7899 if (!nl_freq)
7900 goto nla_put_failure;
7901 if (nl80211_msg_put_channel(msg, channel_after))
7902 goto nla_put_failure;
7903 nla_nest_end(msg, nl_freq);
7904
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007905 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007906
Johannes Berg463d0182009-07-14 00:33:35 +02007907 rcu_read_lock();
7908 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7909 GFP_ATOMIC);
7910 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007911
7912 return;
7913
7914nla_put_failure:
7915 genlmsg_cancel(msg, hdr);
7916 nlmsg_free(msg);
7917}
7918
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007919static void nl80211_send_remain_on_chan_event(
7920 int cmd, struct cfg80211_registered_device *rdev,
7921 struct net_device *netdev, u64 cookie,
7922 struct ieee80211_channel *chan,
7923 enum nl80211_channel_type channel_type,
7924 unsigned int duration, gfp_t gfp)
7925{
7926 struct sk_buff *msg;
7927 void *hdr;
7928
7929 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7930 if (!msg)
7931 return;
7932
7933 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7934 if (!hdr) {
7935 nlmsg_free(msg);
7936 return;
7937 }
7938
David S. Miller9360ffd2012-03-29 04:41:26 -04007939 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7940 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7941 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7942 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7943 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7944 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007945
David S. Miller9360ffd2012-03-29 04:41:26 -04007946 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7947 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7948 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007949
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007950 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007951
7952 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7953 nl80211_mlme_mcgrp.id, gfp);
7954 return;
7955
7956 nla_put_failure:
7957 genlmsg_cancel(msg, hdr);
7958 nlmsg_free(msg);
7959}
7960
7961void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7962 struct net_device *netdev, u64 cookie,
7963 struct ieee80211_channel *chan,
7964 enum nl80211_channel_type channel_type,
7965 unsigned int duration, gfp_t gfp)
7966{
7967 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7968 rdev, netdev, cookie, chan,
7969 channel_type, duration, gfp);
7970}
7971
7972void nl80211_send_remain_on_channel_cancel(
7973 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7974 u64 cookie, struct ieee80211_channel *chan,
7975 enum nl80211_channel_type channel_type, gfp_t gfp)
7976{
7977 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7978 rdev, netdev, cookie, chan,
7979 channel_type, 0, gfp);
7980}
7981
Johannes Berg98b62182009-12-23 13:15:44 +01007982void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7983 struct net_device *dev, const u8 *mac_addr,
7984 struct station_info *sinfo, gfp_t gfp)
7985{
7986 struct sk_buff *msg;
7987
7988 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7989 if (!msg)
7990 return;
7991
John W. Linville66266b32012-03-15 13:25:41 -04007992 if (nl80211_send_station(msg, 0, 0, 0,
7993 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01007994 nlmsg_free(msg);
7995 return;
7996 }
7997
7998 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7999 nl80211_mlme_mcgrp.id, gfp);
8000}
8001
Jouni Malinenec15e682011-03-23 15:29:52 +02008002void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8003 struct net_device *dev, const u8 *mac_addr,
8004 gfp_t gfp)
8005{
8006 struct sk_buff *msg;
8007 void *hdr;
8008
8009 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8010 if (!msg)
8011 return;
8012
8013 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8014 if (!hdr) {
8015 nlmsg_free(msg);
8016 return;
8017 }
8018
David S. Miller9360ffd2012-03-29 04:41:26 -04008019 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8020 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8021 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008022
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008023 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008024
8025 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8026 nl80211_mlme_mcgrp.id, gfp);
8027 return;
8028
8029 nla_put_failure:
8030 genlmsg_cancel(msg, hdr);
8031 nlmsg_free(msg);
8032}
8033
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008034static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8035 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008036{
8037 struct wireless_dev *wdev = dev->ieee80211_ptr;
8038 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8039 struct sk_buff *msg;
8040 void *hdr;
8041 int err;
8042 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8043
8044 if (!nlpid)
8045 return false;
8046
8047 msg = nlmsg_new(100, gfp);
8048 if (!msg)
8049 return true;
8050
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008051 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008052 if (!hdr) {
8053 nlmsg_free(msg);
8054 return true;
8055 }
8056
David S. Miller9360ffd2012-03-29 04:41:26 -04008057 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8058 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8059 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8060 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008061
8062 err = genlmsg_end(msg, hdr);
8063 if (err < 0) {
8064 nlmsg_free(msg);
8065 return true;
8066 }
8067
8068 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8069 return true;
8070
8071 nla_put_failure:
8072 genlmsg_cancel(msg, hdr);
8073 nlmsg_free(msg);
8074 return true;
8075}
8076
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008077bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8078{
8079 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8080 addr, gfp);
8081}
8082
8083bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8084 const u8 *addr, gfp_t gfp)
8085{
8086 return __nl80211_unexpected_frame(dev,
8087 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8088 addr, gfp);
8089}
8090
Johannes Berg2e161f72010-08-12 15:38:38 +02008091int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8092 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008093 int freq, int sig_dbm,
8094 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008095{
8096 struct sk_buff *msg;
8097 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008098
8099 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8100 if (!msg)
8101 return -ENOMEM;
8102
Johannes Berg2e161f72010-08-12 15:38:38 +02008103 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008104 if (!hdr) {
8105 nlmsg_free(msg);
8106 return -ENOMEM;
8107 }
8108
David S. Miller9360ffd2012-03-29 04:41:26 -04008109 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8110 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8111 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8112 (sig_dbm &&
8113 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8114 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8115 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008116
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008117 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008118
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008119 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008120
8121 nla_put_failure:
8122 genlmsg_cancel(msg, hdr);
8123 nlmsg_free(msg);
8124 return -ENOBUFS;
8125}
8126
Johannes Berg2e161f72010-08-12 15:38:38 +02008127void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8128 struct net_device *netdev, u64 cookie,
8129 const u8 *buf, size_t len, bool ack,
8130 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008131{
8132 struct sk_buff *msg;
8133 void *hdr;
8134
8135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8136 if (!msg)
8137 return;
8138
Johannes Berg2e161f72010-08-12 15:38:38 +02008139 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008140 if (!hdr) {
8141 nlmsg_free(msg);
8142 return;
8143 }
8144
David S. Miller9360ffd2012-03-29 04:41:26 -04008145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8146 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8147 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8148 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8149 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8150 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008151
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008152 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008153
8154 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8155 return;
8156
8157 nla_put_failure:
8158 genlmsg_cancel(msg, hdr);
8159 nlmsg_free(msg);
8160}
8161
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008162void
8163nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8164 struct net_device *netdev,
8165 enum nl80211_cqm_rssi_threshold_event rssi_event,
8166 gfp_t gfp)
8167{
8168 struct sk_buff *msg;
8169 struct nlattr *pinfoattr;
8170 void *hdr;
8171
8172 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8173 if (!msg)
8174 return;
8175
8176 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8177 if (!hdr) {
8178 nlmsg_free(msg);
8179 return;
8180 }
8181
David S. Miller9360ffd2012-03-29 04:41:26 -04008182 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8183 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8184 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008185
8186 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8187 if (!pinfoattr)
8188 goto nla_put_failure;
8189
David S. Miller9360ffd2012-03-29 04:41:26 -04008190 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8191 rssi_event))
8192 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008193
8194 nla_nest_end(msg, pinfoattr);
8195
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008196 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008197
8198 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8199 nl80211_mlme_mcgrp.id, gfp);
8200 return;
8201
8202 nla_put_failure:
8203 genlmsg_cancel(msg, hdr);
8204 nlmsg_free(msg);
8205}
8206
Johannes Berge5497d72011-07-05 16:35:40 +02008207void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8208 struct net_device *netdev, const u8 *bssid,
8209 const u8 *replay_ctr, gfp_t gfp)
8210{
8211 struct sk_buff *msg;
8212 struct nlattr *rekey_attr;
8213 void *hdr;
8214
8215 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8216 if (!msg)
8217 return;
8218
8219 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8220 if (!hdr) {
8221 nlmsg_free(msg);
8222 return;
8223 }
8224
David S. Miller9360ffd2012-03-29 04:41:26 -04008225 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8226 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8227 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8228 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008229
8230 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8231 if (!rekey_attr)
8232 goto nla_put_failure;
8233
David S. Miller9360ffd2012-03-29 04:41:26 -04008234 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8235 NL80211_REPLAY_CTR_LEN, replay_ctr))
8236 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008237
8238 nla_nest_end(msg, rekey_attr);
8239
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008240 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008241
8242 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8243 nl80211_mlme_mcgrp.id, gfp);
8244 return;
8245
8246 nla_put_failure:
8247 genlmsg_cancel(msg, hdr);
8248 nlmsg_free(msg);
8249}
8250
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008251void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8252 struct net_device *netdev, int index,
8253 const u8 *bssid, bool preauth, gfp_t gfp)
8254{
8255 struct sk_buff *msg;
8256 struct nlattr *attr;
8257 void *hdr;
8258
8259 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8260 if (!msg)
8261 return;
8262
8263 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8264 if (!hdr) {
8265 nlmsg_free(msg);
8266 return;
8267 }
8268
David S. Miller9360ffd2012-03-29 04:41:26 -04008269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8270 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8271 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008272
8273 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8274 if (!attr)
8275 goto nla_put_failure;
8276
David S. Miller9360ffd2012-03-29 04:41:26 -04008277 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8278 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8279 (preauth &&
8280 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8281 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008282
8283 nla_nest_end(msg, attr);
8284
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008285 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008286
8287 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8288 nl80211_mlme_mcgrp.id, gfp);
8289 return;
8290
8291 nla_put_failure:
8292 genlmsg_cancel(msg, hdr);
8293 nlmsg_free(msg);
8294}
8295
Thomas Pedersen53145262012-04-06 13:35:47 -07008296void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8297 struct net_device *netdev, int freq,
8298 enum nl80211_channel_type type, gfp_t gfp)
8299{
8300 struct sk_buff *msg;
8301 void *hdr;
8302
8303 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8304 if (!msg)
8305 return;
8306
8307 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8308 if (!hdr) {
8309 nlmsg_free(msg);
8310 return;
8311 }
8312
John W. Linville7eab0f62012-04-12 14:25:14 -04008313 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8314 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8315 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8316 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008317
8318 genlmsg_end(msg, hdr);
8319
8320 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8321 nl80211_mlme_mcgrp.id, gfp);
8322 return;
8323
8324 nla_put_failure:
8325 genlmsg_cancel(msg, hdr);
8326 nlmsg_free(msg);
8327}
8328
Johannes Bergc063dbf2010-11-24 08:10:05 +01008329void
8330nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8331 struct net_device *netdev, const u8 *peer,
8332 u32 num_packets, gfp_t gfp)
8333{
8334 struct sk_buff *msg;
8335 struct nlattr *pinfoattr;
8336 void *hdr;
8337
8338 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8339 if (!msg)
8340 return;
8341
8342 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8343 if (!hdr) {
8344 nlmsg_free(msg);
8345 return;
8346 }
8347
David S. Miller9360ffd2012-03-29 04:41:26 -04008348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8349 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8350 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8351 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008352
8353 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8354 if (!pinfoattr)
8355 goto nla_put_failure;
8356
David S. Miller9360ffd2012-03-29 04:41:26 -04008357 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8358 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008359
8360 nla_nest_end(msg, pinfoattr);
8361
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008362 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008363
8364 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8365 nl80211_mlme_mcgrp.id, gfp);
8366 return;
8367
8368 nla_put_failure:
8369 genlmsg_cancel(msg, hdr);
8370 nlmsg_free(msg);
8371}
8372
Johannes Berg7f6cf312011-11-04 11:18:15 +01008373void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8374 u64 cookie, bool acked, gfp_t gfp)
8375{
8376 struct wireless_dev *wdev = dev->ieee80211_ptr;
8377 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8378 struct sk_buff *msg;
8379 void *hdr;
8380 int err;
8381
8382 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8383 if (!msg)
8384 return;
8385
8386 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8387 if (!hdr) {
8388 nlmsg_free(msg);
8389 return;
8390 }
8391
David S. Miller9360ffd2012-03-29 04:41:26 -04008392 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8393 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8394 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8395 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8396 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8397 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008398
8399 err = genlmsg_end(msg, hdr);
8400 if (err < 0) {
8401 nlmsg_free(msg);
8402 return;
8403 }
8404
8405 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8406 nl80211_mlme_mcgrp.id, gfp);
8407 return;
8408
8409 nla_put_failure:
8410 genlmsg_cancel(msg, hdr);
8411 nlmsg_free(msg);
8412}
8413EXPORT_SYMBOL(cfg80211_probe_status);
8414
Johannes Berg5e760232011-11-04 11:18:17 +01008415void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8416 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008417 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008418{
8419 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8420 struct sk_buff *msg;
8421 void *hdr;
8422 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8423
8424 if (!nlpid)
8425 return;
8426
8427 msg = nlmsg_new(len + 100, gfp);
8428 if (!msg)
8429 return;
8430
8431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8432 if (!hdr) {
8433 nlmsg_free(msg);
8434 return;
8435 }
8436
David S. Miller9360ffd2012-03-29 04:41:26 -04008437 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8438 (freq &&
8439 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8440 (sig_dbm &&
8441 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8442 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8443 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01008444
8445 genlmsg_end(msg, hdr);
8446
8447 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8448 return;
8449
8450 nla_put_failure:
8451 genlmsg_cancel(msg, hdr);
8452 nlmsg_free(msg);
8453}
8454EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8455
Jouni Malinen026331c2010-02-15 12:53:10 +02008456static int nl80211_netlink_notify(struct notifier_block * nb,
8457 unsigned long state,
8458 void *_notify)
8459{
8460 struct netlink_notify *notify = _notify;
8461 struct cfg80211_registered_device *rdev;
8462 struct wireless_dev *wdev;
8463
8464 if (state != NETLINK_URELEASE)
8465 return NOTIFY_DONE;
8466
8467 rcu_read_lock();
8468
Johannes Berg5e760232011-11-04 11:18:17 +01008469 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008470 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008471 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e760232011-11-04 11:18:17 +01008472 if (rdev->ap_beacons_nlpid == notify->pid)
8473 rdev->ap_beacons_nlpid = 0;
8474 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008475
8476 rcu_read_unlock();
8477
8478 return NOTIFY_DONE;
8479}
8480
8481static struct notifier_block nl80211_netlink_notifier = {
8482 .notifier_call = nl80211_netlink_notify,
8483};
8484
Johannes Berg55682962007-09-20 13:09:35 -04008485/* initialisation/exit functions */
8486
8487int nl80211_init(void)
8488{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008489 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008490
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008491 err = genl_register_family_with_ops(&nl80211_fam,
8492 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008493 if (err)
8494 return err;
8495
Johannes Berg55682962007-09-20 13:09:35 -04008496 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8497 if (err)
8498 goto err_out;
8499
Johannes Berg2a519312009-02-10 21:25:55 +01008500 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8501 if (err)
8502 goto err_out;
8503
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008504 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8505 if (err)
8506 goto err_out;
8507
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008508 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8509 if (err)
8510 goto err_out;
8511
Johannes Bergaff89a92009-07-01 21:26:51 +02008512#ifdef CONFIG_NL80211_TESTMODE
8513 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8514 if (err)
8515 goto err_out;
8516#endif
8517
Jouni Malinen026331c2010-02-15 12:53:10 +02008518 err = netlink_register_notifier(&nl80211_netlink_notifier);
8519 if (err)
8520 goto err_out;
8521
Johannes Berg55682962007-09-20 13:09:35 -04008522 return 0;
8523 err_out:
8524 genl_unregister_family(&nl80211_fam);
8525 return err;
8526}
8527
8528void nl80211_exit(void)
8529{
Jouni Malinen026331c2010-02-15 12:53:10 +02008530 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008531 genl_unregister_family(&nl80211_fam);
8532}