blob: 12096b4ebf62473d747426d89a4c95354bbe3a0d [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 Malinen36aedc902008-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 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700343 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300344};
345
Holger Schuriga0438972009-11-11 11:30:02 +0100346/* ifidx get helper */
347static int nl80211_get_ifidx(struct netlink_callback *cb)
348{
349 int res;
350
351 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
352 nl80211_fam.attrbuf, nl80211_fam.maxattr,
353 nl80211_policy);
354 if (res)
355 return res;
356
357 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
358 return -EINVAL;
359
360 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
361 if (!res)
362 return -EINVAL;
363 return res;
364}
365
Johannes Berg67748892010-10-04 21:14:06 +0200366static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
367 struct netlink_callback *cb,
368 struct cfg80211_registered_device **rdev,
369 struct net_device **dev)
370{
371 int ifidx = cb->args[0];
372 int err;
373
374 if (!ifidx)
375 ifidx = nl80211_get_ifidx(cb);
376 if (ifidx < 0)
377 return ifidx;
378
379 cb->args[0] = ifidx;
380
381 rtnl_lock();
382
383 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
384 if (!*dev) {
385 err = -ENODEV;
386 goto out_rtnl;
387 }
388
389 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100390 if (IS_ERR(*rdev)) {
391 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200392 goto out_rtnl;
393 }
394
395 return 0;
396 out_rtnl:
397 rtnl_unlock();
398 return err;
399}
400
401static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
402{
403 cfg80211_unlock_rdev(rdev);
404 rtnl_unlock();
405}
406
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100407/* IE validation */
408static bool is_valid_ie_attr(const struct nlattr *attr)
409{
410 const u8 *pos;
411 int len;
412
413 if (!attr)
414 return true;
415
416 pos = nla_data(attr);
417 len = nla_len(attr);
418
419 while (len) {
420 u8 elemlen;
421
422 if (len < 2)
423 return false;
424 len -= 2;
425
426 elemlen = pos[1];
427 if (elemlen > len)
428 return false;
429
430 len -= elemlen;
431 pos += 2 + elemlen;
432 }
433
434 return true;
435}
436
Johannes Berg55682962007-09-20 13:09:35 -0400437/* message building helper */
438static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
439 int flags, u8 cmd)
440{
441 /* since there is no private header just add the generic one */
442 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
443}
444
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400445static int nl80211_msg_put_channel(struct sk_buff *msg,
446 struct ieee80211_channel *chan)
447{
David S. Miller9360ffd2012-03-29 04:41:26 -0400448 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
449 chan->center_freq))
450 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400451
David S. Miller9360ffd2012-03-29 04:41:26 -0400452 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
453 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
454 goto nla_put_failure;
455 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
456 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
457 goto nla_put_failure;
458 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
459 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
460 goto nla_put_failure;
461 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
462 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
463 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400464
David S. Miller9360ffd2012-03-29 04:41:26 -0400465 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
466 DBM_TO_MBM(chan->max_power)))
467 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400468
469 return 0;
470
471 nla_put_failure:
472 return -ENOBUFS;
473}
474
Johannes Berg55682962007-09-20 13:09:35 -0400475/* netlink command implementations */
476
Johannes Bergb9454e82009-07-08 13:29:08 +0200477struct key_parse {
478 struct key_params p;
479 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200480 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200481 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100482 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200483};
484
485static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
486{
487 struct nlattr *tb[NL80211_KEY_MAX + 1];
488 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
489 nl80211_key_policy);
490 if (err)
491 return err;
492
493 k->def = !!tb[NL80211_KEY_DEFAULT];
494 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
495
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100496 if (k->def) {
497 k->def_uni = true;
498 k->def_multi = true;
499 }
500 if (k->defmgmt)
501 k->def_multi = true;
502
Johannes Bergb9454e82009-07-08 13:29:08 +0200503 if (tb[NL80211_KEY_IDX])
504 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
505
506 if (tb[NL80211_KEY_DATA]) {
507 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
508 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
509 }
510
511 if (tb[NL80211_KEY_SEQ]) {
512 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
513 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
514 }
515
516 if (tb[NL80211_KEY_CIPHER])
517 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
518
Johannes Berge31b8212010-10-05 19:39:30 +0200519 if (tb[NL80211_KEY_TYPE]) {
520 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
521 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
522 return -EINVAL;
523 }
524
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100525 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
526 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100527 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
528 tb[NL80211_KEY_DEFAULT_TYPES],
529 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100530 if (err)
531 return err;
532
533 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
534 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
535 }
536
Johannes Bergb9454e82009-07-08 13:29:08 +0200537 return 0;
538}
539
540static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
541{
542 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
543 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
544 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
545 }
546
547 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
548 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
549 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
550 }
551
552 if (info->attrs[NL80211_ATTR_KEY_IDX])
553 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
554
555 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
556 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
557
558 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
559 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
560
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100561 if (k->def) {
562 k->def_uni = true;
563 k->def_multi = true;
564 }
565 if (k->defmgmt)
566 k->def_multi = true;
567
Johannes Berge31b8212010-10-05 19:39:30 +0200568 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
569 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
570 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
571 return -EINVAL;
572 }
573
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100574 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
575 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
576 int err = nla_parse_nested(
577 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
578 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
579 nl80211_key_default_policy);
580 if (err)
581 return err;
582
583 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
584 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
585 }
586
Johannes Bergb9454e82009-07-08 13:29:08 +0200587 return 0;
588}
589
590static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
591{
592 int err;
593
594 memset(k, 0, sizeof(*k));
595 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200596 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200597
598 if (info->attrs[NL80211_ATTR_KEY])
599 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
600 else
601 err = nl80211_parse_key_old(info, k);
602
603 if (err)
604 return err;
605
606 if (k->def && k->defmgmt)
607 return -EINVAL;
608
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100609 if (k->defmgmt) {
610 if (k->def_uni || !k->def_multi)
611 return -EINVAL;
612 }
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (k->idx != -1) {
615 if (k->defmgmt) {
616 if (k->idx < 4 || k->idx > 5)
617 return -EINVAL;
618 } else if (k->def) {
619 if (k->idx < 0 || k->idx > 3)
620 return -EINVAL;
621 } else {
622 if (k->idx < 0 || k->idx > 5)
623 return -EINVAL;
624 }
625 }
626
627 return 0;
628}
629
Johannes Bergfffd0932009-07-08 14:22:54 +0200630static struct cfg80211_cached_keys *
631nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
632 struct nlattr *keys)
633{
634 struct key_parse parse;
635 struct nlattr *key;
636 struct cfg80211_cached_keys *result;
637 int rem, err, def = 0;
638
639 result = kzalloc(sizeof(*result), GFP_KERNEL);
640 if (!result)
641 return ERR_PTR(-ENOMEM);
642
643 result->def = -1;
644 result->defmgmt = -1;
645
646 nla_for_each_nested(key, keys, rem) {
647 memset(&parse, 0, sizeof(parse));
648 parse.idx = -1;
649
650 err = nl80211_parse_key_new(key, &parse);
651 if (err)
652 goto error;
653 err = -EINVAL;
654 if (!parse.p.key)
655 goto error;
656 if (parse.idx < 0 || parse.idx > 4)
657 goto error;
658 if (parse.def) {
659 if (def)
660 goto error;
661 def = 1;
662 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100663 if (!parse.def_uni || !parse.def_multi)
664 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200665 } else if (parse.defmgmt)
666 goto error;
667 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200668 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200669 if (err)
670 goto error;
671 result->params[parse.idx].cipher = parse.p.cipher;
672 result->params[parse.idx].key_len = parse.p.key_len;
673 result->params[parse.idx].key = result->data[parse.idx];
674 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
675 }
676
677 return result;
678 error:
679 kfree(result);
680 return ERR_PTR(err);
681}
682
683static int nl80211_key_allowed(struct wireless_dev *wdev)
684{
685 ASSERT_WDEV_LOCK(wdev);
686
Johannes Bergfffd0932009-07-08 14:22:54 +0200687 switch (wdev->iftype) {
688 case NL80211_IFTYPE_AP:
689 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200690 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700691 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200692 break;
693 case NL80211_IFTYPE_ADHOC:
694 if (!wdev->current_bss)
695 return -ENOLINK;
696 break;
697 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200698 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200699 if (wdev->sme_state != CFG80211_SME_CONNECTED)
700 return -ENOLINK;
701 break;
702 default:
703 return -EINVAL;
704 }
705
706 return 0;
707}
708
Johannes Berg7527a782011-05-13 10:58:57 +0200709static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
710{
711 struct nlattr *nl_modes = nla_nest_start(msg, attr);
712 int i;
713
714 if (!nl_modes)
715 goto nla_put_failure;
716
717 i = 0;
718 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400719 if ((ifmodes & 1) && nla_put_flag(msg, i))
720 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200721 ifmodes >>= 1;
722 i++;
723 }
724
725 nla_nest_end(msg, nl_modes);
726 return 0;
727
728nla_put_failure:
729 return -ENOBUFS;
730}
731
732static int nl80211_put_iface_combinations(struct wiphy *wiphy,
733 struct sk_buff *msg)
734{
735 struct nlattr *nl_combis;
736 int i, j;
737
738 nl_combis = nla_nest_start(msg,
739 NL80211_ATTR_INTERFACE_COMBINATIONS);
740 if (!nl_combis)
741 goto nla_put_failure;
742
743 for (i = 0; i < wiphy->n_iface_combinations; i++) {
744 const struct ieee80211_iface_combination *c;
745 struct nlattr *nl_combi, *nl_limits;
746
747 c = &wiphy->iface_combinations[i];
748
749 nl_combi = nla_nest_start(msg, i + 1);
750 if (!nl_combi)
751 goto nla_put_failure;
752
753 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
754 if (!nl_limits)
755 goto nla_put_failure;
756
757 for (j = 0; j < c->n_limits; j++) {
758 struct nlattr *nl_limit;
759
760 nl_limit = nla_nest_start(msg, j + 1);
761 if (!nl_limit)
762 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400763 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
764 c->limits[j].max))
765 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200766 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
767 c->limits[j].types))
768 goto nla_put_failure;
769 nla_nest_end(msg, nl_limit);
770 }
771
772 nla_nest_end(msg, nl_limits);
773
David S. Miller9360ffd2012-03-29 04:41:26 -0400774 if (c->beacon_int_infra_match &&
775 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
776 goto nla_put_failure;
777 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
778 c->num_different_channels) ||
779 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
780 c->max_interfaces))
781 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200782
783 nla_nest_end(msg, nl_combi);
784 }
785
786 nla_nest_end(msg, nl_combis);
787
788 return 0;
789nla_put_failure:
790 return -ENOBUFS;
791}
792
Johannes Berg55682962007-09-20 13:09:35 -0400793static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
794 struct cfg80211_registered_device *dev)
795{
796 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100797 struct nlattr *nl_bands, *nl_band;
798 struct nlattr *nl_freqs, *nl_freq;
799 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100800 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100801 enum ieee80211_band band;
802 struct ieee80211_channel *chan;
803 struct ieee80211_rate *rate;
804 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200805 const struct ieee80211_txrx_stypes *mgmt_stypes =
806 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400807
808 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
809 if (!hdr)
810 return -1;
811
David S. Miller9360ffd2012-03-29 04:41:26 -0400812 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
813 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
814 nla_put_u32(msg, NL80211_ATTR_GENERATION,
815 cfg80211_rdev_list_generation) ||
816 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
817 dev->wiphy.retry_short) ||
818 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
819 dev->wiphy.retry_long) ||
820 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
821 dev->wiphy.frag_threshold) ||
822 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
823 dev->wiphy.rts_threshold) ||
824 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
825 dev->wiphy.coverage_class) ||
826 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
827 dev->wiphy.max_scan_ssids) ||
828 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
829 dev->wiphy.max_sched_scan_ssids) ||
830 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
831 dev->wiphy.max_scan_ie_len) ||
832 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
833 dev->wiphy.max_sched_scan_ie_len) ||
834 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
835 dev->wiphy.max_match_sets))
836 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200837
David S. Miller9360ffd2012-03-29 04:41:26 -0400838 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
839 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
840 goto nla_put_failure;
841 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
842 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
843 goto nla_put_failure;
844 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
845 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
846 goto nla_put_failure;
847 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
848 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
849 goto nla_put_failure;
850 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
851 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
852 goto nla_put_failure;
853 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
854 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
855 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200856
David S. Miller9360ffd2012-03-29 04:41:26 -0400857 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
858 sizeof(u32) * dev->wiphy.n_cipher_suites,
859 dev->wiphy.cipher_suites))
860 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100861
David S. Miller9360ffd2012-03-29 04:41:26 -0400862 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
863 dev->wiphy.max_num_pmkids))
864 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530865
David S. Miller9360ffd2012-03-29 04:41:26 -0400866 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
867 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
868 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200869
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
871 dev->wiphy.available_antennas_tx) ||
872 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
873 dev->wiphy.available_antennas_rx))
874 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100875
David S. Miller9360ffd2012-03-29 04:41:26 -0400876 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
877 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
878 dev->wiphy.probe_resp_offload))
879 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200880
Bruno Randolf7f531e02010-12-16 11:30:22 +0900881 if ((dev->wiphy.available_antennas_tx ||
882 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900883 u32 tx_ant = 0, rx_ant = 0;
884 int res;
885 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
886 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400887 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
888 tx_ant) ||
889 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
890 rx_ant))
891 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900892 }
893 }
894
Johannes Berg7527a782011-05-13 10:58:57 +0200895 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
896 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700897 goto nla_put_failure;
898
Johannes Bergee688b002008-01-24 19:38:39 +0100899 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
900 if (!nl_bands)
901 goto nla_put_failure;
902
903 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
904 if (!dev->wiphy.bands[band])
905 continue;
906
907 nl_band = nla_nest_start(msg, band);
908 if (!nl_band)
909 goto nla_put_failure;
910
Johannes Bergd51626d2008-10-09 12:20:13 +0200911 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400912 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
913 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
914 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
915 &dev->wiphy.bands[band]->ht_cap.mcs) ||
916 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
917 dev->wiphy.bands[band]->ht_cap.cap) ||
918 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
919 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
920 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
921 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
922 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200923
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000924 /* add VHT info */
925 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
926 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
927 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
928 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
929 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
930 dev->wiphy.bands[band]->vht_cap.cap)))
931 goto nla_put_failure;
932
Johannes Bergee688b002008-01-24 19:38:39 +0100933 /* add frequencies */
934 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
935 if (!nl_freqs)
936 goto nla_put_failure;
937
938 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
939 nl_freq = nla_nest_start(msg, i);
940 if (!nl_freq)
941 goto nla_put_failure;
942
943 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100944
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400945 if (nl80211_msg_put_channel(msg, chan))
946 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200947
Johannes Bergee688b002008-01-24 19:38:39 +0100948 nla_nest_end(msg, nl_freq);
949 }
950
951 nla_nest_end(msg, nl_freqs);
952
953 /* add bitrates */
954 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
955 if (!nl_rates)
956 goto nla_put_failure;
957
958 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
959 nl_rate = nla_nest_start(msg, i);
960 if (!nl_rate)
961 goto nla_put_failure;
962
963 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -0400964 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
965 rate->bitrate))
966 goto nla_put_failure;
967 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
968 nla_put_flag(msg,
969 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
970 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100971
972 nla_nest_end(msg, nl_rate);
973 }
974
975 nla_nest_end(msg, nl_rates);
976
977 nla_nest_end(msg, nl_band);
978 }
979 nla_nest_end(msg, nl_bands);
980
Johannes Berg8fdc6212009-03-14 09:34:01 +0100981 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
982 if (!nl_cmds)
983 goto nla_put_failure;
984
985 i = 0;
986#define CMD(op, n) \
987 do { \
988 if (dev->ops->op) { \
989 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -0400990 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
991 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +0100992 } \
993 } while (0)
994
995 CMD(add_virtual_intf, NEW_INTERFACE);
996 CMD(change_virtual_intf, SET_INTERFACE);
997 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +0100998 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100999 CMD(add_station, NEW_STATION);
1000 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001001 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001002 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001003 CMD(auth, AUTHENTICATE);
1004 CMD(assoc, ASSOCIATE);
1005 CMD(deauth, DEAUTHENTICATE);
1006 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001007 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001008 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001009 CMD(set_pmksa, SET_PMKSA);
1010 CMD(del_pmksa, DEL_PMKSA);
1011 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001012 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1013 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001014 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001015 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001016 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001017 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001018 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001019 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1020 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001021 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001022 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001023 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001024 i++;
1025 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1026 goto nla_put_failure;
1027 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001028 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001029 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1030 CMD(tdls_mgmt, TDLS_MGMT);
1031 CMD(tdls_oper, TDLS_OPER);
1032 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001033 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1034 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001035 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001036 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e7602302011-11-04 11:18:17 +01001037 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1038 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001039 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1040 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01001041 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001042
Kalle Valo4745fc02011-11-17 19:06:10 +02001043#ifdef CONFIG_NL80211_TESTMODE
1044 CMD(testmode_cmd, TESTMODE);
1045#endif
1046
Johannes Berg8fdc6212009-03-14 09:34:01 +01001047#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001048
Johannes Berg6829c872009-07-02 09:13:27 +02001049 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001050 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1052 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001053 }
1054
Johannes Berg6829c872009-07-02 09:13:27 +02001055 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001056 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001057 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1058 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001059 }
1060
Johannes Berg8fdc6212009-03-14 09:34:01 +01001061 nla_nest_end(msg, nl_cmds);
1062
Johannes Berg7c4ef712011-11-18 15:33:48 +01001063 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001064 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1065 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1066 dev->wiphy.max_remain_on_channel_duration))
1067 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001068
David S. Miller9360ffd2012-03-29 04:41:26 -04001069 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1070 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1071 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001072
Johannes Berg2e161f72010-08-12 15:38:38 +02001073 if (mgmt_stypes) {
1074 u16 stypes;
1075 struct nlattr *nl_ftypes, *nl_ifs;
1076 enum nl80211_iftype ift;
1077
1078 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1079 if (!nl_ifs)
1080 goto nla_put_failure;
1081
1082 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1083 nl_ftypes = nla_nest_start(msg, ift);
1084 if (!nl_ftypes)
1085 goto nla_put_failure;
1086 i = 0;
1087 stypes = mgmt_stypes[ift].tx;
1088 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001089 if ((stypes & 1) &&
1090 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1091 (i << 4) | IEEE80211_FTYPE_MGMT))
1092 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001093 stypes >>= 1;
1094 i++;
1095 }
1096 nla_nest_end(msg, nl_ftypes);
1097 }
1098
Johannes Berg74b70a42010-08-24 12:15:53 +02001099 nla_nest_end(msg, nl_ifs);
1100
Johannes Berg2e161f72010-08-12 15:38:38 +02001101 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1102 if (!nl_ifs)
1103 goto nla_put_failure;
1104
1105 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1106 nl_ftypes = nla_nest_start(msg, ift);
1107 if (!nl_ftypes)
1108 goto nla_put_failure;
1109 i = 0;
1110 stypes = mgmt_stypes[ift].rx;
1111 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001112 if ((stypes & 1) &&
1113 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1114 (i << 4) | IEEE80211_FTYPE_MGMT))
1115 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001116 stypes >>= 1;
1117 i++;
1118 }
1119 nla_nest_end(msg, nl_ftypes);
1120 }
1121 nla_nest_end(msg, nl_ifs);
1122 }
1123
Johannes Bergdfb89c52012-06-27 09:23:48 +02001124#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001125 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1126 struct nlattr *nl_wowlan;
1127
1128 nl_wowlan = nla_nest_start(msg,
1129 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1130 if (!nl_wowlan)
1131 goto nla_put_failure;
1132
David S. Miller9360ffd2012-03-29 04:41:26 -04001133 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1134 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1135 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1136 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1137 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1138 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1139 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1140 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1141 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1142 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1143 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1144 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1145 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1147 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1148 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1149 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001150 if (dev->wiphy.wowlan.n_patterns) {
1151 struct nl80211_wowlan_pattern_support pat = {
1152 .max_patterns = dev->wiphy.wowlan.n_patterns,
1153 .min_pattern_len =
1154 dev->wiphy.wowlan.pattern_min_len,
1155 .max_pattern_len =
1156 dev->wiphy.wowlan.pattern_max_len,
1157 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001158 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1159 sizeof(pat), &pat))
1160 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001161 }
1162
1163 nla_nest_end(msg, nl_wowlan);
1164 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001165#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001166
Johannes Berg7527a782011-05-13 10:58:57 +02001167 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1168 dev->wiphy.software_iftypes))
1169 goto nla_put_failure;
1170
1171 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1172 goto nla_put_failure;
1173
David S. Miller9360ffd2012-03-29 04:41:26 -04001174 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1175 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1176 dev->wiphy.ap_sme_capa))
1177 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001178
David S. Miller9360ffd2012-03-29 04:41:26 -04001179 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1180 dev->wiphy.features))
1181 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001182
David S. Miller9360ffd2012-03-29 04:41:26 -04001183 if (dev->wiphy.ht_capa_mod_mask &&
1184 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1185 sizeof(*dev->wiphy.ht_capa_mod_mask),
1186 dev->wiphy.ht_capa_mod_mask))
1187 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001188
Johannes Berg55682962007-09-20 13:09:35 -04001189 return genlmsg_end(msg, hdr);
1190
1191 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001192 genlmsg_cancel(msg, hdr);
1193 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001194}
1195
1196static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1197{
1198 int idx = 0;
1199 int start = cb->args[0];
1200 struct cfg80211_registered_device *dev;
1201
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001202 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001203 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001204 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1205 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001206 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001207 continue;
1208 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1209 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001210 dev) < 0) {
1211 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001212 break;
Julius Volzb4637272008-07-08 14:02:19 +02001213 }
Johannes Berg55682962007-09-20 13:09:35 -04001214 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001215 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001216
1217 cb->args[0] = idx;
1218
1219 return skb->len;
1220}
1221
1222static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1223{
1224 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001225 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001226
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001227 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001228 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001229 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001230
Johannes Berg4c476992010-10-04 21:36:35 +02001231 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1232 nlmsg_free(msg);
1233 return -ENOBUFS;
1234 }
Johannes Berg55682962007-09-20 13:09:35 -04001235
Johannes Berg134e6372009-07-10 09:51:34 +00001236 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001237}
1238
Jouni Malinen31888482008-10-30 16:59:24 +02001239static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1240 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1241 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1242 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1243 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1244 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1245};
1246
1247static int parse_txq_params(struct nlattr *tb[],
1248 struct ieee80211_txq_params *txq_params)
1249{
Johannes Berga3304b02012-03-28 11:04:24 +02001250 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001251 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1252 !tb[NL80211_TXQ_ATTR_AIFS])
1253 return -EINVAL;
1254
Johannes Berga3304b02012-03-28 11:04:24 +02001255 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001256 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1257 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1258 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1259 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1260
Johannes Berga3304b02012-03-28 11:04:24 +02001261 if (txq_params->ac >= NL80211_NUM_ACS)
1262 return -EINVAL;
1263
Jouni Malinen31888482008-10-30 16:59:24 +02001264 return 0;
1265}
1266
Johannes Bergf444de02010-05-05 15:25:02 +02001267static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1268{
1269 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001270 * You can only set the channel explicitly for WDS interfaces,
1271 * all others have their channel managed via their respective
1272 * "establish a connection" command (connect, join, ...)
1273 *
1274 * For AP/GO and mesh mode, the channel can be set with the
1275 * channel userspace API, but is only stored and passed to the
1276 * low-level driver when the AP starts or the mesh is joined.
1277 * This is for backward compatibility, userspace can also give
1278 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001279 *
1280 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001281 * whatever else is going on, so they have their own special
1282 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001283 */
1284 return !wdev ||
1285 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001286 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001287 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1288 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001289}
1290
Johannes Bergcd6c6592012-05-10 21:27:18 +02001291static bool nl80211_valid_channel_type(struct genl_info *info,
1292 enum nl80211_channel_type *channel_type)
1293{
1294 enum nl80211_channel_type tmp;
1295
1296 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1297 return false;
1298
1299 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1300 if (tmp != NL80211_CHAN_NO_HT &&
1301 tmp != NL80211_CHAN_HT20 &&
1302 tmp != NL80211_CHAN_HT40PLUS &&
1303 tmp != NL80211_CHAN_HT40MINUS)
1304 return false;
1305
1306 if (channel_type)
1307 *channel_type = tmp;
1308
1309 return true;
1310}
1311
Johannes Bergf444de02010-05-05 15:25:02 +02001312static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1313 struct wireless_dev *wdev,
1314 struct genl_info *info)
1315{
Johannes Bergaa430da2012-05-16 23:50:18 +02001316 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001317 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1318 u32 freq;
1319 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001320 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1321
1322 if (wdev)
1323 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001324
1325 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1326 return -EINVAL;
1327
1328 if (!nl80211_can_set_dev_channel(wdev))
1329 return -EOPNOTSUPP;
1330
Johannes Bergcd6c6592012-05-10 21:27:18 +02001331 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1332 !nl80211_valid_channel_type(info, &channel_type))
1333 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001334
1335 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1336
1337 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001338 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001339 case NL80211_IFTYPE_AP:
1340 case NL80211_IFTYPE_P2P_GO:
1341 if (wdev->beacon_interval) {
1342 result = -EBUSY;
1343 break;
1344 }
1345 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1346 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1347 channel,
1348 channel_type)) {
1349 result = -EINVAL;
1350 break;
1351 }
1352 wdev->preset_chan = channel;
1353 wdev->preset_chantype = channel_type;
1354 result = 0;
1355 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001356 case NL80211_IFTYPE_MESH_POINT:
1357 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1358 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001359 case NL80211_IFTYPE_MONITOR:
1360 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1361 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001362 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001363 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001364 }
1365 mutex_unlock(&rdev->devlist_mtx);
1366
1367 return result;
1368}
1369
1370static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1371{
Johannes Berg4c476992010-10-04 21:36:35 +02001372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1373 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001374
Johannes Berg4c476992010-10-04 21:36:35 +02001375 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001376}
1377
Bill Jordane8347eb2010-10-01 13:54:28 -04001378static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1379{
Johannes Berg43b19952010-10-07 13:10:30 +02001380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1381 struct net_device *dev = info->user_ptr[1];
1382 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001383 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001384
1385 if (!info->attrs[NL80211_ATTR_MAC])
1386 return -EINVAL;
1387
Johannes Berg43b19952010-10-07 13:10:30 +02001388 if (netif_running(dev))
1389 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001390
Johannes Berg43b19952010-10-07 13:10:30 +02001391 if (!rdev->ops->set_wds_peer)
1392 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001393
Johannes Berg43b19952010-10-07 13:10:30 +02001394 if (wdev->iftype != NL80211_IFTYPE_WDS)
1395 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001396
1397 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001398 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001399}
1400
1401
Johannes Berg55682962007-09-20 13:09:35 -04001402static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1403{
1404 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001405 struct net_device *netdev = NULL;
1406 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001407 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001408 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001409 u32 changed;
1410 u8 retry_short = 0, retry_long = 0;
1411 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001412 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001413
Johannes Bergf444de02010-05-05 15:25:02 +02001414 /*
1415 * Try to find the wiphy and netdev. Normally this
1416 * function shouldn't need the netdev, but this is
1417 * done for backward compatibility -- previously
1418 * setting the channel was done per wiphy, but now
1419 * it is per netdev. Previous userland like hostapd
1420 * also passed a netdev to set_wiphy, so that it is
1421 * possible to let that go to the right netdev!
1422 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001423 mutex_lock(&cfg80211_mutex);
1424
Johannes Bergf444de02010-05-05 15:25:02 +02001425 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1426 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1427
1428 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1429 if (netdev && netdev->ieee80211_ptr) {
1430 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1431 mutex_lock(&rdev->mtx);
1432 } else
1433 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001434 }
1435
Johannes Bergf444de02010-05-05 15:25:02 +02001436 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001437 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1438 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001439 if (IS_ERR(rdev)) {
1440 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001441 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001442 }
1443 wdev = NULL;
1444 netdev = NULL;
1445 result = 0;
1446
1447 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001448 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001449 wdev = netdev->ieee80211_ptr;
1450 else
1451 wdev = NULL;
1452
1453 /*
1454 * end workaround code, by now the rdev is available
1455 * and locked, and wdev may or may not be NULL.
1456 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001457
1458 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001459 result = cfg80211_dev_rename(
1460 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001461
1462 mutex_unlock(&cfg80211_mutex);
1463
1464 if (result)
1465 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001466
Jouni Malinen31888482008-10-30 16:59:24 +02001467 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1468 struct ieee80211_txq_params txq_params;
1469 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1470
1471 if (!rdev->ops->set_txq_params) {
1472 result = -EOPNOTSUPP;
1473 goto bad_res;
1474 }
1475
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001476 if (!netdev) {
1477 result = -EINVAL;
1478 goto bad_res;
1479 }
1480
Johannes Berg133a3ff2011-11-03 14:50:13 +01001481 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1482 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1483 result = -EINVAL;
1484 goto bad_res;
1485 }
1486
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001487 if (!netif_running(netdev)) {
1488 result = -ENETDOWN;
1489 goto bad_res;
1490 }
1491
Jouni Malinen31888482008-10-30 16:59:24 +02001492 nla_for_each_nested(nl_txq_params,
1493 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1494 rem_txq_params) {
1495 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1496 nla_data(nl_txq_params),
1497 nla_len(nl_txq_params),
1498 txq_params_policy);
1499 result = parse_txq_params(tb, &txq_params);
1500 if (result)
1501 goto bad_res;
1502
1503 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001504 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001505 &txq_params);
1506 if (result)
1507 goto bad_res;
1508 }
1509 }
1510
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001511 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001512 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001513 if (result)
1514 goto bad_res;
1515 }
1516
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001517 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1518 enum nl80211_tx_power_setting type;
1519 int idx, mbm = 0;
1520
1521 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001522 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001523 goto bad_res;
1524 }
1525
1526 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1527 type = nla_get_u32(info->attrs[idx]);
1528
1529 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1530 (type != NL80211_TX_POWER_AUTOMATIC)) {
1531 result = -EINVAL;
1532 goto bad_res;
1533 }
1534
1535 if (type != NL80211_TX_POWER_AUTOMATIC) {
1536 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1537 mbm = nla_get_u32(info->attrs[idx]);
1538 }
1539
1540 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1541 if (result)
1542 goto bad_res;
1543 }
1544
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001545 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1546 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1547 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001548 if ((!rdev->wiphy.available_antennas_tx &&
1549 !rdev->wiphy.available_antennas_rx) ||
1550 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001551 result = -EOPNOTSUPP;
1552 goto bad_res;
1553 }
1554
1555 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1556 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1557
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001558 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001559 * available antenna masks, except for the "all" mask */
1560 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1561 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001562 result = -EINVAL;
1563 goto bad_res;
1564 }
1565
Bruno Randolf7f531e02010-12-16 11:30:22 +09001566 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1567 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001568
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001569 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1570 if (result)
1571 goto bad_res;
1572 }
1573
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001574 changed = 0;
1575
1576 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1577 retry_short = nla_get_u8(
1578 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1579 if (retry_short == 0) {
1580 result = -EINVAL;
1581 goto bad_res;
1582 }
1583 changed |= WIPHY_PARAM_RETRY_SHORT;
1584 }
1585
1586 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1587 retry_long = nla_get_u8(
1588 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1589 if (retry_long == 0) {
1590 result = -EINVAL;
1591 goto bad_res;
1592 }
1593 changed |= WIPHY_PARAM_RETRY_LONG;
1594 }
1595
1596 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1597 frag_threshold = nla_get_u32(
1598 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1599 if (frag_threshold < 256) {
1600 result = -EINVAL;
1601 goto bad_res;
1602 }
1603 if (frag_threshold != (u32) -1) {
1604 /*
1605 * Fragments (apart from the last one) are required to
1606 * have even length. Make the fragmentation code
1607 * simpler by stripping LSB should someone try to use
1608 * odd threshold value.
1609 */
1610 frag_threshold &= ~0x1;
1611 }
1612 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1613 }
1614
1615 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1616 rts_threshold = nla_get_u32(
1617 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1618 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1619 }
1620
Lukáš Turek81077e82009-12-21 22:50:47 +01001621 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1622 coverage_class = nla_get_u8(
1623 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1624 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1625 }
1626
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001627 if (changed) {
1628 u8 old_retry_short, old_retry_long;
1629 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001630 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001631
1632 if (!rdev->ops->set_wiphy_params) {
1633 result = -EOPNOTSUPP;
1634 goto bad_res;
1635 }
1636
1637 old_retry_short = rdev->wiphy.retry_short;
1638 old_retry_long = rdev->wiphy.retry_long;
1639 old_frag_threshold = rdev->wiphy.frag_threshold;
1640 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001641 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001642
1643 if (changed & WIPHY_PARAM_RETRY_SHORT)
1644 rdev->wiphy.retry_short = retry_short;
1645 if (changed & WIPHY_PARAM_RETRY_LONG)
1646 rdev->wiphy.retry_long = retry_long;
1647 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1648 rdev->wiphy.frag_threshold = frag_threshold;
1649 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1650 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001651 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1652 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001653
1654 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1655 if (result) {
1656 rdev->wiphy.retry_short = old_retry_short;
1657 rdev->wiphy.retry_long = old_retry_long;
1658 rdev->wiphy.frag_threshold = old_frag_threshold;
1659 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001660 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001661 }
1662 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001663
Johannes Berg306d6112008-12-08 12:39:04 +01001664 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001665 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001666 if (netdev)
1667 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001668 return result;
1669}
1670
1671
1672static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001673 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -04001674 struct net_device *dev)
1675{
1676 void *hdr;
1677
1678 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1679 if (!hdr)
1680 return -1;
1681
David S. Miller9360ffd2012-03-29 04:41:26 -04001682 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
1683 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1684 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
1685 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1686 dev->ieee80211_ptr->iftype) ||
1687 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1688 rdev->devlist_generation ^
1689 (cfg80211_rdev_list_generation << 2)))
1690 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001691
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001692 if (rdev->ops->get_channel) {
1693 struct ieee80211_channel *chan;
1694 enum nl80211_channel_type channel_type;
1695
1696 chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
John W. Linville59ef43e2012-04-18 14:17:13 -04001697 if (chan &&
1698 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1699 chan->center_freq) ||
1700 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1701 channel_type)))
1702 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001703 }
1704
Johannes Berg55682962007-09-20 13:09:35 -04001705 return genlmsg_end(msg, hdr);
1706
1707 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001708 genlmsg_cancel(msg, hdr);
1709 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001710}
1711
1712static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1713{
1714 int wp_idx = 0;
1715 int if_idx = 0;
1716 int wp_start = cb->args[0];
1717 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001718 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001719 struct wireless_dev *wdev;
1720
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001721 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001722 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1723 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001724 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001725 if (wp_idx < wp_start) {
1726 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001727 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001728 }
Johannes Berg55682962007-09-20 13:09:35 -04001729 if_idx = 0;
1730
Johannes Bergf5ea9122009-08-07 16:17:38 +02001731 mutex_lock(&rdev->devlist_mtx);
1732 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001733 if (if_idx < if_start) {
1734 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001735 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001736 }
Johannes Berg55682962007-09-20 13:09:35 -04001737 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1738 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001739 rdev, wdev->netdev) < 0) {
1740 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001741 goto out;
1742 }
1743 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001744 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001745 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001746
1747 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001748 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001749 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001750 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001751
1752 cb->args[0] = wp_idx;
1753 cb->args[1] = if_idx;
1754
1755 return skb->len;
1756}
1757
1758static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1759{
1760 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001761 struct cfg80211_registered_device *dev = info->user_ptr[0];
1762 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001763
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001765 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001766 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001767
Johannes Bergd7264052009-04-19 16:23:20 +02001768 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001769 dev, netdev) < 0) {
1770 nlmsg_free(msg);
1771 return -ENOBUFS;
1772 }
Johannes Berg55682962007-09-20 13:09:35 -04001773
Johannes Berg134e6372009-07-10 09:51:34 +00001774 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001775}
1776
Michael Wu66f7ac52008-01-31 19:48:22 +01001777static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1778 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1779 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1780 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1781 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1782 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1783};
1784
1785static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1786{
1787 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1788 int flag;
1789
1790 *mntrflags = 0;
1791
1792 if (!nla)
1793 return -EINVAL;
1794
1795 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1796 nla, mntr_flags_policy))
1797 return -EINVAL;
1798
1799 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1800 if (flags[flag])
1801 *mntrflags |= (1<<flag);
1802
1803 return 0;
1804}
1805
Johannes Berg9bc383d2009-11-19 11:55:19 +01001806static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001807 struct net_device *netdev, u8 use_4addr,
1808 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001809{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001810 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001811 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001812 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001813 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001814 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001815
1816 switch (iftype) {
1817 case NL80211_IFTYPE_AP_VLAN:
1818 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1819 return 0;
1820 break;
1821 case NL80211_IFTYPE_STATION:
1822 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1823 return 0;
1824 break;
1825 default:
1826 break;
1827 }
1828
1829 return -EOPNOTSUPP;
1830}
1831
Johannes Berg55682962007-09-20 13:09:35 -04001832static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1833{
Johannes Berg4c476992010-10-04 21:36:35 +02001834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001835 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001836 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001837 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001838 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001839 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001840 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001841
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001842 memset(&params, 0, sizeof(params));
1843
Johannes Berg04a773a2009-04-19 21:24:32 +02001844 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001845
Johannes Berg723b0382008-09-16 20:22:09 +02001846 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001847 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001848 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001849 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001850 if (ntype > NL80211_IFTYPE_MAX)
1851 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001852 }
1853
Johannes Berg92ffe052008-09-16 20:39:36 +02001854 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001855 struct wireless_dev *wdev = dev->ieee80211_ptr;
1856
Johannes Berg4c476992010-10-04 21:36:35 +02001857 if (ntype != NL80211_IFTYPE_MESH_POINT)
1858 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001859 if (netif_running(dev))
1860 return -EBUSY;
1861
1862 wdev_lock(wdev);
1863 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1864 IEEE80211_MAX_MESH_ID_LEN);
1865 wdev->mesh_id_up_len =
1866 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1867 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1868 wdev->mesh_id_up_len);
1869 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001870 }
1871
Felix Fietkau8b787642009-11-10 18:53:10 +01001872 if (info->attrs[NL80211_ATTR_4ADDR]) {
1873 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1874 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001875 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001876 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001877 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001878 } else {
1879 params.use_4addr = -1;
1880 }
1881
Johannes Berg92ffe052008-09-16 20:39:36 +02001882 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001883 if (ntype != NL80211_IFTYPE_MONITOR)
1884 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001885 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1886 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001887 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001888 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001889
1890 flags = &_flags;
1891 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001892 }
Johannes Berg3b858752009-03-12 09:55:09 +01001893
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001894 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001895 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001896 else
1897 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001898
Johannes Berg9bc383d2009-11-19 11:55:19 +01001899 if (!err && params.use_4addr != -1)
1900 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1901
Johannes Berg55682962007-09-20 13:09:35 -04001902 return err;
1903}
1904
1905static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1906{
Johannes Berg4c476992010-10-04 21:36:35 +02001907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001908 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001909 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001910 int err;
1911 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001912 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001913
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001914 memset(&params, 0, sizeof(params));
1915
Johannes Berg55682962007-09-20 13:09:35 -04001916 if (!info->attrs[NL80211_ATTR_IFNAME])
1917 return -EINVAL;
1918
1919 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1920 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1921 if (type > NL80211_IFTYPE_MAX)
1922 return -EINVAL;
1923 }
1924
Johannes Berg79c97e92009-07-07 03:56:12 +02001925 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001926 !(rdev->wiphy.interface_modes & (1 << type)))
1927 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001928
Johannes Berg9bc383d2009-11-19 11:55:19 +01001929 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001930 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001931 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001932 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001933 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001934 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001935
Michael Wu66f7ac52008-01-31 19:48:22 +01001936 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1937 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1938 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001939 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001940 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001941 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001942 if (IS_ERR(dev))
1943 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001944
Johannes Berg29cbe682010-12-03 09:20:44 +01001945 if (type == NL80211_IFTYPE_MESH_POINT &&
1946 info->attrs[NL80211_ATTR_MESH_ID]) {
1947 struct wireless_dev *wdev = dev->ieee80211_ptr;
1948
1949 wdev_lock(wdev);
1950 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1951 IEEE80211_MAX_MESH_ID_LEN);
1952 wdev->mesh_id_up_len =
1953 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1954 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1955 wdev->mesh_id_up_len);
1956 wdev_unlock(wdev);
1957 }
1958
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001959 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001960}
1961
1962static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1963{
Johannes Berg4c476992010-10-04 21:36:35 +02001964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1965 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001966
Johannes Berg4c476992010-10-04 21:36:35 +02001967 if (!rdev->ops->del_virtual_intf)
1968 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001969
Johannes Berg4c476992010-10-04 21:36:35 +02001970 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001971}
1972
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001973static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1974{
1975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1976 struct net_device *dev = info->user_ptr[1];
1977 u16 noack_map;
1978
1979 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1980 return -EINVAL;
1981
1982 if (!rdev->ops->set_noack_map)
1983 return -EOPNOTSUPP;
1984
1985 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1986
1987 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1988}
1989
Johannes Berg41ade002007-12-19 02:03:29 +01001990struct get_key_cookie {
1991 struct sk_buff *msg;
1992 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001993 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001994};
1995
1996static void get_key_callback(void *c, struct key_params *params)
1997{
Johannes Bergb9454e82009-07-08 13:29:08 +02001998 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001999 struct get_key_cookie *cookie = c;
2000
David S. Miller9360ffd2012-03-29 04:41:26 -04002001 if ((params->key &&
2002 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2003 params->key_len, params->key)) ||
2004 (params->seq &&
2005 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2006 params->seq_len, params->seq)) ||
2007 (params->cipher &&
2008 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2009 params->cipher)))
2010 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002011
Johannes Bergb9454e82009-07-08 13:29:08 +02002012 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2013 if (!key)
2014 goto nla_put_failure;
2015
David S. Miller9360ffd2012-03-29 04:41:26 -04002016 if ((params->key &&
2017 nla_put(cookie->msg, NL80211_KEY_DATA,
2018 params->key_len, params->key)) ||
2019 (params->seq &&
2020 nla_put(cookie->msg, NL80211_KEY_SEQ,
2021 params->seq_len, params->seq)) ||
2022 (params->cipher &&
2023 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2024 params->cipher)))
2025 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002026
David S. Miller9360ffd2012-03-29 04:41:26 -04002027 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2028 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002029
2030 nla_nest_end(cookie->msg, key);
2031
Johannes Berg41ade002007-12-19 02:03:29 +01002032 return;
2033 nla_put_failure:
2034 cookie->error = 1;
2035}
2036
2037static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2038{
Johannes Berg4c476992010-10-04 21:36:35 +02002039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002040 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002041 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002042 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002043 const u8 *mac_addr = NULL;
2044 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002045 struct get_key_cookie cookie = {
2046 .error = 0,
2047 };
2048 void *hdr;
2049 struct sk_buff *msg;
2050
2051 if (info->attrs[NL80211_ATTR_KEY_IDX])
2052 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2053
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002054 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002055 return -EINVAL;
2056
2057 if (info->attrs[NL80211_ATTR_MAC])
2058 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2059
Johannes Berge31b8212010-10-05 19:39:30 +02002060 pairwise = !!mac_addr;
2061 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2062 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2063 if (kt >= NUM_NL80211_KEYTYPES)
2064 return -EINVAL;
2065 if (kt != NL80211_KEYTYPE_GROUP &&
2066 kt != NL80211_KEYTYPE_PAIRWISE)
2067 return -EINVAL;
2068 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2069 }
2070
Johannes Berg4c476992010-10-04 21:36:35 +02002071 if (!rdev->ops->get_key)
2072 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002073
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002074 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002075 if (!msg)
2076 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002077
2078 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2079 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002080 if (IS_ERR(hdr))
2081 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002082
2083 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002084 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002085
David S. Miller9360ffd2012-03-29 04:41:26 -04002086 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2087 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2088 goto nla_put_failure;
2089 if (mac_addr &&
2090 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2091 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002092
Johannes Berge31b8212010-10-05 19:39:30 +02002093 if (pairwise && mac_addr &&
2094 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2095 return -ENOENT;
2096
2097 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2098 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002099
2100 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002101 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002102
2103 if (cookie.error)
2104 goto nla_put_failure;
2105
2106 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002107 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002108
2109 nla_put_failure:
2110 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002111 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002112 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002113 return err;
2114}
2115
2116static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2117{
Johannes Berg4c476992010-10-04 21:36:35 +02002118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002119 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002120 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002121 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002122
Johannes Bergb9454e82009-07-08 13:29:08 +02002123 err = nl80211_parse_key(info, &key);
2124 if (err)
2125 return err;
2126
2127 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002128 return -EINVAL;
2129
Johannes Bergb9454e82009-07-08 13:29:08 +02002130 /* only support setting default key */
2131 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002132 return -EINVAL;
2133
Johannes Bergfffd0932009-07-08 14:22:54 +02002134 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002135
2136 if (key.def) {
2137 if (!rdev->ops->set_default_key) {
2138 err = -EOPNOTSUPP;
2139 goto out;
2140 }
2141
2142 err = nl80211_key_allowed(dev->ieee80211_ptr);
2143 if (err)
2144 goto out;
2145
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002146 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2147 key.def_uni, key.def_multi);
2148
2149 if (err)
2150 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002151
Johannes Berg3d23e342009-09-29 23:27:28 +02002152#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002153 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002154#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002155 } else {
2156 if (key.def_uni || !key.def_multi) {
2157 err = -EINVAL;
2158 goto out;
2159 }
2160
2161 if (!rdev->ops->set_default_mgmt_key) {
2162 err = -EOPNOTSUPP;
2163 goto out;
2164 }
2165
2166 err = nl80211_key_allowed(dev->ieee80211_ptr);
2167 if (err)
2168 goto out;
2169
2170 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2171 dev, key.idx);
2172 if (err)
2173 goto out;
2174
2175#ifdef CONFIG_CFG80211_WEXT
2176 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2177#endif
2178 }
2179
2180 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002181 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002182
Johannes Berg41ade002007-12-19 02:03:29 +01002183 return err;
2184}
2185
2186static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2187{
Johannes Berg4c476992010-10-04 21:36:35 +02002188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002189 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002190 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002191 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002192 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002193
Johannes Bergb9454e82009-07-08 13:29:08 +02002194 err = nl80211_parse_key(info, &key);
2195 if (err)
2196 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002197
Johannes Bergb9454e82009-07-08 13:29:08 +02002198 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002199 return -EINVAL;
2200
Johannes Berg41ade002007-12-19 02:03:29 +01002201 if (info->attrs[NL80211_ATTR_MAC])
2202 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2203
Johannes Berge31b8212010-10-05 19:39:30 +02002204 if (key.type == -1) {
2205 if (mac_addr)
2206 key.type = NL80211_KEYTYPE_PAIRWISE;
2207 else
2208 key.type = NL80211_KEYTYPE_GROUP;
2209 }
2210
2211 /* for now */
2212 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2213 key.type != NL80211_KEYTYPE_GROUP)
2214 return -EINVAL;
2215
Johannes Berg4c476992010-10-04 21:36:35 +02002216 if (!rdev->ops->add_key)
2217 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002218
Johannes Berge31b8212010-10-05 19:39:30 +02002219 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2220 key.type == NL80211_KEYTYPE_PAIRWISE,
2221 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002222 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002223
2224 wdev_lock(dev->ieee80211_ptr);
2225 err = nl80211_key_allowed(dev->ieee80211_ptr);
2226 if (!err)
2227 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002228 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002229 mac_addr, &key.p);
2230 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002231
Johannes Berg41ade002007-12-19 02:03:29 +01002232 return err;
2233}
2234
2235static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2236{
Johannes Berg4c476992010-10-04 21:36:35 +02002237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002238 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002239 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002240 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002241 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002242
Johannes Bergb9454e82009-07-08 13:29:08 +02002243 err = nl80211_parse_key(info, &key);
2244 if (err)
2245 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002246
2247 if (info->attrs[NL80211_ATTR_MAC])
2248 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2249
Johannes Berge31b8212010-10-05 19:39:30 +02002250 if (key.type == -1) {
2251 if (mac_addr)
2252 key.type = NL80211_KEYTYPE_PAIRWISE;
2253 else
2254 key.type = NL80211_KEYTYPE_GROUP;
2255 }
2256
2257 /* for now */
2258 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2259 key.type != NL80211_KEYTYPE_GROUP)
2260 return -EINVAL;
2261
Johannes Berg4c476992010-10-04 21:36:35 +02002262 if (!rdev->ops->del_key)
2263 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002264
Johannes Bergfffd0932009-07-08 14:22:54 +02002265 wdev_lock(dev->ieee80211_ptr);
2266 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002267
2268 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2269 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2270 err = -ENOENT;
2271
Johannes Bergfffd0932009-07-08 14:22:54 +02002272 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002273 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2274 key.type == NL80211_KEYTYPE_PAIRWISE,
2275 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002276
Johannes Berg3d23e342009-09-29 23:27:28 +02002277#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002278 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002279 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002280 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002281 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002282 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2283 }
2284#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002285 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002286
Johannes Berg41ade002007-12-19 02:03:29 +01002287 return err;
2288}
2289
Johannes Berg88600202012-02-13 15:17:18 +01002290static int nl80211_parse_beacon(struct genl_info *info,
2291 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002292{
Johannes Berg88600202012-02-13 15:17:18 +01002293 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002294
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002295 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2296 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2297 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2298 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002299 return -EINVAL;
2300
Johannes Berg88600202012-02-13 15:17:18 +01002301 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002302
Johannes Berged1b6cc2007-12-19 02:03:32 +01002303 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002304 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2305 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2306 if (!bcn->head_len)
2307 return -EINVAL;
2308 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002309 }
2310
2311 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002312 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2313 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002314 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002315 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002316 }
2317
Johannes Berg4c476992010-10-04 21:36:35 +02002318 if (!haveinfo)
2319 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002320
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002321 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002322 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2323 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002324 }
2325
2326 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002327 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002328 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002329 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002330 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2331 }
2332
2333 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002334 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002335 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002336 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002337 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2338 }
2339
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002340 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002341 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002342 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002343 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002344 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2345 }
2346
Johannes Berg88600202012-02-13 15:17:18 +01002347 return 0;
2348}
2349
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002350static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2351 struct cfg80211_ap_settings *params)
2352{
2353 struct wireless_dev *wdev;
2354 bool ret = false;
2355
2356 mutex_lock(&rdev->devlist_mtx);
2357
2358 list_for_each_entry(wdev, &rdev->netdev_list, list) {
2359 if (wdev->iftype != NL80211_IFTYPE_AP &&
2360 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2361 continue;
2362
2363 if (!wdev->preset_chan)
2364 continue;
2365
2366 params->channel = wdev->preset_chan;
2367 params->channel_type = wdev->preset_chantype;
2368 ret = true;
2369 break;
2370 }
2371
2372 mutex_unlock(&rdev->devlist_mtx);
2373
2374 return ret;
2375}
2376
Johannes Berg88600202012-02-13 15:17:18 +01002377static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2378{
2379 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2380 struct net_device *dev = info->user_ptr[1];
2381 struct wireless_dev *wdev = dev->ieee80211_ptr;
2382 struct cfg80211_ap_settings params;
2383 int err;
2384
2385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2386 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2387 return -EOPNOTSUPP;
2388
2389 if (!rdev->ops->start_ap)
2390 return -EOPNOTSUPP;
2391
2392 if (wdev->beacon_interval)
2393 return -EALREADY;
2394
2395 memset(&params, 0, sizeof(params));
2396
2397 /* these are required for START_AP */
2398 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2399 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2400 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2401 return -EINVAL;
2402
2403 err = nl80211_parse_beacon(info, &params.beacon);
2404 if (err)
2405 return err;
2406
2407 params.beacon_interval =
2408 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2409 params.dtim_period =
2410 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2411
2412 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2413 if (err)
2414 return err;
2415
2416 /*
2417 * In theory, some of these attributes should be required here
2418 * but since they were not used when the command was originally
2419 * added, keep them optional for old user space programs to let
2420 * them continue to work with drivers that do not need the
2421 * additional information -- drivers must check!
2422 */
2423 if (info->attrs[NL80211_ATTR_SSID]) {
2424 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2425 params.ssid_len =
2426 nla_len(info->attrs[NL80211_ATTR_SSID]);
2427 if (params.ssid_len == 0 ||
2428 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2429 return -EINVAL;
2430 }
2431
2432 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2433 params.hidden_ssid = nla_get_u32(
2434 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2435 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2436 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2437 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2438 return -EINVAL;
2439 }
2440
2441 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2442
2443 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2444 params.auth_type = nla_get_u32(
2445 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2446 if (!nl80211_valid_auth_type(params.auth_type))
2447 return -EINVAL;
2448 } else
2449 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2450
2451 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2452 NL80211_MAX_NR_CIPHER_SUITES);
2453 if (err)
2454 return err;
2455
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302456 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2457 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2458 return -EOPNOTSUPP;
2459 params.inactivity_timeout = nla_get_u16(
2460 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2461 }
2462
Johannes Bergaa430da2012-05-16 23:50:18 +02002463 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2464 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2465
2466 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2467 !nl80211_valid_channel_type(info, &channel_type))
2468 return -EINVAL;
2469
2470 params.channel = rdev_freq_to_chan(rdev,
2471 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2472 channel_type);
2473 if (!params.channel)
2474 return -EINVAL;
2475 params.channel_type = channel_type;
2476 } else if (wdev->preset_chan) {
2477 params.channel = wdev->preset_chan;
2478 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002479 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002480 return -EINVAL;
2481
2482 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2483 params.channel_type))
2484 return -EINVAL;
2485
Johannes Berg88600202012-02-13 15:17:18 +01002486 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002487 if (!err) {
2488 wdev->preset_chan = params.channel;
2489 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002490 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002491 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002492 }
Johannes Berg56d18932011-05-09 18:41:15 +02002493 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002494}
2495
Johannes Berg88600202012-02-13 15:17:18 +01002496static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2497{
2498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2499 struct net_device *dev = info->user_ptr[1];
2500 struct wireless_dev *wdev = dev->ieee80211_ptr;
2501 struct cfg80211_beacon_data params;
2502 int err;
2503
2504 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2505 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2506 return -EOPNOTSUPP;
2507
2508 if (!rdev->ops->change_beacon)
2509 return -EOPNOTSUPP;
2510
2511 if (!wdev->beacon_interval)
2512 return -EINVAL;
2513
2514 err = nl80211_parse_beacon(info, &params);
2515 if (err)
2516 return err;
2517
2518 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2519}
2520
2521static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002522{
Johannes Berg4c476992010-10-04 21:36:35 +02002523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2524 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002525
Michal Kazior60771782012-06-29 12:46:56 +02002526 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002527}
2528
Johannes Berg5727ef12007-12-19 02:03:34 +01002529static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2530 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2531 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2532 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002533 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002534 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002535 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002536};
2537
Johannes Bergeccb8e82009-05-11 21:57:56 +03002538static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002539 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002540 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002541{
2542 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002543 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002544 int flag;
2545
Johannes Bergeccb8e82009-05-11 21:57:56 +03002546 /*
2547 * Try parsing the new attribute first so userspace
2548 * can specify both for older kernels.
2549 */
2550 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2551 if (nla) {
2552 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002553
Johannes Bergeccb8e82009-05-11 21:57:56 +03002554 sta_flags = nla_data(nla);
2555 params->sta_flags_mask = sta_flags->mask;
2556 params->sta_flags_set = sta_flags->set;
2557 if ((params->sta_flags_mask |
2558 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2559 return -EINVAL;
2560 return 0;
2561 }
2562
2563 /* if present, parse the old attribute */
2564
2565 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002566 if (!nla)
2567 return 0;
2568
2569 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2570 nla, sta_flags_policy))
2571 return -EINVAL;
2572
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002573 /*
2574 * Only allow certain flags for interface types so that
2575 * other attributes are silently ignored. Remember that
2576 * this is backward compatibility code with old userspace
2577 * and shouldn't be hit in other cases anyway.
2578 */
2579 switch (iftype) {
2580 case NL80211_IFTYPE_AP:
2581 case NL80211_IFTYPE_AP_VLAN:
2582 case NL80211_IFTYPE_P2P_GO:
2583 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2584 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2585 BIT(NL80211_STA_FLAG_WME) |
2586 BIT(NL80211_STA_FLAG_MFP);
2587 break;
2588 case NL80211_IFTYPE_P2P_CLIENT:
2589 case NL80211_IFTYPE_STATION:
2590 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2591 BIT(NL80211_STA_FLAG_TDLS_PEER);
2592 break;
2593 case NL80211_IFTYPE_MESH_POINT:
2594 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2595 BIT(NL80211_STA_FLAG_MFP) |
2596 BIT(NL80211_STA_FLAG_AUTHORIZED);
2597 default:
2598 return -EINVAL;
2599 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002600
Johannes Berg3383b5a2012-05-10 20:14:43 +02002601 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2602 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002603 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002604
Johannes Berg3383b5a2012-05-10 20:14:43 +02002605 /* no longer support new API additions in old API */
2606 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2607 return -EINVAL;
2608 }
2609 }
2610
Johannes Berg5727ef12007-12-19 02:03:34 +01002611 return 0;
2612}
2613
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002614static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2615 int attr)
2616{
2617 struct nlattr *rate;
2618 u16 bitrate;
2619
2620 rate = nla_nest_start(msg, attr);
2621 if (!rate)
2622 goto nla_put_failure;
2623
2624 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2625 bitrate = cfg80211_calculate_bitrate(info);
David S. Miller9360ffd2012-03-29 04:41:26 -04002626 if ((bitrate > 0 &&
2627 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
2628 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2629 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2630 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2631 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2632 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2633 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2634 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002635
2636 nla_nest_end(msg, rate);
2637 return true;
2638
2639nla_put_failure:
2640 return false;
2641}
2642
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002643static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002644 int flags,
2645 struct cfg80211_registered_device *rdev,
2646 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002647 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002648{
2649 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002650 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002651
2652 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2653 if (!hdr)
2654 return -1;
2655
David S. Miller9360ffd2012-03-29 04:41:26 -04002656 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2657 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2658 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2659 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002660
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002661 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2662 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002663 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002664 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2665 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2666 sinfo->connected_time))
2667 goto nla_put_failure;
2668 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2669 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2670 sinfo->inactive_time))
2671 goto nla_put_failure;
2672 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2673 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2674 sinfo->rx_bytes))
2675 goto nla_put_failure;
2676 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2677 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2678 sinfo->tx_bytes))
2679 goto nla_put_failure;
2680 if ((sinfo->filled & STATION_INFO_LLID) &&
2681 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2682 goto nla_put_failure;
2683 if ((sinfo->filled & STATION_INFO_PLID) &&
2684 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2685 goto nla_put_failure;
2686 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2687 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2688 sinfo->plink_state))
2689 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002690 switch (rdev->wiphy.signal_type) {
2691 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002692 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2693 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2694 sinfo->signal))
2695 goto nla_put_failure;
2696 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2697 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2698 sinfo->signal_avg))
2699 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002700 break;
2701 default:
2702 break;
2703 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002704 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002705 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2706 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002707 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002708 }
2709 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2710 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2711 NL80211_STA_INFO_RX_BITRATE))
2712 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002713 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002714 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2715 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2716 sinfo->rx_packets))
2717 goto nla_put_failure;
2718 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2719 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2720 sinfo->tx_packets))
2721 goto nla_put_failure;
2722 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2723 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2724 sinfo->tx_retries))
2725 goto nla_put_failure;
2726 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2727 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2728 sinfo->tx_failed))
2729 goto nla_put_failure;
2730 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2731 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2732 sinfo->beacon_loss_count))
2733 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002734 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2735 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2736 if (!bss_param)
2737 goto nla_put_failure;
2738
David S. Miller9360ffd2012-03-29 04:41:26 -04002739 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2740 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2741 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2742 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2743 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2744 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2745 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2746 sinfo->bss_param.dtim_period) ||
2747 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2748 sinfo->bss_param.beacon_interval))
2749 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002750
2751 nla_nest_end(msg, bss_param);
2752 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002753 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2754 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2755 sizeof(struct nl80211_sta_flag_update),
2756 &sinfo->sta_flags))
2757 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002758 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2759 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2760 sinfo->t_offset))
2761 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002762 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002763
David S. Miller9360ffd2012-03-29 04:41:26 -04002764 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2765 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2766 sinfo->assoc_req_ies))
2767 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002768
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002769 return genlmsg_end(msg, hdr);
2770
2771 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002772 genlmsg_cancel(msg, hdr);
2773 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002774}
2775
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002776static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002777 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002778{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002779 struct station_info sinfo;
2780 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002781 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002782 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002783 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002784 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002785
Johannes Berg67748892010-10-04 21:14:06 +02002786 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2787 if (err)
2788 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002789
2790 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002791 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002792 goto out_err;
2793 }
2794
Johannes Bergbba95fe2008-07-29 13:22:51 +02002795 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002796 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002797 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2798 mac_addr, &sinfo);
2799 if (err == -ENOENT)
2800 break;
2801 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002802 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002803
2804 if (nl80211_send_station(skb,
2805 NETLINK_CB(cb->skb).pid,
2806 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002807 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002808 &sinfo) < 0)
2809 goto out;
2810
2811 sta_idx++;
2812 }
2813
2814
2815 out:
2816 cb->args[1] = sta_idx;
2817 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002818 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002819 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002820
2821 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002822}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002823
Johannes Berg5727ef12007-12-19 02:03:34 +01002824static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2825{
Johannes Berg4c476992010-10-04 21:36:35 +02002826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2827 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002828 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002829 struct sk_buff *msg;
2830 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002831 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002832
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002833 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002834
2835 if (!info->attrs[NL80211_ATTR_MAC])
2836 return -EINVAL;
2837
2838 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2839
Johannes Berg4c476992010-10-04 21:36:35 +02002840 if (!rdev->ops->get_station)
2841 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002842
Johannes Berg79c97e92009-07-07 03:56:12 +02002843 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002844 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002845 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002846
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002847 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002848 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002849 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002850
2851 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002852 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002853 nlmsg_free(msg);
2854 return -ENOBUFS;
2855 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002856
Johannes Berg4c476992010-10-04 21:36:35 +02002857 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002858}
2859
2860/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002861 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002862 */
Johannes Berg80b99892011-11-18 16:23:01 +01002863static struct net_device *get_vlan(struct genl_info *info,
2864 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002865{
Johannes Berg463d0182009-07-14 00:33:35 +02002866 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002867 struct net_device *v;
2868 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002869
Johannes Berg80b99892011-11-18 16:23:01 +01002870 if (!vlanattr)
2871 return NULL;
2872
2873 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2874 if (!v)
2875 return ERR_PTR(-ENODEV);
2876
2877 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2878 ret = -EINVAL;
2879 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002880 }
Johannes Berg80b99892011-11-18 16:23:01 +01002881
2882 if (!netif_running(v)) {
2883 ret = -ENETDOWN;
2884 goto error;
2885 }
2886
2887 return v;
2888 error:
2889 dev_put(v);
2890 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002891}
2892
2893static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2894{
Johannes Berg4c476992010-10-04 21:36:35 +02002895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002896 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002897 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002898 struct station_parameters params;
2899 u8 *mac_addr = NULL;
2900
2901 memset(&params, 0, sizeof(params));
2902
2903 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002904 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002905
2906 if (info->attrs[NL80211_ATTR_STA_AID])
2907 return -EINVAL;
2908
2909 if (!info->attrs[NL80211_ATTR_MAC])
2910 return -EINVAL;
2911
2912 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2913
2914 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2915 params.supported_rates =
2916 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2917 params.supported_rates_len =
2918 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2919 }
2920
2921 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2922 params.listen_interval =
2923 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2924
Jouni Malinen36aedc902008-08-25 11:58:58 +03002925 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2926 params.ht_capa =
2927 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2928
Johannes Bergbdd90d52011-12-14 12:20:27 +01002929 if (!rdev->ops->change_station)
2930 return -EOPNOTSUPP;
2931
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002932 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002933 return -EINVAL;
2934
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002935 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2936 params.plink_action =
2937 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2938
Javier Cardona9c3990a2011-05-03 16:57:11 -07002939 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2940 params.plink_state =
2941 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2942
Johannes Berga97f4422009-06-18 17:23:43 +02002943 switch (dev->ieee80211_ptr->iftype) {
2944 case NL80211_IFTYPE_AP:
2945 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002946 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002947 /* disallow mesh-specific things */
2948 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002949 return -EINVAL;
2950
2951 /* TDLS can't be set, ... */
2952 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2953 return -EINVAL;
2954 /*
2955 * ... but don't bother the driver with it. This works around
2956 * a hostapd/wpa_supplicant issue -- it always includes the
2957 * TLDS_PEER flag in the mask even for AP mode.
2958 */
2959 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2960
2961 /* accept only the listed bits */
2962 if (params.sta_flags_mask &
2963 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2964 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2965 BIT(NL80211_STA_FLAG_WME) |
2966 BIT(NL80211_STA_FLAG_MFP)))
2967 return -EINVAL;
2968
2969 /* must be last in here for error handling */
2970 params.vlan = get_vlan(info, rdev);
2971 if (IS_ERR(params.vlan))
2972 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002973 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002974 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002975 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002976 /*
2977 * Don't allow userspace to change the TDLS_PEER flag,
2978 * but silently ignore attempts to change it since we
2979 * don't have state here to verify that it doesn't try
2980 * to change the flag.
2981 */
2982 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002983 /* fall through */
2984 case NL80211_IFTYPE_ADHOC:
2985 /* disallow things sta doesn't support */
2986 if (params.plink_action)
2987 return -EINVAL;
2988 if (params.ht_capa)
2989 return -EINVAL;
2990 if (params.listen_interval >= 0)
2991 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01002992 /* reject any changes other than AUTHORIZED */
2993 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2994 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02002995 break;
2996 case NL80211_IFTYPE_MESH_POINT:
2997 /* disallow things mesh doesn't support */
2998 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002999 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003000 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003001 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003002 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003003 return -EINVAL;
3004 /*
3005 * No special handling for TDLS here -- the userspace
3006 * mesh code doesn't have this bug.
3007 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003008 if (params.sta_flags_mask &
3009 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003010 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003011 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003012 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003013 break;
3014 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003015 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003016 }
3017
Johannes Bergbdd90d52011-12-14 12:20:27 +01003018 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003019
Johannes Berg79c97e92009-07-07 03:56:12 +02003020 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003021
Johannes Berg5727ef12007-12-19 02:03:34 +01003022 if (params.vlan)
3023 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003024
Johannes Berg5727ef12007-12-19 02:03:34 +01003025 return err;
3026}
3027
Eliad Pellerc75786c2011-08-23 14:37:46 +03003028static struct nla_policy
3029nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3030 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3031 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3032};
3033
Johannes Berg5727ef12007-12-19 02:03:34 +01003034static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3035{
Johannes Berg4c476992010-10-04 21:36:35 +02003036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003037 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003038 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003039 struct station_parameters params;
3040 u8 *mac_addr = NULL;
3041
3042 memset(&params, 0, sizeof(params));
3043
3044 if (!info->attrs[NL80211_ATTR_MAC])
3045 return -EINVAL;
3046
Johannes Berg5727ef12007-12-19 02:03:34 +01003047 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3048 return -EINVAL;
3049
3050 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3051 return -EINVAL;
3052
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003053 if (!info->attrs[NL80211_ATTR_STA_AID])
3054 return -EINVAL;
3055
Johannes Berg5727ef12007-12-19 02:03:34 +01003056 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3057 params.supported_rates =
3058 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3059 params.supported_rates_len =
3060 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3061 params.listen_interval =
3062 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003063
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003064 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3065 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3066 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003067
Jouni Malinen36aedc902008-08-25 11:58:58 +03003068 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3069 params.ht_capa =
3070 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003071
Javier Cardona96b78df2011-04-07 15:08:33 -07003072 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3073 params.plink_action =
3074 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3075
Johannes Bergbdd90d52011-12-14 12:20:27 +01003076 if (!rdev->ops->add_station)
3077 return -EOPNOTSUPP;
3078
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003079 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003080 return -EINVAL;
3081
Johannes Bergbdd90d52011-12-14 12:20:27 +01003082 switch (dev->ieee80211_ptr->iftype) {
3083 case NL80211_IFTYPE_AP:
3084 case NL80211_IFTYPE_AP_VLAN:
3085 case NL80211_IFTYPE_P2P_GO:
3086 /* parse WME attributes if sta is WME capable */
3087 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3088 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3089 info->attrs[NL80211_ATTR_STA_WME]) {
3090 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3091 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003092
Johannes Bergbdd90d52011-12-14 12:20:27 +01003093 nla = info->attrs[NL80211_ATTR_STA_WME];
3094 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3095 nl80211_sta_wme_policy);
3096 if (err)
3097 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003098
Johannes Bergbdd90d52011-12-14 12:20:27 +01003099 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3100 params.uapsd_queues =
3101 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3102 if (params.uapsd_queues &
3103 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3104 return -EINVAL;
3105
3106 if (tb[NL80211_STA_WME_MAX_SP])
3107 params.max_sp =
3108 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3109
3110 if (params.max_sp &
3111 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3112 return -EINVAL;
3113
3114 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3115 }
3116 /* TDLS peers cannot be added */
3117 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003118 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003119 /* but don't bother the driver with it */
3120 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003121
Johannes Bergbdd90d52011-12-14 12:20:27 +01003122 /* must be last in here for error handling */
3123 params.vlan = get_vlan(info, rdev);
3124 if (IS_ERR(params.vlan))
3125 return PTR_ERR(params.vlan);
3126 break;
3127 case NL80211_IFTYPE_MESH_POINT:
3128 /* TDLS peers cannot be added */
3129 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003130 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003131 break;
3132 case NL80211_IFTYPE_STATION:
3133 /* Only TDLS peers can be added */
3134 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3135 return -EINVAL;
3136 /* Can only add if TDLS ... */
3137 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3138 return -EOPNOTSUPP;
3139 /* ... with external setup is supported */
3140 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3141 return -EOPNOTSUPP;
3142 break;
3143 default:
3144 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003145 }
3146
Johannes Bergbdd90d52011-12-14 12:20:27 +01003147 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003148
Johannes Berg79c97e92009-07-07 03:56:12 +02003149 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003150
Johannes Berg5727ef12007-12-19 02:03:34 +01003151 if (params.vlan)
3152 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003153 return err;
3154}
3155
3156static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3157{
Johannes Berg4c476992010-10-04 21:36:35 +02003158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3159 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003160 u8 *mac_addr = NULL;
3161
3162 if (info->attrs[NL80211_ATTR_MAC])
3163 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3164
Johannes Berge80cf852009-05-11 14:43:13 +02003165 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003166 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003167 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003168 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3169 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003170
Johannes Berg4c476992010-10-04 21:36:35 +02003171 if (!rdev->ops->del_station)
3172 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003173
Johannes Berg4c476992010-10-04 21:36:35 +02003174 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003175}
3176
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003177static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3178 int flags, struct net_device *dev,
3179 u8 *dst, u8 *next_hop,
3180 struct mpath_info *pinfo)
3181{
3182 void *hdr;
3183 struct nlattr *pinfoattr;
3184
3185 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3186 if (!hdr)
3187 return -1;
3188
David S. Miller9360ffd2012-03-29 04:41:26 -04003189 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3190 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3191 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3192 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3193 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003194
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003195 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3196 if (!pinfoattr)
3197 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003198 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3199 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3200 pinfo->frame_qlen))
3201 goto nla_put_failure;
3202 if (((pinfo->filled & MPATH_INFO_SN) &&
3203 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3204 ((pinfo->filled & MPATH_INFO_METRIC) &&
3205 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3206 pinfo->metric)) ||
3207 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3208 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3209 pinfo->exptime)) ||
3210 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3211 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3212 pinfo->flags)) ||
3213 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3214 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3215 pinfo->discovery_timeout)) ||
3216 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3217 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3218 pinfo->discovery_retries)))
3219 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003220
3221 nla_nest_end(msg, pinfoattr);
3222
3223 return genlmsg_end(msg, hdr);
3224
3225 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003226 genlmsg_cancel(msg, hdr);
3227 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003228}
3229
3230static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003231 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003232{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003233 struct mpath_info pinfo;
3234 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003235 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003236 u8 dst[ETH_ALEN];
3237 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003238 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003239 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003240
Johannes Berg67748892010-10-04 21:14:06 +02003241 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3242 if (err)
3243 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003244
3245 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003246 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003247 goto out_err;
3248 }
3249
Jouni Malineneec60b02009-03-20 21:21:19 +02003250 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3251 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003252 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003253 }
3254
Johannes Bergbba95fe2008-07-29 13:22:51 +02003255 while (1) {
3256 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3257 dst, next_hop, &pinfo);
3258 if (err == -ENOENT)
3259 break;
3260 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003261 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003262
3263 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3264 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3265 netdev, dst, next_hop,
3266 &pinfo) < 0)
3267 goto out;
3268
3269 path_idx++;
3270 }
3271
3272
3273 out:
3274 cb->args[1] = path_idx;
3275 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003276 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003277 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003278 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003279}
3280
3281static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3282{
Johannes Berg4c476992010-10-04 21:36:35 +02003283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003284 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003285 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003286 struct mpath_info pinfo;
3287 struct sk_buff *msg;
3288 u8 *dst = NULL;
3289 u8 next_hop[ETH_ALEN];
3290
3291 memset(&pinfo, 0, sizeof(pinfo));
3292
3293 if (!info->attrs[NL80211_ATTR_MAC])
3294 return -EINVAL;
3295
3296 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3297
Johannes Berg4c476992010-10-04 21:36:35 +02003298 if (!rdev->ops->get_mpath)
3299 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003300
Johannes Berg4c476992010-10-04 21:36:35 +02003301 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3302 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003303
Johannes Berg79c97e92009-07-07 03:56:12 +02003304 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003305 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003306 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003307
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003308 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003309 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003310 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003311
3312 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003313 dev, dst, next_hop, &pinfo) < 0) {
3314 nlmsg_free(msg);
3315 return -ENOBUFS;
3316 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003317
Johannes Berg4c476992010-10-04 21:36:35 +02003318 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003319}
3320
3321static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3322{
Johannes Berg4c476992010-10-04 21:36:35 +02003323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3324 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003325 u8 *dst = NULL;
3326 u8 *next_hop = NULL;
3327
3328 if (!info->attrs[NL80211_ATTR_MAC])
3329 return -EINVAL;
3330
3331 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3332 return -EINVAL;
3333
3334 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3335 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3336
Johannes Berg4c476992010-10-04 21:36:35 +02003337 if (!rdev->ops->change_mpath)
3338 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003339
Johannes Berg4c476992010-10-04 21:36:35 +02003340 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3341 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003342
Johannes Berg4c476992010-10-04 21:36:35 +02003343 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003344}
Johannes Berg4c476992010-10-04 21:36:35 +02003345
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003346static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3347{
Johannes Berg4c476992010-10-04 21:36:35 +02003348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3349 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003350 u8 *dst = NULL;
3351 u8 *next_hop = NULL;
3352
3353 if (!info->attrs[NL80211_ATTR_MAC])
3354 return -EINVAL;
3355
3356 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3357 return -EINVAL;
3358
3359 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3360 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3361
Johannes Berg4c476992010-10-04 21:36:35 +02003362 if (!rdev->ops->add_mpath)
3363 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003364
Johannes Berg4c476992010-10-04 21:36:35 +02003365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3366 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003367
Johannes Berg4c476992010-10-04 21:36:35 +02003368 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003369}
3370
3371static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3372{
Johannes Berg4c476992010-10-04 21:36:35 +02003373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3374 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003375 u8 *dst = NULL;
3376
3377 if (info->attrs[NL80211_ATTR_MAC])
3378 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3379
Johannes Berg4c476992010-10-04 21:36:35 +02003380 if (!rdev->ops->del_mpath)
3381 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003382
Johannes Berg4c476992010-10-04 21:36:35 +02003383 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003384}
3385
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003386static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3387{
Johannes Berg4c476992010-10-04 21:36:35 +02003388 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3389 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003390 struct bss_parameters params;
3391
3392 memset(&params, 0, sizeof(params));
3393 /* default to not changing parameters */
3394 params.use_cts_prot = -1;
3395 params.use_short_preamble = -1;
3396 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003397 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003398 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003399
3400 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3401 params.use_cts_prot =
3402 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3403 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3404 params.use_short_preamble =
3405 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3406 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3407 params.use_short_slot_time =
3408 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003409 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3410 params.basic_rates =
3411 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3412 params.basic_rates_len =
3413 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3414 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003415 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3416 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003417 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3418 params.ht_opmode =
3419 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003420
Johannes Berg4c476992010-10-04 21:36:35 +02003421 if (!rdev->ops->change_bss)
3422 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003423
Johannes Berg074ac8d2010-09-16 14:58:22 +02003424 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003425 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3426 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003427
Johannes Berg4c476992010-10-04 21:36:35 +02003428 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003429}
3430
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003431static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003432 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3433 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3434 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3435 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3436 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3437 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3438};
3439
3440static int parse_reg_rule(struct nlattr *tb[],
3441 struct ieee80211_reg_rule *reg_rule)
3442{
3443 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3444 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3445
3446 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3447 return -EINVAL;
3448 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3449 return -EINVAL;
3450 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3451 return -EINVAL;
3452 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3453 return -EINVAL;
3454 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3455 return -EINVAL;
3456
3457 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3458
3459 freq_range->start_freq_khz =
3460 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3461 freq_range->end_freq_khz =
3462 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3463 freq_range->max_bandwidth_khz =
3464 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3465
3466 power_rule->max_eirp =
3467 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3468
3469 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3470 power_rule->max_antenna_gain =
3471 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3472
3473 return 0;
3474}
3475
3476static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3477{
3478 int r;
3479 char *data = NULL;
3480
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003481 /*
3482 * You should only get this when cfg80211 hasn't yet initialized
3483 * completely when built-in to the kernel right between the time
3484 * window between nl80211_init() and regulatory_init(), if that is
3485 * even possible.
3486 */
3487 mutex_lock(&cfg80211_mutex);
3488 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003489 mutex_unlock(&cfg80211_mutex);
3490 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003491 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003492 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003493
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003494 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3495 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003496
3497 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3498
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003499 r = regulatory_hint_user(data);
3500
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003501 return r;
3502}
3503
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003504static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003505 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003506{
Johannes Berg4c476992010-10-04 21:36:35 +02003507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003508 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003509 struct wireless_dev *wdev = dev->ieee80211_ptr;
3510 struct mesh_config cur_params;
3511 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003512 void *hdr;
3513 struct nlattr *pinfoattr;
3514 struct sk_buff *msg;
3515
Johannes Berg29cbe682010-12-03 09:20:44 +01003516 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3517 return -EOPNOTSUPP;
3518
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003519 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003520 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003521
Johannes Berg29cbe682010-12-03 09:20:44 +01003522 wdev_lock(wdev);
3523 /* If not connected, get default parameters */
3524 if (!wdev->mesh_id_len)
3525 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3526 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003527 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003528 &cur_params);
3529 wdev_unlock(wdev);
3530
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003531 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003532 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003533
3534 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003535 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003536 if (!msg)
3537 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003538 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003539 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003540 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003541 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003542 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003543 if (!pinfoattr)
3544 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003545 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3546 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3547 cur_params.dot11MeshRetryTimeout) ||
3548 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3549 cur_params.dot11MeshConfirmTimeout) ||
3550 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3551 cur_params.dot11MeshHoldingTimeout) ||
3552 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3553 cur_params.dot11MeshMaxPeerLinks) ||
3554 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3555 cur_params.dot11MeshMaxRetries) ||
3556 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3557 cur_params.dot11MeshTTL) ||
3558 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3559 cur_params.element_ttl) ||
3560 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3561 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003562 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3563 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003564 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3565 cur_params.dot11MeshHWMPmaxPREQretries) ||
3566 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3567 cur_params.path_refresh_time) ||
3568 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3569 cur_params.min_discovery_timeout) ||
3570 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3571 cur_params.dot11MeshHWMPactivePathTimeout) ||
3572 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3573 cur_params.dot11MeshHWMPpreqMinInterval) ||
3574 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3575 cur_params.dot11MeshHWMPperrMinInterval) ||
3576 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3577 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3578 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3579 cur_params.dot11MeshHWMPRootMode) ||
3580 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3581 cur_params.dot11MeshHWMPRannInterval) ||
3582 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3583 cur_params.dot11MeshGateAnnouncementProtocol) ||
3584 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3585 cur_params.dot11MeshForwarding) ||
3586 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003587 cur_params.rssi_threshold) ||
3588 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003589 cur_params.ht_opmode) ||
3590 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3591 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3592 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003593 cur_params.dot11MeshHWMProotInterval) ||
3594 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3595 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003596 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003597 nla_nest_end(msg, pinfoattr);
3598 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003599 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003600
Johannes Berg3b858752009-03-12 09:55:09 +01003601 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003602 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003603 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003604 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003605 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003606}
3607
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003608static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003609 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3610 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3611 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3612 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3613 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3614 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003615 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003616 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003617 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003618 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3619 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3620 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3621 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3622 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003623 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003624 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003625 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003626 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003627 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003628 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003629 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3630 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003631 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3632 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003633 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003634};
3635
Javier Cardonac80d5452010-12-16 17:37:49 -08003636static const struct nla_policy
3637 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003638 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003639 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3640 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003641 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003642 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003643 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003644 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003645};
3646
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003647static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003648 struct mesh_config *cfg,
3649 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003650{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003651 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003652 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003653
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003654#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3655do {\
3656 if (table[attr_num]) {\
3657 cfg->param = nla_fn(table[attr_num]); \
3658 mask |= (1 << (attr_num - 1)); \
3659 } \
3660} while (0);\
3661
3662
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003663 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003664 return -EINVAL;
3665 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003666 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003667 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003668 return -EINVAL;
3669
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003670 /* This makes sure that there aren't more than 32 mesh config
3671 * parameters (otherwise our bitfield scheme would not work.) */
3672 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3673
3674 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003676 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3677 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003679 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3680 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003682 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3683 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003685 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3686 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003688 mask, NL80211_MESHCONF_MAX_RETRIES,
3689 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003690 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003691 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003693 mask, NL80211_MESHCONF_ELEMENT_TTL,
3694 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003696 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3697 nla_get_u8);
3698 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3699 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3700 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003701 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003702 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3703 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003705 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3706 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003708 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3709 nla_get_u16);
3710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3711 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3712 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003714 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3715 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003717 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3718 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003719 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003720 dot11MeshHWMPnetDiameterTraversalTime, mask,
3721 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3722 nla_get_u16);
3723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3724 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3725 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3726 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3727 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003728 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003729 dot11MeshGateAnnouncementProtocol, mask,
3730 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3731 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003732 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003733 mask, NL80211_MESHCONF_FORWARDING,
3734 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003735 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003736 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3737 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003738 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003739 mask, NL80211_MESHCONF_HT_OPMODE,
3740 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3742 mask,
3743 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3744 nla_get_u32);
3745 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3746 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3747 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3749 dot11MeshHWMPconfirmationInterval, mask,
3750 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3751 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003752 if (mask_out)
3753 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003754
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003755 return 0;
3756
3757#undef FILL_IN_MESH_PARAM_IF_SET
3758}
3759
Javier Cardonac80d5452010-12-16 17:37:49 -08003760static int nl80211_parse_mesh_setup(struct genl_info *info,
3761 struct mesh_setup *setup)
3762{
3763 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3764
3765 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3766 return -EINVAL;
3767 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3768 info->attrs[NL80211_ATTR_MESH_SETUP],
3769 nl80211_mesh_setup_params_policy))
3770 return -EINVAL;
3771
Javier Cardonad299a1f2012-03-31 11:31:33 -07003772 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3773 setup->sync_method =
3774 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3775 IEEE80211_SYNC_METHOD_VENDOR :
3776 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3777
Javier Cardonac80d5452010-12-16 17:37:49 -08003778 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3779 setup->path_sel_proto =
3780 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3781 IEEE80211_PATH_PROTOCOL_VENDOR :
3782 IEEE80211_PATH_PROTOCOL_HWMP;
3783
3784 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3785 setup->path_metric =
3786 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3787 IEEE80211_PATH_METRIC_VENDOR :
3788 IEEE80211_PATH_METRIC_AIRTIME;
3789
Javier Cardona581a8b02011-04-07 15:08:27 -07003790
3791 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003792 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003793 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003794 if (!is_valid_ie_attr(ieattr))
3795 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003796 setup->ie = nla_data(ieattr);
3797 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003798 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003799 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3800 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003801
3802 return 0;
3803}
3804
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003805static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003806 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003807{
3808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3809 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003810 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003811 struct mesh_config cfg;
3812 u32 mask;
3813 int err;
3814
Johannes Berg29cbe682010-12-03 09:20:44 +01003815 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3816 return -EOPNOTSUPP;
3817
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003818 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003819 return -EOPNOTSUPP;
3820
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003821 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003822 if (err)
3823 return err;
3824
Johannes Berg29cbe682010-12-03 09:20:44 +01003825 wdev_lock(wdev);
3826 if (!wdev->mesh_id_len)
3827 err = -ENOLINK;
3828
3829 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003830 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003831 mask, &cfg);
3832
3833 wdev_unlock(wdev);
3834
3835 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003836}
3837
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003838static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3839{
3840 struct sk_buff *msg;
3841 void *hdr = NULL;
3842 struct nlattr *nl_reg_rules;
3843 unsigned int i;
3844 int err = -EINVAL;
3845
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003846 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003847
3848 if (!cfg80211_regdomain)
3849 goto out;
3850
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003852 if (!msg) {
3853 err = -ENOBUFS;
3854 goto out;
3855 }
3856
3857 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3858 NL80211_CMD_GET_REG);
3859 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003860 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003861
David S. Miller9360ffd2012-03-29 04:41:26 -04003862 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3863 cfg80211_regdomain->alpha2) ||
3864 (cfg80211_regdomain->dfs_region &&
3865 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3866 cfg80211_regdomain->dfs_region)))
3867 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003868
3869 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3870 if (!nl_reg_rules)
3871 goto nla_put_failure;
3872
3873 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3874 struct nlattr *nl_reg_rule;
3875 const struct ieee80211_reg_rule *reg_rule;
3876 const struct ieee80211_freq_range *freq_range;
3877 const struct ieee80211_power_rule *power_rule;
3878
3879 reg_rule = &cfg80211_regdomain->reg_rules[i];
3880 freq_range = &reg_rule->freq_range;
3881 power_rule = &reg_rule->power_rule;
3882
3883 nl_reg_rule = nla_nest_start(msg, i);
3884 if (!nl_reg_rule)
3885 goto nla_put_failure;
3886
David S. Miller9360ffd2012-03-29 04:41:26 -04003887 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3888 reg_rule->flags) ||
3889 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3890 freq_range->start_freq_khz) ||
3891 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3892 freq_range->end_freq_khz) ||
3893 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3894 freq_range->max_bandwidth_khz) ||
3895 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3896 power_rule->max_antenna_gain) ||
3897 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3898 power_rule->max_eirp))
3899 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003900
3901 nla_nest_end(msg, nl_reg_rule);
3902 }
3903
3904 nla_nest_end(msg, nl_reg_rules);
3905
3906 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003907 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003908 goto out;
3909
3910nla_put_failure:
3911 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003912put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003913 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003914 err = -EMSGSIZE;
3915out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003916 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003917 return err;
3918}
3919
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003920static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3921{
3922 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3923 struct nlattr *nl_reg_rule;
3924 char *alpha2 = NULL;
3925 int rem_reg_rules = 0, r = 0;
3926 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003927 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003928 struct ieee80211_regdomain *rd = NULL;
3929
3930 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3931 return -EINVAL;
3932
3933 if (!info->attrs[NL80211_ATTR_REG_RULES])
3934 return -EINVAL;
3935
3936 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3937
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003938 if (info->attrs[NL80211_ATTR_DFS_REGION])
3939 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3940
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003941 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3942 rem_reg_rules) {
3943 num_rules++;
3944 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003945 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003946 }
3947
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003948 mutex_lock(&cfg80211_mutex);
3949
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003950 if (!reg_is_valid_request(alpha2)) {
3951 r = -EINVAL;
3952 goto bad_reg;
3953 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003954
3955 size_of_regd = sizeof(struct ieee80211_regdomain) +
3956 (num_rules * sizeof(struct ieee80211_reg_rule));
3957
3958 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003959 if (!rd) {
3960 r = -ENOMEM;
3961 goto bad_reg;
3962 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003963
3964 rd->n_reg_rules = num_rules;
3965 rd->alpha2[0] = alpha2[0];
3966 rd->alpha2[1] = alpha2[1];
3967
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003968 /*
3969 * Disable DFS master mode if the DFS region was
3970 * not supported or known on this kernel.
3971 */
3972 if (reg_supported_dfs_region(dfs_region))
3973 rd->dfs_region = dfs_region;
3974
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003975 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3976 rem_reg_rules) {
3977 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3978 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3979 reg_rule_policy);
3980 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3981 if (r)
3982 goto bad_reg;
3983
3984 rule_idx++;
3985
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003986 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3987 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003988 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003989 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003990 }
3991
3992 BUG_ON(rule_idx != num_rules);
3993
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003994 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003995
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003996 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003997
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003998 return r;
3999
Johannes Bergd2372b32008-10-24 20:32:20 +02004000 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004001 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004002 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004003 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004004}
4005
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004006static int validate_scan_freqs(struct nlattr *freqs)
4007{
4008 struct nlattr *attr1, *attr2;
4009 int n_channels = 0, tmp1, tmp2;
4010
4011 nla_for_each_nested(attr1, freqs, tmp1) {
4012 n_channels++;
4013 /*
4014 * Some hardware has a limited channel list for
4015 * scanning, and it is pretty much nonsensical
4016 * to scan for a channel twice, so disallow that
4017 * and don't require drivers to check that the
4018 * channel list they get isn't longer than what
4019 * they can scan, as long as they can scan all
4020 * the channels they registered at once.
4021 */
4022 nla_for_each_nested(attr2, freqs, tmp2)
4023 if (attr1 != attr2 &&
4024 nla_get_u32(attr1) == nla_get_u32(attr2))
4025 return 0;
4026 }
4027
4028 return n_channels;
4029}
4030
Johannes Berg2a519312009-02-10 21:25:55 +01004031static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4032{
Johannes Berg4c476992010-10-04 21:36:35 +02004033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4034 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004035 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004036 struct nlattr *attr;
4037 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004038 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004039 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004040
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004041 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4042 return -EINVAL;
4043
Johannes Berg79c97e92009-07-07 03:56:12 +02004044 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004045
Johannes Berg4c476992010-10-04 21:36:35 +02004046 if (!rdev->ops->scan)
4047 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004048
Johannes Berg4c476992010-10-04 21:36:35 +02004049 if (rdev->scan_req)
4050 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004051
4052 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004053 n_channels = validate_scan_freqs(
4054 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004055 if (!n_channels)
4056 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004057 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004058 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004059 n_channels = 0;
4060
Johannes Berg2a519312009-02-10 21:25:55 +01004061 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4062 if (wiphy->bands[band])
4063 n_channels += wiphy->bands[band]->n_channels;
4064 }
4065
4066 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4067 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4068 n_ssids++;
4069
Johannes Berg4c476992010-10-04 21:36:35 +02004070 if (n_ssids > wiphy->max_scan_ssids)
4071 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004072
Jouni Malinen70692ad2009-02-16 19:39:13 +02004073 if (info->attrs[NL80211_ATTR_IE])
4074 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4075 else
4076 ie_len = 0;
4077
Johannes Berg4c476992010-10-04 21:36:35 +02004078 if (ie_len > wiphy->max_scan_ie_len)
4079 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004080
Johannes Berg2a519312009-02-10 21:25:55 +01004081 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004082 + sizeof(*request->ssids) * n_ssids
4083 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004084 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004085 if (!request)
4086 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004087
Johannes Berg2a519312009-02-10 21:25:55 +01004088 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004089 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004090 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004091 if (ie_len) {
4092 if (request->ssids)
4093 request->ie = (void *)(request->ssids + n_ssids);
4094 else
4095 request->ie = (void *)(request->channels + n_channels);
4096 }
Johannes Berg2a519312009-02-10 21:25:55 +01004097
Johannes Berg584991d2009-11-02 13:32:03 +01004098 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004099 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4100 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004101 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004102 struct ieee80211_channel *chan;
4103
4104 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4105
4106 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004107 err = -EINVAL;
4108 goto out_free;
4109 }
Johannes Berg584991d2009-11-02 13:32:03 +01004110
4111 /* ignore disabled channels */
4112 if (chan->flags & IEEE80211_CHAN_DISABLED)
4113 continue;
4114
4115 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004116 i++;
4117 }
4118 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004119 enum ieee80211_band band;
4120
Johannes Berg2a519312009-02-10 21:25:55 +01004121 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004122 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4123 int j;
4124 if (!wiphy->bands[band])
4125 continue;
4126 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004127 struct ieee80211_channel *chan;
4128
4129 chan = &wiphy->bands[band]->channels[j];
4130
4131 if (chan->flags & IEEE80211_CHAN_DISABLED)
4132 continue;
4133
4134 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004135 i++;
4136 }
4137 }
4138 }
4139
Johannes Berg584991d2009-11-02 13:32:03 +01004140 if (!i) {
4141 err = -EINVAL;
4142 goto out_free;
4143 }
4144
4145 request->n_channels = i;
4146
Johannes Berg2a519312009-02-10 21:25:55 +01004147 i = 0;
4148 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4149 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004150 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004151 err = -EINVAL;
4152 goto out_free;
4153 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004154 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004155 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004156 i++;
4157 }
4158 }
4159
Jouni Malinen70692ad2009-02-16 19:39:13 +02004160 if (info->attrs[NL80211_ATTR_IE]) {
4161 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004162 memcpy((void *)request->ie,
4163 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004164 request->ie_len);
4165 }
4166
Johannes Berg34850ab2011-07-18 18:08:35 +02004167 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004168 if (wiphy->bands[i])
4169 request->rates[i] =
4170 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004171
4172 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4173 nla_for_each_nested(attr,
4174 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4175 tmp) {
4176 enum ieee80211_band band = nla_type(attr);
4177
Dan Carpenter84404622011-07-29 11:52:18 +03004178 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004179 err = -EINVAL;
4180 goto out_free;
4181 }
4182 err = ieee80211_get_ratemask(wiphy->bands[band],
4183 nla_data(attr),
4184 nla_len(attr),
4185 &request->rates[band]);
4186 if (err)
4187 goto out_free;
4188 }
4189 }
4190
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304191 request->no_cck =
4192 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4193
Johannes Berg463d0182009-07-14 00:33:35 +02004194 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004195 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004196
Johannes Berg79c97e92009-07-07 03:56:12 +02004197 rdev->scan_req = request;
4198 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004199
Johannes Berg463d0182009-07-14 00:33:35 +02004200 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004201 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004202 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004203 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004204 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004205 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004206 kfree(request);
4207 }
Johannes Berg3b858752009-03-12 09:55:09 +01004208
Johannes Berg2a519312009-02-10 21:25:55 +01004209 return err;
4210}
4211
Luciano Coelho807f8a82011-05-11 17:09:35 +03004212static int nl80211_start_sched_scan(struct sk_buff *skb,
4213 struct genl_info *info)
4214{
4215 struct cfg80211_sched_scan_request *request;
4216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4217 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004218 struct nlattr *attr;
4219 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004220 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004221 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004222 enum ieee80211_band band;
4223 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004224 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004225
4226 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4227 !rdev->ops->sched_scan_start)
4228 return -EOPNOTSUPP;
4229
4230 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4231 return -EINVAL;
4232
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004233 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4234 return -EINVAL;
4235
4236 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4237 if (interval == 0)
4238 return -EINVAL;
4239
Luciano Coelho807f8a82011-05-11 17:09:35 +03004240 wiphy = &rdev->wiphy;
4241
4242 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4243 n_channels = validate_scan_freqs(
4244 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4245 if (!n_channels)
4246 return -EINVAL;
4247 } else {
4248 n_channels = 0;
4249
4250 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4251 if (wiphy->bands[band])
4252 n_channels += wiphy->bands[band]->n_channels;
4253 }
4254
4255 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4256 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4257 tmp)
4258 n_ssids++;
4259
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004260 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004261 return -EINVAL;
4262
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004263 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4264 nla_for_each_nested(attr,
4265 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4266 tmp)
4267 n_match_sets++;
4268
4269 if (n_match_sets > wiphy->max_match_sets)
4270 return -EINVAL;
4271
Luciano Coelho807f8a82011-05-11 17:09:35 +03004272 if (info->attrs[NL80211_ATTR_IE])
4273 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4274 else
4275 ie_len = 0;
4276
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004277 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004278 return -EINVAL;
4279
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004280 mutex_lock(&rdev->sched_scan_mtx);
4281
4282 if (rdev->sched_scan_req) {
4283 err = -EINPROGRESS;
4284 goto out;
4285 }
4286
Luciano Coelho807f8a82011-05-11 17:09:35 +03004287 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004288 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004289 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004290 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004291 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004292 if (!request) {
4293 err = -ENOMEM;
4294 goto out;
4295 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004296
4297 if (n_ssids)
4298 request->ssids = (void *)&request->channels[n_channels];
4299 request->n_ssids = n_ssids;
4300 if (ie_len) {
4301 if (request->ssids)
4302 request->ie = (void *)(request->ssids + n_ssids);
4303 else
4304 request->ie = (void *)(request->channels + n_channels);
4305 }
4306
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004307 if (n_match_sets) {
4308 if (request->ie)
4309 request->match_sets = (void *)(request->ie + ie_len);
4310 else if (request->ssids)
4311 request->match_sets =
4312 (void *)(request->ssids + n_ssids);
4313 else
4314 request->match_sets =
4315 (void *)(request->channels + n_channels);
4316 }
4317 request->n_match_sets = n_match_sets;
4318
Luciano Coelho807f8a82011-05-11 17:09:35 +03004319 i = 0;
4320 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4321 /* user specified, bail out if channel not found */
4322 nla_for_each_nested(attr,
4323 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4324 tmp) {
4325 struct ieee80211_channel *chan;
4326
4327 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4328
4329 if (!chan) {
4330 err = -EINVAL;
4331 goto out_free;
4332 }
4333
4334 /* ignore disabled channels */
4335 if (chan->flags & IEEE80211_CHAN_DISABLED)
4336 continue;
4337
4338 request->channels[i] = chan;
4339 i++;
4340 }
4341 } else {
4342 /* all channels */
4343 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4344 int j;
4345 if (!wiphy->bands[band])
4346 continue;
4347 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4348 struct ieee80211_channel *chan;
4349
4350 chan = &wiphy->bands[band]->channels[j];
4351
4352 if (chan->flags & IEEE80211_CHAN_DISABLED)
4353 continue;
4354
4355 request->channels[i] = chan;
4356 i++;
4357 }
4358 }
4359 }
4360
4361 if (!i) {
4362 err = -EINVAL;
4363 goto out_free;
4364 }
4365
4366 request->n_channels = i;
4367
4368 i = 0;
4369 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4370 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4371 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004372 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004373 err = -EINVAL;
4374 goto out_free;
4375 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004376 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004377 memcpy(request->ssids[i].ssid, nla_data(attr),
4378 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004379 i++;
4380 }
4381 }
4382
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004383 i = 0;
4384 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4385 nla_for_each_nested(attr,
4386 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4387 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004388 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004389
4390 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4391 nla_data(attr), nla_len(attr),
4392 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004393 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004394 if (ssid) {
4395 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4396 err = -EINVAL;
4397 goto out_free;
4398 }
4399 memcpy(request->match_sets[i].ssid.ssid,
4400 nla_data(ssid), nla_len(ssid));
4401 request->match_sets[i].ssid.ssid_len =
4402 nla_len(ssid);
4403 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004404 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4405 if (rssi)
4406 request->rssi_thold = nla_get_u32(rssi);
4407 else
4408 request->rssi_thold =
4409 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004410 i++;
4411 }
4412 }
4413
Luciano Coelho807f8a82011-05-11 17:09:35 +03004414 if (info->attrs[NL80211_ATTR_IE]) {
4415 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4416 memcpy((void *)request->ie,
4417 nla_data(info->attrs[NL80211_ATTR_IE]),
4418 request->ie_len);
4419 }
4420
4421 request->dev = dev;
4422 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004423 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004424
4425 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4426 if (!err) {
4427 rdev->sched_scan_req = request;
4428 nl80211_send_sched_scan(rdev, dev,
4429 NL80211_CMD_START_SCHED_SCAN);
4430 goto out;
4431 }
4432
4433out_free:
4434 kfree(request);
4435out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004436 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004437 return err;
4438}
4439
4440static int nl80211_stop_sched_scan(struct sk_buff *skb,
4441 struct genl_info *info)
4442{
4443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004444 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004445
4446 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4447 !rdev->ops->sched_scan_stop)
4448 return -EOPNOTSUPP;
4449
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004450 mutex_lock(&rdev->sched_scan_mtx);
4451 err = __cfg80211_stop_sched_scan(rdev, false);
4452 mutex_unlock(&rdev->sched_scan_mtx);
4453
4454 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004455}
4456
Johannes Berg9720bb32011-06-21 09:45:33 +02004457static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4458 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004459 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004460 struct wireless_dev *wdev,
4461 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004462{
Johannes Berg48ab9052009-07-10 18:42:31 +02004463 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004464 void *hdr;
4465 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004466
4467 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004468
Johannes Berg9720bb32011-06-21 09:45:33 +02004469 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004470 NL80211_CMD_NEW_SCAN_RESULTS);
4471 if (!hdr)
4472 return -1;
4473
Johannes Berg9720bb32011-06-21 09:45:33 +02004474 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4475
David S. Miller9360ffd2012-03-29 04:41:26 -04004476 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4477 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4478 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004479
4480 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4481 if (!bss)
4482 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004483 if ((!is_zero_ether_addr(res->bssid) &&
4484 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4485 (res->information_elements && res->len_information_elements &&
4486 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4487 res->len_information_elements,
4488 res->information_elements)) ||
4489 (res->beacon_ies && res->len_beacon_ies &&
4490 res->beacon_ies != res->information_elements &&
4491 nla_put(msg, NL80211_BSS_BEACON_IES,
4492 res->len_beacon_ies, res->beacon_ies)))
4493 goto nla_put_failure;
4494 if (res->tsf &&
4495 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4496 goto nla_put_failure;
4497 if (res->beacon_interval &&
4498 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4499 goto nla_put_failure;
4500 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4501 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4502 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4503 jiffies_to_msecs(jiffies - intbss->ts)))
4504 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004505
Johannes Berg77965c92009-02-18 18:45:06 +01004506 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004507 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004508 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4509 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004510 break;
4511 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004512 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4513 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004514 break;
4515 default:
4516 break;
4517 }
4518
Johannes Berg48ab9052009-07-10 18:42:31 +02004519 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004520 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004521 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004522 if (intbss == wdev->current_bss &&
4523 nla_put_u32(msg, NL80211_BSS_STATUS,
4524 NL80211_BSS_STATUS_ASSOCIATED))
4525 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004526 break;
4527 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004528 if (intbss == wdev->current_bss &&
4529 nla_put_u32(msg, NL80211_BSS_STATUS,
4530 NL80211_BSS_STATUS_IBSS_JOINED))
4531 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004532 break;
4533 default:
4534 break;
4535 }
4536
Johannes Berg2a519312009-02-10 21:25:55 +01004537 nla_nest_end(msg, bss);
4538
4539 return genlmsg_end(msg, hdr);
4540
4541 nla_put_failure:
4542 genlmsg_cancel(msg, hdr);
4543 return -EMSGSIZE;
4544}
4545
4546static int nl80211_dump_scan(struct sk_buff *skb,
4547 struct netlink_callback *cb)
4548{
Johannes Berg48ab9052009-07-10 18:42:31 +02004549 struct cfg80211_registered_device *rdev;
4550 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004551 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004552 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004553 int start = cb->args[1], idx = 0;
4554 int err;
4555
Johannes Berg67748892010-10-04 21:14:06 +02004556 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4557 if (err)
4558 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004559
Johannes Berg48ab9052009-07-10 18:42:31 +02004560 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004561
Johannes Berg48ab9052009-07-10 18:42:31 +02004562 wdev_lock(wdev);
4563 spin_lock_bh(&rdev->bss_lock);
4564 cfg80211_bss_expire(rdev);
4565
Johannes Berg9720bb32011-06-21 09:45:33 +02004566 cb->seq = rdev->bss_generation;
4567
Johannes Berg48ab9052009-07-10 18:42:31 +02004568 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004569 if (++idx <= start)
4570 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004571 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004572 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004573 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004574 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004575 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004576 }
4577 }
4578
Johannes Berg48ab9052009-07-10 18:42:31 +02004579 spin_unlock_bh(&rdev->bss_lock);
4580 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004581
4582 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004583 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004584
Johannes Berg67748892010-10-04 21:14:06 +02004585 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004586}
4587
Holger Schurig61fa7132009-11-11 12:25:40 +01004588static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4589 int flags, struct net_device *dev,
4590 struct survey_info *survey)
4591{
4592 void *hdr;
4593 struct nlattr *infoattr;
4594
Holger Schurig61fa7132009-11-11 12:25:40 +01004595 hdr = nl80211hdr_put(msg, pid, seq, flags,
4596 NL80211_CMD_NEW_SURVEY_RESULTS);
4597 if (!hdr)
4598 return -ENOMEM;
4599
David S. Miller9360ffd2012-03-29 04:41:26 -04004600 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4601 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004602
4603 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4604 if (!infoattr)
4605 goto nla_put_failure;
4606
David S. Miller9360ffd2012-03-29 04:41:26 -04004607 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4608 survey->channel->center_freq))
4609 goto nla_put_failure;
4610
4611 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4612 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4613 goto nla_put_failure;
4614 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4615 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4616 goto nla_put_failure;
4617 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4618 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4619 survey->channel_time))
4620 goto nla_put_failure;
4621 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4622 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4623 survey->channel_time_busy))
4624 goto nla_put_failure;
4625 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4626 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4627 survey->channel_time_ext_busy))
4628 goto nla_put_failure;
4629 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4630 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4631 survey->channel_time_rx))
4632 goto nla_put_failure;
4633 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4634 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4635 survey->channel_time_tx))
4636 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004637
4638 nla_nest_end(msg, infoattr);
4639
4640 return genlmsg_end(msg, hdr);
4641
4642 nla_put_failure:
4643 genlmsg_cancel(msg, hdr);
4644 return -EMSGSIZE;
4645}
4646
4647static int nl80211_dump_survey(struct sk_buff *skb,
4648 struct netlink_callback *cb)
4649{
4650 struct survey_info survey;
4651 struct cfg80211_registered_device *dev;
4652 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004653 int survey_idx = cb->args[1];
4654 int res;
4655
Johannes Berg67748892010-10-04 21:14:06 +02004656 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4657 if (res)
4658 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004659
4660 if (!dev->ops->dump_survey) {
4661 res = -EOPNOTSUPP;
4662 goto out_err;
4663 }
4664
4665 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004666 struct ieee80211_channel *chan;
4667
Holger Schurig61fa7132009-11-11 12:25:40 +01004668 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4669 &survey);
4670 if (res == -ENOENT)
4671 break;
4672 if (res)
4673 goto out_err;
4674
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004675 /* Survey without a channel doesn't make sense */
4676 if (!survey.channel) {
4677 res = -EINVAL;
4678 goto out;
4679 }
4680
4681 chan = ieee80211_get_channel(&dev->wiphy,
4682 survey.channel->center_freq);
4683 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4684 survey_idx++;
4685 continue;
4686 }
4687
Holger Schurig61fa7132009-11-11 12:25:40 +01004688 if (nl80211_send_survey(skb,
4689 NETLINK_CB(cb->skb).pid,
4690 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4691 netdev,
4692 &survey) < 0)
4693 goto out;
4694 survey_idx++;
4695 }
4696
4697 out:
4698 cb->args[1] = survey_idx;
4699 res = skb->len;
4700 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004701 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004702 return res;
4703}
4704
Jouni Malinen255e7372009-03-20 21:21:17 +02004705static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4706{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004707 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004708}
4709
Samuel Ortizb23aa672009-07-01 21:26:54 +02004710static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4711{
4712 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4713 NL80211_WPA_VERSION_2));
4714}
4715
Jouni Malinen636a5d32009-03-19 13:39:22 +02004716static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4717{
Johannes Berg4c476992010-10-04 21:36:35 +02004718 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4719 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004720 struct ieee80211_channel *chan;
4721 const u8 *bssid, *ssid, *ie = NULL;
4722 int err, ssid_len, ie_len = 0;
4723 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004724 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004725 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004726
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004727 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4728 return -EINVAL;
4729
4730 if (!info->attrs[NL80211_ATTR_MAC])
4731 return -EINVAL;
4732
Jouni Malinen17780922009-03-27 20:52:47 +02004733 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4734 return -EINVAL;
4735
Johannes Berg19957bb2009-07-02 17:20:43 +02004736 if (!info->attrs[NL80211_ATTR_SSID])
4737 return -EINVAL;
4738
4739 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4740 return -EINVAL;
4741
Johannes Bergfffd0932009-07-08 14:22:54 +02004742 err = nl80211_parse_key(info, &key);
4743 if (err)
4744 return err;
4745
4746 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004747 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4748 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004749 if (!key.p.key || !key.p.key_len)
4750 return -EINVAL;
4751 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4752 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4753 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4754 key.p.key_len != WLAN_KEY_LEN_WEP104))
4755 return -EINVAL;
4756 if (key.idx > 4)
4757 return -EINVAL;
4758 } else {
4759 key.p.key_len = 0;
4760 key.p.key = NULL;
4761 }
4762
Johannes Bergafea0b72010-08-10 09:46:42 +02004763 if (key.idx >= 0) {
4764 int i;
4765 bool ok = false;
4766 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4767 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4768 ok = true;
4769 break;
4770 }
4771 }
Johannes Berg4c476992010-10-04 21:36:35 +02004772 if (!ok)
4773 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004774 }
4775
Johannes Berg4c476992010-10-04 21:36:35 +02004776 if (!rdev->ops->auth)
4777 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004778
Johannes Berg074ac8d2010-09-16 14:58:22 +02004779 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004780 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4781 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004782
Johannes Berg19957bb2009-07-02 17:20:43 +02004783 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004784 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004785 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004786 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4787 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004788
Johannes Berg19957bb2009-07-02 17:20:43 +02004789 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4790 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4791
4792 if (info->attrs[NL80211_ATTR_IE]) {
4793 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4794 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4795 }
4796
4797 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004798 if (!nl80211_valid_auth_type(auth_type))
4799 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004800
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004801 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4802
Johannes Berg95de8172012-01-20 13:55:25 +01004803 /*
4804 * Since we no longer track auth state, ignore
4805 * requests to only change local state.
4806 */
4807 if (local_state_change)
4808 return 0;
4809
Johannes Berg4c476992010-10-04 21:36:35 +02004810 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4811 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004812 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004813}
4814
Johannes Bergc0692b82010-08-27 14:26:53 +03004815static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4816 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004817 struct cfg80211_crypto_settings *settings,
4818 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004819{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004820 memset(settings, 0, sizeof(*settings));
4821
Samuel Ortizb23aa672009-07-01 21:26:54 +02004822 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4823
Johannes Bergc0692b82010-08-27 14:26:53 +03004824 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4825 u16 proto;
4826 proto = nla_get_u16(
4827 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4828 settings->control_port_ethertype = cpu_to_be16(proto);
4829 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4830 proto != ETH_P_PAE)
4831 return -EINVAL;
4832 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4833 settings->control_port_no_encrypt = true;
4834 } else
4835 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4836
Samuel Ortizb23aa672009-07-01 21:26:54 +02004837 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4838 void *data;
4839 int len, i;
4840
4841 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4842 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4843 settings->n_ciphers_pairwise = len / sizeof(u32);
4844
4845 if (len % sizeof(u32))
4846 return -EINVAL;
4847
Johannes Berg3dc27d22009-07-02 21:36:37 +02004848 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004849 return -EINVAL;
4850
4851 memcpy(settings->ciphers_pairwise, data, len);
4852
4853 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004854 if (!cfg80211_supported_cipher_suite(
4855 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004856 settings->ciphers_pairwise[i]))
4857 return -EINVAL;
4858 }
4859
4860 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4861 settings->cipher_group =
4862 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004863 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4864 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004865 return -EINVAL;
4866 }
4867
4868 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4869 settings->wpa_versions =
4870 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4871 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4872 return -EINVAL;
4873 }
4874
4875 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4876 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004877 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004878
4879 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4880 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4881 settings->n_akm_suites = len / sizeof(u32);
4882
4883 if (len % sizeof(u32))
4884 return -EINVAL;
4885
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004886 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4887 return -EINVAL;
4888
Samuel Ortizb23aa672009-07-01 21:26:54 +02004889 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004890 }
4891
4892 return 0;
4893}
4894
Jouni Malinen636a5d32009-03-19 13:39:22 +02004895static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4896{
Johannes Berg4c476992010-10-04 21:36:35 +02004897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4898 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004899 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004900 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004901 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004902 int err, ssid_len, ie_len = 0;
4903 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004904 u32 flags = 0;
4905 struct ieee80211_ht_cap *ht_capa = NULL;
4906 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004907
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004908 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4909 return -EINVAL;
4910
4911 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004912 !info->attrs[NL80211_ATTR_SSID] ||
4913 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004914 return -EINVAL;
4915
Johannes Berg4c476992010-10-04 21:36:35 +02004916 if (!rdev->ops->assoc)
4917 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004918
Johannes Berg074ac8d2010-09-16 14:58:22 +02004919 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004920 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4921 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004922
Johannes Berg19957bb2009-07-02 17:20:43 +02004923 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004924
Johannes Berg19957bb2009-07-02 17:20:43 +02004925 chan = ieee80211_get_channel(&rdev->wiphy,
4926 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004927 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4928 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004929
Johannes Berg19957bb2009-07-02 17:20:43 +02004930 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4931 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004932
4933 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004934 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4935 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004936 }
4937
Jouni Malinendc6382c2009-05-06 22:09:37 +03004938 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004939 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004940 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004941 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004942 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004943 else if (mfp != NL80211_MFP_NO)
4944 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004945 }
4946
Johannes Berg3e5d7642009-07-07 14:37:26 +02004947 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4948 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4949
Ben Greear7e7c8922011-11-18 11:31:59 -08004950 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4951 flags |= ASSOC_REQ_DISABLE_HT;
4952
4953 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4954 ht_capa_mask =
4955 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4956
4957 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4958 if (!ht_capa_mask)
4959 return -EINVAL;
4960 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4961 }
4962
Johannes Bergc0692b82010-08-27 14:26:53 +03004963 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004964 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004965 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4966 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004967 &crypto, flags, ht_capa,
4968 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004969
Jouni Malinen636a5d32009-03-19 13:39:22 +02004970 return err;
4971}
4972
4973static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4974{
Johannes Berg4c476992010-10-04 21:36:35 +02004975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4976 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004977 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004978 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004979 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004980 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004981
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004982 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4983 return -EINVAL;
4984
4985 if (!info->attrs[NL80211_ATTR_MAC])
4986 return -EINVAL;
4987
4988 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4989 return -EINVAL;
4990
Johannes Berg4c476992010-10-04 21:36:35 +02004991 if (!rdev->ops->deauth)
4992 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004993
Johannes Berg074ac8d2010-09-16 14:58:22 +02004994 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004995 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4996 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004997
Johannes Berg19957bb2009-07-02 17:20:43 +02004998 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004999
Johannes Berg19957bb2009-07-02 17:20:43 +02005000 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5001 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005002 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005003 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005004 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005005
5006 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005007 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5008 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005009 }
5010
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005011 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5012
Johannes Berg4c476992010-10-04 21:36:35 +02005013 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5014 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005015}
5016
5017static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5018{
Johannes Berg4c476992010-10-04 21:36:35 +02005019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5020 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005021 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005022 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005023 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005024 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005025
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005026 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5027 return -EINVAL;
5028
5029 if (!info->attrs[NL80211_ATTR_MAC])
5030 return -EINVAL;
5031
5032 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5033 return -EINVAL;
5034
Johannes Berg4c476992010-10-04 21:36:35 +02005035 if (!rdev->ops->disassoc)
5036 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005037
Johannes Berg074ac8d2010-09-16 14:58:22 +02005038 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005039 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5040 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005041
Johannes Berg19957bb2009-07-02 17:20:43 +02005042 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005043
Johannes Berg19957bb2009-07-02 17:20:43 +02005044 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5045 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005046 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005047 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005048 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005049
5050 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005051 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5052 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005053 }
5054
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005055 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5056
Johannes Berg4c476992010-10-04 21:36:35 +02005057 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5058 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005059}
5060
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005061static bool
5062nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5063 int mcast_rate[IEEE80211_NUM_BANDS],
5064 int rateval)
5065{
5066 struct wiphy *wiphy = &rdev->wiphy;
5067 bool found = false;
5068 int band, i;
5069
5070 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5071 struct ieee80211_supported_band *sband;
5072
5073 sband = wiphy->bands[band];
5074 if (!sband)
5075 continue;
5076
5077 for (i = 0; i < sband->n_bitrates; i++) {
5078 if (sband->bitrates[i].bitrate == rateval) {
5079 mcast_rate[band] = i + 1;
5080 found = true;
5081 break;
5082 }
5083 }
5084 }
5085
5086 return found;
5087}
5088
Johannes Berg04a773a2009-04-19 21:24:32 +02005089static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5090{
Johannes Berg4c476992010-10-04 21:36:35 +02005091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5092 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005093 struct cfg80211_ibss_params ibss;
5094 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005095 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005096 int err;
5097
Johannes Berg8e30bc52009-04-22 17:45:38 +02005098 memset(&ibss, 0, sizeof(ibss));
5099
Johannes Berg04a773a2009-04-19 21:24:32 +02005100 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5101 return -EINVAL;
5102
5103 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5104 !info->attrs[NL80211_ATTR_SSID] ||
5105 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5106 return -EINVAL;
5107
Johannes Berg8e30bc52009-04-22 17:45:38 +02005108 ibss.beacon_interval = 100;
5109
5110 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5111 ibss.beacon_interval =
5112 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5113 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5114 return -EINVAL;
5115 }
5116
Johannes Berg4c476992010-10-04 21:36:35 +02005117 if (!rdev->ops->join_ibss)
5118 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005119
Johannes Berg4c476992010-10-04 21:36:35 +02005120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5121 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005122
Johannes Berg79c97e92009-07-07 03:56:12 +02005123 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005124
Johannes Berg39193492011-09-16 13:45:25 +02005125 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005126 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005127
5128 if (!is_valid_ether_addr(ibss.bssid))
5129 return -EINVAL;
5130 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005131 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5132 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5133
5134 if (info->attrs[NL80211_ATTR_IE]) {
5135 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5136 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5137 }
5138
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005139 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5140 enum nl80211_channel_type channel_type;
5141
Johannes Bergcd6c6592012-05-10 21:27:18 +02005142 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005143 return -EINVAL;
5144
5145 if (channel_type != NL80211_CHAN_NO_HT &&
5146 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5147 return -EINVAL;
5148
5149 ibss.channel_type = channel_type;
5150 } else {
5151 ibss.channel_type = NL80211_CHAN_NO_HT;
5152 }
5153
5154 ibss.channel = rdev_freq_to_chan(rdev,
5155 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5156 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005157 if (!ibss.channel ||
5158 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005159 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5160 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005161
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005162 /* Both channels should be able to initiate communication */
5163 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5164 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5165 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5166 ibss.channel_type))
5167 return -EINVAL;
5168
Johannes Berg04a773a2009-04-19 21:24:32 +02005169 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005170 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005171
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005172 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5173 u8 *rates =
5174 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5175 int n_rates =
5176 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5177 struct ieee80211_supported_band *sband =
5178 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005179
Johannes Berg34850ab2011-07-18 18:08:35 +02005180 err = ieee80211_get_ratemask(sband, rates, n_rates,
5181 &ibss.basic_rates);
5182 if (err)
5183 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005184 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005185
5186 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5187 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5188 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5189 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005190
Johannes Berg4c476992010-10-04 21:36:35 +02005191 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5192 connkeys = nl80211_parse_connkeys(rdev,
5193 info->attrs[NL80211_ATTR_KEYS]);
5194 if (IS_ERR(connkeys))
5195 return PTR_ERR(connkeys);
5196 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005197
Antonio Quartulli267335d2012-01-31 20:25:47 +01005198 ibss.control_port =
5199 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5200
Johannes Berg4c476992010-10-04 21:36:35 +02005201 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005202 if (err)
5203 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005204 return err;
5205}
5206
5207static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5208{
Johannes Berg4c476992010-10-04 21:36:35 +02005209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5210 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005211
Johannes Berg4c476992010-10-04 21:36:35 +02005212 if (!rdev->ops->leave_ibss)
5213 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005214
Johannes Berg4c476992010-10-04 21:36:35 +02005215 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5216 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005217
Johannes Berg4c476992010-10-04 21:36:35 +02005218 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005219}
5220
Johannes Bergaff89a92009-07-01 21:26:51 +02005221#ifdef CONFIG_NL80211_TESTMODE
5222static struct genl_multicast_group nl80211_testmode_mcgrp = {
5223 .name = "testmode",
5224};
5225
5226static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5227{
Johannes Berg4c476992010-10-04 21:36:35 +02005228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005229 int err;
5230
5231 if (!info->attrs[NL80211_ATTR_TESTDATA])
5232 return -EINVAL;
5233
Johannes Bergaff89a92009-07-01 21:26:51 +02005234 err = -EOPNOTSUPP;
5235 if (rdev->ops->testmode_cmd) {
5236 rdev->testmode_info = info;
5237 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5238 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5239 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5240 rdev->testmode_info = NULL;
5241 }
5242
Johannes Bergaff89a92009-07-01 21:26:51 +02005243 return err;
5244}
5245
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005246static int nl80211_testmode_dump(struct sk_buff *skb,
5247 struct netlink_callback *cb)
5248{
Johannes Berg00918d32011-12-13 17:22:05 +01005249 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005250 int err;
5251 long phy_idx;
5252 void *data = NULL;
5253 int data_len = 0;
5254
5255 if (cb->args[0]) {
5256 /*
5257 * 0 is a valid index, but not valid for args[0],
5258 * so we need to offset by 1.
5259 */
5260 phy_idx = cb->args[0] - 1;
5261 } else {
5262 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5263 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5264 nl80211_policy);
5265 if (err)
5266 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005267
Johannes Berg2bd7e352012-06-15 14:23:16 +02005268 mutex_lock(&cfg80211_mutex);
5269 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5270 nl80211_fam.attrbuf);
5271 if (IS_ERR(rdev)) {
5272 mutex_unlock(&cfg80211_mutex);
5273 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005274 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005275 phy_idx = rdev->wiphy_idx;
5276 rdev = NULL;
5277 mutex_unlock(&cfg80211_mutex);
5278
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005279 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5280 cb->args[1] =
5281 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5282 }
5283
5284 if (cb->args[1]) {
5285 data = nla_data((void *)cb->args[1]);
5286 data_len = nla_len((void *)cb->args[1]);
5287 }
5288
5289 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005290 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5291 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005292 mutex_unlock(&cfg80211_mutex);
5293 return -ENOENT;
5294 }
Johannes Berg00918d32011-12-13 17:22:05 +01005295 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005296 mutex_unlock(&cfg80211_mutex);
5297
Johannes Berg00918d32011-12-13 17:22:05 +01005298 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005299 err = -EOPNOTSUPP;
5300 goto out_err;
5301 }
5302
5303 while (1) {
5304 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5305 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5306 NL80211_CMD_TESTMODE);
5307 struct nlattr *tmdata;
5308
David S. Miller9360ffd2012-03-29 04:41:26 -04005309 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005310 genlmsg_cancel(skb, hdr);
5311 break;
5312 }
5313
5314 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5315 if (!tmdata) {
5316 genlmsg_cancel(skb, hdr);
5317 break;
5318 }
Johannes Berg00918d32011-12-13 17:22:05 +01005319 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5320 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005321 nla_nest_end(skb, tmdata);
5322
5323 if (err == -ENOBUFS || err == -ENOENT) {
5324 genlmsg_cancel(skb, hdr);
5325 break;
5326 } else if (err) {
5327 genlmsg_cancel(skb, hdr);
5328 goto out_err;
5329 }
5330
5331 genlmsg_end(skb, hdr);
5332 }
5333
5334 err = skb->len;
5335 /* see above */
5336 cb->args[0] = phy_idx + 1;
5337 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005338 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005339 return err;
5340}
5341
Johannes Bergaff89a92009-07-01 21:26:51 +02005342static struct sk_buff *
5343__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5344 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5345{
5346 struct sk_buff *skb;
5347 void *hdr;
5348 struct nlattr *data;
5349
5350 skb = nlmsg_new(approxlen + 100, gfp);
5351 if (!skb)
5352 return NULL;
5353
5354 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5355 if (!hdr) {
5356 kfree_skb(skb);
5357 return NULL;
5358 }
5359
David S. Miller9360ffd2012-03-29 04:41:26 -04005360 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5361 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005362 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5363
5364 ((void **)skb->cb)[0] = rdev;
5365 ((void **)skb->cb)[1] = hdr;
5366 ((void **)skb->cb)[2] = data;
5367
5368 return skb;
5369
5370 nla_put_failure:
5371 kfree_skb(skb);
5372 return NULL;
5373}
5374
5375struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5376 int approxlen)
5377{
5378 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5379
5380 if (WARN_ON(!rdev->testmode_info))
5381 return NULL;
5382
5383 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5384 rdev->testmode_info->snd_pid,
5385 rdev->testmode_info->snd_seq,
5386 GFP_KERNEL);
5387}
5388EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5389
5390int cfg80211_testmode_reply(struct sk_buff *skb)
5391{
5392 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5393 void *hdr = ((void **)skb->cb)[1];
5394 struct nlattr *data = ((void **)skb->cb)[2];
5395
5396 if (WARN_ON(!rdev->testmode_info)) {
5397 kfree_skb(skb);
5398 return -EINVAL;
5399 }
5400
5401 nla_nest_end(skb, data);
5402 genlmsg_end(skb, hdr);
5403 return genlmsg_reply(skb, rdev->testmode_info);
5404}
5405EXPORT_SYMBOL(cfg80211_testmode_reply);
5406
5407struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5408 int approxlen, gfp_t gfp)
5409{
5410 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5411
5412 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5413}
5414EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5415
5416void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5417{
5418 void *hdr = ((void **)skb->cb)[1];
5419 struct nlattr *data = ((void **)skb->cb)[2];
5420
5421 nla_nest_end(skb, data);
5422 genlmsg_end(skb, hdr);
5423 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5424}
5425EXPORT_SYMBOL(cfg80211_testmode_event);
5426#endif
5427
Samuel Ortizb23aa672009-07-01 21:26:54 +02005428static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5429{
Johannes Berg4c476992010-10-04 21:36:35 +02005430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5431 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005432 struct cfg80211_connect_params connect;
5433 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005434 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005435 int err;
5436
5437 memset(&connect, 0, sizeof(connect));
5438
5439 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5440 return -EINVAL;
5441
5442 if (!info->attrs[NL80211_ATTR_SSID] ||
5443 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5444 return -EINVAL;
5445
5446 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5447 connect.auth_type =
5448 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5449 if (!nl80211_valid_auth_type(connect.auth_type))
5450 return -EINVAL;
5451 } else
5452 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5453
5454 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5455
Johannes Bergc0692b82010-08-27 14:26:53 +03005456 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005457 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005458 if (err)
5459 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005460
Johannes Berg074ac8d2010-09-16 14:58:22 +02005461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005462 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5463 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005464
Johannes Berg79c97e92009-07-07 03:56:12 +02005465 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005466
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305467 connect.bg_scan_period = -1;
5468 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5469 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5470 connect.bg_scan_period =
5471 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5472 }
5473
Samuel Ortizb23aa672009-07-01 21:26:54 +02005474 if (info->attrs[NL80211_ATTR_MAC])
5475 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5476 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5477 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5478
5479 if (info->attrs[NL80211_ATTR_IE]) {
5480 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5481 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5482 }
5483
5484 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5485 connect.channel =
5486 ieee80211_get_channel(wiphy,
5487 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5488 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005489 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5490 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005491 }
5492
Johannes Bergfffd0932009-07-08 14:22:54 +02005493 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5494 connkeys = nl80211_parse_connkeys(rdev,
5495 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005496 if (IS_ERR(connkeys))
5497 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005498 }
5499
Ben Greear7e7c8922011-11-18 11:31:59 -08005500 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5501 connect.flags |= ASSOC_REQ_DISABLE_HT;
5502
5503 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5504 memcpy(&connect.ht_capa_mask,
5505 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5506 sizeof(connect.ht_capa_mask));
5507
5508 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5509 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5510 return -EINVAL;
5511 memcpy(&connect.ht_capa,
5512 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5513 sizeof(connect.ht_capa));
5514 }
5515
Johannes Bergfffd0932009-07-08 14:22:54 +02005516 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005517 if (err)
5518 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005519 return err;
5520}
5521
5522static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5523{
Johannes Berg4c476992010-10-04 21:36:35 +02005524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5525 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005526 u16 reason;
5527
5528 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5529 reason = WLAN_REASON_DEAUTH_LEAVING;
5530 else
5531 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5532
5533 if (reason == 0)
5534 return -EINVAL;
5535
Johannes Berg074ac8d2010-09-16 14:58:22 +02005536 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005537 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5538 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005539
Johannes Berg4c476992010-10-04 21:36:35 +02005540 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005541}
5542
Johannes Berg463d0182009-07-14 00:33:35 +02005543static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5544{
Johannes Berg4c476992010-10-04 21:36:35 +02005545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005546 struct net *net;
5547 int err;
5548 u32 pid;
5549
5550 if (!info->attrs[NL80211_ATTR_PID])
5551 return -EINVAL;
5552
5553 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5554
Johannes Berg463d0182009-07-14 00:33:35 +02005555 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005556 if (IS_ERR(net))
5557 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005558
5559 err = 0;
5560
5561 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005562 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5563 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005564
Johannes Berg463d0182009-07-14 00:33:35 +02005565 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005566 return err;
5567}
5568
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005569static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5570{
Johannes Berg4c476992010-10-04 21:36:35 +02005571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005572 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5573 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005574 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005575 struct cfg80211_pmksa pmksa;
5576
5577 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5578
5579 if (!info->attrs[NL80211_ATTR_MAC])
5580 return -EINVAL;
5581
5582 if (!info->attrs[NL80211_ATTR_PMKID])
5583 return -EINVAL;
5584
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005585 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5586 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5587
Johannes Berg074ac8d2010-09-16 14:58:22 +02005588 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005589 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5590 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005591
5592 switch (info->genlhdr->cmd) {
5593 case NL80211_CMD_SET_PMKSA:
5594 rdev_ops = rdev->ops->set_pmksa;
5595 break;
5596 case NL80211_CMD_DEL_PMKSA:
5597 rdev_ops = rdev->ops->del_pmksa;
5598 break;
5599 default:
5600 WARN_ON(1);
5601 break;
5602 }
5603
Johannes Berg4c476992010-10-04 21:36:35 +02005604 if (!rdev_ops)
5605 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005606
Johannes Berg4c476992010-10-04 21:36:35 +02005607 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005608}
5609
5610static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5611{
Johannes Berg4c476992010-10-04 21:36:35 +02005612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5613 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005614
Johannes Berg074ac8d2010-09-16 14:58:22 +02005615 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005616 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5617 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005618
Johannes Berg4c476992010-10-04 21:36:35 +02005619 if (!rdev->ops->flush_pmksa)
5620 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005621
Johannes Berg4c476992010-10-04 21:36:35 +02005622 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005623}
5624
Arik Nemtsov109086c2011-09-28 14:12:50 +03005625static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5626{
5627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5628 struct net_device *dev = info->user_ptr[1];
5629 u8 action_code, dialog_token;
5630 u16 status_code;
5631 u8 *peer;
5632
5633 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5634 !rdev->ops->tdls_mgmt)
5635 return -EOPNOTSUPP;
5636
5637 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5638 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5639 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5640 !info->attrs[NL80211_ATTR_IE] ||
5641 !info->attrs[NL80211_ATTR_MAC])
5642 return -EINVAL;
5643
5644 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5645 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5646 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5647 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5648
5649 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5650 dialog_token, status_code,
5651 nla_data(info->attrs[NL80211_ATTR_IE]),
5652 nla_len(info->attrs[NL80211_ATTR_IE]));
5653}
5654
5655static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5656{
5657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5658 struct net_device *dev = info->user_ptr[1];
5659 enum nl80211_tdls_operation operation;
5660 u8 *peer;
5661
5662 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5663 !rdev->ops->tdls_oper)
5664 return -EOPNOTSUPP;
5665
5666 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5667 !info->attrs[NL80211_ATTR_MAC])
5668 return -EINVAL;
5669
5670 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5671 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5672
5673 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5674}
5675
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005676static int nl80211_remain_on_channel(struct sk_buff *skb,
5677 struct genl_info *info)
5678{
Johannes Berg4c476992010-10-04 21:36:35 +02005679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5680 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005681 struct ieee80211_channel *chan;
5682 struct sk_buff *msg;
5683 void *hdr;
5684 u64 cookie;
5685 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5686 u32 freq, duration;
5687 int err;
5688
5689 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5690 !info->attrs[NL80211_ATTR_DURATION])
5691 return -EINVAL;
5692
5693 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5694
Johannes Berg7c4ef712011-11-18 15:33:48 +01005695 if (!rdev->ops->remain_on_channel ||
5696 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005697 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005698
Johannes Bergebf348f2012-06-01 12:50:54 +02005699 /*
5700 * We should be on that channel for at least a minimum amount of
5701 * time (10ms) but no longer than the driver supports.
5702 */
5703 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5704 duration > rdev->wiphy.max_remain_on_channel_duration)
5705 return -EINVAL;
5706
Johannes Bergcd6c6592012-05-10 21:27:18 +02005707 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5708 !nl80211_valid_channel_type(info, &channel_type))
5709 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005710
5711 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5712 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005713 if (chan == NULL)
5714 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005715
5716 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005717 if (!msg)
5718 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005719
5720 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5721 NL80211_CMD_REMAIN_ON_CHANNEL);
5722
5723 if (IS_ERR(hdr)) {
5724 err = PTR_ERR(hdr);
5725 goto free_msg;
5726 }
5727
5728 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5729 channel_type, duration, &cookie);
5730
5731 if (err)
5732 goto free_msg;
5733
David S. Miller9360ffd2012-03-29 04:41:26 -04005734 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5735 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005736
5737 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005738
5739 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005740
5741 nla_put_failure:
5742 err = -ENOBUFS;
5743 free_msg:
5744 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005745 return err;
5746}
5747
5748static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5749 struct genl_info *info)
5750{
Johannes Berg4c476992010-10-04 21:36:35 +02005751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5752 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005753 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005754
5755 if (!info->attrs[NL80211_ATTR_COOKIE])
5756 return -EINVAL;
5757
Johannes Berg4c476992010-10-04 21:36:35 +02005758 if (!rdev->ops->cancel_remain_on_channel)
5759 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005760
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005761 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5762
Johannes Berg4c476992010-10-04 21:36:35 +02005763 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005764}
5765
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005766static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5767 u8 *rates, u8 rates_len)
5768{
5769 u8 i;
5770 u32 mask = 0;
5771
5772 for (i = 0; i < rates_len; i++) {
5773 int rate = (rates[i] & 0x7f) * 5;
5774 int ridx;
5775 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5776 struct ieee80211_rate *srate =
5777 &sband->bitrates[ridx];
5778 if (rate == srate->bitrate) {
5779 mask |= 1 << ridx;
5780 break;
5781 }
5782 }
5783 if (ridx == sband->n_bitrates)
5784 return 0; /* rate not found */
5785 }
5786
5787 return mask;
5788}
5789
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005790static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5791 u8 *rates, u8 rates_len,
5792 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5793{
5794 u8 i;
5795
5796 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5797
5798 for (i = 0; i < rates_len; i++) {
5799 int ridx, rbit;
5800
5801 ridx = rates[i] / 8;
5802 rbit = BIT(rates[i] % 8);
5803
5804 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005805 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005806 return false;
5807
5808 /* check availability */
5809 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5810 mcs[ridx] |= rbit;
5811 else
5812 return false;
5813 }
5814
5815 return true;
5816}
5817
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005818static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005819 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5820 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005821 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5822 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005823};
5824
5825static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5826 struct genl_info *info)
5827{
5828 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005830 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005831 int rem, i;
5832 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005833 struct nlattr *tx_rates;
5834 struct ieee80211_supported_band *sband;
5835
5836 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5837 return -EINVAL;
5838
Johannes Berg4c476992010-10-04 21:36:35 +02005839 if (!rdev->ops->set_bitrate_mask)
5840 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005841
5842 memset(&mask, 0, sizeof(mask));
5843 /* Default to all rates enabled */
5844 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5845 sband = rdev->wiphy.bands[i];
5846 mask.control[i].legacy =
5847 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005848 if (sband)
5849 memcpy(mask.control[i].mcs,
5850 sband->ht_cap.mcs.rx_mask,
5851 sizeof(mask.control[i].mcs));
5852 else
5853 memset(mask.control[i].mcs, 0,
5854 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005855 }
5856
5857 /*
5858 * The nested attribute uses enum nl80211_band as the index. This maps
5859 * directly to the enum ieee80211_band values used in cfg80211.
5860 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005861 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005862 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5863 {
5864 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005865 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5866 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005867 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005868 if (sband == NULL)
5869 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005870 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5871 nla_len(tx_rates), nl80211_txattr_policy);
5872 if (tb[NL80211_TXRATE_LEGACY]) {
5873 mask.control[band].legacy = rateset_to_mask(
5874 sband,
5875 nla_data(tb[NL80211_TXRATE_LEGACY]),
5876 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305877 if ((mask.control[band].legacy == 0) &&
5878 nla_len(tb[NL80211_TXRATE_LEGACY]))
5879 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005880 }
5881 if (tb[NL80211_TXRATE_MCS]) {
5882 if (!ht_rateset_to_mask(
5883 sband,
5884 nla_data(tb[NL80211_TXRATE_MCS]),
5885 nla_len(tb[NL80211_TXRATE_MCS]),
5886 mask.control[band].mcs))
5887 return -EINVAL;
5888 }
5889
5890 if (mask.control[band].legacy == 0) {
5891 /* don't allow empty legacy rates if HT
5892 * is not even supported. */
5893 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5894 return -EINVAL;
5895
5896 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5897 if (mask.control[band].mcs[i])
5898 break;
5899
5900 /* legacy and mcs rates may not be both empty */
5901 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005902 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005903 }
5904 }
5905
Johannes Berg4c476992010-10-04 21:36:35 +02005906 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005907}
5908
Johannes Berg2e161f72010-08-12 15:38:38 +02005909static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005910{
Johannes Berg4c476992010-10-04 21:36:35 +02005911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5912 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005913 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005914
5915 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5916 return -EINVAL;
5917
Johannes Berg2e161f72010-08-12 15:38:38 +02005918 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5919 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005920
Johannes Berg9d38d852010-06-09 17:20:33 +02005921 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005922 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005923 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5924 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5925 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005926 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005927 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5928 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005929
5930 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005931 if (!rdev->ops->mgmt_tx)
5932 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005933
Johannes Berg4c476992010-10-04 21:36:35 +02005934 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005935 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005936 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5937 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005938}
5939
Johannes Berg2e161f72010-08-12 15:38:38 +02005940static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005941{
Johannes Berg4c476992010-10-04 21:36:35 +02005942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5943 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005944 struct ieee80211_channel *chan;
5945 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005946 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005947 u32 freq;
5948 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005949 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005950 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005951 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005952 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005953 bool offchan, no_cck, dont_wait_for_ack;
5954
5955 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005956
5957 if (!info->attrs[NL80211_ATTR_FRAME] ||
5958 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5959 return -EINVAL;
5960
Johannes Berg4c476992010-10-04 21:36:35 +02005961 if (!rdev->ops->mgmt_tx)
5962 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005963
Johannes Berg9d38d852010-06-09 17:20:33 +02005964 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005965 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005966 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5967 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5968 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005969 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005970 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5971 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005972
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005973 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005974 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005975 return -EINVAL;
5976 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005977
5978 /*
5979 * We should wait on the channel for at least a minimum amount
5980 * of time (10ms) but no longer than the driver supports.
5981 */
5982 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5983 wait > rdev->wiphy.max_remain_on_channel_duration)
5984 return -EINVAL;
5985
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005986 }
5987
Jouni Malinen026331c2010-02-15 12:53:10 +02005988 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005989 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005990 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005991 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02005992 }
5993
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005994 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5995
Johannes Berg7c4ef712011-11-18 15:33:48 +01005996 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5997 return -EINVAL;
5998
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305999 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6000
Jouni Malinen026331c2010-02-15 12:53:10 +02006001 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6002 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006003 if (chan == NULL)
6004 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006005
Johannes Berge247bd902011-11-04 11:18:21 +01006006 if (!dont_wait_for_ack) {
6007 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6008 if (!msg)
6009 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006010
Johannes Berge247bd902011-11-04 11:18:21 +01006011 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6012 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006013
Johannes Berge247bd902011-11-04 11:18:21 +01006014 if (IS_ERR(hdr)) {
6015 err = PTR_ERR(hdr);
6016 goto free_msg;
6017 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006018 }
Johannes Berge247bd902011-11-04 11:18:21 +01006019
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006020 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
6021 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006022 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6023 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006024 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006025 if (err)
6026 goto free_msg;
6027
Johannes Berge247bd902011-11-04 11:18:21 +01006028 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006029 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6030 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006031
Johannes Berge247bd902011-11-04 11:18:21 +01006032 genlmsg_end(msg, hdr);
6033 return genlmsg_reply(msg, info);
6034 }
6035
6036 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006037
6038 nla_put_failure:
6039 err = -ENOBUFS;
6040 free_msg:
6041 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006042 return err;
6043}
6044
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006045static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6046{
6047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6048 struct net_device *dev = info->user_ptr[1];
6049 u64 cookie;
6050
6051 if (!info->attrs[NL80211_ATTR_COOKIE])
6052 return -EINVAL;
6053
6054 if (!rdev->ops->mgmt_tx_cancel_wait)
6055 return -EOPNOTSUPP;
6056
6057 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6058 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6059 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6060 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6061 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6062 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6063 return -EOPNOTSUPP;
6064
6065 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6066
6067 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6068}
6069
Kalle Valoffb9eb32010-02-17 17:58:10 +02006070static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6071{
Johannes Berg4c476992010-10-04 21:36:35 +02006072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006073 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006074 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006075 u8 ps_state;
6076 bool state;
6077 int err;
6078
Johannes Berg4c476992010-10-04 21:36:35 +02006079 if (!info->attrs[NL80211_ATTR_PS_STATE])
6080 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006081
6082 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6083
Johannes Berg4c476992010-10-04 21:36:35 +02006084 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6085 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006086
6087 wdev = dev->ieee80211_ptr;
6088
Johannes Berg4c476992010-10-04 21:36:35 +02006089 if (!rdev->ops->set_power_mgmt)
6090 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006091
6092 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6093
6094 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006095 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006096
Johannes Berg4c476992010-10-04 21:36:35 +02006097 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6098 wdev->ps_timeout);
6099 if (!err)
6100 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006101 return err;
6102}
6103
6104static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6105{
Johannes Berg4c476992010-10-04 21:36:35 +02006106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006107 enum nl80211_ps_state ps_state;
6108 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006109 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006110 struct sk_buff *msg;
6111 void *hdr;
6112 int err;
6113
Kalle Valoffb9eb32010-02-17 17:58:10 +02006114 wdev = dev->ieee80211_ptr;
6115
Johannes Berg4c476992010-10-04 21:36:35 +02006116 if (!rdev->ops->set_power_mgmt)
6117 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006118
6119 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006120 if (!msg)
6121 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006122
6123 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6124 NL80211_CMD_GET_POWER_SAVE);
6125 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006126 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006127 goto free_msg;
6128 }
6129
6130 if (wdev->ps)
6131 ps_state = NL80211_PS_ENABLED;
6132 else
6133 ps_state = NL80211_PS_DISABLED;
6134
David S. Miller9360ffd2012-03-29 04:41:26 -04006135 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6136 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006137
6138 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006139 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006140
Johannes Berg4c476992010-10-04 21:36:35 +02006141 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006142 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006143 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006144 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006145 return err;
6146}
6147
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006148static struct nla_policy
6149nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6150 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6151 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6152 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6153};
6154
6155static int nl80211_set_cqm_rssi(struct genl_info *info,
6156 s32 threshold, u32 hysteresis)
6157{
Johannes Berg4c476992010-10-04 21:36:35 +02006158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006159 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006160 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006161
6162 if (threshold > 0)
6163 return -EINVAL;
6164
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006165 wdev = dev->ieee80211_ptr;
6166
Johannes Berg4c476992010-10-04 21:36:35 +02006167 if (!rdev->ops->set_cqm_rssi_config)
6168 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006169
Johannes Berg074ac8d2010-09-16 14:58:22 +02006170 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006171 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6172 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006173
Johannes Berg4c476992010-10-04 21:36:35 +02006174 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6175 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006176}
6177
6178static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6179{
6180 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6181 struct nlattr *cqm;
6182 int err;
6183
6184 cqm = info->attrs[NL80211_ATTR_CQM];
6185 if (!cqm) {
6186 err = -EINVAL;
6187 goto out;
6188 }
6189
6190 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6191 nl80211_attr_cqm_policy);
6192 if (err)
6193 goto out;
6194
6195 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6196 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6197 s32 threshold;
6198 u32 hysteresis;
6199 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6200 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6201 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6202 } else
6203 err = -EINVAL;
6204
6205out:
6206 return err;
6207}
6208
Johannes Berg29cbe682010-12-03 09:20:44 +01006209static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6210{
6211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6212 struct net_device *dev = info->user_ptr[1];
6213 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006214 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006215 int err;
6216
6217 /* start with default */
6218 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006219 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006220
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006221 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006222 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006223 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006224 if (err)
6225 return err;
6226 }
6227
6228 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6229 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6230 return -EINVAL;
6231
Javier Cardonac80d5452010-12-16 17:37:49 -08006232 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6233 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6234
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006235 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6236 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6237 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6238 return -EINVAL;
6239
Javier Cardonac80d5452010-12-16 17:37:49 -08006240 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6241 /* parse additional setup parameters if given */
6242 err = nl80211_parse_mesh_setup(info, &setup);
6243 if (err)
6244 return err;
6245 }
6246
Johannes Bergcc1d2802012-05-16 23:50:20 +02006247 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6248 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6249
6250 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6251 !nl80211_valid_channel_type(info, &channel_type))
6252 return -EINVAL;
6253
6254 setup.channel = rdev_freq_to_chan(rdev,
6255 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6256 channel_type);
6257 if (!setup.channel)
6258 return -EINVAL;
6259 setup.channel_type = channel_type;
6260 } else {
6261 /* cfg80211_join_mesh() will sort it out */
6262 setup.channel = NULL;
6263 }
6264
Javier Cardonac80d5452010-12-16 17:37:49 -08006265 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006266}
6267
6268static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6269{
6270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6271 struct net_device *dev = info->user_ptr[1];
6272
6273 return cfg80211_leave_mesh(rdev, dev);
6274}
6275
Johannes Bergdfb89c52012-06-27 09:23:48 +02006276#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006277static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6278{
6279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6280 struct sk_buff *msg;
6281 void *hdr;
6282
6283 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6284 return -EOPNOTSUPP;
6285
6286 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6287 if (!msg)
6288 return -ENOMEM;
6289
6290 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6291 NL80211_CMD_GET_WOWLAN);
6292 if (!hdr)
6293 goto nla_put_failure;
6294
6295 if (rdev->wowlan) {
6296 struct nlattr *nl_wowlan;
6297
6298 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6299 if (!nl_wowlan)
6300 goto nla_put_failure;
6301
David S. Miller9360ffd2012-03-29 04:41:26 -04006302 if ((rdev->wowlan->any &&
6303 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6304 (rdev->wowlan->disconnect &&
6305 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6306 (rdev->wowlan->magic_pkt &&
6307 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6308 (rdev->wowlan->gtk_rekey_failure &&
6309 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6310 (rdev->wowlan->eap_identity_req &&
6311 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6312 (rdev->wowlan->four_way_handshake &&
6313 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6314 (rdev->wowlan->rfkill_release &&
6315 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6316 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006317 if (rdev->wowlan->n_patterns) {
6318 struct nlattr *nl_pats, *nl_pat;
6319 int i, pat_len;
6320
6321 nl_pats = nla_nest_start(msg,
6322 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6323 if (!nl_pats)
6324 goto nla_put_failure;
6325
6326 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6327 nl_pat = nla_nest_start(msg, i + 1);
6328 if (!nl_pat)
6329 goto nla_put_failure;
6330 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006331 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6332 DIV_ROUND_UP(pat_len, 8),
6333 rdev->wowlan->patterns[i].mask) ||
6334 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6335 pat_len,
6336 rdev->wowlan->patterns[i].pattern))
6337 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006338 nla_nest_end(msg, nl_pat);
6339 }
6340 nla_nest_end(msg, nl_pats);
6341 }
6342
6343 nla_nest_end(msg, nl_wowlan);
6344 }
6345
6346 genlmsg_end(msg, hdr);
6347 return genlmsg_reply(msg, info);
6348
6349nla_put_failure:
6350 nlmsg_free(msg);
6351 return -ENOBUFS;
6352}
6353
6354static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6355{
6356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6357 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6358 struct cfg80211_wowlan no_triggers = {};
6359 struct cfg80211_wowlan new_triggers = {};
6360 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6361 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006362 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006363
6364 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6365 return -EOPNOTSUPP;
6366
6367 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6368 goto no_triggers;
6369
6370 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6371 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6372 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6373 nl80211_wowlan_policy);
6374 if (err)
6375 return err;
6376
6377 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6378 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6379 return -EINVAL;
6380 new_triggers.any = true;
6381 }
6382
6383 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6384 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6385 return -EINVAL;
6386 new_triggers.disconnect = true;
6387 }
6388
6389 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6390 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6391 return -EINVAL;
6392 new_triggers.magic_pkt = true;
6393 }
6394
Johannes Berg77dbbb12011-07-13 10:48:55 +02006395 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6396 return -EINVAL;
6397
6398 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6399 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6400 return -EINVAL;
6401 new_triggers.gtk_rekey_failure = true;
6402 }
6403
6404 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6405 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6406 return -EINVAL;
6407 new_triggers.eap_identity_req = true;
6408 }
6409
6410 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6411 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6412 return -EINVAL;
6413 new_triggers.four_way_handshake = true;
6414 }
6415
6416 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6417 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6418 return -EINVAL;
6419 new_triggers.rfkill_release = true;
6420 }
6421
Johannes Bergff1b6e62011-05-04 15:37:28 +02006422 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6423 struct nlattr *pat;
6424 int n_patterns = 0;
6425 int rem, pat_len, mask_len;
6426 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6427
6428 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6429 rem)
6430 n_patterns++;
6431 if (n_patterns > wowlan->n_patterns)
6432 return -EINVAL;
6433
6434 new_triggers.patterns = kcalloc(n_patterns,
6435 sizeof(new_triggers.patterns[0]),
6436 GFP_KERNEL);
6437 if (!new_triggers.patterns)
6438 return -ENOMEM;
6439
6440 new_triggers.n_patterns = n_patterns;
6441 i = 0;
6442
6443 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6444 rem) {
6445 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6446 nla_data(pat), nla_len(pat), NULL);
6447 err = -EINVAL;
6448 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6449 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6450 goto error;
6451 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6452 mask_len = DIV_ROUND_UP(pat_len, 8);
6453 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6454 mask_len)
6455 goto error;
6456 if (pat_len > wowlan->pattern_max_len ||
6457 pat_len < wowlan->pattern_min_len)
6458 goto error;
6459
6460 new_triggers.patterns[i].mask =
6461 kmalloc(mask_len + pat_len, GFP_KERNEL);
6462 if (!new_triggers.patterns[i].mask) {
6463 err = -ENOMEM;
6464 goto error;
6465 }
6466 new_triggers.patterns[i].pattern =
6467 new_triggers.patterns[i].mask + mask_len;
6468 memcpy(new_triggers.patterns[i].mask,
6469 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6470 mask_len);
6471 new_triggers.patterns[i].pattern_len = pat_len;
6472 memcpy(new_triggers.patterns[i].pattern,
6473 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6474 pat_len);
6475 i++;
6476 }
6477 }
6478
6479 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6480 struct cfg80211_wowlan *ntrig;
6481 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6482 GFP_KERNEL);
6483 if (!ntrig) {
6484 err = -ENOMEM;
6485 goto error;
6486 }
6487 cfg80211_rdev_free_wowlan(rdev);
6488 rdev->wowlan = ntrig;
6489 } else {
6490 no_triggers:
6491 cfg80211_rdev_free_wowlan(rdev);
6492 rdev->wowlan = NULL;
6493 }
6494
Johannes Berg6d525632012-04-04 15:05:25 +02006495 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6496 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6497
Johannes Bergff1b6e62011-05-04 15:37:28 +02006498 return 0;
6499 error:
6500 for (i = 0; i < new_triggers.n_patterns; i++)
6501 kfree(new_triggers.patterns[i].mask);
6502 kfree(new_triggers.patterns);
6503 return err;
6504}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006505#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006506
Johannes Berge5497d72011-07-05 16:35:40 +02006507static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6508{
6509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6510 struct net_device *dev = info->user_ptr[1];
6511 struct wireless_dev *wdev = dev->ieee80211_ptr;
6512 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6513 struct cfg80211_gtk_rekey_data rekey_data;
6514 int err;
6515
6516 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6517 return -EINVAL;
6518
6519 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6520 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6521 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6522 nl80211_rekey_policy);
6523 if (err)
6524 return err;
6525
6526 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6527 return -ERANGE;
6528 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6529 return -ERANGE;
6530 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6531 return -ERANGE;
6532
6533 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6534 NL80211_KEK_LEN);
6535 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6536 NL80211_KCK_LEN);
6537 memcpy(rekey_data.replay_ctr,
6538 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6539 NL80211_REPLAY_CTR_LEN);
6540
6541 wdev_lock(wdev);
6542 if (!wdev->current_bss) {
6543 err = -ENOTCONN;
6544 goto out;
6545 }
6546
6547 if (!rdev->ops->set_rekey_data) {
6548 err = -EOPNOTSUPP;
6549 goto out;
6550 }
6551
6552 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6553 out:
6554 wdev_unlock(wdev);
6555 return err;
6556}
6557
Johannes Berg28946da2011-11-04 11:18:12 +01006558static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6559 struct genl_info *info)
6560{
6561 struct net_device *dev = info->user_ptr[1];
6562 struct wireless_dev *wdev = dev->ieee80211_ptr;
6563
6564 if (wdev->iftype != NL80211_IFTYPE_AP &&
6565 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6566 return -EINVAL;
6567
6568 if (wdev->ap_unexpected_nlpid)
6569 return -EBUSY;
6570
6571 wdev->ap_unexpected_nlpid = info->snd_pid;
6572 return 0;
6573}
6574
Johannes Berg7f6cf312011-11-04 11:18:15 +01006575static int nl80211_probe_client(struct sk_buff *skb,
6576 struct genl_info *info)
6577{
6578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6579 struct net_device *dev = info->user_ptr[1];
6580 struct wireless_dev *wdev = dev->ieee80211_ptr;
6581 struct sk_buff *msg;
6582 void *hdr;
6583 const u8 *addr;
6584 u64 cookie;
6585 int err;
6586
6587 if (wdev->iftype != NL80211_IFTYPE_AP &&
6588 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6589 return -EOPNOTSUPP;
6590
6591 if (!info->attrs[NL80211_ATTR_MAC])
6592 return -EINVAL;
6593
6594 if (!rdev->ops->probe_client)
6595 return -EOPNOTSUPP;
6596
6597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6598 if (!msg)
6599 return -ENOMEM;
6600
6601 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6602 NL80211_CMD_PROBE_CLIENT);
6603
6604 if (IS_ERR(hdr)) {
6605 err = PTR_ERR(hdr);
6606 goto free_msg;
6607 }
6608
6609 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6610
6611 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6612 if (err)
6613 goto free_msg;
6614
David S. Miller9360ffd2012-03-29 04:41:26 -04006615 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6616 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006617
6618 genlmsg_end(msg, hdr);
6619
6620 return genlmsg_reply(msg, info);
6621
6622 nla_put_failure:
6623 err = -ENOBUFS;
6624 free_msg:
6625 nlmsg_free(msg);
6626 return err;
6627}
6628
Johannes Berg5e7602302011-11-04 11:18:17 +01006629static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6630{
6631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6632
6633 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6634 return -EOPNOTSUPP;
6635
6636 if (rdev->ap_beacons_nlpid)
6637 return -EBUSY;
6638
6639 rdev->ap_beacons_nlpid = info->snd_pid;
6640
6641 return 0;
6642}
6643
Johannes Berg4c476992010-10-04 21:36:35 +02006644#define NL80211_FLAG_NEED_WIPHY 0x01
6645#define NL80211_FLAG_NEED_NETDEV 0x02
6646#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006647#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6648#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6649 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006650
6651static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6652 struct genl_info *info)
6653{
6654 struct cfg80211_registered_device *rdev;
6655 struct net_device *dev;
6656 int err;
6657 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6658
6659 if (rtnl)
6660 rtnl_lock();
6661
6662 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006663 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006664 if (IS_ERR(rdev)) {
6665 if (rtnl)
6666 rtnl_unlock();
6667 return PTR_ERR(rdev);
6668 }
6669 info->user_ptr[0] = rdev;
6670 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006671 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6672 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006673 if (err) {
6674 if (rtnl)
6675 rtnl_unlock();
6676 return err;
6677 }
Johannes Berg41265712010-10-04 21:14:05 +02006678 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6679 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006680 cfg80211_unlock_rdev(rdev);
6681 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006682 if (rtnl)
6683 rtnl_unlock();
6684 return -ENETDOWN;
6685 }
Johannes Berg4c476992010-10-04 21:36:35 +02006686 info->user_ptr[0] = rdev;
6687 info->user_ptr[1] = dev;
6688 }
6689
6690 return 0;
6691}
6692
6693static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6694 struct genl_info *info)
6695{
6696 if (info->user_ptr[0])
6697 cfg80211_unlock_rdev(info->user_ptr[0]);
6698 if (info->user_ptr[1])
6699 dev_put(info->user_ptr[1]);
6700 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6701 rtnl_unlock();
6702}
6703
Johannes Berg55682962007-09-20 13:09:35 -04006704static struct genl_ops nl80211_ops[] = {
6705 {
6706 .cmd = NL80211_CMD_GET_WIPHY,
6707 .doit = nl80211_get_wiphy,
6708 .dumpit = nl80211_dump_wiphy,
6709 .policy = nl80211_policy,
6710 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006711 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006712 },
6713 {
6714 .cmd = NL80211_CMD_SET_WIPHY,
6715 .doit = nl80211_set_wiphy,
6716 .policy = nl80211_policy,
6717 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006718 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006719 },
6720 {
6721 .cmd = NL80211_CMD_GET_INTERFACE,
6722 .doit = nl80211_get_interface,
6723 .dumpit = nl80211_dump_interface,
6724 .policy = nl80211_policy,
6725 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006726 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006727 },
6728 {
6729 .cmd = NL80211_CMD_SET_INTERFACE,
6730 .doit = nl80211_set_interface,
6731 .policy = nl80211_policy,
6732 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006733 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6734 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006735 },
6736 {
6737 .cmd = NL80211_CMD_NEW_INTERFACE,
6738 .doit = nl80211_new_interface,
6739 .policy = nl80211_policy,
6740 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006741 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6742 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006743 },
6744 {
6745 .cmd = NL80211_CMD_DEL_INTERFACE,
6746 .doit = nl80211_del_interface,
6747 .policy = nl80211_policy,
6748 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006749 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6750 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006751 },
Johannes Berg41ade002007-12-19 02:03:29 +01006752 {
6753 .cmd = NL80211_CMD_GET_KEY,
6754 .doit = nl80211_get_key,
6755 .policy = nl80211_policy,
6756 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006757 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006758 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006759 },
6760 {
6761 .cmd = NL80211_CMD_SET_KEY,
6762 .doit = nl80211_set_key,
6763 .policy = nl80211_policy,
6764 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006765 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006766 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006767 },
6768 {
6769 .cmd = NL80211_CMD_NEW_KEY,
6770 .doit = nl80211_new_key,
6771 .policy = nl80211_policy,
6772 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006773 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006774 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006775 },
6776 {
6777 .cmd = NL80211_CMD_DEL_KEY,
6778 .doit = nl80211_del_key,
6779 .policy = nl80211_policy,
6780 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006782 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006783 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006784 {
6785 .cmd = NL80211_CMD_SET_BEACON,
6786 .policy = nl80211_policy,
6787 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006788 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006790 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006791 },
6792 {
Johannes Berg88600202012-02-13 15:17:18 +01006793 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006794 .policy = nl80211_policy,
6795 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006796 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006797 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006798 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006799 },
6800 {
Johannes Berg88600202012-02-13 15:17:18 +01006801 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006802 .policy = nl80211_policy,
6803 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006804 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006805 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006806 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006807 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006808 {
6809 .cmd = NL80211_CMD_GET_STATION,
6810 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006811 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006812 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006813 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6814 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006815 },
6816 {
6817 .cmd = NL80211_CMD_SET_STATION,
6818 .doit = nl80211_set_station,
6819 .policy = nl80211_policy,
6820 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006822 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006823 },
6824 {
6825 .cmd = NL80211_CMD_NEW_STATION,
6826 .doit = nl80211_new_station,
6827 .policy = nl80211_policy,
6828 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006830 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006831 },
6832 {
6833 .cmd = NL80211_CMD_DEL_STATION,
6834 .doit = nl80211_del_station,
6835 .policy = nl80211_policy,
6836 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006838 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006839 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006840 {
6841 .cmd = NL80211_CMD_GET_MPATH,
6842 .doit = nl80211_get_mpath,
6843 .dumpit = nl80211_dump_mpath,
6844 .policy = nl80211_policy,
6845 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006847 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006848 },
6849 {
6850 .cmd = NL80211_CMD_SET_MPATH,
6851 .doit = nl80211_set_mpath,
6852 .policy = nl80211_policy,
6853 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006854 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006855 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006856 },
6857 {
6858 .cmd = NL80211_CMD_NEW_MPATH,
6859 .doit = nl80211_new_mpath,
6860 .policy = nl80211_policy,
6861 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006862 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006863 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006864 },
6865 {
6866 .cmd = NL80211_CMD_DEL_MPATH,
6867 .doit = nl80211_del_mpath,
6868 .policy = nl80211_policy,
6869 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006870 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006871 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006872 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006873 {
6874 .cmd = NL80211_CMD_SET_BSS,
6875 .doit = nl80211_set_bss,
6876 .policy = nl80211_policy,
6877 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006878 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006879 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006880 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006881 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006882 .cmd = NL80211_CMD_GET_REG,
6883 .doit = nl80211_get_reg,
6884 .policy = nl80211_policy,
6885 /* can be retrieved by unprivileged users */
6886 },
6887 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006888 .cmd = NL80211_CMD_SET_REG,
6889 .doit = nl80211_set_reg,
6890 .policy = nl80211_policy,
6891 .flags = GENL_ADMIN_PERM,
6892 },
6893 {
6894 .cmd = NL80211_CMD_REQ_SET_REG,
6895 .doit = nl80211_req_set_reg,
6896 .policy = nl80211_policy,
6897 .flags = GENL_ADMIN_PERM,
6898 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006899 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006900 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6901 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006902 .policy = nl80211_policy,
6903 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006904 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006905 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006906 },
6907 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006908 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6909 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006910 .policy = nl80211_policy,
6911 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006912 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006913 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006914 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006915 {
Johannes Berg2a519312009-02-10 21:25:55 +01006916 .cmd = NL80211_CMD_TRIGGER_SCAN,
6917 .doit = nl80211_trigger_scan,
6918 .policy = nl80211_policy,
6919 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006920 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006921 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006922 },
6923 {
6924 .cmd = NL80211_CMD_GET_SCAN,
6925 .policy = nl80211_policy,
6926 .dumpit = nl80211_dump_scan,
6927 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006928 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006929 .cmd = NL80211_CMD_START_SCHED_SCAN,
6930 .doit = nl80211_start_sched_scan,
6931 .policy = nl80211_policy,
6932 .flags = GENL_ADMIN_PERM,
6933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6934 NL80211_FLAG_NEED_RTNL,
6935 },
6936 {
6937 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6938 .doit = nl80211_stop_sched_scan,
6939 .policy = nl80211_policy,
6940 .flags = GENL_ADMIN_PERM,
6941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6942 NL80211_FLAG_NEED_RTNL,
6943 },
6944 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006945 .cmd = NL80211_CMD_AUTHENTICATE,
6946 .doit = nl80211_authenticate,
6947 .policy = nl80211_policy,
6948 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006950 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006951 },
6952 {
6953 .cmd = NL80211_CMD_ASSOCIATE,
6954 .doit = nl80211_associate,
6955 .policy = nl80211_policy,
6956 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006957 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006958 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006959 },
6960 {
6961 .cmd = NL80211_CMD_DEAUTHENTICATE,
6962 .doit = nl80211_deauthenticate,
6963 .policy = nl80211_policy,
6964 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006965 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006966 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006967 },
6968 {
6969 .cmd = NL80211_CMD_DISASSOCIATE,
6970 .doit = nl80211_disassociate,
6971 .policy = nl80211_policy,
6972 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006973 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006974 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006975 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006976 {
6977 .cmd = NL80211_CMD_JOIN_IBSS,
6978 .doit = nl80211_join_ibss,
6979 .policy = nl80211_policy,
6980 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006981 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006982 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006983 },
6984 {
6985 .cmd = NL80211_CMD_LEAVE_IBSS,
6986 .doit = nl80211_leave_ibss,
6987 .policy = nl80211_policy,
6988 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006990 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006991 },
Johannes Bergaff89a92009-07-01 21:26:51 +02006992#ifdef CONFIG_NL80211_TESTMODE
6993 {
6994 .cmd = NL80211_CMD_TESTMODE,
6995 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006996 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02006997 .policy = nl80211_policy,
6998 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006999 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7000 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007001 },
7002#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007003 {
7004 .cmd = NL80211_CMD_CONNECT,
7005 .doit = nl80211_connect,
7006 .policy = nl80211_policy,
7007 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007009 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007010 },
7011 {
7012 .cmd = NL80211_CMD_DISCONNECT,
7013 .doit = nl80211_disconnect,
7014 .policy = nl80211_policy,
7015 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007017 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007018 },
Johannes Berg463d0182009-07-14 00:33:35 +02007019 {
7020 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7021 .doit = nl80211_wiphy_netns,
7022 .policy = nl80211_policy,
7023 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007024 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7025 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007026 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007027 {
7028 .cmd = NL80211_CMD_GET_SURVEY,
7029 .policy = nl80211_policy,
7030 .dumpit = nl80211_dump_survey,
7031 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007032 {
7033 .cmd = NL80211_CMD_SET_PMKSA,
7034 .doit = nl80211_setdel_pmksa,
7035 .policy = nl80211_policy,
7036 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007038 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007039 },
7040 {
7041 .cmd = NL80211_CMD_DEL_PMKSA,
7042 .doit = nl80211_setdel_pmksa,
7043 .policy = nl80211_policy,
7044 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007045 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007046 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007047 },
7048 {
7049 .cmd = NL80211_CMD_FLUSH_PMKSA,
7050 .doit = nl80211_flush_pmksa,
7051 .policy = nl80211_policy,
7052 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007053 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007054 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007055 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007056 {
7057 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7058 .doit = nl80211_remain_on_channel,
7059 .policy = nl80211_policy,
7060 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007061 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007062 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007063 },
7064 {
7065 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7066 .doit = nl80211_cancel_remain_on_channel,
7067 .policy = nl80211_policy,
7068 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007069 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007070 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007071 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007072 {
7073 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7074 .doit = nl80211_set_tx_bitrate_mask,
7075 .policy = nl80211_policy,
7076 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007077 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7078 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007079 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007080 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007081 .cmd = NL80211_CMD_REGISTER_FRAME,
7082 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007083 .policy = nl80211_policy,
7084 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007085 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7086 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007087 },
7088 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007089 .cmd = NL80211_CMD_FRAME,
7090 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007091 .policy = nl80211_policy,
7092 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007093 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007094 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007095 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007096 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007097 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7098 .doit = nl80211_tx_mgmt_cancel_wait,
7099 .policy = nl80211_policy,
7100 .flags = GENL_ADMIN_PERM,
7101 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7102 NL80211_FLAG_NEED_RTNL,
7103 },
7104 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007105 .cmd = NL80211_CMD_SET_POWER_SAVE,
7106 .doit = nl80211_set_power_save,
7107 .policy = nl80211_policy,
7108 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007109 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7110 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007111 },
7112 {
7113 .cmd = NL80211_CMD_GET_POWER_SAVE,
7114 .doit = nl80211_get_power_save,
7115 .policy = nl80211_policy,
7116 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007117 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7118 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007119 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007120 {
7121 .cmd = NL80211_CMD_SET_CQM,
7122 .doit = nl80211_set_cqm,
7123 .policy = nl80211_policy,
7124 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007125 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7126 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007127 },
Johannes Bergf444de02010-05-05 15:25:02 +02007128 {
7129 .cmd = NL80211_CMD_SET_CHANNEL,
7130 .doit = nl80211_set_channel,
7131 .policy = nl80211_policy,
7132 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007133 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7134 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007135 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007136 {
7137 .cmd = NL80211_CMD_SET_WDS_PEER,
7138 .doit = nl80211_set_wds_peer,
7139 .policy = nl80211_policy,
7140 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007141 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7142 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007143 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007144 {
7145 .cmd = NL80211_CMD_JOIN_MESH,
7146 .doit = nl80211_join_mesh,
7147 .policy = nl80211_policy,
7148 .flags = GENL_ADMIN_PERM,
7149 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7150 NL80211_FLAG_NEED_RTNL,
7151 },
7152 {
7153 .cmd = NL80211_CMD_LEAVE_MESH,
7154 .doit = nl80211_leave_mesh,
7155 .policy = nl80211_policy,
7156 .flags = GENL_ADMIN_PERM,
7157 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7158 NL80211_FLAG_NEED_RTNL,
7159 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007160#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007161 {
7162 .cmd = NL80211_CMD_GET_WOWLAN,
7163 .doit = nl80211_get_wowlan,
7164 .policy = nl80211_policy,
7165 /* can be retrieved by unprivileged users */
7166 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7167 NL80211_FLAG_NEED_RTNL,
7168 },
7169 {
7170 .cmd = NL80211_CMD_SET_WOWLAN,
7171 .doit = nl80211_set_wowlan,
7172 .policy = nl80211_policy,
7173 .flags = GENL_ADMIN_PERM,
7174 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7175 NL80211_FLAG_NEED_RTNL,
7176 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007177#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007178 {
7179 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7180 .doit = nl80211_set_rekey_data,
7181 .policy = nl80211_policy,
7182 .flags = GENL_ADMIN_PERM,
7183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7184 NL80211_FLAG_NEED_RTNL,
7185 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007186 {
7187 .cmd = NL80211_CMD_TDLS_MGMT,
7188 .doit = nl80211_tdls_mgmt,
7189 .policy = nl80211_policy,
7190 .flags = GENL_ADMIN_PERM,
7191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7192 NL80211_FLAG_NEED_RTNL,
7193 },
7194 {
7195 .cmd = NL80211_CMD_TDLS_OPER,
7196 .doit = nl80211_tdls_oper,
7197 .policy = nl80211_policy,
7198 .flags = GENL_ADMIN_PERM,
7199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7200 NL80211_FLAG_NEED_RTNL,
7201 },
Johannes Berg28946da2011-11-04 11:18:12 +01007202 {
7203 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7204 .doit = nl80211_register_unexpected_frame,
7205 .policy = nl80211_policy,
7206 .flags = GENL_ADMIN_PERM,
7207 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7208 NL80211_FLAG_NEED_RTNL,
7209 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007210 {
7211 .cmd = NL80211_CMD_PROBE_CLIENT,
7212 .doit = nl80211_probe_client,
7213 .policy = nl80211_policy,
7214 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007216 NL80211_FLAG_NEED_RTNL,
7217 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007218 {
7219 .cmd = NL80211_CMD_REGISTER_BEACONS,
7220 .doit = nl80211_register_beacons,
7221 .policy = nl80211_policy,
7222 .flags = GENL_ADMIN_PERM,
7223 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7224 NL80211_FLAG_NEED_RTNL,
7225 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007226 {
7227 .cmd = NL80211_CMD_SET_NOACK_MAP,
7228 .doit = nl80211_set_noack_map,
7229 .policy = nl80211_policy,
7230 .flags = GENL_ADMIN_PERM,
7231 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7232 NL80211_FLAG_NEED_RTNL,
7233 },
7234
Johannes Berg55682962007-09-20 13:09:35 -04007235};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007236
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007237static struct genl_multicast_group nl80211_mlme_mcgrp = {
7238 .name = "mlme",
7239};
Johannes Berg55682962007-09-20 13:09:35 -04007240
7241/* multicast groups */
7242static struct genl_multicast_group nl80211_config_mcgrp = {
7243 .name = "config",
7244};
Johannes Berg2a519312009-02-10 21:25:55 +01007245static struct genl_multicast_group nl80211_scan_mcgrp = {
7246 .name = "scan",
7247};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007248static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7249 .name = "regulatory",
7250};
Johannes Berg55682962007-09-20 13:09:35 -04007251
7252/* notification functions */
7253
7254void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7255{
7256 struct sk_buff *msg;
7257
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007258 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007259 if (!msg)
7260 return;
7261
7262 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7263 nlmsg_free(msg);
7264 return;
7265 }
7266
Johannes Berg463d0182009-07-14 00:33:35 +02007267 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7268 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007269}
7270
Johannes Berg362a4152009-05-24 16:43:15 +02007271static int nl80211_add_scan_req(struct sk_buff *msg,
7272 struct cfg80211_registered_device *rdev)
7273{
7274 struct cfg80211_scan_request *req = rdev->scan_req;
7275 struct nlattr *nest;
7276 int i;
7277
Johannes Berg667503dd2009-07-07 03:56:11 +02007278 ASSERT_RDEV_LOCK(rdev);
7279
Johannes Berg362a4152009-05-24 16:43:15 +02007280 if (WARN_ON(!req))
7281 return 0;
7282
7283 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7284 if (!nest)
7285 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007286 for (i = 0; i < req->n_ssids; i++) {
7287 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7288 goto nla_put_failure;
7289 }
Johannes Berg362a4152009-05-24 16:43:15 +02007290 nla_nest_end(msg, nest);
7291
7292 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7293 if (!nest)
7294 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007295 for (i = 0; i < req->n_channels; i++) {
7296 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7297 goto nla_put_failure;
7298 }
Johannes Berg362a4152009-05-24 16:43:15 +02007299 nla_nest_end(msg, nest);
7300
David S. Miller9360ffd2012-03-29 04:41:26 -04007301 if (req->ie &&
7302 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7303 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007304
7305 return 0;
7306 nla_put_failure:
7307 return -ENOBUFS;
7308}
7309
Johannes Berga538e2d2009-06-16 19:56:42 +02007310static int nl80211_send_scan_msg(struct sk_buff *msg,
7311 struct cfg80211_registered_device *rdev,
7312 struct net_device *netdev,
7313 u32 pid, u32 seq, int flags,
7314 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007315{
7316 void *hdr;
7317
7318 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7319 if (!hdr)
7320 return -1;
7321
David S. Miller9360ffd2012-03-29 04:41:26 -04007322 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7323 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7324 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007325
Johannes Berg362a4152009-05-24 16:43:15 +02007326 /* ignore errors and send incomplete event anyway */
7327 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007328
7329 return genlmsg_end(msg, hdr);
7330
7331 nla_put_failure:
7332 genlmsg_cancel(msg, hdr);
7333 return -EMSGSIZE;
7334}
7335
Luciano Coelho807f8a82011-05-11 17:09:35 +03007336static int
7337nl80211_send_sched_scan_msg(struct sk_buff *msg,
7338 struct cfg80211_registered_device *rdev,
7339 struct net_device *netdev,
7340 u32 pid, u32 seq, int flags, u32 cmd)
7341{
7342 void *hdr;
7343
7344 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7345 if (!hdr)
7346 return -1;
7347
David S. Miller9360ffd2012-03-29 04:41:26 -04007348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7349 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7350 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007351
7352 return genlmsg_end(msg, hdr);
7353
7354 nla_put_failure:
7355 genlmsg_cancel(msg, hdr);
7356 return -EMSGSIZE;
7357}
7358
Johannes Berga538e2d2009-06-16 19:56:42 +02007359void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7360 struct net_device *netdev)
7361{
7362 struct sk_buff *msg;
7363
7364 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7365 if (!msg)
7366 return;
7367
7368 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7369 NL80211_CMD_TRIGGER_SCAN) < 0) {
7370 nlmsg_free(msg);
7371 return;
7372 }
7373
Johannes Berg463d0182009-07-14 00:33:35 +02007374 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7375 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007376}
7377
Johannes Berg2a519312009-02-10 21:25:55 +01007378void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7379 struct net_device *netdev)
7380{
7381 struct sk_buff *msg;
7382
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007384 if (!msg)
7385 return;
7386
Johannes Berga538e2d2009-06-16 19:56:42 +02007387 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7388 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007389 nlmsg_free(msg);
7390 return;
7391 }
7392
Johannes Berg463d0182009-07-14 00:33:35 +02007393 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7394 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007395}
7396
7397void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7398 struct net_device *netdev)
7399{
7400 struct sk_buff *msg;
7401
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007402 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007403 if (!msg)
7404 return;
7405
Johannes Berga538e2d2009-06-16 19:56:42 +02007406 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7407 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007408 nlmsg_free(msg);
7409 return;
7410 }
7411
Johannes Berg463d0182009-07-14 00:33:35 +02007412 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7413 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007414}
7415
Luciano Coelho807f8a82011-05-11 17:09:35 +03007416void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7417 struct net_device *netdev)
7418{
7419 struct sk_buff *msg;
7420
7421 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7422 if (!msg)
7423 return;
7424
7425 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7426 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7427 nlmsg_free(msg);
7428 return;
7429 }
7430
7431 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7432 nl80211_scan_mcgrp.id, GFP_KERNEL);
7433}
7434
7435void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7436 struct net_device *netdev, u32 cmd)
7437{
7438 struct sk_buff *msg;
7439
7440 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7441 if (!msg)
7442 return;
7443
7444 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7445 nlmsg_free(msg);
7446 return;
7447 }
7448
7449 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7450 nl80211_scan_mcgrp.id, GFP_KERNEL);
7451}
7452
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007453/*
7454 * This can happen on global regulatory changes or device specific settings
7455 * based on custom world regulatory domains.
7456 */
7457void nl80211_send_reg_change_event(struct regulatory_request *request)
7458{
7459 struct sk_buff *msg;
7460 void *hdr;
7461
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007462 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007463 if (!msg)
7464 return;
7465
7466 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7467 if (!hdr) {
7468 nlmsg_free(msg);
7469 return;
7470 }
7471
7472 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007473 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7474 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007475
David S. Miller9360ffd2012-03-29 04:41:26 -04007476 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7477 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7478 NL80211_REGDOM_TYPE_WORLD))
7479 goto nla_put_failure;
7480 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7481 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7482 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7483 goto nla_put_failure;
7484 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7485 request->intersect) {
7486 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7487 NL80211_REGDOM_TYPE_INTERSECTION))
7488 goto nla_put_failure;
7489 } else {
7490 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7491 NL80211_REGDOM_TYPE_COUNTRY) ||
7492 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7493 request->alpha2))
7494 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007495 }
7496
David S. Miller9360ffd2012-03-29 04:41:26 -04007497 if (wiphy_idx_valid(request->wiphy_idx) &&
7498 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7499 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007500
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007501 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007502
Johannes Bergbc43b282009-07-25 10:54:13 +02007503 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007504 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007505 GFP_ATOMIC);
7506 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007507
7508 return;
7509
7510nla_put_failure:
7511 genlmsg_cancel(msg, hdr);
7512 nlmsg_free(msg);
7513}
7514
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007515static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7516 struct net_device *netdev,
7517 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007518 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007519{
7520 struct sk_buff *msg;
7521 void *hdr;
7522
Johannes Berge6d6e342009-07-01 21:26:47 +02007523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007524 if (!msg)
7525 return;
7526
7527 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7528 if (!hdr) {
7529 nlmsg_free(msg);
7530 return;
7531 }
7532
David S. Miller9360ffd2012-03-29 04:41:26 -04007533 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7534 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7535 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7536 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007537
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007538 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007539
Johannes Berg463d0182009-07-14 00:33:35 +02007540 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7541 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007542 return;
7543
7544 nla_put_failure:
7545 genlmsg_cancel(msg, hdr);
7546 nlmsg_free(msg);
7547}
7548
7549void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007550 struct net_device *netdev, const u8 *buf,
7551 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007552{
7553 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007554 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007555}
7556
7557void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7558 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007559 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007560{
Johannes Berge6d6e342009-07-01 21:26:47 +02007561 nl80211_send_mlme_event(rdev, netdev, buf, len,
7562 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007563}
7564
Jouni Malinen53b46b82009-03-27 20:53:56 +02007565void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007566 struct net_device *netdev, const u8 *buf,
7567 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_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007571}
7572
Jouni Malinen53b46b82009-03-27 20:53:56 +02007573void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7574 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007575 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007576{
7577 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007578 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007579}
7580
Jouni Malinencf4e5942010-12-16 00:52:40 +02007581void nl80211_send_unprot_deauth(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_DEAUTHENTICATE, gfp);
7587}
7588
7589void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7590 struct net_device *netdev, const u8 *buf,
7591 size_t len, gfp_t gfp)
7592{
7593 nl80211_send_mlme_event(rdev, netdev, buf, len,
7594 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7595}
7596
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007597static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7598 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007599 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007600{
7601 struct sk_buff *msg;
7602 void *hdr;
7603
Johannes Berge6d6e342009-07-01 21:26:47 +02007604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007605 if (!msg)
7606 return;
7607
7608 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7609 if (!hdr) {
7610 nlmsg_free(msg);
7611 return;
7612 }
7613
David S. Miller9360ffd2012-03-29 04:41:26 -04007614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7616 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7617 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7618 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007619
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007620 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007621
Johannes Berg463d0182009-07-14 00:33:35 +02007622 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7623 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007624 return;
7625
7626 nla_put_failure:
7627 genlmsg_cancel(msg, hdr);
7628 nlmsg_free(msg);
7629}
7630
7631void nl80211_send_auth_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{
7635 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007636 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007637}
7638
7639void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007640 struct net_device *netdev, const u8 *addr,
7641 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007642{
Johannes Berge6d6e342009-07-01 21:26:47 +02007643 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7644 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007645}
7646
Samuel Ortizb23aa672009-07-01 21:26:54 +02007647void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7648 struct net_device *netdev, const u8 *bssid,
7649 const u8 *req_ie, size_t req_ie_len,
7650 const u8 *resp_ie, size_t resp_ie_len,
7651 u16 status, gfp_t gfp)
7652{
7653 struct sk_buff *msg;
7654 void *hdr;
7655
7656 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7657 if (!msg)
7658 return;
7659
7660 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7661 if (!hdr) {
7662 nlmsg_free(msg);
7663 return;
7664 }
7665
David S. Miller9360ffd2012-03-29 04:41:26 -04007666 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7667 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7668 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7669 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7670 (req_ie &&
7671 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7672 (resp_ie &&
7673 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7674 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007675
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007676 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007677
Johannes Berg463d0182009-07-14 00:33:35 +02007678 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7679 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007680 return;
7681
7682 nla_put_failure:
7683 genlmsg_cancel(msg, hdr);
7684 nlmsg_free(msg);
7685
7686}
7687
7688void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7689 struct net_device *netdev, const u8 *bssid,
7690 const u8 *req_ie, size_t req_ie_len,
7691 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7692{
7693 struct sk_buff *msg;
7694 void *hdr;
7695
7696 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7697 if (!msg)
7698 return;
7699
7700 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7701 if (!hdr) {
7702 nlmsg_free(msg);
7703 return;
7704 }
7705
David S. Miller9360ffd2012-03-29 04:41:26 -04007706 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7707 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7708 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7709 (req_ie &&
7710 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7711 (resp_ie &&
7712 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7713 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007714
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007715 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007716
Johannes Berg463d0182009-07-14 00:33:35 +02007717 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7718 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007719 return;
7720
7721 nla_put_failure:
7722 genlmsg_cancel(msg, hdr);
7723 nlmsg_free(msg);
7724
7725}
7726
7727void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7728 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007729 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007730{
7731 struct sk_buff *msg;
7732 void *hdr;
7733
Johannes Berg667503dd2009-07-07 03:56:11 +02007734 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007735 if (!msg)
7736 return;
7737
7738 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7739 if (!hdr) {
7740 nlmsg_free(msg);
7741 return;
7742 }
7743
David S. Miller9360ffd2012-03-29 04:41:26 -04007744 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7746 (from_ap && reason &&
7747 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7748 (from_ap &&
7749 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7750 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7751 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007752
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007753 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007754
Johannes Berg463d0182009-07-14 00:33:35 +02007755 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7756 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007757 return;
7758
7759 nla_put_failure:
7760 genlmsg_cancel(msg, hdr);
7761 nlmsg_free(msg);
7762
7763}
7764
Johannes Berg04a773a2009-04-19 21:24:32 +02007765void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7766 struct net_device *netdev, const u8 *bssid,
7767 gfp_t gfp)
7768{
7769 struct sk_buff *msg;
7770 void *hdr;
7771
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007772 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007773 if (!msg)
7774 return;
7775
7776 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7777 if (!hdr) {
7778 nlmsg_free(msg);
7779 return;
7780 }
7781
David S. Miller9360ffd2012-03-29 04:41:26 -04007782 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7783 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7784 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7785 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007786
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007787 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007788
Johannes Berg463d0182009-07-14 00:33:35 +02007789 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7790 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007791 return;
7792
7793 nla_put_failure:
7794 genlmsg_cancel(msg, hdr);
7795 nlmsg_free(msg);
7796}
7797
Javier Cardonac93b5e72011-04-07 15:08:34 -07007798void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7799 struct net_device *netdev,
7800 const u8 *macaddr, const u8* ie, u8 ie_len,
7801 gfp_t gfp)
7802{
7803 struct sk_buff *msg;
7804 void *hdr;
7805
7806 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7807 if (!msg)
7808 return;
7809
7810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7811 if (!hdr) {
7812 nlmsg_free(msg);
7813 return;
7814 }
7815
David S. Miller9360ffd2012-03-29 04:41:26 -04007816 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7818 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7819 (ie_len && ie &&
7820 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7821 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007822
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007823 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007824
7825 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7826 nl80211_mlme_mcgrp.id, gfp);
7827 return;
7828
7829 nla_put_failure:
7830 genlmsg_cancel(msg, hdr);
7831 nlmsg_free(msg);
7832}
7833
Jouni Malinena3b8b052009-03-27 21:59:49 +02007834void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7835 struct net_device *netdev, const u8 *addr,
7836 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007837 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007838{
7839 struct sk_buff *msg;
7840 void *hdr;
7841
Johannes Berge6d6e342009-07-01 21:26:47 +02007842 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007843 if (!msg)
7844 return;
7845
7846 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7847 if (!hdr) {
7848 nlmsg_free(msg);
7849 return;
7850 }
7851
David S. Miller9360ffd2012-03-29 04:41:26 -04007852 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7853 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7854 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7855 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7856 (key_id != -1 &&
7857 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7858 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7859 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007860
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007861 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007862
Johannes Berg463d0182009-07-14 00:33:35 +02007863 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7864 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007865 return;
7866
7867 nla_put_failure:
7868 genlmsg_cancel(msg, hdr);
7869 nlmsg_free(msg);
7870}
7871
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007872void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7873 struct ieee80211_channel *channel_before,
7874 struct ieee80211_channel *channel_after)
7875{
7876 struct sk_buff *msg;
7877 void *hdr;
7878 struct nlattr *nl_freq;
7879
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007880 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007881 if (!msg)
7882 return;
7883
7884 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7885 if (!hdr) {
7886 nlmsg_free(msg);
7887 return;
7888 }
7889
7890 /*
7891 * Since we are applying the beacon hint to a wiphy we know its
7892 * wiphy_idx is valid
7893 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7895 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007896
7897 /* Before */
7898 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7899 if (!nl_freq)
7900 goto nla_put_failure;
7901 if (nl80211_msg_put_channel(msg, channel_before))
7902 goto nla_put_failure;
7903 nla_nest_end(msg, nl_freq);
7904
7905 /* After */
7906 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7907 if (!nl_freq)
7908 goto nla_put_failure;
7909 if (nl80211_msg_put_channel(msg, channel_after))
7910 goto nla_put_failure;
7911 nla_nest_end(msg, nl_freq);
7912
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007913 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007914
Johannes Berg463d0182009-07-14 00:33:35 +02007915 rcu_read_lock();
7916 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7917 GFP_ATOMIC);
7918 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007919
7920 return;
7921
7922nla_put_failure:
7923 genlmsg_cancel(msg, hdr);
7924 nlmsg_free(msg);
7925}
7926
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007927static void nl80211_send_remain_on_chan_event(
7928 int cmd, struct cfg80211_registered_device *rdev,
7929 struct net_device *netdev, u64 cookie,
7930 struct ieee80211_channel *chan,
7931 enum nl80211_channel_type channel_type,
7932 unsigned int duration, gfp_t gfp)
7933{
7934 struct sk_buff *msg;
7935 void *hdr;
7936
7937 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7938 if (!msg)
7939 return;
7940
7941 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7942 if (!hdr) {
7943 nlmsg_free(msg);
7944 return;
7945 }
7946
David S. Miller9360ffd2012-03-29 04:41:26 -04007947 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7948 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7949 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7950 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7951 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7952 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007953
David S. Miller9360ffd2012-03-29 04:41:26 -04007954 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7955 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7956 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007957
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007958 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007959
7960 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7961 nl80211_mlme_mcgrp.id, gfp);
7962 return;
7963
7964 nla_put_failure:
7965 genlmsg_cancel(msg, hdr);
7966 nlmsg_free(msg);
7967}
7968
7969void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7970 struct net_device *netdev, u64 cookie,
7971 struct ieee80211_channel *chan,
7972 enum nl80211_channel_type channel_type,
7973 unsigned int duration, gfp_t gfp)
7974{
7975 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7976 rdev, netdev, cookie, chan,
7977 channel_type, duration, gfp);
7978}
7979
7980void nl80211_send_remain_on_channel_cancel(
7981 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7982 u64 cookie, struct ieee80211_channel *chan,
7983 enum nl80211_channel_type channel_type, gfp_t gfp)
7984{
7985 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7986 rdev, netdev, cookie, chan,
7987 channel_type, 0, gfp);
7988}
7989
Johannes Berg98b62182009-12-23 13:15:44 +01007990void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7991 struct net_device *dev, const u8 *mac_addr,
7992 struct station_info *sinfo, gfp_t gfp)
7993{
7994 struct sk_buff *msg;
7995
7996 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7997 if (!msg)
7998 return;
7999
John W. Linville66266b32012-03-15 13:25:41 -04008000 if (nl80211_send_station(msg, 0, 0, 0,
8001 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008002 nlmsg_free(msg);
8003 return;
8004 }
8005
8006 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8007 nl80211_mlme_mcgrp.id, gfp);
8008}
8009
Jouni Malinenec15e682011-03-23 15:29:52 +02008010void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8011 struct net_device *dev, const u8 *mac_addr,
8012 gfp_t gfp)
8013{
8014 struct sk_buff *msg;
8015 void *hdr;
8016
8017 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8018 if (!msg)
8019 return;
8020
8021 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8022 if (!hdr) {
8023 nlmsg_free(msg);
8024 return;
8025 }
8026
David S. Miller9360ffd2012-03-29 04:41:26 -04008027 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8028 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8029 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008030
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008031 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008032
8033 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8034 nl80211_mlme_mcgrp.id, gfp);
8035 return;
8036
8037 nla_put_failure:
8038 genlmsg_cancel(msg, hdr);
8039 nlmsg_free(msg);
8040}
8041
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008042static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8043 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008044{
8045 struct wireless_dev *wdev = dev->ieee80211_ptr;
8046 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8047 struct sk_buff *msg;
8048 void *hdr;
8049 int err;
8050 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8051
8052 if (!nlpid)
8053 return false;
8054
8055 msg = nlmsg_new(100, gfp);
8056 if (!msg)
8057 return true;
8058
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008059 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008060 if (!hdr) {
8061 nlmsg_free(msg);
8062 return true;
8063 }
8064
David S. Miller9360ffd2012-03-29 04:41:26 -04008065 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8066 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8067 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8068 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008069
8070 err = genlmsg_end(msg, hdr);
8071 if (err < 0) {
8072 nlmsg_free(msg);
8073 return true;
8074 }
8075
8076 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8077 return true;
8078
8079 nla_put_failure:
8080 genlmsg_cancel(msg, hdr);
8081 nlmsg_free(msg);
8082 return true;
8083}
8084
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008085bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8086{
8087 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8088 addr, gfp);
8089}
8090
8091bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8092 const u8 *addr, gfp_t gfp)
8093{
8094 return __nl80211_unexpected_frame(dev,
8095 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8096 addr, gfp);
8097}
8098
Johannes Berg2e161f72010-08-12 15:38:38 +02008099int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8100 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008101 int freq, int sig_dbm,
8102 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008103{
8104 struct sk_buff *msg;
8105 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008106
8107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8108 if (!msg)
8109 return -ENOMEM;
8110
Johannes Berg2e161f72010-08-12 15:38:38 +02008111 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008112 if (!hdr) {
8113 nlmsg_free(msg);
8114 return -ENOMEM;
8115 }
8116
David S. Miller9360ffd2012-03-29 04:41:26 -04008117 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8118 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8119 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8120 (sig_dbm &&
8121 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8122 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8123 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008124
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008125 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008126
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008127 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008128
8129 nla_put_failure:
8130 genlmsg_cancel(msg, hdr);
8131 nlmsg_free(msg);
8132 return -ENOBUFS;
8133}
8134
Johannes Berg2e161f72010-08-12 15:38:38 +02008135void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8136 struct net_device *netdev, u64 cookie,
8137 const u8 *buf, size_t len, bool ack,
8138 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008139{
8140 struct sk_buff *msg;
8141 void *hdr;
8142
8143 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8144 if (!msg)
8145 return;
8146
Johannes Berg2e161f72010-08-12 15:38:38 +02008147 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008148 if (!hdr) {
8149 nlmsg_free(msg);
8150 return;
8151 }
8152
David S. Miller9360ffd2012-03-29 04:41:26 -04008153 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8154 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8155 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8156 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8157 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8158 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008159
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008160 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008161
8162 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8163 return;
8164
8165 nla_put_failure:
8166 genlmsg_cancel(msg, hdr);
8167 nlmsg_free(msg);
8168}
8169
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008170void
8171nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8172 struct net_device *netdev,
8173 enum nl80211_cqm_rssi_threshold_event rssi_event,
8174 gfp_t gfp)
8175{
8176 struct sk_buff *msg;
8177 struct nlattr *pinfoattr;
8178 void *hdr;
8179
8180 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8181 if (!msg)
8182 return;
8183
8184 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8185 if (!hdr) {
8186 nlmsg_free(msg);
8187 return;
8188 }
8189
David S. Miller9360ffd2012-03-29 04:41:26 -04008190 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8192 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008193
8194 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8195 if (!pinfoattr)
8196 goto nla_put_failure;
8197
David S. Miller9360ffd2012-03-29 04:41:26 -04008198 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8199 rssi_event))
8200 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008201
8202 nla_nest_end(msg, pinfoattr);
8203
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008204 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008205
8206 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8207 nl80211_mlme_mcgrp.id, gfp);
8208 return;
8209
8210 nla_put_failure:
8211 genlmsg_cancel(msg, hdr);
8212 nlmsg_free(msg);
8213}
8214
Johannes Berge5497d72011-07-05 16:35:40 +02008215void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8216 struct net_device *netdev, const u8 *bssid,
8217 const u8 *replay_ctr, gfp_t gfp)
8218{
8219 struct sk_buff *msg;
8220 struct nlattr *rekey_attr;
8221 void *hdr;
8222
8223 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8224 if (!msg)
8225 return;
8226
8227 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8228 if (!hdr) {
8229 nlmsg_free(msg);
8230 return;
8231 }
8232
David S. Miller9360ffd2012-03-29 04:41:26 -04008233 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8234 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8235 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8236 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008237
8238 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8239 if (!rekey_attr)
8240 goto nla_put_failure;
8241
David S. Miller9360ffd2012-03-29 04:41:26 -04008242 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8243 NL80211_REPLAY_CTR_LEN, replay_ctr))
8244 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008245
8246 nla_nest_end(msg, rekey_attr);
8247
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008248 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008249
8250 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8251 nl80211_mlme_mcgrp.id, gfp);
8252 return;
8253
8254 nla_put_failure:
8255 genlmsg_cancel(msg, hdr);
8256 nlmsg_free(msg);
8257}
8258
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008259void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8260 struct net_device *netdev, int index,
8261 const u8 *bssid, bool preauth, gfp_t gfp)
8262{
8263 struct sk_buff *msg;
8264 struct nlattr *attr;
8265 void *hdr;
8266
8267 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8268 if (!msg)
8269 return;
8270
8271 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8272 if (!hdr) {
8273 nlmsg_free(msg);
8274 return;
8275 }
8276
David S. Miller9360ffd2012-03-29 04:41:26 -04008277 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8278 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8279 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008280
8281 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8282 if (!attr)
8283 goto nla_put_failure;
8284
David S. Miller9360ffd2012-03-29 04:41:26 -04008285 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8286 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8287 (preauth &&
8288 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8289 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008290
8291 nla_nest_end(msg, attr);
8292
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008293 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008294
8295 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8296 nl80211_mlme_mcgrp.id, gfp);
8297 return;
8298
8299 nla_put_failure:
8300 genlmsg_cancel(msg, hdr);
8301 nlmsg_free(msg);
8302}
8303
Thomas Pedersen53145262012-04-06 13:35:47 -07008304void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8305 struct net_device *netdev, int freq,
8306 enum nl80211_channel_type type, gfp_t gfp)
8307{
8308 struct sk_buff *msg;
8309 void *hdr;
8310
8311 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8312 if (!msg)
8313 return;
8314
8315 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8316 if (!hdr) {
8317 nlmsg_free(msg);
8318 return;
8319 }
8320
John W. Linville7eab0f62012-04-12 14:25:14 -04008321 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8322 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8323 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8324 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008325
8326 genlmsg_end(msg, hdr);
8327
8328 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8329 nl80211_mlme_mcgrp.id, gfp);
8330 return;
8331
8332 nla_put_failure:
8333 genlmsg_cancel(msg, hdr);
8334 nlmsg_free(msg);
8335}
8336
Johannes Bergc063dbf2010-11-24 08:10:05 +01008337void
8338nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8339 struct net_device *netdev, const u8 *peer,
8340 u32 num_packets, gfp_t gfp)
8341{
8342 struct sk_buff *msg;
8343 struct nlattr *pinfoattr;
8344 void *hdr;
8345
8346 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8347 if (!msg)
8348 return;
8349
8350 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8351 if (!hdr) {
8352 nlmsg_free(msg);
8353 return;
8354 }
8355
David S. Miller9360ffd2012-03-29 04:41:26 -04008356 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8357 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8358 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8359 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008360
8361 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8362 if (!pinfoattr)
8363 goto nla_put_failure;
8364
David S. Miller9360ffd2012-03-29 04:41:26 -04008365 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8366 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008367
8368 nla_nest_end(msg, pinfoattr);
8369
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008370 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008371
8372 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8373 nl80211_mlme_mcgrp.id, gfp);
8374 return;
8375
8376 nla_put_failure:
8377 genlmsg_cancel(msg, hdr);
8378 nlmsg_free(msg);
8379}
8380
Johannes Berg7f6cf312011-11-04 11:18:15 +01008381void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8382 u64 cookie, bool acked, gfp_t gfp)
8383{
8384 struct wireless_dev *wdev = dev->ieee80211_ptr;
8385 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8386 struct sk_buff *msg;
8387 void *hdr;
8388 int err;
8389
8390 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8391 if (!msg)
8392 return;
8393
8394 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8395 if (!hdr) {
8396 nlmsg_free(msg);
8397 return;
8398 }
8399
David S. Miller9360ffd2012-03-29 04:41:26 -04008400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8401 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8402 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8403 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8404 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8405 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008406
8407 err = genlmsg_end(msg, hdr);
8408 if (err < 0) {
8409 nlmsg_free(msg);
8410 return;
8411 }
8412
8413 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8414 nl80211_mlme_mcgrp.id, gfp);
8415 return;
8416
8417 nla_put_failure:
8418 genlmsg_cancel(msg, hdr);
8419 nlmsg_free(msg);
8420}
8421EXPORT_SYMBOL(cfg80211_probe_status);
8422
Johannes Berg5e7602302011-11-04 11:18:17 +01008423void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8424 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008425 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008426{
8427 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8428 struct sk_buff *msg;
8429 void *hdr;
8430 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8431
8432 if (!nlpid)
8433 return;
8434
8435 msg = nlmsg_new(len + 100, gfp);
8436 if (!msg)
8437 return;
8438
8439 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8440 if (!hdr) {
8441 nlmsg_free(msg);
8442 return;
8443 }
8444
David S. Miller9360ffd2012-03-29 04:41:26 -04008445 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8446 (freq &&
8447 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8448 (sig_dbm &&
8449 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8450 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8451 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008452
8453 genlmsg_end(msg, hdr);
8454
8455 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8456 return;
8457
8458 nla_put_failure:
8459 genlmsg_cancel(msg, hdr);
8460 nlmsg_free(msg);
8461}
8462EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8463
Jouni Malinen026331c2010-02-15 12:53:10 +02008464static int nl80211_netlink_notify(struct notifier_block * nb,
8465 unsigned long state,
8466 void *_notify)
8467{
8468 struct netlink_notify *notify = _notify;
8469 struct cfg80211_registered_device *rdev;
8470 struct wireless_dev *wdev;
8471
8472 if (state != NETLINK_URELEASE)
8473 return NOTIFY_DONE;
8474
8475 rcu_read_lock();
8476
Johannes Berg5e7602302011-11-04 11:18:17 +01008477 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008478 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008479 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008480 if (rdev->ap_beacons_nlpid == notify->pid)
8481 rdev->ap_beacons_nlpid = 0;
8482 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008483
8484 rcu_read_unlock();
8485
8486 return NOTIFY_DONE;
8487}
8488
8489static struct notifier_block nl80211_netlink_notifier = {
8490 .notifier_call = nl80211_netlink_notify,
8491};
8492
Johannes Berg55682962007-09-20 13:09:35 -04008493/* initialisation/exit functions */
8494
8495int nl80211_init(void)
8496{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008497 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008498
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008499 err = genl_register_family_with_ops(&nl80211_fam,
8500 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008501 if (err)
8502 return err;
8503
Johannes Berg55682962007-09-20 13:09:35 -04008504 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8505 if (err)
8506 goto err_out;
8507
Johannes Berg2a519312009-02-10 21:25:55 +01008508 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8509 if (err)
8510 goto err_out;
8511
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008512 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8513 if (err)
8514 goto err_out;
8515
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008516 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8517 if (err)
8518 goto err_out;
8519
Johannes Bergaff89a92009-07-01 21:26:51 +02008520#ifdef CONFIG_NL80211_TESTMODE
8521 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8522 if (err)
8523 goto err_out;
8524#endif
8525
Jouni Malinen026331c2010-02-15 12:53:10 +02008526 err = netlink_register_notifier(&nl80211_netlink_notifier);
8527 if (err)
8528 goto err_out;
8529
Johannes Berg55682962007-09-20 13:09:35 -04008530 return 0;
8531 err_out:
8532 genl_unregister_family(&nl80211_fam);
8533 return err;
8534}
8535
8536void nl80211_exit(void)
8537{
Jouni Malinen026331c2010-02-15 12:53:10 +02008538 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008539 genl_unregister_family(&nl80211_fam);
8540}