blob: aee252d65b8f7ff0e06e8569c23c8c127d5fab13 [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 int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
27 struct genl_info *info,
28 struct cfg80211_crypto_settings *settings,
29 int cipher_limit);
30
Johannes Berg4c476992010-10-04 21:36:35 +020031static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
32 struct genl_info *info);
33static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35
Johannes Berg55682962007-09-20 13:09:35 -040036/* the netlink family */
37static struct genl_family nl80211_fam = {
38 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
39 .name = "nl80211", /* have users key off the name instead */
40 .hdrsize = 0, /* no private header */
41 .version = 1, /* no particular meaning now */
42 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020043 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020044 .pre_doit = nl80211_pre_doit,
45 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040046};
47
Johannes Berg89a54e42012-06-15 14:33:17 +020048/* returns ERR_PTR values */
49static struct wireless_dev *
50__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040051{
Johannes Berg89a54e42012-06-15 14:33:17 +020052 struct cfg80211_registered_device *rdev;
53 struct wireless_dev *result = NULL;
54 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
55 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
56 u64 wdev_id;
57 int wiphy_idx = -1;
58 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040059
Johannes Berg89a54e42012-06-15 14:33:17 +020060 assert_cfg80211_lock();
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg89a54e42012-06-15 14:33:17 +020062 if (!have_ifidx && !have_wdev_id)
63 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040064
Johannes Berg89a54e42012-06-15 14:33:17 +020065 if (have_ifidx)
66 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
67 if (have_wdev_id) {
68 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
69 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040070 }
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
73 struct wireless_dev *wdev;
74
75 if (wiphy_net(&rdev->wiphy) != netns)
76 continue;
77
78 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
79 continue;
80
81 mutex_lock(&rdev->devlist_mtx);
82 list_for_each_entry(wdev, &rdev->wdev_list, list) {
83 if (have_ifidx && wdev->netdev &&
84 wdev->netdev->ifindex == ifidx) {
85 result = wdev;
86 break;
87 }
88 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
89 result = wdev;
90 break;
91 }
92 }
93 mutex_unlock(&rdev->devlist_mtx);
94
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
110 assert_cfg80211_lock();
111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
129 mutex_lock(&tmp->devlist_mtx);
130 list_for_each_entry(wdev, &tmp->wdev_list, list) {
131 if (wdev->identifier != (u32)wdev_id)
132 continue;
133 found = true;
134 break;
135 }
136 mutex_unlock(&tmp->devlist_mtx);
137
138 if (!found)
139 tmp = NULL;
140
141 if (rdev && tmp != rdev)
142 return ERR_PTR(-EINVAL);
143 rdev = tmp;
144 }
145 }
146
Johannes Berg878d9ec2012-06-15 14:18:32 +0200147 if (attrs[NL80211_ATTR_IFINDEX]) {
148 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200149 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200150 if (netdev) {
151 if (netdev->ieee80211_ptr)
152 tmp = wiphy_to_dev(
153 netdev->ieee80211_ptr->wiphy);
154 else
155 tmp = NULL;
156
157 dev_put(netdev);
158
159 /* not wireless device -- return error */
160 if (!tmp)
161 return ERR_PTR(-EINVAL);
162
163 /* mismatch -- return error */
164 if (rdev && tmp != rdev)
165 return ERR_PTR(-EINVAL);
166
167 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200168 }
Johannes Berga9455402012-06-15 13:32:49 +0200169 }
170
Johannes Berg4f7eff12012-06-15 14:14:22 +0200171 if (!rdev)
172 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200173
Johannes Berg4f7eff12012-06-15 14:14:22 +0200174 if (netns != wiphy_net(&rdev->wiphy))
175 return ERR_PTR(-ENODEV);
176
177 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200178}
179
180/*
181 * This function returns a pointer to the driver
182 * that the genl_info item that is passed refers to.
183 * If successful, it returns non-NULL and also locks
184 * the driver's mutex!
185 *
186 * This means that you need to call cfg80211_unlock_rdev()
187 * before being allowed to acquire &cfg80211_mutex!
188 *
189 * This is necessary because we need to lock the global
190 * mutex to get an item off the list safely, and then
191 * we lock the rdev mutex so it doesn't go away under us.
192 *
193 * We don't want to keep cfg80211_mutex locked
194 * for all the time in order to allow requests on
195 * other interfaces to go through at the same time.
196 *
197 * The result of this can be a PTR_ERR and hence must
198 * be checked with IS_ERR() for errors.
199 */
200static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200201cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200202{
203 struct cfg80211_registered_device *rdev;
204
205 mutex_lock(&cfg80211_mutex);
Johannes Berg878d9ec2012-06-15 14:18:32 +0200206 rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200207
208 /* if it is not an error we grab the lock on
209 * it to assure it won't be going away while
210 * we operate on it */
211 if (!IS_ERR(rdev))
212 mutex_lock(&rdev->mtx);
213
214 mutex_unlock(&cfg80211_mutex);
215
216 return rdev;
217}
218
Johannes Berg55682962007-09-20 13:09:35 -0400219/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000220static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400221 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
222 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700223 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200224 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200225 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530226 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200227 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
228 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
229 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
230 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100231 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400232
233 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
235 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100236
Eliad Pellere007b852011-11-24 18:13:56 +0200237 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
238 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100239
Johannes Bergb9454e82009-07-08 13:29:08 +0200240 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100241 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
242 .len = WLAN_MAX_KEY_LEN },
243 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
244 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
245 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200246 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200247 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100248
249 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
250 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
251 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
253 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100255 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
257 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
258 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
259 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100260 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100261 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200262 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800264 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100265 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700267 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
268 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
269
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300270 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200273 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
274 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100275 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300276
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800277 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700278 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700279
Johannes Berg6c739412011-11-03 09:27:01 +0100280 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200281
282 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
283 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
284 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100285 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
286 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200287
288 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_SSID_LEN },
290 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
291 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200292 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300293 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300294 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300295 [NL80211_ATTR_STA_FLAGS2] = {
296 .len = sizeof(struct nl80211_sta_flag_update),
297 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300298 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200301 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
302 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
303 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200304 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100305 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100306 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
307 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100308 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
309 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200310 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200311 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
313 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200314 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200315 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300316 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200317 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200320 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900321 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
322 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100323 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100324 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100325 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200326 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700327 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300328 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200329 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200330 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300331 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300332 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
334 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530336 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300337 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530338 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300339 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400360};
361
Johannes Berge31b8212010-10-05 19:39:30 +0200362/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000363static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200364 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200365 [NL80211_KEY_IDX] = { .type = NLA_U8 },
366 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200367 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200368 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
369 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200370 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100371 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
372};
373
374/* policy for the key default flags */
375static const struct nla_policy
376nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
377 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
378 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200379};
380
Johannes Bergff1b6e62011-05-04 15:37:28 +0200381/* policy for WoWLAN attributes */
382static const struct nla_policy
383nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
384 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
385 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-07-13 10:48:55 +0200388 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
389 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
390 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
391 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200392};
393
Johannes Berge5497d72011-07-05 16:35:40 +0200394/* policy for GTK rekey offload attributes */
395static const struct nla_policy
396nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
397 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
398 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
399 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
400};
401
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300402static const struct nla_policy
403nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200404 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300405 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700406 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300407};
408
Holger Schuriga0438972009-11-11 11:30:02 +0100409/* ifidx get helper */
410static int nl80211_get_ifidx(struct netlink_callback *cb)
411{
412 int res;
413
414 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
415 nl80211_fam.attrbuf, nl80211_fam.maxattr,
416 nl80211_policy);
417 if (res)
418 return res;
419
420 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
421 return -EINVAL;
422
423 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
424 if (!res)
425 return -EINVAL;
426 return res;
427}
428
Johannes Berg67748892010-10-04 21:14:06 +0200429static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
430 struct netlink_callback *cb,
431 struct cfg80211_registered_device **rdev,
432 struct net_device **dev)
433{
434 int ifidx = cb->args[0];
435 int err;
436
437 if (!ifidx)
438 ifidx = nl80211_get_ifidx(cb);
439 if (ifidx < 0)
440 return ifidx;
441
442 cb->args[0] = ifidx;
443
444 rtnl_lock();
445
446 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
447 if (!*dev) {
448 err = -ENODEV;
449 goto out_rtnl;
450 }
451
452 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100453 if (IS_ERR(*rdev)) {
454 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200455 goto out_rtnl;
456 }
457
458 return 0;
459 out_rtnl:
460 rtnl_unlock();
461 return err;
462}
463
464static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
465{
466 cfg80211_unlock_rdev(rdev);
467 rtnl_unlock();
468}
469
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100470/* IE validation */
471static bool is_valid_ie_attr(const struct nlattr *attr)
472{
473 const u8 *pos;
474 int len;
475
476 if (!attr)
477 return true;
478
479 pos = nla_data(attr);
480 len = nla_len(attr);
481
482 while (len) {
483 u8 elemlen;
484
485 if (len < 2)
486 return false;
487 len -= 2;
488
489 elemlen = pos[1];
490 if (elemlen > len)
491 return false;
492
493 len -= elemlen;
494 pos += 2 + elemlen;
495 }
496
497 return true;
498}
499
Johannes Berg55682962007-09-20 13:09:35 -0400500/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000501static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400502 int flags, u8 cmd)
503{
504 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000505 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400506}
507
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400508static int nl80211_msg_put_channel(struct sk_buff *msg,
509 struct ieee80211_channel *chan)
510{
David S. Miller9360ffd2012-03-29 04:41:26 -0400511 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
512 chan->center_freq))
513 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400514
David S. Miller9360ffd2012-03-29 04:41:26 -0400515 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
516 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
517 goto nla_put_failure;
518 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
519 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
520 goto nla_put_failure;
521 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
522 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
523 goto nla_put_failure;
524 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
525 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
526 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400527
David S. Miller9360ffd2012-03-29 04:41:26 -0400528 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
529 DBM_TO_MBM(chan->max_power)))
530 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400531
532 return 0;
533
534 nla_put_failure:
535 return -ENOBUFS;
536}
537
Johannes Berg55682962007-09-20 13:09:35 -0400538/* netlink command implementations */
539
Johannes Bergb9454e82009-07-08 13:29:08 +0200540struct key_parse {
541 struct key_params p;
542 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200543 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200544 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100545 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200546};
547
548static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
549{
550 struct nlattr *tb[NL80211_KEY_MAX + 1];
551 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
552 nl80211_key_policy);
553 if (err)
554 return err;
555
556 k->def = !!tb[NL80211_KEY_DEFAULT];
557 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
558
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100559 if (k->def) {
560 k->def_uni = true;
561 k->def_multi = true;
562 }
563 if (k->defmgmt)
564 k->def_multi = true;
565
Johannes Bergb9454e82009-07-08 13:29:08 +0200566 if (tb[NL80211_KEY_IDX])
567 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
568
569 if (tb[NL80211_KEY_DATA]) {
570 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
571 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
572 }
573
574 if (tb[NL80211_KEY_SEQ]) {
575 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
576 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
577 }
578
579 if (tb[NL80211_KEY_CIPHER])
580 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
581
Johannes Berge31b8212010-10-05 19:39:30 +0200582 if (tb[NL80211_KEY_TYPE]) {
583 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
584 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
585 return -EINVAL;
586 }
587
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100588 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
589 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100590 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
591 tb[NL80211_KEY_DEFAULT_TYPES],
592 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100593 if (err)
594 return err;
595
596 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
597 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
598 }
599
Johannes Bergb9454e82009-07-08 13:29:08 +0200600 return 0;
601}
602
603static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
604{
605 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
606 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
607 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
608 }
609
610 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
611 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
612 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
613 }
614
615 if (info->attrs[NL80211_ATTR_KEY_IDX])
616 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
617
618 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
619 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
620
621 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
622 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
623
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100624 if (k->def) {
625 k->def_uni = true;
626 k->def_multi = true;
627 }
628 if (k->defmgmt)
629 k->def_multi = true;
630
Johannes Berge31b8212010-10-05 19:39:30 +0200631 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
632 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
633 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
634 return -EINVAL;
635 }
636
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100637 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
638 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
639 int err = nla_parse_nested(
640 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
641 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
642 nl80211_key_default_policy);
643 if (err)
644 return err;
645
646 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
647 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
648 }
649
Johannes Bergb9454e82009-07-08 13:29:08 +0200650 return 0;
651}
652
653static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
654{
655 int err;
656
657 memset(k, 0, sizeof(*k));
658 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200659 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200660
661 if (info->attrs[NL80211_ATTR_KEY])
662 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
663 else
664 err = nl80211_parse_key_old(info, k);
665
666 if (err)
667 return err;
668
669 if (k->def && k->defmgmt)
670 return -EINVAL;
671
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100672 if (k->defmgmt) {
673 if (k->def_uni || !k->def_multi)
674 return -EINVAL;
675 }
676
Johannes Bergb9454e82009-07-08 13:29:08 +0200677 if (k->idx != -1) {
678 if (k->defmgmt) {
679 if (k->idx < 4 || k->idx > 5)
680 return -EINVAL;
681 } else if (k->def) {
682 if (k->idx < 0 || k->idx > 3)
683 return -EINVAL;
684 } else {
685 if (k->idx < 0 || k->idx > 5)
686 return -EINVAL;
687 }
688 }
689
690 return 0;
691}
692
Johannes Bergfffd0932009-07-08 14:22:54 +0200693static struct cfg80211_cached_keys *
694nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
695 struct nlattr *keys)
696{
697 struct key_parse parse;
698 struct nlattr *key;
699 struct cfg80211_cached_keys *result;
700 int rem, err, def = 0;
701
702 result = kzalloc(sizeof(*result), GFP_KERNEL);
703 if (!result)
704 return ERR_PTR(-ENOMEM);
705
706 result->def = -1;
707 result->defmgmt = -1;
708
709 nla_for_each_nested(key, keys, rem) {
710 memset(&parse, 0, sizeof(parse));
711 parse.idx = -1;
712
713 err = nl80211_parse_key_new(key, &parse);
714 if (err)
715 goto error;
716 err = -EINVAL;
717 if (!parse.p.key)
718 goto error;
719 if (parse.idx < 0 || parse.idx > 4)
720 goto error;
721 if (parse.def) {
722 if (def)
723 goto error;
724 def = 1;
725 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100726 if (!parse.def_uni || !parse.def_multi)
727 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200728 } else if (parse.defmgmt)
729 goto error;
730 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200731 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200732 if (err)
733 goto error;
734 result->params[parse.idx].cipher = parse.p.cipher;
735 result->params[parse.idx].key_len = parse.p.key_len;
736 result->params[parse.idx].key = result->data[parse.idx];
737 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
738 }
739
740 return result;
741 error:
742 kfree(result);
743 return ERR_PTR(err);
744}
745
746static int nl80211_key_allowed(struct wireless_dev *wdev)
747{
748 ASSERT_WDEV_LOCK(wdev);
749
Johannes Bergfffd0932009-07-08 14:22:54 +0200750 switch (wdev->iftype) {
751 case NL80211_IFTYPE_AP:
752 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200753 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700754 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200755 break;
756 case NL80211_IFTYPE_ADHOC:
757 if (!wdev->current_bss)
758 return -ENOLINK;
759 break;
760 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200761 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200762 if (wdev->sme_state != CFG80211_SME_CONNECTED)
763 return -ENOLINK;
764 break;
765 default:
766 return -EINVAL;
767 }
768
769 return 0;
770}
771
Johannes Berg7527a782011-05-13 10:58:57 +0200772static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
773{
774 struct nlattr *nl_modes = nla_nest_start(msg, attr);
775 int i;
776
777 if (!nl_modes)
778 goto nla_put_failure;
779
780 i = 0;
781 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400782 if ((ifmodes & 1) && nla_put_flag(msg, i))
783 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200784 ifmodes >>= 1;
785 i++;
786 }
787
788 nla_nest_end(msg, nl_modes);
789 return 0;
790
791nla_put_failure:
792 return -ENOBUFS;
793}
794
795static int nl80211_put_iface_combinations(struct wiphy *wiphy,
796 struct sk_buff *msg)
797{
798 struct nlattr *nl_combis;
799 int i, j;
800
801 nl_combis = nla_nest_start(msg,
802 NL80211_ATTR_INTERFACE_COMBINATIONS);
803 if (!nl_combis)
804 goto nla_put_failure;
805
806 for (i = 0; i < wiphy->n_iface_combinations; i++) {
807 const struct ieee80211_iface_combination *c;
808 struct nlattr *nl_combi, *nl_limits;
809
810 c = &wiphy->iface_combinations[i];
811
812 nl_combi = nla_nest_start(msg, i + 1);
813 if (!nl_combi)
814 goto nla_put_failure;
815
816 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
817 if (!nl_limits)
818 goto nla_put_failure;
819
820 for (j = 0; j < c->n_limits; j++) {
821 struct nlattr *nl_limit;
822
823 nl_limit = nla_nest_start(msg, j + 1);
824 if (!nl_limit)
825 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400826 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
827 c->limits[j].max))
828 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200829 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
830 c->limits[j].types))
831 goto nla_put_failure;
832 nla_nest_end(msg, nl_limit);
833 }
834
835 nla_nest_end(msg, nl_limits);
836
David S. Miller9360ffd2012-03-29 04:41:26 -0400837 if (c->beacon_int_infra_match &&
838 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
839 goto nla_put_failure;
840 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
841 c->num_different_channels) ||
842 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
843 c->max_interfaces))
844 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200845
846 nla_nest_end(msg, nl_combi);
847 }
848
849 nla_nest_end(msg, nl_combis);
850
851 return 0;
852nla_put_failure:
853 return -ENOBUFS;
854}
855
Eric W. Biederman15e47302012-09-07 20:12:54 +0000856static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Berg55682962007-09-20 13:09:35 -0400857 struct cfg80211_registered_device *dev)
858{
859 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100860 struct nlattr *nl_bands, *nl_band;
861 struct nlattr *nl_freqs, *nl_freq;
862 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100863 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100864 enum ieee80211_band band;
865 struct ieee80211_channel *chan;
866 struct ieee80211_rate *rate;
867 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200868 const struct ieee80211_txrx_stypes *mgmt_stypes =
869 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400870
Eric W. Biederman15e47302012-09-07 20:12:54 +0000871 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -0400872 if (!hdr)
873 return -1;
874
David S. Miller9360ffd2012-03-29 04:41:26 -0400875 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
876 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
877 nla_put_u32(msg, NL80211_ATTR_GENERATION,
878 cfg80211_rdev_list_generation) ||
879 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
880 dev->wiphy.retry_short) ||
881 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
882 dev->wiphy.retry_long) ||
883 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
884 dev->wiphy.frag_threshold) ||
885 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
886 dev->wiphy.rts_threshold) ||
887 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
888 dev->wiphy.coverage_class) ||
889 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
890 dev->wiphy.max_scan_ssids) ||
891 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
892 dev->wiphy.max_sched_scan_ssids) ||
893 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
894 dev->wiphy.max_scan_ie_len) ||
895 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
896 dev->wiphy.max_sched_scan_ie_len) ||
897 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
898 dev->wiphy.max_match_sets))
899 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200900
David S. Miller9360ffd2012-03-29 04:41:26 -0400901 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
902 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
903 goto nla_put_failure;
904 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
905 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
906 goto nla_put_failure;
907 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
908 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
909 goto nla_put_failure;
910 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
911 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
912 goto nla_put_failure;
913 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
914 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
915 goto nla_put_failure;
916 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
917 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
918 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200919
David S. Miller9360ffd2012-03-29 04:41:26 -0400920 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
921 sizeof(u32) * dev->wiphy.n_cipher_suites,
922 dev->wiphy.cipher_suites))
923 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100924
David S. Miller9360ffd2012-03-29 04:41:26 -0400925 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
926 dev->wiphy.max_num_pmkids))
927 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530928
David S. Miller9360ffd2012-03-29 04:41:26 -0400929 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
930 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
931 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200932
David S. Miller9360ffd2012-03-29 04:41:26 -0400933 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
934 dev->wiphy.available_antennas_tx) ||
935 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
936 dev->wiphy.available_antennas_rx))
937 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100938
David S. Miller9360ffd2012-03-29 04:41:26 -0400939 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
940 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
941 dev->wiphy.probe_resp_offload))
942 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200943
Bruno Randolf7f531e02010-12-16 11:30:22 +0900944 if ((dev->wiphy.available_antennas_tx ||
945 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900946 u32 tx_ant = 0, rx_ant = 0;
947 int res;
948 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
949 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400950 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
951 tx_ant) ||
952 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
953 rx_ant))
954 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900955 }
956 }
957
Johannes Berg7527a782011-05-13 10:58:57 +0200958 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
959 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700960 goto nla_put_failure;
961
Johannes Bergee688b002008-01-24 19:38:39 +0100962 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
963 if (!nl_bands)
964 goto nla_put_failure;
965
966 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
967 if (!dev->wiphy.bands[band])
968 continue;
969
970 nl_band = nla_nest_start(msg, band);
971 if (!nl_band)
972 goto nla_put_failure;
973
Johannes Bergd51626d2008-10-09 12:20:13 +0200974 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400975 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
976 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
977 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
978 &dev->wiphy.bands[band]->ht_cap.mcs) ||
979 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
980 dev->wiphy.bands[band]->ht_cap.cap) ||
981 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
982 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
983 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
984 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
985 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200986
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000987 /* add VHT info */
988 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
989 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
990 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
991 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
992 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
993 dev->wiphy.bands[band]->vht_cap.cap)))
994 goto nla_put_failure;
995
Johannes Bergee688b002008-01-24 19:38:39 +0100996 /* add frequencies */
997 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
998 if (!nl_freqs)
999 goto nla_put_failure;
1000
1001 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1002 nl_freq = nla_nest_start(msg, i);
1003 if (!nl_freq)
1004 goto nla_put_failure;
1005
1006 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +01001007
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001008 if (nl80211_msg_put_channel(msg, chan))
1009 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001010
Johannes Bergee688b002008-01-24 19:38:39 +01001011 nla_nest_end(msg, nl_freq);
1012 }
1013
1014 nla_nest_end(msg, nl_freqs);
1015
1016 /* add bitrates */
1017 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1018 if (!nl_rates)
1019 goto nla_put_failure;
1020
1021 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1022 nl_rate = nla_nest_start(msg, i);
1023 if (!nl_rate)
1024 goto nla_put_failure;
1025
1026 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -04001027 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1028 rate->bitrate))
1029 goto nla_put_failure;
1030 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1031 nla_put_flag(msg,
1032 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1033 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001034
1035 nla_nest_end(msg, nl_rate);
1036 }
1037
1038 nla_nest_end(msg, nl_rates);
1039
1040 nla_nest_end(msg, nl_band);
1041 }
1042 nla_nest_end(msg, nl_bands);
1043
Johannes Berg8fdc6212009-03-14 09:34:01 +01001044 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1045 if (!nl_cmds)
1046 goto nla_put_failure;
1047
1048 i = 0;
1049#define CMD(op, n) \
1050 do { \
1051 if (dev->ops->op) { \
1052 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -04001053 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1054 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +01001055 } \
1056 } while (0)
1057
1058 CMD(add_virtual_intf, NEW_INTERFACE);
1059 CMD(change_virtual_intf, SET_INTERFACE);
1060 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +01001061 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001062 CMD(add_station, NEW_STATION);
1063 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001064 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001065 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001066 CMD(auth, AUTHENTICATE);
1067 CMD(assoc, ASSOCIATE);
1068 CMD(deauth, DEAUTHENTICATE);
1069 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001070 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001071 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001072 CMD(set_pmksa, SET_PMKSA);
1073 CMD(del_pmksa, DEL_PMKSA);
1074 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001075 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1076 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001077 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001078 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001079 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001080 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001081 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001082 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1083 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001084 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001085 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001086 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001087 i++;
1088 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1089 goto nla_put_failure;
1090 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001091 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001092 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1093 CMD(tdls_mgmt, TDLS_MGMT);
1094 CMD(tdls_oper, TDLS_OPER);
1095 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001096 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1097 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001098 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001099 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001100 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1101 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001102 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1103 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001104 }
Johannes Berg98104fde2012-06-16 00:19:54 +02001105 CMD(start_p2p_device, START_P2P_DEVICE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001106
Kalle Valo4745fc02011-11-17 19:06:10 +02001107#ifdef CONFIG_NL80211_TESTMODE
1108 CMD(testmode_cmd, TESTMODE);
1109#endif
1110
Johannes Berg8fdc6212009-03-14 09:34:01 +01001111#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001112
Johannes Berg6829c872009-07-02 09:13:27 +02001113 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001114 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001115 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1116 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001117 }
1118
Johannes Berg6829c872009-07-02 09:13:27 +02001119 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001120 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001121 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1122 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001123 }
1124
Johannes Berg8fdc6212009-03-14 09:34:01 +01001125 nla_nest_end(msg, nl_cmds);
1126
Johannes Berg7c4ef712011-11-18 15:33:48 +01001127 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001128 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1129 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1130 dev->wiphy.max_remain_on_channel_duration))
1131 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001132
David S. Miller9360ffd2012-03-29 04:41:26 -04001133 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1134 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1135 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001136
Johannes Berg2e161f72010-08-12 15:38:38 +02001137 if (mgmt_stypes) {
1138 u16 stypes;
1139 struct nlattr *nl_ftypes, *nl_ifs;
1140 enum nl80211_iftype ift;
1141
1142 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1143 if (!nl_ifs)
1144 goto nla_put_failure;
1145
1146 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1147 nl_ftypes = nla_nest_start(msg, ift);
1148 if (!nl_ftypes)
1149 goto nla_put_failure;
1150 i = 0;
1151 stypes = mgmt_stypes[ift].tx;
1152 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001153 if ((stypes & 1) &&
1154 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1155 (i << 4) | IEEE80211_FTYPE_MGMT))
1156 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001157 stypes >>= 1;
1158 i++;
1159 }
1160 nla_nest_end(msg, nl_ftypes);
1161 }
1162
Johannes Berg74b70a42010-08-24 12:15:53 +02001163 nla_nest_end(msg, nl_ifs);
1164
Johannes Berg2e161f72010-08-12 15:38:38 +02001165 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1166 if (!nl_ifs)
1167 goto nla_put_failure;
1168
1169 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1170 nl_ftypes = nla_nest_start(msg, ift);
1171 if (!nl_ftypes)
1172 goto nla_put_failure;
1173 i = 0;
1174 stypes = mgmt_stypes[ift].rx;
1175 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001176 if ((stypes & 1) &&
1177 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1178 (i << 4) | IEEE80211_FTYPE_MGMT))
1179 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001180 stypes >>= 1;
1181 i++;
1182 }
1183 nla_nest_end(msg, nl_ftypes);
1184 }
1185 nla_nest_end(msg, nl_ifs);
1186 }
1187
Johannes Bergdfb89c52012-06-27 09:23:48 +02001188#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001189 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1190 struct nlattr *nl_wowlan;
1191
1192 nl_wowlan = nla_nest_start(msg,
1193 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1194 if (!nl_wowlan)
1195 goto nla_put_failure;
1196
David S. Miller9360ffd2012-03-29 04:41:26 -04001197 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1198 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1199 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1200 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1201 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1202 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1203 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1204 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1205 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1206 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1207 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1208 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1209 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1210 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1211 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1212 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1213 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001214 if (dev->wiphy.wowlan.n_patterns) {
1215 struct nl80211_wowlan_pattern_support pat = {
1216 .max_patterns = dev->wiphy.wowlan.n_patterns,
1217 .min_pattern_len =
1218 dev->wiphy.wowlan.pattern_min_len,
1219 .max_pattern_len =
1220 dev->wiphy.wowlan.pattern_max_len,
1221 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001222 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1223 sizeof(pat), &pat))
1224 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001225 }
1226
1227 nla_nest_end(msg, nl_wowlan);
1228 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001229#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001230
Johannes Berg7527a782011-05-13 10:58:57 +02001231 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1232 dev->wiphy.software_iftypes))
1233 goto nla_put_failure;
1234
1235 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1236 goto nla_put_failure;
1237
David S. Miller9360ffd2012-03-29 04:41:26 -04001238 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1239 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1240 dev->wiphy.ap_sme_capa))
1241 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001242
David S. Miller9360ffd2012-03-29 04:41:26 -04001243 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1244 dev->wiphy.features))
1245 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001246
David S. Miller9360ffd2012-03-29 04:41:26 -04001247 if (dev->wiphy.ht_capa_mod_mask &&
1248 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1249 sizeof(*dev->wiphy.ht_capa_mod_mask),
1250 dev->wiphy.ht_capa_mod_mask))
1251 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001252
Johannes Berg55682962007-09-20 13:09:35 -04001253 return genlmsg_end(msg, hdr);
1254
1255 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001256 genlmsg_cancel(msg, hdr);
1257 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001258}
1259
1260static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1261{
1262 int idx = 0;
1263 int start = cb->args[0];
1264 struct cfg80211_registered_device *dev;
1265
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001266 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001267 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001268 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1269 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001270 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001271 continue;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001272 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001273 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001274 dev) < 0) {
1275 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001276 break;
Julius Volzb4637272008-07-08 14:02:19 +02001277 }
Johannes Berg55682962007-09-20 13:09:35 -04001278 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001279 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001280
1281 cb->args[0] = idx;
1282
1283 return skb->len;
1284}
1285
1286static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1287{
1288 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001289 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001290
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001291 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001292 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001293 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001294
Eric W. Biederman15e47302012-09-07 20:12:54 +00001295 if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001296 nlmsg_free(msg);
1297 return -ENOBUFS;
1298 }
Johannes Berg55682962007-09-20 13:09:35 -04001299
Johannes Berg134e6372009-07-10 09:51:34 +00001300 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001301}
1302
Jouni Malinen31888482008-10-30 16:59:24 +02001303static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1304 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1305 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1306 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1307 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1308 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1309};
1310
1311static int parse_txq_params(struct nlattr *tb[],
1312 struct ieee80211_txq_params *txq_params)
1313{
Johannes Berga3304b02012-03-28 11:04:24 +02001314 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001315 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1316 !tb[NL80211_TXQ_ATTR_AIFS])
1317 return -EINVAL;
1318
Johannes Berga3304b02012-03-28 11:04:24 +02001319 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001320 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1321 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1322 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1323 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1324
Johannes Berga3304b02012-03-28 11:04:24 +02001325 if (txq_params->ac >= NL80211_NUM_ACS)
1326 return -EINVAL;
1327
Jouni Malinen31888482008-10-30 16:59:24 +02001328 return 0;
1329}
1330
Johannes Bergf444de02010-05-05 15:25:02 +02001331static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1332{
1333 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001334 * You can only set the channel explicitly for WDS interfaces,
1335 * all others have their channel managed via their respective
1336 * "establish a connection" command (connect, join, ...)
1337 *
1338 * For AP/GO and mesh mode, the channel can be set with the
1339 * channel userspace API, but is only stored and passed to the
1340 * low-level driver when the AP starts or the mesh is joined.
1341 * This is for backward compatibility, userspace can also give
1342 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001343 *
1344 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001345 * whatever else is going on, so they have their own special
1346 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001347 */
1348 return !wdev ||
1349 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001350 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001351 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1352 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001353}
1354
Johannes Bergcd6c6592012-05-10 21:27:18 +02001355static bool nl80211_valid_channel_type(struct genl_info *info,
1356 enum nl80211_channel_type *channel_type)
1357{
1358 enum nl80211_channel_type tmp;
1359
1360 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1361 return false;
1362
1363 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1364 if (tmp != NL80211_CHAN_NO_HT &&
1365 tmp != NL80211_CHAN_HT20 &&
1366 tmp != NL80211_CHAN_HT40PLUS &&
1367 tmp != NL80211_CHAN_HT40MINUS)
1368 return false;
1369
1370 if (channel_type)
1371 *channel_type = tmp;
1372
1373 return true;
1374}
1375
Johannes Bergf444de02010-05-05 15:25:02 +02001376static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1377 struct wireless_dev *wdev,
1378 struct genl_info *info)
1379{
Johannes Bergaa430da2012-05-16 23:50:18 +02001380 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001381 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1382 u32 freq;
1383 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001384 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1385
1386 if (wdev)
1387 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001388
1389 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1390 return -EINVAL;
1391
1392 if (!nl80211_can_set_dev_channel(wdev))
1393 return -EOPNOTSUPP;
1394
Johannes Bergcd6c6592012-05-10 21:27:18 +02001395 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1396 !nl80211_valid_channel_type(info, &channel_type))
1397 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001398
1399 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1400
1401 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001402 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001403 case NL80211_IFTYPE_AP:
1404 case NL80211_IFTYPE_P2P_GO:
1405 if (wdev->beacon_interval) {
1406 result = -EBUSY;
1407 break;
1408 }
1409 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1410 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1411 channel,
1412 channel_type)) {
1413 result = -EINVAL;
1414 break;
1415 }
1416 wdev->preset_chan = channel;
1417 wdev->preset_chantype = channel_type;
1418 result = 0;
1419 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001420 case NL80211_IFTYPE_MESH_POINT:
1421 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1422 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001423 case NL80211_IFTYPE_MONITOR:
1424 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1425 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001426 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001427 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001428 }
1429 mutex_unlock(&rdev->devlist_mtx);
1430
1431 return result;
1432}
1433
1434static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1435{
Johannes Berg4c476992010-10-04 21:36:35 +02001436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1437 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001438
Johannes Berg4c476992010-10-04 21:36:35 +02001439 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001440}
1441
Bill Jordane8347eb2010-10-01 13:54:28 -04001442static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1443{
Johannes Berg43b19952010-10-07 13:10:30 +02001444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1445 struct net_device *dev = info->user_ptr[1];
1446 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001447 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001448
1449 if (!info->attrs[NL80211_ATTR_MAC])
1450 return -EINVAL;
1451
Johannes Berg43b19952010-10-07 13:10:30 +02001452 if (netif_running(dev))
1453 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001454
Johannes Berg43b19952010-10-07 13:10:30 +02001455 if (!rdev->ops->set_wds_peer)
1456 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001457
Johannes Berg43b19952010-10-07 13:10:30 +02001458 if (wdev->iftype != NL80211_IFTYPE_WDS)
1459 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001460
1461 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001462 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001463}
1464
1465
Johannes Berg55682962007-09-20 13:09:35 -04001466static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1467{
1468 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001469 struct net_device *netdev = NULL;
1470 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001471 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001472 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001473 u32 changed;
1474 u8 retry_short = 0, retry_long = 0;
1475 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001476 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001477
Johannes Bergf444de02010-05-05 15:25:02 +02001478 /*
1479 * Try to find the wiphy and netdev. Normally this
1480 * function shouldn't need the netdev, but this is
1481 * done for backward compatibility -- previously
1482 * setting the channel was done per wiphy, but now
1483 * it is per netdev. Previous userland like hostapd
1484 * also passed a netdev to set_wiphy, so that it is
1485 * possible to let that go to the right netdev!
1486 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001487 mutex_lock(&cfg80211_mutex);
1488
Johannes Bergf444de02010-05-05 15:25:02 +02001489 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1490 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1491
1492 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1493 if (netdev && netdev->ieee80211_ptr) {
1494 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1495 mutex_lock(&rdev->mtx);
1496 } else
1497 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001498 }
1499
Johannes Bergf444de02010-05-05 15:25:02 +02001500 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001501 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1502 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001503 if (IS_ERR(rdev)) {
1504 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001505 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001506 }
1507 wdev = NULL;
1508 netdev = NULL;
1509 result = 0;
1510
1511 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001512 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001513 wdev = netdev->ieee80211_ptr;
1514 else
1515 wdev = NULL;
1516
1517 /*
1518 * end workaround code, by now the rdev is available
1519 * and locked, and wdev may or may not be NULL.
1520 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001521
1522 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001523 result = cfg80211_dev_rename(
1524 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001525
1526 mutex_unlock(&cfg80211_mutex);
1527
1528 if (result)
1529 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001530
Jouni Malinen31888482008-10-30 16:59:24 +02001531 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1532 struct ieee80211_txq_params txq_params;
1533 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1534
1535 if (!rdev->ops->set_txq_params) {
1536 result = -EOPNOTSUPP;
1537 goto bad_res;
1538 }
1539
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001540 if (!netdev) {
1541 result = -EINVAL;
1542 goto bad_res;
1543 }
1544
Johannes Berg133a3ff2011-11-03 14:50:13 +01001545 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1546 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1547 result = -EINVAL;
1548 goto bad_res;
1549 }
1550
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001551 if (!netif_running(netdev)) {
1552 result = -ENETDOWN;
1553 goto bad_res;
1554 }
1555
Jouni Malinen31888482008-10-30 16:59:24 +02001556 nla_for_each_nested(nl_txq_params,
1557 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1558 rem_txq_params) {
1559 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1560 nla_data(nl_txq_params),
1561 nla_len(nl_txq_params),
1562 txq_params_policy);
1563 result = parse_txq_params(tb, &txq_params);
1564 if (result)
1565 goto bad_res;
1566
1567 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001568 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001569 &txq_params);
1570 if (result)
1571 goto bad_res;
1572 }
1573 }
1574
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001575 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001576 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001577 if (result)
1578 goto bad_res;
1579 }
1580
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001581 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1582 enum nl80211_tx_power_setting type;
1583 int idx, mbm = 0;
1584
1585 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001586 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001587 goto bad_res;
1588 }
1589
1590 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1591 type = nla_get_u32(info->attrs[idx]);
1592
1593 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1594 (type != NL80211_TX_POWER_AUTOMATIC)) {
1595 result = -EINVAL;
1596 goto bad_res;
1597 }
1598
1599 if (type != NL80211_TX_POWER_AUTOMATIC) {
1600 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1601 mbm = nla_get_u32(info->attrs[idx]);
1602 }
1603
1604 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1605 if (result)
1606 goto bad_res;
1607 }
1608
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001609 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1610 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1611 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001612 if ((!rdev->wiphy.available_antennas_tx &&
1613 !rdev->wiphy.available_antennas_rx) ||
1614 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001615 result = -EOPNOTSUPP;
1616 goto bad_res;
1617 }
1618
1619 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1620 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1621
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001622 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001623 * available antenna masks, except for the "all" mask */
1624 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1625 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001626 result = -EINVAL;
1627 goto bad_res;
1628 }
1629
Bruno Randolf7f531e02010-12-16 11:30:22 +09001630 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1631 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001632
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001633 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1634 if (result)
1635 goto bad_res;
1636 }
1637
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001638 changed = 0;
1639
1640 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1641 retry_short = nla_get_u8(
1642 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1643 if (retry_short == 0) {
1644 result = -EINVAL;
1645 goto bad_res;
1646 }
1647 changed |= WIPHY_PARAM_RETRY_SHORT;
1648 }
1649
1650 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1651 retry_long = nla_get_u8(
1652 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1653 if (retry_long == 0) {
1654 result = -EINVAL;
1655 goto bad_res;
1656 }
1657 changed |= WIPHY_PARAM_RETRY_LONG;
1658 }
1659
1660 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1661 frag_threshold = nla_get_u32(
1662 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1663 if (frag_threshold < 256) {
1664 result = -EINVAL;
1665 goto bad_res;
1666 }
1667 if (frag_threshold != (u32) -1) {
1668 /*
1669 * Fragments (apart from the last one) are required to
1670 * have even length. Make the fragmentation code
1671 * simpler by stripping LSB should someone try to use
1672 * odd threshold value.
1673 */
1674 frag_threshold &= ~0x1;
1675 }
1676 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1677 }
1678
1679 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1680 rts_threshold = nla_get_u32(
1681 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1682 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1683 }
1684
Lukáš Turek81077e82009-12-21 22:50:47 +01001685 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1686 coverage_class = nla_get_u8(
1687 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1688 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1689 }
1690
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001691 if (changed) {
1692 u8 old_retry_short, old_retry_long;
1693 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001694 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001695
1696 if (!rdev->ops->set_wiphy_params) {
1697 result = -EOPNOTSUPP;
1698 goto bad_res;
1699 }
1700
1701 old_retry_short = rdev->wiphy.retry_short;
1702 old_retry_long = rdev->wiphy.retry_long;
1703 old_frag_threshold = rdev->wiphy.frag_threshold;
1704 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001705 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001706
1707 if (changed & WIPHY_PARAM_RETRY_SHORT)
1708 rdev->wiphy.retry_short = retry_short;
1709 if (changed & WIPHY_PARAM_RETRY_LONG)
1710 rdev->wiphy.retry_long = retry_long;
1711 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1712 rdev->wiphy.frag_threshold = frag_threshold;
1713 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1714 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001715 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1716 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001717
1718 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1719 if (result) {
1720 rdev->wiphy.retry_short = old_retry_short;
1721 rdev->wiphy.retry_long = old_retry_long;
1722 rdev->wiphy.frag_threshold = old_frag_threshold;
1723 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001724 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001725 }
1726 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001727
Johannes Berg306d6112008-12-08 12:39:04 +01001728 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001729 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001730 if (netdev)
1731 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001732 return result;
1733}
1734
Johannes Berg71bbc992012-06-15 15:30:18 +02001735static inline u64 wdev_id(struct wireless_dev *wdev)
1736{
1737 return (u64)wdev->identifier |
1738 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1739}
Johannes Berg55682962007-09-20 13:09:35 -04001740
Eric W. Biederman15e47302012-09-07 20:12:54 +00001741static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001742 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001743 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04001744{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001745 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04001746 void *hdr;
1747
Eric W. Biederman15e47302012-09-07 20:12:54 +00001748 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04001749 if (!hdr)
1750 return -1;
1751
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001752 if (dev &&
1753 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001754 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001755 goto nla_put_failure;
1756
1757 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1758 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02001759 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001760 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001761 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1762 rdev->devlist_generation ^
1763 (cfg80211_rdev_list_generation << 2)))
1764 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001765
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02001766 if (rdev->ops->get_channel) {
1767 struct ieee80211_channel *chan;
1768 enum nl80211_channel_type channel_type;
1769
1770 chan = rdev->ops->get_channel(&rdev->wiphy, wdev,
1771 &channel_type);
1772 if (chan &&
1773 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1774 chan->center_freq) ||
1775 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1776 channel_type)))
John W. Linville59ef43e2012-04-18 14:17:13 -04001777 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001778 }
1779
Johannes Berg55682962007-09-20 13:09:35 -04001780 return genlmsg_end(msg, hdr);
1781
1782 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001783 genlmsg_cancel(msg, hdr);
1784 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001785}
1786
1787static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1788{
1789 int wp_idx = 0;
1790 int if_idx = 0;
1791 int wp_start = cb->args[0];
1792 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001793 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001794 struct wireless_dev *wdev;
1795
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001796 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001797 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1798 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001799 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001800 if (wp_idx < wp_start) {
1801 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001802 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001803 }
Johannes Berg55682962007-09-20 13:09:35 -04001804 if_idx = 0;
1805
Johannes Bergf5ea9122009-08-07 16:17:38 +02001806 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02001807 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001808 if (if_idx < if_start) {
1809 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001810 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001811 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00001812 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001813 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001814 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02001815 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001816 goto out;
1817 }
1818 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001819 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001820 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001821
1822 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001823 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001824 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001825 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001826
1827 cb->args[0] = wp_idx;
1828 cb->args[1] = if_idx;
1829
1830 return skb->len;
1831}
1832
1833static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1834{
1835 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001836 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001837 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001838
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001840 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001841 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001842
Eric W. Biederman15e47302012-09-07 20:12:54 +00001843 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001844 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001845 nlmsg_free(msg);
1846 return -ENOBUFS;
1847 }
Johannes Berg55682962007-09-20 13:09:35 -04001848
Johannes Berg134e6372009-07-10 09:51:34 +00001849 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001850}
1851
Michael Wu66f7ac52008-01-31 19:48:22 +01001852static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1853 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1854 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1855 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1856 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1857 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1858};
1859
1860static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1861{
1862 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1863 int flag;
1864
1865 *mntrflags = 0;
1866
1867 if (!nla)
1868 return -EINVAL;
1869
1870 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1871 nla, mntr_flags_policy))
1872 return -EINVAL;
1873
1874 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1875 if (flags[flag])
1876 *mntrflags |= (1<<flag);
1877
1878 return 0;
1879}
1880
Johannes Berg9bc383d2009-11-19 11:55:19 +01001881static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001882 struct net_device *netdev, u8 use_4addr,
1883 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001884{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001885 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001886 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001887 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001888 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001889 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001890
1891 switch (iftype) {
1892 case NL80211_IFTYPE_AP_VLAN:
1893 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1894 return 0;
1895 break;
1896 case NL80211_IFTYPE_STATION:
1897 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1898 return 0;
1899 break;
1900 default:
1901 break;
1902 }
1903
1904 return -EOPNOTSUPP;
1905}
1906
Johannes Berg55682962007-09-20 13:09:35 -04001907static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1908{
Johannes Berg4c476992010-10-04 21:36:35 +02001909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001910 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001911 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001912 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001913 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001914 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001915 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001916
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001917 memset(&params, 0, sizeof(params));
1918
Johannes Berg04a773a2009-04-19 21:24:32 +02001919 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001920
Johannes Berg723b0382008-09-16 20:22:09 +02001921 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001922 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001923 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001924 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001925 if (ntype > NL80211_IFTYPE_MAX)
1926 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001927 }
1928
Johannes Berg92ffe052008-09-16 20:39:36 +02001929 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001930 struct wireless_dev *wdev = dev->ieee80211_ptr;
1931
Johannes Berg4c476992010-10-04 21:36:35 +02001932 if (ntype != NL80211_IFTYPE_MESH_POINT)
1933 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001934 if (netif_running(dev))
1935 return -EBUSY;
1936
1937 wdev_lock(wdev);
1938 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1939 IEEE80211_MAX_MESH_ID_LEN);
1940 wdev->mesh_id_up_len =
1941 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1942 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1943 wdev->mesh_id_up_len);
1944 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001945 }
1946
Felix Fietkau8b787642009-11-10 18:53:10 +01001947 if (info->attrs[NL80211_ATTR_4ADDR]) {
1948 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1949 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001950 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001951 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001952 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001953 } else {
1954 params.use_4addr = -1;
1955 }
1956
Johannes Berg92ffe052008-09-16 20:39:36 +02001957 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001958 if (ntype != NL80211_IFTYPE_MONITOR)
1959 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001960 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1961 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001962 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001963 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001964
1965 flags = &_flags;
1966 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001967 }
Johannes Berg3b858752009-03-12 09:55:09 +01001968
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001969 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001970 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001971 else
1972 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001973
Johannes Berg9bc383d2009-11-19 11:55:19 +01001974 if (!err && params.use_4addr != -1)
1975 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1976
Johannes Berg55682962007-09-20 13:09:35 -04001977 return err;
1978}
1979
1980static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1981{
Johannes Berg4c476992010-10-04 21:36:35 +02001982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001983 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02001984 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02001985 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04001986 int err;
1987 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001988 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001989
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001990 memset(&params, 0, sizeof(params));
1991
Johannes Berg55682962007-09-20 13:09:35 -04001992 if (!info->attrs[NL80211_ATTR_IFNAME])
1993 return -EINVAL;
1994
1995 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1996 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1997 if (type > NL80211_IFTYPE_MAX)
1998 return -EINVAL;
1999 }
2000
Johannes Berg79c97e92009-07-07 03:56:12 +02002001 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002002 !(rdev->wiphy.interface_modes & (1 << type)))
2003 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002004
Johannes Berg9bc383d2009-11-19 11:55:19 +01002005 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002006 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002007 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002008 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002009 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002010 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002011
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2013 if (!msg)
2014 return -ENOMEM;
2015
Michael Wu66f7ac52008-01-31 19:48:22 +01002016 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2017 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2018 &flags);
Johannes Berg84efbb82012-06-16 00:00:26 +02002019 wdev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01002020 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002021 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002022 if (IS_ERR(wdev)) {
2023 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002024 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002025 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002026
Johannes Berg98104fde2012-06-16 00:19:54 +02002027 switch (type) {
2028 case NL80211_IFTYPE_MESH_POINT:
2029 if (!info->attrs[NL80211_ATTR_MESH_ID])
2030 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002031 wdev_lock(wdev);
2032 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2033 IEEE80211_MAX_MESH_ID_LEN);
2034 wdev->mesh_id_up_len =
2035 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2036 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2037 wdev->mesh_id_up_len);
2038 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002039 break;
2040 case NL80211_IFTYPE_P2P_DEVICE:
2041 /*
2042 * P2P Device doesn't have a netdev, so doesn't go
2043 * through the netdev notifier and must be added here
2044 */
2045 mutex_init(&wdev->mtx);
2046 INIT_LIST_HEAD(&wdev->event_list);
2047 spin_lock_init(&wdev->event_lock);
2048 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2049 spin_lock_init(&wdev->mgmt_registrations_lock);
2050
2051 mutex_lock(&rdev->devlist_mtx);
2052 wdev->identifier = ++rdev->wdev_id;
2053 list_add_rcu(&wdev->list, &rdev->wdev_list);
2054 rdev->devlist_generation++;
2055 mutex_unlock(&rdev->devlist_mtx);
2056 break;
2057 default:
2058 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002059 }
2060
Eric W. Biederman15e47302012-09-07 20:12:54 +00002061 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002062 rdev, wdev) < 0) {
2063 nlmsg_free(msg);
2064 return -ENOBUFS;
2065 }
2066
2067 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002068}
2069
2070static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2071{
Johannes Berg4c476992010-10-04 21:36:35 +02002072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002073 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002074
Johannes Berg4c476992010-10-04 21:36:35 +02002075 if (!rdev->ops->del_virtual_intf)
2076 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002077
Johannes Berg84efbb82012-06-16 00:00:26 +02002078 /*
2079 * If we remove a wireless device without a netdev then clear
2080 * user_ptr[1] so that nl80211_post_doit won't dereference it
2081 * to check if it needs to do dev_put(). Otherwise it crashes
2082 * since the wdev has been freed, unlike with a netdev where
2083 * we need the dev_put() for the netdev to really be freed.
2084 */
2085 if (!wdev->netdev)
2086 info->user_ptr[1] = NULL;
2087
2088 return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002089}
2090
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002091static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2092{
2093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2094 struct net_device *dev = info->user_ptr[1];
2095 u16 noack_map;
2096
2097 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2098 return -EINVAL;
2099
2100 if (!rdev->ops->set_noack_map)
2101 return -EOPNOTSUPP;
2102
2103 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2104
2105 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
2106}
2107
Johannes Berg41ade002007-12-19 02:03:29 +01002108struct get_key_cookie {
2109 struct sk_buff *msg;
2110 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002111 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002112};
2113
2114static void get_key_callback(void *c, struct key_params *params)
2115{
Johannes Bergb9454e82009-07-08 13:29:08 +02002116 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002117 struct get_key_cookie *cookie = c;
2118
David S. Miller9360ffd2012-03-29 04:41:26 -04002119 if ((params->key &&
2120 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2121 params->key_len, params->key)) ||
2122 (params->seq &&
2123 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2124 params->seq_len, params->seq)) ||
2125 (params->cipher &&
2126 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2127 params->cipher)))
2128 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002129
Johannes Bergb9454e82009-07-08 13:29:08 +02002130 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2131 if (!key)
2132 goto nla_put_failure;
2133
David S. Miller9360ffd2012-03-29 04:41:26 -04002134 if ((params->key &&
2135 nla_put(cookie->msg, NL80211_KEY_DATA,
2136 params->key_len, params->key)) ||
2137 (params->seq &&
2138 nla_put(cookie->msg, NL80211_KEY_SEQ,
2139 params->seq_len, params->seq)) ||
2140 (params->cipher &&
2141 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2142 params->cipher)))
2143 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002144
David S. Miller9360ffd2012-03-29 04:41:26 -04002145 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2146 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002147
2148 nla_nest_end(cookie->msg, key);
2149
Johannes Berg41ade002007-12-19 02:03:29 +01002150 return;
2151 nla_put_failure:
2152 cookie->error = 1;
2153}
2154
2155static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2156{
Johannes Berg4c476992010-10-04 21:36:35 +02002157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002158 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002159 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002160 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002161 const u8 *mac_addr = NULL;
2162 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002163 struct get_key_cookie cookie = {
2164 .error = 0,
2165 };
2166 void *hdr;
2167 struct sk_buff *msg;
2168
2169 if (info->attrs[NL80211_ATTR_KEY_IDX])
2170 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2171
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002172 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002173 return -EINVAL;
2174
2175 if (info->attrs[NL80211_ATTR_MAC])
2176 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2177
Johannes Berge31b8212010-10-05 19:39:30 +02002178 pairwise = !!mac_addr;
2179 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2180 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2181 if (kt >= NUM_NL80211_KEYTYPES)
2182 return -EINVAL;
2183 if (kt != NL80211_KEYTYPE_GROUP &&
2184 kt != NL80211_KEYTYPE_PAIRWISE)
2185 return -EINVAL;
2186 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2187 }
2188
Johannes Berg4c476992010-10-04 21:36:35 +02002189 if (!rdev->ops->get_key)
2190 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002191
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002192 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002193 if (!msg)
2194 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002195
Eric W. Biederman15e47302012-09-07 20:12:54 +00002196 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002197 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002198 if (IS_ERR(hdr))
2199 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002200
2201 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002202 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002203
David S. Miller9360ffd2012-03-29 04:41:26 -04002204 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2205 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2206 goto nla_put_failure;
2207 if (mac_addr &&
2208 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2209 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002210
Johannes Berge31b8212010-10-05 19:39:30 +02002211 if (pairwise && mac_addr &&
2212 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2213 return -ENOENT;
2214
2215 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2216 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002217
2218 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002219 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002220
2221 if (cookie.error)
2222 goto nla_put_failure;
2223
2224 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002225 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002226
2227 nla_put_failure:
2228 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002229 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002230 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002231 return err;
2232}
2233
2234static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2235{
Johannes Berg4c476992010-10-04 21:36:35 +02002236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002237 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002238 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002239 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002240
Johannes Bergb9454e82009-07-08 13:29:08 +02002241 err = nl80211_parse_key(info, &key);
2242 if (err)
2243 return err;
2244
2245 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002246 return -EINVAL;
2247
Johannes Bergb9454e82009-07-08 13:29:08 +02002248 /* only support setting default key */
2249 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002250 return -EINVAL;
2251
Johannes Bergfffd0932009-07-08 14:22:54 +02002252 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002253
2254 if (key.def) {
2255 if (!rdev->ops->set_default_key) {
2256 err = -EOPNOTSUPP;
2257 goto out;
2258 }
2259
2260 err = nl80211_key_allowed(dev->ieee80211_ptr);
2261 if (err)
2262 goto out;
2263
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002264 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2265 key.def_uni, key.def_multi);
2266
2267 if (err)
2268 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002269
Johannes Berg3d23e342009-09-29 23:27:28 +02002270#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002271 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002272#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002273 } else {
2274 if (key.def_uni || !key.def_multi) {
2275 err = -EINVAL;
2276 goto out;
2277 }
2278
2279 if (!rdev->ops->set_default_mgmt_key) {
2280 err = -EOPNOTSUPP;
2281 goto out;
2282 }
2283
2284 err = nl80211_key_allowed(dev->ieee80211_ptr);
2285 if (err)
2286 goto out;
2287
2288 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2289 dev, key.idx);
2290 if (err)
2291 goto out;
2292
2293#ifdef CONFIG_CFG80211_WEXT
2294 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2295#endif
2296 }
2297
2298 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002299 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002300
Johannes Berg41ade002007-12-19 02:03:29 +01002301 return err;
2302}
2303
2304static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2305{
Johannes Berg4c476992010-10-04 21:36:35 +02002306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002307 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002308 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002309 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002310 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002311
Johannes Bergb9454e82009-07-08 13:29:08 +02002312 err = nl80211_parse_key(info, &key);
2313 if (err)
2314 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002315
Johannes Bergb9454e82009-07-08 13:29:08 +02002316 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002317 return -EINVAL;
2318
Johannes Berg41ade002007-12-19 02:03:29 +01002319 if (info->attrs[NL80211_ATTR_MAC])
2320 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2321
Johannes Berge31b8212010-10-05 19:39:30 +02002322 if (key.type == -1) {
2323 if (mac_addr)
2324 key.type = NL80211_KEYTYPE_PAIRWISE;
2325 else
2326 key.type = NL80211_KEYTYPE_GROUP;
2327 }
2328
2329 /* for now */
2330 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2331 key.type != NL80211_KEYTYPE_GROUP)
2332 return -EINVAL;
2333
Johannes Berg4c476992010-10-04 21:36:35 +02002334 if (!rdev->ops->add_key)
2335 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002336
Johannes Berge31b8212010-10-05 19:39:30 +02002337 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2338 key.type == NL80211_KEYTYPE_PAIRWISE,
2339 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002340 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002341
2342 wdev_lock(dev->ieee80211_ptr);
2343 err = nl80211_key_allowed(dev->ieee80211_ptr);
2344 if (!err)
2345 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002346 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002347 mac_addr, &key.p);
2348 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002349
Johannes Berg41ade002007-12-19 02:03:29 +01002350 return err;
2351}
2352
2353static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2354{
Johannes Berg4c476992010-10-04 21:36:35 +02002355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002356 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002357 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002358 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002359 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002360
Johannes Bergb9454e82009-07-08 13:29:08 +02002361 err = nl80211_parse_key(info, &key);
2362 if (err)
2363 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002364
2365 if (info->attrs[NL80211_ATTR_MAC])
2366 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2367
Johannes Berge31b8212010-10-05 19:39:30 +02002368 if (key.type == -1) {
2369 if (mac_addr)
2370 key.type = NL80211_KEYTYPE_PAIRWISE;
2371 else
2372 key.type = NL80211_KEYTYPE_GROUP;
2373 }
2374
2375 /* for now */
2376 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2377 key.type != NL80211_KEYTYPE_GROUP)
2378 return -EINVAL;
2379
Johannes Berg4c476992010-10-04 21:36:35 +02002380 if (!rdev->ops->del_key)
2381 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002382
Johannes Bergfffd0932009-07-08 14:22:54 +02002383 wdev_lock(dev->ieee80211_ptr);
2384 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002385
2386 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2387 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2388 err = -ENOENT;
2389
Johannes Bergfffd0932009-07-08 14:22:54 +02002390 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002391 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2392 key.type == NL80211_KEYTYPE_PAIRWISE,
2393 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002394
Johannes Berg3d23e342009-09-29 23:27:28 +02002395#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002396 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002397 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002398 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002399 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002400 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2401 }
2402#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002403 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002404
Johannes Berg41ade002007-12-19 02:03:29 +01002405 return err;
2406}
2407
Johannes Berg88600202012-02-13 15:17:18 +01002408static int nl80211_parse_beacon(struct genl_info *info,
2409 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002410{
Johannes Berg88600202012-02-13 15:17:18 +01002411 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002412
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002413 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2414 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2415 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2416 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002417 return -EINVAL;
2418
Johannes Berg88600202012-02-13 15:17:18 +01002419 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002420
Johannes Berged1b6cc2007-12-19 02:03:32 +01002421 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002422 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2423 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2424 if (!bcn->head_len)
2425 return -EINVAL;
2426 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002427 }
2428
2429 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002430 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2431 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002432 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002433 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002434 }
2435
Johannes Berg4c476992010-10-04 21:36:35 +02002436 if (!haveinfo)
2437 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002438
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002439 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002440 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2441 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002442 }
2443
2444 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002445 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002446 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002447 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002448 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2449 }
2450
2451 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002452 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002453 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002454 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002455 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2456 }
2457
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002458 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002459 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002460 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002461 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002462 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2463 }
2464
Johannes Berg88600202012-02-13 15:17:18 +01002465 return 0;
2466}
2467
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002468static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2469 struct cfg80211_ap_settings *params)
2470{
2471 struct wireless_dev *wdev;
2472 bool ret = false;
2473
2474 mutex_lock(&rdev->devlist_mtx);
2475
Johannes Berg89a54e42012-06-15 14:33:17 +02002476 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002477 if (wdev->iftype != NL80211_IFTYPE_AP &&
2478 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2479 continue;
2480
2481 if (!wdev->preset_chan)
2482 continue;
2483
2484 params->channel = wdev->preset_chan;
2485 params->channel_type = wdev->preset_chantype;
2486 ret = true;
2487 break;
2488 }
2489
2490 mutex_unlock(&rdev->devlist_mtx);
2491
2492 return ret;
2493}
2494
Jouni Malinene39e5b52012-09-30 19:29:39 +03002495static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2496 enum nl80211_auth_type auth_type,
2497 enum nl80211_commands cmd)
2498{
2499 if (auth_type > NL80211_AUTHTYPE_MAX)
2500 return false;
2501
2502 switch (cmd) {
2503 case NL80211_CMD_AUTHENTICATE:
2504 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2505 auth_type == NL80211_AUTHTYPE_SAE)
2506 return false;
2507 return true;
2508 case NL80211_CMD_CONNECT:
2509 case NL80211_CMD_START_AP:
2510 /* SAE not supported yet */
2511 if (auth_type == NL80211_AUTHTYPE_SAE)
2512 return false;
2513 return true;
2514 default:
2515 return false;
2516 }
2517}
2518
Johannes Berg88600202012-02-13 15:17:18 +01002519static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2520{
2521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2522 struct net_device *dev = info->user_ptr[1];
2523 struct wireless_dev *wdev = dev->ieee80211_ptr;
2524 struct cfg80211_ap_settings params;
2525 int err;
2526
2527 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2528 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2529 return -EOPNOTSUPP;
2530
2531 if (!rdev->ops->start_ap)
2532 return -EOPNOTSUPP;
2533
2534 if (wdev->beacon_interval)
2535 return -EALREADY;
2536
2537 memset(&params, 0, sizeof(params));
2538
2539 /* these are required for START_AP */
2540 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2541 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2542 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2543 return -EINVAL;
2544
2545 err = nl80211_parse_beacon(info, &params.beacon);
2546 if (err)
2547 return err;
2548
2549 params.beacon_interval =
2550 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2551 params.dtim_period =
2552 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2553
2554 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2555 if (err)
2556 return err;
2557
2558 /*
2559 * In theory, some of these attributes should be required here
2560 * but since they were not used when the command was originally
2561 * added, keep them optional for old user space programs to let
2562 * them continue to work with drivers that do not need the
2563 * additional information -- drivers must check!
2564 */
2565 if (info->attrs[NL80211_ATTR_SSID]) {
2566 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2567 params.ssid_len =
2568 nla_len(info->attrs[NL80211_ATTR_SSID]);
2569 if (params.ssid_len == 0 ||
2570 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2571 return -EINVAL;
2572 }
2573
2574 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2575 params.hidden_ssid = nla_get_u32(
2576 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2577 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2578 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2579 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2580 return -EINVAL;
2581 }
2582
2583 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2584
2585 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2586 params.auth_type = nla_get_u32(
2587 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03002588 if (!nl80211_valid_auth_type(rdev, params.auth_type,
2589 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01002590 return -EINVAL;
2591 } else
2592 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2593
2594 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2595 NL80211_MAX_NR_CIPHER_SUITES);
2596 if (err)
2597 return err;
2598
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302599 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2600 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2601 return -EOPNOTSUPP;
2602 params.inactivity_timeout = nla_get_u16(
2603 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2604 }
2605
Johannes Bergaa430da2012-05-16 23:50:18 +02002606 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2607 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2608
2609 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2610 !nl80211_valid_channel_type(info, &channel_type))
2611 return -EINVAL;
2612
2613 params.channel = rdev_freq_to_chan(rdev,
2614 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2615 channel_type);
2616 if (!params.channel)
2617 return -EINVAL;
2618 params.channel_type = channel_type;
2619 } else if (wdev->preset_chan) {
2620 params.channel = wdev->preset_chan;
2621 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002622 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002623 return -EINVAL;
2624
2625 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2626 params.channel_type))
2627 return -EINVAL;
2628
Michal Kaziore4e32452012-06-29 12:47:08 +02002629 mutex_lock(&rdev->devlist_mtx);
2630 err = cfg80211_can_use_chan(rdev, wdev, params.channel,
2631 CHAN_MODE_SHARED);
2632 mutex_unlock(&rdev->devlist_mtx);
2633
2634 if (err)
2635 return err;
2636
Johannes Berg88600202012-02-13 15:17:18 +01002637 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002638 if (!err) {
2639 wdev->preset_chan = params.channel;
2640 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002641 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002642 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002643 }
Johannes Berg56d18932011-05-09 18:41:15 +02002644 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002645}
2646
Johannes Berg88600202012-02-13 15:17:18 +01002647static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2648{
2649 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2650 struct net_device *dev = info->user_ptr[1];
2651 struct wireless_dev *wdev = dev->ieee80211_ptr;
2652 struct cfg80211_beacon_data params;
2653 int err;
2654
2655 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2656 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2657 return -EOPNOTSUPP;
2658
2659 if (!rdev->ops->change_beacon)
2660 return -EOPNOTSUPP;
2661
2662 if (!wdev->beacon_interval)
2663 return -EINVAL;
2664
2665 err = nl80211_parse_beacon(info, &params);
2666 if (err)
2667 return err;
2668
2669 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2670}
2671
2672static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002673{
Johannes Berg4c476992010-10-04 21:36:35 +02002674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2675 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002676
Michal Kazior60771782012-06-29 12:46:56 +02002677 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002678}
2679
Johannes Berg5727ef12007-12-19 02:03:34 +01002680static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2681 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2682 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2683 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002684 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002685 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002686 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002687};
2688
Johannes Bergeccb8e82009-05-11 21:57:56 +03002689static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002690 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002691 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002692{
2693 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002694 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002695 int flag;
2696
Johannes Bergeccb8e82009-05-11 21:57:56 +03002697 /*
2698 * Try parsing the new attribute first so userspace
2699 * can specify both for older kernels.
2700 */
2701 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2702 if (nla) {
2703 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002704
Johannes Bergeccb8e82009-05-11 21:57:56 +03002705 sta_flags = nla_data(nla);
2706 params->sta_flags_mask = sta_flags->mask;
2707 params->sta_flags_set = sta_flags->set;
2708 if ((params->sta_flags_mask |
2709 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2710 return -EINVAL;
2711 return 0;
2712 }
2713
2714 /* if present, parse the old attribute */
2715
2716 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002717 if (!nla)
2718 return 0;
2719
2720 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2721 nla, sta_flags_policy))
2722 return -EINVAL;
2723
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002724 /*
2725 * Only allow certain flags for interface types so that
2726 * other attributes are silently ignored. Remember that
2727 * this is backward compatibility code with old userspace
2728 * and shouldn't be hit in other cases anyway.
2729 */
2730 switch (iftype) {
2731 case NL80211_IFTYPE_AP:
2732 case NL80211_IFTYPE_AP_VLAN:
2733 case NL80211_IFTYPE_P2P_GO:
2734 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2735 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2736 BIT(NL80211_STA_FLAG_WME) |
2737 BIT(NL80211_STA_FLAG_MFP);
2738 break;
2739 case NL80211_IFTYPE_P2P_CLIENT:
2740 case NL80211_IFTYPE_STATION:
2741 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2742 BIT(NL80211_STA_FLAG_TDLS_PEER);
2743 break;
2744 case NL80211_IFTYPE_MESH_POINT:
2745 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2746 BIT(NL80211_STA_FLAG_MFP) |
2747 BIT(NL80211_STA_FLAG_AUTHORIZED);
2748 default:
2749 return -EINVAL;
2750 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002751
Johannes Berg3383b5a2012-05-10 20:14:43 +02002752 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2753 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002754 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002755
Johannes Berg3383b5a2012-05-10 20:14:43 +02002756 /* no longer support new API additions in old API */
2757 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2758 return -EINVAL;
2759 }
2760 }
2761
Johannes Berg5727ef12007-12-19 02:03:34 +01002762 return 0;
2763}
2764
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002765static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2766 int attr)
2767{
2768 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002769 u32 bitrate;
2770 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002771
2772 rate = nla_nest_start(msg, attr);
2773 if (!rate)
2774 goto nla_put_failure;
2775
2776 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2777 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002778 /* report 16-bit bitrate only if we can */
2779 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
David S. Miller9360ffd2012-03-29 04:41:26 -04002780 if ((bitrate > 0 &&
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002781 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
2782 (bitrate_compat > 0 &&
2783 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002784 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2785 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2786 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2787 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2788 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2789 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2790 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002791
2792 nla_nest_end(msg, rate);
2793 return true;
2794
2795nla_put_failure:
2796 return false;
2797}
2798
Eric W. Biederman15e47302012-09-07 20:12:54 +00002799static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002800 int flags,
2801 struct cfg80211_registered_device *rdev,
2802 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002803 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002804{
2805 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002806 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002807
Eric W. Biederman15e47302012-09-07 20:12:54 +00002808 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002809 if (!hdr)
2810 return -1;
2811
David S. Miller9360ffd2012-03-29 04:41:26 -04002812 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2813 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2814 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2815 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002816
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002817 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2818 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002819 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002820 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2821 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2822 sinfo->connected_time))
2823 goto nla_put_failure;
2824 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2825 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2826 sinfo->inactive_time))
2827 goto nla_put_failure;
2828 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2829 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2830 sinfo->rx_bytes))
2831 goto nla_put_failure;
2832 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2833 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2834 sinfo->tx_bytes))
2835 goto nla_put_failure;
2836 if ((sinfo->filled & STATION_INFO_LLID) &&
2837 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2838 goto nla_put_failure;
2839 if ((sinfo->filled & STATION_INFO_PLID) &&
2840 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2841 goto nla_put_failure;
2842 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2843 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2844 sinfo->plink_state))
2845 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002846 switch (rdev->wiphy.signal_type) {
2847 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002848 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2849 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2850 sinfo->signal))
2851 goto nla_put_failure;
2852 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2853 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2854 sinfo->signal_avg))
2855 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002856 break;
2857 default:
2858 break;
2859 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002860 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002861 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2862 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002863 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002864 }
2865 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2866 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2867 NL80211_STA_INFO_RX_BITRATE))
2868 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002869 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002870 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2871 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2872 sinfo->rx_packets))
2873 goto nla_put_failure;
2874 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2875 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2876 sinfo->tx_packets))
2877 goto nla_put_failure;
2878 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2879 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2880 sinfo->tx_retries))
2881 goto nla_put_failure;
2882 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2883 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2884 sinfo->tx_failed))
2885 goto nla_put_failure;
2886 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2887 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2888 sinfo->beacon_loss_count))
2889 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002890 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2891 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2892 if (!bss_param)
2893 goto nla_put_failure;
2894
David S. Miller9360ffd2012-03-29 04:41:26 -04002895 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2896 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2897 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2898 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2899 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2900 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2901 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2902 sinfo->bss_param.dtim_period) ||
2903 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2904 sinfo->bss_param.beacon_interval))
2905 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002906
2907 nla_nest_end(msg, bss_param);
2908 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002909 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2910 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2911 sizeof(struct nl80211_sta_flag_update),
2912 &sinfo->sta_flags))
2913 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002914 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2915 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2916 sinfo->t_offset))
2917 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002918 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002919
David S. Miller9360ffd2012-03-29 04:41:26 -04002920 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2921 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2922 sinfo->assoc_req_ies))
2923 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002924
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002925 return genlmsg_end(msg, hdr);
2926
2927 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002928 genlmsg_cancel(msg, hdr);
2929 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002930}
2931
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002932static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002933 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002934{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002935 struct station_info sinfo;
2936 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002937 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002938 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002939 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002940 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002941
Johannes Berg67748892010-10-04 21:14:06 +02002942 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2943 if (err)
2944 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002945
2946 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002947 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002948 goto out_err;
2949 }
2950
Johannes Bergbba95fe2008-07-29 13:22:51 +02002951 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002952 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002953 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2954 mac_addr, &sinfo);
2955 if (err == -ENOENT)
2956 break;
2957 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002958 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002959
2960 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00002961 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002962 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002963 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002964 &sinfo) < 0)
2965 goto out;
2966
2967 sta_idx++;
2968 }
2969
2970
2971 out:
2972 cb->args[1] = sta_idx;
2973 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002974 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002975 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002976
2977 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002978}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002979
Johannes Berg5727ef12007-12-19 02:03:34 +01002980static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2981{
Johannes Berg4c476992010-10-04 21:36:35 +02002982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2983 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002984 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002985 struct sk_buff *msg;
2986 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002987 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002988
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002989 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002990
2991 if (!info->attrs[NL80211_ATTR_MAC])
2992 return -EINVAL;
2993
2994 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2995
Johannes Berg4c476992010-10-04 21:36:35 +02002996 if (!rdev->ops->get_station)
2997 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002998
Johannes Berg79c97e92009-07-07 03:56:12 +02002999 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003000 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003001 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003002
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003004 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003005 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003006
Eric W. Biederman15e47302012-09-07 20:12:54 +00003007 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003008 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003009 nlmsg_free(msg);
3010 return -ENOBUFS;
3011 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003012
Johannes Berg4c476992010-10-04 21:36:35 +02003013 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003014}
3015
3016/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003017 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003018 */
Johannes Berg80b99892011-11-18 16:23:01 +01003019static struct net_device *get_vlan(struct genl_info *info,
3020 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003021{
Johannes Berg463d0182009-07-14 00:33:35 +02003022 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003023 struct net_device *v;
3024 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003025
Johannes Berg80b99892011-11-18 16:23:01 +01003026 if (!vlanattr)
3027 return NULL;
3028
3029 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3030 if (!v)
3031 return ERR_PTR(-ENODEV);
3032
3033 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3034 ret = -EINVAL;
3035 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003036 }
Johannes Berg80b99892011-11-18 16:23:01 +01003037
3038 if (!netif_running(v)) {
3039 ret = -ENETDOWN;
3040 goto error;
3041 }
3042
3043 return v;
3044 error:
3045 dev_put(v);
3046 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003047}
3048
3049static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3050{
Johannes Berg4c476992010-10-04 21:36:35 +02003051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003052 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003053 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003054 struct station_parameters params;
3055 u8 *mac_addr = NULL;
3056
3057 memset(&params, 0, sizeof(params));
3058
3059 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07003060 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01003061
3062 if (info->attrs[NL80211_ATTR_STA_AID])
3063 return -EINVAL;
3064
3065 if (!info->attrs[NL80211_ATTR_MAC])
3066 return -EINVAL;
3067
3068 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3069
3070 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3071 params.supported_rates =
3072 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3073 params.supported_rates_len =
3074 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3075 }
3076
3077 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3078 params.listen_interval =
3079 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3080
Jouni Malinen36aedc92008-08-25 11:58:58 +03003081 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3082 params.ht_capa =
3083 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3084
Johannes Bergbdd90d52011-12-14 12:20:27 +01003085 if (!rdev->ops->change_station)
3086 return -EOPNOTSUPP;
3087
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003088 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003089 return -EINVAL;
3090
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003091 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3092 params.plink_action =
3093 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3094
Javier Cardona9c3990a2011-05-03 16:57:11 -07003095 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
3096 params.plink_state =
3097 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3098
Johannes Berga97f4422009-06-18 17:23:43 +02003099 switch (dev->ieee80211_ptr->iftype) {
3100 case NL80211_IFTYPE_AP:
3101 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003102 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02003103 /* disallow mesh-specific things */
3104 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003105 return -EINVAL;
3106
3107 /* TDLS can't be set, ... */
3108 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3109 return -EINVAL;
3110 /*
3111 * ... but don't bother the driver with it. This works around
3112 * a hostapd/wpa_supplicant issue -- it always includes the
3113 * TLDS_PEER flag in the mask even for AP mode.
3114 */
3115 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3116
3117 /* accept only the listed bits */
3118 if (params.sta_flags_mask &
3119 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3120 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3121 BIT(NL80211_STA_FLAG_WME) |
3122 BIT(NL80211_STA_FLAG_MFP)))
3123 return -EINVAL;
3124
3125 /* must be last in here for error handling */
3126 params.vlan = get_vlan(info, rdev);
3127 if (IS_ERR(params.vlan))
3128 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02003129 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02003130 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003131 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003132 /*
3133 * Don't allow userspace to change the TDLS_PEER flag,
3134 * but silently ignore attempts to change it since we
3135 * don't have state here to verify that it doesn't try
3136 * to change the flag.
3137 */
3138 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01003139 /* fall through */
3140 case NL80211_IFTYPE_ADHOC:
3141 /* disallow things sta doesn't support */
3142 if (params.plink_action)
3143 return -EINVAL;
3144 if (params.ht_capa)
3145 return -EINVAL;
3146 if (params.listen_interval >= 0)
3147 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003148 /* reject any changes other than AUTHORIZED */
3149 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3150 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003151 break;
3152 case NL80211_IFTYPE_MESH_POINT:
3153 /* disallow things mesh doesn't support */
3154 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003155 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003156 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003157 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003158 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003159 return -EINVAL;
3160 /*
3161 * No special handling for TDLS here -- the userspace
3162 * mesh code doesn't have this bug.
3163 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003164 if (params.sta_flags_mask &
3165 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003166 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003167 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003168 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003169 break;
3170 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003171 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003172 }
3173
Johannes Bergbdd90d52011-12-14 12:20:27 +01003174 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003175
Johannes Berg79c97e92009-07-07 03:56:12 +02003176 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003177
Johannes Berg5727ef12007-12-19 02:03:34 +01003178 if (params.vlan)
3179 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003180
Johannes Berg5727ef12007-12-19 02:03:34 +01003181 return err;
3182}
3183
Eliad Pellerc75786c2011-08-23 14:37:46 +03003184static struct nla_policy
3185nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3186 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3187 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3188};
3189
Johannes Berg5727ef12007-12-19 02:03:34 +01003190static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3191{
Johannes Berg4c476992010-10-04 21:36:35 +02003192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003193 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003194 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003195 struct station_parameters params;
3196 u8 *mac_addr = NULL;
3197
3198 memset(&params, 0, sizeof(params));
3199
3200 if (!info->attrs[NL80211_ATTR_MAC])
3201 return -EINVAL;
3202
Johannes Berg5727ef12007-12-19 02:03:34 +01003203 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3204 return -EINVAL;
3205
3206 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3207 return -EINVAL;
3208
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003209 if (!info->attrs[NL80211_ATTR_STA_AID])
3210 return -EINVAL;
3211
Johannes Berg5727ef12007-12-19 02:03:34 +01003212 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3213 params.supported_rates =
3214 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3215 params.supported_rates_len =
3216 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3217 params.listen_interval =
3218 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003219
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003220 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3221 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3222 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003223
Jouni Malinen36aedc92008-08-25 11:58:58 +03003224 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3225 params.ht_capa =
3226 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003227
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003228 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3229 params.vht_capa =
3230 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3231
Javier Cardona96b78df2011-04-07 15:08:33 -07003232 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3233 params.plink_action =
3234 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3235
Johannes Bergbdd90d52011-12-14 12:20:27 +01003236 if (!rdev->ops->add_station)
3237 return -EOPNOTSUPP;
3238
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003239 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003240 return -EINVAL;
3241
Johannes Bergbdd90d52011-12-14 12:20:27 +01003242 switch (dev->ieee80211_ptr->iftype) {
3243 case NL80211_IFTYPE_AP:
3244 case NL80211_IFTYPE_AP_VLAN:
3245 case NL80211_IFTYPE_P2P_GO:
3246 /* parse WME attributes if sta is WME capable */
3247 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3248 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3249 info->attrs[NL80211_ATTR_STA_WME]) {
3250 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3251 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003252
Johannes Bergbdd90d52011-12-14 12:20:27 +01003253 nla = info->attrs[NL80211_ATTR_STA_WME];
3254 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3255 nl80211_sta_wme_policy);
3256 if (err)
3257 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003258
Johannes Bergbdd90d52011-12-14 12:20:27 +01003259 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3260 params.uapsd_queues =
3261 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3262 if (params.uapsd_queues &
3263 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3264 return -EINVAL;
3265
3266 if (tb[NL80211_STA_WME_MAX_SP])
3267 params.max_sp =
3268 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3269
3270 if (params.max_sp &
3271 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3272 return -EINVAL;
3273
3274 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3275 }
3276 /* TDLS peers cannot be added */
3277 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003278 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003279 /* but don't bother the driver with it */
3280 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003281
Johannes Bergbdd90d52011-12-14 12:20:27 +01003282 /* must be last in here for error handling */
3283 params.vlan = get_vlan(info, rdev);
3284 if (IS_ERR(params.vlan))
3285 return PTR_ERR(params.vlan);
3286 break;
3287 case NL80211_IFTYPE_MESH_POINT:
3288 /* TDLS peers cannot be added */
3289 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003290 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003291 break;
3292 case NL80211_IFTYPE_STATION:
3293 /* Only TDLS peers can be added */
3294 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3295 return -EINVAL;
3296 /* Can only add if TDLS ... */
3297 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3298 return -EOPNOTSUPP;
3299 /* ... with external setup is supported */
3300 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3301 return -EOPNOTSUPP;
3302 break;
3303 default:
3304 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003305 }
3306
Johannes Bergbdd90d52011-12-14 12:20:27 +01003307 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003308
Johannes Berg79c97e92009-07-07 03:56:12 +02003309 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003310
Johannes Berg5727ef12007-12-19 02:03:34 +01003311 if (params.vlan)
3312 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003313 return err;
3314}
3315
3316static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3317{
Johannes Berg4c476992010-10-04 21:36:35 +02003318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3319 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003320 u8 *mac_addr = NULL;
3321
3322 if (info->attrs[NL80211_ATTR_MAC])
3323 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3324
Johannes Berge80cf852009-05-11 14:43:13 +02003325 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003326 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003327 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003328 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3329 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003330
Johannes Berg4c476992010-10-04 21:36:35 +02003331 if (!rdev->ops->del_station)
3332 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003333
Johannes Berg4c476992010-10-04 21:36:35 +02003334 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003335}
3336
Eric W. Biederman15e47302012-09-07 20:12:54 +00003337static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003338 int flags, struct net_device *dev,
3339 u8 *dst, u8 *next_hop,
3340 struct mpath_info *pinfo)
3341{
3342 void *hdr;
3343 struct nlattr *pinfoattr;
3344
Eric W. Biederman15e47302012-09-07 20:12:54 +00003345 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003346 if (!hdr)
3347 return -1;
3348
David S. Miller9360ffd2012-03-29 04:41:26 -04003349 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3350 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3351 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3352 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3353 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003354
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003355 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3356 if (!pinfoattr)
3357 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003358 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3359 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3360 pinfo->frame_qlen))
3361 goto nla_put_failure;
3362 if (((pinfo->filled & MPATH_INFO_SN) &&
3363 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3364 ((pinfo->filled & MPATH_INFO_METRIC) &&
3365 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3366 pinfo->metric)) ||
3367 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3368 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3369 pinfo->exptime)) ||
3370 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3371 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3372 pinfo->flags)) ||
3373 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3374 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3375 pinfo->discovery_timeout)) ||
3376 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3377 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3378 pinfo->discovery_retries)))
3379 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003380
3381 nla_nest_end(msg, pinfoattr);
3382
3383 return genlmsg_end(msg, hdr);
3384
3385 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003386 genlmsg_cancel(msg, hdr);
3387 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003388}
3389
3390static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003391 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003392{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003393 struct mpath_info pinfo;
3394 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003395 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003396 u8 dst[ETH_ALEN];
3397 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003398 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003399 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003400
Johannes Berg67748892010-10-04 21:14:06 +02003401 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3402 if (err)
3403 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003404
3405 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003406 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003407 goto out_err;
3408 }
3409
Jouni Malineneec60b02009-03-20 21:21:19 +02003410 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3411 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003412 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003413 }
3414
Johannes Bergbba95fe2008-07-29 13:22:51 +02003415 while (1) {
3416 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3417 dst, next_hop, &pinfo);
3418 if (err == -ENOENT)
3419 break;
3420 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003421 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003422
Eric W. Biederman15e47302012-09-07 20:12:54 +00003423 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003424 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3425 netdev, dst, next_hop,
3426 &pinfo) < 0)
3427 goto out;
3428
3429 path_idx++;
3430 }
3431
3432
3433 out:
3434 cb->args[1] = path_idx;
3435 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003436 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003437 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003438 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003439}
3440
3441static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3442{
Johannes Berg4c476992010-10-04 21:36:35 +02003443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003444 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003445 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003446 struct mpath_info pinfo;
3447 struct sk_buff *msg;
3448 u8 *dst = NULL;
3449 u8 next_hop[ETH_ALEN];
3450
3451 memset(&pinfo, 0, sizeof(pinfo));
3452
3453 if (!info->attrs[NL80211_ATTR_MAC])
3454 return -EINVAL;
3455
3456 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3457
Johannes Berg4c476992010-10-04 21:36:35 +02003458 if (!rdev->ops->get_mpath)
3459 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003460
Johannes Berg4c476992010-10-04 21:36:35 +02003461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3462 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003463
Johannes Berg79c97e92009-07-07 03:56:12 +02003464 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003465 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003466 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003467
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003469 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003470 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003471
Eric W. Biederman15e47302012-09-07 20:12:54 +00003472 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003473 dev, dst, next_hop, &pinfo) < 0) {
3474 nlmsg_free(msg);
3475 return -ENOBUFS;
3476 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003477
Johannes Berg4c476992010-10-04 21:36:35 +02003478 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003479}
3480
3481static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3482{
Johannes Berg4c476992010-10-04 21:36:35 +02003483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3484 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003485 u8 *dst = NULL;
3486 u8 *next_hop = NULL;
3487
3488 if (!info->attrs[NL80211_ATTR_MAC])
3489 return -EINVAL;
3490
3491 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3492 return -EINVAL;
3493
3494 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3495 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3496
Johannes Berg4c476992010-10-04 21:36:35 +02003497 if (!rdev->ops->change_mpath)
3498 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003499
Johannes Berg4c476992010-10-04 21:36:35 +02003500 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3501 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003502
Johannes Berg4c476992010-10-04 21:36:35 +02003503 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504}
Johannes Berg4c476992010-10-04 21:36:35 +02003505
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003506static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3507{
Johannes Berg4c476992010-10-04 21:36:35 +02003508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3509 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003510 u8 *dst = NULL;
3511 u8 *next_hop = NULL;
3512
3513 if (!info->attrs[NL80211_ATTR_MAC])
3514 return -EINVAL;
3515
3516 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3517 return -EINVAL;
3518
3519 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3520 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3521
Johannes Berg4c476992010-10-04 21:36:35 +02003522 if (!rdev->ops->add_mpath)
3523 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003524
Johannes Berg4c476992010-10-04 21:36:35 +02003525 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3526 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003527
Johannes Berg4c476992010-10-04 21:36:35 +02003528 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529}
3530
3531static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3532{
Johannes Berg4c476992010-10-04 21:36:35 +02003533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3534 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003535 u8 *dst = NULL;
3536
3537 if (info->attrs[NL80211_ATTR_MAC])
3538 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3539
Johannes Berg4c476992010-10-04 21:36:35 +02003540 if (!rdev->ops->del_mpath)
3541 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003542
Johannes Berg4c476992010-10-04 21:36:35 +02003543 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003544}
3545
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003546static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3547{
Johannes Berg4c476992010-10-04 21:36:35 +02003548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3549 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003550 struct bss_parameters params;
3551
3552 memset(&params, 0, sizeof(params));
3553 /* default to not changing parameters */
3554 params.use_cts_prot = -1;
3555 params.use_short_preamble = -1;
3556 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003557 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003558 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003559
3560 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3561 params.use_cts_prot =
3562 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3563 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3564 params.use_short_preamble =
3565 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3566 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3567 params.use_short_slot_time =
3568 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003569 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3570 params.basic_rates =
3571 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3572 params.basic_rates_len =
3573 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3574 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003575 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3576 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003577 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3578 params.ht_opmode =
3579 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003580
Johannes Berg4c476992010-10-04 21:36:35 +02003581 if (!rdev->ops->change_bss)
3582 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003583
Johannes Berg074ac8d2010-09-16 14:58:22 +02003584 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003585 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3586 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003587
Johannes Berg4c476992010-10-04 21:36:35 +02003588 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003589}
3590
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003591static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003592 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3593 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3594 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3595 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3596 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3597 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3598};
3599
3600static int parse_reg_rule(struct nlattr *tb[],
3601 struct ieee80211_reg_rule *reg_rule)
3602{
3603 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3604 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3605
3606 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3607 return -EINVAL;
3608 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3609 return -EINVAL;
3610 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3611 return -EINVAL;
3612 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3613 return -EINVAL;
3614 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3615 return -EINVAL;
3616
3617 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3618
3619 freq_range->start_freq_khz =
3620 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3621 freq_range->end_freq_khz =
3622 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3623 freq_range->max_bandwidth_khz =
3624 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3625
3626 power_rule->max_eirp =
3627 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3628
3629 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3630 power_rule->max_antenna_gain =
3631 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3632
3633 return 0;
3634}
3635
3636static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3637{
3638 int r;
3639 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003640 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003641
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003642 /*
3643 * You should only get this when cfg80211 hasn't yet initialized
3644 * completely when built-in to the kernel right between the time
3645 * window between nl80211_init() and regulatory_init(), if that is
3646 * even possible.
3647 */
3648 mutex_lock(&cfg80211_mutex);
3649 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003650 mutex_unlock(&cfg80211_mutex);
3651 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003652 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003653 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003654
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003655 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3656 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003657
3658 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3659
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003660 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
3661 user_reg_hint_type =
3662 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
3663 else
3664 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
3665
3666 switch (user_reg_hint_type) {
3667 case NL80211_USER_REG_HINT_USER:
3668 case NL80211_USER_REG_HINT_CELL_BASE:
3669 break;
3670 default:
3671 return -EINVAL;
3672 }
3673
3674 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003675
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003676 return r;
3677}
3678
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003679static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003680 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003681{
Johannes Berg4c476992010-10-04 21:36:35 +02003682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003683 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003684 struct wireless_dev *wdev = dev->ieee80211_ptr;
3685 struct mesh_config cur_params;
3686 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003687 void *hdr;
3688 struct nlattr *pinfoattr;
3689 struct sk_buff *msg;
3690
Johannes Berg29cbe682010-12-03 09:20:44 +01003691 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3692 return -EOPNOTSUPP;
3693
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003694 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003695 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003696
Johannes Berg29cbe682010-12-03 09:20:44 +01003697 wdev_lock(wdev);
3698 /* If not connected, get default parameters */
3699 if (!wdev->mesh_id_len)
3700 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3701 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003702 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003703 &cur_params);
3704 wdev_unlock(wdev);
3705
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003706 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003707 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003708
3709 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003711 if (!msg)
3712 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00003713 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003714 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003715 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003716 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003717 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003718 if (!pinfoattr)
3719 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003720 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3721 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3722 cur_params.dot11MeshRetryTimeout) ||
3723 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3724 cur_params.dot11MeshConfirmTimeout) ||
3725 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3726 cur_params.dot11MeshHoldingTimeout) ||
3727 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3728 cur_params.dot11MeshMaxPeerLinks) ||
3729 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3730 cur_params.dot11MeshMaxRetries) ||
3731 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3732 cur_params.dot11MeshTTL) ||
3733 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3734 cur_params.element_ttl) ||
3735 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3736 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003737 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3738 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003739 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3740 cur_params.dot11MeshHWMPmaxPREQretries) ||
3741 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3742 cur_params.path_refresh_time) ||
3743 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3744 cur_params.min_discovery_timeout) ||
3745 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3746 cur_params.dot11MeshHWMPactivePathTimeout) ||
3747 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3748 cur_params.dot11MeshHWMPpreqMinInterval) ||
3749 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3750 cur_params.dot11MeshHWMPperrMinInterval) ||
3751 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3752 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3753 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3754 cur_params.dot11MeshHWMPRootMode) ||
3755 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3756 cur_params.dot11MeshHWMPRannInterval) ||
3757 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3758 cur_params.dot11MeshGateAnnouncementProtocol) ||
3759 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3760 cur_params.dot11MeshForwarding) ||
3761 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003762 cur_params.rssi_threshold) ||
3763 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003764 cur_params.ht_opmode) ||
3765 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3766 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3767 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003768 cur_params.dot11MeshHWMProotInterval) ||
3769 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3770 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003771 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003772 nla_nest_end(msg, pinfoattr);
3773 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003774 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003775
Johannes Berg3b858752009-03-12 09:55:09 +01003776 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003777 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003778 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003779 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003780 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003781}
3782
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003783static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003784 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3785 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3786 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3787 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3788 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3789 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003790 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003791 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003792 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003793 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3794 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3795 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3796 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3797 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003798 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003799 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003800 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003801 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003802 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003803 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003804 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3805 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003806 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3807 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003808 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003809};
3810
Javier Cardonac80d5452010-12-16 17:37:49 -08003811static const struct nla_policy
3812 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003813 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003814 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3815 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003816 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003817 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003818 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003819 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003820};
3821
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003822static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003823 struct mesh_config *cfg,
3824 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003825{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003826 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003827 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003828
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003829#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3830do {\
3831 if (table[attr_num]) {\
3832 cfg->param = nla_fn(table[attr_num]); \
3833 mask |= (1 << (attr_num - 1)); \
3834 } \
3835} while (0);\
3836
3837
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003838 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003839 return -EINVAL;
3840 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003841 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003842 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003843 return -EINVAL;
3844
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003845 /* This makes sure that there aren't more than 32 mesh config
3846 * parameters (otherwise our bitfield scheme would not work.) */
3847 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3848
3849 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003851 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3852 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003854 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3855 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003856 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003857 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3858 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003859 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003860 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3861 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003862 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003863 mask, NL80211_MESHCONF_MAX_RETRIES,
3864 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003865 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003866 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003867 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003868 mask, NL80211_MESHCONF_ELEMENT_TTL,
3869 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003871 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3872 nla_get_u8);
3873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3874 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3875 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003877 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3878 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003879 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003880 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3881 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003882 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003883 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3884 nla_get_u16);
3885 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3886 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3887 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003888 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003889 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3890 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003891 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003892 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3893 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003895 dot11MeshHWMPnetDiameterTraversalTime, mask,
3896 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3897 nla_get_u16);
3898 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3899 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3900 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3901 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3902 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003903 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003904 dot11MeshGateAnnouncementProtocol, mask,
3905 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3906 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003907 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003908 mask, NL80211_MESHCONF_FORWARDING,
3909 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003911 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3912 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003913 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003914 mask, NL80211_MESHCONF_HT_OPMODE,
3915 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003916 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3917 mask,
3918 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3919 nla_get_u32);
3920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3921 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3922 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3924 dot11MeshHWMPconfirmationInterval, mask,
3925 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3926 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003927 if (mask_out)
3928 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003929
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003930 return 0;
3931
3932#undef FILL_IN_MESH_PARAM_IF_SET
3933}
3934
Javier Cardonac80d5452010-12-16 17:37:49 -08003935static int nl80211_parse_mesh_setup(struct genl_info *info,
3936 struct mesh_setup *setup)
3937{
3938 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3939
3940 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3941 return -EINVAL;
3942 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3943 info->attrs[NL80211_ATTR_MESH_SETUP],
3944 nl80211_mesh_setup_params_policy))
3945 return -EINVAL;
3946
Javier Cardonad299a1f2012-03-31 11:31:33 -07003947 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3948 setup->sync_method =
3949 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3950 IEEE80211_SYNC_METHOD_VENDOR :
3951 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3952
Javier Cardonac80d5452010-12-16 17:37:49 -08003953 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3954 setup->path_sel_proto =
3955 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3956 IEEE80211_PATH_PROTOCOL_VENDOR :
3957 IEEE80211_PATH_PROTOCOL_HWMP;
3958
3959 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3960 setup->path_metric =
3961 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3962 IEEE80211_PATH_METRIC_VENDOR :
3963 IEEE80211_PATH_METRIC_AIRTIME;
3964
Javier Cardona581a8b02011-04-07 15:08:27 -07003965
3966 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003967 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003968 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003969 if (!is_valid_ie_attr(ieattr))
3970 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003971 setup->ie = nla_data(ieattr);
3972 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003973 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003974 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3975 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003976
3977 return 0;
3978}
3979
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003980static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003981 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003982{
3983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3984 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003985 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003986 struct mesh_config cfg;
3987 u32 mask;
3988 int err;
3989
Johannes Berg29cbe682010-12-03 09:20:44 +01003990 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3991 return -EOPNOTSUPP;
3992
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003993 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003994 return -EOPNOTSUPP;
3995
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003996 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003997 if (err)
3998 return err;
3999
Johannes Berg29cbe682010-12-03 09:20:44 +01004000 wdev_lock(wdev);
4001 if (!wdev->mesh_id_len)
4002 err = -ENOLINK;
4003
4004 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004005 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01004006 mask, &cfg);
4007
4008 wdev_unlock(wdev);
4009
4010 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004011}
4012
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004013static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4014{
4015 struct sk_buff *msg;
4016 void *hdr = NULL;
4017 struct nlattr *nl_reg_rules;
4018 unsigned int i;
4019 int err = -EINVAL;
4020
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004021 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004022
4023 if (!cfg80211_regdomain)
4024 goto out;
4025
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004026 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004027 if (!msg) {
4028 err = -ENOBUFS;
4029 goto out;
4030 }
4031
Eric W. Biederman15e47302012-09-07 20:12:54 +00004032 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004033 NL80211_CMD_GET_REG);
4034 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004035 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004036
David S. Miller9360ffd2012-03-29 04:41:26 -04004037 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
4038 cfg80211_regdomain->alpha2) ||
4039 (cfg80211_regdomain->dfs_region &&
4040 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
4041 cfg80211_regdomain->dfs_region)))
4042 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004043
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004044 if (reg_last_request_cell_base() &&
4045 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4046 NL80211_USER_REG_HINT_CELL_BASE))
4047 goto nla_put_failure;
4048
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004049 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4050 if (!nl_reg_rules)
4051 goto nla_put_failure;
4052
4053 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
4054 struct nlattr *nl_reg_rule;
4055 const struct ieee80211_reg_rule *reg_rule;
4056 const struct ieee80211_freq_range *freq_range;
4057 const struct ieee80211_power_rule *power_rule;
4058
4059 reg_rule = &cfg80211_regdomain->reg_rules[i];
4060 freq_range = &reg_rule->freq_range;
4061 power_rule = &reg_rule->power_rule;
4062
4063 nl_reg_rule = nla_nest_start(msg, i);
4064 if (!nl_reg_rule)
4065 goto nla_put_failure;
4066
David S. Miller9360ffd2012-03-29 04:41:26 -04004067 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4068 reg_rule->flags) ||
4069 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4070 freq_range->start_freq_khz) ||
4071 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4072 freq_range->end_freq_khz) ||
4073 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4074 freq_range->max_bandwidth_khz) ||
4075 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4076 power_rule->max_antenna_gain) ||
4077 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4078 power_rule->max_eirp))
4079 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004080
4081 nla_nest_end(msg, nl_reg_rule);
4082 }
4083
4084 nla_nest_end(msg, nl_reg_rules);
4085
4086 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004087 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004088 goto out;
4089
4090nla_put_failure:
4091 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004092put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004093 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004094 err = -EMSGSIZE;
4095out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004096 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004097 return err;
4098}
4099
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004100static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4101{
4102 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4103 struct nlattr *nl_reg_rule;
4104 char *alpha2 = NULL;
4105 int rem_reg_rules = 0, r = 0;
4106 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004107 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004108 struct ieee80211_regdomain *rd = NULL;
4109
4110 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4111 return -EINVAL;
4112
4113 if (!info->attrs[NL80211_ATTR_REG_RULES])
4114 return -EINVAL;
4115
4116 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4117
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004118 if (info->attrs[NL80211_ATTR_DFS_REGION])
4119 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4120
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004121 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4122 rem_reg_rules) {
4123 num_rules++;
4124 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004125 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004126 }
4127
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004128 mutex_lock(&cfg80211_mutex);
4129
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004130 if (!reg_is_valid_request(alpha2)) {
4131 r = -EINVAL;
4132 goto bad_reg;
4133 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004134
4135 size_of_regd = sizeof(struct ieee80211_regdomain) +
4136 (num_rules * sizeof(struct ieee80211_reg_rule));
4137
4138 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004139 if (!rd) {
4140 r = -ENOMEM;
4141 goto bad_reg;
4142 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004143
4144 rd->n_reg_rules = num_rules;
4145 rd->alpha2[0] = alpha2[0];
4146 rd->alpha2[1] = alpha2[1];
4147
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004148 /*
4149 * Disable DFS master mode if the DFS region was
4150 * not supported or known on this kernel.
4151 */
4152 if (reg_supported_dfs_region(dfs_region))
4153 rd->dfs_region = dfs_region;
4154
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004155 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4156 rem_reg_rules) {
4157 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4158 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4159 reg_rule_policy);
4160 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4161 if (r)
4162 goto bad_reg;
4163
4164 rule_idx++;
4165
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004166 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4167 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004168 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004169 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004170 }
4171
4172 BUG_ON(rule_idx != num_rules);
4173
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004174 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004175
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004176 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004177
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004178 return r;
4179
Johannes Bergd2372b32008-10-24 20:32:20 +02004180 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004181 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004182 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004183 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004184}
4185
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004186static int validate_scan_freqs(struct nlattr *freqs)
4187{
4188 struct nlattr *attr1, *attr2;
4189 int n_channels = 0, tmp1, tmp2;
4190
4191 nla_for_each_nested(attr1, freqs, tmp1) {
4192 n_channels++;
4193 /*
4194 * Some hardware has a limited channel list for
4195 * scanning, and it is pretty much nonsensical
4196 * to scan for a channel twice, so disallow that
4197 * and don't require drivers to check that the
4198 * channel list they get isn't longer than what
4199 * they can scan, as long as they can scan all
4200 * the channels they registered at once.
4201 */
4202 nla_for_each_nested(attr2, freqs, tmp2)
4203 if (attr1 != attr2 &&
4204 nla_get_u32(attr1) == nla_get_u32(attr2))
4205 return 0;
4206 }
4207
4208 return n_channels;
4209}
4210
Johannes Berg2a519312009-02-10 21:25:55 +01004211static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4212{
Johannes Berg4c476992010-10-04 21:36:35 +02004213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02004214 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004215 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004216 struct nlattr *attr;
4217 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004218 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004219 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004220
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004221 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4222 return -EINVAL;
4223
Johannes Berg79c97e92009-07-07 03:56:12 +02004224 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004225
Johannes Berg4c476992010-10-04 21:36:35 +02004226 if (!rdev->ops->scan)
4227 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004228
Johannes Berg4c476992010-10-04 21:36:35 +02004229 if (rdev->scan_req)
4230 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004231
4232 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004233 n_channels = validate_scan_freqs(
4234 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004235 if (!n_channels)
4236 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004237 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004238 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004239 n_channels = 0;
4240
Johannes Berg2a519312009-02-10 21:25:55 +01004241 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4242 if (wiphy->bands[band])
4243 n_channels += wiphy->bands[band]->n_channels;
4244 }
4245
4246 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4247 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4248 n_ssids++;
4249
Johannes Berg4c476992010-10-04 21:36:35 +02004250 if (n_ssids > wiphy->max_scan_ssids)
4251 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004252
Jouni Malinen70692ad2009-02-16 19:39:13 +02004253 if (info->attrs[NL80211_ATTR_IE])
4254 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4255 else
4256 ie_len = 0;
4257
Johannes Berg4c476992010-10-04 21:36:35 +02004258 if (ie_len > wiphy->max_scan_ie_len)
4259 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004260
Johannes Berg2a519312009-02-10 21:25:55 +01004261 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004262 + sizeof(*request->ssids) * n_ssids
4263 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004264 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004265 if (!request)
4266 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004267
Johannes Berg2a519312009-02-10 21:25:55 +01004268 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004269 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004270 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004271 if (ie_len) {
4272 if (request->ssids)
4273 request->ie = (void *)(request->ssids + n_ssids);
4274 else
4275 request->ie = (void *)(request->channels + n_channels);
4276 }
Johannes Berg2a519312009-02-10 21:25:55 +01004277
Johannes Berg584991d2009-11-02 13:32:03 +01004278 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004279 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4280 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004281 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004282 struct ieee80211_channel *chan;
4283
4284 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4285
4286 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004287 err = -EINVAL;
4288 goto out_free;
4289 }
Johannes Berg584991d2009-11-02 13:32:03 +01004290
4291 /* ignore disabled channels */
4292 if (chan->flags & IEEE80211_CHAN_DISABLED)
4293 continue;
4294
4295 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004296 i++;
4297 }
4298 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004299 enum ieee80211_band band;
4300
Johannes Berg2a519312009-02-10 21:25:55 +01004301 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004302 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4303 int j;
4304 if (!wiphy->bands[band])
4305 continue;
4306 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004307 struct ieee80211_channel *chan;
4308
4309 chan = &wiphy->bands[band]->channels[j];
4310
4311 if (chan->flags & IEEE80211_CHAN_DISABLED)
4312 continue;
4313
4314 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004315 i++;
4316 }
4317 }
4318 }
4319
Johannes Berg584991d2009-11-02 13:32:03 +01004320 if (!i) {
4321 err = -EINVAL;
4322 goto out_free;
4323 }
4324
4325 request->n_channels = i;
4326
Johannes Berg2a519312009-02-10 21:25:55 +01004327 i = 0;
4328 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4329 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004330 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004331 err = -EINVAL;
4332 goto out_free;
4333 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004334 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004335 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004336 i++;
4337 }
4338 }
4339
Jouni Malinen70692ad2009-02-16 19:39:13 +02004340 if (info->attrs[NL80211_ATTR_IE]) {
4341 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004342 memcpy((void *)request->ie,
4343 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004344 request->ie_len);
4345 }
4346
Johannes Berg34850ab2011-07-18 18:08:35 +02004347 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004348 if (wiphy->bands[i])
4349 request->rates[i] =
4350 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004351
4352 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4353 nla_for_each_nested(attr,
4354 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4355 tmp) {
4356 enum ieee80211_band band = nla_type(attr);
4357
Dan Carpenter84404622011-07-29 11:52:18 +03004358 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004359 err = -EINVAL;
4360 goto out_free;
4361 }
4362 err = ieee80211_get_ratemask(wiphy->bands[band],
4363 nla_data(attr),
4364 nla_len(attr),
4365 &request->rates[band]);
4366 if (err)
4367 goto out_free;
4368 }
4369 }
4370
Sam Leffler46856bb2012-10-11 21:03:32 -07004371 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07004372 request->flags = nla_get_u32(
4373 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler46856bb2012-10-11 21:03:32 -07004374 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
4375 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
4376 err = -EOPNOTSUPP;
4377 goto out_free;
4378 }
4379 }
Sam Lefflered4737712012-10-11 21:03:31 -07004380
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304381 request->no_cck =
4382 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4383
Johannes Bergfd014282012-06-18 19:17:03 +02004384 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004385 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004386
Johannes Berg79c97e92009-07-07 03:56:12 +02004387 rdev->scan_req = request;
Johannes Bergfd014282012-06-18 19:17:03 +02004388 err = rdev->ops->scan(&rdev->wiphy, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004389
Johannes Berg463d0182009-07-14 00:33:35 +02004390 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02004391 nl80211_send_scan_start(rdev, wdev);
4392 if (wdev->netdev)
4393 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02004394 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004395 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004396 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004397 kfree(request);
4398 }
Johannes Berg3b858752009-03-12 09:55:09 +01004399
Johannes Berg2a519312009-02-10 21:25:55 +01004400 return err;
4401}
4402
Luciano Coelho807f8a82011-05-11 17:09:35 +03004403static int nl80211_start_sched_scan(struct sk_buff *skb,
4404 struct genl_info *info)
4405{
4406 struct cfg80211_sched_scan_request *request;
4407 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4408 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004409 struct nlattr *attr;
4410 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004411 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004412 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004413 enum ieee80211_band band;
4414 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004415 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004416
4417 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4418 !rdev->ops->sched_scan_start)
4419 return -EOPNOTSUPP;
4420
4421 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4422 return -EINVAL;
4423
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004424 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4425 return -EINVAL;
4426
4427 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4428 if (interval == 0)
4429 return -EINVAL;
4430
Luciano Coelho807f8a82011-05-11 17:09:35 +03004431 wiphy = &rdev->wiphy;
4432
4433 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4434 n_channels = validate_scan_freqs(
4435 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4436 if (!n_channels)
4437 return -EINVAL;
4438 } else {
4439 n_channels = 0;
4440
4441 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4442 if (wiphy->bands[band])
4443 n_channels += wiphy->bands[band]->n_channels;
4444 }
4445
4446 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4447 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4448 tmp)
4449 n_ssids++;
4450
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004451 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004452 return -EINVAL;
4453
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004454 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4455 nla_for_each_nested(attr,
4456 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4457 tmp)
4458 n_match_sets++;
4459
4460 if (n_match_sets > wiphy->max_match_sets)
4461 return -EINVAL;
4462
Luciano Coelho807f8a82011-05-11 17:09:35 +03004463 if (info->attrs[NL80211_ATTR_IE])
4464 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4465 else
4466 ie_len = 0;
4467
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004468 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004469 return -EINVAL;
4470
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004471 mutex_lock(&rdev->sched_scan_mtx);
4472
4473 if (rdev->sched_scan_req) {
4474 err = -EINPROGRESS;
4475 goto out;
4476 }
4477
Luciano Coelho807f8a82011-05-11 17:09:35 +03004478 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004479 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004480 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004481 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004482 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004483 if (!request) {
4484 err = -ENOMEM;
4485 goto out;
4486 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004487
4488 if (n_ssids)
4489 request->ssids = (void *)&request->channels[n_channels];
4490 request->n_ssids = n_ssids;
4491 if (ie_len) {
4492 if (request->ssids)
4493 request->ie = (void *)(request->ssids + n_ssids);
4494 else
4495 request->ie = (void *)(request->channels + n_channels);
4496 }
4497
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004498 if (n_match_sets) {
4499 if (request->ie)
4500 request->match_sets = (void *)(request->ie + ie_len);
4501 else if (request->ssids)
4502 request->match_sets =
4503 (void *)(request->ssids + n_ssids);
4504 else
4505 request->match_sets =
4506 (void *)(request->channels + n_channels);
4507 }
4508 request->n_match_sets = n_match_sets;
4509
Luciano Coelho807f8a82011-05-11 17:09:35 +03004510 i = 0;
4511 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4512 /* user specified, bail out if channel not found */
4513 nla_for_each_nested(attr,
4514 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4515 tmp) {
4516 struct ieee80211_channel *chan;
4517
4518 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4519
4520 if (!chan) {
4521 err = -EINVAL;
4522 goto out_free;
4523 }
4524
4525 /* ignore disabled channels */
4526 if (chan->flags & IEEE80211_CHAN_DISABLED)
4527 continue;
4528
4529 request->channels[i] = chan;
4530 i++;
4531 }
4532 } else {
4533 /* all channels */
4534 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4535 int j;
4536 if (!wiphy->bands[band])
4537 continue;
4538 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4539 struct ieee80211_channel *chan;
4540
4541 chan = &wiphy->bands[band]->channels[j];
4542
4543 if (chan->flags & IEEE80211_CHAN_DISABLED)
4544 continue;
4545
4546 request->channels[i] = chan;
4547 i++;
4548 }
4549 }
4550 }
4551
4552 if (!i) {
4553 err = -EINVAL;
4554 goto out_free;
4555 }
4556
4557 request->n_channels = i;
4558
4559 i = 0;
4560 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4561 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4562 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004563 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004564 err = -EINVAL;
4565 goto out_free;
4566 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004567 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004568 memcpy(request->ssids[i].ssid, nla_data(attr),
4569 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004570 i++;
4571 }
4572 }
4573
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004574 i = 0;
4575 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4576 nla_for_each_nested(attr,
4577 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4578 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004579 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004580
4581 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4582 nla_data(attr), nla_len(attr),
4583 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004584 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004585 if (ssid) {
4586 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4587 err = -EINVAL;
4588 goto out_free;
4589 }
4590 memcpy(request->match_sets[i].ssid.ssid,
4591 nla_data(ssid), nla_len(ssid));
4592 request->match_sets[i].ssid.ssid_len =
4593 nla_len(ssid);
4594 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004595 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4596 if (rssi)
4597 request->rssi_thold = nla_get_u32(rssi);
4598 else
4599 request->rssi_thold =
4600 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004601 i++;
4602 }
4603 }
4604
Luciano Coelho807f8a82011-05-11 17:09:35 +03004605 if (info->attrs[NL80211_ATTR_IE]) {
4606 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4607 memcpy((void *)request->ie,
4608 nla_data(info->attrs[NL80211_ATTR_IE]),
4609 request->ie_len);
4610 }
4611
Sam Leffler46856bb2012-10-11 21:03:32 -07004612 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07004613 request->flags = nla_get_u32(
4614 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler46856bb2012-10-11 21:03:32 -07004615 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
4616 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
4617 err = -EOPNOTSUPP;
4618 goto out_free;
4619 }
4620 }
Sam Lefflered4737712012-10-11 21:03:31 -07004621
Luciano Coelho807f8a82011-05-11 17:09:35 +03004622 request->dev = dev;
4623 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004624 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004625
4626 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4627 if (!err) {
4628 rdev->sched_scan_req = request;
4629 nl80211_send_sched_scan(rdev, dev,
4630 NL80211_CMD_START_SCHED_SCAN);
4631 goto out;
4632 }
4633
4634out_free:
4635 kfree(request);
4636out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004637 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004638 return err;
4639}
4640
4641static int nl80211_stop_sched_scan(struct sk_buff *skb,
4642 struct genl_info *info)
4643{
4644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004645 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004646
4647 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4648 !rdev->ops->sched_scan_stop)
4649 return -EOPNOTSUPP;
4650
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004651 mutex_lock(&rdev->sched_scan_mtx);
4652 err = __cfg80211_stop_sched_scan(rdev, false);
4653 mutex_unlock(&rdev->sched_scan_mtx);
4654
4655 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004656}
4657
Johannes Berg9720bb32011-06-21 09:45:33 +02004658static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4659 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004660 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004661 struct wireless_dev *wdev,
4662 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004663{
Johannes Berg48ab9052009-07-10 18:42:31 +02004664 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004665 void *hdr;
4666 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004667
4668 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004669
Eric W. Biederman15e47302012-09-07 20:12:54 +00004670 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004671 NL80211_CMD_NEW_SCAN_RESULTS);
4672 if (!hdr)
4673 return -1;
4674
Johannes Berg9720bb32011-06-21 09:45:33 +02004675 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4676
David S. Miller9360ffd2012-03-29 04:41:26 -04004677 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4678 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4679 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004680
4681 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4682 if (!bss)
4683 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004684 if ((!is_zero_ether_addr(res->bssid) &&
4685 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4686 (res->information_elements && res->len_information_elements &&
4687 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4688 res->len_information_elements,
4689 res->information_elements)) ||
4690 (res->beacon_ies && res->len_beacon_ies &&
4691 res->beacon_ies != res->information_elements &&
4692 nla_put(msg, NL80211_BSS_BEACON_IES,
4693 res->len_beacon_ies, res->beacon_ies)))
4694 goto nla_put_failure;
4695 if (res->tsf &&
4696 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4697 goto nla_put_failure;
4698 if (res->beacon_interval &&
4699 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4700 goto nla_put_failure;
4701 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4702 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4703 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4704 jiffies_to_msecs(jiffies - intbss->ts)))
4705 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004706
Johannes Berg77965c92009-02-18 18:45:06 +01004707 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004708 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004709 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4710 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004711 break;
4712 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004713 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4714 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004715 break;
4716 default:
4717 break;
4718 }
4719
Johannes Berg48ab9052009-07-10 18:42:31 +02004720 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004721 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004722 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004723 if (intbss == wdev->current_bss &&
4724 nla_put_u32(msg, NL80211_BSS_STATUS,
4725 NL80211_BSS_STATUS_ASSOCIATED))
4726 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004727 break;
4728 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004729 if (intbss == wdev->current_bss &&
4730 nla_put_u32(msg, NL80211_BSS_STATUS,
4731 NL80211_BSS_STATUS_IBSS_JOINED))
4732 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004733 break;
4734 default:
4735 break;
4736 }
4737
Johannes Berg2a519312009-02-10 21:25:55 +01004738 nla_nest_end(msg, bss);
4739
4740 return genlmsg_end(msg, hdr);
4741
4742 nla_put_failure:
4743 genlmsg_cancel(msg, hdr);
4744 return -EMSGSIZE;
4745}
4746
4747static int nl80211_dump_scan(struct sk_buff *skb,
4748 struct netlink_callback *cb)
4749{
Johannes Berg48ab9052009-07-10 18:42:31 +02004750 struct cfg80211_registered_device *rdev;
4751 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004752 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004753 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004754 int start = cb->args[1], idx = 0;
4755 int err;
4756
Johannes Berg67748892010-10-04 21:14:06 +02004757 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4758 if (err)
4759 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004760
Johannes Berg48ab9052009-07-10 18:42:31 +02004761 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004762
Johannes Berg48ab9052009-07-10 18:42:31 +02004763 wdev_lock(wdev);
4764 spin_lock_bh(&rdev->bss_lock);
4765 cfg80211_bss_expire(rdev);
4766
Johannes Berg9720bb32011-06-21 09:45:33 +02004767 cb->seq = rdev->bss_generation;
4768
Johannes Berg48ab9052009-07-10 18:42:31 +02004769 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004770 if (++idx <= start)
4771 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004772 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004773 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004774 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004775 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004776 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004777 }
4778 }
4779
Johannes Berg48ab9052009-07-10 18:42:31 +02004780 spin_unlock_bh(&rdev->bss_lock);
4781 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004782
4783 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004784 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004785
Johannes Berg67748892010-10-04 21:14:06 +02004786 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004787}
4788
Eric W. Biederman15e47302012-09-07 20:12:54 +00004789static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01004790 int flags, struct net_device *dev,
4791 struct survey_info *survey)
4792{
4793 void *hdr;
4794 struct nlattr *infoattr;
4795
Eric W. Biederman15e47302012-09-07 20:12:54 +00004796 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01004797 NL80211_CMD_NEW_SURVEY_RESULTS);
4798 if (!hdr)
4799 return -ENOMEM;
4800
David S. Miller9360ffd2012-03-29 04:41:26 -04004801 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4802 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004803
4804 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4805 if (!infoattr)
4806 goto nla_put_failure;
4807
David S. Miller9360ffd2012-03-29 04:41:26 -04004808 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4809 survey->channel->center_freq))
4810 goto nla_put_failure;
4811
4812 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4813 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4814 goto nla_put_failure;
4815 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4816 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4817 goto nla_put_failure;
4818 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4819 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4820 survey->channel_time))
4821 goto nla_put_failure;
4822 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4823 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4824 survey->channel_time_busy))
4825 goto nla_put_failure;
4826 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4827 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4828 survey->channel_time_ext_busy))
4829 goto nla_put_failure;
4830 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4831 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4832 survey->channel_time_rx))
4833 goto nla_put_failure;
4834 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4835 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4836 survey->channel_time_tx))
4837 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004838
4839 nla_nest_end(msg, infoattr);
4840
4841 return genlmsg_end(msg, hdr);
4842
4843 nla_put_failure:
4844 genlmsg_cancel(msg, hdr);
4845 return -EMSGSIZE;
4846}
4847
4848static int nl80211_dump_survey(struct sk_buff *skb,
4849 struct netlink_callback *cb)
4850{
4851 struct survey_info survey;
4852 struct cfg80211_registered_device *dev;
4853 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004854 int survey_idx = cb->args[1];
4855 int res;
4856
Johannes Berg67748892010-10-04 21:14:06 +02004857 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4858 if (res)
4859 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004860
4861 if (!dev->ops->dump_survey) {
4862 res = -EOPNOTSUPP;
4863 goto out_err;
4864 }
4865
4866 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004867 struct ieee80211_channel *chan;
4868
Holger Schurig61fa7132009-11-11 12:25:40 +01004869 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4870 &survey);
4871 if (res == -ENOENT)
4872 break;
4873 if (res)
4874 goto out_err;
4875
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004876 /* Survey without a channel doesn't make sense */
4877 if (!survey.channel) {
4878 res = -EINVAL;
4879 goto out;
4880 }
4881
4882 chan = ieee80211_get_channel(&dev->wiphy,
4883 survey.channel->center_freq);
4884 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4885 survey_idx++;
4886 continue;
4887 }
4888
Holger Schurig61fa7132009-11-11 12:25:40 +01004889 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004890 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01004891 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4892 netdev,
4893 &survey) < 0)
4894 goto out;
4895 survey_idx++;
4896 }
4897
4898 out:
4899 cb->args[1] = survey_idx;
4900 res = skb->len;
4901 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004902 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004903 return res;
4904}
4905
Samuel Ortizb23aa672009-07-01 21:26:54 +02004906static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4907{
4908 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4909 NL80211_WPA_VERSION_2));
4910}
4911
Jouni Malinen636a5d32009-03-19 13:39:22 +02004912static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4913{
Johannes Berg4c476992010-10-04 21:36:35 +02004914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4915 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004916 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004917 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
4918 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004919 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004920 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004921 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004922
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4924 return -EINVAL;
4925
4926 if (!info->attrs[NL80211_ATTR_MAC])
4927 return -EINVAL;
4928
Jouni Malinen17780922009-03-27 20:52:47 +02004929 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4930 return -EINVAL;
4931
Johannes Berg19957bb2009-07-02 17:20:43 +02004932 if (!info->attrs[NL80211_ATTR_SSID])
4933 return -EINVAL;
4934
4935 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4936 return -EINVAL;
4937
Johannes Bergfffd0932009-07-08 14:22:54 +02004938 err = nl80211_parse_key(info, &key);
4939 if (err)
4940 return err;
4941
4942 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004943 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4944 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004945 if (!key.p.key || !key.p.key_len)
4946 return -EINVAL;
4947 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4948 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4949 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4950 key.p.key_len != WLAN_KEY_LEN_WEP104))
4951 return -EINVAL;
4952 if (key.idx > 4)
4953 return -EINVAL;
4954 } else {
4955 key.p.key_len = 0;
4956 key.p.key = NULL;
4957 }
4958
Johannes Bergafea0b72010-08-10 09:46:42 +02004959 if (key.idx >= 0) {
4960 int i;
4961 bool ok = false;
4962 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4963 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4964 ok = true;
4965 break;
4966 }
4967 }
Johannes Berg4c476992010-10-04 21:36:35 +02004968 if (!ok)
4969 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004970 }
4971
Johannes Berg4c476992010-10-04 21:36:35 +02004972 if (!rdev->ops->auth)
4973 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004974
Johannes Berg074ac8d2010-09-16 14:58:22 +02004975 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004976 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4977 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004978
Johannes Berg19957bb2009-07-02 17:20:43 +02004979 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004980 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004981 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004982 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4983 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004984
Johannes Berg19957bb2009-07-02 17:20:43 +02004985 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4986 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4987
4988 if (info->attrs[NL80211_ATTR_IE]) {
4989 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4990 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4991 }
4992
4993 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004994 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02004995 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004996
Jouni Malinene39e5b52012-09-30 19:29:39 +03004997 if (auth_type == NL80211_AUTHTYPE_SAE &&
4998 !info->attrs[NL80211_ATTR_SAE_DATA])
4999 return -EINVAL;
5000
5001 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5002 if (auth_type != NL80211_AUTHTYPE_SAE)
5003 return -EINVAL;
5004 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5005 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5006 /* need to include at least Auth Transaction and Status Code */
5007 if (sae_data_len < 4)
5008 return -EINVAL;
5009 }
5010
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005011 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5012
Johannes Berg95de8172012-01-20 13:55:25 +01005013 /*
5014 * Since we no longer track auth state, ignore
5015 * requests to only change local state.
5016 */
5017 if (local_state_change)
5018 return 0;
5019
Johannes Berg4c476992010-10-04 21:36:35 +02005020 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5021 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005022 key.p.key, key.p.key_len, key.idx,
5023 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005024}
5025
Johannes Bergc0692b82010-08-27 14:26:53 +03005026static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5027 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005028 struct cfg80211_crypto_settings *settings,
5029 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005030{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005031 memset(settings, 0, sizeof(*settings));
5032
Samuel Ortizb23aa672009-07-01 21:26:54 +02005033 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5034
Johannes Bergc0692b82010-08-27 14:26:53 +03005035 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5036 u16 proto;
5037 proto = nla_get_u16(
5038 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5039 settings->control_port_ethertype = cpu_to_be16(proto);
5040 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5041 proto != ETH_P_PAE)
5042 return -EINVAL;
5043 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5044 settings->control_port_no_encrypt = true;
5045 } else
5046 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5047
Samuel Ortizb23aa672009-07-01 21:26:54 +02005048 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5049 void *data;
5050 int len, i;
5051
5052 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5053 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5054 settings->n_ciphers_pairwise = len / sizeof(u32);
5055
5056 if (len % sizeof(u32))
5057 return -EINVAL;
5058
Johannes Berg3dc27d22009-07-02 21:36:37 +02005059 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005060 return -EINVAL;
5061
5062 memcpy(settings->ciphers_pairwise, data, len);
5063
5064 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005065 if (!cfg80211_supported_cipher_suite(
5066 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005067 settings->ciphers_pairwise[i]))
5068 return -EINVAL;
5069 }
5070
5071 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5072 settings->cipher_group =
5073 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005074 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5075 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005076 return -EINVAL;
5077 }
5078
5079 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5080 settings->wpa_versions =
5081 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5082 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5083 return -EINVAL;
5084 }
5085
5086 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5087 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005088 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005089
5090 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5091 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5092 settings->n_akm_suites = len / sizeof(u32);
5093
5094 if (len % sizeof(u32))
5095 return -EINVAL;
5096
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005097 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5098 return -EINVAL;
5099
Samuel Ortizb23aa672009-07-01 21:26:54 +02005100 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005101 }
5102
5103 return 0;
5104}
5105
Jouni Malinen636a5d32009-03-19 13:39:22 +02005106static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5107{
Johannes Berg4c476992010-10-04 21:36:35 +02005108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5109 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005110 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005111 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005112 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005113 int err, ssid_len, ie_len = 0;
5114 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005115 u32 flags = 0;
5116 struct ieee80211_ht_cap *ht_capa = NULL;
5117 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005118
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005119 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5120 return -EINVAL;
5121
5122 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005123 !info->attrs[NL80211_ATTR_SSID] ||
5124 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005125 return -EINVAL;
5126
Johannes Berg4c476992010-10-04 21:36:35 +02005127 if (!rdev->ops->assoc)
5128 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005129
Johannes Berg074ac8d2010-09-16 14:58:22 +02005130 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005131 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5132 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005133
Johannes Berg19957bb2009-07-02 17:20:43 +02005134 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005135
Johannes Berg19957bb2009-07-02 17:20:43 +02005136 chan = ieee80211_get_channel(&rdev->wiphy,
5137 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005138 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5139 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005140
Johannes Berg19957bb2009-07-02 17:20:43 +02005141 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5142 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005143
5144 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005145 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5146 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005147 }
5148
Jouni Malinendc6382c2009-05-06 22:09:37 +03005149 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005150 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03005151 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005152 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02005153 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02005154 else if (mfp != NL80211_MFP_NO)
5155 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03005156 }
5157
Johannes Berg3e5d7642009-07-07 14:37:26 +02005158 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5159 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5160
Ben Greear7e7c8922011-11-18 11:31:59 -08005161 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5162 flags |= ASSOC_REQ_DISABLE_HT;
5163
5164 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5165 ht_capa_mask =
5166 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5167
5168 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5169 if (!ht_capa_mask)
5170 return -EINVAL;
5171 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5172 }
5173
Johannes Bergc0692b82010-08-27 14:26:53 +03005174 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005175 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02005176 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5177 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08005178 &crypto, flags, ht_capa,
5179 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005180
Jouni Malinen636a5d32009-03-19 13:39:22 +02005181 return err;
5182}
5183
5184static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5185{
Johannes Berg4c476992010-10-04 21:36:35 +02005186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5187 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005188 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005189 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005190 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005191 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005192
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005193 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5194 return -EINVAL;
5195
5196 if (!info->attrs[NL80211_ATTR_MAC])
5197 return -EINVAL;
5198
5199 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5200 return -EINVAL;
5201
Johannes Berg4c476992010-10-04 21:36:35 +02005202 if (!rdev->ops->deauth)
5203 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005204
Johannes Berg074ac8d2010-09-16 14:58:22 +02005205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5207 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005208
Johannes Berg19957bb2009-07-02 17:20:43 +02005209 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005210
Johannes Berg19957bb2009-07-02 17:20:43 +02005211 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5212 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005213 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005214 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005215 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005216
5217 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005218 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5219 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005220 }
5221
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005222 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5223
Johannes Berg4c476992010-10-04 21:36:35 +02005224 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5225 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005226}
5227
5228static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5229{
Johannes Berg4c476992010-10-04 21:36:35 +02005230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5231 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005232 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005233 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005234 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005235 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005236
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005237 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5238 return -EINVAL;
5239
5240 if (!info->attrs[NL80211_ATTR_MAC])
5241 return -EINVAL;
5242
5243 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5244 return -EINVAL;
5245
Johannes Berg4c476992010-10-04 21:36:35 +02005246 if (!rdev->ops->disassoc)
5247 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005248
Johannes Berg074ac8d2010-09-16 14:58:22 +02005249 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005250 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5251 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005252
Johannes Berg19957bb2009-07-02 17:20:43 +02005253 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005254
Johannes Berg19957bb2009-07-02 17:20:43 +02005255 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5256 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005257 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005258 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005259 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005260
5261 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005262 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5263 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005264 }
5265
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005266 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5267
Johannes Berg4c476992010-10-04 21:36:35 +02005268 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5269 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005270}
5271
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005272static bool
5273nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5274 int mcast_rate[IEEE80211_NUM_BANDS],
5275 int rateval)
5276{
5277 struct wiphy *wiphy = &rdev->wiphy;
5278 bool found = false;
5279 int band, i;
5280
5281 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5282 struct ieee80211_supported_band *sband;
5283
5284 sband = wiphy->bands[band];
5285 if (!sband)
5286 continue;
5287
5288 for (i = 0; i < sband->n_bitrates; i++) {
5289 if (sband->bitrates[i].bitrate == rateval) {
5290 mcast_rate[band] = i + 1;
5291 found = true;
5292 break;
5293 }
5294 }
5295 }
5296
5297 return found;
5298}
5299
Johannes Berg04a773a2009-04-19 21:24:32 +02005300static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5301{
Johannes Berg4c476992010-10-04 21:36:35 +02005302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5303 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005304 struct cfg80211_ibss_params ibss;
5305 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005306 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005307 int err;
5308
Johannes Berg8e30bc52009-04-22 17:45:38 +02005309 memset(&ibss, 0, sizeof(ibss));
5310
Johannes Berg04a773a2009-04-19 21:24:32 +02005311 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5312 return -EINVAL;
5313
5314 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5315 !info->attrs[NL80211_ATTR_SSID] ||
5316 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5317 return -EINVAL;
5318
Johannes Berg8e30bc52009-04-22 17:45:38 +02005319 ibss.beacon_interval = 100;
5320
5321 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5322 ibss.beacon_interval =
5323 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5324 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5325 return -EINVAL;
5326 }
5327
Johannes Berg4c476992010-10-04 21:36:35 +02005328 if (!rdev->ops->join_ibss)
5329 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005330
Johannes Berg4c476992010-10-04 21:36:35 +02005331 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5332 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005333
Johannes Berg79c97e92009-07-07 03:56:12 +02005334 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005335
Johannes Berg39193492011-09-16 13:45:25 +02005336 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005337 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005338
5339 if (!is_valid_ether_addr(ibss.bssid))
5340 return -EINVAL;
5341 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005342 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5343 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5344
5345 if (info->attrs[NL80211_ATTR_IE]) {
5346 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5347 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5348 }
5349
Alexander Simon54858ee2011-11-30 16:56:32 +01005350 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5351 enum nl80211_channel_type channel_type;
5352
Johannes Bergcd6c6592012-05-10 21:27:18 +02005353 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee2011-11-30 16:56:32 +01005354 return -EINVAL;
5355
5356 if (channel_type != NL80211_CHAN_NO_HT &&
5357 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5358 return -EINVAL;
5359
5360 ibss.channel_type = channel_type;
5361 } else {
5362 ibss.channel_type = NL80211_CHAN_NO_HT;
5363 }
5364
5365 ibss.channel = rdev_freq_to_chan(rdev,
5366 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5367 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005368 if (!ibss.channel ||
5369 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005370 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5371 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005372
Alexander Simon54858ee2011-11-30 16:56:32 +01005373 /* Both channels should be able to initiate communication */
5374 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5375 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5376 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5377 ibss.channel_type))
5378 return -EINVAL;
5379
Johannes Berg04a773a2009-04-19 21:24:32 +02005380 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005381 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005382
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005383 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5384 u8 *rates =
5385 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5386 int n_rates =
5387 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5388 struct ieee80211_supported_band *sband =
5389 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005390
Johannes Berg34850ab2011-07-18 18:08:35 +02005391 err = ieee80211_get_ratemask(sband, rates, n_rates,
5392 &ibss.basic_rates);
5393 if (err)
5394 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005395 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005396
5397 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5398 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5399 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5400 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005401
Johannes Berg4c476992010-10-04 21:36:35 +02005402 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5403 connkeys = nl80211_parse_connkeys(rdev,
5404 info->attrs[NL80211_ATTR_KEYS]);
5405 if (IS_ERR(connkeys))
5406 return PTR_ERR(connkeys);
5407 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005408
Antonio Quartulli267335d2012-01-31 20:25:47 +01005409 ibss.control_port =
5410 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5411
Johannes Berg4c476992010-10-04 21:36:35 +02005412 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005413 if (err)
5414 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005415 return err;
5416}
5417
5418static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5419{
Johannes Berg4c476992010-10-04 21:36:35 +02005420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5421 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005422
Johannes Berg4c476992010-10-04 21:36:35 +02005423 if (!rdev->ops->leave_ibss)
5424 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005425
Johannes Berg4c476992010-10-04 21:36:35 +02005426 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5427 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005428
Johannes Berg4c476992010-10-04 21:36:35 +02005429 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005430}
5431
Johannes Bergaff89a92009-07-01 21:26:51 +02005432#ifdef CONFIG_NL80211_TESTMODE
5433static struct genl_multicast_group nl80211_testmode_mcgrp = {
5434 .name = "testmode",
5435};
5436
5437static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5438{
Johannes Berg4c476992010-10-04 21:36:35 +02005439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005440 int err;
5441
5442 if (!info->attrs[NL80211_ATTR_TESTDATA])
5443 return -EINVAL;
5444
Johannes Bergaff89a92009-07-01 21:26:51 +02005445 err = -EOPNOTSUPP;
5446 if (rdev->ops->testmode_cmd) {
5447 rdev->testmode_info = info;
5448 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5449 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5450 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5451 rdev->testmode_info = NULL;
5452 }
5453
Johannes Bergaff89a92009-07-01 21:26:51 +02005454 return err;
5455}
5456
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005457static int nl80211_testmode_dump(struct sk_buff *skb,
5458 struct netlink_callback *cb)
5459{
Johannes Berg00918d32011-12-13 17:22:05 +01005460 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005461 int err;
5462 long phy_idx;
5463 void *data = NULL;
5464 int data_len = 0;
5465
5466 if (cb->args[0]) {
5467 /*
5468 * 0 is a valid index, but not valid for args[0],
5469 * so we need to offset by 1.
5470 */
5471 phy_idx = cb->args[0] - 1;
5472 } else {
5473 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5474 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5475 nl80211_policy);
5476 if (err)
5477 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005478
Johannes Berg2bd7e352012-06-15 14:23:16 +02005479 mutex_lock(&cfg80211_mutex);
5480 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5481 nl80211_fam.attrbuf);
5482 if (IS_ERR(rdev)) {
5483 mutex_unlock(&cfg80211_mutex);
5484 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005485 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005486 phy_idx = rdev->wiphy_idx;
5487 rdev = NULL;
5488 mutex_unlock(&cfg80211_mutex);
5489
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005490 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5491 cb->args[1] =
5492 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5493 }
5494
5495 if (cb->args[1]) {
5496 data = nla_data((void *)cb->args[1]);
5497 data_len = nla_len((void *)cb->args[1]);
5498 }
5499
5500 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005501 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5502 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005503 mutex_unlock(&cfg80211_mutex);
5504 return -ENOENT;
5505 }
Johannes Berg00918d32011-12-13 17:22:05 +01005506 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005507 mutex_unlock(&cfg80211_mutex);
5508
Johannes Berg00918d32011-12-13 17:22:05 +01005509 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005510 err = -EOPNOTSUPP;
5511 goto out_err;
5512 }
5513
5514 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00005515 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005516 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5517 NL80211_CMD_TESTMODE);
5518 struct nlattr *tmdata;
5519
David S. Miller9360ffd2012-03-29 04:41:26 -04005520 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005521 genlmsg_cancel(skb, hdr);
5522 break;
5523 }
5524
5525 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5526 if (!tmdata) {
5527 genlmsg_cancel(skb, hdr);
5528 break;
5529 }
Johannes Berg00918d32011-12-13 17:22:05 +01005530 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5531 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005532 nla_nest_end(skb, tmdata);
5533
5534 if (err == -ENOBUFS || err == -ENOENT) {
5535 genlmsg_cancel(skb, hdr);
5536 break;
5537 } else if (err) {
5538 genlmsg_cancel(skb, hdr);
5539 goto out_err;
5540 }
5541
5542 genlmsg_end(skb, hdr);
5543 }
5544
5545 err = skb->len;
5546 /* see above */
5547 cb->args[0] = phy_idx + 1;
5548 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005549 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005550 return err;
5551}
5552
Johannes Bergaff89a92009-07-01 21:26:51 +02005553static struct sk_buff *
5554__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005555 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02005556{
5557 struct sk_buff *skb;
5558 void *hdr;
5559 struct nlattr *data;
5560
5561 skb = nlmsg_new(approxlen + 100, gfp);
5562 if (!skb)
5563 return NULL;
5564
Eric W. Biederman15e47302012-09-07 20:12:54 +00005565 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02005566 if (!hdr) {
5567 kfree_skb(skb);
5568 return NULL;
5569 }
5570
David S. Miller9360ffd2012-03-29 04:41:26 -04005571 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5572 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005573 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5574
5575 ((void **)skb->cb)[0] = rdev;
5576 ((void **)skb->cb)[1] = hdr;
5577 ((void **)skb->cb)[2] = data;
5578
5579 return skb;
5580
5581 nla_put_failure:
5582 kfree_skb(skb);
5583 return NULL;
5584}
5585
5586struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5587 int approxlen)
5588{
5589 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5590
5591 if (WARN_ON(!rdev->testmode_info))
5592 return NULL;
5593
5594 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005595 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02005596 rdev->testmode_info->snd_seq,
5597 GFP_KERNEL);
5598}
5599EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5600
5601int cfg80211_testmode_reply(struct sk_buff *skb)
5602{
5603 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5604 void *hdr = ((void **)skb->cb)[1];
5605 struct nlattr *data = ((void **)skb->cb)[2];
5606
5607 if (WARN_ON(!rdev->testmode_info)) {
5608 kfree_skb(skb);
5609 return -EINVAL;
5610 }
5611
5612 nla_nest_end(skb, data);
5613 genlmsg_end(skb, hdr);
5614 return genlmsg_reply(skb, rdev->testmode_info);
5615}
5616EXPORT_SYMBOL(cfg80211_testmode_reply);
5617
5618struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5619 int approxlen, gfp_t gfp)
5620{
5621 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5622
5623 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5624}
5625EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5626
5627void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5628{
5629 void *hdr = ((void **)skb->cb)[1];
5630 struct nlattr *data = ((void **)skb->cb)[2];
5631
5632 nla_nest_end(skb, data);
5633 genlmsg_end(skb, hdr);
5634 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5635}
5636EXPORT_SYMBOL(cfg80211_testmode_event);
5637#endif
5638
Samuel Ortizb23aa672009-07-01 21:26:54 +02005639static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5640{
Johannes Berg4c476992010-10-04 21:36:35 +02005641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5642 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005643 struct cfg80211_connect_params connect;
5644 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005645 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005646 int err;
5647
5648 memset(&connect, 0, sizeof(connect));
5649
5650 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5651 return -EINVAL;
5652
5653 if (!info->attrs[NL80211_ATTR_SSID] ||
5654 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5655 return -EINVAL;
5656
5657 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5658 connect.auth_type =
5659 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005660 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
5661 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005662 return -EINVAL;
5663 } else
5664 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5665
5666 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5667
Johannes Bergc0692b82010-08-27 14:26:53 +03005668 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005669 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005670 if (err)
5671 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005672
Johannes Berg074ac8d2010-09-16 14:58:22 +02005673 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005674 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5675 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005676
Johannes Berg79c97e92009-07-07 03:56:12 +02005677 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005678
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305679 connect.bg_scan_period = -1;
5680 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5681 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5682 connect.bg_scan_period =
5683 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5684 }
5685
Samuel Ortizb23aa672009-07-01 21:26:54 +02005686 if (info->attrs[NL80211_ATTR_MAC])
5687 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5688 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5689 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5690
5691 if (info->attrs[NL80211_ATTR_IE]) {
5692 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5693 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5694 }
5695
5696 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5697 connect.channel =
5698 ieee80211_get_channel(wiphy,
5699 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5700 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005701 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5702 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005703 }
5704
Johannes Bergfffd0932009-07-08 14:22:54 +02005705 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5706 connkeys = nl80211_parse_connkeys(rdev,
5707 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005708 if (IS_ERR(connkeys))
5709 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005710 }
5711
Ben Greear7e7c8922011-11-18 11:31:59 -08005712 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5713 connect.flags |= ASSOC_REQ_DISABLE_HT;
5714
5715 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5716 memcpy(&connect.ht_capa_mask,
5717 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5718 sizeof(connect.ht_capa_mask));
5719
5720 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005721 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
5722 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08005723 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005724 }
Ben Greear7e7c8922011-11-18 11:31:59 -08005725 memcpy(&connect.ht_capa,
5726 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5727 sizeof(connect.ht_capa));
5728 }
5729
Johannes Bergfffd0932009-07-08 14:22:54 +02005730 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005731 if (err)
5732 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005733 return err;
5734}
5735
5736static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5737{
Johannes Berg4c476992010-10-04 21:36:35 +02005738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5739 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005740 u16 reason;
5741
5742 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5743 reason = WLAN_REASON_DEAUTH_LEAVING;
5744 else
5745 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5746
5747 if (reason == 0)
5748 return -EINVAL;
5749
Johannes Berg074ac8d2010-09-16 14:58:22 +02005750 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005751 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5752 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005753
Johannes Berg4c476992010-10-04 21:36:35 +02005754 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005755}
5756
Johannes Berg463d0182009-07-14 00:33:35 +02005757static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5758{
Johannes Berg4c476992010-10-04 21:36:35 +02005759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005760 struct net *net;
5761 int err;
5762 u32 pid;
5763
5764 if (!info->attrs[NL80211_ATTR_PID])
5765 return -EINVAL;
5766
5767 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5768
Johannes Berg463d0182009-07-14 00:33:35 +02005769 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005770 if (IS_ERR(net))
5771 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005772
5773 err = 0;
5774
5775 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005776 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5777 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005778
Johannes Berg463d0182009-07-14 00:33:35 +02005779 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005780 return err;
5781}
5782
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005783static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5784{
Johannes Berg4c476992010-10-04 21:36:35 +02005785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005786 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5787 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005788 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005789 struct cfg80211_pmksa pmksa;
5790
5791 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5792
5793 if (!info->attrs[NL80211_ATTR_MAC])
5794 return -EINVAL;
5795
5796 if (!info->attrs[NL80211_ATTR_PMKID])
5797 return -EINVAL;
5798
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005799 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5800 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5801
Johannes Berg074ac8d2010-09-16 14:58:22 +02005802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005803 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5804 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005805
5806 switch (info->genlhdr->cmd) {
5807 case NL80211_CMD_SET_PMKSA:
5808 rdev_ops = rdev->ops->set_pmksa;
5809 break;
5810 case NL80211_CMD_DEL_PMKSA:
5811 rdev_ops = rdev->ops->del_pmksa;
5812 break;
5813 default:
5814 WARN_ON(1);
5815 break;
5816 }
5817
Johannes Berg4c476992010-10-04 21:36:35 +02005818 if (!rdev_ops)
5819 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005820
Johannes Berg4c476992010-10-04 21:36:35 +02005821 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005822}
5823
5824static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5825{
Johannes Berg4c476992010-10-04 21:36:35 +02005826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5827 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005828
Johannes Berg074ac8d2010-09-16 14:58:22 +02005829 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005830 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5831 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005832
Johannes Berg4c476992010-10-04 21:36:35 +02005833 if (!rdev->ops->flush_pmksa)
5834 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005835
Johannes Berg4c476992010-10-04 21:36:35 +02005836 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005837}
5838
Arik Nemtsov109086c2011-09-28 14:12:50 +03005839static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5840{
5841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5842 struct net_device *dev = info->user_ptr[1];
5843 u8 action_code, dialog_token;
5844 u16 status_code;
5845 u8 *peer;
5846
5847 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5848 !rdev->ops->tdls_mgmt)
5849 return -EOPNOTSUPP;
5850
5851 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5852 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5853 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5854 !info->attrs[NL80211_ATTR_IE] ||
5855 !info->attrs[NL80211_ATTR_MAC])
5856 return -EINVAL;
5857
5858 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5859 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5860 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5861 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5862
5863 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5864 dialog_token, status_code,
5865 nla_data(info->attrs[NL80211_ATTR_IE]),
5866 nla_len(info->attrs[NL80211_ATTR_IE]));
5867}
5868
5869static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5870{
5871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5872 struct net_device *dev = info->user_ptr[1];
5873 enum nl80211_tdls_operation operation;
5874 u8 *peer;
5875
5876 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5877 !rdev->ops->tdls_oper)
5878 return -EOPNOTSUPP;
5879
5880 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5881 !info->attrs[NL80211_ATTR_MAC])
5882 return -EINVAL;
5883
5884 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5885 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5886
5887 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5888}
5889
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005890static int nl80211_remain_on_channel(struct sk_buff *skb,
5891 struct genl_info *info)
5892{
Johannes Berg4c476992010-10-04 21:36:35 +02005893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005894 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005895 struct ieee80211_channel *chan;
5896 struct sk_buff *msg;
5897 void *hdr;
5898 u64 cookie;
5899 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5900 u32 freq, duration;
5901 int err;
5902
5903 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5904 !info->attrs[NL80211_ATTR_DURATION])
5905 return -EINVAL;
5906
5907 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5908
Johannes Berg7c4ef712011-11-18 15:33:48 +01005909 if (!rdev->ops->remain_on_channel ||
5910 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005911 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005912
Johannes Bergebf348f2012-06-01 12:50:54 +02005913 /*
5914 * We should be on that channel for at least a minimum amount of
5915 * time (10ms) but no longer than the driver supports.
5916 */
5917 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5918 duration > rdev->wiphy.max_remain_on_channel_duration)
5919 return -EINVAL;
5920
Johannes Bergcd6c6592012-05-10 21:27:18 +02005921 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5922 !nl80211_valid_channel_type(info, &channel_type))
5923 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005924
5925 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5926 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005927 if (chan == NULL)
5928 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005929
5930 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005931 if (!msg)
5932 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005933
Eric W. Biederman15e47302012-09-07 20:12:54 +00005934 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005935 NL80211_CMD_REMAIN_ON_CHANNEL);
5936
5937 if (IS_ERR(hdr)) {
5938 err = PTR_ERR(hdr);
5939 goto free_msg;
5940 }
5941
Johannes Berg71bbc992012-06-15 15:30:18 +02005942 err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005943 channel_type, duration, &cookie);
5944
5945 if (err)
5946 goto free_msg;
5947
David S. Miller9360ffd2012-03-29 04:41:26 -04005948 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5949 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005950
5951 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005952
5953 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005954
5955 nla_put_failure:
5956 err = -ENOBUFS;
5957 free_msg:
5958 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005959 return err;
5960}
5961
5962static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5963 struct genl_info *info)
5964{
Johannes Berg4c476992010-10-04 21:36:35 +02005965 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005966 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005967 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005968
5969 if (!info->attrs[NL80211_ATTR_COOKIE])
5970 return -EINVAL;
5971
Johannes Berg4c476992010-10-04 21:36:35 +02005972 if (!rdev->ops->cancel_remain_on_channel)
5973 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005974
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005975 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5976
Johannes Berg71bbc992012-06-15 15:30:18 +02005977 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005978}
5979
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005980static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5981 u8 *rates, u8 rates_len)
5982{
5983 u8 i;
5984 u32 mask = 0;
5985
5986 for (i = 0; i < rates_len; i++) {
5987 int rate = (rates[i] & 0x7f) * 5;
5988 int ridx;
5989 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5990 struct ieee80211_rate *srate =
5991 &sband->bitrates[ridx];
5992 if (rate == srate->bitrate) {
5993 mask |= 1 << ridx;
5994 break;
5995 }
5996 }
5997 if (ridx == sband->n_bitrates)
5998 return 0; /* rate not found */
5999 }
6000
6001 return mask;
6002}
6003
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006004static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6005 u8 *rates, u8 rates_len,
6006 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6007{
6008 u8 i;
6009
6010 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6011
6012 for (i = 0; i < rates_len; i++) {
6013 int ridx, rbit;
6014
6015 ridx = rates[i] / 8;
6016 rbit = BIT(rates[i] % 8);
6017
6018 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006019 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006020 return false;
6021
6022 /* check availability */
6023 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6024 mcs[ridx] |= rbit;
6025 else
6026 return false;
6027 }
6028
6029 return true;
6030}
6031
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006032static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006033 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6034 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006035 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6036 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006037};
6038
6039static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6040 struct genl_info *info)
6041{
6042 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006043 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006044 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006045 int rem, i;
6046 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006047 struct nlattr *tx_rates;
6048 struct ieee80211_supported_band *sband;
6049
6050 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6051 return -EINVAL;
6052
Johannes Berg4c476992010-10-04 21:36:35 +02006053 if (!rdev->ops->set_bitrate_mask)
6054 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006055
6056 memset(&mask, 0, sizeof(mask));
6057 /* Default to all rates enabled */
6058 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6059 sband = rdev->wiphy.bands[i];
6060 mask.control[i].legacy =
6061 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006062 if (sband)
6063 memcpy(mask.control[i].mcs,
6064 sband->ht_cap.mcs.rx_mask,
6065 sizeof(mask.control[i].mcs));
6066 else
6067 memset(mask.control[i].mcs, 0,
6068 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006069 }
6070
6071 /*
6072 * The nested attribute uses enum nl80211_band as the index. This maps
6073 * directly to the enum ieee80211_band values used in cfg80211.
6074 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006075 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006076 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6077 {
6078 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006079 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6080 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006081 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006082 if (sband == NULL)
6083 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006084 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6085 nla_len(tx_rates), nl80211_txattr_policy);
6086 if (tb[NL80211_TXRATE_LEGACY]) {
6087 mask.control[band].legacy = rateset_to_mask(
6088 sband,
6089 nla_data(tb[NL80211_TXRATE_LEGACY]),
6090 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306091 if ((mask.control[band].legacy == 0) &&
6092 nla_len(tb[NL80211_TXRATE_LEGACY]))
6093 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006094 }
6095 if (tb[NL80211_TXRATE_MCS]) {
6096 if (!ht_rateset_to_mask(
6097 sband,
6098 nla_data(tb[NL80211_TXRATE_MCS]),
6099 nla_len(tb[NL80211_TXRATE_MCS]),
6100 mask.control[band].mcs))
6101 return -EINVAL;
6102 }
6103
6104 if (mask.control[band].legacy == 0) {
6105 /* don't allow empty legacy rates if HT
6106 * is not even supported. */
6107 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6108 return -EINVAL;
6109
6110 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6111 if (mask.control[band].mcs[i])
6112 break;
6113
6114 /* legacy and mcs rates may not be both empty */
6115 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02006116 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006117 }
6118 }
6119
Johannes Berg4c476992010-10-04 21:36:35 +02006120 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006121}
6122
Johannes Berg2e161f72010-08-12 15:38:38 +02006123static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006124{
Johannes Berg4c476992010-10-04 21:36:35 +02006125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006126 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02006127 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02006128
6129 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6130 return -EINVAL;
6131
Johannes Berg2e161f72010-08-12 15:38:38 +02006132 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6133 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02006134
Johannes Berg71bbc992012-06-15 15:30:18 +02006135 switch (wdev->iftype) {
6136 case NL80211_IFTYPE_STATION:
6137 case NL80211_IFTYPE_ADHOC:
6138 case NL80211_IFTYPE_P2P_CLIENT:
6139 case NL80211_IFTYPE_AP:
6140 case NL80211_IFTYPE_AP_VLAN:
6141 case NL80211_IFTYPE_MESH_POINT:
6142 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006143 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006144 break;
6145 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006146 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006147 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006148
6149 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02006150 if (!rdev->ops->mgmt_tx)
6151 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006152
Eric W. Biederman15e47302012-09-07 20:12:54 +00006153 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02006154 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6155 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02006156}
6157
Johannes Berg2e161f72010-08-12 15:38:38 +02006158static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006159{
Johannes Berg4c476992010-10-04 21:36:35 +02006160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006161 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02006162 struct ieee80211_channel *chan;
6163 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02006164 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02006165 u32 freq;
6166 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01006167 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006168 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01006169 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006170 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01006171 bool offchan, no_cck, dont_wait_for_ack;
6172
6173 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02006174
6175 if (!info->attrs[NL80211_ATTR_FRAME] ||
6176 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6177 return -EINVAL;
6178
Johannes Berg4c476992010-10-04 21:36:35 +02006179 if (!rdev->ops->mgmt_tx)
6180 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006181
Johannes Berg71bbc992012-06-15 15:30:18 +02006182 switch (wdev->iftype) {
6183 case NL80211_IFTYPE_STATION:
6184 case NL80211_IFTYPE_ADHOC:
6185 case NL80211_IFTYPE_P2P_CLIENT:
6186 case NL80211_IFTYPE_AP:
6187 case NL80211_IFTYPE_AP_VLAN:
6188 case NL80211_IFTYPE_MESH_POINT:
6189 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006190 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006191 break;
6192 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006193 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006194 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006195
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006196 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01006197 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006198 return -EINVAL;
6199 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02006200
6201 /*
6202 * We should wait on the channel for at least a minimum amount
6203 * of time (10ms) but no longer than the driver supports.
6204 */
6205 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6206 wait > rdev->wiphy.max_remain_on_channel_duration)
6207 return -EINVAL;
6208
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006209 }
6210
Jouni Malinen026331c2010-02-15 12:53:10 +02006211 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02006212 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02006213 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02006214 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02006215 }
6216
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006217 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6218
Johannes Berg7c4ef712011-11-18 15:33:48 +01006219 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6220 return -EINVAL;
6221
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306222 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6223
Jouni Malinen026331c2010-02-15 12:53:10 +02006224 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6225 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006226 if (chan == NULL)
6227 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006228
Johannes Berge247bd902011-11-04 11:18:21 +01006229 if (!dont_wait_for_ack) {
6230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6231 if (!msg)
6232 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006233
Eric W. Biederman15e47302012-09-07 20:12:54 +00006234 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01006235 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006236
Johannes Berge247bd902011-11-04 11:18:21 +01006237 if (IS_ERR(hdr)) {
6238 err = PTR_ERR(hdr);
6239 goto free_msg;
6240 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006241 }
Johannes Berge247bd902011-11-04 11:18:21 +01006242
Johannes Berg71bbc992012-06-15 15:30:18 +02006243 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006244 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006245 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6246 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006247 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006248 if (err)
6249 goto free_msg;
6250
Johannes Berge247bd902011-11-04 11:18:21 +01006251 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006252 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6253 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006254
Johannes Berge247bd902011-11-04 11:18:21 +01006255 genlmsg_end(msg, hdr);
6256 return genlmsg_reply(msg, info);
6257 }
6258
6259 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006260
6261 nla_put_failure:
6262 err = -ENOBUFS;
6263 free_msg:
6264 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006265 return err;
6266}
6267
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006268static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6269{
6270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006271 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006272 u64 cookie;
6273
6274 if (!info->attrs[NL80211_ATTR_COOKIE])
6275 return -EINVAL;
6276
6277 if (!rdev->ops->mgmt_tx_cancel_wait)
6278 return -EOPNOTSUPP;
6279
Johannes Berg71bbc992012-06-15 15:30:18 +02006280 switch (wdev->iftype) {
6281 case NL80211_IFTYPE_STATION:
6282 case NL80211_IFTYPE_ADHOC:
6283 case NL80211_IFTYPE_P2P_CLIENT:
6284 case NL80211_IFTYPE_AP:
6285 case NL80211_IFTYPE_AP_VLAN:
6286 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006287 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006288 break;
6289 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006290 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006291 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006292
6293 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6294
Johannes Berg71bbc992012-06-15 15:30:18 +02006295 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006296}
6297
Kalle Valoffb9eb32010-02-17 17:58:10 +02006298static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6299{
Johannes Berg4c476992010-10-04 21:36:35 +02006300 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006301 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006302 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006303 u8 ps_state;
6304 bool state;
6305 int err;
6306
Johannes Berg4c476992010-10-04 21:36:35 +02006307 if (!info->attrs[NL80211_ATTR_PS_STATE])
6308 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006309
6310 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6311
Johannes Berg4c476992010-10-04 21:36:35 +02006312 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6313 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006314
6315 wdev = dev->ieee80211_ptr;
6316
Johannes Berg4c476992010-10-04 21:36:35 +02006317 if (!rdev->ops->set_power_mgmt)
6318 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006319
6320 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6321
6322 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006323 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006324
Johannes Berg4c476992010-10-04 21:36:35 +02006325 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6326 wdev->ps_timeout);
6327 if (!err)
6328 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006329 return err;
6330}
6331
6332static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6333{
Johannes Berg4c476992010-10-04 21:36:35 +02006334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006335 enum nl80211_ps_state ps_state;
6336 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006337 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006338 struct sk_buff *msg;
6339 void *hdr;
6340 int err;
6341
Kalle Valoffb9eb32010-02-17 17:58:10 +02006342 wdev = dev->ieee80211_ptr;
6343
Johannes Berg4c476992010-10-04 21:36:35 +02006344 if (!rdev->ops->set_power_mgmt)
6345 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006346
6347 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006348 if (!msg)
6349 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006350
Eric W. Biederman15e47302012-09-07 20:12:54 +00006351 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006352 NL80211_CMD_GET_POWER_SAVE);
6353 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006354 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006355 goto free_msg;
6356 }
6357
6358 if (wdev->ps)
6359 ps_state = NL80211_PS_ENABLED;
6360 else
6361 ps_state = NL80211_PS_DISABLED;
6362
David S. Miller9360ffd2012-03-29 04:41:26 -04006363 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6364 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006365
6366 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006367 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006368
Johannes Berg4c476992010-10-04 21:36:35 +02006369 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006370 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006371 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006372 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006373 return err;
6374}
6375
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006376static struct nla_policy
6377nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6378 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6379 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6380 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07006381 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6382 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6383 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006384};
6385
Thomas Pedersen84f10702012-07-12 16:17:33 -07006386static int nl80211_set_cqm_txe(struct genl_info *info,
6387 u32 rate, u32 pkts, u32 intvl)
6388{
6389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6390 struct wireless_dev *wdev;
6391 struct net_device *dev = info->user_ptr[1];
6392
6393 if ((rate < 0 || rate > 100) ||
6394 (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL))
6395 return -EINVAL;
6396
6397 wdev = dev->ieee80211_ptr;
6398
6399 if (!rdev->ops->set_cqm_txe_config)
6400 return -EOPNOTSUPP;
6401
6402 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6403 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6404 return -EOPNOTSUPP;
6405
6406 return rdev->ops->set_cqm_txe_config(wdev->wiphy, dev,
6407 rate, pkts, intvl);
6408}
6409
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006410static int nl80211_set_cqm_rssi(struct genl_info *info,
6411 s32 threshold, u32 hysteresis)
6412{
Johannes Berg4c476992010-10-04 21:36:35 +02006413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006414 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006415 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006416
6417 if (threshold > 0)
6418 return -EINVAL;
6419
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006420 wdev = dev->ieee80211_ptr;
6421
Johannes Berg4c476992010-10-04 21:36:35 +02006422 if (!rdev->ops->set_cqm_rssi_config)
6423 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006424
Johannes Berg074ac8d2010-09-16 14:58:22 +02006425 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006426 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6427 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006428
Johannes Berg4c476992010-10-04 21:36:35 +02006429 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6430 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006431}
6432
6433static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6434{
6435 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6436 struct nlattr *cqm;
6437 int err;
6438
6439 cqm = info->attrs[NL80211_ATTR_CQM];
6440 if (!cqm) {
6441 err = -EINVAL;
6442 goto out;
6443 }
6444
6445 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6446 nl80211_attr_cqm_policy);
6447 if (err)
6448 goto out;
6449
6450 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6451 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6452 s32 threshold;
6453 u32 hysteresis;
6454 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6455 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6456 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07006457 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
6458 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
6459 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
6460 u32 rate, pkts, intvl;
6461 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
6462 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
6463 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6464 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006465 } else
6466 err = -EINVAL;
6467
6468out:
6469 return err;
6470}
6471
Johannes Berg29cbe682010-12-03 09:20:44 +01006472static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6473{
6474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6475 struct net_device *dev = info->user_ptr[1];
6476 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006477 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006478 int err;
6479
6480 /* start with default */
6481 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006482 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006483
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006484 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006485 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006486 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006487 if (err)
6488 return err;
6489 }
6490
6491 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6492 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6493 return -EINVAL;
6494
Javier Cardonac80d5452010-12-16 17:37:49 -08006495 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6496 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6497
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006498 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6499 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6500 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6501 return -EINVAL;
6502
Javier Cardonac80d5452010-12-16 17:37:49 -08006503 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6504 /* parse additional setup parameters if given */
6505 err = nl80211_parse_mesh_setup(info, &setup);
6506 if (err)
6507 return err;
6508 }
6509
Johannes Bergcc1d2802012-05-16 23:50:20 +02006510 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6511 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6512
6513 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6514 !nl80211_valid_channel_type(info, &channel_type))
6515 return -EINVAL;
6516
6517 setup.channel = rdev_freq_to_chan(rdev,
6518 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6519 channel_type);
6520 if (!setup.channel)
6521 return -EINVAL;
6522 setup.channel_type = channel_type;
6523 } else {
6524 /* cfg80211_join_mesh() will sort it out */
6525 setup.channel = NULL;
6526 }
6527
Javier Cardonac80d5452010-12-16 17:37:49 -08006528 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006529}
6530
6531static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6532{
6533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6534 struct net_device *dev = info->user_ptr[1];
6535
6536 return cfg80211_leave_mesh(rdev, dev);
6537}
6538
Johannes Bergdfb89c52012-06-27 09:23:48 +02006539#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006540static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6541{
6542 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6543 struct sk_buff *msg;
6544 void *hdr;
6545
6546 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6547 return -EOPNOTSUPP;
6548
6549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6550 if (!msg)
6551 return -ENOMEM;
6552
Eric W. Biederman15e47302012-09-07 20:12:54 +00006553 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02006554 NL80211_CMD_GET_WOWLAN);
6555 if (!hdr)
6556 goto nla_put_failure;
6557
6558 if (rdev->wowlan) {
6559 struct nlattr *nl_wowlan;
6560
6561 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6562 if (!nl_wowlan)
6563 goto nla_put_failure;
6564
David S. Miller9360ffd2012-03-29 04:41:26 -04006565 if ((rdev->wowlan->any &&
6566 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6567 (rdev->wowlan->disconnect &&
6568 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6569 (rdev->wowlan->magic_pkt &&
6570 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6571 (rdev->wowlan->gtk_rekey_failure &&
6572 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6573 (rdev->wowlan->eap_identity_req &&
6574 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6575 (rdev->wowlan->four_way_handshake &&
6576 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6577 (rdev->wowlan->rfkill_release &&
6578 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6579 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006580 if (rdev->wowlan->n_patterns) {
6581 struct nlattr *nl_pats, *nl_pat;
6582 int i, pat_len;
6583
6584 nl_pats = nla_nest_start(msg,
6585 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6586 if (!nl_pats)
6587 goto nla_put_failure;
6588
6589 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6590 nl_pat = nla_nest_start(msg, i + 1);
6591 if (!nl_pat)
6592 goto nla_put_failure;
6593 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006594 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6595 DIV_ROUND_UP(pat_len, 8),
6596 rdev->wowlan->patterns[i].mask) ||
6597 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6598 pat_len,
6599 rdev->wowlan->patterns[i].pattern))
6600 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006601 nla_nest_end(msg, nl_pat);
6602 }
6603 nla_nest_end(msg, nl_pats);
6604 }
6605
6606 nla_nest_end(msg, nl_wowlan);
6607 }
6608
6609 genlmsg_end(msg, hdr);
6610 return genlmsg_reply(msg, info);
6611
6612nla_put_failure:
6613 nlmsg_free(msg);
6614 return -ENOBUFS;
6615}
6616
6617static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6618{
6619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6620 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02006621 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02006622 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006623 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6624 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006625 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006626
6627 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6628 return -EOPNOTSUPP;
6629
Johannes Bergae33bd82012-07-12 16:25:02 +02006630 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
6631 cfg80211_rdev_free_wowlan(rdev);
6632 rdev->wowlan = NULL;
6633 goto set_wakeup;
6634 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02006635
6636 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6637 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6638 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6639 nl80211_wowlan_policy);
6640 if (err)
6641 return err;
6642
6643 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6644 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6645 return -EINVAL;
6646 new_triggers.any = true;
6647 }
6648
6649 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6650 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6651 return -EINVAL;
6652 new_triggers.disconnect = true;
6653 }
6654
6655 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6656 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6657 return -EINVAL;
6658 new_triggers.magic_pkt = true;
6659 }
6660
Johannes Berg77dbbb132011-07-13 10:48:55 +02006661 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6662 return -EINVAL;
6663
6664 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6665 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6666 return -EINVAL;
6667 new_triggers.gtk_rekey_failure = true;
6668 }
6669
6670 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6671 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6672 return -EINVAL;
6673 new_triggers.eap_identity_req = true;
6674 }
6675
6676 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6677 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6678 return -EINVAL;
6679 new_triggers.four_way_handshake = true;
6680 }
6681
6682 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6683 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6684 return -EINVAL;
6685 new_triggers.rfkill_release = true;
6686 }
6687
Johannes Bergff1b6e62011-05-04 15:37:28 +02006688 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6689 struct nlattr *pat;
6690 int n_patterns = 0;
6691 int rem, pat_len, mask_len;
6692 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6693
6694 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6695 rem)
6696 n_patterns++;
6697 if (n_patterns > wowlan->n_patterns)
6698 return -EINVAL;
6699
6700 new_triggers.patterns = kcalloc(n_patterns,
6701 sizeof(new_triggers.patterns[0]),
6702 GFP_KERNEL);
6703 if (!new_triggers.patterns)
6704 return -ENOMEM;
6705
6706 new_triggers.n_patterns = n_patterns;
6707 i = 0;
6708
6709 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6710 rem) {
6711 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6712 nla_data(pat), nla_len(pat), NULL);
6713 err = -EINVAL;
6714 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6715 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6716 goto error;
6717 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6718 mask_len = DIV_ROUND_UP(pat_len, 8);
6719 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6720 mask_len)
6721 goto error;
6722 if (pat_len > wowlan->pattern_max_len ||
6723 pat_len < wowlan->pattern_min_len)
6724 goto error;
6725
6726 new_triggers.patterns[i].mask =
6727 kmalloc(mask_len + pat_len, GFP_KERNEL);
6728 if (!new_triggers.patterns[i].mask) {
6729 err = -ENOMEM;
6730 goto error;
6731 }
6732 new_triggers.patterns[i].pattern =
6733 new_triggers.patterns[i].mask + mask_len;
6734 memcpy(new_triggers.patterns[i].mask,
6735 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6736 mask_len);
6737 new_triggers.patterns[i].pattern_len = pat_len;
6738 memcpy(new_triggers.patterns[i].pattern,
6739 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6740 pat_len);
6741 i++;
6742 }
6743 }
6744
Johannes Bergae33bd82012-07-12 16:25:02 +02006745 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
6746 if (!ntrig) {
6747 err = -ENOMEM;
6748 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006749 }
Johannes Bergae33bd82012-07-12 16:25:02 +02006750 cfg80211_rdev_free_wowlan(rdev);
6751 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006752
Johannes Bergae33bd82012-07-12 16:25:02 +02006753 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02006754 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6755 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6756
Johannes Bergff1b6e62011-05-04 15:37:28 +02006757 return 0;
6758 error:
6759 for (i = 0; i < new_triggers.n_patterns; i++)
6760 kfree(new_triggers.patterns[i].mask);
6761 kfree(new_triggers.patterns);
6762 return err;
6763}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006764#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006765
Johannes Berge5497d72011-07-05 16:35:40 +02006766static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6767{
6768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6769 struct net_device *dev = info->user_ptr[1];
6770 struct wireless_dev *wdev = dev->ieee80211_ptr;
6771 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6772 struct cfg80211_gtk_rekey_data rekey_data;
6773 int err;
6774
6775 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6776 return -EINVAL;
6777
6778 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6779 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6780 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6781 nl80211_rekey_policy);
6782 if (err)
6783 return err;
6784
6785 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6786 return -ERANGE;
6787 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6788 return -ERANGE;
6789 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6790 return -ERANGE;
6791
6792 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6793 NL80211_KEK_LEN);
6794 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6795 NL80211_KCK_LEN);
6796 memcpy(rekey_data.replay_ctr,
6797 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6798 NL80211_REPLAY_CTR_LEN);
6799
6800 wdev_lock(wdev);
6801 if (!wdev->current_bss) {
6802 err = -ENOTCONN;
6803 goto out;
6804 }
6805
6806 if (!rdev->ops->set_rekey_data) {
6807 err = -EOPNOTSUPP;
6808 goto out;
6809 }
6810
6811 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6812 out:
6813 wdev_unlock(wdev);
6814 return err;
6815}
6816
Johannes Berg28946da2011-11-04 11:18:12 +01006817static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6818 struct genl_info *info)
6819{
6820 struct net_device *dev = info->user_ptr[1];
6821 struct wireless_dev *wdev = dev->ieee80211_ptr;
6822
6823 if (wdev->iftype != NL80211_IFTYPE_AP &&
6824 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6825 return -EINVAL;
6826
Eric W. Biederman15e47302012-09-07 20:12:54 +00006827 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01006828 return -EBUSY;
6829
Eric W. Biederman15e47302012-09-07 20:12:54 +00006830 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01006831 return 0;
6832}
6833
Johannes Berg7f6cf312011-11-04 11:18:15 +01006834static int nl80211_probe_client(struct sk_buff *skb,
6835 struct genl_info *info)
6836{
6837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6838 struct net_device *dev = info->user_ptr[1];
6839 struct wireless_dev *wdev = dev->ieee80211_ptr;
6840 struct sk_buff *msg;
6841 void *hdr;
6842 const u8 *addr;
6843 u64 cookie;
6844 int err;
6845
6846 if (wdev->iftype != NL80211_IFTYPE_AP &&
6847 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6848 return -EOPNOTSUPP;
6849
6850 if (!info->attrs[NL80211_ATTR_MAC])
6851 return -EINVAL;
6852
6853 if (!rdev->ops->probe_client)
6854 return -EOPNOTSUPP;
6855
6856 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6857 if (!msg)
6858 return -ENOMEM;
6859
Eric W. Biederman15e47302012-09-07 20:12:54 +00006860 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01006861 NL80211_CMD_PROBE_CLIENT);
6862
6863 if (IS_ERR(hdr)) {
6864 err = PTR_ERR(hdr);
6865 goto free_msg;
6866 }
6867
6868 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6869
6870 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6871 if (err)
6872 goto free_msg;
6873
David S. Miller9360ffd2012-03-29 04:41:26 -04006874 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6875 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006876
6877 genlmsg_end(msg, hdr);
6878
6879 return genlmsg_reply(msg, info);
6880
6881 nla_put_failure:
6882 err = -ENOBUFS;
6883 free_msg:
6884 nlmsg_free(msg);
6885 return err;
6886}
6887
Johannes Berg5e760232011-11-04 11:18:17 +01006888static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6889{
6890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6891
6892 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6893 return -EOPNOTSUPP;
6894
Eric W. Biederman15e47302012-09-07 20:12:54 +00006895 if (rdev->ap_beacons_nlportid)
Johannes Berg5e760232011-11-04 11:18:17 +01006896 return -EBUSY;
6897
Eric W. Biederman15e47302012-09-07 20:12:54 +00006898 rdev->ap_beacons_nlportid = info->snd_portid;
Johannes Berg5e760232011-11-04 11:18:17 +01006899
6900 return 0;
6901}
6902
Johannes Berg98104fde2012-06-16 00:19:54 +02006903static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
6904{
6905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6906 struct wireless_dev *wdev = info->user_ptr[1];
6907 int err;
6908
6909 if (!rdev->ops->start_p2p_device)
6910 return -EOPNOTSUPP;
6911
6912 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6913 return -EOPNOTSUPP;
6914
6915 if (wdev->p2p_started)
6916 return 0;
6917
6918 mutex_lock(&rdev->devlist_mtx);
6919 err = cfg80211_can_add_interface(rdev, wdev->iftype);
6920 mutex_unlock(&rdev->devlist_mtx);
6921 if (err)
6922 return err;
6923
6924 err = rdev->ops->start_p2p_device(&rdev->wiphy, wdev);
6925 if (err)
6926 return err;
6927
6928 wdev->p2p_started = true;
6929 mutex_lock(&rdev->devlist_mtx);
6930 rdev->opencount++;
6931 mutex_unlock(&rdev->devlist_mtx);
6932
6933 return 0;
6934}
6935
6936static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
6937{
6938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6939 struct wireless_dev *wdev = info->user_ptr[1];
6940
6941 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6942 return -EOPNOTSUPP;
6943
6944 if (!rdev->ops->stop_p2p_device)
6945 return -EOPNOTSUPP;
6946
6947 if (!wdev->p2p_started)
6948 return 0;
6949
6950 rdev->ops->stop_p2p_device(&rdev->wiphy, wdev);
6951 wdev->p2p_started = false;
6952
6953 mutex_lock(&rdev->devlist_mtx);
6954 rdev->opencount--;
6955 mutex_unlock(&rdev->devlist_mtx);
6956
6957 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
6958 rdev->scan_req->aborted = true;
6959 ___cfg80211_scan_done(rdev, true);
6960 }
6961
6962 return 0;
6963}
6964
Johannes Berg4c476992010-10-04 21:36:35 +02006965#define NL80211_FLAG_NEED_WIPHY 0x01
6966#define NL80211_FLAG_NEED_NETDEV 0x02
6967#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006968#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6969#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6970 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02006971#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02006972/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02006973#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6974 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006975
6976static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6977 struct genl_info *info)
6978{
6979 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02006980 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006981 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02006982 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6983
6984 if (rtnl)
6985 rtnl_lock();
6986
6987 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006988 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006989 if (IS_ERR(rdev)) {
6990 if (rtnl)
6991 rtnl_unlock();
6992 return PTR_ERR(rdev);
6993 }
6994 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02006995 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
6996 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02006997 mutex_lock(&cfg80211_mutex);
6998 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
6999 info->attrs);
7000 if (IS_ERR(wdev)) {
7001 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02007002 if (rtnl)
7003 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02007004 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007005 }
Johannes Berg89a54e42012-06-15 14:33:17 +02007006
Johannes Berg89a54e42012-06-15 14:33:17 +02007007 dev = wdev->netdev;
7008 rdev = wiphy_to_dev(wdev->wiphy);
7009
Johannes Berg1bf614e2012-06-15 15:23:36 +02007010 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
7011 if (!dev) {
7012 mutex_unlock(&cfg80211_mutex);
7013 if (rtnl)
7014 rtnl_unlock();
7015 return -EINVAL;
7016 }
7017
7018 info->user_ptr[1] = dev;
7019 } else {
7020 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02007021 }
Johannes Berg89a54e42012-06-15 14:33:17 +02007022
Johannes Berg1bf614e2012-06-15 15:23:36 +02007023 if (dev) {
7024 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
7025 !netif_running(dev)) {
7026 mutex_unlock(&cfg80211_mutex);
7027 if (rtnl)
7028 rtnl_unlock();
7029 return -ENETDOWN;
7030 }
7031
7032 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02007033 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7034 if (!wdev->p2p_started) {
7035 mutex_unlock(&cfg80211_mutex);
7036 if (rtnl)
7037 rtnl_unlock();
7038 return -ENETDOWN;
7039 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02007040 }
7041
Johannes Berg89a54e42012-06-15 14:33:17 +02007042 cfg80211_lock_rdev(rdev);
7043
7044 mutex_unlock(&cfg80211_mutex);
7045
Johannes Berg4c476992010-10-04 21:36:35 +02007046 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007047 }
7048
7049 return 0;
7050}
7051
7052static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7053 struct genl_info *info)
7054{
7055 if (info->user_ptr[0])
7056 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02007057 if (info->user_ptr[1]) {
7058 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7059 struct wireless_dev *wdev = info->user_ptr[1];
7060
7061 if (wdev->netdev)
7062 dev_put(wdev->netdev);
7063 } else {
7064 dev_put(info->user_ptr[1]);
7065 }
7066 }
Johannes Berg4c476992010-10-04 21:36:35 +02007067 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7068 rtnl_unlock();
7069}
7070
Johannes Berg55682962007-09-20 13:09:35 -04007071static struct genl_ops nl80211_ops[] = {
7072 {
7073 .cmd = NL80211_CMD_GET_WIPHY,
7074 .doit = nl80211_get_wiphy,
7075 .dumpit = nl80211_dump_wiphy,
7076 .policy = nl80211_policy,
7077 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007078 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04007079 },
7080 {
7081 .cmd = NL80211_CMD_SET_WIPHY,
7082 .doit = nl80211_set_wiphy,
7083 .policy = nl80211_policy,
7084 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007085 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007086 },
7087 {
7088 .cmd = NL80211_CMD_GET_INTERFACE,
7089 .doit = nl80211_get_interface,
7090 .dumpit = nl80211_dump_interface,
7091 .policy = nl80211_policy,
7092 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02007093 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04007094 },
7095 {
7096 .cmd = NL80211_CMD_SET_INTERFACE,
7097 .doit = nl80211_set_interface,
7098 .policy = nl80211_policy,
7099 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007100 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7101 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007102 },
7103 {
7104 .cmd = NL80211_CMD_NEW_INTERFACE,
7105 .doit = nl80211_new_interface,
7106 .policy = nl80211_policy,
7107 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007108 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7109 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007110 },
7111 {
7112 .cmd = NL80211_CMD_DEL_INTERFACE,
7113 .doit = nl80211_del_interface,
7114 .policy = nl80211_policy,
7115 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02007116 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007117 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007118 },
Johannes Berg41ade002007-12-19 02:03:29 +01007119 {
7120 .cmd = NL80211_CMD_GET_KEY,
7121 .doit = nl80211_get_key,
7122 .policy = nl80211_policy,
7123 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007125 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007126 },
7127 {
7128 .cmd = NL80211_CMD_SET_KEY,
7129 .doit = nl80211_set_key,
7130 .policy = nl80211_policy,
7131 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007133 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007134 },
7135 {
7136 .cmd = NL80211_CMD_NEW_KEY,
7137 .doit = nl80211_new_key,
7138 .policy = nl80211_policy,
7139 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007141 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007142 },
7143 {
7144 .cmd = NL80211_CMD_DEL_KEY,
7145 .doit = nl80211_del_key,
7146 .policy = nl80211_policy,
7147 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007149 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007150 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01007151 {
7152 .cmd = NL80211_CMD_SET_BEACON,
7153 .policy = nl80211_policy,
7154 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007155 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007157 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007158 },
7159 {
Johannes Berg88600202012-02-13 15:17:18 +01007160 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007161 .policy = nl80211_policy,
7162 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007163 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007165 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007166 },
7167 {
Johannes Berg88600202012-02-13 15:17:18 +01007168 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007169 .policy = nl80211_policy,
7170 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007171 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007173 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007174 },
Johannes Berg5727ef12007-12-19 02:03:34 +01007175 {
7176 .cmd = NL80211_CMD_GET_STATION,
7177 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007178 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01007179 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02007180 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7181 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007182 },
7183 {
7184 .cmd = NL80211_CMD_SET_STATION,
7185 .doit = nl80211_set_station,
7186 .policy = nl80211_policy,
7187 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007188 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007189 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007190 },
7191 {
7192 .cmd = NL80211_CMD_NEW_STATION,
7193 .doit = nl80211_new_station,
7194 .policy = nl80211_policy,
7195 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007197 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007198 },
7199 {
7200 .cmd = NL80211_CMD_DEL_STATION,
7201 .doit = nl80211_del_station,
7202 .policy = nl80211_policy,
7203 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007205 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007206 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007207 {
7208 .cmd = NL80211_CMD_GET_MPATH,
7209 .doit = nl80211_get_mpath,
7210 .dumpit = nl80211_dump_mpath,
7211 .policy = nl80211_policy,
7212 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007214 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007215 },
7216 {
7217 .cmd = NL80211_CMD_SET_MPATH,
7218 .doit = nl80211_set_mpath,
7219 .policy = nl80211_policy,
7220 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007222 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007223 },
7224 {
7225 .cmd = NL80211_CMD_NEW_MPATH,
7226 .doit = nl80211_new_mpath,
7227 .policy = nl80211_policy,
7228 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007230 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007231 },
7232 {
7233 .cmd = NL80211_CMD_DEL_MPATH,
7234 .doit = nl80211_del_mpath,
7235 .policy = nl80211_policy,
7236 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007238 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007239 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007240 {
7241 .cmd = NL80211_CMD_SET_BSS,
7242 .doit = nl80211_set_bss,
7243 .policy = nl80211_policy,
7244 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007246 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007247 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007248 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007249 .cmd = NL80211_CMD_GET_REG,
7250 .doit = nl80211_get_reg,
7251 .policy = nl80211_policy,
7252 /* can be retrieved by unprivileged users */
7253 },
7254 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007255 .cmd = NL80211_CMD_SET_REG,
7256 .doit = nl80211_set_reg,
7257 .policy = nl80211_policy,
7258 .flags = GENL_ADMIN_PERM,
7259 },
7260 {
7261 .cmd = NL80211_CMD_REQ_SET_REG,
7262 .doit = nl80211_req_set_reg,
7263 .policy = nl80211_policy,
7264 .flags = GENL_ADMIN_PERM,
7265 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007266 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007267 .cmd = NL80211_CMD_GET_MESH_CONFIG,
7268 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007269 .policy = nl80211_policy,
7270 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007272 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007273 },
7274 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007275 .cmd = NL80211_CMD_SET_MESH_CONFIG,
7276 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007277 .policy = nl80211_policy,
7278 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01007279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007280 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007281 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02007282 {
Johannes Berg2a519312009-02-10 21:25:55 +01007283 .cmd = NL80211_CMD_TRIGGER_SCAN,
7284 .doit = nl80211_trigger_scan,
7285 .policy = nl80211_policy,
7286 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02007287 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007288 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01007289 },
7290 {
7291 .cmd = NL80211_CMD_GET_SCAN,
7292 .policy = nl80211_policy,
7293 .dumpit = nl80211_dump_scan,
7294 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02007295 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007296 .cmd = NL80211_CMD_START_SCHED_SCAN,
7297 .doit = nl80211_start_sched_scan,
7298 .policy = nl80211_policy,
7299 .flags = GENL_ADMIN_PERM,
7300 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7301 NL80211_FLAG_NEED_RTNL,
7302 },
7303 {
7304 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
7305 .doit = nl80211_stop_sched_scan,
7306 .policy = nl80211_policy,
7307 .flags = GENL_ADMIN_PERM,
7308 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7309 NL80211_FLAG_NEED_RTNL,
7310 },
7311 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02007312 .cmd = NL80211_CMD_AUTHENTICATE,
7313 .doit = nl80211_authenticate,
7314 .policy = nl80211_policy,
7315 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007317 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007318 },
7319 {
7320 .cmd = NL80211_CMD_ASSOCIATE,
7321 .doit = nl80211_associate,
7322 .policy = nl80211_policy,
7323 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007324 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007325 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007326 },
7327 {
7328 .cmd = NL80211_CMD_DEAUTHENTICATE,
7329 .doit = nl80211_deauthenticate,
7330 .policy = nl80211_policy,
7331 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007332 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007333 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007334 },
7335 {
7336 .cmd = NL80211_CMD_DISASSOCIATE,
7337 .doit = nl80211_disassociate,
7338 .policy = nl80211_policy,
7339 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007340 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007341 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007342 },
Johannes Berg04a773a2009-04-19 21:24:32 +02007343 {
7344 .cmd = NL80211_CMD_JOIN_IBSS,
7345 .doit = nl80211_join_ibss,
7346 .policy = nl80211_policy,
7347 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007348 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007349 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007350 },
7351 {
7352 .cmd = NL80211_CMD_LEAVE_IBSS,
7353 .doit = nl80211_leave_ibss,
7354 .policy = nl80211_policy,
7355 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007356 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007357 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007358 },
Johannes Bergaff89a92009-07-01 21:26:51 +02007359#ifdef CONFIG_NL80211_TESTMODE
7360 {
7361 .cmd = NL80211_CMD_TESTMODE,
7362 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007363 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02007364 .policy = nl80211_policy,
7365 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007366 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7367 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007368 },
7369#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007370 {
7371 .cmd = NL80211_CMD_CONNECT,
7372 .doit = nl80211_connect,
7373 .policy = nl80211_policy,
7374 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007375 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007376 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007377 },
7378 {
7379 .cmd = NL80211_CMD_DISCONNECT,
7380 .doit = nl80211_disconnect,
7381 .policy = nl80211_policy,
7382 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007384 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007385 },
Johannes Berg463d0182009-07-14 00:33:35 +02007386 {
7387 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7388 .doit = nl80211_wiphy_netns,
7389 .policy = nl80211_policy,
7390 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007391 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7392 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007393 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007394 {
7395 .cmd = NL80211_CMD_GET_SURVEY,
7396 .policy = nl80211_policy,
7397 .dumpit = nl80211_dump_survey,
7398 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007399 {
7400 .cmd = NL80211_CMD_SET_PMKSA,
7401 .doit = nl80211_setdel_pmksa,
7402 .policy = nl80211_policy,
7403 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007404 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007405 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007406 },
7407 {
7408 .cmd = NL80211_CMD_DEL_PMKSA,
7409 .doit = nl80211_setdel_pmksa,
7410 .policy = nl80211_policy,
7411 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007412 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007413 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007414 },
7415 {
7416 .cmd = NL80211_CMD_FLUSH_PMKSA,
7417 .doit = nl80211_flush_pmksa,
7418 .policy = nl80211_policy,
7419 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007421 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007422 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007423 {
7424 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7425 .doit = nl80211_remain_on_channel,
7426 .policy = nl80211_policy,
7427 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007428 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007429 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007430 },
7431 {
7432 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7433 .doit = nl80211_cancel_remain_on_channel,
7434 .policy = nl80211_policy,
7435 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007436 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007437 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007438 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007439 {
7440 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7441 .doit = nl80211_set_tx_bitrate_mask,
7442 .policy = nl80211_policy,
7443 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007444 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7445 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007446 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007447 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007448 .cmd = NL80211_CMD_REGISTER_FRAME,
7449 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007450 .policy = nl80211_policy,
7451 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007452 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007453 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007454 },
7455 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007456 .cmd = NL80211_CMD_FRAME,
7457 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007458 .policy = nl80211_policy,
7459 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007460 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007461 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007462 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007463 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007464 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7465 .doit = nl80211_tx_mgmt_cancel_wait,
7466 .policy = nl80211_policy,
7467 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007468 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007469 NL80211_FLAG_NEED_RTNL,
7470 },
7471 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007472 .cmd = NL80211_CMD_SET_POWER_SAVE,
7473 .doit = nl80211_set_power_save,
7474 .policy = nl80211_policy,
7475 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007476 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7477 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007478 },
7479 {
7480 .cmd = NL80211_CMD_GET_POWER_SAVE,
7481 .doit = nl80211_get_power_save,
7482 .policy = nl80211_policy,
7483 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007484 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7485 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007486 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007487 {
7488 .cmd = NL80211_CMD_SET_CQM,
7489 .doit = nl80211_set_cqm,
7490 .policy = nl80211_policy,
7491 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007492 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7493 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007494 },
Johannes Bergf444de02010-05-05 15:25:02 +02007495 {
7496 .cmd = NL80211_CMD_SET_CHANNEL,
7497 .doit = nl80211_set_channel,
7498 .policy = nl80211_policy,
7499 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007500 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7501 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007502 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007503 {
7504 .cmd = NL80211_CMD_SET_WDS_PEER,
7505 .doit = nl80211_set_wds_peer,
7506 .policy = nl80211_policy,
7507 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007508 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7509 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007510 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007511 {
7512 .cmd = NL80211_CMD_JOIN_MESH,
7513 .doit = nl80211_join_mesh,
7514 .policy = nl80211_policy,
7515 .flags = GENL_ADMIN_PERM,
7516 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7517 NL80211_FLAG_NEED_RTNL,
7518 },
7519 {
7520 .cmd = NL80211_CMD_LEAVE_MESH,
7521 .doit = nl80211_leave_mesh,
7522 .policy = nl80211_policy,
7523 .flags = GENL_ADMIN_PERM,
7524 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7525 NL80211_FLAG_NEED_RTNL,
7526 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007527#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007528 {
7529 .cmd = NL80211_CMD_GET_WOWLAN,
7530 .doit = nl80211_get_wowlan,
7531 .policy = nl80211_policy,
7532 /* can be retrieved by unprivileged users */
7533 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7534 NL80211_FLAG_NEED_RTNL,
7535 },
7536 {
7537 .cmd = NL80211_CMD_SET_WOWLAN,
7538 .doit = nl80211_set_wowlan,
7539 .policy = nl80211_policy,
7540 .flags = GENL_ADMIN_PERM,
7541 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7542 NL80211_FLAG_NEED_RTNL,
7543 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007544#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007545 {
7546 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7547 .doit = nl80211_set_rekey_data,
7548 .policy = nl80211_policy,
7549 .flags = GENL_ADMIN_PERM,
7550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7551 NL80211_FLAG_NEED_RTNL,
7552 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007553 {
7554 .cmd = NL80211_CMD_TDLS_MGMT,
7555 .doit = nl80211_tdls_mgmt,
7556 .policy = nl80211_policy,
7557 .flags = GENL_ADMIN_PERM,
7558 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7559 NL80211_FLAG_NEED_RTNL,
7560 },
7561 {
7562 .cmd = NL80211_CMD_TDLS_OPER,
7563 .doit = nl80211_tdls_oper,
7564 .policy = nl80211_policy,
7565 .flags = GENL_ADMIN_PERM,
7566 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7567 NL80211_FLAG_NEED_RTNL,
7568 },
Johannes Berg28946da2011-11-04 11:18:12 +01007569 {
7570 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7571 .doit = nl80211_register_unexpected_frame,
7572 .policy = nl80211_policy,
7573 .flags = GENL_ADMIN_PERM,
7574 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7575 NL80211_FLAG_NEED_RTNL,
7576 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007577 {
7578 .cmd = NL80211_CMD_PROBE_CLIENT,
7579 .doit = nl80211_probe_client,
7580 .policy = nl80211_policy,
7581 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007582 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007583 NL80211_FLAG_NEED_RTNL,
7584 },
Johannes Berg5e760232011-11-04 11:18:17 +01007585 {
7586 .cmd = NL80211_CMD_REGISTER_BEACONS,
7587 .doit = nl80211_register_beacons,
7588 .policy = nl80211_policy,
7589 .flags = GENL_ADMIN_PERM,
7590 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7591 NL80211_FLAG_NEED_RTNL,
7592 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007593 {
7594 .cmd = NL80211_CMD_SET_NOACK_MAP,
7595 .doit = nl80211_set_noack_map,
7596 .policy = nl80211_policy,
7597 .flags = GENL_ADMIN_PERM,
7598 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7599 NL80211_FLAG_NEED_RTNL,
7600 },
Johannes Berg98104fde2012-06-16 00:19:54 +02007601 {
7602 .cmd = NL80211_CMD_START_P2P_DEVICE,
7603 .doit = nl80211_start_p2p_device,
7604 .policy = nl80211_policy,
7605 .flags = GENL_ADMIN_PERM,
7606 .internal_flags = NL80211_FLAG_NEED_WDEV |
7607 NL80211_FLAG_NEED_RTNL,
7608 },
7609 {
7610 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
7611 .doit = nl80211_stop_p2p_device,
7612 .policy = nl80211_policy,
7613 .flags = GENL_ADMIN_PERM,
7614 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7615 NL80211_FLAG_NEED_RTNL,
7616 },
Johannes Berg55682962007-09-20 13:09:35 -04007617};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007618
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007619static struct genl_multicast_group nl80211_mlme_mcgrp = {
7620 .name = "mlme",
7621};
Johannes Berg55682962007-09-20 13:09:35 -04007622
7623/* multicast groups */
7624static struct genl_multicast_group nl80211_config_mcgrp = {
7625 .name = "config",
7626};
Johannes Berg2a519312009-02-10 21:25:55 +01007627static struct genl_multicast_group nl80211_scan_mcgrp = {
7628 .name = "scan",
7629};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007630static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7631 .name = "regulatory",
7632};
Johannes Berg55682962007-09-20 13:09:35 -04007633
7634/* notification functions */
7635
7636void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7637{
7638 struct sk_buff *msg;
7639
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007640 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007641 if (!msg)
7642 return;
7643
7644 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7645 nlmsg_free(msg);
7646 return;
7647 }
7648
Johannes Berg463d0182009-07-14 00:33:35 +02007649 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7650 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007651}
7652
Johannes Berg362a4152009-05-24 16:43:15 +02007653static int nl80211_add_scan_req(struct sk_buff *msg,
7654 struct cfg80211_registered_device *rdev)
7655{
7656 struct cfg80211_scan_request *req = rdev->scan_req;
7657 struct nlattr *nest;
7658 int i;
7659
Johannes Berg667503d2009-07-07 03:56:11 +02007660 ASSERT_RDEV_LOCK(rdev);
7661
Johannes Berg362a4152009-05-24 16:43:15 +02007662 if (WARN_ON(!req))
7663 return 0;
7664
7665 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7666 if (!nest)
7667 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007668 for (i = 0; i < req->n_ssids; i++) {
7669 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7670 goto nla_put_failure;
7671 }
Johannes Berg362a4152009-05-24 16:43:15 +02007672 nla_nest_end(msg, nest);
7673
7674 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7675 if (!nest)
7676 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007677 for (i = 0; i < req->n_channels; i++) {
7678 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7679 goto nla_put_failure;
7680 }
Johannes Berg362a4152009-05-24 16:43:15 +02007681 nla_nest_end(msg, nest);
7682
David S. Miller9360ffd2012-03-29 04:41:26 -04007683 if (req->ie &&
7684 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7685 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007686
Sam Lefflered4737712012-10-11 21:03:31 -07007687 if (req->flags)
7688 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
7689
Johannes Berg362a4152009-05-24 16:43:15 +02007690 return 0;
7691 nla_put_failure:
7692 return -ENOBUFS;
7693}
7694
Johannes Berga538e2d2009-06-16 19:56:42 +02007695static int nl80211_send_scan_msg(struct sk_buff *msg,
7696 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007697 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007698 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02007699 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007700{
7701 void *hdr;
7702
Eric W. Biederman15e47302012-09-07 20:12:54 +00007703 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01007704 if (!hdr)
7705 return -1;
7706
David S. Miller9360ffd2012-03-29 04:41:26 -04007707 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02007708 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
7709 wdev->netdev->ifindex)) ||
7710 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007711 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007712
Johannes Berg362a4152009-05-24 16:43:15 +02007713 /* ignore errors and send incomplete event anyway */
7714 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007715
7716 return genlmsg_end(msg, hdr);
7717
7718 nla_put_failure:
7719 genlmsg_cancel(msg, hdr);
7720 return -EMSGSIZE;
7721}
7722
Luciano Coelho807f8a82011-05-11 17:09:35 +03007723static int
7724nl80211_send_sched_scan_msg(struct sk_buff *msg,
7725 struct cfg80211_registered_device *rdev,
7726 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007727 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007728{
7729 void *hdr;
7730
Eric W. Biederman15e47302012-09-07 20:12:54 +00007731 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007732 if (!hdr)
7733 return -1;
7734
David S. Miller9360ffd2012-03-29 04:41:26 -04007735 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7736 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7737 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007738
7739 return genlmsg_end(msg, hdr);
7740
7741 nla_put_failure:
7742 genlmsg_cancel(msg, hdr);
7743 return -EMSGSIZE;
7744}
7745
Johannes Berga538e2d2009-06-16 19:56:42 +02007746void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007747 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02007748{
7749 struct sk_buff *msg;
7750
Thomas Graf58050fc2012-06-28 03:57:45 +00007751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007752 if (!msg)
7753 return;
7754
Johannes Bergfd014282012-06-18 19:17:03 +02007755 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007756 NL80211_CMD_TRIGGER_SCAN) < 0) {
7757 nlmsg_free(msg);
7758 return;
7759 }
7760
Johannes Berg463d0182009-07-14 00:33:35 +02007761 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7762 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007763}
7764
Johannes Berg2a519312009-02-10 21:25:55 +01007765void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007766 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007767{
7768 struct sk_buff *msg;
7769
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007771 if (!msg)
7772 return;
7773
Johannes Bergfd014282012-06-18 19:17:03 +02007774 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007775 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007776 nlmsg_free(msg);
7777 return;
7778 }
7779
Johannes Berg463d0182009-07-14 00:33:35 +02007780 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7781 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007782}
7783
7784void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007785 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007786{
7787 struct sk_buff *msg;
7788
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007789 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007790 if (!msg)
7791 return;
7792
Johannes Bergfd014282012-06-18 19:17:03 +02007793 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007794 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007795 nlmsg_free(msg);
7796 return;
7797 }
7798
Johannes Berg463d0182009-07-14 00:33:35 +02007799 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7800 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007801}
7802
Luciano Coelho807f8a82011-05-11 17:09:35 +03007803void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7804 struct net_device *netdev)
7805{
7806 struct sk_buff *msg;
7807
7808 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7809 if (!msg)
7810 return;
7811
7812 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7813 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7814 nlmsg_free(msg);
7815 return;
7816 }
7817
7818 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7819 nl80211_scan_mcgrp.id, GFP_KERNEL);
7820}
7821
7822void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7823 struct net_device *netdev, u32 cmd)
7824{
7825 struct sk_buff *msg;
7826
Thomas Graf58050fc2012-06-28 03:57:45 +00007827 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007828 if (!msg)
7829 return;
7830
7831 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7832 nlmsg_free(msg);
7833 return;
7834 }
7835
7836 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7837 nl80211_scan_mcgrp.id, GFP_KERNEL);
7838}
7839
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007840/*
7841 * This can happen on global regulatory changes or device specific settings
7842 * based on custom world regulatory domains.
7843 */
7844void nl80211_send_reg_change_event(struct regulatory_request *request)
7845{
7846 struct sk_buff *msg;
7847 void *hdr;
7848
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007849 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007850 if (!msg)
7851 return;
7852
7853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7854 if (!hdr) {
7855 nlmsg_free(msg);
7856 return;
7857 }
7858
7859 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007860 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7861 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007862
David S. Miller9360ffd2012-03-29 04:41:26 -04007863 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7864 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7865 NL80211_REGDOM_TYPE_WORLD))
7866 goto nla_put_failure;
7867 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7868 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7869 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7870 goto nla_put_failure;
7871 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7872 request->intersect) {
7873 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7874 NL80211_REGDOM_TYPE_INTERSECTION))
7875 goto nla_put_failure;
7876 } else {
7877 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7878 NL80211_REGDOM_TYPE_COUNTRY) ||
7879 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7880 request->alpha2))
7881 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007882 }
7883
David S. Miller9360ffd2012-03-29 04:41:26 -04007884 if (wiphy_idx_valid(request->wiphy_idx) &&
7885 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7886 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007887
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007888 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007889
Johannes Bergbc43b282009-07-25 10:54:13 +02007890 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007891 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007892 GFP_ATOMIC);
7893 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007894
7895 return;
7896
7897nla_put_failure:
7898 genlmsg_cancel(msg, hdr);
7899 nlmsg_free(msg);
7900}
7901
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007902static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7903 struct net_device *netdev,
7904 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007905 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007906{
7907 struct sk_buff *msg;
7908 void *hdr;
7909
Johannes Berge6d6e342009-07-01 21:26:47 +02007910 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007911 if (!msg)
7912 return;
7913
7914 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7915 if (!hdr) {
7916 nlmsg_free(msg);
7917 return;
7918 }
7919
David S. Miller9360ffd2012-03-29 04:41:26 -04007920 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7921 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7922 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7923 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007924
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007925 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007926
Johannes Berg463d0182009-07-14 00:33:35 +02007927 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7928 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007929 return;
7930
7931 nla_put_failure:
7932 genlmsg_cancel(msg, hdr);
7933 nlmsg_free(msg);
7934}
7935
7936void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007937 struct net_device *netdev, const u8 *buf,
7938 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007939{
7940 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007941 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007942}
7943
7944void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7945 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007946 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007947{
Johannes Berge6d6e342009-07-01 21:26:47 +02007948 nl80211_send_mlme_event(rdev, netdev, buf, len,
7949 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007950}
7951
Jouni Malinen53b46b82009-03-27 20:53:56 +02007952void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007953 struct net_device *netdev, const u8 *buf,
7954 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007955{
7956 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007957 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007958}
7959
Jouni Malinen53b46b82009-03-27 20:53:56 +02007960void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7961 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007962 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007963{
7964 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007965 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007966}
7967
Jouni Malinencf4e5942010-12-16 00:52:40 +02007968void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7969 struct net_device *netdev, const u8 *buf,
7970 size_t len, gfp_t gfp)
7971{
7972 nl80211_send_mlme_event(rdev, netdev, buf, len,
7973 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7974}
7975
7976void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7977 struct net_device *netdev, const u8 *buf,
7978 size_t len, gfp_t gfp)
7979{
7980 nl80211_send_mlme_event(rdev, netdev, buf, len,
7981 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7982}
7983
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007984static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7985 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007986 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007987{
7988 struct sk_buff *msg;
7989 void *hdr;
7990
Johannes Berge6d6e342009-07-01 21:26:47 +02007991 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007992 if (!msg)
7993 return;
7994
7995 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7996 if (!hdr) {
7997 nlmsg_free(msg);
7998 return;
7999 }
8000
David S. Miller9360ffd2012-03-29 04:41:26 -04008001 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8002 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8003 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
8004 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8005 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03008006
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008007 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03008008
Johannes Berg463d0182009-07-14 00:33:35 +02008009 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8010 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008011 return;
8012
8013 nla_put_failure:
8014 genlmsg_cancel(msg, hdr);
8015 nlmsg_free(msg);
8016}
8017
8018void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008019 struct net_device *netdev, const u8 *addr,
8020 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008021{
8022 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02008023 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008024}
8025
8026void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008027 struct net_device *netdev, const u8 *addr,
8028 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008029{
Johannes Berge6d6e342009-07-01 21:26:47 +02008030 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8031 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008032}
8033
Samuel Ortizb23aa672009-07-01 21:26:54 +02008034void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8035 struct net_device *netdev, const u8 *bssid,
8036 const u8 *req_ie, size_t req_ie_len,
8037 const u8 *resp_ie, size_t resp_ie_len,
8038 u16 status, gfp_t gfp)
8039{
8040 struct sk_buff *msg;
8041 void *hdr;
8042
Thomas Graf58050fc2012-06-28 03:57:45 +00008043 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008044 if (!msg)
8045 return;
8046
8047 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8048 if (!hdr) {
8049 nlmsg_free(msg);
8050 return;
8051 }
8052
David S. Miller9360ffd2012-03-29 04:41:26 -04008053 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8054 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8055 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8056 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8057 (req_ie &&
8058 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8059 (resp_ie &&
8060 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8061 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008062
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008063 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008064
Johannes Berg463d0182009-07-14 00:33:35 +02008065 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8066 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008067 return;
8068
8069 nla_put_failure:
8070 genlmsg_cancel(msg, hdr);
8071 nlmsg_free(msg);
8072
8073}
8074
8075void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8076 struct net_device *netdev, const u8 *bssid,
8077 const u8 *req_ie, size_t req_ie_len,
8078 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8079{
8080 struct sk_buff *msg;
8081 void *hdr;
8082
Thomas Graf58050fc2012-06-28 03:57:45 +00008083 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008084 if (!msg)
8085 return;
8086
8087 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8088 if (!hdr) {
8089 nlmsg_free(msg);
8090 return;
8091 }
8092
David S. Miller9360ffd2012-03-29 04:41:26 -04008093 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8094 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8095 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8096 (req_ie &&
8097 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8098 (resp_ie &&
8099 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8100 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008101
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008102 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008103
Johannes Berg463d0182009-07-14 00:33:35 +02008104 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8105 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008106 return;
8107
8108 nla_put_failure:
8109 genlmsg_cancel(msg, hdr);
8110 nlmsg_free(msg);
8111
8112}
8113
8114void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8115 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02008116 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008117{
8118 struct sk_buff *msg;
8119 void *hdr;
8120
Thomas Graf58050fc2012-06-28 03:57:45 +00008121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008122 if (!msg)
8123 return;
8124
8125 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8126 if (!hdr) {
8127 nlmsg_free(msg);
8128 return;
8129 }
8130
David S. Miller9360ffd2012-03-29 04:41:26 -04008131 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8132 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8133 (from_ap && reason &&
8134 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8135 (from_ap &&
8136 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8137 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8138 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008139
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008140 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008141
Johannes Berg463d0182009-07-14 00:33:35 +02008142 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8143 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008144 return;
8145
8146 nla_put_failure:
8147 genlmsg_cancel(msg, hdr);
8148 nlmsg_free(msg);
8149
8150}
8151
Johannes Berg04a773a2009-04-19 21:24:32 +02008152void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8153 struct net_device *netdev, const u8 *bssid,
8154 gfp_t gfp)
8155{
8156 struct sk_buff *msg;
8157 void *hdr;
8158
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008159 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008160 if (!msg)
8161 return;
8162
8163 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
8164 if (!hdr) {
8165 nlmsg_free(msg);
8166 return;
8167 }
8168
David S. Miller9360ffd2012-03-29 04:41:26 -04008169 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8170 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8172 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02008173
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008174 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02008175
Johannes Berg463d0182009-07-14 00:33:35 +02008176 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8177 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008178 return;
8179
8180 nla_put_failure:
8181 genlmsg_cancel(msg, hdr);
8182 nlmsg_free(msg);
8183}
8184
Javier Cardonac93b5e72011-04-07 15:08:34 -07008185void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
8186 struct net_device *netdev,
8187 const u8 *macaddr, const u8* ie, u8 ie_len,
8188 gfp_t gfp)
8189{
8190 struct sk_buff *msg;
8191 void *hdr;
8192
8193 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8194 if (!msg)
8195 return;
8196
8197 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
8198 if (!hdr) {
8199 nlmsg_free(msg);
8200 return;
8201 }
8202
David S. Miller9360ffd2012-03-29 04:41:26 -04008203 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8204 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8205 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
8206 (ie_len && ie &&
8207 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8208 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07008209
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008210 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07008211
8212 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8213 nl80211_mlme_mcgrp.id, gfp);
8214 return;
8215
8216 nla_put_failure:
8217 genlmsg_cancel(msg, hdr);
8218 nlmsg_free(msg);
8219}
8220
Jouni Malinena3b8b052009-03-27 21:59:49 +02008221void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
8222 struct net_device *netdev, const u8 *addr,
8223 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02008224 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02008225{
8226 struct sk_buff *msg;
8227 void *hdr;
8228
Johannes Berge6d6e342009-07-01 21:26:47 +02008229 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008230 if (!msg)
8231 return;
8232
8233 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
8234 if (!hdr) {
8235 nlmsg_free(msg);
8236 return;
8237 }
8238
David S. Miller9360ffd2012-03-29 04:41:26 -04008239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8240 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8241 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
8242 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
8243 (key_id != -1 &&
8244 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
8245 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
8246 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02008247
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008248 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008249
Johannes Berg463d0182009-07-14 00:33:35 +02008250 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8251 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008252 return;
8253
8254 nla_put_failure:
8255 genlmsg_cancel(msg, hdr);
8256 nlmsg_free(msg);
8257}
8258
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008259void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
8260 struct ieee80211_channel *channel_before,
8261 struct ieee80211_channel *channel_after)
8262{
8263 struct sk_buff *msg;
8264 void *hdr;
8265 struct nlattr *nl_freq;
8266
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008267 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008268 if (!msg)
8269 return;
8270
8271 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
8272 if (!hdr) {
8273 nlmsg_free(msg);
8274 return;
8275 }
8276
8277 /*
8278 * Since we are applying the beacon hint to a wiphy we know its
8279 * wiphy_idx is valid
8280 */
David S. Miller9360ffd2012-03-29 04:41:26 -04008281 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8282 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008283
8284 /* Before */
8285 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
8286 if (!nl_freq)
8287 goto nla_put_failure;
8288 if (nl80211_msg_put_channel(msg, channel_before))
8289 goto nla_put_failure;
8290 nla_nest_end(msg, nl_freq);
8291
8292 /* After */
8293 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
8294 if (!nl_freq)
8295 goto nla_put_failure;
8296 if (nl80211_msg_put_channel(msg, channel_after))
8297 goto nla_put_failure;
8298 nla_nest_end(msg, nl_freq);
8299
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008300 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008301
Johannes Berg463d0182009-07-14 00:33:35 +02008302 rcu_read_lock();
8303 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8304 GFP_ATOMIC);
8305 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008306
8307 return;
8308
8309nla_put_failure:
8310 genlmsg_cancel(msg, hdr);
8311 nlmsg_free(msg);
8312}
8313
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008314static void nl80211_send_remain_on_chan_event(
8315 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008316 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008317 struct ieee80211_channel *chan,
8318 enum nl80211_channel_type channel_type,
8319 unsigned int duration, gfp_t gfp)
8320{
8321 struct sk_buff *msg;
8322 void *hdr;
8323
8324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8325 if (!msg)
8326 return;
8327
8328 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8329 if (!hdr) {
8330 nlmsg_free(msg);
8331 return;
8332 }
8333
David S. Miller9360ffd2012-03-29 04:41:26 -04008334 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008335 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8336 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02008337 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008338 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
8339 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
8340 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8341 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008342
David S. Miller9360ffd2012-03-29 04:41:26 -04008343 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
8344 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
8345 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008346
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008347 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008348
8349 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8350 nl80211_mlme_mcgrp.id, gfp);
8351 return;
8352
8353 nla_put_failure:
8354 genlmsg_cancel(msg, hdr);
8355 nlmsg_free(msg);
8356}
8357
8358void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008359 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008360 struct ieee80211_channel *chan,
8361 enum nl80211_channel_type channel_type,
8362 unsigned int duration, gfp_t gfp)
8363{
8364 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008365 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008366 channel_type, duration, gfp);
8367}
8368
8369void nl80211_send_remain_on_channel_cancel(
Johannes Berg71bbc992012-06-15 15:30:18 +02008370 struct cfg80211_registered_device *rdev,
8371 struct wireless_dev *wdev,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008372 u64 cookie, struct ieee80211_channel *chan,
8373 enum nl80211_channel_type channel_type, gfp_t gfp)
8374{
8375 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008376 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008377 channel_type, 0, gfp);
8378}
8379
Johannes Berg98b62182009-12-23 13:15:44 +01008380void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
8381 struct net_device *dev, const u8 *mac_addr,
8382 struct station_info *sinfo, gfp_t gfp)
8383{
8384 struct sk_buff *msg;
8385
Thomas Graf58050fc2012-06-28 03:57:45 +00008386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01008387 if (!msg)
8388 return;
8389
John W. Linville66266b32012-03-15 13:25:41 -04008390 if (nl80211_send_station(msg, 0, 0, 0,
8391 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008392 nlmsg_free(msg);
8393 return;
8394 }
8395
8396 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8397 nl80211_mlme_mcgrp.id, gfp);
8398}
8399
Jouni Malinenec15e682011-03-23 15:29:52 +02008400void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8401 struct net_device *dev, const u8 *mac_addr,
8402 gfp_t gfp)
8403{
8404 struct sk_buff *msg;
8405 void *hdr;
8406
Thomas Graf58050fc2012-06-28 03:57:45 +00008407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02008408 if (!msg)
8409 return;
8410
8411 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8412 if (!hdr) {
8413 nlmsg_free(msg);
8414 return;
8415 }
8416
David S. Miller9360ffd2012-03-29 04:41:26 -04008417 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8418 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8419 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008420
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008421 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008422
8423 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8424 nl80211_mlme_mcgrp.id, gfp);
8425 return;
8426
8427 nla_put_failure:
8428 genlmsg_cancel(msg, hdr);
8429 nlmsg_free(msg);
8430}
8431
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05308432void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
8433 struct net_device *dev, const u8 *mac_addr,
8434 enum nl80211_connect_failed_reason reason,
8435 gfp_t gfp)
8436{
8437 struct sk_buff *msg;
8438 void *hdr;
8439
8440 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8441 if (!msg)
8442 return;
8443
8444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
8445 if (!hdr) {
8446 nlmsg_free(msg);
8447 return;
8448 }
8449
8450 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8451 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
8452 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
8453 goto nla_put_failure;
8454
8455 genlmsg_end(msg, hdr);
8456
8457 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8458 nl80211_mlme_mcgrp.id, gfp);
8459 return;
8460
8461 nla_put_failure:
8462 genlmsg_cancel(msg, hdr);
8463 nlmsg_free(msg);
8464}
8465
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008466static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8467 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008468{
8469 struct wireless_dev *wdev = dev->ieee80211_ptr;
8470 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8471 struct sk_buff *msg;
8472 void *hdr;
8473 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00008474 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01008475
Eric W. Biederman15e47302012-09-07 20:12:54 +00008476 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008477 return false;
8478
8479 msg = nlmsg_new(100, gfp);
8480 if (!msg)
8481 return true;
8482
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008483 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008484 if (!hdr) {
8485 nlmsg_free(msg);
8486 return true;
8487 }
8488
David S. Miller9360ffd2012-03-29 04:41:26 -04008489 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8490 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8491 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8492 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008493
8494 err = genlmsg_end(msg, hdr);
8495 if (err < 0) {
8496 nlmsg_free(msg);
8497 return true;
8498 }
8499
Eric W. Biederman15e47302012-09-07 20:12:54 +00008500 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01008501 return true;
8502
8503 nla_put_failure:
8504 genlmsg_cancel(msg, hdr);
8505 nlmsg_free(msg);
8506 return true;
8507}
8508
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008509bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8510{
8511 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8512 addr, gfp);
8513}
8514
8515bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8516 const u8 *addr, gfp_t gfp)
8517{
8518 return __nl80211_unexpected_frame(dev,
8519 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8520 addr, gfp);
8521}
8522
Johannes Berg2e161f72010-08-12 15:38:38 +02008523int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008524 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01008525 int freq, int sig_dbm,
8526 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008527{
Johannes Berg71bbc992012-06-15 15:30:18 +02008528 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008529 struct sk_buff *msg;
8530 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008531
8532 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8533 if (!msg)
8534 return -ENOMEM;
8535
Johannes Berg2e161f72010-08-12 15:38:38 +02008536 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008537 if (!hdr) {
8538 nlmsg_free(msg);
8539 return -ENOMEM;
8540 }
8541
David S. Miller9360ffd2012-03-29 04:41:26 -04008542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008543 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8544 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008545 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8546 (sig_dbm &&
8547 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8548 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8549 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008550
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008551 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008552
Eric W. Biederman15e47302012-09-07 20:12:54 +00008553 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008554
8555 nla_put_failure:
8556 genlmsg_cancel(msg, hdr);
8557 nlmsg_free(msg);
8558 return -ENOBUFS;
8559}
8560
Johannes Berg2e161f72010-08-12 15:38:38 +02008561void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008562 struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +02008563 const u8 *buf, size_t len, bool ack,
8564 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008565{
Johannes Berg71bbc992012-06-15 15:30:18 +02008566 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008567 struct sk_buff *msg;
8568 void *hdr;
8569
8570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8571 if (!msg)
8572 return;
8573
Johannes Berg2e161f72010-08-12 15:38:38 +02008574 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008575 if (!hdr) {
8576 nlmsg_free(msg);
8577 return;
8578 }
8579
David S. Miller9360ffd2012-03-29 04:41:26 -04008580 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008581 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8582 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008583 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8584 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8585 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8586 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008587
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008588 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008589
8590 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8591 return;
8592
8593 nla_put_failure:
8594 genlmsg_cancel(msg, hdr);
8595 nlmsg_free(msg);
8596}
8597
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008598void
8599nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8600 struct net_device *netdev,
8601 enum nl80211_cqm_rssi_threshold_event rssi_event,
8602 gfp_t gfp)
8603{
8604 struct sk_buff *msg;
8605 struct nlattr *pinfoattr;
8606 void *hdr;
8607
Thomas Graf58050fc2012-06-28 03:57:45 +00008608 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008609 if (!msg)
8610 return;
8611
8612 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8613 if (!hdr) {
8614 nlmsg_free(msg);
8615 return;
8616 }
8617
David S. Miller9360ffd2012-03-29 04:41:26 -04008618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8620 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008621
8622 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8623 if (!pinfoattr)
8624 goto nla_put_failure;
8625
David S. Miller9360ffd2012-03-29 04:41:26 -04008626 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8627 rssi_event))
8628 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008629
8630 nla_nest_end(msg, pinfoattr);
8631
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008632 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008633
8634 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8635 nl80211_mlme_mcgrp.id, gfp);
8636 return;
8637
8638 nla_put_failure:
8639 genlmsg_cancel(msg, hdr);
8640 nlmsg_free(msg);
8641}
8642
Johannes Berge5497d72011-07-05 16:35:40 +02008643void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8644 struct net_device *netdev, const u8 *bssid,
8645 const u8 *replay_ctr, gfp_t gfp)
8646{
8647 struct sk_buff *msg;
8648 struct nlattr *rekey_attr;
8649 void *hdr;
8650
Thomas Graf58050fc2012-06-28 03:57:45 +00008651 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02008652 if (!msg)
8653 return;
8654
8655 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8656 if (!hdr) {
8657 nlmsg_free(msg);
8658 return;
8659 }
8660
David S. Miller9360ffd2012-03-29 04:41:26 -04008661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8662 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8663 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8664 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008665
8666 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8667 if (!rekey_attr)
8668 goto nla_put_failure;
8669
David S. Miller9360ffd2012-03-29 04:41:26 -04008670 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8671 NL80211_REPLAY_CTR_LEN, replay_ctr))
8672 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008673
8674 nla_nest_end(msg, rekey_attr);
8675
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008676 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008677
8678 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8679 nl80211_mlme_mcgrp.id, gfp);
8680 return;
8681
8682 nla_put_failure:
8683 genlmsg_cancel(msg, hdr);
8684 nlmsg_free(msg);
8685}
8686
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008687void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8688 struct net_device *netdev, int index,
8689 const u8 *bssid, bool preauth, gfp_t gfp)
8690{
8691 struct sk_buff *msg;
8692 struct nlattr *attr;
8693 void *hdr;
8694
Thomas Graf58050fc2012-06-28 03:57:45 +00008695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008696 if (!msg)
8697 return;
8698
8699 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8700 if (!hdr) {
8701 nlmsg_free(msg);
8702 return;
8703 }
8704
David S. Miller9360ffd2012-03-29 04:41:26 -04008705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8707 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008708
8709 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8710 if (!attr)
8711 goto nla_put_failure;
8712
David S. Miller9360ffd2012-03-29 04:41:26 -04008713 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8714 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8715 (preauth &&
8716 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8717 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008718
8719 nla_nest_end(msg, attr);
8720
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008721 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008722
8723 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8724 nl80211_mlme_mcgrp.id, gfp);
8725 return;
8726
8727 nla_put_failure:
8728 genlmsg_cancel(msg, hdr);
8729 nlmsg_free(msg);
8730}
8731
Thomas Pedersen53145262012-04-06 13:35:47 -07008732void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8733 struct net_device *netdev, int freq,
8734 enum nl80211_channel_type type, gfp_t gfp)
8735{
8736 struct sk_buff *msg;
8737 void *hdr;
8738
Thomas Graf58050fc2012-06-28 03:57:45 +00008739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -07008740 if (!msg)
8741 return;
8742
8743 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8744 if (!hdr) {
8745 nlmsg_free(msg);
8746 return;
8747 }
8748
John W. Linville7eab0f62012-04-12 14:25:14 -04008749 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8750 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8751 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8752 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008753
8754 genlmsg_end(msg, hdr);
8755
8756 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8757 nl80211_mlme_mcgrp.id, gfp);
8758 return;
8759
8760 nla_put_failure:
8761 genlmsg_cancel(msg, hdr);
8762 nlmsg_free(msg);
8763}
8764
Johannes Bergc063dbf2010-11-24 08:10:05 +01008765void
Thomas Pedersen84f10702012-07-12 16:17:33 -07008766nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
8767 struct net_device *netdev, const u8 *peer,
8768 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
8769{
8770 struct sk_buff *msg;
8771 struct nlattr *pinfoattr;
8772 void *hdr;
8773
8774 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8775 if (!msg)
8776 return;
8777
8778 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8779 if (!hdr) {
8780 nlmsg_free(msg);
8781 return;
8782 }
8783
8784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8785 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8786 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8787 goto nla_put_failure;
8788
8789 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8790 if (!pinfoattr)
8791 goto nla_put_failure;
8792
8793 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
8794 goto nla_put_failure;
8795
8796 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
8797 goto nla_put_failure;
8798
8799 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
8800 goto nla_put_failure;
8801
8802 nla_nest_end(msg, pinfoattr);
8803
8804 genlmsg_end(msg, hdr);
8805
8806 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8807 nl80211_mlme_mcgrp.id, gfp);
8808 return;
8809
8810 nla_put_failure:
8811 genlmsg_cancel(msg, hdr);
8812 nlmsg_free(msg);
8813}
8814
8815void
Johannes Bergc063dbf2010-11-24 08:10:05 +01008816nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8817 struct net_device *netdev, const u8 *peer,
8818 u32 num_packets, gfp_t gfp)
8819{
8820 struct sk_buff *msg;
8821 struct nlattr *pinfoattr;
8822 void *hdr;
8823
Thomas Graf58050fc2012-06-28 03:57:45 +00008824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008825 if (!msg)
8826 return;
8827
8828 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8829 if (!hdr) {
8830 nlmsg_free(msg);
8831 return;
8832 }
8833
David S. Miller9360ffd2012-03-29 04:41:26 -04008834 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8835 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8836 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8837 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008838
8839 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8840 if (!pinfoattr)
8841 goto nla_put_failure;
8842
David S. Miller9360ffd2012-03-29 04:41:26 -04008843 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8844 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008845
8846 nla_nest_end(msg, pinfoattr);
8847
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008848 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008849
8850 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8851 nl80211_mlme_mcgrp.id, gfp);
8852 return;
8853
8854 nla_put_failure:
8855 genlmsg_cancel(msg, hdr);
8856 nlmsg_free(msg);
8857}
8858
Johannes Berg7f6cf312011-11-04 11:18:15 +01008859void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8860 u64 cookie, bool acked, gfp_t gfp)
8861{
8862 struct wireless_dev *wdev = dev->ieee80211_ptr;
8863 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8864 struct sk_buff *msg;
8865 void *hdr;
8866 int err;
8867
Thomas Graf58050fc2012-06-28 03:57:45 +00008868 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008869 if (!msg)
8870 return;
8871
8872 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8873 if (!hdr) {
8874 nlmsg_free(msg);
8875 return;
8876 }
8877
David S. Miller9360ffd2012-03-29 04:41:26 -04008878 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8879 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8880 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8881 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8882 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8883 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008884
8885 err = genlmsg_end(msg, hdr);
8886 if (err < 0) {
8887 nlmsg_free(msg);
8888 return;
8889 }
8890
8891 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8892 nl80211_mlme_mcgrp.id, gfp);
8893 return;
8894
8895 nla_put_failure:
8896 genlmsg_cancel(msg, hdr);
8897 nlmsg_free(msg);
8898}
8899EXPORT_SYMBOL(cfg80211_probe_status);
8900
Johannes Berg5e760232011-11-04 11:18:17 +01008901void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8902 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008903 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008904{
8905 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8906 struct sk_buff *msg;
8907 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00008908 u32 nlportid = ACCESS_ONCE(rdev->ap_beacons_nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +01008909
Eric W. Biederman15e47302012-09-07 20:12:54 +00008910 if (!nlportid)
Johannes Berg5e760232011-11-04 11:18:17 +01008911 return;
8912
8913 msg = nlmsg_new(len + 100, gfp);
8914 if (!msg)
8915 return;
8916
8917 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8918 if (!hdr) {
8919 nlmsg_free(msg);
8920 return;
8921 }
8922
David S. Miller9360ffd2012-03-29 04:41:26 -04008923 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8924 (freq &&
8925 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8926 (sig_dbm &&
8927 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8928 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8929 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01008930
8931 genlmsg_end(msg, hdr);
8932
Eric W. Biederman15e47302012-09-07 20:12:54 +00008933 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +01008934 return;
8935
8936 nla_put_failure:
8937 genlmsg_cancel(msg, hdr);
8938 nlmsg_free(msg);
8939}
8940EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8941
Jouni Malinen026331c2010-02-15 12:53:10 +02008942static int nl80211_netlink_notify(struct notifier_block * nb,
8943 unsigned long state,
8944 void *_notify)
8945{
8946 struct netlink_notify *notify = _notify;
8947 struct cfg80211_registered_device *rdev;
8948 struct wireless_dev *wdev;
8949
8950 if (state != NETLINK_URELEASE)
8951 return NOTIFY_DONE;
8952
8953 rcu_read_lock();
8954
Johannes Berg5e760232011-11-04 11:18:17 +01008955 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008956 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +00008957 cfg80211_mlme_unregister_socket(wdev, notify->portid);
8958 if (rdev->ap_beacons_nlportid == notify->portid)
8959 rdev->ap_beacons_nlportid = 0;
Johannes Berg5e760232011-11-04 11:18:17 +01008960 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008961
8962 rcu_read_unlock();
8963
8964 return NOTIFY_DONE;
8965}
8966
8967static struct notifier_block nl80211_netlink_notifier = {
8968 .notifier_call = nl80211_netlink_notify,
8969};
8970
Johannes Berg55682962007-09-20 13:09:35 -04008971/* initialisation/exit functions */
8972
8973int nl80211_init(void)
8974{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008975 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008976
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008977 err = genl_register_family_with_ops(&nl80211_fam,
8978 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008979 if (err)
8980 return err;
8981
Johannes Berg55682962007-09-20 13:09:35 -04008982 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8983 if (err)
8984 goto err_out;
8985
Johannes Berg2a519312009-02-10 21:25:55 +01008986 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8987 if (err)
8988 goto err_out;
8989
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008990 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8991 if (err)
8992 goto err_out;
8993
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008994 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8995 if (err)
8996 goto err_out;
8997
Johannes Bergaff89a92009-07-01 21:26:51 +02008998#ifdef CONFIG_NL80211_TESTMODE
8999 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
9000 if (err)
9001 goto err_out;
9002#endif
9003
Jouni Malinen026331c2010-02-15 12:53:10 +02009004 err = netlink_register_notifier(&nl80211_netlink_notifier);
9005 if (err)
9006 goto err_out;
9007
Johannes Berg55682962007-09-20 13:09:35 -04009008 return 0;
9009 err_out:
9010 genl_unregister_family(&nl80211_fam);
9011 return err;
9012}
9013
9014void nl80211_exit(void)
9015{
Jouni Malinen026331c2010-02-15 12:53:10 +02009016 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04009017 genl_unregister_family(&nl80211_fam);
9018}