blob: 2a5cdb60bc6e0ba15003592149bb10d56d4d0c4d [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
Michal Kazior2e165b82012-06-29 12:47:06 +02001692 if (rdev->monitor_channel) {
1693 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1694 rdev->monitor_channel->center_freq) ||
1695 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1696 rdev->monitor_channel_type))
John W. Linville59ef43e2012-04-18 14:17:13 -04001697 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001698 }
1699
Johannes Berg55682962007-09-20 13:09:35 -04001700 return genlmsg_end(msg, hdr);
1701
1702 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001703 genlmsg_cancel(msg, hdr);
1704 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001705}
1706
1707static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1708{
1709 int wp_idx = 0;
1710 int if_idx = 0;
1711 int wp_start = cb->args[0];
1712 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001713 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001714 struct wireless_dev *wdev;
1715
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001716 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001717 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1718 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001719 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001720 if (wp_idx < wp_start) {
1721 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001722 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001723 }
Johannes Berg55682962007-09-20 13:09:35 -04001724 if_idx = 0;
1725
Johannes Bergf5ea9122009-08-07 16:17:38 +02001726 mutex_lock(&rdev->devlist_mtx);
1727 list_for_each_entry(wdev, &rdev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001728 if (if_idx < if_start) {
1729 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001730 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001731 }
Johannes Berg55682962007-09-20 13:09:35 -04001732 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1733 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergf5ea9122009-08-07 16:17:38 +02001734 rdev, wdev->netdev) < 0) {
1735 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001736 goto out;
1737 }
1738 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001739 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001740 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001741
1742 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001743 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001744 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001745 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001746
1747 cb->args[0] = wp_idx;
1748 cb->args[1] = if_idx;
1749
1750 return skb->len;
1751}
1752
1753static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1754{
1755 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001756 struct cfg80211_registered_device *dev = info->user_ptr[0];
1757 struct net_device *netdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001758
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001759 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001760 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001761 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001762
Johannes Bergd7264052009-04-19 16:23:20 +02001763 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02001764 dev, netdev) < 0) {
1765 nlmsg_free(msg);
1766 return -ENOBUFS;
1767 }
Johannes Berg55682962007-09-20 13:09:35 -04001768
Johannes Berg134e6372009-07-10 09:51:34 +00001769 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001770}
1771
Michael Wu66f7ac52008-01-31 19:48:22 +01001772static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1773 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1774 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1775 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1776 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1777 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1778};
1779
1780static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1781{
1782 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1783 int flag;
1784
1785 *mntrflags = 0;
1786
1787 if (!nla)
1788 return -EINVAL;
1789
1790 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1791 nla, mntr_flags_policy))
1792 return -EINVAL;
1793
1794 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1795 if (flags[flag])
1796 *mntrflags |= (1<<flag);
1797
1798 return 0;
1799}
1800
Johannes Berg9bc383d2009-11-19 11:55:19 +01001801static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001802 struct net_device *netdev, u8 use_4addr,
1803 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001804{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001805 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001806 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001807 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001808 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001809 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001810
1811 switch (iftype) {
1812 case NL80211_IFTYPE_AP_VLAN:
1813 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1814 return 0;
1815 break;
1816 case NL80211_IFTYPE_STATION:
1817 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1818 return 0;
1819 break;
1820 default:
1821 break;
1822 }
1823
1824 return -EOPNOTSUPP;
1825}
1826
Johannes Berg55682962007-09-20 13:09:35 -04001827static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1828{
Johannes Berg4c476992010-10-04 21:36:35 +02001829 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001830 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001831 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001832 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001833 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001834 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001835 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001836
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001837 memset(&params, 0, sizeof(params));
1838
Johannes Berg04a773a2009-04-19 21:24:32 +02001839 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001840
Johannes Berg723b0382008-09-16 20:22:09 +02001841 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001842 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001843 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001844 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001845 if (ntype > NL80211_IFTYPE_MAX)
1846 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001847 }
1848
Johannes Berg92ffe052008-09-16 20:39:36 +02001849 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001850 struct wireless_dev *wdev = dev->ieee80211_ptr;
1851
Johannes Berg4c476992010-10-04 21:36:35 +02001852 if (ntype != NL80211_IFTYPE_MESH_POINT)
1853 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001854 if (netif_running(dev))
1855 return -EBUSY;
1856
1857 wdev_lock(wdev);
1858 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1859 IEEE80211_MAX_MESH_ID_LEN);
1860 wdev->mesh_id_up_len =
1861 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1862 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1863 wdev->mesh_id_up_len);
1864 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001865 }
1866
Felix Fietkau8b787642009-11-10 18:53:10 +01001867 if (info->attrs[NL80211_ATTR_4ADDR]) {
1868 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1869 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001870 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001871 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001872 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001873 } else {
1874 params.use_4addr = -1;
1875 }
1876
Johannes Berg92ffe052008-09-16 20:39:36 +02001877 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001878 if (ntype != NL80211_IFTYPE_MONITOR)
1879 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001880 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1881 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001882 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001883 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001884
1885 flags = &_flags;
1886 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001887 }
Johannes Berg3b858752009-03-12 09:55:09 +01001888
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001889 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001890 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001891 else
1892 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001893
Johannes Berg9bc383d2009-11-19 11:55:19 +01001894 if (!err && params.use_4addr != -1)
1895 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1896
Johannes Berg55682962007-09-20 13:09:35 -04001897 return err;
1898}
1899
1900static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1901{
Johannes Berg4c476992010-10-04 21:36:35 +02001902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001903 struct vif_params params;
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001904 struct net_device *dev;
Johannes Berg55682962007-09-20 13:09:35 -04001905 int err;
1906 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001907 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001908
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001909 memset(&params, 0, sizeof(params));
1910
Johannes Berg55682962007-09-20 13:09:35 -04001911 if (!info->attrs[NL80211_ATTR_IFNAME])
1912 return -EINVAL;
1913
1914 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1915 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1916 if (type > NL80211_IFTYPE_MAX)
1917 return -EINVAL;
1918 }
1919
Johannes Berg79c97e92009-07-07 03:56:12 +02001920 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02001921 !(rdev->wiphy.interface_modes & (1 << type)))
1922 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04001923
Johannes Berg9bc383d2009-11-19 11:55:19 +01001924 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01001925 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001926 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001927 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001928 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001929 }
Felix Fietkau8b787642009-11-10 18:53:10 +01001930
Michael Wu66f7ac52008-01-31 19:48:22 +01001931 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1932 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1933 &flags);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001934 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01001935 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001936 type, err ? NULL : &flags, &params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001937 if (IS_ERR(dev))
1938 return PTR_ERR(dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001939
Johannes Berg29cbe682010-12-03 09:20:44 +01001940 if (type == NL80211_IFTYPE_MESH_POINT &&
1941 info->attrs[NL80211_ATTR_MESH_ID]) {
1942 struct wireless_dev *wdev = dev->ieee80211_ptr;
1943
1944 wdev_lock(wdev);
1945 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1946 IEEE80211_MAX_MESH_ID_LEN);
1947 wdev->mesh_id_up_len =
1948 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1949 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1950 wdev->mesh_id_up_len);
1951 wdev_unlock(wdev);
1952 }
1953
Johannes Bergf9e10ce2010-12-03 09:20:42 +01001954 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001955}
1956
1957static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1958{
Johannes Berg4c476992010-10-04 21:36:35 +02001959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1960 struct net_device *dev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001961
Johannes Berg4c476992010-10-04 21:36:35 +02001962 if (!rdev->ops->del_virtual_intf)
1963 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01001964
Johannes Berg4c476992010-10-04 21:36:35 +02001965 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
Johannes Berg55682962007-09-20 13:09:35 -04001966}
1967
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001968static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1969{
1970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1971 struct net_device *dev = info->user_ptr[1];
1972 u16 noack_map;
1973
1974 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1975 return -EINVAL;
1976
1977 if (!rdev->ops->set_noack_map)
1978 return -EOPNOTSUPP;
1979
1980 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1981
1982 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1983}
1984
Johannes Berg41ade002007-12-19 02:03:29 +01001985struct get_key_cookie {
1986 struct sk_buff *msg;
1987 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02001988 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01001989};
1990
1991static void get_key_callback(void *c, struct key_params *params)
1992{
Johannes Bergb9454e82009-07-08 13:29:08 +02001993 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01001994 struct get_key_cookie *cookie = c;
1995
David S. Miller9360ffd2012-03-29 04:41:26 -04001996 if ((params->key &&
1997 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
1998 params->key_len, params->key)) ||
1999 (params->seq &&
2000 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2001 params->seq_len, params->seq)) ||
2002 (params->cipher &&
2003 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2004 params->cipher)))
2005 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002006
Johannes Bergb9454e82009-07-08 13:29:08 +02002007 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2008 if (!key)
2009 goto nla_put_failure;
2010
David S. Miller9360ffd2012-03-29 04:41:26 -04002011 if ((params->key &&
2012 nla_put(cookie->msg, NL80211_KEY_DATA,
2013 params->key_len, params->key)) ||
2014 (params->seq &&
2015 nla_put(cookie->msg, NL80211_KEY_SEQ,
2016 params->seq_len, params->seq)) ||
2017 (params->cipher &&
2018 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2019 params->cipher)))
2020 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002021
David S. Miller9360ffd2012-03-29 04:41:26 -04002022 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2023 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002024
2025 nla_nest_end(cookie->msg, key);
2026
Johannes Berg41ade002007-12-19 02:03:29 +01002027 return;
2028 nla_put_failure:
2029 cookie->error = 1;
2030}
2031
2032static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2033{
Johannes Berg4c476992010-10-04 21:36:35 +02002034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002035 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002036 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002037 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002038 const u8 *mac_addr = NULL;
2039 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002040 struct get_key_cookie cookie = {
2041 .error = 0,
2042 };
2043 void *hdr;
2044 struct sk_buff *msg;
2045
2046 if (info->attrs[NL80211_ATTR_KEY_IDX])
2047 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2048
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002049 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002050 return -EINVAL;
2051
2052 if (info->attrs[NL80211_ATTR_MAC])
2053 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2054
Johannes Berge31b8212010-10-05 19:39:30 +02002055 pairwise = !!mac_addr;
2056 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2057 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2058 if (kt >= NUM_NL80211_KEYTYPES)
2059 return -EINVAL;
2060 if (kt != NL80211_KEYTYPE_GROUP &&
2061 kt != NL80211_KEYTYPE_PAIRWISE)
2062 return -EINVAL;
2063 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2064 }
2065
Johannes Berg4c476992010-10-04 21:36:35 +02002066 if (!rdev->ops->get_key)
2067 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002068
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002070 if (!msg)
2071 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002072
2073 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2074 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002075 if (IS_ERR(hdr))
2076 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002077
2078 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002079 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002080
David S. Miller9360ffd2012-03-29 04:41:26 -04002081 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2082 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2083 goto nla_put_failure;
2084 if (mac_addr &&
2085 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2086 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002087
Johannes Berge31b8212010-10-05 19:39:30 +02002088 if (pairwise && mac_addr &&
2089 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2090 return -ENOENT;
2091
2092 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2093 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002094
2095 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002096 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002097
2098 if (cookie.error)
2099 goto nla_put_failure;
2100
2101 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002102 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002103
2104 nla_put_failure:
2105 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002106 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002107 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002108 return err;
2109}
2110
2111static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2112{
Johannes Berg4c476992010-10-04 21:36:35 +02002113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002114 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002115 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002116 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002117
Johannes Bergb9454e82009-07-08 13:29:08 +02002118 err = nl80211_parse_key(info, &key);
2119 if (err)
2120 return err;
2121
2122 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002123 return -EINVAL;
2124
Johannes Bergb9454e82009-07-08 13:29:08 +02002125 /* only support setting default key */
2126 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002127 return -EINVAL;
2128
Johannes Bergfffd0932009-07-08 14:22:54 +02002129 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002130
2131 if (key.def) {
2132 if (!rdev->ops->set_default_key) {
2133 err = -EOPNOTSUPP;
2134 goto out;
2135 }
2136
2137 err = nl80211_key_allowed(dev->ieee80211_ptr);
2138 if (err)
2139 goto out;
2140
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002141 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2142 key.def_uni, key.def_multi);
2143
2144 if (err)
2145 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002146
Johannes Berg3d23e342009-09-29 23:27:28 +02002147#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002148 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002149#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002150 } else {
2151 if (key.def_uni || !key.def_multi) {
2152 err = -EINVAL;
2153 goto out;
2154 }
2155
2156 if (!rdev->ops->set_default_mgmt_key) {
2157 err = -EOPNOTSUPP;
2158 goto out;
2159 }
2160
2161 err = nl80211_key_allowed(dev->ieee80211_ptr);
2162 if (err)
2163 goto out;
2164
2165 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2166 dev, key.idx);
2167 if (err)
2168 goto out;
2169
2170#ifdef CONFIG_CFG80211_WEXT
2171 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2172#endif
2173 }
2174
2175 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002176 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002177
Johannes Berg41ade002007-12-19 02:03:29 +01002178 return err;
2179}
2180
2181static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2182{
Johannes Berg4c476992010-10-04 21:36:35 +02002183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002184 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002185 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002186 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002187 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002188
Johannes Bergb9454e82009-07-08 13:29:08 +02002189 err = nl80211_parse_key(info, &key);
2190 if (err)
2191 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002192
Johannes Bergb9454e82009-07-08 13:29:08 +02002193 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002194 return -EINVAL;
2195
Johannes Berg41ade002007-12-19 02:03:29 +01002196 if (info->attrs[NL80211_ATTR_MAC])
2197 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2198
Johannes Berge31b8212010-10-05 19:39:30 +02002199 if (key.type == -1) {
2200 if (mac_addr)
2201 key.type = NL80211_KEYTYPE_PAIRWISE;
2202 else
2203 key.type = NL80211_KEYTYPE_GROUP;
2204 }
2205
2206 /* for now */
2207 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2208 key.type != NL80211_KEYTYPE_GROUP)
2209 return -EINVAL;
2210
Johannes Berg4c476992010-10-04 21:36:35 +02002211 if (!rdev->ops->add_key)
2212 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002213
Johannes Berge31b8212010-10-05 19:39:30 +02002214 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2215 key.type == NL80211_KEYTYPE_PAIRWISE,
2216 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002217 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002218
2219 wdev_lock(dev->ieee80211_ptr);
2220 err = nl80211_key_allowed(dev->ieee80211_ptr);
2221 if (!err)
2222 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002223 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002224 mac_addr, &key.p);
2225 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002226
Johannes Berg41ade002007-12-19 02:03:29 +01002227 return err;
2228}
2229
2230static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2231{
Johannes Berg4c476992010-10-04 21:36:35 +02002232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002233 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002234 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002235 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002236 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002237
Johannes Bergb9454e82009-07-08 13:29:08 +02002238 err = nl80211_parse_key(info, &key);
2239 if (err)
2240 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002241
2242 if (info->attrs[NL80211_ATTR_MAC])
2243 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2244
Johannes Berge31b8212010-10-05 19:39:30 +02002245 if (key.type == -1) {
2246 if (mac_addr)
2247 key.type = NL80211_KEYTYPE_PAIRWISE;
2248 else
2249 key.type = NL80211_KEYTYPE_GROUP;
2250 }
2251
2252 /* for now */
2253 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2254 key.type != NL80211_KEYTYPE_GROUP)
2255 return -EINVAL;
2256
Johannes Berg4c476992010-10-04 21:36:35 +02002257 if (!rdev->ops->del_key)
2258 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002259
Johannes Bergfffd0932009-07-08 14:22:54 +02002260 wdev_lock(dev->ieee80211_ptr);
2261 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002262
2263 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2264 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2265 err = -ENOENT;
2266
Johannes Bergfffd0932009-07-08 14:22:54 +02002267 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002268 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2269 key.type == NL80211_KEYTYPE_PAIRWISE,
2270 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002271
Johannes Berg3d23e342009-09-29 23:27:28 +02002272#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002273 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002274 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002275 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002276 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002277 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2278 }
2279#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002280 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002281
Johannes Berg41ade002007-12-19 02:03:29 +01002282 return err;
2283}
2284
Johannes Berg88600202012-02-13 15:17:18 +01002285static int nl80211_parse_beacon(struct genl_info *info,
2286 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002287{
Johannes Berg88600202012-02-13 15:17:18 +01002288 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002289
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002290 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2291 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2292 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2293 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002294 return -EINVAL;
2295
Johannes Berg88600202012-02-13 15:17:18 +01002296 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002297
Johannes Berged1b6cc2007-12-19 02:03:32 +01002298 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002299 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2300 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2301 if (!bcn->head_len)
2302 return -EINVAL;
2303 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002304 }
2305
2306 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002307 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2308 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002309 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002310 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002311 }
2312
Johannes Berg4c476992010-10-04 21:36:35 +02002313 if (!haveinfo)
2314 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002315
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002316 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002317 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2318 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002319 }
2320
2321 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002322 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002323 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002324 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002325 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2326 }
2327
2328 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002329 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002330 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002331 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002332 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2333 }
2334
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002335 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002336 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002337 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002338 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002339 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2340 }
2341
Johannes Berg88600202012-02-13 15:17:18 +01002342 return 0;
2343}
2344
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002345static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2346 struct cfg80211_ap_settings *params)
2347{
2348 struct wireless_dev *wdev;
2349 bool ret = false;
2350
2351 mutex_lock(&rdev->devlist_mtx);
2352
2353 list_for_each_entry(wdev, &rdev->netdev_list, list) {
2354 if (wdev->iftype != NL80211_IFTYPE_AP &&
2355 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2356 continue;
2357
2358 if (!wdev->preset_chan)
2359 continue;
2360
2361 params->channel = wdev->preset_chan;
2362 params->channel_type = wdev->preset_chantype;
2363 ret = true;
2364 break;
2365 }
2366
2367 mutex_unlock(&rdev->devlist_mtx);
2368
2369 return ret;
2370}
2371
Johannes Berg88600202012-02-13 15:17:18 +01002372static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2373{
2374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2375 struct net_device *dev = info->user_ptr[1];
2376 struct wireless_dev *wdev = dev->ieee80211_ptr;
2377 struct cfg80211_ap_settings params;
2378 int err;
2379
2380 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2381 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2382 return -EOPNOTSUPP;
2383
2384 if (!rdev->ops->start_ap)
2385 return -EOPNOTSUPP;
2386
2387 if (wdev->beacon_interval)
2388 return -EALREADY;
2389
2390 memset(&params, 0, sizeof(params));
2391
2392 /* these are required for START_AP */
2393 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2394 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2395 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2396 return -EINVAL;
2397
2398 err = nl80211_parse_beacon(info, &params.beacon);
2399 if (err)
2400 return err;
2401
2402 params.beacon_interval =
2403 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2404 params.dtim_period =
2405 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2406
2407 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2408 if (err)
2409 return err;
2410
2411 /*
2412 * In theory, some of these attributes should be required here
2413 * but since they were not used when the command was originally
2414 * added, keep them optional for old user space programs to let
2415 * them continue to work with drivers that do not need the
2416 * additional information -- drivers must check!
2417 */
2418 if (info->attrs[NL80211_ATTR_SSID]) {
2419 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2420 params.ssid_len =
2421 nla_len(info->attrs[NL80211_ATTR_SSID]);
2422 if (params.ssid_len == 0 ||
2423 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2424 return -EINVAL;
2425 }
2426
2427 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2428 params.hidden_ssid = nla_get_u32(
2429 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2430 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2431 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2432 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2433 return -EINVAL;
2434 }
2435
2436 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2437
2438 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2439 params.auth_type = nla_get_u32(
2440 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2441 if (!nl80211_valid_auth_type(params.auth_type))
2442 return -EINVAL;
2443 } else
2444 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2445
2446 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2447 NL80211_MAX_NR_CIPHER_SUITES);
2448 if (err)
2449 return err;
2450
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302451 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2452 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2453 return -EOPNOTSUPP;
2454 params.inactivity_timeout = nla_get_u16(
2455 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2456 }
2457
Johannes Bergaa430da2012-05-16 23:50:18 +02002458 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2459 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2460
2461 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2462 !nl80211_valid_channel_type(info, &channel_type))
2463 return -EINVAL;
2464
2465 params.channel = rdev_freq_to_chan(rdev,
2466 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2467 channel_type);
2468 if (!params.channel)
2469 return -EINVAL;
2470 params.channel_type = channel_type;
2471 } else if (wdev->preset_chan) {
2472 params.channel = wdev->preset_chan;
2473 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002474 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002475 return -EINVAL;
2476
2477 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2478 params.channel_type))
2479 return -EINVAL;
2480
Michal Kaziore4e32452012-06-29 12:47:08 +02002481 mutex_lock(&rdev->devlist_mtx);
2482 err = cfg80211_can_use_chan(rdev, wdev, params.channel,
2483 CHAN_MODE_SHARED);
2484 mutex_unlock(&rdev->devlist_mtx);
2485
2486 if (err)
2487 return err;
2488
Johannes Berg88600202012-02-13 15:17:18 +01002489 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002490 if (!err) {
2491 wdev->preset_chan = params.channel;
2492 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002493 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002494 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002495 }
Johannes Berg56d18932011-05-09 18:41:15 +02002496 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002497}
2498
Johannes Berg88600202012-02-13 15:17:18 +01002499static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2500{
2501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2502 struct net_device *dev = info->user_ptr[1];
2503 struct wireless_dev *wdev = dev->ieee80211_ptr;
2504 struct cfg80211_beacon_data params;
2505 int err;
2506
2507 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2508 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2509 return -EOPNOTSUPP;
2510
2511 if (!rdev->ops->change_beacon)
2512 return -EOPNOTSUPP;
2513
2514 if (!wdev->beacon_interval)
2515 return -EINVAL;
2516
2517 err = nl80211_parse_beacon(info, &params);
2518 if (err)
2519 return err;
2520
2521 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2522}
2523
2524static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002525{
Johannes Berg4c476992010-10-04 21:36:35 +02002526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2527 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002528
Michal Kazior60771782012-06-29 12:46:56 +02002529 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002530}
2531
Johannes Berg5727ef12007-12-19 02:03:34 +01002532static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2533 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2534 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2535 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002536 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002537 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002538 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002539};
2540
Johannes Bergeccb8e82009-05-11 21:57:56 +03002541static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002542 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002543 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002544{
2545 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002546 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002547 int flag;
2548
Johannes Bergeccb8e82009-05-11 21:57:56 +03002549 /*
2550 * Try parsing the new attribute first so userspace
2551 * can specify both for older kernels.
2552 */
2553 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2554 if (nla) {
2555 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002556
Johannes Bergeccb8e82009-05-11 21:57:56 +03002557 sta_flags = nla_data(nla);
2558 params->sta_flags_mask = sta_flags->mask;
2559 params->sta_flags_set = sta_flags->set;
2560 if ((params->sta_flags_mask |
2561 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2562 return -EINVAL;
2563 return 0;
2564 }
2565
2566 /* if present, parse the old attribute */
2567
2568 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002569 if (!nla)
2570 return 0;
2571
2572 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2573 nla, sta_flags_policy))
2574 return -EINVAL;
2575
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002576 /*
2577 * Only allow certain flags for interface types so that
2578 * other attributes are silently ignored. Remember that
2579 * this is backward compatibility code with old userspace
2580 * and shouldn't be hit in other cases anyway.
2581 */
2582 switch (iftype) {
2583 case NL80211_IFTYPE_AP:
2584 case NL80211_IFTYPE_AP_VLAN:
2585 case NL80211_IFTYPE_P2P_GO:
2586 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2587 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2588 BIT(NL80211_STA_FLAG_WME) |
2589 BIT(NL80211_STA_FLAG_MFP);
2590 break;
2591 case NL80211_IFTYPE_P2P_CLIENT:
2592 case NL80211_IFTYPE_STATION:
2593 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2594 BIT(NL80211_STA_FLAG_TDLS_PEER);
2595 break;
2596 case NL80211_IFTYPE_MESH_POINT:
2597 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2598 BIT(NL80211_STA_FLAG_MFP) |
2599 BIT(NL80211_STA_FLAG_AUTHORIZED);
2600 default:
2601 return -EINVAL;
2602 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002603
Johannes Berg3383b5a2012-05-10 20:14:43 +02002604 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2605 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002606 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002607
Johannes Berg3383b5a2012-05-10 20:14:43 +02002608 /* no longer support new API additions in old API */
2609 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2610 return -EINVAL;
2611 }
2612 }
2613
Johannes Berg5727ef12007-12-19 02:03:34 +01002614 return 0;
2615}
2616
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002617static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2618 int attr)
2619{
2620 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002621 u32 bitrate;
2622 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002623
2624 rate = nla_nest_start(msg, attr);
2625 if (!rate)
2626 goto nla_put_failure;
2627
2628 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2629 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002630 /* report 16-bit bitrate only if we can */
2631 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
David S. Miller9360ffd2012-03-29 04:41:26 -04002632 if ((bitrate > 0 &&
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002633 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
2634 (bitrate_compat > 0 &&
2635 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002636 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2637 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2638 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2639 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2640 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2641 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2642 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002643
2644 nla_nest_end(msg, rate);
2645 return true;
2646
2647nla_put_failure:
2648 return false;
2649}
2650
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002651static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002652 int flags,
2653 struct cfg80211_registered_device *rdev,
2654 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002655 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002656{
2657 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002658 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002659
2660 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2661 if (!hdr)
2662 return -1;
2663
David S. Miller9360ffd2012-03-29 04:41:26 -04002664 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2665 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2666 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2667 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002668
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002669 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2670 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002671 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002672 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2673 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2674 sinfo->connected_time))
2675 goto nla_put_failure;
2676 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2677 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2678 sinfo->inactive_time))
2679 goto nla_put_failure;
2680 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2681 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2682 sinfo->rx_bytes))
2683 goto nla_put_failure;
2684 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2685 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2686 sinfo->tx_bytes))
2687 goto nla_put_failure;
2688 if ((sinfo->filled & STATION_INFO_LLID) &&
2689 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2690 goto nla_put_failure;
2691 if ((sinfo->filled & STATION_INFO_PLID) &&
2692 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2693 goto nla_put_failure;
2694 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2695 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2696 sinfo->plink_state))
2697 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002698 switch (rdev->wiphy.signal_type) {
2699 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002700 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2701 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2702 sinfo->signal))
2703 goto nla_put_failure;
2704 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2705 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2706 sinfo->signal_avg))
2707 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002708 break;
2709 default:
2710 break;
2711 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002712 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002713 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2714 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002715 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002716 }
2717 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2718 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2719 NL80211_STA_INFO_RX_BITRATE))
2720 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002721 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002722 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2723 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2724 sinfo->rx_packets))
2725 goto nla_put_failure;
2726 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2727 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2728 sinfo->tx_packets))
2729 goto nla_put_failure;
2730 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2731 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2732 sinfo->tx_retries))
2733 goto nla_put_failure;
2734 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2735 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2736 sinfo->tx_failed))
2737 goto nla_put_failure;
2738 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2739 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2740 sinfo->beacon_loss_count))
2741 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002742 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2743 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2744 if (!bss_param)
2745 goto nla_put_failure;
2746
David S. Miller9360ffd2012-03-29 04:41:26 -04002747 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2748 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2749 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2750 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2751 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2752 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2753 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2754 sinfo->bss_param.dtim_period) ||
2755 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2756 sinfo->bss_param.beacon_interval))
2757 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002758
2759 nla_nest_end(msg, bss_param);
2760 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002761 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2762 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2763 sizeof(struct nl80211_sta_flag_update),
2764 &sinfo->sta_flags))
2765 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002766 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2767 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2768 sinfo->t_offset))
2769 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002770 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002771
David S. Miller9360ffd2012-03-29 04:41:26 -04002772 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2773 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2774 sinfo->assoc_req_ies))
2775 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002776
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002777 return genlmsg_end(msg, hdr);
2778
2779 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002780 genlmsg_cancel(msg, hdr);
2781 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002782}
2783
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002784static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002785 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002786{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002787 struct station_info sinfo;
2788 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002789 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002790 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002791 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002792 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002793
Johannes Berg67748892010-10-04 21:14:06 +02002794 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2795 if (err)
2796 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002797
2798 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002799 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002800 goto out_err;
2801 }
2802
Johannes Bergbba95fe2008-07-29 13:22:51 +02002803 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002804 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002805 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2806 mac_addr, &sinfo);
2807 if (err == -ENOENT)
2808 break;
2809 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002810 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002811
2812 if (nl80211_send_station(skb,
2813 NETLINK_CB(cb->skb).pid,
2814 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002815 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002816 &sinfo) < 0)
2817 goto out;
2818
2819 sta_idx++;
2820 }
2821
2822
2823 out:
2824 cb->args[1] = sta_idx;
2825 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002826 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002827 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002828
2829 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002830}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002831
Johannes Berg5727ef12007-12-19 02:03:34 +01002832static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2833{
Johannes Berg4c476992010-10-04 21:36:35 +02002834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2835 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002836 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002837 struct sk_buff *msg;
2838 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002839 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002840
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002841 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002842
2843 if (!info->attrs[NL80211_ATTR_MAC])
2844 return -EINVAL;
2845
2846 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2847
Johannes Berg4c476992010-10-04 21:36:35 +02002848 if (!rdev->ops->get_station)
2849 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002850
Johannes Berg79c97e92009-07-07 03:56:12 +02002851 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002852 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002853 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002854
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002855 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002856 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002857 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002858
2859 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04002860 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002861 nlmsg_free(msg);
2862 return -ENOBUFS;
2863 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002864
Johannes Berg4c476992010-10-04 21:36:35 +02002865 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01002866}
2867
2868/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01002869 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01002870 */
Johannes Berg80b99892011-11-18 16:23:01 +01002871static struct net_device *get_vlan(struct genl_info *info,
2872 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01002873{
Johannes Berg463d0182009-07-14 00:33:35 +02002874 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01002875 struct net_device *v;
2876 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01002877
Johannes Berg80b99892011-11-18 16:23:01 +01002878 if (!vlanattr)
2879 return NULL;
2880
2881 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2882 if (!v)
2883 return ERR_PTR(-ENODEV);
2884
2885 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2886 ret = -EINVAL;
2887 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01002888 }
Johannes Berg80b99892011-11-18 16:23:01 +01002889
2890 if (!netif_running(v)) {
2891 ret = -ENETDOWN;
2892 goto error;
2893 }
2894
2895 return v;
2896 error:
2897 dev_put(v);
2898 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01002899}
2900
2901static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2902{
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01002904 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002905 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01002906 struct station_parameters params;
2907 u8 *mac_addr = NULL;
2908
2909 memset(&params, 0, sizeof(params));
2910
2911 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07002912 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01002913
2914 if (info->attrs[NL80211_ATTR_STA_AID])
2915 return -EINVAL;
2916
2917 if (!info->attrs[NL80211_ATTR_MAC])
2918 return -EINVAL;
2919
2920 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2921
2922 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2923 params.supported_rates =
2924 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2925 params.supported_rates_len =
2926 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2927 }
2928
2929 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2930 params.listen_interval =
2931 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2932
Jouni Malinen36aedc902008-08-25 11:58:58 +03002933 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2934 params.ht_capa =
2935 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2936
Johannes Bergbdd90d52011-12-14 12:20:27 +01002937 if (!rdev->ops->change_station)
2938 return -EOPNOTSUPP;
2939
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002940 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01002941 return -EINVAL;
2942
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002943 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2944 params.plink_action =
2945 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2946
Javier Cardona9c3990a2011-05-03 16:57:11 -07002947 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2948 params.plink_state =
2949 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2950
Johannes Berga97f4422009-06-18 17:23:43 +02002951 switch (dev->ieee80211_ptr->iftype) {
2952 case NL80211_IFTYPE_AP:
2953 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02002954 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02002955 /* disallow mesh-specific things */
2956 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01002957 return -EINVAL;
2958
2959 /* TDLS can't be set, ... */
2960 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2961 return -EINVAL;
2962 /*
2963 * ... but don't bother the driver with it. This works around
2964 * a hostapd/wpa_supplicant issue -- it always includes the
2965 * TLDS_PEER flag in the mask even for AP mode.
2966 */
2967 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2968
2969 /* accept only the listed bits */
2970 if (params.sta_flags_mask &
2971 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2972 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2973 BIT(NL80211_STA_FLAG_WME) |
2974 BIT(NL80211_STA_FLAG_MFP)))
2975 return -EINVAL;
2976
2977 /* must be last in here for error handling */
2978 params.vlan = get_vlan(info, rdev);
2979 if (IS_ERR(params.vlan))
2980 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02002981 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02002982 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02002983 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01002984 /*
2985 * Don't allow userspace to change the TDLS_PEER flag,
2986 * but silently ignore attempts to change it since we
2987 * don't have state here to verify that it doesn't try
2988 * to change the flag.
2989 */
2990 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01002991 /* fall through */
2992 case NL80211_IFTYPE_ADHOC:
2993 /* disallow things sta doesn't support */
2994 if (params.plink_action)
2995 return -EINVAL;
2996 if (params.ht_capa)
2997 return -EINVAL;
2998 if (params.listen_interval >= 0)
2999 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003000 /* reject any changes other than AUTHORIZED */
3001 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3002 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003003 break;
3004 case NL80211_IFTYPE_MESH_POINT:
3005 /* disallow things mesh doesn't support */
3006 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003007 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003008 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003009 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003010 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003011 return -EINVAL;
3012 /*
3013 * No special handling for TDLS here -- the userspace
3014 * mesh code doesn't have this bug.
3015 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003016 if (params.sta_flags_mask &
3017 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003018 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003019 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003020 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003021 break;
3022 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003023 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003024 }
3025
Johannes Bergbdd90d52011-12-14 12:20:27 +01003026 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003027
Johannes Berg79c97e92009-07-07 03:56:12 +02003028 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003029
Johannes Berg5727ef12007-12-19 02:03:34 +01003030 if (params.vlan)
3031 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003032
Johannes Berg5727ef12007-12-19 02:03:34 +01003033 return err;
3034}
3035
Eliad Pellerc75786c2011-08-23 14:37:46 +03003036static struct nla_policy
3037nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3038 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3039 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3040};
3041
Johannes Berg5727ef12007-12-19 02:03:34 +01003042static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3043{
Johannes Berg4c476992010-10-04 21:36:35 +02003044 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003045 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003046 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003047 struct station_parameters params;
3048 u8 *mac_addr = NULL;
3049
3050 memset(&params, 0, sizeof(params));
3051
3052 if (!info->attrs[NL80211_ATTR_MAC])
3053 return -EINVAL;
3054
Johannes Berg5727ef12007-12-19 02:03:34 +01003055 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3056 return -EINVAL;
3057
3058 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3059 return -EINVAL;
3060
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003061 if (!info->attrs[NL80211_ATTR_STA_AID])
3062 return -EINVAL;
3063
Johannes Berg5727ef12007-12-19 02:03:34 +01003064 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3065 params.supported_rates =
3066 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3067 params.supported_rates_len =
3068 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3069 params.listen_interval =
3070 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003071
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003072 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3073 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3074 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003075
Jouni Malinen36aedc902008-08-25 11:58:58 +03003076 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3077 params.ht_capa =
3078 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003079
Javier Cardona96b78df2011-04-07 15:08:33 -07003080 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3081 params.plink_action =
3082 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3083
Johannes Bergbdd90d52011-12-14 12:20:27 +01003084 if (!rdev->ops->add_station)
3085 return -EOPNOTSUPP;
3086
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003087 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003088 return -EINVAL;
3089
Johannes Bergbdd90d52011-12-14 12:20:27 +01003090 switch (dev->ieee80211_ptr->iftype) {
3091 case NL80211_IFTYPE_AP:
3092 case NL80211_IFTYPE_AP_VLAN:
3093 case NL80211_IFTYPE_P2P_GO:
3094 /* parse WME attributes if sta is WME capable */
3095 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3096 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3097 info->attrs[NL80211_ATTR_STA_WME]) {
3098 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3099 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003100
Johannes Bergbdd90d52011-12-14 12:20:27 +01003101 nla = info->attrs[NL80211_ATTR_STA_WME];
3102 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3103 nl80211_sta_wme_policy);
3104 if (err)
3105 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003106
Johannes Bergbdd90d52011-12-14 12:20:27 +01003107 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3108 params.uapsd_queues =
3109 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3110 if (params.uapsd_queues &
3111 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3112 return -EINVAL;
3113
3114 if (tb[NL80211_STA_WME_MAX_SP])
3115 params.max_sp =
3116 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3117
3118 if (params.max_sp &
3119 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3120 return -EINVAL;
3121
3122 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3123 }
3124 /* TDLS peers cannot be added */
3125 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003126 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003127 /* but don't bother the driver with it */
3128 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003129
Johannes Bergbdd90d52011-12-14 12:20:27 +01003130 /* must be last in here for error handling */
3131 params.vlan = get_vlan(info, rdev);
3132 if (IS_ERR(params.vlan))
3133 return PTR_ERR(params.vlan);
3134 break;
3135 case NL80211_IFTYPE_MESH_POINT:
3136 /* TDLS peers cannot be added */
3137 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003138 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003139 break;
3140 case NL80211_IFTYPE_STATION:
3141 /* Only TDLS peers can be added */
3142 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3143 return -EINVAL;
3144 /* Can only add if TDLS ... */
3145 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3146 return -EOPNOTSUPP;
3147 /* ... with external setup is supported */
3148 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3149 return -EOPNOTSUPP;
3150 break;
3151 default:
3152 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003153 }
3154
Johannes Bergbdd90d52011-12-14 12:20:27 +01003155 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003156
Johannes Berg79c97e92009-07-07 03:56:12 +02003157 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003158
Johannes Berg5727ef12007-12-19 02:03:34 +01003159 if (params.vlan)
3160 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003161 return err;
3162}
3163
3164static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3165{
Johannes Berg4c476992010-10-04 21:36:35 +02003166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3167 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003168 u8 *mac_addr = NULL;
3169
3170 if (info->attrs[NL80211_ATTR_MAC])
3171 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3172
Johannes Berge80cf852009-05-11 14:43:13 +02003173 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003174 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003175 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003176 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3177 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003178
Johannes Berg4c476992010-10-04 21:36:35 +02003179 if (!rdev->ops->del_station)
3180 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003181
Johannes Berg4c476992010-10-04 21:36:35 +02003182 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003183}
3184
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003185static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
3186 int flags, struct net_device *dev,
3187 u8 *dst, u8 *next_hop,
3188 struct mpath_info *pinfo)
3189{
3190 void *hdr;
3191 struct nlattr *pinfoattr;
3192
3193 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
3194 if (!hdr)
3195 return -1;
3196
David S. Miller9360ffd2012-03-29 04:41:26 -04003197 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3198 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3199 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3200 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3201 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003202
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003203 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3204 if (!pinfoattr)
3205 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003206 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3207 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3208 pinfo->frame_qlen))
3209 goto nla_put_failure;
3210 if (((pinfo->filled & MPATH_INFO_SN) &&
3211 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3212 ((pinfo->filled & MPATH_INFO_METRIC) &&
3213 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3214 pinfo->metric)) ||
3215 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3216 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3217 pinfo->exptime)) ||
3218 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3219 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3220 pinfo->flags)) ||
3221 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3222 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3223 pinfo->discovery_timeout)) ||
3224 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3225 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3226 pinfo->discovery_retries)))
3227 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003228
3229 nla_nest_end(msg, pinfoattr);
3230
3231 return genlmsg_end(msg, hdr);
3232
3233 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003234 genlmsg_cancel(msg, hdr);
3235 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003236}
3237
3238static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003239 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003240{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003241 struct mpath_info pinfo;
3242 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003243 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003244 u8 dst[ETH_ALEN];
3245 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003246 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003247 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003248
Johannes Berg67748892010-10-04 21:14:06 +02003249 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3250 if (err)
3251 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003252
3253 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003254 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003255 goto out_err;
3256 }
3257
Jouni Malineneec60b02009-03-20 21:21:19 +02003258 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3259 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003260 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003261 }
3262
Johannes Bergbba95fe2008-07-29 13:22:51 +02003263 while (1) {
3264 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3265 dst, next_hop, &pinfo);
3266 if (err == -ENOENT)
3267 break;
3268 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003269 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003270
3271 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
3272 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3273 netdev, dst, next_hop,
3274 &pinfo) < 0)
3275 goto out;
3276
3277 path_idx++;
3278 }
3279
3280
3281 out:
3282 cb->args[1] = path_idx;
3283 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003284 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003285 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003286 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003287}
3288
3289static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3290{
Johannes Berg4c476992010-10-04 21:36:35 +02003291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003292 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003293 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003294 struct mpath_info pinfo;
3295 struct sk_buff *msg;
3296 u8 *dst = NULL;
3297 u8 next_hop[ETH_ALEN];
3298
3299 memset(&pinfo, 0, sizeof(pinfo));
3300
3301 if (!info->attrs[NL80211_ATTR_MAC])
3302 return -EINVAL;
3303
3304 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3305
Johannes Berg4c476992010-10-04 21:36:35 +02003306 if (!rdev->ops->get_mpath)
3307 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003308
Johannes Berg4c476992010-10-04 21:36:35 +02003309 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3310 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003311
Johannes Berg79c97e92009-07-07 03:56:12 +02003312 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003313 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003314 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003315
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003316 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003317 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003318 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003319
3320 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003321 dev, dst, next_hop, &pinfo) < 0) {
3322 nlmsg_free(msg);
3323 return -ENOBUFS;
3324 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003325
Johannes Berg4c476992010-10-04 21:36:35 +02003326 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003327}
3328
3329static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3330{
Johannes Berg4c476992010-10-04 21:36:35 +02003331 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3332 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003333 u8 *dst = NULL;
3334 u8 *next_hop = NULL;
3335
3336 if (!info->attrs[NL80211_ATTR_MAC])
3337 return -EINVAL;
3338
3339 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3340 return -EINVAL;
3341
3342 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3343 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3344
Johannes Berg4c476992010-10-04 21:36:35 +02003345 if (!rdev->ops->change_mpath)
3346 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003347
Johannes Berg4c476992010-10-04 21:36:35 +02003348 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3349 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003350
Johannes Berg4c476992010-10-04 21:36:35 +02003351 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003352}
Johannes Berg4c476992010-10-04 21:36:35 +02003353
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003354static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3355{
Johannes Berg4c476992010-10-04 21:36:35 +02003356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3357 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003358 u8 *dst = NULL;
3359 u8 *next_hop = NULL;
3360
3361 if (!info->attrs[NL80211_ATTR_MAC])
3362 return -EINVAL;
3363
3364 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3365 return -EINVAL;
3366
3367 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3368 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3369
Johannes Berg4c476992010-10-04 21:36:35 +02003370 if (!rdev->ops->add_mpath)
3371 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003372
Johannes Berg4c476992010-10-04 21:36:35 +02003373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3374 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003375
Johannes Berg4c476992010-10-04 21:36:35 +02003376 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003377}
3378
3379static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3380{
Johannes Berg4c476992010-10-04 21:36:35 +02003381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3382 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003383 u8 *dst = NULL;
3384
3385 if (info->attrs[NL80211_ATTR_MAC])
3386 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3387
Johannes Berg4c476992010-10-04 21:36:35 +02003388 if (!rdev->ops->del_mpath)
3389 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003390
Johannes Berg4c476992010-10-04 21:36:35 +02003391 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003392}
3393
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003394static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3395{
Johannes Berg4c476992010-10-04 21:36:35 +02003396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3397 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003398 struct bss_parameters params;
3399
3400 memset(&params, 0, sizeof(params));
3401 /* default to not changing parameters */
3402 params.use_cts_prot = -1;
3403 params.use_short_preamble = -1;
3404 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003405 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003406 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003407
3408 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3409 params.use_cts_prot =
3410 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3411 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3412 params.use_short_preamble =
3413 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3414 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3415 params.use_short_slot_time =
3416 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003417 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3418 params.basic_rates =
3419 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3420 params.basic_rates_len =
3421 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3422 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003423 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3424 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003425 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3426 params.ht_opmode =
3427 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003428
Johannes Berg4c476992010-10-04 21:36:35 +02003429 if (!rdev->ops->change_bss)
3430 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003431
Johannes Berg074ac8d2010-09-16 14:58:22 +02003432 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003433 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3434 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003435
Johannes Berg4c476992010-10-04 21:36:35 +02003436 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003437}
3438
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003439static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003440 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3441 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3442 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3443 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3444 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3445 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3446};
3447
3448static int parse_reg_rule(struct nlattr *tb[],
3449 struct ieee80211_reg_rule *reg_rule)
3450{
3451 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3452 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3453
3454 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3455 return -EINVAL;
3456 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3457 return -EINVAL;
3458 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3459 return -EINVAL;
3460 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3461 return -EINVAL;
3462 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3463 return -EINVAL;
3464
3465 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3466
3467 freq_range->start_freq_khz =
3468 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3469 freq_range->end_freq_khz =
3470 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3471 freq_range->max_bandwidth_khz =
3472 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3473
3474 power_rule->max_eirp =
3475 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3476
3477 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3478 power_rule->max_antenna_gain =
3479 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3480
3481 return 0;
3482}
3483
3484static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3485{
3486 int r;
3487 char *data = NULL;
3488
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003489 /*
3490 * You should only get this when cfg80211 hasn't yet initialized
3491 * completely when built-in to the kernel right between the time
3492 * window between nl80211_init() and regulatory_init(), if that is
3493 * even possible.
3494 */
3495 mutex_lock(&cfg80211_mutex);
3496 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003497 mutex_unlock(&cfg80211_mutex);
3498 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003499 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003500 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003501
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003502 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3503 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003504
3505 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3506
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003507 r = regulatory_hint_user(data);
3508
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003509 return r;
3510}
3511
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003512static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003513 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003514{
Johannes Berg4c476992010-10-04 21:36:35 +02003515 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003516 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003517 struct wireless_dev *wdev = dev->ieee80211_ptr;
3518 struct mesh_config cur_params;
3519 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003520 void *hdr;
3521 struct nlattr *pinfoattr;
3522 struct sk_buff *msg;
3523
Johannes Berg29cbe682010-12-03 09:20:44 +01003524 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3525 return -EOPNOTSUPP;
3526
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003527 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003528 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003529
Johannes Berg29cbe682010-12-03 09:20:44 +01003530 wdev_lock(wdev);
3531 /* If not connected, get default parameters */
3532 if (!wdev->mesh_id_len)
3533 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3534 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003535 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003536 &cur_params);
3537 wdev_unlock(wdev);
3538
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003539 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003540 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003541
3542 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003543 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003544 if (!msg)
3545 return -ENOMEM;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003546 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003547 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003548 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003549 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003550 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003551 if (!pinfoattr)
3552 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003553 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3554 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3555 cur_params.dot11MeshRetryTimeout) ||
3556 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3557 cur_params.dot11MeshConfirmTimeout) ||
3558 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3559 cur_params.dot11MeshHoldingTimeout) ||
3560 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3561 cur_params.dot11MeshMaxPeerLinks) ||
3562 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3563 cur_params.dot11MeshMaxRetries) ||
3564 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3565 cur_params.dot11MeshTTL) ||
3566 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3567 cur_params.element_ttl) ||
3568 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3569 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003570 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3571 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003572 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3573 cur_params.dot11MeshHWMPmaxPREQretries) ||
3574 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3575 cur_params.path_refresh_time) ||
3576 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3577 cur_params.min_discovery_timeout) ||
3578 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3579 cur_params.dot11MeshHWMPactivePathTimeout) ||
3580 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3581 cur_params.dot11MeshHWMPpreqMinInterval) ||
3582 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3583 cur_params.dot11MeshHWMPperrMinInterval) ||
3584 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3585 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3586 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3587 cur_params.dot11MeshHWMPRootMode) ||
3588 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3589 cur_params.dot11MeshHWMPRannInterval) ||
3590 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3591 cur_params.dot11MeshGateAnnouncementProtocol) ||
3592 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3593 cur_params.dot11MeshForwarding) ||
3594 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003595 cur_params.rssi_threshold) ||
3596 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003597 cur_params.ht_opmode) ||
3598 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3599 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3600 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003601 cur_params.dot11MeshHWMProotInterval) ||
3602 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3603 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003604 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003605 nla_nest_end(msg, pinfoattr);
3606 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003607 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003608
Johannes Berg3b858752009-03-12 09:55:09 +01003609 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003610 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003611 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003612 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003613 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003614}
3615
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003616static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003617 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3618 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3619 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3620 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3621 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3622 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003623 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003624 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003625 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003626 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3627 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3628 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3629 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3630 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003631 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003632 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003633 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003634 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003635 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003636 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003637 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3638 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003639 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3640 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003641 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003642};
3643
Javier Cardonac80d5452010-12-16 17:37:49 -08003644static const struct nla_policy
3645 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003646 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003647 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3648 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003649 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003650 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003651 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003652 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003653};
3654
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003655static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003656 struct mesh_config *cfg,
3657 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003658{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003659 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003660 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003661
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003662#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3663do {\
3664 if (table[attr_num]) {\
3665 cfg->param = nla_fn(table[attr_num]); \
3666 mask |= (1 << (attr_num - 1)); \
3667 } \
3668} while (0);\
3669
3670
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003671 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003672 return -EINVAL;
3673 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003674 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003675 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003676 return -EINVAL;
3677
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003678 /* This makes sure that there aren't more than 32 mesh config
3679 * parameters (otherwise our bitfield scheme would not work.) */
3680 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3681
3682 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003683 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003684 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3685 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003686 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003687 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3688 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003690 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3691 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003693 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3694 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003696 mask, NL80211_MESHCONF_MAX_RETRIES,
3697 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003698 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003699 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003701 mask, NL80211_MESHCONF_ELEMENT_TTL,
3702 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003703 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003704 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3705 nla_get_u8);
3706 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3707 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3708 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003709 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003710 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3711 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003713 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3714 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003715 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003716 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3717 nla_get_u16);
3718 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3719 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3720 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003721 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003722 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3723 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003725 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3726 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003728 dot11MeshHWMPnetDiameterTraversalTime, mask,
3729 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3730 nla_get_u16);
3731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3732 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3734 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3735 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003737 dot11MeshGateAnnouncementProtocol, mask,
3738 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3739 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003741 mask, NL80211_MESHCONF_FORWARDING,
3742 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003744 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3745 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003746 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003747 mask, NL80211_MESHCONF_HT_OPMODE,
3748 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003749 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3750 mask,
3751 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3752 nla_get_u32);
3753 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3754 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3755 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003756 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3757 dot11MeshHWMPconfirmationInterval, mask,
3758 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3759 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003760 if (mask_out)
3761 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003762
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003763 return 0;
3764
3765#undef FILL_IN_MESH_PARAM_IF_SET
3766}
3767
Javier Cardonac80d5452010-12-16 17:37:49 -08003768static int nl80211_parse_mesh_setup(struct genl_info *info,
3769 struct mesh_setup *setup)
3770{
3771 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3772
3773 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3774 return -EINVAL;
3775 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3776 info->attrs[NL80211_ATTR_MESH_SETUP],
3777 nl80211_mesh_setup_params_policy))
3778 return -EINVAL;
3779
Javier Cardonad299a1f2012-03-31 11:31:33 -07003780 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3781 setup->sync_method =
3782 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3783 IEEE80211_SYNC_METHOD_VENDOR :
3784 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3785
Javier Cardonac80d5452010-12-16 17:37:49 -08003786 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3787 setup->path_sel_proto =
3788 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3789 IEEE80211_PATH_PROTOCOL_VENDOR :
3790 IEEE80211_PATH_PROTOCOL_HWMP;
3791
3792 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3793 setup->path_metric =
3794 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3795 IEEE80211_PATH_METRIC_VENDOR :
3796 IEEE80211_PATH_METRIC_AIRTIME;
3797
Javier Cardona581a8b02011-04-07 15:08:27 -07003798
3799 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003800 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003801 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003802 if (!is_valid_ie_attr(ieattr))
3803 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003804 setup->ie = nla_data(ieattr);
3805 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003806 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003807 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3808 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003809
3810 return 0;
3811}
3812
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003813static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003814 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003815{
3816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3817 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003818 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003819 struct mesh_config cfg;
3820 u32 mask;
3821 int err;
3822
Johannes Berg29cbe682010-12-03 09:20:44 +01003823 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3824 return -EOPNOTSUPP;
3825
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003826 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003827 return -EOPNOTSUPP;
3828
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003829 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003830 if (err)
3831 return err;
3832
Johannes Berg29cbe682010-12-03 09:20:44 +01003833 wdev_lock(wdev);
3834 if (!wdev->mesh_id_len)
3835 err = -ENOLINK;
3836
3837 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003838 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003839 mask, &cfg);
3840
3841 wdev_unlock(wdev);
3842
3843 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003844}
3845
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003846static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3847{
3848 struct sk_buff *msg;
3849 void *hdr = NULL;
3850 struct nlattr *nl_reg_rules;
3851 unsigned int i;
3852 int err = -EINVAL;
3853
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003854 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003855
3856 if (!cfg80211_regdomain)
3857 goto out;
3858
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003860 if (!msg) {
3861 err = -ENOBUFS;
3862 goto out;
3863 }
3864
3865 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3866 NL80211_CMD_GET_REG);
3867 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003868 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003869
David S. Miller9360ffd2012-03-29 04:41:26 -04003870 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
3871 cfg80211_regdomain->alpha2) ||
3872 (cfg80211_regdomain->dfs_region &&
3873 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
3874 cfg80211_regdomain->dfs_region)))
3875 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003876
3877 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3878 if (!nl_reg_rules)
3879 goto nla_put_failure;
3880
3881 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3882 struct nlattr *nl_reg_rule;
3883 const struct ieee80211_reg_rule *reg_rule;
3884 const struct ieee80211_freq_range *freq_range;
3885 const struct ieee80211_power_rule *power_rule;
3886
3887 reg_rule = &cfg80211_regdomain->reg_rules[i];
3888 freq_range = &reg_rule->freq_range;
3889 power_rule = &reg_rule->power_rule;
3890
3891 nl_reg_rule = nla_nest_start(msg, i);
3892 if (!nl_reg_rule)
3893 goto nla_put_failure;
3894
David S. Miller9360ffd2012-03-29 04:41:26 -04003895 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3896 reg_rule->flags) ||
3897 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
3898 freq_range->start_freq_khz) ||
3899 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
3900 freq_range->end_freq_khz) ||
3901 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3902 freq_range->max_bandwidth_khz) ||
3903 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3904 power_rule->max_antenna_gain) ||
3905 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3906 power_rule->max_eirp))
3907 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003908
3909 nla_nest_end(msg, nl_reg_rule);
3910 }
3911
3912 nla_nest_end(msg, nl_reg_rules);
3913
3914 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00003915 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003916 goto out;
3917
3918nla_put_failure:
3919 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003920put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04003921 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003922 err = -EMSGSIZE;
3923out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05003924 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003925 return err;
3926}
3927
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003928static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3929{
3930 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3931 struct nlattr *nl_reg_rule;
3932 char *alpha2 = NULL;
3933 int rem_reg_rules = 0, r = 0;
3934 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003935 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003936 struct ieee80211_regdomain *rd = NULL;
3937
3938 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3939 return -EINVAL;
3940
3941 if (!info->attrs[NL80211_ATTR_REG_RULES])
3942 return -EINVAL;
3943
3944 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3945
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003946 if (info->attrs[NL80211_ATTR_DFS_REGION])
3947 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3948
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003949 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3950 rem_reg_rules) {
3951 num_rules++;
3952 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04003953 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003954 }
3955
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04003956 mutex_lock(&cfg80211_mutex);
3957
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003958 if (!reg_is_valid_request(alpha2)) {
3959 r = -EINVAL;
3960 goto bad_reg;
3961 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003962
3963 size_of_regd = sizeof(struct ieee80211_regdomain) +
3964 (num_rules * sizeof(struct ieee80211_reg_rule));
3965
3966 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003967 if (!rd) {
3968 r = -ENOMEM;
3969 goto bad_reg;
3970 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003971
3972 rd->n_reg_rules = num_rules;
3973 rd->alpha2[0] = alpha2[0];
3974 rd->alpha2[1] = alpha2[1];
3975
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07003976 /*
3977 * Disable DFS master mode if the DFS region was
3978 * not supported or known on this kernel.
3979 */
3980 if (reg_supported_dfs_region(dfs_region))
3981 rd->dfs_region = dfs_region;
3982
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003983 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3984 rem_reg_rules) {
3985 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3986 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3987 reg_rule_policy);
3988 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3989 if (r)
3990 goto bad_reg;
3991
3992 rule_idx++;
3993
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003994 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3995 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003996 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04003997 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003998 }
3999
4000 BUG_ON(rule_idx != num_rules);
4001
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004002 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004003
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004004 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004005
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004006 return r;
4007
Johannes Bergd2372b32008-10-24 20:32:20 +02004008 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004009 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004010 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004011 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004012}
4013
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004014static int validate_scan_freqs(struct nlattr *freqs)
4015{
4016 struct nlattr *attr1, *attr2;
4017 int n_channels = 0, tmp1, tmp2;
4018
4019 nla_for_each_nested(attr1, freqs, tmp1) {
4020 n_channels++;
4021 /*
4022 * Some hardware has a limited channel list for
4023 * scanning, and it is pretty much nonsensical
4024 * to scan for a channel twice, so disallow that
4025 * and don't require drivers to check that the
4026 * channel list they get isn't longer than what
4027 * they can scan, as long as they can scan all
4028 * the channels they registered at once.
4029 */
4030 nla_for_each_nested(attr2, freqs, tmp2)
4031 if (attr1 != attr2 &&
4032 nla_get_u32(attr1) == nla_get_u32(attr2))
4033 return 0;
4034 }
4035
4036 return n_channels;
4037}
4038
Johannes Berg2a519312009-02-10 21:25:55 +01004039static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4040{
Johannes Berg4c476992010-10-04 21:36:35 +02004041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4042 struct net_device *dev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004043 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004044 struct nlattr *attr;
4045 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004046 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004047 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004048
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004049 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4050 return -EINVAL;
4051
Johannes Berg79c97e92009-07-07 03:56:12 +02004052 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004053
Johannes Berg4c476992010-10-04 21:36:35 +02004054 if (!rdev->ops->scan)
4055 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004056
Johannes Berg4c476992010-10-04 21:36:35 +02004057 if (rdev->scan_req)
4058 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004059
4060 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004061 n_channels = validate_scan_freqs(
4062 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004063 if (!n_channels)
4064 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004065 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004066 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004067 n_channels = 0;
4068
Johannes Berg2a519312009-02-10 21:25:55 +01004069 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4070 if (wiphy->bands[band])
4071 n_channels += wiphy->bands[band]->n_channels;
4072 }
4073
4074 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4075 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4076 n_ssids++;
4077
Johannes Berg4c476992010-10-04 21:36:35 +02004078 if (n_ssids > wiphy->max_scan_ssids)
4079 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004080
Jouni Malinen70692ad2009-02-16 19:39:13 +02004081 if (info->attrs[NL80211_ATTR_IE])
4082 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4083 else
4084 ie_len = 0;
4085
Johannes Berg4c476992010-10-04 21:36:35 +02004086 if (ie_len > wiphy->max_scan_ie_len)
4087 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004088
Johannes Berg2a519312009-02-10 21:25:55 +01004089 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004090 + sizeof(*request->ssids) * n_ssids
4091 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004092 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004093 if (!request)
4094 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004095
Johannes Berg2a519312009-02-10 21:25:55 +01004096 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004097 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004098 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004099 if (ie_len) {
4100 if (request->ssids)
4101 request->ie = (void *)(request->ssids + n_ssids);
4102 else
4103 request->ie = (void *)(request->channels + n_channels);
4104 }
Johannes Berg2a519312009-02-10 21:25:55 +01004105
Johannes Berg584991d2009-11-02 13:32:03 +01004106 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004107 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4108 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004109 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004110 struct ieee80211_channel *chan;
4111
4112 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4113
4114 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004115 err = -EINVAL;
4116 goto out_free;
4117 }
Johannes Berg584991d2009-11-02 13:32:03 +01004118
4119 /* ignore disabled channels */
4120 if (chan->flags & IEEE80211_CHAN_DISABLED)
4121 continue;
4122
4123 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004124 i++;
4125 }
4126 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004127 enum ieee80211_band band;
4128
Johannes Berg2a519312009-02-10 21:25:55 +01004129 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004130 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4131 int j;
4132 if (!wiphy->bands[band])
4133 continue;
4134 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004135 struct ieee80211_channel *chan;
4136
4137 chan = &wiphy->bands[band]->channels[j];
4138
4139 if (chan->flags & IEEE80211_CHAN_DISABLED)
4140 continue;
4141
4142 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004143 i++;
4144 }
4145 }
4146 }
4147
Johannes Berg584991d2009-11-02 13:32:03 +01004148 if (!i) {
4149 err = -EINVAL;
4150 goto out_free;
4151 }
4152
4153 request->n_channels = i;
4154
Johannes Berg2a519312009-02-10 21:25:55 +01004155 i = 0;
4156 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4157 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004158 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004159 err = -EINVAL;
4160 goto out_free;
4161 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004162 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004163 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004164 i++;
4165 }
4166 }
4167
Jouni Malinen70692ad2009-02-16 19:39:13 +02004168 if (info->attrs[NL80211_ATTR_IE]) {
4169 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004170 memcpy((void *)request->ie,
4171 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004172 request->ie_len);
4173 }
4174
Johannes Berg34850ab2011-07-18 18:08:35 +02004175 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004176 if (wiphy->bands[i])
4177 request->rates[i] =
4178 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004179
4180 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4181 nla_for_each_nested(attr,
4182 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4183 tmp) {
4184 enum ieee80211_band band = nla_type(attr);
4185
Dan Carpenter84404622011-07-29 11:52:18 +03004186 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004187 err = -EINVAL;
4188 goto out_free;
4189 }
4190 err = ieee80211_get_ratemask(wiphy->bands[band],
4191 nla_data(attr),
4192 nla_len(attr),
4193 &request->rates[band]);
4194 if (err)
4195 goto out_free;
4196 }
4197 }
4198
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304199 request->no_cck =
4200 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4201
Johannes Berg463d0182009-07-14 00:33:35 +02004202 request->dev = dev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004203 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004204
Johannes Berg79c97e92009-07-07 03:56:12 +02004205 rdev->scan_req = request;
4206 err = rdev->ops->scan(&rdev->wiphy, dev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004207
Johannes Berg463d0182009-07-14 00:33:35 +02004208 if (!err) {
Johannes Berg79c97e92009-07-07 03:56:12 +02004209 nl80211_send_scan_start(rdev, dev);
Johannes Berg463d0182009-07-14 00:33:35 +02004210 dev_hold(dev);
Johannes Berg4c476992010-10-04 21:36:35 +02004211 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004212 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004213 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004214 kfree(request);
4215 }
Johannes Berg3b858752009-03-12 09:55:09 +01004216
Johannes Berg2a519312009-02-10 21:25:55 +01004217 return err;
4218}
4219
Luciano Coelho807f8a82011-05-11 17:09:35 +03004220static int nl80211_start_sched_scan(struct sk_buff *skb,
4221 struct genl_info *info)
4222{
4223 struct cfg80211_sched_scan_request *request;
4224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4225 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004226 struct nlattr *attr;
4227 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004228 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004229 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004230 enum ieee80211_band band;
4231 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004232 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004233
4234 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4235 !rdev->ops->sched_scan_start)
4236 return -EOPNOTSUPP;
4237
4238 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4239 return -EINVAL;
4240
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004241 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4242 return -EINVAL;
4243
4244 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4245 if (interval == 0)
4246 return -EINVAL;
4247
Luciano Coelho807f8a82011-05-11 17:09:35 +03004248 wiphy = &rdev->wiphy;
4249
4250 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4251 n_channels = validate_scan_freqs(
4252 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4253 if (!n_channels)
4254 return -EINVAL;
4255 } else {
4256 n_channels = 0;
4257
4258 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4259 if (wiphy->bands[band])
4260 n_channels += wiphy->bands[band]->n_channels;
4261 }
4262
4263 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4264 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4265 tmp)
4266 n_ssids++;
4267
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004268 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004269 return -EINVAL;
4270
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004271 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4272 nla_for_each_nested(attr,
4273 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4274 tmp)
4275 n_match_sets++;
4276
4277 if (n_match_sets > wiphy->max_match_sets)
4278 return -EINVAL;
4279
Luciano Coelho807f8a82011-05-11 17:09:35 +03004280 if (info->attrs[NL80211_ATTR_IE])
4281 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4282 else
4283 ie_len = 0;
4284
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004285 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004286 return -EINVAL;
4287
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004288 mutex_lock(&rdev->sched_scan_mtx);
4289
4290 if (rdev->sched_scan_req) {
4291 err = -EINPROGRESS;
4292 goto out;
4293 }
4294
Luciano Coelho807f8a82011-05-11 17:09:35 +03004295 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004296 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004297 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004298 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004299 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004300 if (!request) {
4301 err = -ENOMEM;
4302 goto out;
4303 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004304
4305 if (n_ssids)
4306 request->ssids = (void *)&request->channels[n_channels];
4307 request->n_ssids = n_ssids;
4308 if (ie_len) {
4309 if (request->ssids)
4310 request->ie = (void *)(request->ssids + n_ssids);
4311 else
4312 request->ie = (void *)(request->channels + n_channels);
4313 }
4314
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004315 if (n_match_sets) {
4316 if (request->ie)
4317 request->match_sets = (void *)(request->ie + ie_len);
4318 else if (request->ssids)
4319 request->match_sets =
4320 (void *)(request->ssids + n_ssids);
4321 else
4322 request->match_sets =
4323 (void *)(request->channels + n_channels);
4324 }
4325 request->n_match_sets = n_match_sets;
4326
Luciano Coelho807f8a82011-05-11 17:09:35 +03004327 i = 0;
4328 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4329 /* user specified, bail out if channel not found */
4330 nla_for_each_nested(attr,
4331 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4332 tmp) {
4333 struct ieee80211_channel *chan;
4334
4335 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4336
4337 if (!chan) {
4338 err = -EINVAL;
4339 goto out_free;
4340 }
4341
4342 /* ignore disabled channels */
4343 if (chan->flags & IEEE80211_CHAN_DISABLED)
4344 continue;
4345
4346 request->channels[i] = chan;
4347 i++;
4348 }
4349 } else {
4350 /* all channels */
4351 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4352 int j;
4353 if (!wiphy->bands[band])
4354 continue;
4355 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4356 struct ieee80211_channel *chan;
4357
4358 chan = &wiphy->bands[band]->channels[j];
4359
4360 if (chan->flags & IEEE80211_CHAN_DISABLED)
4361 continue;
4362
4363 request->channels[i] = chan;
4364 i++;
4365 }
4366 }
4367 }
4368
4369 if (!i) {
4370 err = -EINVAL;
4371 goto out_free;
4372 }
4373
4374 request->n_channels = i;
4375
4376 i = 0;
4377 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4378 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4379 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004380 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004381 err = -EINVAL;
4382 goto out_free;
4383 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004384 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004385 memcpy(request->ssids[i].ssid, nla_data(attr),
4386 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004387 i++;
4388 }
4389 }
4390
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004391 i = 0;
4392 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4393 nla_for_each_nested(attr,
4394 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4395 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004396 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004397
4398 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4399 nla_data(attr), nla_len(attr),
4400 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004401 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004402 if (ssid) {
4403 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4404 err = -EINVAL;
4405 goto out_free;
4406 }
4407 memcpy(request->match_sets[i].ssid.ssid,
4408 nla_data(ssid), nla_len(ssid));
4409 request->match_sets[i].ssid.ssid_len =
4410 nla_len(ssid);
4411 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004412 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4413 if (rssi)
4414 request->rssi_thold = nla_get_u32(rssi);
4415 else
4416 request->rssi_thold =
4417 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004418 i++;
4419 }
4420 }
4421
Luciano Coelho807f8a82011-05-11 17:09:35 +03004422 if (info->attrs[NL80211_ATTR_IE]) {
4423 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4424 memcpy((void *)request->ie,
4425 nla_data(info->attrs[NL80211_ATTR_IE]),
4426 request->ie_len);
4427 }
4428
4429 request->dev = dev;
4430 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004431 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004432
4433 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4434 if (!err) {
4435 rdev->sched_scan_req = request;
4436 nl80211_send_sched_scan(rdev, dev,
4437 NL80211_CMD_START_SCHED_SCAN);
4438 goto out;
4439 }
4440
4441out_free:
4442 kfree(request);
4443out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004444 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004445 return err;
4446}
4447
4448static int nl80211_stop_sched_scan(struct sk_buff *skb,
4449 struct genl_info *info)
4450{
4451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004452 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004453
4454 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4455 !rdev->ops->sched_scan_stop)
4456 return -EOPNOTSUPP;
4457
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004458 mutex_lock(&rdev->sched_scan_mtx);
4459 err = __cfg80211_stop_sched_scan(rdev, false);
4460 mutex_unlock(&rdev->sched_scan_mtx);
4461
4462 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004463}
4464
Johannes Berg9720bb32011-06-21 09:45:33 +02004465static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4466 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004467 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004468 struct wireless_dev *wdev,
4469 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004470{
Johannes Berg48ab9052009-07-10 18:42:31 +02004471 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004472 void *hdr;
4473 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004474
4475 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004476
Johannes Berg9720bb32011-06-21 09:45:33 +02004477 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004478 NL80211_CMD_NEW_SCAN_RESULTS);
4479 if (!hdr)
4480 return -1;
4481
Johannes Berg9720bb32011-06-21 09:45:33 +02004482 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4483
David S. Miller9360ffd2012-03-29 04:41:26 -04004484 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4486 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004487
4488 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4489 if (!bss)
4490 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004491 if ((!is_zero_ether_addr(res->bssid) &&
4492 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4493 (res->information_elements && res->len_information_elements &&
4494 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4495 res->len_information_elements,
4496 res->information_elements)) ||
4497 (res->beacon_ies && res->len_beacon_ies &&
4498 res->beacon_ies != res->information_elements &&
4499 nla_put(msg, NL80211_BSS_BEACON_IES,
4500 res->len_beacon_ies, res->beacon_ies)))
4501 goto nla_put_failure;
4502 if (res->tsf &&
4503 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4504 goto nla_put_failure;
4505 if (res->beacon_interval &&
4506 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4507 goto nla_put_failure;
4508 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4509 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4510 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4511 jiffies_to_msecs(jiffies - intbss->ts)))
4512 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004513
Johannes Berg77965c92009-02-18 18:45:06 +01004514 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004515 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004516 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4517 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004518 break;
4519 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004520 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4521 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004522 break;
4523 default:
4524 break;
4525 }
4526
Johannes Berg48ab9052009-07-10 18:42:31 +02004527 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004528 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004529 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004530 if (intbss == wdev->current_bss &&
4531 nla_put_u32(msg, NL80211_BSS_STATUS,
4532 NL80211_BSS_STATUS_ASSOCIATED))
4533 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004534 break;
4535 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004536 if (intbss == wdev->current_bss &&
4537 nla_put_u32(msg, NL80211_BSS_STATUS,
4538 NL80211_BSS_STATUS_IBSS_JOINED))
4539 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004540 break;
4541 default:
4542 break;
4543 }
4544
Johannes Berg2a519312009-02-10 21:25:55 +01004545 nla_nest_end(msg, bss);
4546
4547 return genlmsg_end(msg, hdr);
4548
4549 nla_put_failure:
4550 genlmsg_cancel(msg, hdr);
4551 return -EMSGSIZE;
4552}
4553
4554static int nl80211_dump_scan(struct sk_buff *skb,
4555 struct netlink_callback *cb)
4556{
Johannes Berg48ab9052009-07-10 18:42:31 +02004557 struct cfg80211_registered_device *rdev;
4558 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004559 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004560 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004561 int start = cb->args[1], idx = 0;
4562 int err;
4563
Johannes Berg67748892010-10-04 21:14:06 +02004564 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4565 if (err)
4566 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004567
Johannes Berg48ab9052009-07-10 18:42:31 +02004568 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004569
Johannes Berg48ab9052009-07-10 18:42:31 +02004570 wdev_lock(wdev);
4571 spin_lock_bh(&rdev->bss_lock);
4572 cfg80211_bss_expire(rdev);
4573
Johannes Berg9720bb32011-06-21 09:45:33 +02004574 cb->seq = rdev->bss_generation;
4575
Johannes Berg48ab9052009-07-10 18:42:31 +02004576 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004577 if (++idx <= start)
4578 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004579 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004580 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004581 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004582 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004583 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004584 }
4585 }
4586
Johannes Berg48ab9052009-07-10 18:42:31 +02004587 spin_unlock_bh(&rdev->bss_lock);
4588 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004589
4590 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004591 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004592
Johannes Berg67748892010-10-04 21:14:06 +02004593 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004594}
4595
Holger Schurig61fa7132009-11-11 12:25:40 +01004596static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4597 int flags, struct net_device *dev,
4598 struct survey_info *survey)
4599{
4600 void *hdr;
4601 struct nlattr *infoattr;
4602
Holger Schurig61fa7132009-11-11 12:25:40 +01004603 hdr = nl80211hdr_put(msg, pid, seq, flags,
4604 NL80211_CMD_NEW_SURVEY_RESULTS);
4605 if (!hdr)
4606 return -ENOMEM;
4607
David S. Miller9360ffd2012-03-29 04:41:26 -04004608 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4609 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004610
4611 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4612 if (!infoattr)
4613 goto nla_put_failure;
4614
David S. Miller9360ffd2012-03-29 04:41:26 -04004615 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4616 survey->channel->center_freq))
4617 goto nla_put_failure;
4618
4619 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4620 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4621 goto nla_put_failure;
4622 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4623 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4624 goto nla_put_failure;
4625 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4626 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4627 survey->channel_time))
4628 goto nla_put_failure;
4629 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4630 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4631 survey->channel_time_busy))
4632 goto nla_put_failure;
4633 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4634 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4635 survey->channel_time_ext_busy))
4636 goto nla_put_failure;
4637 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4638 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4639 survey->channel_time_rx))
4640 goto nla_put_failure;
4641 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4642 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4643 survey->channel_time_tx))
4644 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004645
4646 nla_nest_end(msg, infoattr);
4647
4648 return genlmsg_end(msg, hdr);
4649
4650 nla_put_failure:
4651 genlmsg_cancel(msg, hdr);
4652 return -EMSGSIZE;
4653}
4654
4655static int nl80211_dump_survey(struct sk_buff *skb,
4656 struct netlink_callback *cb)
4657{
4658 struct survey_info survey;
4659 struct cfg80211_registered_device *dev;
4660 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004661 int survey_idx = cb->args[1];
4662 int res;
4663
Johannes Berg67748892010-10-04 21:14:06 +02004664 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4665 if (res)
4666 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004667
4668 if (!dev->ops->dump_survey) {
4669 res = -EOPNOTSUPP;
4670 goto out_err;
4671 }
4672
4673 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004674 struct ieee80211_channel *chan;
4675
Holger Schurig61fa7132009-11-11 12:25:40 +01004676 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4677 &survey);
4678 if (res == -ENOENT)
4679 break;
4680 if (res)
4681 goto out_err;
4682
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004683 /* Survey without a channel doesn't make sense */
4684 if (!survey.channel) {
4685 res = -EINVAL;
4686 goto out;
4687 }
4688
4689 chan = ieee80211_get_channel(&dev->wiphy,
4690 survey.channel->center_freq);
4691 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4692 survey_idx++;
4693 continue;
4694 }
4695
Holger Schurig61fa7132009-11-11 12:25:40 +01004696 if (nl80211_send_survey(skb,
4697 NETLINK_CB(cb->skb).pid,
4698 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4699 netdev,
4700 &survey) < 0)
4701 goto out;
4702 survey_idx++;
4703 }
4704
4705 out:
4706 cb->args[1] = survey_idx;
4707 res = skb->len;
4708 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004709 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004710 return res;
4711}
4712
Jouni Malinen255e7372009-03-20 21:21:17 +02004713static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4714{
Samuel Ortizb23aa672009-07-01 21:26:54 +02004715 return auth_type <= NL80211_AUTHTYPE_MAX;
Jouni Malinen255e7372009-03-20 21:21:17 +02004716}
4717
Samuel Ortizb23aa672009-07-01 21:26:54 +02004718static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4719{
4720 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4721 NL80211_WPA_VERSION_2));
4722}
4723
Jouni Malinen636a5d32009-03-19 13:39:22 +02004724static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4725{
Johannes Berg4c476992010-10-04 21:36:35 +02004726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4727 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004728 struct ieee80211_channel *chan;
4729 const u8 *bssid, *ssid, *ie = NULL;
4730 int err, ssid_len, ie_len = 0;
4731 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004732 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004733 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004734
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004735 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4736 return -EINVAL;
4737
4738 if (!info->attrs[NL80211_ATTR_MAC])
4739 return -EINVAL;
4740
Jouni Malinen17780922009-03-27 20:52:47 +02004741 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4742 return -EINVAL;
4743
Johannes Berg19957bb2009-07-02 17:20:43 +02004744 if (!info->attrs[NL80211_ATTR_SSID])
4745 return -EINVAL;
4746
4747 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4748 return -EINVAL;
4749
Johannes Bergfffd0932009-07-08 14:22:54 +02004750 err = nl80211_parse_key(info, &key);
4751 if (err)
4752 return err;
4753
4754 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004755 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4756 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004757 if (!key.p.key || !key.p.key_len)
4758 return -EINVAL;
4759 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4760 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4761 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4762 key.p.key_len != WLAN_KEY_LEN_WEP104))
4763 return -EINVAL;
4764 if (key.idx > 4)
4765 return -EINVAL;
4766 } else {
4767 key.p.key_len = 0;
4768 key.p.key = NULL;
4769 }
4770
Johannes Bergafea0b72010-08-10 09:46:42 +02004771 if (key.idx >= 0) {
4772 int i;
4773 bool ok = false;
4774 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4775 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4776 ok = true;
4777 break;
4778 }
4779 }
Johannes Berg4c476992010-10-04 21:36:35 +02004780 if (!ok)
4781 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004782 }
4783
Johannes Berg4c476992010-10-04 21:36:35 +02004784 if (!rdev->ops->auth)
4785 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004786
Johannes Berg074ac8d2010-09-16 14:58:22 +02004787 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004788 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4789 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004790
Johannes Berg19957bb2009-07-02 17:20:43 +02004791 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004792 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004793 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004794 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4795 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004796
Johannes Berg19957bb2009-07-02 17:20:43 +02004797 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4798 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4799
4800 if (info->attrs[NL80211_ATTR_IE]) {
4801 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4802 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4803 }
4804
4805 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Johannes Berg4c476992010-10-04 21:36:35 +02004806 if (!nl80211_valid_auth_type(auth_type))
4807 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004808
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004809 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4810
Johannes Berg95de8172012-01-20 13:55:25 +01004811 /*
4812 * Since we no longer track auth state, ignore
4813 * requests to only change local state.
4814 */
4815 if (local_state_change)
4816 return 0;
4817
Johannes Berg4c476992010-10-04 21:36:35 +02004818 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4819 ssid, ssid_len, ie, ie_len,
Johannes Berg95de8172012-01-20 13:55:25 +01004820 key.p.key, key.p.key_len, key.idx);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004821}
4822
Johannes Bergc0692b82010-08-27 14:26:53 +03004823static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4824 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02004825 struct cfg80211_crypto_settings *settings,
4826 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004827{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02004828 memset(settings, 0, sizeof(*settings));
4829
Samuel Ortizb23aa672009-07-01 21:26:54 +02004830 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4831
Johannes Bergc0692b82010-08-27 14:26:53 +03004832 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4833 u16 proto;
4834 proto = nla_get_u16(
4835 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4836 settings->control_port_ethertype = cpu_to_be16(proto);
4837 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4838 proto != ETH_P_PAE)
4839 return -EINVAL;
4840 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4841 settings->control_port_no_encrypt = true;
4842 } else
4843 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4844
Samuel Ortizb23aa672009-07-01 21:26:54 +02004845 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4846 void *data;
4847 int len, i;
4848
4849 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4850 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4851 settings->n_ciphers_pairwise = len / sizeof(u32);
4852
4853 if (len % sizeof(u32))
4854 return -EINVAL;
4855
Johannes Berg3dc27d22009-07-02 21:36:37 +02004856 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02004857 return -EINVAL;
4858
4859 memcpy(settings->ciphers_pairwise, data, len);
4860
4861 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004862 if (!cfg80211_supported_cipher_suite(
4863 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02004864 settings->ciphers_pairwise[i]))
4865 return -EINVAL;
4866 }
4867
4868 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4869 settings->cipher_group =
4870 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03004871 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4872 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02004873 return -EINVAL;
4874 }
4875
4876 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4877 settings->wpa_versions =
4878 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4879 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4880 return -EINVAL;
4881 }
4882
4883 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4884 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03004885 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02004886
4887 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4888 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4889 settings->n_akm_suites = len / sizeof(u32);
4890
4891 if (len % sizeof(u32))
4892 return -EINVAL;
4893
Jouni Malinen1b9ca022011-09-21 16:13:07 +03004894 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4895 return -EINVAL;
4896
Samuel Ortizb23aa672009-07-01 21:26:54 +02004897 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004898 }
4899
4900 return 0;
4901}
4902
Jouni Malinen636a5d32009-03-19 13:39:22 +02004903static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4904{
Johannes Berg4c476992010-10-04 21:36:35 +02004905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4906 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004907 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02004908 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02004909 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004910 int err, ssid_len, ie_len = 0;
4911 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08004912 u32 flags = 0;
4913 struct ieee80211_ht_cap *ht_capa = NULL;
4914 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004915
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004916 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4917 return -EINVAL;
4918
4919 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02004920 !info->attrs[NL80211_ATTR_SSID] ||
4921 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004922 return -EINVAL;
4923
Johannes Berg4c476992010-10-04 21:36:35 +02004924 if (!rdev->ops->assoc)
4925 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004926
Johannes Berg074ac8d2010-09-16 14:58:22 +02004927 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004928 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4929 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004930
Johannes Berg19957bb2009-07-02 17:20:43 +02004931 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004932
Johannes Berg19957bb2009-07-02 17:20:43 +02004933 chan = ieee80211_get_channel(&rdev->wiphy,
4934 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004935 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4936 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004937
Johannes Berg19957bb2009-07-02 17:20:43 +02004938 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4939 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004940
4941 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02004942 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4943 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004944 }
4945
Jouni Malinendc6382c2009-05-06 22:09:37 +03004946 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004947 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03004948 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02004949 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02004950 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02004951 else if (mfp != NL80211_MFP_NO)
4952 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03004953 }
4954
Johannes Berg3e5d7642009-07-07 14:37:26 +02004955 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4956 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4957
Ben Greear7e7c8922011-11-18 11:31:59 -08004958 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4959 flags |= ASSOC_REQ_DISABLE_HT;
4960
4961 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4962 ht_capa_mask =
4963 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4964
4965 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4966 if (!ht_capa_mask)
4967 return -EINVAL;
4968 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4969 }
4970
Johannes Bergc0692b82010-08-27 14:26:53 +03004971 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02004972 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02004973 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4974 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08004975 &crypto, flags, ht_capa,
4976 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004977
Jouni Malinen636a5d32009-03-19 13:39:22 +02004978 return err;
4979}
4980
4981static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4982{
Johannes Berg4c476992010-10-04 21:36:35 +02004983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4984 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004985 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02004986 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004987 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004988 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004989
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004990 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4991 return -EINVAL;
4992
4993 if (!info->attrs[NL80211_ATTR_MAC])
4994 return -EINVAL;
4995
4996 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4997 return -EINVAL;
4998
Johannes Berg4c476992010-10-04 21:36:35 +02004999 if (!rdev->ops->deauth)
5000 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005001
Johannes Berg074ac8d2010-09-16 14:58:22 +02005002 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005003 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5004 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005005
Johannes Berg19957bb2009-07-02 17:20:43 +02005006 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005007
Johannes Berg19957bb2009-07-02 17:20:43 +02005008 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5009 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005010 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005011 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005012 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005013
5014 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005015 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5016 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005017 }
5018
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005019 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5020
Johannes Berg4c476992010-10-04 21:36:35 +02005021 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5022 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005023}
5024
5025static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5026{
Johannes Berg4c476992010-10-04 21:36:35 +02005027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5028 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005029 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005030 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005031 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005032 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005033
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005034 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5035 return -EINVAL;
5036
5037 if (!info->attrs[NL80211_ATTR_MAC])
5038 return -EINVAL;
5039
5040 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5041 return -EINVAL;
5042
Johannes Berg4c476992010-10-04 21:36:35 +02005043 if (!rdev->ops->disassoc)
5044 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005045
Johannes Berg074ac8d2010-09-16 14:58:22 +02005046 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005047 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5048 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005049
Johannes Berg19957bb2009-07-02 17:20:43 +02005050 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005051
Johannes Berg19957bb2009-07-02 17:20:43 +02005052 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5053 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005054 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005055 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005056 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005057
5058 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005059 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5060 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005061 }
5062
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005063 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5064
Johannes Berg4c476992010-10-04 21:36:35 +02005065 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5066 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005067}
5068
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005069static bool
5070nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5071 int mcast_rate[IEEE80211_NUM_BANDS],
5072 int rateval)
5073{
5074 struct wiphy *wiphy = &rdev->wiphy;
5075 bool found = false;
5076 int band, i;
5077
5078 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5079 struct ieee80211_supported_band *sband;
5080
5081 sband = wiphy->bands[band];
5082 if (!sband)
5083 continue;
5084
5085 for (i = 0; i < sband->n_bitrates; i++) {
5086 if (sband->bitrates[i].bitrate == rateval) {
5087 mcast_rate[band] = i + 1;
5088 found = true;
5089 break;
5090 }
5091 }
5092 }
5093
5094 return found;
5095}
5096
Johannes Berg04a773a2009-04-19 21:24:32 +02005097static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5098{
Johannes Berg4c476992010-10-04 21:36:35 +02005099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5100 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005101 struct cfg80211_ibss_params ibss;
5102 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005103 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005104 int err;
5105
Johannes Berg8e30bc52009-04-22 17:45:38 +02005106 memset(&ibss, 0, sizeof(ibss));
5107
Johannes Berg04a773a2009-04-19 21:24:32 +02005108 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5109 return -EINVAL;
5110
5111 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5112 !info->attrs[NL80211_ATTR_SSID] ||
5113 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5114 return -EINVAL;
5115
Johannes Berg8e30bc52009-04-22 17:45:38 +02005116 ibss.beacon_interval = 100;
5117
5118 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5119 ibss.beacon_interval =
5120 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5121 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5122 return -EINVAL;
5123 }
5124
Johannes Berg4c476992010-10-04 21:36:35 +02005125 if (!rdev->ops->join_ibss)
5126 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005127
Johannes Berg4c476992010-10-04 21:36:35 +02005128 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5129 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005130
Johannes Berg79c97e92009-07-07 03:56:12 +02005131 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005132
Johannes Berg39193492011-09-16 13:45:25 +02005133 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005134 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005135
5136 if (!is_valid_ether_addr(ibss.bssid))
5137 return -EINVAL;
5138 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005139 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5140 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5141
5142 if (info->attrs[NL80211_ATTR_IE]) {
5143 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5144 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5145 }
5146
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005147 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5148 enum nl80211_channel_type channel_type;
5149
Johannes Bergcd6c6592012-05-10 21:27:18 +02005150 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005151 return -EINVAL;
5152
5153 if (channel_type != NL80211_CHAN_NO_HT &&
5154 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5155 return -EINVAL;
5156
5157 ibss.channel_type = channel_type;
5158 } else {
5159 ibss.channel_type = NL80211_CHAN_NO_HT;
5160 }
5161
5162 ibss.channel = rdev_freq_to_chan(rdev,
5163 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5164 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005165 if (!ibss.channel ||
5166 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005167 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5168 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005169
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005170 /* Both channels should be able to initiate communication */
5171 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5172 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5173 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5174 ibss.channel_type))
5175 return -EINVAL;
5176
Johannes Berg04a773a2009-04-19 21:24:32 +02005177 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005178 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005179
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005180 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5181 u8 *rates =
5182 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5183 int n_rates =
5184 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5185 struct ieee80211_supported_band *sband =
5186 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005187
Johannes Berg34850ab2011-07-18 18:08:35 +02005188 err = ieee80211_get_ratemask(sband, rates, n_rates,
5189 &ibss.basic_rates);
5190 if (err)
5191 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005192 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005193
5194 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5195 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5196 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5197 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005198
Johannes Berg4c476992010-10-04 21:36:35 +02005199 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5200 connkeys = nl80211_parse_connkeys(rdev,
5201 info->attrs[NL80211_ATTR_KEYS]);
5202 if (IS_ERR(connkeys))
5203 return PTR_ERR(connkeys);
5204 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005205
Antonio Quartulli267335d2012-01-31 20:25:47 +01005206 ibss.control_port =
5207 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5208
Johannes Berg4c476992010-10-04 21:36:35 +02005209 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005210 if (err)
5211 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005212 return err;
5213}
5214
5215static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5216{
Johannes Berg4c476992010-10-04 21:36:35 +02005217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5218 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005219
Johannes Berg4c476992010-10-04 21:36:35 +02005220 if (!rdev->ops->leave_ibss)
5221 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005222
Johannes Berg4c476992010-10-04 21:36:35 +02005223 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5224 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005225
Johannes Berg4c476992010-10-04 21:36:35 +02005226 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005227}
5228
Johannes Bergaff89a92009-07-01 21:26:51 +02005229#ifdef CONFIG_NL80211_TESTMODE
5230static struct genl_multicast_group nl80211_testmode_mcgrp = {
5231 .name = "testmode",
5232};
5233
5234static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5235{
Johannes Berg4c476992010-10-04 21:36:35 +02005236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005237 int err;
5238
5239 if (!info->attrs[NL80211_ATTR_TESTDATA])
5240 return -EINVAL;
5241
Johannes Bergaff89a92009-07-01 21:26:51 +02005242 err = -EOPNOTSUPP;
5243 if (rdev->ops->testmode_cmd) {
5244 rdev->testmode_info = info;
5245 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5246 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5247 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5248 rdev->testmode_info = NULL;
5249 }
5250
Johannes Bergaff89a92009-07-01 21:26:51 +02005251 return err;
5252}
5253
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005254static int nl80211_testmode_dump(struct sk_buff *skb,
5255 struct netlink_callback *cb)
5256{
Johannes Berg00918d32011-12-13 17:22:05 +01005257 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005258 int err;
5259 long phy_idx;
5260 void *data = NULL;
5261 int data_len = 0;
5262
5263 if (cb->args[0]) {
5264 /*
5265 * 0 is a valid index, but not valid for args[0],
5266 * so we need to offset by 1.
5267 */
5268 phy_idx = cb->args[0] - 1;
5269 } else {
5270 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5271 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5272 nl80211_policy);
5273 if (err)
5274 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005275
Johannes Berg2bd7e352012-06-15 14:23:16 +02005276 mutex_lock(&cfg80211_mutex);
5277 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5278 nl80211_fam.attrbuf);
5279 if (IS_ERR(rdev)) {
5280 mutex_unlock(&cfg80211_mutex);
5281 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005282 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005283 phy_idx = rdev->wiphy_idx;
5284 rdev = NULL;
5285 mutex_unlock(&cfg80211_mutex);
5286
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005287 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5288 cb->args[1] =
5289 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5290 }
5291
5292 if (cb->args[1]) {
5293 data = nla_data((void *)cb->args[1]);
5294 data_len = nla_len((void *)cb->args[1]);
5295 }
5296
5297 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005298 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5299 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005300 mutex_unlock(&cfg80211_mutex);
5301 return -ENOENT;
5302 }
Johannes Berg00918d32011-12-13 17:22:05 +01005303 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005304 mutex_unlock(&cfg80211_mutex);
5305
Johannes Berg00918d32011-12-13 17:22:05 +01005306 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005307 err = -EOPNOTSUPP;
5308 goto out_err;
5309 }
5310
5311 while (1) {
5312 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
5313 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5314 NL80211_CMD_TESTMODE);
5315 struct nlattr *tmdata;
5316
David S. Miller9360ffd2012-03-29 04:41:26 -04005317 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005318 genlmsg_cancel(skb, hdr);
5319 break;
5320 }
5321
5322 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5323 if (!tmdata) {
5324 genlmsg_cancel(skb, hdr);
5325 break;
5326 }
Johannes Berg00918d32011-12-13 17:22:05 +01005327 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5328 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005329 nla_nest_end(skb, tmdata);
5330
5331 if (err == -ENOBUFS || err == -ENOENT) {
5332 genlmsg_cancel(skb, hdr);
5333 break;
5334 } else if (err) {
5335 genlmsg_cancel(skb, hdr);
5336 goto out_err;
5337 }
5338
5339 genlmsg_end(skb, hdr);
5340 }
5341
5342 err = skb->len;
5343 /* see above */
5344 cb->args[0] = phy_idx + 1;
5345 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005346 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005347 return err;
5348}
5349
Johannes Bergaff89a92009-07-01 21:26:51 +02005350static struct sk_buff *
5351__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
5352 int approxlen, u32 pid, u32 seq, gfp_t gfp)
5353{
5354 struct sk_buff *skb;
5355 void *hdr;
5356 struct nlattr *data;
5357
5358 skb = nlmsg_new(approxlen + 100, gfp);
5359 if (!skb)
5360 return NULL;
5361
5362 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
5363 if (!hdr) {
5364 kfree_skb(skb);
5365 return NULL;
5366 }
5367
David S. Miller9360ffd2012-03-29 04:41:26 -04005368 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5369 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005370 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5371
5372 ((void **)skb->cb)[0] = rdev;
5373 ((void **)skb->cb)[1] = hdr;
5374 ((void **)skb->cb)[2] = data;
5375
5376 return skb;
5377
5378 nla_put_failure:
5379 kfree_skb(skb);
5380 return NULL;
5381}
5382
5383struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5384 int approxlen)
5385{
5386 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5387
5388 if (WARN_ON(!rdev->testmode_info))
5389 return NULL;
5390
5391 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5392 rdev->testmode_info->snd_pid,
5393 rdev->testmode_info->snd_seq,
5394 GFP_KERNEL);
5395}
5396EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5397
5398int cfg80211_testmode_reply(struct sk_buff *skb)
5399{
5400 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5401 void *hdr = ((void **)skb->cb)[1];
5402 struct nlattr *data = ((void **)skb->cb)[2];
5403
5404 if (WARN_ON(!rdev->testmode_info)) {
5405 kfree_skb(skb);
5406 return -EINVAL;
5407 }
5408
5409 nla_nest_end(skb, data);
5410 genlmsg_end(skb, hdr);
5411 return genlmsg_reply(skb, rdev->testmode_info);
5412}
5413EXPORT_SYMBOL(cfg80211_testmode_reply);
5414
5415struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5416 int approxlen, gfp_t gfp)
5417{
5418 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5419
5420 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5421}
5422EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5423
5424void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5425{
5426 void *hdr = ((void **)skb->cb)[1];
5427 struct nlattr *data = ((void **)skb->cb)[2];
5428
5429 nla_nest_end(skb, data);
5430 genlmsg_end(skb, hdr);
5431 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5432}
5433EXPORT_SYMBOL(cfg80211_testmode_event);
5434#endif
5435
Samuel Ortizb23aa672009-07-01 21:26:54 +02005436static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5437{
Johannes Berg4c476992010-10-04 21:36:35 +02005438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5439 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005440 struct cfg80211_connect_params connect;
5441 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005442 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005443 int err;
5444
5445 memset(&connect, 0, sizeof(connect));
5446
5447 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5448 return -EINVAL;
5449
5450 if (!info->attrs[NL80211_ATTR_SSID] ||
5451 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5452 return -EINVAL;
5453
5454 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5455 connect.auth_type =
5456 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5457 if (!nl80211_valid_auth_type(connect.auth_type))
5458 return -EINVAL;
5459 } else
5460 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5461
5462 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5463
Johannes Bergc0692b82010-08-27 14:26:53 +03005464 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005465 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005466 if (err)
5467 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005468
Johannes Berg074ac8d2010-09-16 14:58:22 +02005469 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005470 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5471 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005472
Johannes Berg79c97e92009-07-07 03:56:12 +02005473 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005474
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305475 connect.bg_scan_period = -1;
5476 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5477 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5478 connect.bg_scan_period =
5479 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5480 }
5481
Samuel Ortizb23aa672009-07-01 21:26:54 +02005482 if (info->attrs[NL80211_ATTR_MAC])
5483 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5484 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5485 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5486
5487 if (info->attrs[NL80211_ATTR_IE]) {
5488 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5489 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5490 }
5491
5492 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5493 connect.channel =
5494 ieee80211_get_channel(wiphy,
5495 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5496 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005497 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5498 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005499 }
5500
Johannes Bergfffd0932009-07-08 14:22:54 +02005501 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5502 connkeys = nl80211_parse_connkeys(rdev,
5503 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005504 if (IS_ERR(connkeys))
5505 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005506 }
5507
Ben Greear7e7c8922011-11-18 11:31:59 -08005508 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5509 connect.flags |= ASSOC_REQ_DISABLE_HT;
5510
5511 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5512 memcpy(&connect.ht_capa_mask,
5513 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5514 sizeof(connect.ht_capa_mask));
5515
5516 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5517 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5518 return -EINVAL;
5519 memcpy(&connect.ht_capa,
5520 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5521 sizeof(connect.ht_capa));
5522 }
5523
Johannes Bergfffd0932009-07-08 14:22:54 +02005524 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005525 if (err)
5526 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005527 return err;
5528}
5529
5530static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5531{
Johannes Berg4c476992010-10-04 21:36:35 +02005532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5533 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005534 u16 reason;
5535
5536 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5537 reason = WLAN_REASON_DEAUTH_LEAVING;
5538 else
5539 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5540
5541 if (reason == 0)
5542 return -EINVAL;
5543
Johannes Berg074ac8d2010-09-16 14:58:22 +02005544 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005545 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5546 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005547
Johannes Berg4c476992010-10-04 21:36:35 +02005548 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005549}
5550
Johannes Berg463d0182009-07-14 00:33:35 +02005551static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5552{
Johannes Berg4c476992010-10-04 21:36:35 +02005553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005554 struct net *net;
5555 int err;
5556 u32 pid;
5557
5558 if (!info->attrs[NL80211_ATTR_PID])
5559 return -EINVAL;
5560
5561 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5562
Johannes Berg463d0182009-07-14 00:33:35 +02005563 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005564 if (IS_ERR(net))
5565 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005566
5567 err = 0;
5568
5569 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005570 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5571 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005572
Johannes Berg463d0182009-07-14 00:33:35 +02005573 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005574 return err;
5575}
5576
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005577static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5578{
Johannes Berg4c476992010-10-04 21:36:35 +02005579 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005580 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5581 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005582 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005583 struct cfg80211_pmksa pmksa;
5584
5585 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5586
5587 if (!info->attrs[NL80211_ATTR_MAC])
5588 return -EINVAL;
5589
5590 if (!info->attrs[NL80211_ATTR_PMKID])
5591 return -EINVAL;
5592
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005593 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5594 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5595
Johannes Berg074ac8d2010-09-16 14:58:22 +02005596 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005597 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5598 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005599
5600 switch (info->genlhdr->cmd) {
5601 case NL80211_CMD_SET_PMKSA:
5602 rdev_ops = rdev->ops->set_pmksa;
5603 break;
5604 case NL80211_CMD_DEL_PMKSA:
5605 rdev_ops = rdev->ops->del_pmksa;
5606 break;
5607 default:
5608 WARN_ON(1);
5609 break;
5610 }
5611
Johannes Berg4c476992010-10-04 21:36:35 +02005612 if (!rdev_ops)
5613 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005614
Johannes Berg4c476992010-10-04 21:36:35 +02005615 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005616}
5617
5618static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5619{
Johannes Berg4c476992010-10-04 21:36:35 +02005620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5621 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005622
Johannes Berg074ac8d2010-09-16 14:58:22 +02005623 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005624 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5625 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005626
Johannes Berg4c476992010-10-04 21:36:35 +02005627 if (!rdev->ops->flush_pmksa)
5628 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005629
Johannes Berg4c476992010-10-04 21:36:35 +02005630 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005631}
5632
Arik Nemtsov109086c2011-09-28 14:12:50 +03005633static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5634{
5635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5636 struct net_device *dev = info->user_ptr[1];
5637 u8 action_code, dialog_token;
5638 u16 status_code;
5639 u8 *peer;
5640
5641 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5642 !rdev->ops->tdls_mgmt)
5643 return -EOPNOTSUPP;
5644
5645 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5646 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5647 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5648 !info->attrs[NL80211_ATTR_IE] ||
5649 !info->attrs[NL80211_ATTR_MAC])
5650 return -EINVAL;
5651
5652 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5653 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5654 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5655 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5656
5657 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5658 dialog_token, status_code,
5659 nla_data(info->attrs[NL80211_ATTR_IE]),
5660 nla_len(info->attrs[NL80211_ATTR_IE]));
5661}
5662
5663static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5664{
5665 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5666 struct net_device *dev = info->user_ptr[1];
5667 enum nl80211_tdls_operation operation;
5668 u8 *peer;
5669
5670 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5671 !rdev->ops->tdls_oper)
5672 return -EOPNOTSUPP;
5673
5674 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5675 !info->attrs[NL80211_ATTR_MAC])
5676 return -EINVAL;
5677
5678 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5679 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5680
5681 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5682}
5683
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005684static int nl80211_remain_on_channel(struct sk_buff *skb,
5685 struct genl_info *info)
5686{
Johannes Berg4c476992010-10-04 21:36:35 +02005687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5688 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005689 struct ieee80211_channel *chan;
5690 struct sk_buff *msg;
5691 void *hdr;
5692 u64 cookie;
5693 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5694 u32 freq, duration;
5695 int err;
5696
5697 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5698 !info->attrs[NL80211_ATTR_DURATION])
5699 return -EINVAL;
5700
5701 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5702
Johannes Berg7c4ef712011-11-18 15:33:48 +01005703 if (!rdev->ops->remain_on_channel ||
5704 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005705 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005706
Johannes Bergebf348f2012-06-01 12:50:54 +02005707 /*
5708 * We should be on that channel for at least a minimum amount of
5709 * time (10ms) but no longer than the driver supports.
5710 */
5711 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5712 duration > rdev->wiphy.max_remain_on_channel_duration)
5713 return -EINVAL;
5714
Johannes Bergcd6c6592012-05-10 21:27:18 +02005715 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5716 !nl80211_valid_channel_type(info, &channel_type))
5717 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005718
5719 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5720 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005721 if (chan == NULL)
5722 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005723
5724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005725 if (!msg)
5726 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005727
5728 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5729 NL80211_CMD_REMAIN_ON_CHANNEL);
5730
5731 if (IS_ERR(hdr)) {
5732 err = PTR_ERR(hdr);
5733 goto free_msg;
5734 }
5735
5736 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5737 channel_type, duration, &cookie);
5738
5739 if (err)
5740 goto free_msg;
5741
David S. Miller9360ffd2012-03-29 04:41:26 -04005742 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5743 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005744
5745 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005746
5747 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005748
5749 nla_put_failure:
5750 err = -ENOBUFS;
5751 free_msg:
5752 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005753 return err;
5754}
5755
5756static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5757 struct genl_info *info)
5758{
Johannes Berg4c476992010-10-04 21:36:35 +02005759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5760 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005761 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005762
5763 if (!info->attrs[NL80211_ATTR_COOKIE])
5764 return -EINVAL;
5765
Johannes Berg4c476992010-10-04 21:36:35 +02005766 if (!rdev->ops->cancel_remain_on_channel)
5767 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005768
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005769 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5770
Johannes Berg4c476992010-10-04 21:36:35 +02005771 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005772}
5773
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005774static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5775 u8 *rates, u8 rates_len)
5776{
5777 u8 i;
5778 u32 mask = 0;
5779
5780 for (i = 0; i < rates_len; i++) {
5781 int rate = (rates[i] & 0x7f) * 5;
5782 int ridx;
5783 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5784 struct ieee80211_rate *srate =
5785 &sband->bitrates[ridx];
5786 if (rate == srate->bitrate) {
5787 mask |= 1 << ridx;
5788 break;
5789 }
5790 }
5791 if (ridx == sband->n_bitrates)
5792 return 0; /* rate not found */
5793 }
5794
5795 return mask;
5796}
5797
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005798static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5799 u8 *rates, u8 rates_len,
5800 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5801{
5802 u8 i;
5803
5804 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5805
5806 for (i = 0; i < rates_len; i++) {
5807 int ridx, rbit;
5808
5809 ridx = rates[i] / 8;
5810 rbit = BIT(rates[i] % 8);
5811
5812 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005813 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005814 return false;
5815
5816 /* check availability */
5817 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5818 mcs[ridx] |= rbit;
5819 else
5820 return false;
5821 }
5822
5823 return true;
5824}
5825
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005826static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005827 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5828 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005829 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
5830 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005831};
5832
5833static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5834 struct genl_info *info)
5835{
5836 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02005837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005838 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02005839 int rem, i;
5840 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005841 struct nlattr *tx_rates;
5842 struct ieee80211_supported_band *sband;
5843
5844 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5845 return -EINVAL;
5846
Johannes Berg4c476992010-10-04 21:36:35 +02005847 if (!rdev->ops->set_bitrate_mask)
5848 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005849
5850 memset(&mask, 0, sizeof(mask));
5851 /* Default to all rates enabled */
5852 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5853 sband = rdev->wiphy.bands[i];
5854 mask.control[i].legacy =
5855 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005856 if (sband)
5857 memcpy(mask.control[i].mcs,
5858 sband->ht_cap.mcs.rx_mask,
5859 sizeof(mask.control[i].mcs));
5860 else
5861 memset(mask.control[i].mcs, 0,
5862 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005863 }
5864
5865 /*
5866 * The nested attribute uses enum nl80211_band as the index. This maps
5867 * directly to the enum ieee80211_band values used in cfg80211.
5868 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005869 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005870 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5871 {
5872 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02005873 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5874 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005875 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02005876 if (sband == NULL)
5877 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005878 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5879 nla_len(tx_rates), nl80211_txattr_policy);
5880 if (tb[NL80211_TXRATE_LEGACY]) {
5881 mask.control[band].legacy = rateset_to_mask(
5882 sband,
5883 nla_data(tb[NL80211_TXRATE_LEGACY]),
5884 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05305885 if ((mask.control[band].legacy == 0) &&
5886 nla_len(tb[NL80211_TXRATE_LEGACY]))
5887 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005888 }
5889 if (tb[NL80211_TXRATE_MCS]) {
5890 if (!ht_rateset_to_mask(
5891 sband,
5892 nla_data(tb[NL80211_TXRATE_MCS]),
5893 nla_len(tb[NL80211_TXRATE_MCS]),
5894 mask.control[band].mcs))
5895 return -EINVAL;
5896 }
5897
5898 if (mask.control[band].legacy == 0) {
5899 /* don't allow empty legacy rates if HT
5900 * is not even supported. */
5901 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
5902 return -EINVAL;
5903
5904 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5905 if (mask.control[band].mcs[i])
5906 break;
5907
5908 /* legacy and mcs rates may not be both empty */
5909 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02005910 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005911 }
5912 }
5913
Johannes Berg4c476992010-10-04 21:36:35 +02005914 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005915}
5916
Johannes Berg2e161f72010-08-12 15:38:38 +02005917static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005918{
Johannes Berg4c476992010-10-04 21:36:35 +02005919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5920 struct net_device *dev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02005921 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02005922
5923 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5924 return -EINVAL;
5925
Johannes Berg2e161f72010-08-12 15:38:38 +02005926 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5927 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02005928
Johannes Berg9d38d852010-06-09 17:20:33 +02005929 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005930 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005931 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5932 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5933 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005934 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005935 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5936 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005937
5938 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02005939 if (!rdev->ops->mgmt_tx)
5940 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005941
Johannes Berg4c476992010-10-04 21:36:35 +02005942 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
Johannes Berg2e161f72010-08-12 15:38:38 +02005943 frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02005944 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5945 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02005946}
5947
Johannes Berg2e161f72010-08-12 15:38:38 +02005948static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02005949{
Johannes Berg4c476992010-10-04 21:36:35 +02005950 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5951 struct net_device *dev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02005952 struct ieee80211_channel *chan;
5953 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02005954 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02005955 u32 freq;
5956 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01005957 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02005958 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01005959 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005960 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01005961 bool offchan, no_cck, dont_wait_for_ack;
5962
5963 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02005964
5965 if (!info->attrs[NL80211_ATTR_FRAME] ||
5966 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5967 return -EINVAL;
5968
Johannes Berg4c476992010-10-04 21:36:35 +02005969 if (!rdev->ops->mgmt_tx)
5970 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005971
Johannes Berg9d38d852010-06-09 17:20:33 +02005972 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005973 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Johannes Berg663fcaf2010-09-30 21:06:09 +02005974 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5975 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5976 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Javier Cardonac7108a72010-12-16 17:37:50 -08005977 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005978 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5979 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02005980
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005981 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01005982 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005983 return -EINVAL;
5984 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02005985
5986 /*
5987 * We should wait on the channel for at least a minimum amount
5988 * of time (10ms) but no longer than the driver supports.
5989 */
5990 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5991 wait > rdev->wiphy.max_remain_on_channel_duration)
5992 return -EINVAL;
5993
Johannes Bergf7ca38d2010-11-25 10:02:29 +01005994 }
5995
Jouni Malinen026331c2010-02-15 12:53:10 +02005996 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02005997 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02005998 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02005999 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02006000 }
6001
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006002 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6003
Johannes Berg7c4ef712011-11-18 15:33:48 +01006004 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6005 return -EINVAL;
6006
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306007 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6008
Jouni Malinen026331c2010-02-15 12:53:10 +02006009 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6010 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006011 if (chan == NULL)
6012 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006013
Johannes Berge247bd902011-11-04 11:18:21 +01006014 if (!dont_wait_for_ack) {
6015 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6016 if (!msg)
6017 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006018
Johannes Berge247bd902011-11-04 11:18:21 +01006019 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6020 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006021
Johannes Berge247bd902011-11-04 11:18:21 +01006022 if (IS_ERR(hdr)) {
6023 err = PTR_ERR(hdr);
6024 goto free_msg;
6025 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006026 }
Johannes Berge247bd902011-11-04 11:18:21 +01006027
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006028 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
6029 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006030 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6031 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006032 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006033 if (err)
6034 goto free_msg;
6035
Johannes Berge247bd902011-11-04 11:18:21 +01006036 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006037 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6038 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006039
Johannes Berge247bd902011-11-04 11:18:21 +01006040 genlmsg_end(msg, hdr);
6041 return genlmsg_reply(msg, info);
6042 }
6043
6044 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006045
6046 nla_put_failure:
6047 err = -ENOBUFS;
6048 free_msg:
6049 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006050 return err;
6051}
6052
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006053static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6054{
6055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6056 struct net_device *dev = info->user_ptr[1];
6057 u64 cookie;
6058
6059 if (!info->attrs[NL80211_ATTR_COOKIE])
6060 return -EINVAL;
6061
6062 if (!rdev->ops->mgmt_tx_cancel_wait)
6063 return -EOPNOTSUPP;
6064
6065 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
6066 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6067 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
6068 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
6069 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
6070 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6071 return -EOPNOTSUPP;
6072
6073 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6074
6075 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
6076}
6077
Kalle Valoffb9eb32010-02-17 17:58:10 +02006078static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6079{
Johannes Berg4c476992010-10-04 21:36:35 +02006080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006081 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006082 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006083 u8 ps_state;
6084 bool state;
6085 int err;
6086
Johannes Berg4c476992010-10-04 21:36:35 +02006087 if (!info->attrs[NL80211_ATTR_PS_STATE])
6088 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006089
6090 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6091
Johannes Berg4c476992010-10-04 21:36:35 +02006092 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6093 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006094
6095 wdev = dev->ieee80211_ptr;
6096
Johannes Berg4c476992010-10-04 21:36:35 +02006097 if (!rdev->ops->set_power_mgmt)
6098 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006099
6100 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6101
6102 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006103 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006104
Johannes Berg4c476992010-10-04 21:36:35 +02006105 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6106 wdev->ps_timeout);
6107 if (!err)
6108 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006109 return err;
6110}
6111
6112static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6113{
Johannes Berg4c476992010-10-04 21:36:35 +02006114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006115 enum nl80211_ps_state ps_state;
6116 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006117 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006118 struct sk_buff *msg;
6119 void *hdr;
6120 int err;
6121
Kalle Valoffb9eb32010-02-17 17:58:10 +02006122 wdev = dev->ieee80211_ptr;
6123
Johannes Berg4c476992010-10-04 21:36:35 +02006124 if (!rdev->ops->set_power_mgmt)
6125 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006126
6127 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006128 if (!msg)
6129 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006130
6131 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6132 NL80211_CMD_GET_POWER_SAVE);
6133 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006134 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006135 goto free_msg;
6136 }
6137
6138 if (wdev->ps)
6139 ps_state = NL80211_PS_ENABLED;
6140 else
6141 ps_state = NL80211_PS_DISABLED;
6142
David S. Miller9360ffd2012-03-29 04:41:26 -04006143 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6144 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006145
6146 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006147 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006148
Johannes Berg4c476992010-10-04 21:36:35 +02006149 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006150 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006151 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006152 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006153 return err;
6154}
6155
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006156static struct nla_policy
6157nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6158 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6159 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6160 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
6161};
6162
6163static int nl80211_set_cqm_rssi(struct genl_info *info,
6164 s32 threshold, u32 hysteresis)
6165{
Johannes Berg4c476992010-10-04 21:36:35 +02006166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006167 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006168 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006169
6170 if (threshold > 0)
6171 return -EINVAL;
6172
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006173 wdev = dev->ieee80211_ptr;
6174
Johannes Berg4c476992010-10-04 21:36:35 +02006175 if (!rdev->ops->set_cqm_rssi_config)
6176 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006177
Johannes Berg074ac8d2010-09-16 14:58:22 +02006178 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006179 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6180 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006181
Johannes Berg4c476992010-10-04 21:36:35 +02006182 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6183 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006184}
6185
6186static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6187{
6188 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6189 struct nlattr *cqm;
6190 int err;
6191
6192 cqm = info->attrs[NL80211_ATTR_CQM];
6193 if (!cqm) {
6194 err = -EINVAL;
6195 goto out;
6196 }
6197
6198 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6199 nl80211_attr_cqm_policy);
6200 if (err)
6201 goto out;
6202
6203 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6204 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6205 s32 threshold;
6206 u32 hysteresis;
6207 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6208 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6209 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6210 } else
6211 err = -EINVAL;
6212
6213out:
6214 return err;
6215}
6216
Johannes Berg29cbe682010-12-03 09:20:44 +01006217static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6218{
6219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6220 struct net_device *dev = info->user_ptr[1];
6221 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006222 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006223 int err;
6224
6225 /* start with default */
6226 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006227 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006228
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006229 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006230 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006231 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006232 if (err)
6233 return err;
6234 }
6235
6236 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6237 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6238 return -EINVAL;
6239
Javier Cardonac80d5452010-12-16 17:37:49 -08006240 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6241 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6242
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006243 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6244 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6245 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6246 return -EINVAL;
6247
Javier Cardonac80d5452010-12-16 17:37:49 -08006248 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6249 /* parse additional setup parameters if given */
6250 err = nl80211_parse_mesh_setup(info, &setup);
6251 if (err)
6252 return err;
6253 }
6254
Johannes Bergcc1d2802012-05-16 23:50:20 +02006255 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6256 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6257
6258 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6259 !nl80211_valid_channel_type(info, &channel_type))
6260 return -EINVAL;
6261
6262 setup.channel = rdev_freq_to_chan(rdev,
6263 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6264 channel_type);
6265 if (!setup.channel)
6266 return -EINVAL;
6267 setup.channel_type = channel_type;
6268 } else {
6269 /* cfg80211_join_mesh() will sort it out */
6270 setup.channel = NULL;
6271 }
6272
Javier Cardonac80d5452010-12-16 17:37:49 -08006273 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006274}
6275
6276static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6277{
6278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6279 struct net_device *dev = info->user_ptr[1];
6280
6281 return cfg80211_leave_mesh(rdev, dev);
6282}
6283
Johannes Bergdfb89c52012-06-27 09:23:48 +02006284#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006285static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6286{
6287 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6288 struct sk_buff *msg;
6289 void *hdr;
6290
6291 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6292 return -EOPNOTSUPP;
6293
6294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6295 if (!msg)
6296 return -ENOMEM;
6297
6298 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6299 NL80211_CMD_GET_WOWLAN);
6300 if (!hdr)
6301 goto nla_put_failure;
6302
6303 if (rdev->wowlan) {
6304 struct nlattr *nl_wowlan;
6305
6306 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6307 if (!nl_wowlan)
6308 goto nla_put_failure;
6309
David S. Miller9360ffd2012-03-29 04:41:26 -04006310 if ((rdev->wowlan->any &&
6311 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6312 (rdev->wowlan->disconnect &&
6313 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6314 (rdev->wowlan->magic_pkt &&
6315 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6316 (rdev->wowlan->gtk_rekey_failure &&
6317 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6318 (rdev->wowlan->eap_identity_req &&
6319 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6320 (rdev->wowlan->four_way_handshake &&
6321 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6322 (rdev->wowlan->rfkill_release &&
6323 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6324 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006325 if (rdev->wowlan->n_patterns) {
6326 struct nlattr *nl_pats, *nl_pat;
6327 int i, pat_len;
6328
6329 nl_pats = nla_nest_start(msg,
6330 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6331 if (!nl_pats)
6332 goto nla_put_failure;
6333
6334 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6335 nl_pat = nla_nest_start(msg, i + 1);
6336 if (!nl_pat)
6337 goto nla_put_failure;
6338 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006339 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6340 DIV_ROUND_UP(pat_len, 8),
6341 rdev->wowlan->patterns[i].mask) ||
6342 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6343 pat_len,
6344 rdev->wowlan->patterns[i].pattern))
6345 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006346 nla_nest_end(msg, nl_pat);
6347 }
6348 nla_nest_end(msg, nl_pats);
6349 }
6350
6351 nla_nest_end(msg, nl_wowlan);
6352 }
6353
6354 genlmsg_end(msg, hdr);
6355 return genlmsg_reply(msg, info);
6356
6357nla_put_failure:
6358 nlmsg_free(msg);
6359 return -ENOBUFS;
6360}
6361
6362static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6363{
6364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6365 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
6366 struct cfg80211_wowlan no_triggers = {};
6367 struct cfg80211_wowlan new_triggers = {};
6368 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6369 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006370 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006371
6372 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6373 return -EOPNOTSUPP;
6374
6375 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
6376 goto no_triggers;
6377
6378 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6379 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6380 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6381 nl80211_wowlan_policy);
6382 if (err)
6383 return err;
6384
6385 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6386 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6387 return -EINVAL;
6388 new_triggers.any = true;
6389 }
6390
6391 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6392 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6393 return -EINVAL;
6394 new_triggers.disconnect = true;
6395 }
6396
6397 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6398 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6399 return -EINVAL;
6400 new_triggers.magic_pkt = true;
6401 }
6402
Johannes Berg77dbbb12011-07-13 10:48:55 +02006403 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6404 return -EINVAL;
6405
6406 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6407 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6408 return -EINVAL;
6409 new_triggers.gtk_rekey_failure = true;
6410 }
6411
6412 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6413 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6414 return -EINVAL;
6415 new_triggers.eap_identity_req = true;
6416 }
6417
6418 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6419 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6420 return -EINVAL;
6421 new_triggers.four_way_handshake = true;
6422 }
6423
6424 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6425 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6426 return -EINVAL;
6427 new_triggers.rfkill_release = true;
6428 }
6429
Johannes Bergff1b6e62011-05-04 15:37:28 +02006430 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6431 struct nlattr *pat;
6432 int n_patterns = 0;
6433 int rem, pat_len, mask_len;
6434 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6435
6436 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6437 rem)
6438 n_patterns++;
6439 if (n_patterns > wowlan->n_patterns)
6440 return -EINVAL;
6441
6442 new_triggers.patterns = kcalloc(n_patterns,
6443 sizeof(new_triggers.patterns[0]),
6444 GFP_KERNEL);
6445 if (!new_triggers.patterns)
6446 return -ENOMEM;
6447
6448 new_triggers.n_patterns = n_patterns;
6449 i = 0;
6450
6451 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6452 rem) {
6453 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6454 nla_data(pat), nla_len(pat), NULL);
6455 err = -EINVAL;
6456 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6457 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6458 goto error;
6459 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6460 mask_len = DIV_ROUND_UP(pat_len, 8);
6461 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6462 mask_len)
6463 goto error;
6464 if (pat_len > wowlan->pattern_max_len ||
6465 pat_len < wowlan->pattern_min_len)
6466 goto error;
6467
6468 new_triggers.patterns[i].mask =
6469 kmalloc(mask_len + pat_len, GFP_KERNEL);
6470 if (!new_triggers.patterns[i].mask) {
6471 err = -ENOMEM;
6472 goto error;
6473 }
6474 new_triggers.patterns[i].pattern =
6475 new_triggers.patterns[i].mask + mask_len;
6476 memcpy(new_triggers.patterns[i].mask,
6477 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6478 mask_len);
6479 new_triggers.patterns[i].pattern_len = pat_len;
6480 memcpy(new_triggers.patterns[i].pattern,
6481 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6482 pat_len);
6483 i++;
6484 }
6485 }
6486
6487 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
6488 struct cfg80211_wowlan *ntrig;
6489 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6490 GFP_KERNEL);
6491 if (!ntrig) {
6492 err = -ENOMEM;
6493 goto error;
6494 }
6495 cfg80211_rdev_free_wowlan(rdev);
6496 rdev->wowlan = ntrig;
6497 } else {
6498 no_triggers:
6499 cfg80211_rdev_free_wowlan(rdev);
6500 rdev->wowlan = NULL;
6501 }
6502
Johannes Berg6d525632012-04-04 15:05:25 +02006503 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6504 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6505
Johannes Bergff1b6e62011-05-04 15:37:28 +02006506 return 0;
6507 error:
6508 for (i = 0; i < new_triggers.n_patterns; i++)
6509 kfree(new_triggers.patterns[i].mask);
6510 kfree(new_triggers.patterns);
6511 return err;
6512}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006513#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006514
Johannes Berge5497d72011-07-05 16:35:40 +02006515static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6516{
6517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6518 struct net_device *dev = info->user_ptr[1];
6519 struct wireless_dev *wdev = dev->ieee80211_ptr;
6520 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6521 struct cfg80211_gtk_rekey_data rekey_data;
6522 int err;
6523
6524 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6525 return -EINVAL;
6526
6527 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6528 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6529 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6530 nl80211_rekey_policy);
6531 if (err)
6532 return err;
6533
6534 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6535 return -ERANGE;
6536 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6537 return -ERANGE;
6538 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6539 return -ERANGE;
6540
6541 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6542 NL80211_KEK_LEN);
6543 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6544 NL80211_KCK_LEN);
6545 memcpy(rekey_data.replay_ctr,
6546 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6547 NL80211_REPLAY_CTR_LEN);
6548
6549 wdev_lock(wdev);
6550 if (!wdev->current_bss) {
6551 err = -ENOTCONN;
6552 goto out;
6553 }
6554
6555 if (!rdev->ops->set_rekey_data) {
6556 err = -EOPNOTSUPP;
6557 goto out;
6558 }
6559
6560 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6561 out:
6562 wdev_unlock(wdev);
6563 return err;
6564}
6565
Johannes Berg28946da2011-11-04 11:18:12 +01006566static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6567 struct genl_info *info)
6568{
6569 struct net_device *dev = info->user_ptr[1];
6570 struct wireless_dev *wdev = dev->ieee80211_ptr;
6571
6572 if (wdev->iftype != NL80211_IFTYPE_AP &&
6573 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6574 return -EINVAL;
6575
6576 if (wdev->ap_unexpected_nlpid)
6577 return -EBUSY;
6578
6579 wdev->ap_unexpected_nlpid = info->snd_pid;
6580 return 0;
6581}
6582
Johannes Berg7f6cf312011-11-04 11:18:15 +01006583static int nl80211_probe_client(struct sk_buff *skb,
6584 struct genl_info *info)
6585{
6586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6587 struct net_device *dev = info->user_ptr[1];
6588 struct wireless_dev *wdev = dev->ieee80211_ptr;
6589 struct sk_buff *msg;
6590 void *hdr;
6591 const u8 *addr;
6592 u64 cookie;
6593 int err;
6594
6595 if (wdev->iftype != NL80211_IFTYPE_AP &&
6596 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6597 return -EOPNOTSUPP;
6598
6599 if (!info->attrs[NL80211_ATTR_MAC])
6600 return -EINVAL;
6601
6602 if (!rdev->ops->probe_client)
6603 return -EOPNOTSUPP;
6604
6605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6606 if (!msg)
6607 return -ENOMEM;
6608
6609 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6610 NL80211_CMD_PROBE_CLIENT);
6611
6612 if (IS_ERR(hdr)) {
6613 err = PTR_ERR(hdr);
6614 goto free_msg;
6615 }
6616
6617 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6618
6619 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6620 if (err)
6621 goto free_msg;
6622
David S. Miller9360ffd2012-03-29 04:41:26 -04006623 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6624 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006625
6626 genlmsg_end(msg, hdr);
6627
6628 return genlmsg_reply(msg, info);
6629
6630 nla_put_failure:
6631 err = -ENOBUFS;
6632 free_msg:
6633 nlmsg_free(msg);
6634 return err;
6635}
6636
Johannes Berg5e7602302011-11-04 11:18:17 +01006637static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6638{
6639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6640
6641 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6642 return -EOPNOTSUPP;
6643
6644 if (rdev->ap_beacons_nlpid)
6645 return -EBUSY;
6646
6647 rdev->ap_beacons_nlpid = info->snd_pid;
6648
6649 return 0;
6650}
6651
Johannes Berg4c476992010-10-04 21:36:35 +02006652#define NL80211_FLAG_NEED_WIPHY 0x01
6653#define NL80211_FLAG_NEED_NETDEV 0x02
6654#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006655#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6656#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6657 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006658
6659static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6660 struct genl_info *info)
6661{
6662 struct cfg80211_registered_device *rdev;
6663 struct net_device *dev;
6664 int err;
6665 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6666
6667 if (rtnl)
6668 rtnl_lock();
6669
6670 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006671 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006672 if (IS_ERR(rdev)) {
6673 if (rtnl)
6674 rtnl_unlock();
6675 return PTR_ERR(rdev);
6676 }
6677 info->user_ptr[0] = rdev;
6678 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
Johannes Berg00918d32011-12-13 17:22:05 +01006679 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6680 &rdev, &dev);
Johannes Berg4c476992010-10-04 21:36:35 +02006681 if (err) {
6682 if (rtnl)
6683 rtnl_unlock();
6684 return err;
6685 }
Johannes Berg41265712010-10-04 21:14:05 +02006686 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6687 !netif_running(dev)) {
Johannes Bergd537f5f2010-10-05 21:34:11 +02006688 cfg80211_unlock_rdev(rdev);
6689 dev_put(dev);
Johannes Berg41265712010-10-04 21:14:05 +02006690 if (rtnl)
6691 rtnl_unlock();
6692 return -ENETDOWN;
6693 }
Johannes Berg4c476992010-10-04 21:36:35 +02006694 info->user_ptr[0] = rdev;
6695 info->user_ptr[1] = dev;
6696 }
6697
6698 return 0;
6699}
6700
6701static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6702 struct genl_info *info)
6703{
6704 if (info->user_ptr[0])
6705 cfg80211_unlock_rdev(info->user_ptr[0]);
6706 if (info->user_ptr[1])
6707 dev_put(info->user_ptr[1]);
6708 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6709 rtnl_unlock();
6710}
6711
Johannes Berg55682962007-09-20 13:09:35 -04006712static struct genl_ops nl80211_ops[] = {
6713 {
6714 .cmd = NL80211_CMD_GET_WIPHY,
6715 .doit = nl80211_get_wiphy,
6716 .dumpit = nl80211_dump_wiphy,
6717 .policy = nl80211_policy,
6718 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006719 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04006720 },
6721 {
6722 .cmd = NL80211_CMD_SET_WIPHY,
6723 .doit = nl80211_set_wiphy,
6724 .policy = nl80211_policy,
6725 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006726 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006727 },
6728 {
6729 .cmd = NL80211_CMD_GET_INTERFACE,
6730 .doit = nl80211_get_interface,
6731 .dumpit = nl80211_dump_interface,
6732 .policy = nl80211_policy,
6733 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02006734 .internal_flags = NL80211_FLAG_NEED_NETDEV,
Johannes Berg55682962007-09-20 13:09:35 -04006735 },
6736 {
6737 .cmd = NL80211_CMD_SET_INTERFACE,
6738 .doit = nl80211_set_interface,
6739 .policy = nl80211_policy,
6740 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006741 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6742 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006743 },
6744 {
6745 .cmd = NL80211_CMD_NEW_INTERFACE,
6746 .doit = nl80211_new_interface,
6747 .policy = nl80211_policy,
6748 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006749 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6750 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006751 },
6752 {
6753 .cmd = NL80211_CMD_DEL_INTERFACE,
6754 .doit = nl80211_del_interface,
6755 .policy = nl80211_policy,
6756 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02006757 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6758 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04006759 },
Johannes Berg41ade002007-12-19 02:03:29 +01006760 {
6761 .cmd = NL80211_CMD_GET_KEY,
6762 .doit = nl80211_get_key,
6763 .policy = nl80211_policy,
6764 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +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_SET_KEY,
6770 .doit = nl80211_set_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_NEW_KEY,
6778 .doit = nl80211_new_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 },
6784 {
6785 .cmd = NL80211_CMD_DEL_KEY,
6786 .doit = nl80211_del_key,
6787 .policy = nl80211_policy,
6788 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006790 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01006791 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01006792 {
6793 .cmd = NL80211_CMD_SET_BEACON,
6794 .policy = nl80211_policy,
6795 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006796 .doit = nl80211_set_beacon,
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_START_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_start_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 },
6808 {
Johannes Berg88600202012-02-13 15:17:18 +01006809 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006810 .policy = nl80211_policy,
6811 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01006812 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006813 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006814 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01006815 },
Johannes Berg5727ef12007-12-19 02:03:34 +01006816 {
6817 .cmd = NL80211_CMD_GET_STATION,
6818 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006819 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01006820 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02006821 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6822 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006823 },
6824 {
6825 .cmd = NL80211_CMD_SET_STATION,
6826 .doit = nl80211_set_station,
6827 .policy = nl80211_policy,
6828 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +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_NEW_STATION,
6834 .doit = nl80211_new_station,
6835 .policy = nl80211_policy,
6836 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +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 },
6840 {
6841 .cmd = NL80211_CMD_DEL_STATION,
6842 .doit = nl80211_del_station,
6843 .policy = nl80211_policy,
6844 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006845 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006846 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01006847 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006848 {
6849 .cmd = NL80211_CMD_GET_MPATH,
6850 .doit = nl80211_get_mpath,
6851 .dumpit = nl80211_dump_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_SET_MPATH,
6859 .doit = nl80211_set_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_NEW_MPATH,
6867 .doit = nl80211_new_mpath,
6868 .policy = nl80211_policy,
6869 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +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 },
6873 {
6874 .cmd = NL80211_CMD_DEL_MPATH,
6875 .doit = nl80211_del_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006880 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006881 {
6882 .cmd = NL80211_CMD_SET_BSS,
6883 .doit = nl80211_set_bss,
6884 .policy = nl80211_policy,
6885 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006886 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006887 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006888 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006889 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006890 .cmd = NL80211_CMD_GET_REG,
6891 .doit = nl80211_get_reg,
6892 .policy = nl80211_policy,
6893 /* can be retrieved by unprivileged users */
6894 },
6895 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006896 .cmd = NL80211_CMD_SET_REG,
6897 .doit = nl80211_set_reg,
6898 .policy = nl80211_policy,
6899 .flags = GENL_ADMIN_PERM,
6900 },
6901 {
6902 .cmd = NL80211_CMD_REQ_SET_REG,
6903 .doit = nl80211_req_set_reg,
6904 .policy = nl80211_policy,
6905 .flags = GENL_ADMIN_PERM,
6906 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006907 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006908 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6909 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006910 .policy = nl80211_policy,
6911 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02006912 .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 },
6915 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006916 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6917 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006918 .policy = nl80211_policy,
6919 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01006920 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006921 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006922 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02006923 {
Johannes Berg2a519312009-02-10 21:25:55 +01006924 .cmd = NL80211_CMD_TRIGGER_SCAN,
6925 .doit = nl80211_trigger_scan,
6926 .policy = nl80211_policy,
6927 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006928 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006929 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01006930 },
6931 {
6932 .cmd = NL80211_CMD_GET_SCAN,
6933 .policy = nl80211_policy,
6934 .dumpit = nl80211_dump_scan,
6935 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02006936 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006937 .cmd = NL80211_CMD_START_SCHED_SCAN,
6938 .doit = nl80211_start_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 {
6945 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6946 .doit = nl80211_stop_sched_scan,
6947 .policy = nl80211_policy,
6948 .flags = GENL_ADMIN_PERM,
6949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6950 NL80211_FLAG_NEED_RTNL,
6951 },
6952 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02006953 .cmd = NL80211_CMD_AUTHENTICATE,
6954 .doit = nl80211_authenticate,
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_ASSOCIATE,
6962 .doit = nl80211_associate,
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_DEAUTHENTICATE,
6970 .doit = nl80211_deauthenticate,
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 },
6976 {
6977 .cmd = NL80211_CMD_DISASSOCIATE,
6978 .doit = nl80211_disassociate,
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,
Jouni Malinen636a5d32009-03-19 13:39:22 +02006983 },
Johannes Berg04a773a2009-04-19 21:24:32 +02006984 {
6985 .cmd = NL80211_CMD_JOIN_IBSS,
6986 .doit = nl80211_join_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 },
6992 {
6993 .cmd = NL80211_CMD_LEAVE_IBSS,
6994 .doit = nl80211_leave_ibss,
6995 .policy = nl80211_policy,
6996 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02006997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02006998 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02006999 },
Johannes Bergaff89a92009-07-01 21:26:51 +02007000#ifdef CONFIG_NL80211_TESTMODE
7001 {
7002 .cmd = NL80211_CMD_TESTMODE,
7003 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007004 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02007005 .policy = nl80211_policy,
7006 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007007 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7008 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007009 },
7010#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007011 {
7012 .cmd = NL80211_CMD_CONNECT,
7013 .doit = nl80211_connect,
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 },
7019 {
7020 .cmd = NL80211_CMD_DISCONNECT,
7021 .doit = nl80211_disconnect,
7022 .policy = nl80211_policy,
7023 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007025 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007026 },
Johannes Berg463d0182009-07-14 00:33:35 +02007027 {
7028 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7029 .doit = nl80211_wiphy_netns,
7030 .policy = nl80211_policy,
7031 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007032 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7033 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007034 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007035 {
7036 .cmd = NL80211_CMD_GET_SURVEY,
7037 .policy = nl80211_policy,
7038 .dumpit = nl80211_dump_survey,
7039 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007040 {
7041 .cmd = NL80211_CMD_SET_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_DEL_PMKSA,
7050 .doit = nl80211_setdel_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 },
7056 {
7057 .cmd = NL80211_CMD_FLUSH_PMKSA,
7058 .doit = nl80211_flush_pmksa,
7059 .policy = nl80211_policy,
7060 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007061 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007062 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007063 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007064 {
7065 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7066 .doit = nl80211_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 },
7072 {
7073 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7074 .doit = nl80211_cancel_remain_on_channel,
7075 .policy = nl80211_policy,
7076 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007077 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007078 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007079 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007080 {
7081 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7082 .doit = nl80211_set_tx_bitrate_mask,
7083 .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 Malinen13ae75b2009-12-29 12:59:45 +02007087 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007088 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007089 .cmd = NL80211_CMD_REGISTER_FRAME,
7090 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007091 .policy = nl80211_policy,
7092 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007093 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7094 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007095 },
7096 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007097 .cmd = NL80211_CMD_FRAME,
7098 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007099 .policy = nl80211_policy,
7100 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007101 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007102 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007103 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007104 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007105 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7106 .doit = nl80211_tx_mgmt_cancel_wait,
7107 .policy = nl80211_policy,
7108 .flags = GENL_ADMIN_PERM,
7109 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7110 NL80211_FLAG_NEED_RTNL,
7111 },
7112 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007113 .cmd = NL80211_CMD_SET_POWER_SAVE,
7114 .doit = nl80211_set_power_save,
7115 .policy = nl80211_policy,
7116 .flags = GENL_ADMIN_PERM,
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 },
7120 {
7121 .cmd = NL80211_CMD_GET_POWER_SAVE,
7122 .doit = nl80211_get_power_save,
7123 .policy = nl80211_policy,
7124 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007125 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7126 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007127 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007128 {
7129 .cmd = NL80211_CMD_SET_CQM,
7130 .doit = nl80211_set_cqm,
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,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007135 },
Johannes Bergf444de02010-05-05 15:25:02 +02007136 {
7137 .cmd = NL80211_CMD_SET_CHANNEL,
7138 .doit = nl80211_set_channel,
7139 .policy = nl80211_policy,
7140 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007141 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7142 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007143 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007144 {
7145 .cmd = NL80211_CMD_SET_WDS_PEER,
7146 .doit = nl80211_set_wds_peer,
7147 .policy = nl80211_policy,
7148 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007149 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7150 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007151 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007152 {
7153 .cmd = NL80211_CMD_JOIN_MESH,
7154 .doit = nl80211_join_mesh,
7155 .policy = nl80211_policy,
7156 .flags = GENL_ADMIN_PERM,
7157 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7158 NL80211_FLAG_NEED_RTNL,
7159 },
7160 {
7161 .cmd = NL80211_CMD_LEAVE_MESH,
7162 .doit = nl80211_leave_mesh,
7163 .policy = nl80211_policy,
7164 .flags = GENL_ADMIN_PERM,
7165 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7166 NL80211_FLAG_NEED_RTNL,
7167 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007168#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007169 {
7170 .cmd = NL80211_CMD_GET_WOWLAN,
7171 .doit = nl80211_get_wowlan,
7172 .policy = nl80211_policy,
7173 /* can be retrieved by unprivileged users */
7174 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7175 NL80211_FLAG_NEED_RTNL,
7176 },
7177 {
7178 .cmd = NL80211_CMD_SET_WOWLAN,
7179 .doit = nl80211_set_wowlan,
7180 .policy = nl80211_policy,
7181 .flags = GENL_ADMIN_PERM,
7182 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7183 NL80211_FLAG_NEED_RTNL,
7184 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007185#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007186 {
7187 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7188 .doit = nl80211_set_rekey_data,
7189 .policy = nl80211_policy,
7190 .flags = GENL_ADMIN_PERM,
7191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7192 NL80211_FLAG_NEED_RTNL,
7193 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007194 {
7195 .cmd = NL80211_CMD_TDLS_MGMT,
7196 .doit = nl80211_tdls_mgmt,
7197 .policy = nl80211_policy,
7198 .flags = GENL_ADMIN_PERM,
7199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7200 NL80211_FLAG_NEED_RTNL,
7201 },
7202 {
7203 .cmd = NL80211_CMD_TDLS_OPER,
7204 .doit = nl80211_tdls_oper,
7205 .policy = nl80211_policy,
7206 .flags = GENL_ADMIN_PERM,
7207 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7208 NL80211_FLAG_NEED_RTNL,
7209 },
Johannes Berg28946da2011-11-04 11:18:12 +01007210 {
7211 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7212 .doit = nl80211_register_unexpected_frame,
7213 .policy = nl80211_policy,
7214 .flags = GENL_ADMIN_PERM,
7215 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7216 NL80211_FLAG_NEED_RTNL,
7217 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007218 {
7219 .cmd = NL80211_CMD_PROBE_CLIENT,
7220 .doit = nl80211_probe_client,
7221 .policy = nl80211_policy,
7222 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007224 NL80211_FLAG_NEED_RTNL,
7225 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007226 {
7227 .cmd = NL80211_CMD_REGISTER_BEACONS,
7228 .doit = nl80211_register_beacons,
7229 .policy = nl80211_policy,
7230 .flags = GENL_ADMIN_PERM,
7231 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7232 NL80211_FLAG_NEED_RTNL,
7233 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007234 {
7235 .cmd = NL80211_CMD_SET_NOACK_MAP,
7236 .doit = nl80211_set_noack_map,
7237 .policy = nl80211_policy,
7238 .flags = GENL_ADMIN_PERM,
7239 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7240 NL80211_FLAG_NEED_RTNL,
7241 },
7242
Johannes Berg55682962007-09-20 13:09:35 -04007243};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007244
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007245static struct genl_multicast_group nl80211_mlme_mcgrp = {
7246 .name = "mlme",
7247};
Johannes Berg55682962007-09-20 13:09:35 -04007248
7249/* multicast groups */
7250static struct genl_multicast_group nl80211_config_mcgrp = {
7251 .name = "config",
7252};
Johannes Berg2a519312009-02-10 21:25:55 +01007253static struct genl_multicast_group nl80211_scan_mcgrp = {
7254 .name = "scan",
7255};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007256static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7257 .name = "regulatory",
7258};
Johannes Berg55682962007-09-20 13:09:35 -04007259
7260/* notification functions */
7261
7262void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7263{
7264 struct sk_buff *msg;
7265
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007266 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007267 if (!msg)
7268 return;
7269
7270 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7271 nlmsg_free(msg);
7272 return;
7273 }
7274
Johannes Berg463d0182009-07-14 00:33:35 +02007275 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7276 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007277}
7278
Johannes Berg362a4152009-05-24 16:43:15 +02007279static int nl80211_add_scan_req(struct sk_buff *msg,
7280 struct cfg80211_registered_device *rdev)
7281{
7282 struct cfg80211_scan_request *req = rdev->scan_req;
7283 struct nlattr *nest;
7284 int i;
7285
Johannes Berg667503dd2009-07-07 03:56:11 +02007286 ASSERT_RDEV_LOCK(rdev);
7287
Johannes Berg362a4152009-05-24 16:43:15 +02007288 if (WARN_ON(!req))
7289 return 0;
7290
7291 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7292 if (!nest)
7293 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007294 for (i = 0; i < req->n_ssids; i++) {
7295 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7296 goto nla_put_failure;
7297 }
Johannes Berg362a4152009-05-24 16:43:15 +02007298 nla_nest_end(msg, nest);
7299
7300 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7301 if (!nest)
7302 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007303 for (i = 0; i < req->n_channels; i++) {
7304 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7305 goto nla_put_failure;
7306 }
Johannes Berg362a4152009-05-24 16:43:15 +02007307 nla_nest_end(msg, nest);
7308
David S. Miller9360ffd2012-03-29 04:41:26 -04007309 if (req->ie &&
7310 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7311 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007312
7313 return 0;
7314 nla_put_failure:
7315 return -ENOBUFS;
7316}
7317
Johannes Berga538e2d2009-06-16 19:56:42 +02007318static int nl80211_send_scan_msg(struct sk_buff *msg,
7319 struct cfg80211_registered_device *rdev,
7320 struct net_device *netdev,
7321 u32 pid, u32 seq, int flags,
7322 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007323{
7324 void *hdr;
7325
7326 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7327 if (!hdr)
7328 return -1;
7329
David S. Miller9360ffd2012-03-29 04:41:26 -04007330 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7331 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7332 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007333
Johannes Berg362a4152009-05-24 16:43:15 +02007334 /* ignore errors and send incomplete event anyway */
7335 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007336
7337 return genlmsg_end(msg, hdr);
7338
7339 nla_put_failure:
7340 genlmsg_cancel(msg, hdr);
7341 return -EMSGSIZE;
7342}
7343
Luciano Coelho807f8a82011-05-11 17:09:35 +03007344static int
7345nl80211_send_sched_scan_msg(struct sk_buff *msg,
7346 struct cfg80211_registered_device *rdev,
7347 struct net_device *netdev,
7348 u32 pid, u32 seq, int flags, u32 cmd)
7349{
7350 void *hdr;
7351
7352 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
7353 if (!hdr)
7354 return -1;
7355
David S. Miller9360ffd2012-03-29 04:41:26 -04007356 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7357 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7358 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007359
7360 return genlmsg_end(msg, hdr);
7361
7362 nla_put_failure:
7363 genlmsg_cancel(msg, hdr);
7364 return -EMSGSIZE;
7365}
7366
Johannes Berga538e2d2009-06-16 19:56:42 +02007367void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
7368 struct net_device *netdev)
7369{
7370 struct sk_buff *msg;
7371
7372 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7373 if (!msg)
7374 return;
7375
7376 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7377 NL80211_CMD_TRIGGER_SCAN) < 0) {
7378 nlmsg_free(msg);
7379 return;
7380 }
7381
Johannes Berg463d0182009-07-14 00:33:35 +02007382 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7383 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007384}
7385
Johannes Berg2a519312009-02-10 21:25:55 +01007386void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
7387 struct net_device *netdev)
7388{
7389 struct sk_buff *msg;
7390
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007391 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007392 if (!msg)
7393 return;
7394
Johannes Berga538e2d2009-06-16 19:56:42 +02007395 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7396 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007397 nlmsg_free(msg);
7398 return;
7399 }
7400
Johannes Berg463d0182009-07-14 00:33:35 +02007401 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7402 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007403}
7404
7405void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
7406 struct net_device *netdev)
7407{
7408 struct sk_buff *msg;
7409
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007411 if (!msg)
7412 return;
7413
Johannes Berga538e2d2009-06-16 19:56:42 +02007414 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
7415 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007416 nlmsg_free(msg);
7417 return;
7418 }
7419
Johannes Berg463d0182009-07-14 00:33:35 +02007420 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7421 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007422}
7423
Luciano Coelho807f8a82011-05-11 17:09:35 +03007424void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7425 struct net_device *netdev)
7426{
7427 struct sk_buff *msg;
7428
7429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7430 if (!msg)
7431 return;
7432
7433 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7434 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7435 nlmsg_free(msg);
7436 return;
7437 }
7438
7439 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7440 nl80211_scan_mcgrp.id, GFP_KERNEL);
7441}
7442
7443void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7444 struct net_device *netdev, u32 cmd)
7445{
7446 struct sk_buff *msg;
7447
7448 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7449 if (!msg)
7450 return;
7451
7452 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7453 nlmsg_free(msg);
7454 return;
7455 }
7456
7457 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7458 nl80211_scan_mcgrp.id, GFP_KERNEL);
7459}
7460
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007461/*
7462 * This can happen on global regulatory changes or device specific settings
7463 * based on custom world regulatory domains.
7464 */
7465void nl80211_send_reg_change_event(struct regulatory_request *request)
7466{
7467 struct sk_buff *msg;
7468 void *hdr;
7469
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007470 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007471 if (!msg)
7472 return;
7473
7474 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7475 if (!hdr) {
7476 nlmsg_free(msg);
7477 return;
7478 }
7479
7480 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007481 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7482 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007483
David S. Miller9360ffd2012-03-29 04:41:26 -04007484 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7485 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7486 NL80211_REGDOM_TYPE_WORLD))
7487 goto nla_put_failure;
7488 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7489 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7490 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7491 goto nla_put_failure;
7492 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7493 request->intersect) {
7494 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7495 NL80211_REGDOM_TYPE_INTERSECTION))
7496 goto nla_put_failure;
7497 } else {
7498 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7499 NL80211_REGDOM_TYPE_COUNTRY) ||
7500 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7501 request->alpha2))
7502 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007503 }
7504
David S. Miller9360ffd2012-03-29 04:41:26 -04007505 if (wiphy_idx_valid(request->wiphy_idx) &&
7506 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7507 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007508
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007509 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007510
Johannes Bergbc43b282009-07-25 10:54:13 +02007511 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007512 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007513 GFP_ATOMIC);
7514 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007515
7516 return;
7517
7518nla_put_failure:
7519 genlmsg_cancel(msg, hdr);
7520 nlmsg_free(msg);
7521}
7522
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007523static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7524 struct net_device *netdev,
7525 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007526 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007527{
7528 struct sk_buff *msg;
7529 void *hdr;
7530
Johannes Berge6d6e342009-07-01 21:26:47 +02007531 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007532 if (!msg)
7533 return;
7534
7535 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7536 if (!hdr) {
7537 nlmsg_free(msg);
7538 return;
7539 }
7540
David S. Miller9360ffd2012-03-29 04:41:26 -04007541 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7542 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7543 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7544 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007545
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007546 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007547
Johannes Berg463d0182009-07-14 00:33:35 +02007548 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7549 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007550 return;
7551
7552 nla_put_failure:
7553 genlmsg_cancel(msg, hdr);
7554 nlmsg_free(msg);
7555}
7556
7557void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007558 struct net_device *netdev, const u8 *buf,
7559 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007560{
7561 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007562 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007563}
7564
7565void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7566 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007567 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007568{
Johannes Berge6d6e342009-07-01 21:26:47 +02007569 nl80211_send_mlme_event(rdev, netdev, buf, len,
7570 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007571}
7572
Jouni Malinen53b46b82009-03-27 20:53:56 +02007573void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007574 struct net_device *netdev, const u8 *buf,
7575 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_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007579}
7580
Jouni Malinen53b46b82009-03-27 20:53:56 +02007581void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7582 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007583 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007584{
7585 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007586 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007587}
7588
Jouni Malinencf4e5942010-12-16 00:52:40 +02007589void nl80211_send_unprot_deauth(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_DEAUTHENTICATE, gfp);
7595}
7596
7597void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7598 struct net_device *netdev, const u8 *buf,
7599 size_t len, gfp_t gfp)
7600{
7601 nl80211_send_mlme_event(rdev, netdev, buf, len,
7602 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7603}
7604
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007605static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7606 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007607 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007608{
7609 struct sk_buff *msg;
7610 void *hdr;
7611
Johannes Berge6d6e342009-07-01 21:26:47 +02007612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007613 if (!msg)
7614 return;
7615
7616 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7617 if (!hdr) {
7618 nlmsg_free(msg);
7619 return;
7620 }
7621
David S. Miller9360ffd2012-03-29 04:41:26 -04007622 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7623 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7624 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7625 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7626 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007627
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007628 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007629
Johannes Berg463d0182009-07-14 00:33:35 +02007630 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7631 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007632 return;
7633
7634 nla_put_failure:
7635 genlmsg_cancel(msg, hdr);
7636 nlmsg_free(msg);
7637}
7638
7639void nl80211_send_auth_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{
7643 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007644 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007645}
7646
7647void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007648 struct net_device *netdev, const u8 *addr,
7649 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007650{
Johannes Berge6d6e342009-07-01 21:26:47 +02007651 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7652 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007653}
7654
Samuel Ortizb23aa672009-07-01 21:26:54 +02007655void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7656 struct net_device *netdev, const u8 *bssid,
7657 const u8 *req_ie, size_t req_ie_len,
7658 const u8 *resp_ie, size_t resp_ie_len,
7659 u16 status, gfp_t gfp)
7660{
7661 struct sk_buff *msg;
7662 void *hdr;
7663
7664 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7665 if (!msg)
7666 return;
7667
7668 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7669 if (!hdr) {
7670 nlmsg_free(msg);
7671 return;
7672 }
7673
David S. Miller9360ffd2012-03-29 04:41:26 -04007674 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7676 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
7677 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
7678 (req_ie &&
7679 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7680 (resp_ie &&
7681 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7682 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007683
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007684 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007685
Johannes Berg463d0182009-07-14 00:33:35 +02007686 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7687 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007688 return;
7689
7690 nla_put_failure:
7691 genlmsg_cancel(msg, hdr);
7692 nlmsg_free(msg);
7693
7694}
7695
7696void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7697 struct net_device *netdev, const u8 *bssid,
7698 const u8 *req_ie, size_t req_ie_len,
7699 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7700{
7701 struct sk_buff *msg;
7702 void *hdr;
7703
7704 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7705 if (!msg)
7706 return;
7707
7708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7709 if (!hdr) {
7710 nlmsg_free(msg);
7711 return;
7712 }
7713
David S. Miller9360ffd2012-03-29 04:41:26 -04007714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7716 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
7717 (req_ie &&
7718 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
7719 (resp_ie &&
7720 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
7721 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007722
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007723 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007724
Johannes Berg463d0182009-07-14 00:33:35 +02007725 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7726 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007727 return;
7728
7729 nla_put_failure:
7730 genlmsg_cancel(msg, hdr);
7731 nlmsg_free(msg);
7732
7733}
7734
7735void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7736 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02007737 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007738{
7739 struct sk_buff *msg;
7740 void *hdr;
7741
Johannes Berg667503dd2009-07-07 03:56:11 +02007742 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007743 if (!msg)
7744 return;
7745
7746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7747 if (!hdr) {
7748 nlmsg_free(msg);
7749 return;
7750 }
7751
David S. Miller9360ffd2012-03-29 04:41:26 -04007752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7753 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7754 (from_ap && reason &&
7755 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
7756 (from_ap &&
7757 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
7758 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
7759 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007760
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007761 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007762
Johannes Berg463d0182009-07-14 00:33:35 +02007763 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7764 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007765 return;
7766
7767 nla_put_failure:
7768 genlmsg_cancel(msg, hdr);
7769 nlmsg_free(msg);
7770
7771}
7772
Johannes Berg04a773a2009-04-19 21:24:32 +02007773void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7774 struct net_device *netdev, const u8 *bssid,
7775 gfp_t gfp)
7776{
7777 struct sk_buff *msg;
7778 void *hdr;
7779
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007780 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007781 if (!msg)
7782 return;
7783
7784 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7785 if (!hdr) {
7786 nlmsg_free(msg);
7787 return;
7788 }
7789
David S. Miller9360ffd2012-03-29 04:41:26 -04007790 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7791 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7792 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
7793 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02007794
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007795 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02007796
Johannes Berg463d0182009-07-14 00:33:35 +02007797 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7798 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02007799 return;
7800
7801 nla_put_failure:
7802 genlmsg_cancel(msg, hdr);
7803 nlmsg_free(msg);
7804}
7805
Javier Cardonac93b5e72011-04-07 15:08:34 -07007806void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7807 struct net_device *netdev,
7808 const u8 *macaddr, const u8* ie, u8 ie_len,
7809 gfp_t gfp)
7810{
7811 struct sk_buff *msg;
7812 void *hdr;
7813
7814 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7815 if (!msg)
7816 return;
7817
7818 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7819 if (!hdr) {
7820 nlmsg_free(msg);
7821 return;
7822 }
7823
David S. Miller9360ffd2012-03-29 04:41:26 -04007824 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7825 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7826 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
7827 (ie_len && ie &&
7828 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
7829 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07007830
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007831 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07007832
7833 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7834 nl80211_mlme_mcgrp.id, gfp);
7835 return;
7836
7837 nla_put_failure:
7838 genlmsg_cancel(msg, hdr);
7839 nlmsg_free(msg);
7840}
7841
Jouni Malinena3b8b052009-03-27 21:59:49 +02007842void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7843 struct net_device *netdev, const u8 *addr,
7844 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02007845 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02007846{
7847 struct sk_buff *msg;
7848 void *hdr;
7849
Johannes Berge6d6e342009-07-01 21:26:47 +02007850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007851 if (!msg)
7852 return;
7853
7854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7855 if (!hdr) {
7856 nlmsg_free(msg);
7857 return;
7858 }
7859
David S. Miller9360ffd2012-03-29 04:41:26 -04007860 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7861 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7862 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
7863 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
7864 (key_id != -1 &&
7865 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
7866 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
7867 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02007868
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007869 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007870
Johannes Berg463d0182009-07-14 00:33:35 +02007871 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7872 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02007873 return;
7874
7875 nla_put_failure:
7876 genlmsg_cancel(msg, hdr);
7877 nlmsg_free(msg);
7878}
7879
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007880void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7881 struct ieee80211_channel *channel_before,
7882 struct ieee80211_channel *channel_after)
7883{
7884 struct sk_buff *msg;
7885 void *hdr;
7886 struct nlattr *nl_freq;
7887
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007888 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007889 if (!msg)
7890 return;
7891
7892 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7893 if (!hdr) {
7894 nlmsg_free(msg);
7895 return;
7896 }
7897
7898 /*
7899 * Since we are applying the beacon hint to a wiphy we know its
7900 * wiphy_idx is valid
7901 */
David S. Miller9360ffd2012-03-29 04:41:26 -04007902 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7903 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007904
7905 /* Before */
7906 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7907 if (!nl_freq)
7908 goto nla_put_failure;
7909 if (nl80211_msg_put_channel(msg, channel_before))
7910 goto nla_put_failure;
7911 nla_nest_end(msg, nl_freq);
7912
7913 /* After */
7914 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7915 if (!nl_freq)
7916 goto nla_put_failure;
7917 if (nl80211_msg_put_channel(msg, channel_after))
7918 goto nla_put_failure;
7919 nla_nest_end(msg, nl_freq);
7920
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007921 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007922
Johannes Berg463d0182009-07-14 00:33:35 +02007923 rcu_read_lock();
7924 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7925 GFP_ATOMIC);
7926 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04007927
7928 return;
7929
7930nla_put_failure:
7931 genlmsg_cancel(msg, hdr);
7932 nlmsg_free(msg);
7933}
7934
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007935static void nl80211_send_remain_on_chan_event(
7936 int cmd, struct cfg80211_registered_device *rdev,
7937 struct net_device *netdev, u64 cookie,
7938 struct ieee80211_channel *chan,
7939 enum nl80211_channel_type channel_type,
7940 unsigned int duration, gfp_t gfp)
7941{
7942 struct sk_buff *msg;
7943 void *hdr;
7944
7945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7946 if (!msg)
7947 return;
7948
7949 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7950 if (!hdr) {
7951 nlmsg_free(msg);
7952 return;
7953 }
7954
David S. Miller9360ffd2012-03-29 04:41:26 -04007955 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7957 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
7958 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
7959 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7960 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007961
David S. Miller9360ffd2012-03-29 04:41:26 -04007962 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
7963 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
7964 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007965
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007966 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007967
7968 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7969 nl80211_mlme_mcgrp.id, gfp);
7970 return;
7971
7972 nla_put_failure:
7973 genlmsg_cancel(msg, hdr);
7974 nlmsg_free(msg);
7975}
7976
7977void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7978 struct net_device *netdev, u64 cookie,
7979 struct ieee80211_channel *chan,
7980 enum nl80211_channel_type channel_type,
7981 unsigned int duration, gfp_t gfp)
7982{
7983 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7984 rdev, netdev, cookie, chan,
7985 channel_type, duration, gfp);
7986}
7987
7988void nl80211_send_remain_on_channel_cancel(
7989 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7990 u64 cookie, struct ieee80211_channel *chan,
7991 enum nl80211_channel_type channel_type, gfp_t gfp)
7992{
7993 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7994 rdev, netdev, cookie, chan,
7995 channel_type, 0, gfp);
7996}
7997
Johannes Berg98b62182009-12-23 13:15:44 +01007998void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7999 struct net_device *dev, const u8 *mac_addr,
8000 struct station_info *sinfo, gfp_t gfp)
8001{
8002 struct sk_buff *msg;
8003
8004 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8005 if (!msg)
8006 return;
8007
John W. Linville66266b32012-03-15 13:25:41 -04008008 if (nl80211_send_station(msg, 0, 0, 0,
8009 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008010 nlmsg_free(msg);
8011 return;
8012 }
8013
8014 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8015 nl80211_mlme_mcgrp.id, gfp);
8016}
8017
Jouni Malinenec15e682011-03-23 15:29:52 +02008018void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8019 struct net_device *dev, const u8 *mac_addr,
8020 gfp_t gfp)
8021{
8022 struct sk_buff *msg;
8023 void *hdr;
8024
8025 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8026 if (!msg)
8027 return;
8028
8029 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8030 if (!hdr) {
8031 nlmsg_free(msg);
8032 return;
8033 }
8034
David S. Miller9360ffd2012-03-29 04:41:26 -04008035 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8036 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8037 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008038
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008039 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008040
8041 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8042 nl80211_mlme_mcgrp.id, gfp);
8043 return;
8044
8045 nla_put_failure:
8046 genlmsg_cancel(msg, hdr);
8047 nlmsg_free(msg);
8048}
8049
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008050static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8051 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008052{
8053 struct wireless_dev *wdev = dev->ieee80211_ptr;
8054 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8055 struct sk_buff *msg;
8056 void *hdr;
8057 int err;
8058 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
8059
8060 if (!nlpid)
8061 return false;
8062
8063 msg = nlmsg_new(100, gfp);
8064 if (!msg)
8065 return true;
8066
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008067 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008068 if (!hdr) {
8069 nlmsg_free(msg);
8070 return true;
8071 }
8072
David S. Miller9360ffd2012-03-29 04:41:26 -04008073 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8074 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8075 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8076 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008077
8078 err = genlmsg_end(msg, hdr);
8079 if (err < 0) {
8080 nlmsg_free(msg);
8081 return true;
8082 }
8083
8084 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8085 return true;
8086
8087 nla_put_failure:
8088 genlmsg_cancel(msg, hdr);
8089 nlmsg_free(msg);
8090 return true;
8091}
8092
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008093bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8094{
8095 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8096 addr, gfp);
8097}
8098
8099bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8100 const u8 *addr, gfp_t gfp)
8101{
8102 return __nl80211_unexpected_frame(dev,
8103 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8104 addr, gfp);
8105}
8106
Johannes Berg2e161f72010-08-12 15:38:38 +02008107int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
8108 struct net_device *netdev, u32 nlpid,
Johannes Berg804483e2012-03-05 22:18:41 +01008109 int freq, int sig_dbm,
8110 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008111{
8112 struct sk_buff *msg;
8113 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008114
8115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8116 if (!msg)
8117 return -ENOMEM;
8118
Johannes Berg2e161f72010-08-12 15:38:38 +02008119 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008120 if (!hdr) {
8121 nlmsg_free(msg);
8122 return -ENOMEM;
8123 }
8124
David S. Miller9360ffd2012-03-29 04:41:26 -04008125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8126 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8127 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8128 (sig_dbm &&
8129 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8130 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8131 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008132
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008133 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008134
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008135 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008136
8137 nla_put_failure:
8138 genlmsg_cancel(msg, hdr);
8139 nlmsg_free(msg);
8140 return -ENOBUFS;
8141}
8142
Johannes Berg2e161f72010-08-12 15:38:38 +02008143void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
8144 struct net_device *netdev, u64 cookie,
8145 const u8 *buf, size_t len, bool ack,
8146 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008147{
8148 struct sk_buff *msg;
8149 void *hdr;
8150
8151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8152 if (!msg)
8153 return;
8154
Johannes Berg2e161f72010-08-12 15:38:38 +02008155 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008156 if (!hdr) {
8157 nlmsg_free(msg);
8158 return;
8159 }
8160
David S. Miller9360ffd2012-03-29 04:41:26 -04008161 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8163 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8164 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8165 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8166 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008167
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008168 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008169
8170 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8171 return;
8172
8173 nla_put_failure:
8174 genlmsg_cancel(msg, hdr);
8175 nlmsg_free(msg);
8176}
8177
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008178void
8179nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8180 struct net_device *netdev,
8181 enum nl80211_cqm_rssi_threshold_event rssi_event,
8182 gfp_t gfp)
8183{
8184 struct sk_buff *msg;
8185 struct nlattr *pinfoattr;
8186 void *hdr;
8187
8188 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8189 if (!msg)
8190 return;
8191
8192 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8193 if (!hdr) {
8194 nlmsg_free(msg);
8195 return;
8196 }
8197
David S. Miller9360ffd2012-03-29 04:41:26 -04008198 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8199 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8200 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008201
8202 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8203 if (!pinfoattr)
8204 goto nla_put_failure;
8205
David S. Miller9360ffd2012-03-29 04:41:26 -04008206 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8207 rssi_event))
8208 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008209
8210 nla_nest_end(msg, pinfoattr);
8211
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008212 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008213
8214 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8215 nl80211_mlme_mcgrp.id, gfp);
8216 return;
8217
8218 nla_put_failure:
8219 genlmsg_cancel(msg, hdr);
8220 nlmsg_free(msg);
8221}
8222
Johannes Berge5497d72011-07-05 16:35:40 +02008223void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8224 struct net_device *netdev, const u8 *bssid,
8225 const u8 *replay_ctr, gfp_t gfp)
8226{
8227 struct sk_buff *msg;
8228 struct nlattr *rekey_attr;
8229 void *hdr;
8230
8231 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8232 if (!msg)
8233 return;
8234
8235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8236 if (!hdr) {
8237 nlmsg_free(msg);
8238 return;
8239 }
8240
David S. Miller9360ffd2012-03-29 04:41:26 -04008241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8242 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8243 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8244 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008245
8246 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8247 if (!rekey_attr)
8248 goto nla_put_failure;
8249
David S. Miller9360ffd2012-03-29 04:41:26 -04008250 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8251 NL80211_REPLAY_CTR_LEN, replay_ctr))
8252 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008253
8254 nla_nest_end(msg, rekey_attr);
8255
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008256 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008257
8258 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8259 nl80211_mlme_mcgrp.id, gfp);
8260 return;
8261
8262 nla_put_failure:
8263 genlmsg_cancel(msg, hdr);
8264 nlmsg_free(msg);
8265}
8266
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008267void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8268 struct net_device *netdev, int index,
8269 const u8 *bssid, bool preauth, gfp_t gfp)
8270{
8271 struct sk_buff *msg;
8272 struct nlattr *attr;
8273 void *hdr;
8274
8275 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8276 if (!msg)
8277 return;
8278
8279 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8280 if (!hdr) {
8281 nlmsg_free(msg);
8282 return;
8283 }
8284
David S. Miller9360ffd2012-03-29 04:41:26 -04008285 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8286 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8287 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008288
8289 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8290 if (!attr)
8291 goto nla_put_failure;
8292
David S. Miller9360ffd2012-03-29 04:41:26 -04008293 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8294 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8295 (preauth &&
8296 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8297 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008298
8299 nla_nest_end(msg, attr);
8300
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008301 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008302
8303 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8304 nl80211_mlme_mcgrp.id, gfp);
8305 return;
8306
8307 nla_put_failure:
8308 genlmsg_cancel(msg, hdr);
8309 nlmsg_free(msg);
8310}
8311
Thomas Pedersen53145262012-04-06 13:35:47 -07008312void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8313 struct net_device *netdev, int freq,
8314 enum nl80211_channel_type type, gfp_t gfp)
8315{
8316 struct sk_buff *msg;
8317 void *hdr;
8318
8319 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8320 if (!msg)
8321 return;
8322
8323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8324 if (!hdr) {
8325 nlmsg_free(msg);
8326 return;
8327 }
8328
John W. Linville7eab0f62012-04-12 14:25:14 -04008329 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8330 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8331 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8332 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008333
8334 genlmsg_end(msg, hdr);
8335
8336 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8337 nl80211_mlme_mcgrp.id, gfp);
8338 return;
8339
8340 nla_put_failure:
8341 genlmsg_cancel(msg, hdr);
8342 nlmsg_free(msg);
8343}
8344
Johannes Bergc063dbf2010-11-24 08:10:05 +01008345void
8346nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8347 struct net_device *netdev, const u8 *peer,
8348 u32 num_packets, gfp_t gfp)
8349{
8350 struct sk_buff *msg;
8351 struct nlattr *pinfoattr;
8352 void *hdr;
8353
8354 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8355 if (!msg)
8356 return;
8357
8358 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8359 if (!hdr) {
8360 nlmsg_free(msg);
8361 return;
8362 }
8363
David S. Miller9360ffd2012-03-29 04:41:26 -04008364 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8365 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8366 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8367 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008368
8369 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8370 if (!pinfoattr)
8371 goto nla_put_failure;
8372
David S. Miller9360ffd2012-03-29 04:41:26 -04008373 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8374 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008375
8376 nla_nest_end(msg, pinfoattr);
8377
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008378 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008379
8380 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8381 nl80211_mlme_mcgrp.id, gfp);
8382 return;
8383
8384 nla_put_failure:
8385 genlmsg_cancel(msg, hdr);
8386 nlmsg_free(msg);
8387}
8388
Johannes Berg7f6cf312011-11-04 11:18:15 +01008389void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8390 u64 cookie, bool acked, gfp_t gfp)
8391{
8392 struct wireless_dev *wdev = dev->ieee80211_ptr;
8393 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8394 struct sk_buff *msg;
8395 void *hdr;
8396 int err;
8397
8398 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8399 if (!msg)
8400 return;
8401
8402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8403 if (!hdr) {
8404 nlmsg_free(msg);
8405 return;
8406 }
8407
David S. Miller9360ffd2012-03-29 04:41:26 -04008408 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8409 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8410 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8411 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8412 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8413 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008414
8415 err = genlmsg_end(msg, hdr);
8416 if (err < 0) {
8417 nlmsg_free(msg);
8418 return;
8419 }
8420
8421 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8422 nl80211_mlme_mcgrp.id, gfp);
8423 return;
8424
8425 nla_put_failure:
8426 genlmsg_cancel(msg, hdr);
8427 nlmsg_free(msg);
8428}
8429EXPORT_SYMBOL(cfg80211_probe_status);
8430
Johannes Berg5e7602302011-11-04 11:18:17 +01008431void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8432 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008433 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008434{
8435 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8436 struct sk_buff *msg;
8437 void *hdr;
8438 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
8439
8440 if (!nlpid)
8441 return;
8442
8443 msg = nlmsg_new(len + 100, gfp);
8444 if (!msg)
8445 return;
8446
8447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8448 if (!hdr) {
8449 nlmsg_free(msg);
8450 return;
8451 }
8452
David S. Miller9360ffd2012-03-29 04:41:26 -04008453 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8454 (freq &&
8455 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8456 (sig_dbm &&
8457 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8458 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8459 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008460
8461 genlmsg_end(msg, hdr);
8462
8463 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
8464 return;
8465
8466 nla_put_failure:
8467 genlmsg_cancel(msg, hdr);
8468 nlmsg_free(msg);
8469}
8470EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8471
Jouni Malinen026331c2010-02-15 12:53:10 +02008472static int nl80211_netlink_notify(struct notifier_block * nb,
8473 unsigned long state,
8474 void *_notify)
8475{
8476 struct netlink_notify *notify = _notify;
8477 struct cfg80211_registered_device *rdev;
8478 struct wireless_dev *wdev;
8479
8480 if (state != NETLINK_URELEASE)
8481 return NOTIFY_DONE;
8482
8483 rcu_read_lock();
8484
Johannes Berg5e7602302011-11-04 11:18:17 +01008485 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Jouni Malinen026331c2010-02-15 12:53:10 +02008486 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
Johannes Berg2e161f72010-08-12 15:38:38 +02008487 cfg80211_mlme_unregister_socket(wdev, notify->pid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008488 if (rdev->ap_beacons_nlpid == notify->pid)
8489 rdev->ap_beacons_nlpid = 0;
8490 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008491
8492 rcu_read_unlock();
8493
8494 return NOTIFY_DONE;
8495}
8496
8497static struct notifier_block nl80211_netlink_notifier = {
8498 .notifier_call = nl80211_netlink_notify,
8499};
8500
Johannes Berg55682962007-09-20 13:09:35 -04008501/* initialisation/exit functions */
8502
8503int nl80211_init(void)
8504{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008505 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008506
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008507 err = genl_register_family_with_ops(&nl80211_fam,
8508 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008509 if (err)
8510 return err;
8511
Johannes Berg55682962007-09-20 13:09:35 -04008512 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8513 if (err)
8514 goto err_out;
8515
Johannes Berg2a519312009-02-10 21:25:55 +01008516 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8517 if (err)
8518 goto err_out;
8519
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008520 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8521 if (err)
8522 goto err_out;
8523
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008524 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8525 if (err)
8526 goto err_out;
8527
Johannes Bergaff89a92009-07-01 21:26:51 +02008528#ifdef CONFIG_NL80211_TESTMODE
8529 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8530 if (err)
8531 goto err_out;
8532#endif
8533
Jouni Malinen026331c2010-02-15 12:53:10 +02008534 err = netlink_register_notifier(&nl80211_netlink_notifier);
8535 if (err)
8536 goto err_out;
8537
Johannes Berg55682962007-09-20 13:09:35 -04008538 return 0;
8539 err_out:
8540 genl_unregister_family(&nl80211_fam);
8541 return err;
8542}
8543
8544void nl80211_exit(void)
8545{
Jouni Malinen026331c2010-02-15 12:53:10 +02008546 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008547 genl_unregister_family(&nl80211_fam);
8548}