blob: ef170e982f912aadbb6b54ba5a017726972aef11 [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 Malinendc6382ce2009-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 },
Johannes Berg55682962007-09-20 13:09:35 -0400359};
360
Johannes Berge31b8212010-10-05 19:39:30 +0200361/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000362static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200363 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200364 [NL80211_KEY_IDX] = { .type = NLA_U8 },
365 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200366 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200367 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
368 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200369 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100370 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
371};
372
373/* policy for the key default flags */
374static const struct nla_policy
375nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
376 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
377 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200378};
379
Johannes Bergff1b6e62011-05-04 15:37:28 +0200380/* policy for WoWLAN attributes */
381static const struct nla_policy
382nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
383 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
385 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200387 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
389 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
390 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200391};
392
Johannes Berge5497d72011-07-05 16:35:40 +0200393/* policy for GTK rekey offload attributes */
394static const struct nla_policy
395nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
396 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
397 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
398 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
399};
400
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300401static const struct nla_policy
402nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200403 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300404 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700405 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300406};
407
Holger Schuriga0438972009-11-11 11:30:02 +0100408/* ifidx get helper */
409static int nl80211_get_ifidx(struct netlink_callback *cb)
410{
411 int res;
412
413 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
414 nl80211_fam.attrbuf, nl80211_fam.maxattr,
415 nl80211_policy);
416 if (res)
417 return res;
418
419 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
420 return -EINVAL;
421
422 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
423 if (!res)
424 return -EINVAL;
425 return res;
426}
427
Johannes Berg67748892010-10-04 21:14:06 +0200428static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
429 struct netlink_callback *cb,
430 struct cfg80211_registered_device **rdev,
431 struct net_device **dev)
432{
433 int ifidx = cb->args[0];
434 int err;
435
436 if (!ifidx)
437 ifidx = nl80211_get_ifidx(cb);
438 if (ifidx < 0)
439 return ifidx;
440
441 cb->args[0] = ifidx;
442
443 rtnl_lock();
444
445 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
446 if (!*dev) {
447 err = -ENODEV;
448 goto out_rtnl;
449 }
450
451 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100452 if (IS_ERR(*rdev)) {
453 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200454 goto out_rtnl;
455 }
456
457 return 0;
458 out_rtnl:
459 rtnl_unlock();
460 return err;
461}
462
463static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
464{
465 cfg80211_unlock_rdev(rdev);
466 rtnl_unlock();
467}
468
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100469/* IE validation */
470static bool is_valid_ie_attr(const struct nlattr *attr)
471{
472 const u8 *pos;
473 int len;
474
475 if (!attr)
476 return true;
477
478 pos = nla_data(attr);
479 len = nla_len(attr);
480
481 while (len) {
482 u8 elemlen;
483
484 if (len < 2)
485 return false;
486 len -= 2;
487
488 elemlen = pos[1];
489 if (elemlen > len)
490 return false;
491
492 len -= elemlen;
493 pos += 2 + elemlen;
494 }
495
496 return true;
497}
498
Johannes Berg55682962007-09-20 13:09:35 -0400499/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000500static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400501 int flags, u8 cmd)
502{
503 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000504 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400505}
506
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400507static int nl80211_msg_put_channel(struct sk_buff *msg,
508 struct ieee80211_channel *chan)
509{
David S. Miller9360ffd2012-03-29 04:41:26 -0400510 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
511 chan->center_freq))
512 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400513
David S. Miller9360ffd2012-03-29 04:41:26 -0400514 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
515 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
516 goto nla_put_failure;
517 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
518 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
519 goto nla_put_failure;
520 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
521 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
522 goto nla_put_failure;
523 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
524 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
525 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400526
David S. Miller9360ffd2012-03-29 04:41:26 -0400527 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
528 DBM_TO_MBM(chan->max_power)))
529 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400530
531 return 0;
532
533 nla_put_failure:
534 return -ENOBUFS;
535}
536
Johannes Berg55682962007-09-20 13:09:35 -0400537/* netlink command implementations */
538
Johannes Bergb9454e82009-07-08 13:29:08 +0200539struct key_parse {
540 struct key_params p;
541 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200542 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200543 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100544 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200545};
546
547static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
548{
549 struct nlattr *tb[NL80211_KEY_MAX + 1];
550 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
551 nl80211_key_policy);
552 if (err)
553 return err;
554
555 k->def = !!tb[NL80211_KEY_DEFAULT];
556 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
557
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100558 if (k->def) {
559 k->def_uni = true;
560 k->def_multi = true;
561 }
562 if (k->defmgmt)
563 k->def_multi = true;
564
Johannes Bergb9454e82009-07-08 13:29:08 +0200565 if (tb[NL80211_KEY_IDX])
566 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
567
568 if (tb[NL80211_KEY_DATA]) {
569 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
570 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
571 }
572
573 if (tb[NL80211_KEY_SEQ]) {
574 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
575 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
576 }
577
578 if (tb[NL80211_KEY_CIPHER])
579 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
580
Johannes Berge31b8212010-10-05 19:39:30 +0200581 if (tb[NL80211_KEY_TYPE]) {
582 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
583 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
584 return -EINVAL;
585 }
586
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100587 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
588 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100589 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
590 tb[NL80211_KEY_DEFAULT_TYPES],
591 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100592 if (err)
593 return err;
594
595 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
596 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
597 }
598
Johannes Bergb9454e82009-07-08 13:29:08 +0200599 return 0;
600}
601
602static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
603{
604 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
605 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
606 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
607 }
608
609 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
610 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
611 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
612 }
613
614 if (info->attrs[NL80211_ATTR_KEY_IDX])
615 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
616
617 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
618 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
619
620 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
621 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
622
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100623 if (k->def) {
624 k->def_uni = true;
625 k->def_multi = true;
626 }
627 if (k->defmgmt)
628 k->def_multi = true;
629
Johannes Berge31b8212010-10-05 19:39:30 +0200630 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
631 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
632 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
633 return -EINVAL;
634 }
635
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100636 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
637 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
638 int err = nla_parse_nested(
639 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
640 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
641 nl80211_key_default_policy);
642 if (err)
643 return err;
644
645 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
646 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
647 }
648
Johannes Bergb9454e82009-07-08 13:29:08 +0200649 return 0;
650}
651
652static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
653{
654 int err;
655
656 memset(k, 0, sizeof(*k));
657 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200658 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200659
660 if (info->attrs[NL80211_ATTR_KEY])
661 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
662 else
663 err = nl80211_parse_key_old(info, k);
664
665 if (err)
666 return err;
667
668 if (k->def && k->defmgmt)
669 return -EINVAL;
670
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100671 if (k->defmgmt) {
672 if (k->def_uni || !k->def_multi)
673 return -EINVAL;
674 }
675
Johannes Bergb9454e82009-07-08 13:29:08 +0200676 if (k->idx != -1) {
677 if (k->defmgmt) {
678 if (k->idx < 4 || k->idx > 5)
679 return -EINVAL;
680 } else if (k->def) {
681 if (k->idx < 0 || k->idx > 3)
682 return -EINVAL;
683 } else {
684 if (k->idx < 0 || k->idx > 5)
685 return -EINVAL;
686 }
687 }
688
689 return 0;
690}
691
Johannes Bergfffd0932009-07-08 14:22:54 +0200692static struct cfg80211_cached_keys *
693nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
694 struct nlattr *keys)
695{
696 struct key_parse parse;
697 struct nlattr *key;
698 struct cfg80211_cached_keys *result;
699 int rem, err, def = 0;
700
701 result = kzalloc(sizeof(*result), GFP_KERNEL);
702 if (!result)
703 return ERR_PTR(-ENOMEM);
704
705 result->def = -1;
706 result->defmgmt = -1;
707
708 nla_for_each_nested(key, keys, rem) {
709 memset(&parse, 0, sizeof(parse));
710 parse.idx = -1;
711
712 err = nl80211_parse_key_new(key, &parse);
713 if (err)
714 goto error;
715 err = -EINVAL;
716 if (!parse.p.key)
717 goto error;
718 if (parse.idx < 0 || parse.idx > 4)
719 goto error;
720 if (parse.def) {
721 if (def)
722 goto error;
723 def = 1;
724 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100725 if (!parse.def_uni || !parse.def_multi)
726 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200727 } else if (parse.defmgmt)
728 goto error;
729 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200730 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200731 if (err)
732 goto error;
733 result->params[parse.idx].cipher = parse.p.cipher;
734 result->params[parse.idx].key_len = parse.p.key_len;
735 result->params[parse.idx].key = result->data[parse.idx];
736 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
737 }
738
739 return result;
740 error:
741 kfree(result);
742 return ERR_PTR(err);
743}
744
745static int nl80211_key_allowed(struct wireless_dev *wdev)
746{
747 ASSERT_WDEV_LOCK(wdev);
748
Johannes Bergfffd0932009-07-08 14:22:54 +0200749 switch (wdev->iftype) {
750 case NL80211_IFTYPE_AP:
751 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200752 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700753 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200754 break;
755 case NL80211_IFTYPE_ADHOC:
756 if (!wdev->current_bss)
757 return -ENOLINK;
758 break;
759 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200760 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200761 if (wdev->sme_state != CFG80211_SME_CONNECTED)
762 return -ENOLINK;
763 break;
764 default:
765 return -EINVAL;
766 }
767
768 return 0;
769}
770
Johannes Berg7527a782011-05-13 10:58:57 +0200771static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
772{
773 struct nlattr *nl_modes = nla_nest_start(msg, attr);
774 int i;
775
776 if (!nl_modes)
777 goto nla_put_failure;
778
779 i = 0;
780 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400781 if ((ifmodes & 1) && nla_put_flag(msg, i))
782 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200783 ifmodes >>= 1;
784 i++;
785 }
786
787 nla_nest_end(msg, nl_modes);
788 return 0;
789
790nla_put_failure:
791 return -ENOBUFS;
792}
793
794static int nl80211_put_iface_combinations(struct wiphy *wiphy,
795 struct sk_buff *msg)
796{
797 struct nlattr *nl_combis;
798 int i, j;
799
800 nl_combis = nla_nest_start(msg,
801 NL80211_ATTR_INTERFACE_COMBINATIONS);
802 if (!nl_combis)
803 goto nla_put_failure;
804
805 for (i = 0; i < wiphy->n_iface_combinations; i++) {
806 const struct ieee80211_iface_combination *c;
807 struct nlattr *nl_combi, *nl_limits;
808
809 c = &wiphy->iface_combinations[i];
810
811 nl_combi = nla_nest_start(msg, i + 1);
812 if (!nl_combi)
813 goto nla_put_failure;
814
815 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
816 if (!nl_limits)
817 goto nla_put_failure;
818
819 for (j = 0; j < c->n_limits; j++) {
820 struct nlattr *nl_limit;
821
822 nl_limit = nla_nest_start(msg, j + 1);
823 if (!nl_limit)
824 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400825 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
826 c->limits[j].max))
827 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200828 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
829 c->limits[j].types))
830 goto nla_put_failure;
831 nla_nest_end(msg, nl_limit);
832 }
833
834 nla_nest_end(msg, nl_limits);
835
David S. Miller9360ffd2012-03-29 04:41:26 -0400836 if (c->beacon_int_infra_match &&
837 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
838 goto nla_put_failure;
839 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
840 c->num_different_channels) ||
841 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
842 c->max_interfaces))
843 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200844
845 nla_nest_end(msg, nl_combi);
846 }
847
848 nla_nest_end(msg, nl_combis);
849
850 return 0;
851nla_put_failure:
852 return -ENOBUFS;
853}
854
Eric W. Biederman15e47302012-09-07 20:12:54 +0000855static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Berg55682962007-09-20 13:09:35 -0400856 struct cfg80211_registered_device *dev)
857{
858 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100859 struct nlattr *nl_bands, *nl_band;
860 struct nlattr *nl_freqs, *nl_freq;
861 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100862 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100863 enum ieee80211_band band;
864 struct ieee80211_channel *chan;
865 struct ieee80211_rate *rate;
866 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200867 const struct ieee80211_txrx_stypes *mgmt_stypes =
868 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400869
Eric W. Biederman15e47302012-09-07 20:12:54 +0000870 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -0400871 if (!hdr)
872 return -1;
873
David S. Miller9360ffd2012-03-29 04:41:26 -0400874 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
875 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
876 nla_put_u32(msg, NL80211_ATTR_GENERATION,
877 cfg80211_rdev_list_generation) ||
878 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
879 dev->wiphy.retry_short) ||
880 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
881 dev->wiphy.retry_long) ||
882 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
883 dev->wiphy.frag_threshold) ||
884 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
885 dev->wiphy.rts_threshold) ||
886 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
887 dev->wiphy.coverage_class) ||
888 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
889 dev->wiphy.max_scan_ssids) ||
890 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
891 dev->wiphy.max_sched_scan_ssids) ||
892 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
893 dev->wiphy.max_scan_ie_len) ||
894 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
895 dev->wiphy.max_sched_scan_ie_len) ||
896 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
897 dev->wiphy.max_match_sets))
898 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200899
David S. Miller9360ffd2012-03-29 04:41:26 -0400900 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
901 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
902 goto nla_put_failure;
903 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
904 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
905 goto nla_put_failure;
906 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
907 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
908 goto nla_put_failure;
909 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
910 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
911 goto nla_put_failure;
912 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
913 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
914 goto nla_put_failure;
915 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
916 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
917 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200918
David S. Miller9360ffd2012-03-29 04:41:26 -0400919 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
920 sizeof(u32) * dev->wiphy.n_cipher_suites,
921 dev->wiphy.cipher_suites))
922 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100923
David S. Miller9360ffd2012-03-29 04:41:26 -0400924 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
925 dev->wiphy.max_num_pmkids))
926 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530927
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
929 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
930 goto nla_put_failure;
Johannes Berg25e47c182009-04-02 20:14:06 +0200931
David S. Miller9360ffd2012-03-29 04:41:26 -0400932 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
933 dev->wiphy.available_antennas_tx) ||
934 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
935 dev->wiphy.available_antennas_rx))
936 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100937
David S. Miller9360ffd2012-03-29 04:41:26 -0400938 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
939 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
940 dev->wiphy.probe_resp_offload))
941 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200942
Bruno Randolf7f531e02010-12-16 11:30:22 +0900943 if ((dev->wiphy.available_antennas_tx ||
944 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900945 u32 tx_ant = 0, rx_ant = 0;
946 int res;
947 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
948 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400949 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
950 tx_ant) ||
951 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
952 rx_ant))
953 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900954 }
955 }
956
Johannes Berg7527a782011-05-13 10:58:57 +0200957 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
958 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700959 goto nla_put_failure;
960
Johannes Bergee688b002008-01-24 19:38:39 +0100961 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
962 if (!nl_bands)
963 goto nla_put_failure;
964
965 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
966 if (!dev->wiphy.bands[band])
967 continue;
968
969 nl_band = nla_nest_start(msg, band);
970 if (!nl_band)
971 goto nla_put_failure;
972
Johannes Bergd51626d2008-10-09 12:20:13 +0200973 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400974 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
975 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
976 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
977 &dev->wiphy.bands[band]->ht_cap.mcs) ||
978 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
979 dev->wiphy.bands[band]->ht_cap.cap) ||
980 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
981 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
982 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
983 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
984 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200985
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000986 /* add VHT info */
987 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
988 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
989 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
990 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
991 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
992 dev->wiphy.bands[band]->vht_cap.cap)))
993 goto nla_put_failure;
994
Johannes Bergee688b002008-01-24 19:38:39 +0100995 /* add frequencies */
996 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
997 if (!nl_freqs)
998 goto nla_put_failure;
999
1000 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1001 nl_freq = nla_nest_start(msg, i);
1002 if (!nl_freq)
1003 goto nla_put_failure;
1004
1005 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +01001006
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001007 if (nl80211_msg_put_channel(msg, chan))
1008 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001009
Johannes Bergee688b002008-01-24 19:38:39 +01001010 nla_nest_end(msg, nl_freq);
1011 }
1012
1013 nla_nest_end(msg, nl_freqs);
1014
1015 /* add bitrates */
1016 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1017 if (!nl_rates)
1018 goto nla_put_failure;
1019
1020 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1021 nl_rate = nla_nest_start(msg, i);
1022 if (!nl_rate)
1023 goto nla_put_failure;
1024
1025 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -04001026 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1027 rate->bitrate))
1028 goto nla_put_failure;
1029 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1030 nla_put_flag(msg,
1031 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1032 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001033
1034 nla_nest_end(msg, nl_rate);
1035 }
1036
1037 nla_nest_end(msg, nl_rates);
1038
1039 nla_nest_end(msg, nl_band);
1040 }
1041 nla_nest_end(msg, nl_bands);
1042
Johannes Berg8fdc6212009-03-14 09:34:01 +01001043 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1044 if (!nl_cmds)
1045 goto nla_put_failure;
1046
1047 i = 0;
1048#define CMD(op, n) \
1049 do { \
1050 if (dev->ops->op) { \
1051 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -04001052 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1053 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +01001054 } \
1055 } while (0)
1056
1057 CMD(add_virtual_intf, NEW_INTERFACE);
1058 CMD(change_virtual_intf, SET_INTERFACE);
1059 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +01001060 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001061 CMD(add_station, NEW_STATION);
1062 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001063 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001064 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001065 CMD(auth, AUTHENTICATE);
1066 CMD(assoc, ASSOCIATE);
1067 CMD(deauth, DEAUTHENTICATE);
1068 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001069 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001070 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001071 CMD(set_pmksa, SET_PMKSA);
1072 CMD(del_pmksa, DEL_PMKSA);
1073 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001074 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1075 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001076 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001077 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001078 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001079 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001080 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001081 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1082 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001083 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001084 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001085 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001086 i++;
1087 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1088 goto nla_put_failure;
1089 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001090 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001091 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1092 CMD(tdls_mgmt, TDLS_MGMT);
1093 CMD(tdls_oper, TDLS_OPER);
1094 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001095 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1096 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001097 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001098 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e760232011-11-04 11:18:17 +01001099 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1100 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001101 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1102 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01001103 }
Johannes Berg98104fde2012-06-16 00:19:54 +02001104 CMD(start_p2p_device, START_P2P_DEVICE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001105
Kalle Valo4745fc02011-11-17 19:06:10 +02001106#ifdef CONFIG_NL80211_TESTMODE
1107 CMD(testmode_cmd, TESTMODE);
1108#endif
1109
Johannes Berg8fdc6212009-03-14 09:34:01 +01001110#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001111
Johannes Berg6829c872009-07-02 09:13:27 +02001112 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001113 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001114 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1115 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001116 }
1117
Johannes Berg6829c872009-07-02 09:13:27 +02001118 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001119 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001120 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1121 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001122 }
1123
Johannes Berg8fdc6212009-03-14 09:34:01 +01001124 nla_nest_end(msg, nl_cmds);
1125
Johannes Berg7c4ef712011-11-18 15:33:48 +01001126 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001127 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1128 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1129 dev->wiphy.max_remain_on_channel_duration))
1130 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001131
David S. Miller9360ffd2012-03-29 04:41:26 -04001132 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1133 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1134 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001135
Johannes Berg2e161f72010-08-12 15:38:38 +02001136 if (mgmt_stypes) {
1137 u16 stypes;
1138 struct nlattr *nl_ftypes, *nl_ifs;
1139 enum nl80211_iftype ift;
1140
1141 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1142 if (!nl_ifs)
1143 goto nla_put_failure;
1144
1145 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1146 nl_ftypes = nla_nest_start(msg, ift);
1147 if (!nl_ftypes)
1148 goto nla_put_failure;
1149 i = 0;
1150 stypes = mgmt_stypes[ift].tx;
1151 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001152 if ((stypes & 1) &&
1153 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1154 (i << 4) | IEEE80211_FTYPE_MGMT))
1155 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001156 stypes >>= 1;
1157 i++;
1158 }
1159 nla_nest_end(msg, nl_ftypes);
1160 }
1161
Johannes Berg74b70a42010-08-24 12:15:53 +02001162 nla_nest_end(msg, nl_ifs);
1163
Johannes Berg2e161f72010-08-12 15:38:38 +02001164 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1165 if (!nl_ifs)
1166 goto nla_put_failure;
1167
1168 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1169 nl_ftypes = nla_nest_start(msg, ift);
1170 if (!nl_ftypes)
1171 goto nla_put_failure;
1172 i = 0;
1173 stypes = mgmt_stypes[ift].rx;
1174 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 if ((stypes & 1) &&
1176 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1177 (i << 4) | IEEE80211_FTYPE_MGMT))
1178 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001179 stypes >>= 1;
1180 i++;
1181 }
1182 nla_nest_end(msg, nl_ftypes);
1183 }
1184 nla_nest_end(msg, nl_ifs);
1185 }
1186
Johannes Bergdfb89c52012-06-27 09:23:48 +02001187#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001188 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1189 struct nlattr *nl_wowlan;
1190
1191 nl_wowlan = nla_nest_start(msg,
1192 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1193 if (!nl_wowlan)
1194 goto nla_put_failure;
1195
David S. Miller9360ffd2012-03-29 04:41:26 -04001196 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1197 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1198 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1199 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1200 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1201 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1202 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1203 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1204 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1205 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1206 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1207 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1208 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1209 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1210 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1211 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1212 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001213 if (dev->wiphy.wowlan.n_patterns) {
1214 struct nl80211_wowlan_pattern_support pat = {
1215 .max_patterns = dev->wiphy.wowlan.n_patterns,
1216 .min_pattern_len =
1217 dev->wiphy.wowlan.pattern_min_len,
1218 .max_pattern_len =
1219 dev->wiphy.wowlan.pattern_max_len,
1220 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001221 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1222 sizeof(pat), &pat))
1223 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001224 }
1225
1226 nla_nest_end(msg, nl_wowlan);
1227 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001228#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001229
Johannes Berg7527a782011-05-13 10:58:57 +02001230 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1231 dev->wiphy.software_iftypes))
1232 goto nla_put_failure;
1233
1234 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1235 goto nla_put_failure;
1236
David S. Miller9360ffd2012-03-29 04:41:26 -04001237 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1238 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1239 dev->wiphy.ap_sme_capa))
1240 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001241
David S. Miller9360ffd2012-03-29 04:41:26 -04001242 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1243 dev->wiphy.features))
1244 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001245
David S. Miller9360ffd2012-03-29 04:41:26 -04001246 if (dev->wiphy.ht_capa_mod_mask &&
1247 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1248 sizeof(*dev->wiphy.ht_capa_mod_mask),
1249 dev->wiphy.ht_capa_mod_mask))
1250 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001251
Johannes Berg55682962007-09-20 13:09:35 -04001252 return genlmsg_end(msg, hdr);
1253
1254 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001255 genlmsg_cancel(msg, hdr);
1256 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001257}
1258
1259static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1260{
1261 int idx = 0;
1262 int start = cb->args[0];
1263 struct cfg80211_registered_device *dev;
1264
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001265 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001266 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001267 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1268 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001269 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001270 continue;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001271 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001272 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001273 dev) < 0) {
1274 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001275 break;
Julius Volzb4637272008-07-08 14:02:19 +02001276 }
Johannes Berg55682962007-09-20 13:09:35 -04001277 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001278 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001279
1280 cb->args[0] = idx;
1281
1282 return skb->len;
1283}
1284
1285static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1286{
1287 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001288 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001289
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001290 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001291 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001292 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001293
Eric W. Biederman15e47302012-09-07 20:12:54 +00001294 if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001295 nlmsg_free(msg);
1296 return -ENOBUFS;
1297 }
Johannes Berg55682962007-09-20 13:09:35 -04001298
Johannes Berg134e6372009-07-10 09:51:34 +00001299 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001300}
1301
Jouni Malinen31888482008-10-30 16:59:24 +02001302static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1303 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1304 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1305 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1306 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1307 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1308};
1309
1310static int parse_txq_params(struct nlattr *tb[],
1311 struct ieee80211_txq_params *txq_params)
1312{
Johannes Berga3304b02012-03-28 11:04:24 +02001313 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001314 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1315 !tb[NL80211_TXQ_ATTR_AIFS])
1316 return -EINVAL;
1317
Johannes Berga3304b02012-03-28 11:04:24 +02001318 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001319 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1320 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1321 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1322 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1323
Johannes Berga3304b02012-03-28 11:04:24 +02001324 if (txq_params->ac >= NL80211_NUM_ACS)
1325 return -EINVAL;
1326
Jouni Malinen31888482008-10-30 16:59:24 +02001327 return 0;
1328}
1329
Johannes Bergf444de02010-05-05 15:25:02 +02001330static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1331{
1332 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001333 * You can only set the channel explicitly for WDS interfaces,
1334 * all others have their channel managed via their respective
1335 * "establish a connection" command (connect, join, ...)
1336 *
1337 * For AP/GO and mesh mode, the channel can be set with the
1338 * channel userspace API, but is only stored and passed to the
1339 * low-level driver when the AP starts or the mesh is joined.
1340 * This is for backward compatibility, userspace can also give
1341 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001342 *
1343 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001344 * whatever else is going on, so they have their own special
1345 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001346 */
1347 return !wdev ||
1348 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001349 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001350 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1351 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001352}
1353
Johannes Bergcd6c6592012-05-10 21:27:18 +02001354static bool nl80211_valid_channel_type(struct genl_info *info,
1355 enum nl80211_channel_type *channel_type)
1356{
1357 enum nl80211_channel_type tmp;
1358
1359 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1360 return false;
1361
1362 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1363 if (tmp != NL80211_CHAN_NO_HT &&
1364 tmp != NL80211_CHAN_HT20 &&
1365 tmp != NL80211_CHAN_HT40PLUS &&
1366 tmp != NL80211_CHAN_HT40MINUS)
1367 return false;
1368
1369 if (channel_type)
1370 *channel_type = tmp;
1371
1372 return true;
1373}
1374
Johannes Bergf444de02010-05-05 15:25:02 +02001375static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1376 struct wireless_dev *wdev,
1377 struct genl_info *info)
1378{
Johannes Bergaa430da2012-05-16 23:50:18 +02001379 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001380 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1381 u32 freq;
1382 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001383 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1384
1385 if (wdev)
1386 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001387
1388 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1389 return -EINVAL;
1390
1391 if (!nl80211_can_set_dev_channel(wdev))
1392 return -EOPNOTSUPP;
1393
Johannes Bergcd6c6592012-05-10 21:27:18 +02001394 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1395 !nl80211_valid_channel_type(info, &channel_type))
1396 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001397
1398 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1399
1400 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001401 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001402 case NL80211_IFTYPE_AP:
1403 case NL80211_IFTYPE_P2P_GO:
1404 if (wdev->beacon_interval) {
1405 result = -EBUSY;
1406 break;
1407 }
1408 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1409 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1410 channel,
1411 channel_type)) {
1412 result = -EINVAL;
1413 break;
1414 }
1415 wdev->preset_chan = channel;
1416 wdev->preset_chantype = channel_type;
1417 result = 0;
1418 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001419 case NL80211_IFTYPE_MESH_POINT:
1420 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1421 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001422 case NL80211_IFTYPE_MONITOR:
1423 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1424 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001425 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001426 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001427 }
1428 mutex_unlock(&rdev->devlist_mtx);
1429
1430 return result;
1431}
1432
1433static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1434{
Johannes Berg4c476992010-10-04 21:36:35 +02001435 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1436 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001437
Johannes Berg4c476992010-10-04 21:36:35 +02001438 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001439}
1440
Bill Jordane8347eb2010-10-01 13:54:28 -04001441static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1442{
Johannes Berg43b19952010-10-07 13:10:30 +02001443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1444 struct net_device *dev = info->user_ptr[1];
1445 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001446 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001447
1448 if (!info->attrs[NL80211_ATTR_MAC])
1449 return -EINVAL;
1450
Johannes Berg43b19952010-10-07 13:10:30 +02001451 if (netif_running(dev))
1452 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001453
Johannes Berg43b19952010-10-07 13:10:30 +02001454 if (!rdev->ops->set_wds_peer)
1455 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001456
Johannes Berg43b19952010-10-07 13:10:30 +02001457 if (wdev->iftype != NL80211_IFTYPE_WDS)
1458 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001459
1460 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001461 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001462}
1463
1464
Johannes Berg55682962007-09-20 13:09:35 -04001465static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1466{
1467 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001468 struct net_device *netdev = NULL;
1469 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001470 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001471 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001472 u32 changed;
1473 u8 retry_short = 0, retry_long = 0;
1474 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001475 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001476
Johannes Bergf444de02010-05-05 15:25:02 +02001477 /*
1478 * Try to find the wiphy and netdev. Normally this
1479 * function shouldn't need the netdev, but this is
1480 * done for backward compatibility -- previously
1481 * setting the channel was done per wiphy, but now
1482 * it is per netdev. Previous userland like hostapd
1483 * also passed a netdev to set_wiphy, so that it is
1484 * possible to let that go to the right netdev!
1485 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001486 mutex_lock(&cfg80211_mutex);
1487
Johannes Bergf444de02010-05-05 15:25:02 +02001488 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1489 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1490
1491 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1492 if (netdev && netdev->ieee80211_ptr) {
1493 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1494 mutex_lock(&rdev->mtx);
1495 } else
1496 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001497 }
1498
Johannes Bergf444de02010-05-05 15:25:02 +02001499 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001500 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1501 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001502 if (IS_ERR(rdev)) {
1503 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001504 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001505 }
1506 wdev = NULL;
1507 netdev = NULL;
1508 result = 0;
1509
1510 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001511 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001512 wdev = netdev->ieee80211_ptr;
1513 else
1514 wdev = NULL;
1515
1516 /*
1517 * end workaround code, by now the rdev is available
1518 * and locked, and wdev may or may not be NULL.
1519 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001520
1521 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001522 result = cfg80211_dev_rename(
1523 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001524
1525 mutex_unlock(&cfg80211_mutex);
1526
1527 if (result)
1528 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001529
Jouni Malinen31888482008-10-30 16:59:24 +02001530 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1531 struct ieee80211_txq_params txq_params;
1532 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1533
1534 if (!rdev->ops->set_txq_params) {
1535 result = -EOPNOTSUPP;
1536 goto bad_res;
1537 }
1538
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001539 if (!netdev) {
1540 result = -EINVAL;
1541 goto bad_res;
1542 }
1543
Johannes Berg133a3ff2011-11-03 14:50:13 +01001544 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1545 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1546 result = -EINVAL;
1547 goto bad_res;
1548 }
1549
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001550 if (!netif_running(netdev)) {
1551 result = -ENETDOWN;
1552 goto bad_res;
1553 }
1554
Jouni Malinen31888482008-10-30 16:59:24 +02001555 nla_for_each_nested(nl_txq_params,
1556 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1557 rem_txq_params) {
1558 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1559 nla_data(nl_txq_params),
1560 nla_len(nl_txq_params),
1561 txq_params_policy);
1562 result = parse_txq_params(tb, &txq_params);
1563 if (result)
1564 goto bad_res;
1565
1566 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001567 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001568 &txq_params);
1569 if (result)
1570 goto bad_res;
1571 }
1572 }
1573
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001574 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001575 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001576 if (result)
1577 goto bad_res;
1578 }
1579
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001580 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1581 enum nl80211_tx_power_setting type;
1582 int idx, mbm = 0;
1583
1584 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001585 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001586 goto bad_res;
1587 }
1588
1589 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1590 type = nla_get_u32(info->attrs[idx]);
1591
1592 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1593 (type != NL80211_TX_POWER_AUTOMATIC)) {
1594 result = -EINVAL;
1595 goto bad_res;
1596 }
1597
1598 if (type != NL80211_TX_POWER_AUTOMATIC) {
1599 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1600 mbm = nla_get_u32(info->attrs[idx]);
1601 }
1602
1603 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1604 if (result)
1605 goto bad_res;
1606 }
1607
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001608 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1609 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1610 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001611 if ((!rdev->wiphy.available_antennas_tx &&
1612 !rdev->wiphy.available_antennas_rx) ||
1613 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001614 result = -EOPNOTSUPP;
1615 goto bad_res;
1616 }
1617
1618 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1619 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1620
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001621 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001622 * available antenna masks, except for the "all" mask */
1623 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1624 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001625 result = -EINVAL;
1626 goto bad_res;
1627 }
1628
Bruno Randolf7f531e02010-12-16 11:30:22 +09001629 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1630 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001631
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001632 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1633 if (result)
1634 goto bad_res;
1635 }
1636
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001637 changed = 0;
1638
1639 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1640 retry_short = nla_get_u8(
1641 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1642 if (retry_short == 0) {
1643 result = -EINVAL;
1644 goto bad_res;
1645 }
1646 changed |= WIPHY_PARAM_RETRY_SHORT;
1647 }
1648
1649 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1650 retry_long = nla_get_u8(
1651 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1652 if (retry_long == 0) {
1653 result = -EINVAL;
1654 goto bad_res;
1655 }
1656 changed |= WIPHY_PARAM_RETRY_LONG;
1657 }
1658
1659 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1660 frag_threshold = nla_get_u32(
1661 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1662 if (frag_threshold < 256) {
1663 result = -EINVAL;
1664 goto bad_res;
1665 }
1666 if (frag_threshold != (u32) -1) {
1667 /*
1668 * Fragments (apart from the last one) are required to
1669 * have even length. Make the fragmentation code
1670 * simpler by stripping LSB should someone try to use
1671 * odd threshold value.
1672 */
1673 frag_threshold &= ~0x1;
1674 }
1675 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1676 }
1677
1678 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1679 rts_threshold = nla_get_u32(
1680 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1681 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1682 }
1683
Lukáš Turek81077e82009-12-21 22:50:47 +01001684 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1685 coverage_class = nla_get_u8(
1686 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1687 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1688 }
1689
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001690 if (changed) {
1691 u8 old_retry_short, old_retry_long;
1692 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001693 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001694
1695 if (!rdev->ops->set_wiphy_params) {
1696 result = -EOPNOTSUPP;
1697 goto bad_res;
1698 }
1699
1700 old_retry_short = rdev->wiphy.retry_short;
1701 old_retry_long = rdev->wiphy.retry_long;
1702 old_frag_threshold = rdev->wiphy.frag_threshold;
1703 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001704 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001705
1706 if (changed & WIPHY_PARAM_RETRY_SHORT)
1707 rdev->wiphy.retry_short = retry_short;
1708 if (changed & WIPHY_PARAM_RETRY_LONG)
1709 rdev->wiphy.retry_long = retry_long;
1710 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1711 rdev->wiphy.frag_threshold = frag_threshold;
1712 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1713 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001714 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1715 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001716
1717 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1718 if (result) {
1719 rdev->wiphy.retry_short = old_retry_short;
1720 rdev->wiphy.retry_long = old_retry_long;
1721 rdev->wiphy.frag_threshold = old_frag_threshold;
1722 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001723 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001724 }
1725 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001726
Johannes Berg306d6112008-12-08 12:39:04 +01001727 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001728 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001729 if (netdev)
1730 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001731 return result;
1732}
1733
Johannes Berg71bbc992012-06-15 15:30:18 +02001734static inline u64 wdev_id(struct wireless_dev *wdev)
1735{
1736 return (u64)wdev->identifier |
1737 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1738}
Johannes Berg55682962007-09-20 13:09:35 -04001739
Eric W. Biederman15e47302012-09-07 20:12:54 +00001740static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001741 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001742 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04001743{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001744 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04001745 void *hdr;
1746
Eric W. Biederman15e47302012-09-07 20:12:54 +00001747 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04001748 if (!hdr)
1749 return -1;
1750
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001751 if (dev &&
1752 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001753 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001754 goto nla_put_failure;
1755
1756 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1757 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02001758 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001759 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001760 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1761 rdev->devlist_generation ^
1762 (cfg80211_rdev_list_generation << 2)))
1763 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001764
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02001765 if (rdev->ops->get_channel) {
1766 struct ieee80211_channel *chan;
1767 enum nl80211_channel_type channel_type;
1768
1769 chan = rdev->ops->get_channel(&rdev->wiphy, wdev,
1770 &channel_type);
1771 if (chan &&
1772 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1773 chan->center_freq) ||
1774 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1775 channel_type)))
John W. Linville59ef43e2012-04-18 14:17:13 -04001776 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001777 }
1778
Johannes Berg55682962007-09-20 13:09:35 -04001779 return genlmsg_end(msg, hdr);
1780
1781 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001782 genlmsg_cancel(msg, hdr);
1783 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001784}
1785
1786static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1787{
1788 int wp_idx = 0;
1789 int if_idx = 0;
1790 int wp_start = cb->args[0];
1791 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001792 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001793 struct wireless_dev *wdev;
1794
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001795 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001796 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1797 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001798 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001799 if (wp_idx < wp_start) {
1800 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001801 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001802 }
Johannes Berg55682962007-09-20 13:09:35 -04001803 if_idx = 0;
1804
Johannes Bergf5ea9122009-08-07 16:17:38 +02001805 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02001806 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001807 if (if_idx < if_start) {
1808 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001809 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001810 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00001811 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001812 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001813 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02001814 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001815 goto out;
1816 }
1817 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001818 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001819 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001820
1821 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001822 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001823 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001824 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001825
1826 cb->args[0] = wp_idx;
1827 cb->args[1] = if_idx;
1828
1829 return skb->len;
1830}
1831
1832static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1833{
1834 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001835 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001836 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001837
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001838 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001839 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001840 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001841
Eric W. Biederman15e47302012-09-07 20:12:54 +00001842 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001843 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001844 nlmsg_free(msg);
1845 return -ENOBUFS;
1846 }
Johannes Berg55682962007-09-20 13:09:35 -04001847
Johannes Berg134e6372009-07-10 09:51:34 +00001848 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001849}
1850
Michael Wu66f7ac52008-01-31 19:48:22 +01001851static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1852 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1853 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1854 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1855 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1856 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1857};
1858
1859static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1860{
1861 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1862 int flag;
1863
1864 *mntrflags = 0;
1865
1866 if (!nla)
1867 return -EINVAL;
1868
1869 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1870 nla, mntr_flags_policy))
1871 return -EINVAL;
1872
1873 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1874 if (flags[flag])
1875 *mntrflags |= (1<<flag);
1876
1877 return 0;
1878}
1879
Johannes Berg9bc383d2009-11-19 11:55:19 +01001880static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001881 struct net_device *netdev, u8 use_4addr,
1882 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001883{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001884 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001885 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001886 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001887 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001888 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001889
1890 switch (iftype) {
1891 case NL80211_IFTYPE_AP_VLAN:
1892 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1893 return 0;
1894 break;
1895 case NL80211_IFTYPE_STATION:
1896 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1897 return 0;
1898 break;
1899 default:
1900 break;
1901 }
1902
1903 return -EOPNOTSUPP;
1904}
1905
Johannes Berg55682962007-09-20 13:09:35 -04001906static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1907{
Johannes Berg4c476992010-10-04 21:36:35 +02001908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001909 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001910 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001911 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001912 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001913 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001914 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001915
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001916 memset(&params, 0, sizeof(params));
1917
Johannes Berg04a773a2009-04-19 21:24:32 +02001918 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001919
Johannes Berg723b0382008-09-16 20:22:09 +02001920 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001921 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001922 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001923 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001924 if (ntype > NL80211_IFTYPE_MAX)
1925 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001926 }
1927
Johannes Berg92ffe052008-09-16 20:39:36 +02001928 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001929 struct wireless_dev *wdev = dev->ieee80211_ptr;
1930
Johannes Berg4c476992010-10-04 21:36:35 +02001931 if (ntype != NL80211_IFTYPE_MESH_POINT)
1932 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001933 if (netif_running(dev))
1934 return -EBUSY;
1935
1936 wdev_lock(wdev);
1937 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1938 IEEE80211_MAX_MESH_ID_LEN);
1939 wdev->mesh_id_up_len =
1940 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1941 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1942 wdev->mesh_id_up_len);
1943 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001944 }
1945
Felix Fietkau8b787642009-11-10 18:53:10 +01001946 if (info->attrs[NL80211_ATTR_4ADDR]) {
1947 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1948 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001949 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001950 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001951 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001952 } else {
1953 params.use_4addr = -1;
1954 }
1955
Johannes Berg92ffe052008-09-16 20:39:36 +02001956 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001957 if (ntype != NL80211_IFTYPE_MONITOR)
1958 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001959 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1960 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001961 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001962 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001963
1964 flags = &_flags;
1965 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001966 }
Johannes Berg3b858752009-03-12 09:55:09 +01001967
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001968 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001969 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001970 else
1971 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001972
Johannes Berg9bc383d2009-11-19 11:55:19 +01001973 if (!err && params.use_4addr != -1)
1974 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1975
Johannes Berg55682962007-09-20 13:09:35 -04001976 return err;
1977}
1978
1979static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1980{
Johannes Berg4c476992010-10-04 21:36:35 +02001981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001982 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02001983 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02001984 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04001985 int err;
1986 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001987 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001988
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001989 memset(&params, 0, sizeof(params));
1990
Johannes Berg55682962007-09-20 13:09:35 -04001991 if (!info->attrs[NL80211_ATTR_IFNAME])
1992 return -EINVAL;
1993
1994 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1995 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1996 if (type > NL80211_IFTYPE_MAX)
1997 return -EINVAL;
1998 }
1999
Johannes Berg79c97e92009-07-07 03:56:12 +02002000 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002001 !(rdev->wiphy.interface_modes & (1 << type)))
2002 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002003
Johannes Berg9bc383d2009-11-19 11:55:19 +01002004 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002005 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002006 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002007 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002008 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002009 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002010
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2012 if (!msg)
2013 return -ENOMEM;
2014
Michael Wu66f7ac52008-01-31 19:48:22 +01002015 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2016 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2017 &flags);
Johannes Berg84efbb82012-06-16 00:00:26 +02002018 wdev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01002019 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002020 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002021 if (IS_ERR(wdev)) {
2022 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002023 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002024 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002025
Johannes Berg98104fde2012-06-16 00:19:54 +02002026 switch (type) {
2027 case NL80211_IFTYPE_MESH_POINT:
2028 if (!info->attrs[NL80211_ATTR_MESH_ID])
2029 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002030 wdev_lock(wdev);
2031 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2032 IEEE80211_MAX_MESH_ID_LEN);
2033 wdev->mesh_id_up_len =
2034 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2035 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2036 wdev->mesh_id_up_len);
2037 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002038 break;
2039 case NL80211_IFTYPE_P2P_DEVICE:
2040 /*
2041 * P2P Device doesn't have a netdev, so doesn't go
2042 * through the netdev notifier and must be added here
2043 */
2044 mutex_init(&wdev->mtx);
2045 INIT_LIST_HEAD(&wdev->event_list);
2046 spin_lock_init(&wdev->event_lock);
2047 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2048 spin_lock_init(&wdev->mgmt_registrations_lock);
2049
2050 mutex_lock(&rdev->devlist_mtx);
2051 wdev->identifier = ++rdev->wdev_id;
2052 list_add_rcu(&wdev->list, &rdev->wdev_list);
2053 rdev->devlist_generation++;
2054 mutex_unlock(&rdev->devlist_mtx);
2055 break;
2056 default:
2057 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002058 }
2059
Eric W. Biederman15e47302012-09-07 20:12:54 +00002060 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002061 rdev, wdev) < 0) {
2062 nlmsg_free(msg);
2063 return -ENOBUFS;
2064 }
2065
2066 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002067}
2068
2069static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2070{
Johannes Berg4c476992010-10-04 21:36:35 +02002071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002072 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002073
Johannes Berg4c476992010-10-04 21:36:35 +02002074 if (!rdev->ops->del_virtual_intf)
2075 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002076
Johannes Berg84efbb82012-06-16 00:00:26 +02002077 /*
2078 * If we remove a wireless device without a netdev then clear
2079 * user_ptr[1] so that nl80211_post_doit won't dereference it
2080 * to check if it needs to do dev_put(). Otherwise it crashes
2081 * since the wdev has been freed, unlike with a netdev where
2082 * we need the dev_put() for the netdev to really be freed.
2083 */
2084 if (!wdev->netdev)
2085 info->user_ptr[1] = NULL;
2086
2087 return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002088}
2089
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002090static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2091{
2092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2093 struct net_device *dev = info->user_ptr[1];
2094 u16 noack_map;
2095
2096 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2097 return -EINVAL;
2098
2099 if (!rdev->ops->set_noack_map)
2100 return -EOPNOTSUPP;
2101
2102 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2103
2104 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
2105}
2106
Johannes Berg41ade002007-12-19 02:03:29 +01002107struct get_key_cookie {
2108 struct sk_buff *msg;
2109 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002110 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002111};
2112
2113static void get_key_callback(void *c, struct key_params *params)
2114{
Johannes Bergb9454e82009-07-08 13:29:08 +02002115 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002116 struct get_key_cookie *cookie = c;
2117
David S. Miller9360ffd2012-03-29 04:41:26 -04002118 if ((params->key &&
2119 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2120 params->key_len, params->key)) ||
2121 (params->seq &&
2122 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2123 params->seq_len, params->seq)) ||
2124 (params->cipher &&
2125 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2126 params->cipher)))
2127 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002128
Johannes Bergb9454e82009-07-08 13:29:08 +02002129 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2130 if (!key)
2131 goto nla_put_failure;
2132
David S. Miller9360ffd2012-03-29 04:41:26 -04002133 if ((params->key &&
2134 nla_put(cookie->msg, NL80211_KEY_DATA,
2135 params->key_len, params->key)) ||
2136 (params->seq &&
2137 nla_put(cookie->msg, NL80211_KEY_SEQ,
2138 params->seq_len, params->seq)) ||
2139 (params->cipher &&
2140 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2141 params->cipher)))
2142 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002143
David S. Miller9360ffd2012-03-29 04:41:26 -04002144 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2145 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002146
2147 nla_nest_end(cookie->msg, key);
2148
Johannes Berg41ade002007-12-19 02:03:29 +01002149 return;
2150 nla_put_failure:
2151 cookie->error = 1;
2152}
2153
2154static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2155{
Johannes Berg4c476992010-10-04 21:36:35 +02002156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002157 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002158 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002159 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002160 const u8 *mac_addr = NULL;
2161 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002162 struct get_key_cookie cookie = {
2163 .error = 0,
2164 };
2165 void *hdr;
2166 struct sk_buff *msg;
2167
2168 if (info->attrs[NL80211_ATTR_KEY_IDX])
2169 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2170
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002171 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002172 return -EINVAL;
2173
2174 if (info->attrs[NL80211_ATTR_MAC])
2175 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2176
Johannes Berge31b8212010-10-05 19:39:30 +02002177 pairwise = !!mac_addr;
2178 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2179 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2180 if (kt >= NUM_NL80211_KEYTYPES)
2181 return -EINVAL;
2182 if (kt != NL80211_KEYTYPE_GROUP &&
2183 kt != NL80211_KEYTYPE_PAIRWISE)
2184 return -EINVAL;
2185 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2186 }
2187
Johannes Berg4c476992010-10-04 21:36:35 +02002188 if (!rdev->ops->get_key)
2189 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002190
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002191 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002192 if (!msg)
2193 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002194
Eric W. Biederman15e47302012-09-07 20:12:54 +00002195 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002196 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002197 if (IS_ERR(hdr))
2198 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002199
2200 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002201 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002202
David S. Miller9360ffd2012-03-29 04:41:26 -04002203 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2204 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2205 goto nla_put_failure;
2206 if (mac_addr &&
2207 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2208 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002209
Johannes Berge31b8212010-10-05 19:39:30 +02002210 if (pairwise && mac_addr &&
2211 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2212 return -ENOENT;
2213
2214 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2215 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002216
2217 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002218 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002219
2220 if (cookie.error)
2221 goto nla_put_failure;
2222
2223 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002224 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002225
2226 nla_put_failure:
2227 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002228 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002229 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002230 return err;
2231}
2232
2233static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2234{
Johannes Berg4c476992010-10-04 21:36:35 +02002235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002236 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002237 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002238 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002239
Johannes Bergb9454e82009-07-08 13:29:08 +02002240 err = nl80211_parse_key(info, &key);
2241 if (err)
2242 return err;
2243
2244 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002245 return -EINVAL;
2246
Johannes Bergb9454e82009-07-08 13:29:08 +02002247 /* only support setting default key */
2248 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002249 return -EINVAL;
2250
Johannes Bergfffd0932009-07-08 14:22:54 +02002251 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002252
2253 if (key.def) {
2254 if (!rdev->ops->set_default_key) {
2255 err = -EOPNOTSUPP;
2256 goto out;
2257 }
2258
2259 err = nl80211_key_allowed(dev->ieee80211_ptr);
2260 if (err)
2261 goto out;
2262
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002263 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2264 key.def_uni, key.def_multi);
2265
2266 if (err)
2267 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002268
Johannes Berg3d23e342009-09-29 23:27:28 +02002269#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002270 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002271#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002272 } else {
2273 if (key.def_uni || !key.def_multi) {
2274 err = -EINVAL;
2275 goto out;
2276 }
2277
2278 if (!rdev->ops->set_default_mgmt_key) {
2279 err = -EOPNOTSUPP;
2280 goto out;
2281 }
2282
2283 err = nl80211_key_allowed(dev->ieee80211_ptr);
2284 if (err)
2285 goto out;
2286
2287 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2288 dev, key.idx);
2289 if (err)
2290 goto out;
2291
2292#ifdef CONFIG_CFG80211_WEXT
2293 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2294#endif
2295 }
2296
2297 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002298 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002299
Johannes Berg41ade002007-12-19 02:03:29 +01002300 return err;
2301}
2302
2303static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2304{
Johannes Berg4c476992010-10-04 21:36:35 +02002305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002306 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002307 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002308 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002309 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002310
Johannes Bergb9454e82009-07-08 13:29:08 +02002311 err = nl80211_parse_key(info, &key);
2312 if (err)
2313 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002314
Johannes Bergb9454e82009-07-08 13:29:08 +02002315 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002316 return -EINVAL;
2317
Johannes Berg41ade002007-12-19 02:03:29 +01002318 if (info->attrs[NL80211_ATTR_MAC])
2319 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2320
Johannes Berge31b8212010-10-05 19:39:30 +02002321 if (key.type == -1) {
2322 if (mac_addr)
2323 key.type = NL80211_KEYTYPE_PAIRWISE;
2324 else
2325 key.type = NL80211_KEYTYPE_GROUP;
2326 }
2327
2328 /* for now */
2329 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2330 key.type != NL80211_KEYTYPE_GROUP)
2331 return -EINVAL;
2332
Johannes Berg4c476992010-10-04 21:36:35 +02002333 if (!rdev->ops->add_key)
2334 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002335
Johannes Berge31b8212010-10-05 19:39:30 +02002336 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2337 key.type == NL80211_KEYTYPE_PAIRWISE,
2338 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002339 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002340
2341 wdev_lock(dev->ieee80211_ptr);
2342 err = nl80211_key_allowed(dev->ieee80211_ptr);
2343 if (!err)
2344 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002345 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002346 mac_addr, &key.p);
2347 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002348
Johannes Berg41ade002007-12-19 02:03:29 +01002349 return err;
2350}
2351
2352static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2353{
Johannes Berg4c476992010-10-04 21:36:35 +02002354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002355 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002356 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002357 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002358 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002359
Johannes Bergb9454e82009-07-08 13:29:08 +02002360 err = nl80211_parse_key(info, &key);
2361 if (err)
2362 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002363
2364 if (info->attrs[NL80211_ATTR_MAC])
2365 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2366
Johannes Berge31b8212010-10-05 19:39:30 +02002367 if (key.type == -1) {
2368 if (mac_addr)
2369 key.type = NL80211_KEYTYPE_PAIRWISE;
2370 else
2371 key.type = NL80211_KEYTYPE_GROUP;
2372 }
2373
2374 /* for now */
2375 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2376 key.type != NL80211_KEYTYPE_GROUP)
2377 return -EINVAL;
2378
Johannes Berg4c476992010-10-04 21:36:35 +02002379 if (!rdev->ops->del_key)
2380 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002381
Johannes Bergfffd0932009-07-08 14:22:54 +02002382 wdev_lock(dev->ieee80211_ptr);
2383 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002384
2385 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2386 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2387 err = -ENOENT;
2388
Johannes Bergfffd0932009-07-08 14:22:54 +02002389 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002390 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2391 key.type == NL80211_KEYTYPE_PAIRWISE,
2392 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002393
Johannes Berg3d23e342009-09-29 23:27:28 +02002394#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002395 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002396 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002397 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002398 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002399 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2400 }
2401#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002402 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002403
Johannes Berg41ade002007-12-19 02:03:29 +01002404 return err;
2405}
2406
Johannes Berg88600202012-02-13 15:17:18 +01002407static int nl80211_parse_beacon(struct genl_info *info,
2408 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002409{
Johannes Berg88600202012-02-13 15:17:18 +01002410 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002411
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002412 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2413 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2414 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2415 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002416 return -EINVAL;
2417
Johannes Berg88600202012-02-13 15:17:18 +01002418 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002419
Johannes Berged1b6cc2007-12-19 02:03:32 +01002420 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002421 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2422 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2423 if (!bcn->head_len)
2424 return -EINVAL;
2425 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002426 }
2427
2428 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002429 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2430 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002431 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002432 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002433 }
2434
Johannes Berg4c476992010-10-04 21:36:35 +02002435 if (!haveinfo)
2436 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002437
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002438 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002439 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2440 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002441 }
2442
2443 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002444 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002445 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002446 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002447 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2448 }
2449
2450 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002451 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002452 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002453 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002454 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2455 }
2456
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002457 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002458 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002459 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002460 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002461 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2462 }
2463
Johannes Berg88600202012-02-13 15:17:18 +01002464 return 0;
2465}
2466
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002467static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2468 struct cfg80211_ap_settings *params)
2469{
2470 struct wireless_dev *wdev;
2471 bool ret = false;
2472
2473 mutex_lock(&rdev->devlist_mtx);
2474
Johannes Berg89a54e42012-06-15 14:33:17 +02002475 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002476 if (wdev->iftype != NL80211_IFTYPE_AP &&
2477 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2478 continue;
2479
2480 if (!wdev->preset_chan)
2481 continue;
2482
2483 params->channel = wdev->preset_chan;
2484 params->channel_type = wdev->preset_chantype;
2485 ret = true;
2486 break;
2487 }
2488
2489 mutex_unlock(&rdev->devlist_mtx);
2490
2491 return ret;
2492}
2493
Jouni Malinene39e5b52012-09-30 19:29:39 +03002494static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2495 enum nl80211_auth_type auth_type,
2496 enum nl80211_commands cmd)
2497{
2498 if (auth_type > NL80211_AUTHTYPE_MAX)
2499 return false;
2500
2501 switch (cmd) {
2502 case NL80211_CMD_AUTHENTICATE:
2503 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2504 auth_type == NL80211_AUTHTYPE_SAE)
2505 return false;
2506 return true;
2507 case NL80211_CMD_CONNECT:
2508 case NL80211_CMD_START_AP:
2509 /* SAE not supported yet */
2510 if (auth_type == NL80211_AUTHTYPE_SAE)
2511 return false;
2512 return true;
2513 default:
2514 return false;
2515 }
2516}
2517
Johannes Berg88600202012-02-13 15:17:18 +01002518static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2519{
2520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2521 struct net_device *dev = info->user_ptr[1];
2522 struct wireless_dev *wdev = dev->ieee80211_ptr;
2523 struct cfg80211_ap_settings params;
2524 int err;
2525
2526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2527 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2528 return -EOPNOTSUPP;
2529
2530 if (!rdev->ops->start_ap)
2531 return -EOPNOTSUPP;
2532
2533 if (wdev->beacon_interval)
2534 return -EALREADY;
2535
2536 memset(&params, 0, sizeof(params));
2537
2538 /* these are required for START_AP */
2539 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2540 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2541 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2542 return -EINVAL;
2543
2544 err = nl80211_parse_beacon(info, &params.beacon);
2545 if (err)
2546 return err;
2547
2548 params.beacon_interval =
2549 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2550 params.dtim_period =
2551 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2552
2553 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2554 if (err)
2555 return err;
2556
2557 /*
2558 * In theory, some of these attributes should be required here
2559 * but since they were not used when the command was originally
2560 * added, keep them optional for old user space programs to let
2561 * them continue to work with drivers that do not need the
2562 * additional information -- drivers must check!
2563 */
2564 if (info->attrs[NL80211_ATTR_SSID]) {
2565 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2566 params.ssid_len =
2567 nla_len(info->attrs[NL80211_ATTR_SSID]);
2568 if (params.ssid_len == 0 ||
2569 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2570 return -EINVAL;
2571 }
2572
2573 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2574 params.hidden_ssid = nla_get_u32(
2575 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2576 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2577 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2578 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2579 return -EINVAL;
2580 }
2581
2582 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2583
2584 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2585 params.auth_type = nla_get_u32(
2586 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03002587 if (!nl80211_valid_auth_type(rdev, params.auth_type,
2588 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01002589 return -EINVAL;
2590 } else
2591 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2592
2593 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2594 NL80211_MAX_NR_CIPHER_SUITES);
2595 if (err)
2596 return err;
2597
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302598 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2599 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2600 return -EOPNOTSUPP;
2601 params.inactivity_timeout = nla_get_u16(
2602 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2603 }
2604
Johannes Bergaa430da2012-05-16 23:50:18 +02002605 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2606 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2607
2608 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2609 !nl80211_valid_channel_type(info, &channel_type))
2610 return -EINVAL;
2611
2612 params.channel = rdev_freq_to_chan(rdev,
2613 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2614 channel_type);
2615 if (!params.channel)
2616 return -EINVAL;
2617 params.channel_type = channel_type;
2618 } else if (wdev->preset_chan) {
2619 params.channel = wdev->preset_chan;
2620 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002621 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002622 return -EINVAL;
2623
2624 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2625 params.channel_type))
2626 return -EINVAL;
2627
Michal Kaziore4e32452012-06-29 12:47:08 +02002628 mutex_lock(&rdev->devlist_mtx);
2629 err = cfg80211_can_use_chan(rdev, wdev, params.channel,
2630 CHAN_MODE_SHARED);
2631 mutex_unlock(&rdev->devlist_mtx);
2632
2633 if (err)
2634 return err;
2635
Johannes Berg88600202012-02-13 15:17:18 +01002636 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002637 if (!err) {
2638 wdev->preset_chan = params.channel;
2639 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002640 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002641 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002642 }
Johannes Berg56d18932011-05-09 18:41:15 +02002643 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002644}
2645
Johannes Berg88600202012-02-13 15:17:18 +01002646static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2647{
2648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2649 struct net_device *dev = info->user_ptr[1];
2650 struct wireless_dev *wdev = dev->ieee80211_ptr;
2651 struct cfg80211_beacon_data params;
2652 int err;
2653
2654 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2655 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2656 return -EOPNOTSUPP;
2657
2658 if (!rdev->ops->change_beacon)
2659 return -EOPNOTSUPP;
2660
2661 if (!wdev->beacon_interval)
2662 return -EINVAL;
2663
2664 err = nl80211_parse_beacon(info, &params);
2665 if (err)
2666 return err;
2667
2668 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2669}
2670
2671static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002672{
Johannes Berg4c476992010-10-04 21:36:35 +02002673 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2674 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002675
Michal Kazior60771782012-06-29 12:46:56 +02002676 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002677}
2678
Johannes Berg5727ef12007-12-19 02:03:34 +01002679static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2680 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2681 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2682 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002683 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002684 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002685 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002686};
2687
Johannes Bergeccb8e82009-05-11 21:57:56 +03002688static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002689 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002690 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002691{
2692 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002693 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002694 int flag;
2695
Johannes Bergeccb8e82009-05-11 21:57:56 +03002696 /*
2697 * Try parsing the new attribute first so userspace
2698 * can specify both for older kernels.
2699 */
2700 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2701 if (nla) {
2702 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002703
Johannes Bergeccb8e82009-05-11 21:57:56 +03002704 sta_flags = nla_data(nla);
2705 params->sta_flags_mask = sta_flags->mask;
2706 params->sta_flags_set = sta_flags->set;
2707 if ((params->sta_flags_mask |
2708 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2709 return -EINVAL;
2710 return 0;
2711 }
2712
2713 /* if present, parse the old attribute */
2714
2715 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002716 if (!nla)
2717 return 0;
2718
2719 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2720 nla, sta_flags_policy))
2721 return -EINVAL;
2722
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002723 /*
2724 * Only allow certain flags for interface types so that
2725 * other attributes are silently ignored. Remember that
2726 * this is backward compatibility code with old userspace
2727 * and shouldn't be hit in other cases anyway.
2728 */
2729 switch (iftype) {
2730 case NL80211_IFTYPE_AP:
2731 case NL80211_IFTYPE_AP_VLAN:
2732 case NL80211_IFTYPE_P2P_GO:
2733 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2734 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2735 BIT(NL80211_STA_FLAG_WME) |
2736 BIT(NL80211_STA_FLAG_MFP);
2737 break;
2738 case NL80211_IFTYPE_P2P_CLIENT:
2739 case NL80211_IFTYPE_STATION:
2740 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2741 BIT(NL80211_STA_FLAG_TDLS_PEER);
2742 break;
2743 case NL80211_IFTYPE_MESH_POINT:
2744 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2745 BIT(NL80211_STA_FLAG_MFP) |
2746 BIT(NL80211_STA_FLAG_AUTHORIZED);
2747 default:
2748 return -EINVAL;
2749 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002750
Johannes Berg3383b5a2012-05-10 20:14:43 +02002751 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2752 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002753 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002754
Johannes Berg3383b5a2012-05-10 20:14:43 +02002755 /* no longer support new API additions in old API */
2756 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2757 return -EINVAL;
2758 }
2759 }
2760
Johannes Berg5727ef12007-12-19 02:03:34 +01002761 return 0;
2762}
2763
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002764static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2765 int attr)
2766{
2767 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002768 u32 bitrate;
2769 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002770
2771 rate = nla_nest_start(msg, attr);
2772 if (!rate)
2773 goto nla_put_failure;
2774
2775 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2776 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002777 /* report 16-bit bitrate only if we can */
2778 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
David S. Miller9360ffd2012-03-29 04:41:26 -04002779 if ((bitrate > 0 &&
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002780 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
2781 (bitrate_compat > 0 &&
2782 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002783 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2784 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2785 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2786 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2787 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2788 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2789 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002790
2791 nla_nest_end(msg, rate);
2792 return true;
2793
2794nla_put_failure:
2795 return false;
2796}
2797
Eric W. Biederman15e47302012-09-07 20:12:54 +00002798static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002799 int flags,
2800 struct cfg80211_registered_device *rdev,
2801 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002802 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002803{
2804 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002805 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002806
Eric W. Biederman15e47302012-09-07 20:12:54 +00002807 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002808 if (!hdr)
2809 return -1;
2810
David S. Miller9360ffd2012-03-29 04:41:26 -04002811 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2812 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2813 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2814 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002815
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002816 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2817 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002818 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002819 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2820 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2821 sinfo->connected_time))
2822 goto nla_put_failure;
2823 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2824 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2825 sinfo->inactive_time))
2826 goto nla_put_failure;
2827 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2828 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2829 sinfo->rx_bytes))
2830 goto nla_put_failure;
2831 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2832 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2833 sinfo->tx_bytes))
2834 goto nla_put_failure;
2835 if ((sinfo->filled & STATION_INFO_LLID) &&
2836 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2837 goto nla_put_failure;
2838 if ((sinfo->filled & STATION_INFO_PLID) &&
2839 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2840 goto nla_put_failure;
2841 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2842 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2843 sinfo->plink_state))
2844 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002845 switch (rdev->wiphy.signal_type) {
2846 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002847 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2848 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2849 sinfo->signal))
2850 goto nla_put_failure;
2851 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2852 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2853 sinfo->signal_avg))
2854 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002855 break;
2856 default:
2857 break;
2858 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002859 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002860 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2861 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002862 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002863 }
2864 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2865 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2866 NL80211_STA_INFO_RX_BITRATE))
2867 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002868 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002869 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2870 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2871 sinfo->rx_packets))
2872 goto nla_put_failure;
2873 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2874 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2875 sinfo->tx_packets))
2876 goto nla_put_failure;
2877 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2878 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2879 sinfo->tx_retries))
2880 goto nla_put_failure;
2881 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2882 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2883 sinfo->tx_failed))
2884 goto nla_put_failure;
2885 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2886 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2887 sinfo->beacon_loss_count))
2888 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002889 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2890 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2891 if (!bss_param)
2892 goto nla_put_failure;
2893
David S. Miller9360ffd2012-03-29 04:41:26 -04002894 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2895 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2896 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2897 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2898 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2899 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2900 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2901 sinfo->bss_param.dtim_period) ||
2902 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2903 sinfo->bss_param.beacon_interval))
2904 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002905
2906 nla_nest_end(msg, bss_param);
2907 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002908 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2909 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2910 sizeof(struct nl80211_sta_flag_update),
2911 &sinfo->sta_flags))
2912 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002913 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2914 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2915 sinfo->t_offset))
2916 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002917 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002918
David S. Miller9360ffd2012-03-29 04:41:26 -04002919 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2920 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2921 sinfo->assoc_req_ies))
2922 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002923
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002924 return genlmsg_end(msg, hdr);
2925
2926 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002927 genlmsg_cancel(msg, hdr);
2928 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002929}
2930
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002931static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002932 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002933{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002934 struct station_info sinfo;
2935 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002936 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002937 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002938 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002939 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002940
Johannes Berg67748892010-10-04 21:14:06 +02002941 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2942 if (err)
2943 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002944
2945 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002946 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002947 goto out_err;
2948 }
2949
Johannes Bergbba95fe2008-07-29 13:22:51 +02002950 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002951 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002952 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2953 mac_addr, &sinfo);
2954 if (err == -ENOENT)
2955 break;
2956 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002957 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002958
2959 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00002960 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002961 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002962 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002963 &sinfo) < 0)
2964 goto out;
2965
2966 sta_idx++;
2967 }
2968
2969
2970 out:
2971 cb->args[1] = sta_idx;
2972 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002973 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002974 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002975
2976 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002977}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002978
Johannes Berg5727ef12007-12-19 02:03:34 +01002979static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2980{
Johannes Berg4c476992010-10-04 21:36:35 +02002981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2982 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002983 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002984 struct sk_buff *msg;
2985 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002986 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002987
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002988 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002989
2990 if (!info->attrs[NL80211_ATTR_MAC])
2991 return -EINVAL;
2992
2993 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2994
Johannes Berg4c476992010-10-04 21:36:35 +02002995 if (!rdev->ops->get_station)
2996 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002997
Johannes Berg79c97e92009-07-07 03:56:12 +02002998 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002999 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003000 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003001
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003003 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003004 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003005
Eric W. Biederman15e47302012-09-07 20:12:54 +00003006 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003007 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003008 nlmsg_free(msg);
3009 return -ENOBUFS;
3010 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003011
Johannes Berg4c476992010-10-04 21:36:35 +02003012 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003013}
3014
3015/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003016 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003017 */
Johannes Berg80b99892011-11-18 16:23:01 +01003018static struct net_device *get_vlan(struct genl_info *info,
3019 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003020{
Johannes Berg463d0182009-07-14 00:33:35 +02003021 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003022 struct net_device *v;
3023 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003024
Johannes Berg80b99892011-11-18 16:23:01 +01003025 if (!vlanattr)
3026 return NULL;
3027
3028 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3029 if (!v)
3030 return ERR_PTR(-ENODEV);
3031
3032 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3033 ret = -EINVAL;
3034 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003035 }
Johannes Berg80b99892011-11-18 16:23:01 +01003036
3037 if (!netif_running(v)) {
3038 ret = -ENETDOWN;
3039 goto error;
3040 }
3041
3042 return v;
3043 error:
3044 dev_put(v);
3045 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003046}
3047
3048static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3049{
Johannes Berg4c476992010-10-04 21:36:35 +02003050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003051 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003052 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003053 struct station_parameters params;
3054 u8 *mac_addr = NULL;
3055
3056 memset(&params, 0, sizeof(params));
3057
3058 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07003059 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01003060
3061 if (info->attrs[NL80211_ATTR_STA_AID])
3062 return -EINVAL;
3063
3064 if (!info->attrs[NL80211_ATTR_MAC])
3065 return -EINVAL;
3066
3067 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3068
3069 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3070 params.supported_rates =
3071 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3072 params.supported_rates_len =
3073 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3074 }
3075
3076 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3077 params.listen_interval =
3078 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3079
Jouni Malinen36aedc92008-08-25 11:58:58 +03003080 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3081 params.ht_capa =
3082 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3083
Johannes Bergbdd90d52011-12-14 12:20:27 +01003084 if (!rdev->ops->change_station)
3085 return -EOPNOTSUPP;
3086
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003087 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003088 return -EINVAL;
3089
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003090 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3091 params.plink_action =
3092 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3093
Javier Cardona9c3990a2011-05-03 16:57:11 -07003094 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
3095 params.plink_state =
3096 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3097
Johannes Berga97f4422009-06-18 17:23:43 +02003098 switch (dev->ieee80211_ptr->iftype) {
3099 case NL80211_IFTYPE_AP:
3100 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003101 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02003102 /* disallow mesh-specific things */
3103 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003104 return -EINVAL;
3105
3106 /* TDLS can't be set, ... */
3107 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3108 return -EINVAL;
3109 /*
3110 * ... but don't bother the driver with it. This works around
3111 * a hostapd/wpa_supplicant issue -- it always includes the
3112 * TLDS_PEER flag in the mask even for AP mode.
3113 */
3114 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3115
3116 /* accept only the listed bits */
3117 if (params.sta_flags_mask &
3118 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3119 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3120 BIT(NL80211_STA_FLAG_WME) |
3121 BIT(NL80211_STA_FLAG_MFP)))
3122 return -EINVAL;
3123
3124 /* must be last in here for error handling */
3125 params.vlan = get_vlan(info, rdev);
3126 if (IS_ERR(params.vlan))
3127 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02003128 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02003129 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003130 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003131 /*
3132 * Don't allow userspace to change the TDLS_PEER flag,
3133 * but silently ignore attempts to change it since we
3134 * don't have state here to verify that it doesn't try
3135 * to change the flag.
3136 */
3137 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01003138 /* fall through */
3139 case NL80211_IFTYPE_ADHOC:
3140 /* disallow things sta doesn't support */
3141 if (params.plink_action)
3142 return -EINVAL;
3143 if (params.ht_capa)
3144 return -EINVAL;
3145 if (params.listen_interval >= 0)
3146 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003147 /* reject any changes other than AUTHORIZED */
3148 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3149 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003150 break;
3151 case NL80211_IFTYPE_MESH_POINT:
3152 /* disallow things mesh doesn't support */
3153 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003154 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003155 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003156 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003157 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003158 return -EINVAL;
3159 /*
3160 * No special handling for TDLS here -- the userspace
3161 * mesh code doesn't have this bug.
3162 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003163 if (params.sta_flags_mask &
3164 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003165 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003166 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003167 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003168 break;
3169 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003170 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003171 }
3172
Johannes Bergbdd90d52011-12-14 12:20:27 +01003173 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003174
Johannes Berg79c97e92009-07-07 03:56:12 +02003175 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003176
Johannes Berg5727ef12007-12-19 02:03:34 +01003177 if (params.vlan)
3178 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003179
Johannes Berg5727ef12007-12-19 02:03:34 +01003180 return err;
3181}
3182
Eliad Pellerc75786c2011-08-23 14:37:46 +03003183static struct nla_policy
3184nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3185 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3186 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3187};
3188
Johannes Berg5727ef12007-12-19 02:03:34 +01003189static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3190{
Johannes Berg4c476992010-10-04 21:36:35 +02003191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003192 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003193 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003194 struct station_parameters params;
3195 u8 *mac_addr = NULL;
3196
3197 memset(&params, 0, sizeof(params));
3198
3199 if (!info->attrs[NL80211_ATTR_MAC])
3200 return -EINVAL;
3201
Johannes Berg5727ef12007-12-19 02:03:34 +01003202 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3203 return -EINVAL;
3204
3205 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3206 return -EINVAL;
3207
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003208 if (!info->attrs[NL80211_ATTR_STA_AID])
3209 return -EINVAL;
3210
Johannes Berg5727ef12007-12-19 02:03:34 +01003211 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3212 params.supported_rates =
3213 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3214 params.supported_rates_len =
3215 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3216 params.listen_interval =
3217 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003218
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003219 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3220 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3221 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003222
Jouni Malinen36aedc92008-08-25 11:58:58 +03003223 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3224 params.ht_capa =
3225 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003226
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003227 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3228 params.vht_capa =
3229 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3230
Javier Cardona96b78df2011-04-07 15:08:33 -07003231 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3232 params.plink_action =
3233 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3234
Johannes Bergbdd90d52011-12-14 12:20:27 +01003235 if (!rdev->ops->add_station)
3236 return -EOPNOTSUPP;
3237
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003238 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003239 return -EINVAL;
3240
Johannes Bergbdd90d52011-12-14 12:20:27 +01003241 switch (dev->ieee80211_ptr->iftype) {
3242 case NL80211_IFTYPE_AP:
3243 case NL80211_IFTYPE_AP_VLAN:
3244 case NL80211_IFTYPE_P2P_GO:
3245 /* parse WME attributes if sta is WME capable */
3246 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3247 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3248 info->attrs[NL80211_ATTR_STA_WME]) {
3249 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3250 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003251
Johannes Bergbdd90d52011-12-14 12:20:27 +01003252 nla = info->attrs[NL80211_ATTR_STA_WME];
3253 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3254 nl80211_sta_wme_policy);
3255 if (err)
3256 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003257
Johannes Bergbdd90d52011-12-14 12:20:27 +01003258 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3259 params.uapsd_queues =
3260 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3261 if (params.uapsd_queues &
3262 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3263 return -EINVAL;
3264
3265 if (tb[NL80211_STA_WME_MAX_SP])
3266 params.max_sp =
3267 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3268
3269 if (params.max_sp &
3270 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3271 return -EINVAL;
3272
3273 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3274 }
3275 /* TDLS peers cannot be added */
3276 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003277 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003278 /* but don't bother the driver with it */
3279 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003280
Johannes Bergbdd90d52011-12-14 12:20:27 +01003281 /* must be last in here for error handling */
3282 params.vlan = get_vlan(info, rdev);
3283 if (IS_ERR(params.vlan))
3284 return PTR_ERR(params.vlan);
3285 break;
3286 case NL80211_IFTYPE_MESH_POINT:
3287 /* TDLS peers cannot be added */
3288 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003289 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003290 break;
3291 case NL80211_IFTYPE_STATION:
3292 /* Only TDLS peers can be added */
3293 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3294 return -EINVAL;
3295 /* Can only add if TDLS ... */
3296 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3297 return -EOPNOTSUPP;
3298 /* ... with external setup is supported */
3299 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3300 return -EOPNOTSUPP;
3301 break;
3302 default:
3303 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003304 }
3305
Johannes Bergbdd90d52011-12-14 12:20:27 +01003306 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003307
Johannes Berg79c97e92009-07-07 03:56:12 +02003308 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003309
Johannes Berg5727ef12007-12-19 02:03:34 +01003310 if (params.vlan)
3311 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003312 return err;
3313}
3314
3315static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3316{
Johannes Berg4c476992010-10-04 21:36:35 +02003317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3318 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003319 u8 *mac_addr = NULL;
3320
3321 if (info->attrs[NL80211_ATTR_MAC])
3322 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3323
Johannes Berge80cf852009-05-11 14:43:13 +02003324 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003325 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003326 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003327 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3328 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003329
Johannes Berg4c476992010-10-04 21:36:35 +02003330 if (!rdev->ops->del_station)
3331 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003332
Johannes Berg4c476992010-10-04 21:36:35 +02003333 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003334}
3335
Eric W. Biederman15e47302012-09-07 20:12:54 +00003336static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003337 int flags, struct net_device *dev,
3338 u8 *dst, u8 *next_hop,
3339 struct mpath_info *pinfo)
3340{
3341 void *hdr;
3342 struct nlattr *pinfoattr;
3343
Eric W. Biederman15e47302012-09-07 20:12:54 +00003344 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003345 if (!hdr)
3346 return -1;
3347
David S. Miller9360ffd2012-03-29 04:41:26 -04003348 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3349 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3350 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3351 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3352 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003353
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003354 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3355 if (!pinfoattr)
3356 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003357 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3358 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3359 pinfo->frame_qlen))
3360 goto nla_put_failure;
3361 if (((pinfo->filled & MPATH_INFO_SN) &&
3362 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3363 ((pinfo->filled & MPATH_INFO_METRIC) &&
3364 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3365 pinfo->metric)) ||
3366 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3367 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3368 pinfo->exptime)) ||
3369 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3370 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3371 pinfo->flags)) ||
3372 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3373 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3374 pinfo->discovery_timeout)) ||
3375 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3376 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3377 pinfo->discovery_retries)))
3378 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003379
3380 nla_nest_end(msg, pinfoattr);
3381
3382 return genlmsg_end(msg, hdr);
3383
3384 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003385 genlmsg_cancel(msg, hdr);
3386 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003387}
3388
3389static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003390 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003391{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003392 struct mpath_info pinfo;
3393 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003394 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003395 u8 dst[ETH_ALEN];
3396 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003397 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003398 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003399
Johannes Berg67748892010-10-04 21:14:06 +02003400 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3401 if (err)
3402 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003403
3404 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003405 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003406 goto out_err;
3407 }
3408
Jouni Malineneec60b02009-03-20 21:21:19 +02003409 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3410 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003411 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003412 }
3413
Johannes Bergbba95fe2008-07-29 13:22:51 +02003414 while (1) {
3415 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3416 dst, next_hop, &pinfo);
3417 if (err == -ENOENT)
3418 break;
3419 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003420 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003421
Eric W. Biederman15e47302012-09-07 20:12:54 +00003422 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003423 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3424 netdev, dst, next_hop,
3425 &pinfo) < 0)
3426 goto out;
3427
3428 path_idx++;
3429 }
3430
3431
3432 out:
3433 cb->args[1] = path_idx;
3434 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003435 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003436 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003437 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003438}
3439
3440static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3441{
Johannes Berg4c476992010-10-04 21:36:35 +02003442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003443 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003444 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003445 struct mpath_info pinfo;
3446 struct sk_buff *msg;
3447 u8 *dst = NULL;
3448 u8 next_hop[ETH_ALEN];
3449
3450 memset(&pinfo, 0, sizeof(pinfo));
3451
3452 if (!info->attrs[NL80211_ATTR_MAC])
3453 return -EINVAL;
3454
3455 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3456
Johannes Berg4c476992010-10-04 21:36:35 +02003457 if (!rdev->ops->get_mpath)
3458 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003459
Johannes Berg4c476992010-10-04 21:36:35 +02003460 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3461 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003462
Johannes Berg79c97e92009-07-07 03:56:12 +02003463 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003464 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003465 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003466
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003468 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003469 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003470
Eric W. Biederman15e47302012-09-07 20:12:54 +00003471 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003472 dev, dst, next_hop, &pinfo) < 0) {
3473 nlmsg_free(msg);
3474 return -ENOBUFS;
3475 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003476
Johannes Berg4c476992010-10-04 21:36:35 +02003477 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003478}
3479
3480static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3481{
Johannes Berg4c476992010-10-04 21:36:35 +02003482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3483 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003484 u8 *dst = NULL;
3485 u8 *next_hop = NULL;
3486
3487 if (!info->attrs[NL80211_ATTR_MAC])
3488 return -EINVAL;
3489
3490 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3491 return -EINVAL;
3492
3493 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3494 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3495
Johannes Berg4c476992010-10-04 21:36:35 +02003496 if (!rdev->ops->change_mpath)
3497 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003498
Johannes Berg4c476992010-10-04 21:36:35 +02003499 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3500 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003501
Johannes Berg4c476992010-10-04 21:36:35 +02003502 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003503}
Johannes Berg4c476992010-10-04 21:36:35 +02003504
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003505static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3506{
Johannes Berg4c476992010-10-04 21:36:35 +02003507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3508 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003509 u8 *dst = NULL;
3510 u8 *next_hop = NULL;
3511
3512 if (!info->attrs[NL80211_ATTR_MAC])
3513 return -EINVAL;
3514
3515 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3516 return -EINVAL;
3517
3518 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3519 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3520
Johannes Berg4c476992010-10-04 21:36:35 +02003521 if (!rdev->ops->add_mpath)
3522 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003523
Johannes Berg4c476992010-10-04 21:36:35 +02003524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3525 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526
Johannes Berg4c476992010-10-04 21:36:35 +02003527 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003528}
3529
3530static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3531{
Johannes Berg4c476992010-10-04 21:36:35 +02003532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3533 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003534 u8 *dst = NULL;
3535
3536 if (info->attrs[NL80211_ATTR_MAC])
3537 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3538
Johannes Berg4c476992010-10-04 21:36:35 +02003539 if (!rdev->ops->del_mpath)
3540 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003541
Johannes Berg4c476992010-10-04 21:36:35 +02003542 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003543}
3544
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003545static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3546{
Johannes Berg4c476992010-10-04 21:36:35 +02003547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3548 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003549 struct bss_parameters params;
3550
3551 memset(&params, 0, sizeof(params));
3552 /* default to not changing parameters */
3553 params.use_cts_prot = -1;
3554 params.use_short_preamble = -1;
3555 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003556 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003557 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003558
3559 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3560 params.use_cts_prot =
3561 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3562 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3563 params.use_short_preamble =
3564 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3565 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3566 params.use_short_slot_time =
3567 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003568 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3569 params.basic_rates =
3570 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3571 params.basic_rates_len =
3572 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3573 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003574 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3575 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003576 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3577 params.ht_opmode =
3578 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003579
Johannes Berg4c476992010-10-04 21:36:35 +02003580 if (!rdev->ops->change_bss)
3581 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003582
Johannes Berg074ac8d2010-09-16 14:58:22 +02003583 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003584 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3585 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003588}
3589
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003590static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003591 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3592 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3593 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3594 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3595 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3596 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3597};
3598
3599static int parse_reg_rule(struct nlattr *tb[],
3600 struct ieee80211_reg_rule *reg_rule)
3601{
3602 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3603 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3604
3605 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3606 return -EINVAL;
3607 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3608 return -EINVAL;
3609 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3610 return -EINVAL;
3611 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3612 return -EINVAL;
3613 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3614 return -EINVAL;
3615
3616 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3617
3618 freq_range->start_freq_khz =
3619 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3620 freq_range->end_freq_khz =
3621 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3622 freq_range->max_bandwidth_khz =
3623 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3624
3625 power_rule->max_eirp =
3626 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3627
3628 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3629 power_rule->max_antenna_gain =
3630 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3631
3632 return 0;
3633}
3634
3635static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3636{
3637 int r;
3638 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003639 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003640
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003641 /*
3642 * You should only get this when cfg80211 hasn't yet initialized
3643 * completely when built-in to the kernel right between the time
3644 * window between nl80211_init() and regulatory_init(), if that is
3645 * even possible.
3646 */
3647 mutex_lock(&cfg80211_mutex);
3648 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003649 mutex_unlock(&cfg80211_mutex);
3650 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003651 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003652 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003653
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003654 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3655 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003656
3657 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3658
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003659 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
3660 user_reg_hint_type =
3661 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
3662 else
3663 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
3664
3665 switch (user_reg_hint_type) {
3666 case NL80211_USER_REG_HINT_USER:
3667 case NL80211_USER_REG_HINT_CELL_BASE:
3668 break;
3669 default:
3670 return -EINVAL;
3671 }
3672
3673 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003674
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003675 return r;
3676}
3677
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003678static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003679 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003680{
Johannes Berg4c476992010-10-04 21:36:35 +02003681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003682 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003683 struct wireless_dev *wdev = dev->ieee80211_ptr;
3684 struct mesh_config cur_params;
3685 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003686 void *hdr;
3687 struct nlattr *pinfoattr;
3688 struct sk_buff *msg;
3689
Johannes Berg29cbe682010-12-03 09:20:44 +01003690 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3691 return -EOPNOTSUPP;
3692
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003693 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003694 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003695
Johannes Berg29cbe682010-12-03 09:20:44 +01003696 wdev_lock(wdev);
3697 /* If not connected, get default parameters */
3698 if (!wdev->mesh_id_len)
3699 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3700 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003701 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003702 &cur_params);
3703 wdev_unlock(wdev);
3704
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003705 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003706 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003707
3708 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003710 if (!msg)
3711 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00003712 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003713 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003714 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003715 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003716 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003717 if (!pinfoattr)
3718 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003719 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3720 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3721 cur_params.dot11MeshRetryTimeout) ||
3722 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3723 cur_params.dot11MeshConfirmTimeout) ||
3724 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3725 cur_params.dot11MeshHoldingTimeout) ||
3726 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3727 cur_params.dot11MeshMaxPeerLinks) ||
3728 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3729 cur_params.dot11MeshMaxRetries) ||
3730 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3731 cur_params.dot11MeshTTL) ||
3732 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3733 cur_params.element_ttl) ||
3734 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3735 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003736 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3737 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003738 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3739 cur_params.dot11MeshHWMPmaxPREQretries) ||
3740 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3741 cur_params.path_refresh_time) ||
3742 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3743 cur_params.min_discovery_timeout) ||
3744 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3745 cur_params.dot11MeshHWMPactivePathTimeout) ||
3746 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3747 cur_params.dot11MeshHWMPpreqMinInterval) ||
3748 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3749 cur_params.dot11MeshHWMPperrMinInterval) ||
3750 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3751 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3752 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3753 cur_params.dot11MeshHWMPRootMode) ||
3754 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3755 cur_params.dot11MeshHWMPRannInterval) ||
3756 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3757 cur_params.dot11MeshGateAnnouncementProtocol) ||
3758 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3759 cur_params.dot11MeshForwarding) ||
3760 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003761 cur_params.rssi_threshold) ||
3762 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003763 cur_params.ht_opmode) ||
3764 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3765 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3766 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003767 cur_params.dot11MeshHWMProotInterval) ||
3768 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3769 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003770 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003771 nla_nest_end(msg, pinfoattr);
3772 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003773 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003774
Johannes Berg3b858752009-03-12 09:55:09 +01003775 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003776 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003777 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003778 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003779 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003780}
3781
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003782static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003783 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3784 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3785 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3786 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3787 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3788 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003789 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003790 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003791 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003792 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3793 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3794 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3795 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3796 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003797 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003798 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003799 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003800 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003801 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003802 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003803 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3804 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003805 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3806 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003807 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003808};
3809
Javier Cardonac80d5452010-12-16 17:37:49 -08003810static const struct nla_policy
3811 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003812 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003813 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3814 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003815 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003816 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003817 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003818 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003819};
3820
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003821static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003822 struct mesh_config *cfg,
3823 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003824{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003825 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003826 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003827
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003828#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3829do {\
3830 if (table[attr_num]) {\
3831 cfg->param = nla_fn(table[attr_num]); \
3832 mask |= (1 << (attr_num - 1)); \
3833 } \
3834} while (0);\
3835
3836
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003837 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003838 return -EINVAL;
3839 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003840 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003841 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003842 return -EINVAL;
3843
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003844 /* This makes sure that there aren't more than 32 mesh config
3845 * parameters (otherwise our bitfield scheme would not work.) */
3846 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3847
3848 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003849 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003850 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3851 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003852 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003853 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3854 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003855 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003856 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3857 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003858 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003859 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3860 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003861 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003862 mask, NL80211_MESHCONF_MAX_RETRIES,
3863 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003864 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003865 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003866 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003867 mask, NL80211_MESHCONF_ELEMENT_TTL,
3868 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003869 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003870 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3871 nla_get_u8);
3872 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3873 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3874 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003876 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3877 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003878 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003879 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3880 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003882 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3883 nla_get_u16);
3884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3885 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3886 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003888 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3889 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003891 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3892 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003893 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003894 dot11MeshHWMPnetDiameterTraversalTime, mask,
3895 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3896 nla_get_u16);
3897 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3898 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3899 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3900 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3901 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003903 dot11MeshGateAnnouncementProtocol, mask,
3904 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3905 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003906 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003907 mask, NL80211_MESHCONF_FORWARDING,
3908 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003909 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003910 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3911 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003912 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003913 mask, NL80211_MESHCONF_HT_OPMODE,
3914 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003915 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3916 mask,
3917 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3918 nla_get_u32);
3919 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3920 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3921 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003922 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3923 dot11MeshHWMPconfirmationInterval, mask,
3924 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3925 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003926 if (mask_out)
3927 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003928
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003929 return 0;
3930
3931#undef FILL_IN_MESH_PARAM_IF_SET
3932}
3933
Javier Cardonac80d5452010-12-16 17:37:49 -08003934static int nl80211_parse_mesh_setup(struct genl_info *info,
3935 struct mesh_setup *setup)
3936{
3937 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3938
3939 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3940 return -EINVAL;
3941 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3942 info->attrs[NL80211_ATTR_MESH_SETUP],
3943 nl80211_mesh_setup_params_policy))
3944 return -EINVAL;
3945
Javier Cardonad299a1f2012-03-31 11:31:33 -07003946 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3947 setup->sync_method =
3948 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3949 IEEE80211_SYNC_METHOD_VENDOR :
3950 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3951
Javier Cardonac80d5452010-12-16 17:37:49 -08003952 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3953 setup->path_sel_proto =
3954 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3955 IEEE80211_PATH_PROTOCOL_VENDOR :
3956 IEEE80211_PATH_PROTOCOL_HWMP;
3957
3958 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3959 setup->path_metric =
3960 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3961 IEEE80211_PATH_METRIC_VENDOR :
3962 IEEE80211_PATH_METRIC_AIRTIME;
3963
Javier Cardona581a8b02011-04-07 15:08:27 -07003964
3965 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003966 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003967 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003968 if (!is_valid_ie_attr(ieattr))
3969 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003970 setup->ie = nla_data(ieattr);
3971 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003972 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003973 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3974 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003975
3976 return 0;
3977}
3978
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003979static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003980 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003981{
3982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3983 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003984 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003985 struct mesh_config cfg;
3986 u32 mask;
3987 int err;
3988
Johannes Berg29cbe682010-12-03 09:20:44 +01003989 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3990 return -EOPNOTSUPP;
3991
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003992 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003993 return -EOPNOTSUPP;
3994
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003995 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003996 if (err)
3997 return err;
3998
Johannes Berg29cbe682010-12-03 09:20:44 +01003999 wdev_lock(wdev);
4000 if (!wdev->mesh_id_len)
4001 err = -ENOLINK;
4002
4003 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004004 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01004005 mask, &cfg);
4006
4007 wdev_unlock(wdev);
4008
4009 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004010}
4011
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004012static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4013{
4014 struct sk_buff *msg;
4015 void *hdr = NULL;
4016 struct nlattr *nl_reg_rules;
4017 unsigned int i;
4018 int err = -EINVAL;
4019
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004020 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004021
4022 if (!cfg80211_regdomain)
4023 goto out;
4024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004026 if (!msg) {
4027 err = -ENOBUFS;
4028 goto out;
4029 }
4030
Eric W. Biederman15e47302012-09-07 20:12:54 +00004031 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004032 NL80211_CMD_GET_REG);
4033 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004034 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004035
David S. Miller9360ffd2012-03-29 04:41:26 -04004036 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
4037 cfg80211_regdomain->alpha2) ||
4038 (cfg80211_regdomain->dfs_region &&
4039 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
4040 cfg80211_regdomain->dfs_region)))
4041 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004042
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004043 if (reg_last_request_cell_base() &&
4044 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4045 NL80211_USER_REG_HINT_CELL_BASE))
4046 goto nla_put_failure;
4047
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004048 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4049 if (!nl_reg_rules)
4050 goto nla_put_failure;
4051
4052 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
4053 struct nlattr *nl_reg_rule;
4054 const struct ieee80211_reg_rule *reg_rule;
4055 const struct ieee80211_freq_range *freq_range;
4056 const struct ieee80211_power_rule *power_rule;
4057
4058 reg_rule = &cfg80211_regdomain->reg_rules[i];
4059 freq_range = &reg_rule->freq_range;
4060 power_rule = &reg_rule->power_rule;
4061
4062 nl_reg_rule = nla_nest_start(msg, i);
4063 if (!nl_reg_rule)
4064 goto nla_put_failure;
4065
David S. Miller9360ffd2012-03-29 04:41:26 -04004066 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4067 reg_rule->flags) ||
4068 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4069 freq_range->start_freq_khz) ||
4070 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4071 freq_range->end_freq_khz) ||
4072 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4073 freq_range->max_bandwidth_khz) ||
4074 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4075 power_rule->max_antenna_gain) ||
4076 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4077 power_rule->max_eirp))
4078 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004079
4080 nla_nest_end(msg, nl_reg_rule);
4081 }
4082
4083 nla_nest_end(msg, nl_reg_rules);
4084
4085 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004086 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004087 goto out;
4088
4089nla_put_failure:
4090 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004091put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004092 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004093 err = -EMSGSIZE;
4094out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004095 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004096 return err;
4097}
4098
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004099static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4100{
4101 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4102 struct nlattr *nl_reg_rule;
4103 char *alpha2 = NULL;
4104 int rem_reg_rules = 0, r = 0;
4105 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004106 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004107 struct ieee80211_regdomain *rd = NULL;
4108
4109 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4110 return -EINVAL;
4111
4112 if (!info->attrs[NL80211_ATTR_REG_RULES])
4113 return -EINVAL;
4114
4115 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4116
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004117 if (info->attrs[NL80211_ATTR_DFS_REGION])
4118 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4119
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004120 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4121 rem_reg_rules) {
4122 num_rules++;
4123 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004124 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004125 }
4126
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004127 mutex_lock(&cfg80211_mutex);
4128
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004129 if (!reg_is_valid_request(alpha2)) {
4130 r = -EINVAL;
4131 goto bad_reg;
4132 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004133
4134 size_of_regd = sizeof(struct ieee80211_regdomain) +
4135 (num_rules * sizeof(struct ieee80211_reg_rule));
4136
4137 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004138 if (!rd) {
4139 r = -ENOMEM;
4140 goto bad_reg;
4141 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004142
4143 rd->n_reg_rules = num_rules;
4144 rd->alpha2[0] = alpha2[0];
4145 rd->alpha2[1] = alpha2[1];
4146
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004147 /*
4148 * Disable DFS master mode if the DFS region was
4149 * not supported or known on this kernel.
4150 */
4151 if (reg_supported_dfs_region(dfs_region))
4152 rd->dfs_region = dfs_region;
4153
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004154 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4155 rem_reg_rules) {
4156 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4157 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4158 reg_rule_policy);
4159 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4160 if (r)
4161 goto bad_reg;
4162
4163 rule_idx++;
4164
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004165 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4166 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004167 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004168 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004169 }
4170
4171 BUG_ON(rule_idx != num_rules);
4172
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004173 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004174
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004175 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004176
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004177 return r;
4178
Johannes Bergd2372b32008-10-24 20:32:20 +02004179 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004180 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004181 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004182 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004183}
4184
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004185static int validate_scan_freqs(struct nlattr *freqs)
4186{
4187 struct nlattr *attr1, *attr2;
4188 int n_channels = 0, tmp1, tmp2;
4189
4190 nla_for_each_nested(attr1, freqs, tmp1) {
4191 n_channels++;
4192 /*
4193 * Some hardware has a limited channel list for
4194 * scanning, and it is pretty much nonsensical
4195 * to scan for a channel twice, so disallow that
4196 * and don't require drivers to check that the
4197 * channel list they get isn't longer than what
4198 * they can scan, as long as they can scan all
4199 * the channels they registered at once.
4200 */
4201 nla_for_each_nested(attr2, freqs, tmp2)
4202 if (attr1 != attr2 &&
4203 nla_get_u32(attr1) == nla_get_u32(attr2))
4204 return 0;
4205 }
4206
4207 return n_channels;
4208}
4209
Johannes Berg2a519312009-02-10 21:25:55 +01004210static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4211{
Johannes Berg4c476992010-10-04 21:36:35 +02004212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02004213 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004214 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004215 struct nlattr *attr;
4216 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004217 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004218 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004219
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004220 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4221 return -EINVAL;
4222
Johannes Berg79c97e92009-07-07 03:56:12 +02004223 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004224
Johannes Berg4c476992010-10-04 21:36:35 +02004225 if (!rdev->ops->scan)
4226 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004227
Johannes Berg4c476992010-10-04 21:36:35 +02004228 if (rdev->scan_req)
4229 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004230
4231 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004232 n_channels = validate_scan_freqs(
4233 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004234 if (!n_channels)
4235 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004236 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004237 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004238 n_channels = 0;
4239
Johannes Berg2a519312009-02-10 21:25:55 +01004240 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4241 if (wiphy->bands[band])
4242 n_channels += wiphy->bands[band]->n_channels;
4243 }
4244
4245 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4246 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4247 n_ssids++;
4248
Johannes Berg4c476992010-10-04 21:36:35 +02004249 if (n_ssids > wiphy->max_scan_ssids)
4250 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004251
Jouni Malinen70692ad2009-02-16 19:39:13 +02004252 if (info->attrs[NL80211_ATTR_IE])
4253 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4254 else
4255 ie_len = 0;
4256
Johannes Berg4c476992010-10-04 21:36:35 +02004257 if (ie_len > wiphy->max_scan_ie_len)
4258 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004259
Johannes Berg2a519312009-02-10 21:25:55 +01004260 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004261 + sizeof(*request->ssids) * n_ssids
4262 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004263 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004264 if (!request)
4265 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004266
Johannes Berg2a519312009-02-10 21:25:55 +01004267 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004268 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004269 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004270 if (ie_len) {
4271 if (request->ssids)
4272 request->ie = (void *)(request->ssids + n_ssids);
4273 else
4274 request->ie = (void *)(request->channels + n_channels);
4275 }
Johannes Berg2a519312009-02-10 21:25:55 +01004276
Johannes Berg584991d2009-11-02 13:32:03 +01004277 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004278 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4279 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004280 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004281 struct ieee80211_channel *chan;
4282
4283 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4284
4285 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004286 err = -EINVAL;
4287 goto out_free;
4288 }
Johannes Berg584991d2009-11-02 13:32:03 +01004289
4290 /* ignore disabled channels */
4291 if (chan->flags & IEEE80211_CHAN_DISABLED)
4292 continue;
4293
4294 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004295 i++;
4296 }
4297 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004298 enum ieee80211_band band;
4299
Johannes Berg2a519312009-02-10 21:25:55 +01004300 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004301 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4302 int j;
4303 if (!wiphy->bands[band])
4304 continue;
4305 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004306 struct ieee80211_channel *chan;
4307
4308 chan = &wiphy->bands[band]->channels[j];
4309
4310 if (chan->flags & IEEE80211_CHAN_DISABLED)
4311 continue;
4312
4313 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004314 i++;
4315 }
4316 }
4317 }
4318
Johannes Berg584991d2009-11-02 13:32:03 +01004319 if (!i) {
4320 err = -EINVAL;
4321 goto out_free;
4322 }
4323
4324 request->n_channels = i;
4325
Johannes Berg2a519312009-02-10 21:25:55 +01004326 i = 0;
4327 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4328 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004329 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004330 err = -EINVAL;
4331 goto out_free;
4332 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004333 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004334 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004335 i++;
4336 }
4337 }
4338
Jouni Malinen70692ad2009-02-16 19:39:13 +02004339 if (info->attrs[NL80211_ATTR_IE]) {
4340 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004341 memcpy((void *)request->ie,
4342 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004343 request->ie_len);
4344 }
4345
Johannes Berg34850ab2011-07-18 18:08:35 +02004346 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004347 if (wiphy->bands[i])
4348 request->rates[i] =
4349 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004350
4351 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4352 nla_for_each_nested(attr,
4353 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4354 tmp) {
4355 enum ieee80211_band band = nla_type(attr);
4356
Dan Carpenter84404622011-07-29 11:52:18 +03004357 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004358 err = -EINVAL;
4359 goto out_free;
4360 }
4361 err = ieee80211_get_ratemask(wiphy->bands[band],
4362 nla_data(attr),
4363 nla_len(attr),
4364 &request->rates[band]);
4365 if (err)
4366 goto out_free;
4367 }
4368 }
4369
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304370 request->no_cck =
4371 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4372
Johannes Bergfd014282012-06-18 19:17:03 +02004373 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004374 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004375
Johannes Berg79c97e92009-07-07 03:56:12 +02004376 rdev->scan_req = request;
Johannes Bergfd014282012-06-18 19:17:03 +02004377 err = rdev->ops->scan(&rdev->wiphy, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004378
Johannes Berg463d0182009-07-14 00:33:35 +02004379 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02004380 nl80211_send_scan_start(rdev, wdev);
4381 if (wdev->netdev)
4382 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02004383 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004384 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004385 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004386 kfree(request);
4387 }
Johannes Berg3b858752009-03-12 09:55:09 +01004388
Johannes Berg2a519312009-02-10 21:25:55 +01004389 return err;
4390}
4391
Luciano Coelho807f8a82011-05-11 17:09:35 +03004392static int nl80211_start_sched_scan(struct sk_buff *skb,
4393 struct genl_info *info)
4394{
4395 struct cfg80211_sched_scan_request *request;
4396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4397 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004398 struct nlattr *attr;
4399 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004400 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004401 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004402 enum ieee80211_band band;
4403 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004404 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004405
4406 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4407 !rdev->ops->sched_scan_start)
4408 return -EOPNOTSUPP;
4409
4410 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4411 return -EINVAL;
4412
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004413 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4414 return -EINVAL;
4415
4416 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4417 if (interval == 0)
4418 return -EINVAL;
4419
Luciano Coelho807f8a82011-05-11 17:09:35 +03004420 wiphy = &rdev->wiphy;
4421
4422 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4423 n_channels = validate_scan_freqs(
4424 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4425 if (!n_channels)
4426 return -EINVAL;
4427 } else {
4428 n_channels = 0;
4429
4430 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4431 if (wiphy->bands[band])
4432 n_channels += wiphy->bands[band]->n_channels;
4433 }
4434
4435 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4436 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4437 tmp)
4438 n_ssids++;
4439
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004440 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004441 return -EINVAL;
4442
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004443 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4444 nla_for_each_nested(attr,
4445 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4446 tmp)
4447 n_match_sets++;
4448
4449 if (n_match_sets > wiphy->max_match_sets)
4450 return -EINVAL;
4451
Luciano Coelho807f8a82011-05-11 17:09:35 +03004452 if (info->attrs[NL80211_ATTR_IE])
4453 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4454 else
4455 ie_len = 0;
4456
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004457 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004458 return -EINVAL;
4459
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004460 mutex_lock(&rdev->sched_scan_mtx);
4461
4462 if (rdev->sched_scan_req) {
4463 err = -EINPROGRESS;
4464 goto out;
4465 }
4466
Luciano Coelho807f8a82011-05-11 17:09:35 +03004467 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004468 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004469 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004470 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004471 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004472 if (!request) {
4473 err = -ENOMEM;
4474 goto out;
4475 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004476
4477 if (n_ssids)
4478 request->ssids = (void *)&request->channels[n_channels];
4479 request->n_ssids = n_ssids;
4480 if (ie_len) {
4481 if (request->ssids)
4482 request->ie = (void *)(request->ssids + n_ssids);
4483 else
4484 request->ie = (void *)(request->channels + n_channels);
4485 }
4486
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004487 if (n_match_sets) {
4488 if (request->ie)
4489 request->match_sets = (void *)(request->ie + ie_len);
4490 else if (request->ssids)
4491 request->match_sets =
4492 (void *)(request->ssids + n_ssids);
4493 else
4494 request->match_sets =
4495 (void *)(request->channels + n_channels);
4496 }
4497 request->n_match_sets = n_match_sets;
4498
Luciano Coelho807f8a82011-05-11 17:09:35 +03004499 i = 0;
4500 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4501 /* user specified, bail out if channel not found */
4502 nla_for_each_nested(attr,
4503 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4504 tmp) {
4505 struct ieee80211_channel *chan;
4506
4507 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4508
4509 if (!chan) {
4510 err = -EINVAL;
4511 goto out_free;
4512 }
4513
4514 /* ignore disabled channels */
4515 if (chan->flags & IEEE80211_CHAN_DISABLED)
4516 continue;
4517
4518 request->channels[i] = chan;
4519 i++;
4520 }
4521 } else {
4522 /* all channels */
4523 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4524 int j;
4525 if (!wiphy->bands[band])
4526 continue;
4527 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4528 struct ieee80211_channel *chan;
4529
4530 chan = &wiphy->bands[band]->channels[j];
4531
4532 if (chan->flags & IEEE80211_CHAN_DISABLED)
4533 continue;
4534
4535 request->channels[i] = chan;
4536 i++;
4537 }
4538 }
4539 }
4540
4541 if (!i) {
4542 err = -EINVAL;
4543 goto out_free;
4544 }
4545
4546 request->n_channels = i;
4547
4548 i = 0;
4549 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4550 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4551 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004552 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004553 err = -EINVAL;
4554 goto out_free;
4555 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004556 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004557 memcpy(request->ssids[i].ssid, nla_data(attr),
4558 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004559 i++;
4560 }
4561 }
4562
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004563 i = 0;
4564 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4565 nla_for_each_nested(attr,
4566 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4567 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004568 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004569
4570 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4571 nla_data(attr), nla_len(attr),
4572 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004573 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004574 if (ssid) {
4575 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4576 err = -EINVAL;
4577 goto out_free;
4578 }
4579 memcpy(request->match_sets[i].ssid.ssid,
4580 nla_data(ssid), nla_len(ssid));
4581 request->match_sets[i].ssid.ssid_len =
4582 nla_len(ssid);
4583 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004584 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4585 if (rssi)
4586 request->rssi_thold = nla_get_u32(rssi);
4587 else
4588 request->rssi_thold =
4589 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004590 i++;
4591 }
4592 }
4593
Luciano Coelho807f8a82011-05-11 17:09:35 +03004594 if (info->attrs[NL80211_ATTR_IE]) {
4595 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4596 memcpy((void *)request->ie,
4597 nla_data(info->attrs[NL80211_ATTR_IE]),
4598 request->ie_len);
4599 }
4600
4601 request->dev = dev;
4602 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004603 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004604
4605 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4606 if (!err) {
4607 rdev->sched_scan_req = request;
4608 nl80211_send_sched_scan(rdev, dev,
4609 NL80211_CMD_START_SCHED_SCAN);
4610 goto out;
4611 }
4612
4613out_free:
4614 kfree(request);
4615out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004616 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004617 return err;
4618}
4619
4620static int nl80211_stop_sched_scan(struct sk_buff *skb,
4621 struct genl_info *info)
4622{
4623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004624 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004625
4626 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4627 !rdev->ops->sched_scan_stop)
4628 return -EOPNOTSUPP;
4629
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004630 mutex_lock(&rdev->sched_scan_mtx);
4631 err = __cfg80211_stop_sched_scan(rdev, false);
4632 mutex_unlock(&rdev->sched_scan_mtx);
4633
4634 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004635}
4636
Johannes Berg9720bb32011-06-21 09:45:33 +02004637static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4638 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004639 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004640 struct wireless_dev *wdev,
4641 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004642{
Johannes Berg48ab9052009-07-10 18:42:31 +02004643 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004644 void *hdr;
4645 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004646
4647 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004648
Eric W. Biederman15e47302012-09-07 20:12:54 +00004649 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004650 NL80211_CMD_NEW_SCAN_RESULTS);
4651 if (!hdr)
4652 return -1;
4653
Johannes Berg9720bb32011-06-21 09:45:33 +02004654 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4655
David S. Miller9360ffd2012-03-29 04:41:26 -04004656 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4657 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4658 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004659
4660 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4661 if (!bss)
4662 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004663 if ((!is_zero_ether_addr(res->bssid) &&
4664 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4665 (res->information_elements && res->len_information_elements &&
4666 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4667 res->len_information_elements,
4668 res->information_elements)) ||
4669 (res->beacon_ies && res->len_beacon_ies &&
4670 res->beacon_ies != res->information_elements &&
4671 nla_put(msg, NL80211_BSS_BEACON_IES,
4672 res->len_beacon_ies, res->beacon_ies)))
4673 goto nla_put_failure;
4674 if (res->tsf &&
4675 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4676 goto nla_put_failure;
4677 if (res->beacon_interval &&
4678 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4679 goto nla_put_failure;
4680 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4681 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4682 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4683 jiffies_to_msecs(jiffies - intbss->ts)))
4684 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004685
Johannes Berg77965c92009-02-18 18:45:06 +01004686 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004687 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004688 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4689 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004690 break;
4691 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004692 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4693 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004694 break;
4695 default:
4696 break;
4697 }
4698
Johannes Berg48ab9052009-07-10 18:42:31 +02004699 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004700 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004701 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004702 if (intbss == wdev->current_bss &&
4703 nla_put_u32(msg, NL80211_BSS_STATUS,
4704 NL80211_BSS_STATUS_ASSOCIATED))
4705 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004706 break;
4707 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004708 if (intbss == wdev->current_bss &&
4709 nla_put_u32(msg, NL80211_BSS_STATUS,
4710 NL80211_BSS_STATUS_IBSS_JOINED))
4711 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004712 break;
4713 default:
4714 break;
4715 }
4716
Johannes Berg2a519312009-02-10 21:25:55 +01004717 nla_nest_end(msg, bss);
4718
4719 return genlmsg_end(msg, hdr);
4720
4721 nla_put_failure:
4722 genlmsg_cancel(msg, hdr);
4723 return -EMSGSIZE;
4724}
4725
4726static int nl80211_dump_scan(struct sk_buff *skb,
4727 struct netlink_callback *cb)
4728{
Johannes Berg48ab9052009-07-10 18:42:31 +02004729 struct cfg80211_registered_device *rdev;
4730 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004731 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004732 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004733 int start = cb->args[1], idx = 0;
4734 int err;
4735
Johannes Berg67748892010-10-04 21:14:06 +02004736 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4737 if (err)
4738 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004739
Johannes Berg48ab9052009-07-10 18:42:31 +02004740 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004741
Johannes Berg48ab9052009-07-10 18:42:31 +02004742 wdev_lock(wdev);
4743 spin_lock_bh(&rdev->bss_lock);
4744 cfg80211_bss_expire(rdev);
4745
Johannes Berg9720bb32011-06-21 09:45:33 +02004746 cb->seq = rdev->bss_generation;
4747
Johannes Berg48ab9052009-07-10 18:42:31 +02004748 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004749 if (++idx <= start)
4750 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004751 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004752 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004753 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004754 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004755 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004756 }
4757 }
4758
Johannes Berg48ab9052009-07-10 18:42:31 +02004759 spin_unlock_bh(&rdev->bss_lock);
4760 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004761
4762 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004763 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004764
Johannes Berg67748892010-10-04 21:14:06 +02004765 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004766}
4767
Eric W. Biederman15e47302012-09-07 20:12:54 +00004768static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01004769 int flags, struct net_device *dev,
4770 struct survey_info *survey)
4771{
4772 void *hdr;
4773 struct nlattr *infoattr;
4774
Eric W. Biederman15e47302012-09-07 20:12:54 +00004775 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01004776 NL80211_CMD_NEW_SURVEY_RESULTS);
4777 if (!hdr)
4778 return -ENOMEM;
4779
David S. Miller9360ffd2012-03-29 04:41:26 -04004780 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4781 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004782
4783 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4784 if (!infoattr)
4785 goto nla_put_failure;
4786
David S. Miller9360ffd2012-03-29 04:41:26 -04004787 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4788 survey->channel->center_freq))
4789 goto nla_put_failure;
4790
4791 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4792 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4793 goto nla_put_failure;
4794 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4795 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4796 goto nla_put_failure;
4797 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4798 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4799 survey->channel_time))
4800 goto nla_put_failure;
4801 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4802 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4803 survey->channel_time_busy))
4804 goto nla_put_failure;
4805 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4806 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4807 survey->channel_time_ext_busy))
4808 goto nla_put_failure;
4809 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4810 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4811 survey->channel_time_rx))
4812 goto nla_put_failure;
4813 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4814 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4815 survey->channel_time_tx))
4816 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004817
4818 nla_nest_end(msg, infoattr);
4819
4820 return genlmsg_end(msg, hdr);
4821
4822 nla_put_failure:
4823 genlmsg_cancel(msg, hdr);
4824 return -EMSGSIZE;
4825}
4826
4827static int nl80211_dump_survey(struct sk_buff *skb,
4828 struct netlink_callback *cb)
4829{
4830 struct survey_info survey;
4831 struct cfg80211_registered_device *dev;
4832 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004833 int survey_idx = cb->args[1];
4834 int res;
4835
Johannes Berg67748892010-10-04 21:14:06 +02004836 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4837 if (res)
4838 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004839
4840 if (!dev->ops->dump_survey) {
4841 res = -EOPNOTSUPP;
4842 goto out_err;
4843 }
4844
4845 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004846 struct ieee80211_channel *chan;
4847
Holger Schurig61fa7132009-11-11 12:25:40 +01004848 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4849 &survey);
4850 if (res == -ENOENT)
4851 break;
4852 if (res)
4853 goto out_err;
4854
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004855 /* Survey without a channel doesn't make sense */
4856 if (!survey.channel) {
4857 res = -EINVAL;
4858 goto out;
4859 }
4860
4861 chan = ieee80211_get_channel(&dev->wiphy,
4862 survey.channel->center_freq);
4863 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4864 survey_idx++;
4865 continue;
4866 }
4867
Holger Schurig61fa7132009-11-11 12:25:40 +01004868 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004869 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01004870 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4871 netdev,
4872 &survey) < 0)
4873 goto out;
4874 survey_idx++;
4875 }
4876
4877 out:
4878 cb->args[1] = survey_idx;
4879 res = skb->len;
4880 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004881 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004882 return res;
4883}
4884
Samuel Ortizb23aa672009-07-01 21:26:54 +02004885static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4886{
4887 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4888 NL80211_WPA_VERSION_2));
4889}
4890
Jouni Malinen636a5d32009-03-19 13:39:22 +02004891static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4892{
Johannes Berg4c476992010-10-04 21:36:35 +02004893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4894 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004895 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004896 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
4897 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004898 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004899 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004900 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004901
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004902 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4903 return -EINVAL;
4904
4905 if (!info->attrs[NL80211_ATTR_MAC])
4906 return -EINVAL;
4907
Jouni Malinen17780922009-03-27 20:52:47 +02004908 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4909 return -EINVAL;
4910
Johannes Berg19957bb2009-07-02 17:20:43 +02004911 if (!info->attrs[NL80211_ATTR_SSID])
4912 return -EINVAL;
4913
4914 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4915 return -EINVAL;
4916
Johannes Bergfffd0932009-07-08 14:22:54 +02004917 err = nl80211_parse_key(info, &key);
4918 if (err)
4919 return err;
4920
4921 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004922 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4923 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004924 if (!key.p.key || !key.p.key_len)
4925 return -EINVAL;
4926 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4927 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4928 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4929 key.p.key_len != WLAN_KEY_LEN_WEP104))
4930 return -EINVAL;
4931 if (key.idx > 4)
4932 return -EINVAL;
4933 } else {
4934 key.p.key_len = 0;
4935 key.p.key = NULL;
4936 }
4937
Johannes Bergafea0b72010-08-10 09:46:42 +02004938 if (key.idx >= 0) {
4939 int i;
4940 bool ok = false;
4941 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4942 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4943 ok = true;
4944 break;
4945 }
4946 }
Johannes Berg4c476992010-10-04 21:36:35 +02004947 if (!ok)
4948 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004949 }
4950
Johannes Berg4c476992010-10-04 21:36:35 +02004951 if (!rdev->ops->auth)
4952 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004953
Johannes Berg074ac8d2010-09-16 14:58:22 +02004954 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004955 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4956 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004957
Johannes Berg19957bb2009-07-02 17:20:43 +02004958 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004959 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004960 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004961 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4962 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004963
Johannes Berg19957bb2009-07-02 17:20:43 +02004964 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4965 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4966
4967 if (info->attrs[NL80211_ATTR_IE]) {
4968 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4969 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4970 }
4971
4972 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004973 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02004974 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004975
Jouni Malinene39e5b52012-09-30 19:29:39 +03004976 if (auth_type == NL80211_AUTHTYPE_SAE &&
4977 !info->attrs[NL80211_ATTR_SAE_DATA])
4978 return -EINVAL;
4979
4980 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
4981 if (auth_type != NL80211_AUTHTYPE_SAE)
4982 return -EINVAL;
4983 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
4984 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
4985 /* need to include at least Auth Transaction and Status Code */
4986 if (sae_data_len < 4)
4987 return -EINVAL;
4988 }
4989
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004990 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4991
Johannes Berg95de8172012-01-20 13:55:25 +01004992 /*
4993 * Since we no longer track auth state, ignore
4994 * requests to only change local state.
4995 */
4996 if (local_state_change)
4997 return 0;
4998
Johannes Berg4c476992010-10-04 21:36:35 +02004999 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5000 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03005001 key.p.key, key.p.key_len, key.idx,
5002 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005003}
5004
Johannes Bergc0692b82010-08-27 14:26:53 +03005005static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5006 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005007 struct cfg80211_crypto_settings *settings,
5008 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005009{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005010 memset(settings, 0, sizeof(*settings));
5011
Samuel Ortizb23aa672009-07-01 21:26:54 +02005012 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5013
Johannes Bergc0692b82010-08-27 14:26:53 +03005014 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5015 u16 proto;
5016 proto = nla_get_u16(
5017 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5018 settings->control_port_ethertype = cpu_to_be16(proto);
5019 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5020 proto != ETH_P_PAE)
5021 return -EINVAL;
5022 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5023 settings->control_port_no_encrypt = true;
5024 } else
5025 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5026
Samuel Ortizb23aa672009-07-01 21:26:54 +02005027 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5028 void *data;
5029 int len, i;
5030
5031 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5032 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5033 settings->n_ciphers_pairwise = len / sizeof(u32);
5034
5035 if (len % sizeof(u32))
5036 return -EINVAL;
5037
Johannes Berg3dc27d22009-07-02 21:36:37 +02005038 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005039 return -EINVAL;
5040
5041 memcpy(settings->ciphers_pairwise, data, len);
5042
5043 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005044 if (!cfg80211_supported_cipher_suite(
5045 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005046 settings->ciphers_pairwise[i]))
5047 return -EINVAL;
5048 }
5049
5050 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5051 settings->cipher_group =
5052 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005053 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5054 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005055 return -EINVAL;
5056 }
5057
5058 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5059 settings->wpa_versions =
5060 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5061 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5062 return -EINVAL;
5063 }
5064
5065 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5066 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005067 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005068
5069 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5070 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5071 settings->n_akm_suites = len / sizeof(u32);
5072
5073 if (len % sizeof(u32))
5074 return -EINVAL;
5075
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005076 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5077 return -EINVAL;
5078
Samuel Ortizb23aa672009-07-01 21:26:54 +02005079 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005080 }
5081
5082 return 0;
5083}
5084
Jouni Malinen636a5d32009-03-19 13:39:22 +02005085static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5086{
Johannes Berg4c476992010-10-04 21:36:35 +02005087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5088 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005089 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005090 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005091 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005092 int err, ssid_len, ie_len = 0;
5093 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005094 u32 flags = 0;
5095 struct ieee80211_ht_cap *ht_capa = NULL;
5096 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005097
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005098 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5099 return -EINVAL;
5100
5101 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005102 !info->attrs[NL80211_ATTR_SSID] ||
5103 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005104 return -EINVAL;
5105
Johannes Berg4c476992010-10-04 21:36:35 +02005106 if (!rdev->ops->assoc)
5107 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005108
Johannes Berg074ac8d2010-09-16 14:58:22 +02005109 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005110 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5111 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005112
Johannes Berg19957bb2009-07-02 17:20:43 +02005113 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005114
Johannes Berg19957bb2009-07-02 17:20:43 +02005115 chan = ieee80211_get_channel(&rdev->wiphy,
5116 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005117 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5118 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005119
Johannes Berg19957bb2009-07-02 17:20:43 +02005120 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5121 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005122
5123 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005124 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5125 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005126 }
5127
Jouni Malinendc6382ce2009-05-06 22:09:37 +03005128 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005129 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03005130 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005131 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02005132 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02005133 else if (mfp != NL80211_MFP_NO)
5134 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03005135 }
5136
Johannes Berg3e5d7642009-07-07 14:37:26 +02005137 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5138 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5139
Ben Greear7e7c8922011-11-18 11:31:59 -08005140 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5141 flags |= ASSOC_REQ_DISABLE_HT;
5142
5143 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5144 ht_capa_mask =
5145 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5146
5147 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5148 if (!ht_capa_mask)
5149 return -EINVAL;
5150 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5151 }
5152
Johannes Bergc0692b82010-08-27 14:26:53 +03005153 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005154 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02005155 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5156 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08005157 &crypto, flags, ht_capa,
5158 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005159
Jouni Malinen636a5d32009-03-19 13:39:22 +02005160 return err;
5161}
5162
5163static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5164{
Johannes Berg4c476992010-10-04 21:36:35 +02005165 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5166 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005167 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005168 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005169 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005170 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005171
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005172 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5173 return -EINVAL;
5174
5175 if (!info->attrs[NL80211_ATTR_MAC])
5176 return -EINVAL;
5177
5178 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5179 return -EINVAL;
5180
Johannes Berg4c476992010-10-04 21:36:35 +02005181 if (!rdev->ops->deauth)
5182 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005183
Johannes Berg074ac8d2010-09-16 14:58:22 +02005184 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005185 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5186 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005187
Johannes Berg19957bb2009-07-02 17:20:43 +02005188 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005189
Johannes Berg19957bb2009-07-02 17:20:43 +02005190 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5191 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005192 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005193 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005194 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005195
5196 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005197 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5198 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005199 }
5200
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005201 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5202
Johannes Berg4c476992010-10-04 21:36:35 +02005203 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5204 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005205}
5206
5207static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5208{
Johannes Berg4c476992010-10-04 21:36:35 +02005209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5210 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005211 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005212 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005213 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005214 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005215
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005216 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5217 return -EINVAL;
5218
5219 if (!info->attrs[NL80211_ATTR_MAC])
5220 return -EINVAL;
5221
5222 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5223 return -EINVAL;
5224
Johannes Berg4c476992010-10-04 21:36:35 +02005225 if (!rdev->ops->disassoc)
5226 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005227
Johannes Berg074ac8d2010-09-16 14:58:22 +02005228 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005229 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5230 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005231
Johannes Berg19957bb2009-07-02 17:20:43 +02005232 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005233
Johannes Berg19957bb2009-07-02 17:20:43 +02005234 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5235 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005236 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005237 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005238 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005239
5240 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005241 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5242 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005243 }
5244
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005245 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5246
Johannes Berg4c476992010-10-04 21:36:35 +02005247 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5248 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005249}
5250
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005251static bool
5252nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5253 int mcast_rate[IEEE80211_NUM_BANDS],
5254 int rateval)
5255{
5256 struct wiphy *wiphy = &rdev->wiphy;
5257 bool found = false;
5258 int band, i;
5259
5260 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5261 struct ieee80211_supported_band *sband;
5262
5263 sband = wiphy->bands[band];
5264 if (!sband)
5265 continue;
5266
5267 for (i = 0; i < sband->n_bitrates; i++) {
5268 if (sband->bitrates[i].bitrate == rateval) {
5269 mcast_rate[band] = i + 1;
5270 found = true;
5271 break;
5272 }
5273 }
5274 }
5275
5276 return found;
5277}
5278
Johannes Berg04a773a2009-04-19 21:24:32 +02005279static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5280{
Johannes Berg4c476992010-10-04 21:36:35 +02005281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5282 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005283 struct cfg80211_ibss_params ibss;
5284 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005285 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005286 int err;
5287
Johannes Berg8e30bc52009-04-22 17:45:38 +02005288 memset(&ibss, 0, sizeof(ibss));
5289
Johannes Berg04a773a2009-04-19 21:24:32 +02005290 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5291 return -EINVAL;
5292
5293 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5294 !info->attrs[NL80211_ATTR_SSID] ||
5295 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5296 return -EINVAL;
5297
Johannes Berg8e30bc52009-04-22 17:45:38 +02005298 ibss.beacon_interval = 100;
5299
5300 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5301 ibss.beacon_interval =
5302 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5303 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5304 return -EINVAL;
5305 }
5306
Johannes Berg4c476992010-10-04 21:36:35 +02005307 if (!rdev->ops->join_ibss)
5308 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005309
Johannes Berg4c476992010-10-04 21:36:35 +02005310 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5311 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005312
Johannes Berg79c97e92009-07-07 03:56:12 +02005313 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005314
Johannes Berg39193492011-09-16 13:45:25 +02005315 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005316 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005317
5318 if (!is_valid_ether_addr(ibss.bssid))
5319 return -EINVAL;
5320 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005321 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5322 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5323
5324 if (info->attrs[NL80211_ATTR_IE]) {
5325 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5326 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5327 }
5328
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005329 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5330 enum nl80211_channel_type channel_type;
5331
Johannes Bergcd6c6592012-05-10 21:27:18 +02005332 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005333 return -EINVAL;
5334
5335 if (channel_type != NL80211_CHAN_NO_HT &&
5336 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5337 return -EINVAL;
5338
5339 ibss.channel_type = channel_type;
5340 } else {
5341 ibss.channel_type = NL80211_CHAN_NO_HT;
5342 }
5343
5344 ibss.channel = rdev_freq_to_chan(rdev,
5345 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5346 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005347 if (!ibss.channel ||
5348 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005349 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5350 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005351
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005352 /* Both channels should be able to initiate communication */
5353 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5354 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5355 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5356 ibss.channel_type))
5357 return -EINVAL;
5358
Johannes Berg04a773a2009-04-19 21:24:32 +02005359 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005360 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005361
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005362 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5363 u8 *rates =
5364 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5365 int n_rates =
5366 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5367 struct ieee80211_supported_band *sband =
5368 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005369
Johannes Berg34850ab2011-07-18 18:08:35 +02005370 err = ieee80211_get_ratemask(sband, rates, n_rates,
5371 &ibss.basic_rates);
5372 if (err)
5373 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005374 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005375
5376 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5377 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5378 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5379 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005380
Johannes Berg4c476992010-10-04 21:36:35 +02005381 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5382 connkeys = nl80211_parse_connkeys(rdev,
5383 info->attrs[NL80211_ATTR_KEYS]);
5384 if (IS_ERR(connkeys))
5385 return PTR_ERR(connkeys);
5386 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005387
Antonio Quartulli267335d2012-01-31 20:25:47 +01005388 ibss.control_port =
5389 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5390
Johannes Berg4c476992010-10-04 21:36:35 +02005391 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005392 if (err)
5393 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005394 return err;
5395}
5396
5397static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5398{
Johannes Berg4c476992010-10-04 21:36:35 +02005399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5400 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005401
Johannes Berg4c476992010-10-04 21:36:35 +02005402 if (!rdev->ops->leave_ibss)
5403 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005404
Johannes Berg4c476992010-10-04 21:36:35 +02005405 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5406 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005407
Johannes Berg4c476992010-10-04 21:36:35 +02005408 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005409}
5410
Johannes Bergaff89a92009-07-01 21:26:51 +02005411#ifdef CONFIG_NL80211_TESTMODE
5412static struct genl_multicast_group nl80211_testmode_mcgrp = {
5413 .name = "testmode",
5414};
5415
5416static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5417{
Johannes Berg4c476992010-10-04 21:36:35 +02005418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005419 int err;
5420
5421 if (!info->attrs[NL80211_ATTR_TESTDATA])
5422 return -EINVAL;
5423
Johannes Bergaff89a92009-07-01 21:26:51 +02005424 err = -EOPNOTSUPP;
5425 if (rdev->ops->testmode_cmd) {
5426 rdev->testmode_info = info;
5427 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5428 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5429 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5430 rdev->testmode_info = NULL;
5431 }
5432
Johannes Bergaff89a92009-07-01 21:26:51 +02005433 return err;
5434}
5435
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005436static int nl80211_testmode_dump(struct sk_buff *skb,
5437 struct netlink_callback *cb)
5438{
Johannes Berg00918d32011-12-13 17:22:05 +01005439 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005440 int err;
5441 long phy_idx;
5442 void *data = NULL;
5443 int data_len = 0;
5444
5445 if (cb->args[0]) {
5446 /*
5447 * 0 is a valid index, but not valid for args[0],
5448 * so we need to offset by 1.
5449 */
5450 phy_idx = cb->args[0] - 1;
5451 } else {
5452 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5453 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5454 nl80211_policy);
5455 if (err)
5456 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005457
Johannes Berg2bd7e352012-06-15 14:23:16 +02005458 mutex_lock(&cfg80211_mutex);
5459 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5460 nl80211_fam.attrbuf);
5461 if (IS_ERR(rdev)) {
5462 mutex_unlock(&cfg80211_mutex);
5463 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005464 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005465 phy_idx = rdev->wiphy_idx;
5466 rdev = NULL;
5467 mutex_unlock(&cfg80211_mutex);
5468
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005469 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5470 cb->args[1] =
5471 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5472 }
5473
5474 if (cb->args[1]) {
5475 data = nla_data((void *)cb->args[1]);
5476 data_len = nla_len((void *)cb->args[1]);
5477 }
5478
5479 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005480 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5481 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005482 mutex_unlock(&cfg80211_mutex);
5483 return -ENOENT;
5484 }
Johannes Berg00918d32011-12-13 17:22:05 +01005485 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005486 mutex_unlock(&cfg80211_mutex);
5487
Johannes Berg00918d32011-12-13 17:22:05 +01005488 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005489 err = -EOPNOTSUPP;
5490 goto out_err;
5491 }
5492
5493 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00005494 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005495 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5496 NL80211_CMD_TESTMODE);
5497 struct nlattr *tmdata;
5498
David S. Miller9360ffd2012-03-29 04:41:26 -04005499 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005500 genlmsg_cancel(skb, hdr);
5501 break;
5502 }
5503
5504 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5505 if (!tmdata) {
5506 genlmsg_cancel(skb, hdr);
5507 break;
5508 }
Johannes Berg00918d32011-12-13 17:22:05 +01005509 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5510 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005511 nla_nest_end(skb, tmdata);
5512
5513 if (err == -ENOBUFS || err == -ENOENT) {
5514 genlmsg_cancel(skb, hdr);
5515 break;
5516 } else if (err) {
5517 genlmsg_cancel(skb, hdr);
5518 goto out_err;
5519 }
5520
5521 genlmsg_end(skb, hdr);
5522 }
5523
5524 err = skb->len;
5525 /* see above */
5526 cb->args[0] = phy_idx + 1;
5527 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005528 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005529 return err;
5530}
5531
Johannes Bergaff89a92009-07-01 21:26:51 +02005532static struct sk_buff *
5533__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005534 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02005535{
5536 struct sk_buff *skb;
5537 void *hdr;
5538 struct nlattr *data;
5539
5540 skb = nlmsg_new(approxlen + 100, gfp);
5541 if (!skb)
5542 return NULL;
5543
Eric W. Biederman15e47302012-09-07 20:12:54 +00005544 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02005545 if (!hdr) {
5546 kfree_skb(skb);
5547 return NULL;
5548 }
5549
David S. Miller9360ffd2012-03-29 04:41:26 -04005550 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5551 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005552 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5553
5554 ((void **)skb->cb)[0] = rdev;
5555 ((void **)skb->cb)[1] = hdr;
5556 ((void **)skb->cb)[2] = data;
5557
5558 return skb;
5559
5560 nla_put_failure:
5561 kfree_skb(skb);
5562 return NULL;
5563}
5564
5565struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5566 int approxlen)
5567{
5568 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5569
5570 if (WARN_ON(!rdev->testmode_info))
5571 return NULL;
5572
5573 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005574 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02005575 rdev->testmode_info->snd_seq,
5576 GFP_KERNEL);
5577}
5578EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5579
5580int cfg80211_testmode_reply(struct sk_buff *skb)
5581{
5582 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5583 void *hdr = ((void **)skb->cb)[1];
5584 struct nlattr *data = ((void **)skb->cb)[2];
5585
5586 if (WARN_ON(!rdev->testmode_info)) {
5587 kfree_skb(skb);
5588 return -EINVAL;
5589 }
5590
5591 nla_nest_end(skb, data);
5592 genlmsg_end(skb, hdr);
5593 return genlmsg_reply(skb, rdev->testmode_info);
5594}
5595EXPORT_SYMBOL(cfg80211_testmode_reply);
5596
5597struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5598 int approxlen, gfp_t gfp)
5599{
5600 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5601
5602 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5603}
5604EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5605
5606void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5607{
5608 void *hdr = ((void **)skb->cb)[1];
5609 struct nlattr *data = ((void **)skb->cb)[2];
5610
5611 nla_nest_end(skb, data);
5612 genlmsg_end(skb, hdr);
5613 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5614}
5615EXPORT_SYMBOL(cfg80211_testmode_event);
5616#endif
5617
Samuel Ortizb23aa672009-07-01 21:26:54 +02005618static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5619{
Johannes Berg4c476992010-10-04 21:36:35 +02005620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5621 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005622 struct cfg80211_connect_params connect;
5623 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005624 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005625 int err;
5626
5627 memset(&connect, 0, sizeof(connect));
5628
5629 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5630 return -EINVAL;
5631
5632 if (!info->attrs[NL80211_ATTR_SSID] ||
5633 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5634 return -EINVAL;
5635
5636 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5637 connect.auth_type =
5638 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005639 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
5640 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005641 return -EINVAL;
5642 } else
5643 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5644
5645 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5646
Johannes Bergc0692b82010-08-27 14:26:53 +03005647 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005648 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005649 if (err)
5650 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005651
Johannes Berg074ac8d2010-09-16 14:58:22 +02005652 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005653 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5654 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005655
Johannes Berg79c97e92009-07-07 03:56:12 +02005656 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005657
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305658 connect.bg_scan_period = -1;
5659 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5660 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5661 connect.bg_scan_period =
5662 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5663 }
5664
Samuel Ortizb23aa672009-07-01 21:26:54 +02005665 if (info->attrs[NL80211_ATTR_MAC])
5666 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5667 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5668 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5669
5670 if (info->attrs[NL80211_ATTR_IE]) {
5671 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5672 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5673 }
5674
5675 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5676 connect.channel =
5677 ieee80211_get_channel(wiphy,
5678 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5679 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005680 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5681 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005682 }
5683
Johannes Bergfffd0932009-07-08 14:22:54 +02005684 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5685 connkeys = nl80211_parse_connkeys(rdev,
5686 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005687 if (IS_ERR(connkeys))
5688 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005689 }
5690
Ben Greear7e7c8922011-11-18 11:31:59 -08005691 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5692 connect.flags |= ASSOC_REQ_DISABLE_HT;
5693
5694 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5695 memcpy(&connect.ht_capa_mask,
5696 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5697 sizeof(connect.ht_capa_mask));
5698
5699 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005700 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
5701 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08005702 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005703 }
Ben Greear7e7c8922011-11-18 11:31:59 -08005704 memcpy(&connect.ht_capa,
5705 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5706 sizeof(connect.ht_capa));
5707 }
5708
Johannes Bergfffd0932009-07-08 14:22:54 +02005709 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005710 if (err)
5711 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005712 return err;
5713}
5714
5715static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5716{
Johannes Berg4c476992010-10-04 21:36:35 +02005717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5718 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005719 u16 reason;
5720
5721 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5722 reason = WLAN_REASON_DEAUTH_LEAVING;
5723 else
5724 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5725
5726 if (reason == 0)
5727 return -EINVAL;
5728
Johannes Berg074ac8d2010-09-16 14:58:22 +02005729 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005730 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5731 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005732
Johannes Berg4c476992010-10-04 21:36:35 +02005733 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005734}
5735
Johannes Berg463d0182009-07-14 00:33:35 +02005736static int nl80211_wiphy_netns(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];
Johannes Berg463d0182009-07-14 00:33:35 +02005739 struct net *net;
5740 int err;
5741 u32 pid;
5742
5743 if (!info->attrs[NL80211_ATTR_PID])
5744 return -EINVAL;
5745
5746 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5747
Johannes Berg463d0182009-07-14 00:33:35 +02005748 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005749 if (IS_ERR(net))
5750 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005751
5752 err = 0;
5753
5754 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005755 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5756 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005757
Johannes Berg463d0182009-07-14 00:33:35 +02005758 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005759 return err;
5760}
5761
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005762static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5763{
Johannes Berg4c476992010-10-04 21:36:35 +02005764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005765 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5766 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005767 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005768 struct cfg80211_pmksa pmksa;
5769
5770 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5771
5772 if (!info->attrs[NL80211_ATTR_MAC])
5773 return -EINVAL;
5774
5775 if (!info->attrs[NL80211_ATTR_PMKID])
5776 return -EINVAL;
5777
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005778 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5779 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5780
Johannes Berg074ac8d2010-09-16 14:58:22 +02005781 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005782 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5783 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005784
5785 switch (info->genlhdr->cmd) {
5786 case NL80211_CMD_SET_PMKSA:
5787 rdev_ops = rdev->ops->set_pmksa;
5788 break;
5789 case NL80211_CMD_DEL_PMKSA:
5790 rdev_ops = rdev->ops->del_pmksa;
5791 break;
5792 default:
5793 WARN_ON(1);
5794 break;
5795 }
5796
Johannes Berg4c476992010-10-04 21:36:35 +02005797 if (!rdev_ops)
5798 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005799
Johannes Berg4c476992010-10-04 21:36:35 +02005800 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005801}
5802
5803static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5804{
Johannes Berg4c476992010-10-04 21:36:35 +02005805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5806 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005807
Johannes Berg074ac8d2010-09-16 14:58:22 +02005808 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005809 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5810 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005811
Johannes Berg4c476992010-10-04 21:36:35 +02005812 if (!rdev->ops->flush_pmksa)
5813 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005814
Johannes Berg4c476992010-10-04 21:36:35 +02005815 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005816}
5817
Arik Nemtsov109086c2011-09-28 14:12:50 +03005818static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5819{
5820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5821 struct net_device *dev = info->user_ptr[1];
5822 u8 action_code, dialog_token;
5823 u16 status_code;
5824 u8 *peer;
5825
5826 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5827 !rdev->ops->tdls_mgmt)
5828 return -EOPNOTSUPP;
5829
5830 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5831 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5832 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5833 !info->attrs[NL80211_ATTR_IE] ||
5834 !info->attrs[NL80211_ATTR_MAC])
5835 return -EINVAL;
5836
5837 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5838 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5839 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5840 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5841
5842 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5843 dialog_token, status_code,
5844 nla_data(info->attrs[NL80211_ATTR_IE]),
5845 nla_len(info->attrs[NL80211_ATTR_IE]));
5846}
5847
5848static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5849{
5850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5851 struct net_device *dev = info->user_ptr[1];
5852 enum nl80211_tdls_operation operation;
5853 u8 *peer;
5854
5855 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5856 !rdev->ops->tdls_oper)
5857 return -EOPNOTSUPP;
5858
5859 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5860 !info->attrs[NL80211_ATTR_MAC])
5861 return -EINVAL;
5862
5863 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5864 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5865
5866 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5867}
5868
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005869static int nl80211_remain_on_channel(struct sk_buff *skb,
5870 struct genl_info *info)
5871{
Johannes Berg4c476992010-10-04 21:36:35 +02005872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005873 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005874 struct ieee80211_channel *chan;
5875 struct sk_buff *msg;
5876 void *hdr;
5877 u64 cookie;
5878 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5879 u32 freq, duration;
5880 int err;
5881
5882 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5883 !info->attrs[NL80211_ATTR_DURATION])
5884 return -EINVAL;
5885
5886 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5887
Johannes Berg7c4ef712011-11-18 15:33:48 +01005888 if (!rdev->ops->remain_on_channel ||
5889 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005890 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005891
Johannes Bergebf348f2012-06-01 12:50:54 +02005892 /*
5893 * We should be on that channel for at least a minimum amount of
5894 * time (10ms) but no longer than the driver supports.
5895 */
5896 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5897 duration > rdev->wiphy.max_remain_on_channel_duration)
5898 return -EINVAL;
5899
Johannes Bergcd6c6592012-05-10 21:27:18 +02005900 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5901 !nl80211_valid_channel_type(info, &channel_type))
5902 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005903
5904 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5905 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005906 if (chan == NULL)
5907 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005908
5909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005910 if (!msg)
5911 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005912
Eric W. Biederman15e47302012-09-07 20:12:54 +00005913 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005914 NL80211_CMD_REMAIN_ON_CHANNEL);
5915
5916 if (IS_ERR(hdr)) {
5917 err = PTR_ERR(hdr);
5918 goto free_msg;
5919 }
5920
Johannes Berg71bbc992012-06-15 15:30:18 +02005921 err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005922 channel_type, duration, &cookie);
5923
5924 if (err)
5925 goto free_msg;
5926
David S. Miller9360ffd2012-03-29 04:41:26 -04005927 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5928 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005929
5930 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005931
5932 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005933
5934 nla_put_failure:
5935 err = -ENOBUFS;
5936 free_msg:
5937 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005938 return err;
5939}
5940
5941static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5942 struct genl_info *info)
5943{
Johannes Berg4c476992010-10-04 21:36:35 +02005944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005945 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005946 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005947
5948 if (!info->attrs[NL80211_ATTR_COOKIE])
5949 return -EINVAL;
5950
Johannes Berg4c476992010-10-04 21:36:35 +02005951 if (!rdev->ops->cancel_remain_on_channel)
5952 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005953
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005954 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5955
Johannes Berg71bbc992012-06-15 15:30:18 +02005956 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005957}
5958
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005959static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5960 u8 *rates, u8 rates_len)
5961{
5962 u8 i;
5963 u32 mask = 0;
5964
5965 for (i = 0; i < rates_len; i++) {
5966 int rate = (rates[i] & 0x7f) * 5;
5967 int ridx;
5968 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5969 struct ieee80211_rate *srate =
5970 &sband->bitrates[ridx];
5971 if (rate == srate->bitrate) {
5972 mask |= 1 << ridx;
5973 break;
5974 }
5975 }
5976 if (ridx == sband->n_bitrates)
5977 return 0; /* rate not found */
5978 }
5979
5980 return mask;
5981}
5982
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005983static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5984 u8 *rates, u8 rates_len,
5985 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5986{
5987 u8 i;
5988
5989 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5990
5991 for (i = 0; i < rates_len; i++) {
5992 int ridx, rbit;
5993
5994 ridx = rates[i] / 8;
5995 rbit = BIT(rates[i] % 8);
5996
5997 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005998 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005999 return false;
6000
6001 /* check availability */
6002 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6003 mcs[ridx] |= rbit;
6004 else
6005 return false;
6006 }
6007
6008 return true;
6009}
6010
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006011static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006012 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6013 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006014 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6015 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006016};
6017
6018static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6019 struct genl_info *info)
6020{
6021 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006023 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006024 int rem, i;
6025 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006026 struct nlattr *tx_rates;
6027 struct ieee80211_supported_band *sband;
6028
6029 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6030 return -EINVAL;
6031
Johannes Berg4c476992010-10-04 21:36:35 +02006032 if (!rdev->ops->set_bitrate_mask)
6033 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006034
6035 memset(&mask, 0, sizeof(mask));
6036 /* Default to all rates enabled */
6037 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6038 sband = rdev->wiphy.bands[i];
6039 mask.control[i].legacy =
6040 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006041 if (sband)
6042 memcpy(mask.control[i].mcs,
6043 sband->ht_cap.mcs.rx_mask,
6044 sizeof(mask.control[i].mcs));
6045 else
6046 memset(mask.control[i].mcs, 0,
6047 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006048 }
6049
6050 /*
6051 * The nested attribute uses enum nl80211_band as the index. This maps
6052 * directly to the enum ieee80211_band values used in cfg80211.
6053 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006054 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006055 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6056 {
6057 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006058 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6059 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006060 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006061 if (sband == NULL)
6062 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006063 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6064 nla_len(tx_rates), nl80211_txattr_policy);
6065 if (tb[NL80211_TXRATE_LEGACY]) {
6066 mask.control[band].legacy = rateset_to_mask(
6067 sband,
6068 nla_data(tb[NL80211_TXRATE_LEGACY]),
6069 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306070 if ((mask.control[band].legacy == 0) &&
6071 nla_len(tb[NL80211_TXRATE_LEGACY]))
6072 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006073 }
6074 if (tb[NL80211_TXRATE_MCS]) {
6075 if (!ht_rateset_to_mask(
6076 sband,
6077 nla_data(tb[NL80211_TXRATE_MCS]),
6078 nla_len(tb[NL80211_TXRATE_MCS]),
6079 mask.control[band].mcs))
6080 return -EINVAL;
6081 }
6082
6083 if (mask.control[band].legacy == 0) {
6084 /* don't allow empty legacy rates if HT
6085 * is not even supported. */
6086 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6087 return -EINVAL;
6088
6089 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6090 if (mask.control[band].mcs[i])
6091 break;
6092
6093 /* legacy and mcs rates may not be both empty */
6094 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02006095 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006096 }
6097 }
6098
Johannes Berg4c476992010-10-04 21:36:35 +02006099 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006100}
6101
Johannes Berg2e161f72010-08-12 15:38:38 +02006102static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006103{
Johannes Berg4c476992010-10-04 21:36:35 +02006104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006105 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02006106 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02006107
6108 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6109 return -EINVAL;
6110
Johannes Berg2e161f72010-08-12 15:38:38 +02006111 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6112 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02006113
Johannes Berg71bbc992012-06-15 15:30:18 +02006114 switch (wdev->iftype) {
6115 case NL80211_IFTYPE_STATION:
6116 case NL80211_IFTYPE_ADHOC:
6117 case NL80211_IFTYPE_P2P_CLIENT:
6118 case NL80211_IFTYPE_AP:
6119 case NL80211_IFTYPE_AP_VLAN:
6120 case NL80211_IFTYPE_MESH_POINT:
6121 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006122 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006123 break;
6124 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006125 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006126 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006127
6128 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02006129 if (!rdev->ops->mgmt_tx)
6130 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006131
Eric W. Biederman15e47302012-09-07 20:12:54 +00006132 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02006133 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6134 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02006135}
6136
Johannes Berg2e161f72010-08-12 15:38:38 +02006137static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006138{
Johannes Berg4c476992010-10-04 21:36:35 +02006139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006140 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02006141 struct ieee80211_channel *chan;
6142 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02006143 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02006144 u32 freq;
6145 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01006146 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006147 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01006148 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006149 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01006150 bool offchan, no_cck, dont_wait_for_ack;
6151
6152 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02006153
6154 if (!info->attrs[NL80211_ATTR_FRAME] ||
6155 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6156 return -EINVAL;
6157
Johannes Berg4c476992010-10-04 21:36:35 +02006158 if (!rdev->ops->mgmt_tx)
6159 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006160
Johannes Berg71bbc992012-06-15 15:30:18 +02006161 switch (wdev->iftype) {
6162 case NL80211_IFTYPE_STATION:
6163 case NL80211_IFTYPE_ADHOC:
6164 case NL80211_IFTYPE_P2P_CLIENT:
6165 case NL80211_IFTYPE_AP:
6166 case NL80211_IFTYPE_AP_VLAN:
6167 case NL80211_IFTYPE_MESH_POINT:
6168 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006169 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006170 break;
6171 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006172 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006173 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006174
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006175 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01006176 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006177 return -EINVAL;
6178 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02006179
6180 /*
6181 * We should wait on the channel for at least a minimum amount
6182 * of time (10ms) but no longer than the driver supports.
6183 */
6184 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6185 wait > rdev->wiphy.max_remain_on_channel_duration)
6186 return -EINVAL;
6187
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006188 }
6189
Jouni Malinen026331c2010-02-15 12:53:10 +02006190 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02006191 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02006192 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02006193 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02006194 }
6195
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006196 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6197
Johannes Berg7c4ef712011-11-18 15:33:48 +01006198 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6199 return -EINVAL;
6200
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306201 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6202
Jouni Malinen026331c2010-02-15 12:53:10 +02006203 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6204 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006205 if (chan == NULL)
6206 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006207
Johannes Berge247bd902011-11-04 11:18:21 +01006208 if (!dont_wait_for_ack) {
6209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6210 if (!msg)
6211 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006212
Eric W. Biederman15e47302012-09-07 20:12:54 +00006213 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01006214 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006215
Johannes Berge247bd902011-11-04 11:18:21 +01006216 if (IS_ERR(hdr)) {
6217 err = PTR_ERR(hdr);
6218 goto free_msg;
6219 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006220 }
Johannes Berge247bd902011-11-04 11:18:21 +01006221
Johannes Berg71bbc992012-06-15 15:30:18 +02006222 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006223 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006224 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6225 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006226 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006227 if (err)
6228 goto free_msg;
6229
Johannes Berge247bd902011-11-04 11:18:21 +01006230 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006231 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6232 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006233
Johannes Berge247bd902011-11-04 11:18:21 +01006234 genlmsg_end(msg, hdr);
6235 return genlmsg_reply(msg, info);
6236 }
6237
6238 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006239
6240 nla_put_failure:
6241 err = -ENOBUFS;
6242 free_msg:
6243 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006244 return err;
6245}
6246
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006247static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6248{
6249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006250 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006251 u64 cookie;
6252
6253 if (!info->attrs[NL80211_ATTR_COOKIE])
6254 return -EINVAL;
6255
6256 if (!rdev->ops->mgmt_tx_cancel_wait)
6257 return -EOPNOTSUPP;
6258
Johannes Berg71bbc992012-06-15 15:30:18 +02006259 switch (wdev->iftype) {
6260 case NL80211_IFTYPE_STATION:
6261 case NL80211_IFTYPE_ADHOC:
6262 case NL80211_IFTYPE_P2P_CLIENT:
6263 case NL80211_IFTYPE_AP:
6264 case NL80211_IFTYPE_AP_VLAN:
6265 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006266 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006267 break;
6268 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006269 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006270 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006271
6272 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6273
Johannes Berg71bbc992012-06-15 15:30:18 +02006274 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006275}
6276
Kalle Valoffb9eb32010-02-17 17:58:10 +02006277static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6278{
Johannes Berg4c476992010-10-04 21:36:35 +02006279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006280 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006281 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006282 u8 ps_state;
6283 bool state;
6284 int err;
6285
Johannes Berg4c476992010-10-04 21:36:35 +02006286 if (!info->attrs[NL80211_ATTR_PS_STATE])
6287 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006288
6289 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6290
Johannes Berg4c476992010-10-04 21:36:35 +02006291 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6292 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006293
6294 wdev = dev->ieee80211_ptr;
6295
Johannes Berg4c476992010-10-04 21:36:35 +02006296 if (!rdev->ops->set_power_mgmt)
6297 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006298
6299 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6300
6301 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006302 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006303
Johannes Berg4c476992010-10-04 21:36:35 +02006304 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6305 wdev->ps_timeout);
6306 if (!err)
6307 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006308 return err;
6309}
6310
6311static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6312{
Johannes Berg4c476992010-10-04 21:36:35 +02006313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006314 enum nl80211_ps_state ps_state;
6315 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006316 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006317 struct sk_buff *msg;
6318 void *hdr;
6319 int err;
6320
Kalle Valoffb9eb32010-02-17 17:58:10 +02006321 wdev = dev->ieee80211_ptr;
6322
Johannes Berg4c476992010-10-04 21:36:35 +02006323 if (!rdev->ops->set_power_mgmt)
6324 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006325
6326 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006327 if (!msg)
6328 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006329
Eric W. Biederman15e47302012-09-07 20:12:54 +00006330 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006331 NL80211_CMD_GET_POWER_SAVE);
6332 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006333 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006334 goto free_msg;
6335 }
6336
6337 if (wdev->ps)
6338 ps_state = NL80211_PS_ENABLED;
6339 else
6340 ps_state = NL80211_PS_DISABLED;
6341
David S. Miller9360ffd2012-03-29 04:41:26 -04006342 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6343 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006344
6345 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006346 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006347
Johannes Berg4c476992010-10-04 21:36:35 +02006348 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006349 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006350 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006351 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006352 return err;
6353}
6354
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006355static struct nla_policy
6356nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6357 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6358 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6359 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07006360 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6361 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6362 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006363};
6364
Thomas Pedersen84f10702012-07-12 16:17:33 -07006365static int nl80211_set_cqm_txe(struct genl_info *info,
6366 u32 rate, u32 pkts, u32 intvl)
6367{
6368 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6369 struct wireless_dev *wdev;
6370 struct net_device *dev = info->user_ptr[1];
6371
6372 if ((rate < 0 || rate > 100) ||
6373 (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL))
6374 return -EINVAL;
6375
6376 wdev = dev->ieee80211_ptr;
6377
6378 if (!rdev->ops->set_cqm_txe_config)
6379 return -EOPNOTSUPP;
6380
6381 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6382 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6383 return -EOPNOTSUPP;
6384
6385 return rdev->ops->set_cqm_txe_config(wdev->wiphy, dev,
6386 rate, pkts, intvl);
6387}
6388
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006389static int nl80211_set_cqm_rssi(struct genl_info *info,
6390 s32 threshold, u32 hysteresis)
6391{
Johannes Berg4c476992010-10-04 21:36:35 +02006392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006393 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006394 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006395
6396 if (threshold > 0)
6397 return -EINVAL;
6398
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006399 wdev = dev->ieee80211_ptr;
6400
Johannes Berg4c476992010-10-04 21:36:35 +02006401 if (!rdev->ops->set_cqm_rssi_config)
6402 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006403
Johannes Berg074ac8d2010-09-16 14:58:22 +02006404 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006405 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6406 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006407
Johannes Berg4c476992010-10-04 21:36:35 +02006408 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6409 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006410}
6411
6412static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6413{
6414 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6415 struct nlattr *cqm;
6416 int err;
6417
6418 cqm = info->attrs[NL80211_ATTR_CQM];
6419 if (!cqm) {
6420 err = -EINVAL;
6421 goto out;
6422 }
6423
6424 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6425 nl80211_attr_cqm_policy);
6426 if (err)
6427 goto out;
6428
6429 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6430 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6431 s32 threshold;
6432 u32 hysteresis;
6433 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6434 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6435 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07006436 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
6437 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
6438 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
6439 u32 rate, pkts, intvl;
6440 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
6441 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
6442 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6443 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006444 } else
6445 err = -EINVAL;
6446
6447out:
6448 return err;
6449}
6450
Johannes Berg29cbe682010-12-03 09:20:44 +01006451static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6452{
6453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6454 struct net_device *dev = info->user_ptr[1];
6455 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006456 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006457 int err;
6458
6459 /* start with default */
6460 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006461 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006462
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006463 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006464 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006465 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006466 if (err)
6467 return err;
6468 }
6469
6470 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6471 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6472 return -EINVAL;
6473
Javier Cardonac80d5452010-12-16 17:37:49 -08006474 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6475 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6476
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006477 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6478 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6479 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6480 return -EINVAL;
6481
Javier Cardonac80d5452010-12-16 17:37:49 -08006482 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6483 /* parse additional setup parameters if given */
6484 err = nl80211_parse_mesh_setup(info, &setup);
6485 if (err)
6486 return err;
6487 }
6488
Johannes Bergcc1d2802012-05-16 23:50:20 +02006489 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6490 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6491
6492 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6493 !nl80211_valid_channel_type(info, &channel_type))
6494 return -EINVAL;
6495
6496 setup.channel = rdev_freq_to_chan(rdev,
6497 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6498 channel_type);
6499 if (!setup.channel)
6500 return -EINVAL;
6501 setup.channel_type = channel_type;
6502 } else {
6503 /* cfg80211_join_mesh() will sort it out */
6504 setup.channel = NULL;
6505 }
6506
Javier Cardonac80d5452010-12-16 17:37:49 -08006507 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006508}
6509
6510static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6511{
6512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6513 struct net_device *dev = info->user_ptr[1];
6514
6515 return cfg80211_leave_mesh(rdev, dev);
6516}
6517
Johannes Bergdfb89c52012-06-27 09:23:48 +02006518#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006519static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6520{
6521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6522 struct sk_buff *msg;
6523 void *hdr;
6524
6525 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6526 return -EOPNOTSUPP;
6527
6528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6529 if (!msg)
6530 return -ENOMEM;
6531
Eric W. Biederman15e47302012-09-07 20:12:54 +00006532 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02006533 NL80211_CMD_GET_WOWLAN);
6534 if (!hdr)
6535 goto nla_put_failure;
6536
6537 if (rdev->wowlan) {
6538 struct nlattr *nl_wowlan;
6539
6540 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6541 if (!nl_wowlan)
6542 goto nla_put_failure;
6543
David S. Miller9360ffd2012-03-29 04:41:26 -04006544 if ((rdev->wowlan->any &&
6545 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6546 (rdev->wowlan->disconnect &&
6547 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6548 (rdev->wowlan->magic_pkt &&
6549 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6550 (rdev->wowlan->gtk_rekey_failure &&
6551 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6552 (rdev->wowlan->eap_identity_req &&
6553 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6554 (rdev->wowlan->four_way_handshake &&
6555 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6556 (rdev->wowlan->rfkill_release &&
6557 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6558 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006559 if (rdev->wowlan->n_patterns) {
6560 struct nlattr *nl_pats, *nl_pat;
6561 int i, pat_len;
6562
6563 nl_pats = nla_nest_start(msg,
6564 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6565 if (!nl_pats)
6566 goto nla_put_failure;
6567
6568 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6569 nl_pat = nla_nest_start(msg, i + 1);
6570 if (!nl_pat)
6571 goto nla_put_failure;
6572 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006573 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6574 DIV_ROUND_UP(pat_len, 8),
6575 rdev->wowlan->patterns[i].mask) ||
6576 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6577 pat_len,
6578 rdev->wowlan->patterns[i].pattern))
6579 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006580 nla_nest_end(msg, nl_pat);
6581 }
6582 nla_nest_end(msg, nl_pats);
6583 }
6584
6585 nla_nest_end(msg, nl_wowlan);
6586 }
6587
6588 genlmsg_end(msg, hdr);
6589 return genlmsg_reply(msg, info);
6590
6591nla_put_failure:
6592 nlmsg_free(msg);
6593 return -ENOBUFS;
6594}
6595
6596static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6597{
6598 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6599 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02006600 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02006601 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006602 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6603 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006604 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006605
6606 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6607 return -EOPNOTSUPP;
6608
Johannes Bergae33bd82012-07-12 16:25:02 +02006609 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
6610 cfg80211_rdev_free_wowlan(rdev);
6611 rdev->wowlan = NULL;
6612 goto set_wakeup;
6613 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02006614
6615 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6616 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6617 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6618 nl80211_wowlan_policy);
6619 if (err)
6620 return err;
6621
6622 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6623 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6624 return -EINVAL;
6625 new_triggers.any = true;
6626 }
6627
6628 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6629 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6630 return -EINVAL;
6631 new_triggers.disconnect = true;
6632 }
6633
6634 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6635 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6636 return -EINVAL;
6637 new_triggers.magic_pkt = true;
6638 }
6639
Johannes Berg77dbbb12011-07-13 10:48:55 +02006640 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6641 return -EINVAL;
6642
6643 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6644 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6645 return -EINVAL;
6646 new_triggers.gtk_rekey_failure = true;
6647 }
6648
6649 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6650 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6651 return -EINVAL;
6652 new_triggers.eap_identity_req = true;
6653 }
6654
6655 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6656 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6657 return -EINVAL;
6658 new_triggers.four_way_handshake = true;
6659 }
6660
6661 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6662 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6663 return -EINVAL;
6664 new_triggers.rfkill_release = true;
6665 }
6666
Johannes Bergff1b6e62011-05-04 15:37:28 +02006667 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6668 struct nlattr *pat;
6669 int n_patterns = 0;
6670 int rem, pat_len, mask_len;
6671 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6672
6673 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6674 rem)
6675 n_patterns++;
6676 if (n_patterns > wowlan->n_patterns)
6677 return -EINVAL;
6678
6679 new_triggers.patterns = kcalloc(n_patterns,
6680 sizeof(new_triggers.patterns[0]),
6681 GFP_KERNEL);
6682 if (!new_triggers.patterns)
6683 return -ENOMEM;
6684
6685 new_triggers.n_patterns = n_patterns;
6686 i = 0;
6687
6688 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6689 rem) {
6690 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6691 nla_data(pat), nla_len(pat), NULL);
6692 err = -EINVAL;
6693 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6694 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6695 goto error;
6696 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6697 mask_len = DIV_ROUND_UP(pat_len, 8);
6698 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6699 mask_len)
6700 goto error;
6701 if (pat_len > wowlan->pattern_max_len ||
6702 pat_len < wowlan->pattern_min_len)
6703 goto error;
6704
6705 new_triggers.patterns[i].mask =
6706 kmalloc(mask_len + pat_len, GFP_KERNEL);
6707 if (!new_triggers.patterns[i].mask) {
6708 err = -ENOMEM;
6709 goto error;
6710 }
6711 new_triggers.patterns[i].pattern =
6712 new_triggers.patterns[i].mask + mask_len;
6713 memcpy(new_triggers.patterns[i].mask,
6714 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6715 mask_len);
6716 new_triggers.patterns[i].pattern_len = pat_len;
6717 memcpy(new_triggers.patterns[i].pattern,
6718 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6719 pat_len);
6720 i++;
6721 }
6722 }
6723
Johannes Bergae33bd82012-07-12 16:25:02 +02006724 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
6725 if (!ntrig) {
6726 err = -ENOMEM;
6727 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006728 }
Johannes Bergae33bd82012-07-12 16:25:02 +02006729 cfg80211_rdev_free_wowlan(rdev);
6730 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006731
Johannes Bergae33bd82012-07-12 16:25:02 +02006732 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02006733 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6734 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6735
Johannes Bergff1b6e62011-05-04 15:37:28 +02006736 return 0;
6737 error:
6738 for (i = 0; i < new_triggers.n_patterns; i++)
6739 kfree(new_triggers.patterns[i].mask);
6740 kfree(new_triggers.patterns);
6741 return err;
6742}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006743#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006744
Johannes Berge5497d72011-07-05 16:35:40 +02006745static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6746{
6747 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6748 struct net_device *dev = info->user_ptr[1];
6749 struct wireless_dev *wdev = dev->ieee80211_ptr;
6750 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6751 struct cfg80211_gtk_rekey_data rekey_data;
6752 int err;
6753
6754 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6755 return -EINVAL;
6756
6757 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6758 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6759 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6760 nl80211_rekey_policy);
6761 if (err)
6762 return err;
6763
6764 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6765 return -ERANGE;
6766 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6767 return -ERANGE;
6768 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6769 return -ERANGE;
6770
6771 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6772 NL80211_KEK_LEN);
6773 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6774 NL80211_KCK_LEN);
6775 memcpy(rekey_data.replay_ctr,
6776 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6777 NL80211_REPLAY_CTR_LEN);
6778
6779 wdev_lock(wdev);
6780 if (!wdev->current_bss) {
6781 err = -ENOTCONN;
6782 goto out;
6783 }
6784
6785 if (!rdev->ops->set_rekey_data) {
6786 err = -EOPNOTSUPP;
6787 goto out;
6788 }
6789
6790 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6791 out:
6792 wdev_unlock(wdev);
6793 return err;
6794}
6795
Johannes Berg28946da2011-11-04 11:18:12 +01006796static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6797 struct genl_info *info)
6798{
6799 struct net_device *dev = info->user_ptr[1];
6800 struct wireless_dev *wdev = dev->ieee80211_ptr;
6801
6802 if (wdev->iftype != NL80211_IFTYPE_AP &&
6803 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6804 return -EINVAL;
6805
Eric W. Biederman15e47302012-09-07 20:12:54 +00006806 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01006807 return -EBUSY;
6808
Eric W. Biederman15e47302012-09-07 20:12:54 +00006809 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01006810 return 0;
6811}
6812
Johannes Berg7f6cf312011-11-04 11:18:15 +01006813static int nl80211_probe_client(struct sk_buff *skb,
6814 struct genl_info *info)
6815{
6816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6817 struct net_device *dev = info->user_ptr[1];
6818 struct wireless_dev *wdev = dev->ieee80211_ptr;
6819 struct sk_buff *msg;
6820 void *hdr;
6821 const u8 *addr;
6822 u64 cookie;
6823 int err;
6824
6825 if (wdev->iftype != NL80211_IFTYPE_AP &&
6826 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6827 return -EOPNOTSUPP;
6828
6829 if (!info->attrs[NL80211_ATTR_MAC])
6830 return -EINVAL;
6831
6832 if (!rdev->ops->probe_client)
6833 return -EOPNOTSUPP;
6834
6835 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6836 if (!msg)
6837 return -ENOMEM;
6838
Eric W. Biederman15e47302012-09-07 20:12:54 +00006839 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01006840 NL80211_CMD_PROBE_CLIENT);
6841
6842 if (IS_ERR(hdr)) {
6843 err = PTR_ERR(hdr);
6844 goto free_msg;
6845 }
6846
6847 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6848
6849 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6850 if (err)
6851 goto free_msg;
6852
David S. Miller9360ffd2012-03-29 04:41:26 -04006853 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6854 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006855
6856 genlmsg_end(msg, hdr);
6857
6858 return genlmsg_reply(msg, info);
6859
6860 nla_put_failure:
6861 err = -ENOBUFS;
6862 free_msg:
6863 nlmsg_free(msg);
6864 return err;
6865}
6866
Johannes Berg5e760232011-11-04 11:18:17 +01006867static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6868{
6869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6870
6871 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6872 return -EOPNOTSUPP;
6873
Eric W. Biederman15e47302012-09-07 20:12:54 +00006874 if (rdev->ap_beacons_nlportid)
Johannes Berg5e760232011-11-04 11:18:17 +01006875 return -EBUSY;
6876
Eric W. Biederman15e47302012-09-07 20:12:54 +00006877 rdev->ap_beacons_nlportid = info->snd_portid;
Johannes Berg5e760232011-11-04 11:18:17 +01006878
6879 return 0;
6880}
6881
Johannes Berg98104fde2012-06-16 00:19:54 +02006882static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
6883{
6884 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6885 struct wireless_dev *wdev = info->user_ptr[1];
6886 int err;
6887
6888 if (!rdev->ops->start_p2p_device)
6889 return -EOPNOTSUPP;
6890
6891 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6892 return -EOPNOTSUPP;
6893
6894 if (wdev->p2p_started)
6895 return 0;
6896
6897 mutex_lock(&rdev->devlist_mtx);
6898 err = cfg80211_can_add_interface(rdev, wdev->iftype);
6899 mutex_unlock(&rdev->devlist_mtx);
6900 if (err)
6901 return err;
6902
6903 err = rdev->ops->start_p2p_device(&rdev->wiphy, wdev);
6904 if (err)
6905 return err;
6906
6907 wdev->p2p_started = true;
6908 mutex_lock(&rdev->devlist_mtx);
6909 rdev->opencount++;
6910 mutex_unlock(&rdev->devlist_mtx);
6911
6912 return 0;
6913}
6914
6915static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
6916{
6917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6918 struct wireless_dev *wdev = info->user_ptr[1];
6919
6920 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6921 return -EOPNOTSUPP;
6922
6923 if (!rdev->ops->stop_p2p_device)
6924 return -EOPNOTSUPP;
6925
6926 if (!wdev->p2p_started)
6927 return 0;
6928
6929 rdev->ops->stop_p2p_device(&rdev->wiphy, wdev);
6930 wdev->p2p_started = false;
6931
6932 mutex_lock(&rdev->devlist_mtx);
6933 rdev->opencount--;
6934 mutex_unlock(&rdev->devlist_mtx);
6935
6936 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
6937 rdev->scan_req->aborted = true;
6938 ___cfg80211_scan_done(rdev, true);
6939 }
6940
6941 return 0;
6942}
6943
Johannes Berg4c476992010-10-04 21:36:35 +02006944#define NL80211_FLAG_NEED_WIPHY 0x01
6945#define NL80211_FLAG_NEED_NETDEV 0x02
6946#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006947#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6948#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6949 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02006950#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02006951/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02006952#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6953 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006954
6955static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6956 struct genl_info *info)
6957{
6958 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02006959 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006960 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02006961 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6962
6963 if (rtnl)
6964 rtnl_lock();
6965
6966 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006967 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006968 if (IS_ERR(rdev)) {
6969 if (rtnl)
6970 rtnl_unlock();
6971 return PTR_ERR(rdev);
6972 }
6973 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02006974 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
6975 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02006976 mutex_lock(&cfg80211_mutex);
6977 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
6978 info->attrs);
6979 if (IS_ERR(wdev)) {
6980 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02006981 if (rtnl)
6982 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02006983 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006984 }
Johannes Berg89a54e42012-06-15 14:33:17 +02006985
Johannes Berg89a54e42012-06-15 14:33:17 +02006986 dev = wdev->netdev;
6987 rdev = wiphy_to_dev(wdev->wiphy);
6988
Johannes Berg1bf614e2012-06-15 15:23:36 +02006989 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
6990 if (!dev) {
6991 mutex_unlock(&cfg80211_mutex);
6992 if (rtnl)
6993 rtnl_unlock();
6994 return -EINVAL;
6995 }
6996
6997 info->user_ptr[1] = dev;
6998 } else {
6999 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02007000 }
Johannes Berg89a54e42012-06-15 14:33:17 +02007001
Johannes Berg1bf614e2012-06-15 15:23:36 +02007002 if (dev) {
7003 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
7004 !netif_running(dev)) {
7005 mutex_unlock(&cfg80211_mutex);
7006 if (rtnl)
7007 rtnl_unlock();
7008 return -ENETDOWN;
7009 }
7010
7011 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02007012 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7013 if (!wdev->p2p_started) {
7014 mutex_unlock(&cfg80211_mutex);
7015 if (rtnl)
7016 rtnl_unlock();
7017 return -ENETDOWN;
7018 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02007019 }
7020
Johannes Berg89a54e42012-06-15 14:33:17 +02007021 cfg80211_lock_rdev(rdev);
7022
7023 mutex_unlock(&cfg80211_mutex);
7024
Johannes Berg4c476992010-10-04 21:36:35 +02007025 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007026 }
7027
7028 return 0;
7029}
7030
7031static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7032 struct genl_info *info)
7033{
7034 if (info->user_ptr[0])
7035 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02007036 if (info->user_ptr[1]) {
7037 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7038 struct wireless_dev *wdev = info->user_ptr[1];
7039
7040 if (wdev->netdev)
7041 dev_put(wdev->netdev);
7042 } else {
7043 dev_put(info->user_ptr[1]);
7044 }
7045 }
Johannes Berg4c476992010-10-04 21:36:35 +02007046 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7047 rtnl_unlock();
7048}
7049
Johannes Berg55682962007-09-20 13:09:35 -04007050static struct genl_ops nl80211_ops[] = {
7051 {
7052 .cmd = NL80211_CMD_GET_WIPHY,
7053 .doit = nl80211_get_wiphy,
7054 .dumpit = nl80211_dump_wiphy,
7055 .policy = nl80211_policy,
7056 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007057 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04007058 },
7059 {
7060 .cmd = NL80211_CMD_SET_WIPHY,
7061 .doit = nl80211_set_wiphy,
7062 .policy = nl80211_policy,
7063 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007064 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007065 },
7066 {
7067 .cmd = NL80211_CMD_GET_INTERFACE,
7068 .doit = nl80211_get_interface,
7069 .dumpit = nl80211_dump_interface,
7070 .policy = nl80211_policy,
7071 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02007072 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04007073 },
7074 {
7075 .cmd = NL80211_CMD_SET_INTERFACE,
7076 .doit = nl80211_set_interface,
7077 .policy = nl80211_policy,
7078 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007079 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7080 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007081 },
7082 {
7083 .cmd = NL80211_CMD_NEW_INTERFACE,
7084 .doit = nl80211_new_interface,
7085 .policy = nl80211_policy,
7086 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007087 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7088 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007089 },
7090 {
7091 .cmd = NL80211_CMD_DEL_INTERFACE,
7092 .doit = nl80211_del_interface,
7093 .policy = nl80211_policy,
7094 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02007095 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007096 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007097 },
Johannes Berg41ade002007-12-19 02:03:29 +01007098 {
7099 .cmd = NL80211_CMD_GET_KEY,
7100 .doit = nl80211_get_key,
7101 .policy = nl80211_policy,
7102 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007103 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007104 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007105 },
7106 {
7107 .cmd = NL80211_CMD_SET_KEY,
7108 .doit = nl80211_set_key,
7109 .policy = nl80211_policy,
7110 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007111 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007112 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007113 },
7114 {
7115 .cmd = NL80211_CMD_NEW_KEY,
7116 .doit = nl80211_new_key,
7117 .policy = nl80211_policy,
7118 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007119 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007120 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007121 },
7122 {
7123 .cmd = NL80211_CMD_DEL_KEY,
7124 .doit = nl80211_del_key,
7125 .policy = nl80211_policy,
7126 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007127 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007128 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007129 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01007130 {
7131 .cmd = NL80211_CMD_SET_BEACON,
7132 .policy = nl80211_policy,
7133 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007134 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007135 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007136 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007137 },
7138 {
Johannes Berg88600202012-02-13 15:17:18 +01007139 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007140 .policy = nl80211_policy,
7141 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007142 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007143 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007144 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007145 },
7146 {
Johannes Berg88600202012-02-13 15:17:18 +01007147 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007148 .policy = nl80211_policy,
7149 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007150 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007152 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007153 },
Johannes Berg5727ef12007-12-19 02:03:34 +01007154 {
7155 .cmd = NL80211_CMD_GET_STATION,
7156 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007157 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01007158 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02007159 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7160 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007161 },
7162 {
7163 .cmd = NL80211_CMD_SET_STATION,
7164 .doit = nl80211_set_station,
7165 .policy = nl80211_policy,
7166 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007167 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007168 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007169 },
7170 {
7171 .cmd = NL80211_CMD_NEW_STATION,
7172 .doit = nl80211_new_station,
7173 .policy = nl80211_policy,
7174 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007175 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007176 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007177 },
7178 {
7179 .cmd = NL80211_CMD_DEL_STATION,
7180 .doit = nl80211_del_station,
7181 .policy = nl80211_policy,
7182 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007183 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007184 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007185 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007186 {
7187 .cmd = NL80211_CMD_GET_MPATH,
7188 .doit = nl80211_get_mpath,
7189 .dumpit = nl80211_dump_mpath,
7190 .policy = nl80211_policy,
7191 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007193 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007194 },
7195 {
7196 .cmd = NL80211_CMD_SET_MPATH,
7197 .doit = nl80211_set_mpath,
7198 .policy = nl80211_policy,
7199 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007201 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007202 },
7203 {
7204 .cmd = NL80211_CMD_NEW_MPATH,
7205 .doit = nl80211_new_mpath,
7206 .policy = nl80211_policy,
7207 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007208 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007209 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007210 },
7211 {
7212 .cmd = NL80211_CMD_DEL_MPATH,
7213 .doit = nl80211_del_mpath,
7214 .policy = nl80211_policy,
7215 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007216 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007217 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007218 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007219 {
7220 .cmd = NL80211_CMD_SET_BSS,
7221 .doit = nl80211_set_bss,
7222 .policy = nl80211_policy,
7223 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007224 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007225 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007226 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007227 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007228 .cmd = NL80211_CMD_GET_REG,
7229 .doit = nl80211_get_reg,
7230 .policy = nl80211_policy,
7231 /* can be retrieved by unprivileged users */
7232 },
7233 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007234 .cmd = NL80211_CMD_SET_REG,
7235 .doit = nl80211_set_reg,
7236 .policy = nl80211_policy,
7237 .flags = GENL_ADMIN_PERM,
7238 },
7239 {
7240 .cmd = NL80211_CMD_REQ_SET_REG,
7241 .doit = nl80211_req_set_reg,
7242 .policy = nl80211_policy,
7243 .flags = GENL_ADMIN_PERM,
7244 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007245 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007246 .cmd = NL80211_CMD_GET_MESH_CONFIG,
7247 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007248 .policy = nl80211_policy,
7249 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007250 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007251 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007252 },
7253 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007254 .cmd = NL80211_CMD_SET_MESH_CONFIG,
7255 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007256 .policy = nl80211_policy,
7257 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01007258 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007259 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007260 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02007261 {
Johannes Berg2a519312009-02-10 21:25:55 +01007262 .cmd = NL80211_CMD_TRIGGER_SCAN,
7263 .doit = nl80211_trigger_scan,
7264 .policy = nl80211_policy,
7265 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02007266 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007267 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01007268 },
7269 {
7270 .cmd = NL80211_CMD_GET_SCAN,
7271 .policy = nl80211_policy,
7272 .dumpit = nl80211_dump_scan,
7273 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02007274 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007275 .cmd = NL80211_CMD_START_SCHED_SCAN,
7276 .doit = nl80211_start_sched_scan,
7277 .policy = nl80211_policy,
7278 .flags = GENL_ADMIN_PERM,
7279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7280 NL80211_FLAG_NEED_RTNL,
7281 },
7282 {
7283 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
7284 .doit = nl80211_stop_sched_scan,
7285 .policy = nl80211_policy,
7286 .flags = GENL_ADMIN_PERM,
7287 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7288 NL80211_FLAG_NEED_RTNL,
7289 },
7290 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02007291 .cmd = NL80211_CMD_AUTHENTICATE,
7292 .doit = nl80211_authenticate,
7293 .policy = nl80211_policy,
7294 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007295 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007296 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007297 },
7298 {
7299 .cmd = NL80211_CMD_ASSOCIATE,
7300 .doit = nl80211_associate,
7301 .policy = nl80211_policy,
7302 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007303 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007304 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007305 },
7306 {
7307 .cmd = NL80211_CMD_DEAUTHENTICATE,
7308 .doit = nl80211_deauthenticate,
7309 .policy = nl80211_policy,
7310 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007311 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007312 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007313 },
7314 {
7315 .cmd = NL80211_CMD_DISASSOCIATE,
7316 .doit = nl80211_disassociate,
7317 .policy = nl80211_policy,
7318 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007319 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007320 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007321 },
Johannes Berg04a773a2009-04-19 21:24:32 +02007322 {
7323 .cmd = NL80211_CMD_JOIN_IBSS,
7324 .doit = nl80211_join_ibss,
7325 .policy = nl80211_policy,
7326 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007327 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007328 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007329 },
7330 {
7331 .cmd = NL80211_CMD_LEAVE_IBSS,
7332 .doit = nl80211_leave_ibss,
7333 .policy = nl80211_policy,
7334 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007335 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007336 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007337 },
Johannes Bergaff89a92009-07-01 21:26:51 +02007338#ifdef CONFIG_NL80211_TESTMODE
7339 {
7340 .cmd = NL80211_CMD_TESTMODE,
7341 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007342 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02007343 .policy = nl80211_policy,
7344 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007345 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7346 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007347 },
7348#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007349 {
7350 .cmd = NL80211_CMD_CONNECT,
7351 .doit = nl80211_connect,
7352 .policy = nl80211_policy,
7353 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007355 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007356 },
7357 {
7358 .cmd = NL80211_CMD_DISCONNECT,
7359 .doit = nl80211_disconnect,
7360 .policy = nl80211_policy,
7361 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007363 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007364 },
Johannes Berg463d0182009-07-14 00:33:35 +02007365 {
7366 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7367 .doit = nl80211_wiphy_netns,
7368 .policy = nl80211_policy,
7369 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007370 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7371 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007372 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007373 {
7374 .cmd = NL80211_CMD_GET_SURVEY,
7375 .policy = nl80211_policy,
7376 .dumpit = nl80211_dump_survey,
7377 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007378 {
7379 .cmd = NL80211_CMD_SET_PMKSA,
7380 .doit = nl80211_setdel_pmksa,
7381 .policy = nl80211_policy,
7382 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007384 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007385 },
7386 {
7387 .cmd = NL80211_CMD_DEL_PMKSA,
7388 .doit = nl80211_setdel_pmksa,
7389 .policy = nl80211_policy,
7390 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007391 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007392 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007393 },
7394 {
7395 .cmd = NL80211_CMD_FLUSH_PMKSA,
7396 .doit = nl80211_flush_pmksa,
7397 .policy = nl80211_policy,
7398 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007399 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007400 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007401 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007402 {
7403 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7404 .doit = nl80211_remain_on_channel,
7405 .policy = nl80211_policy,
7406 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007407 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007408 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007409 },
7410 {
7411 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7412 .doit = nl80211_cancel_remain_on_channel,
7413 .policy = nl80211_policy,
7414 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007415 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007416 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007417 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007418 {
7419 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7420 .doit = nl80211_set_tx_bitrate_mask,
7421 .policy = nl80211_policy,
7422 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007423 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7424 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007425 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007426 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007427 .cmd = NL80211_CMD_REGISTER_FRAME,
7428 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007429 .policy = nl80211_policy,
7430 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007431 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007432 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007433 },
7434 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007435 .cmd = NL80211_CMD_FRAME,
7436 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007437 .policy = nl80211_policy,
7438 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007439 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007440 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007441 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007442 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007443 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7444 .doit = nl80211_tx_mgmt_cancel_wait,
7445 .policy = nl80211_policy,
7446 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007447 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007448 NL80211_FLAG_NEED_RTNL,
7449 },
7450 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007451 .cmd = NL80211_CMD_SET_POWER_SAVE,
7452 .doit = nl80211_set_power_save,
7453 .policy = nl80211_policy,
7454 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007455 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7456 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007457 },
7458 {
7459 .cmd = NL80211_CMD_GET_POWER_SAVE,
7460 .doit = nl80211_get_power_save,
7461 .policy = nl80211_policy,
7462 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007463 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7464 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007465 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007466 {
7467 .cmd = NL80211_CMD_SET_CQM,
7468 .doit = nl80211_set_cqm,
7469 .policy = nl80211_policy,
7470 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007471 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7472 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007473 },
Johannes Bergf444de02010-05-05 15:25:02 +02007474 {
7475 .cmd = NL80211_CMD_SET_CHANNEL,
7476 .doit = nl80211_set_channel,
7477 .policy = nl80211_policy,
7478 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007479 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7480 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007481 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007482 {
7483 .cmd = NL80211_CMD_SET_WDS_PEER,
7484 .doit = nl80211_set_wds_peer,
7485 .policy = nl80211_policy,
7486 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007487 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7488 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007489 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007490 {
7491 .cmd = NL80211_CMD_JOIN_MESH,
7492 .doit = nl80211_join_mesh,
7493 .policy = nl80211_policy,
7494 .flags = GENL_ADMIN_PERM,
7495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7496 NL80211_FLAG_NEED_RTNL,
7497 },
7498 {
7499 .cmd = NL80211_CMD_LEAVE_MESH,
7500 .doit = nl80211_leave_mesh,
7501 .policy = nl80211_policy,
7502 .flags = GENL_ADMIN_PERM,
7503 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7504 NL80211_FLAG_NEED_RTNL,
7505 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007506#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007507 {
7508 .cmd = NL80211_CMD_GET_WOWLAN,
7509 .doit = nl80211_get_wowlan,
7510 .policy = nl80211_policy,
7511 /* can be retrieved by unprivileged users */
7512 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7513 NL80211_FLAG_NEED_RTNL,
7514 },
7515 {
7516 .cmd = NL80211_CMD_SET_WOWLAN,
7517 .doit = nl80211_set_wowlan,
7518 .policy = nl80211_policy,
7519 .flags = GENL_ADMIN_PERM,
7520 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7521 NL80211_FLAG_NEED_RTNL,
7522 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007523#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007524 {
7525 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7526 .doit = nl80211_set_rekey_data,
7527 .policy = nl80211_policy,
7528 .flags = GENL_ADMIN_PERM,
7529 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7530 NL80211_FLAG_NEED_RTNL,
7531 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007532 {
7533 .cmd = NL80211_CMD_TDLS_MGMT,
7534 .doit = nl80211_tdls_mgmt,
7535 .policy = nl80211_policy,
7536 .flags = GENL_ADMIN_PERM,
7537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7538 NL80211_FLAG_NEED_RTNL,
7539 },
7540 {
7541 .cmd = NL80211_CMD_TDLS_OPER,
7542 .doit = nl80211_tdls_oper,
7543 .policy = nl80211_policy,
7544 .flags = GENL_ADMIN_PERM,
7545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7546 NL80211_FLAG_NEED_RTNL,
7547 },
Johannes Berg28946da2011-11-04 11:18:12 +01007548 {
7549 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7550 .doit = nl80211_register_unexpected_frame,
7551 .policy = nl80211_policy,
7552 .flags = GENL_ADMIN_PERM,
7553 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7554 NL80211_FLAG_NEED_RTNL,
7555 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007556 {
7557 .cmd = NL80211_CMD_PROBE_CLIENT,
7558 .doit = nl80211_probe_client,
7559 .policy = nl80211_policy,
7560 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007562 NL80211_FLAG_NEED_RTNL,
7563 },
Johannes Berg5e760232011-11-04 11:18:17 +01007564 {
7565 .cmd = NL80211_CMD_REGISTER_BEACONS,
7566 .doit = nl80211_register_beacons,
7567 .policy = nl80211_policy,
7568 .flags = GENL_ADMIN_PERM,
7569 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7570 NL80211_FLAG_NEED_RTNL,
7571 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007572 {
7573 .cmd = NL80211_CMD_SET_NOACK_MAP,
7574 .doit = nl80211_set_noack_map,
7575 .policy = nl80211_policy,
7576 .flags = GENL_ADMIN_PERM,
7577 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7578 NL80211_FLAG_NEED_RTNL,
7579 },
Johannes Berg98104fde2012-06-16 00:19:54 +02007580 {
7581 .cmd = NL80211_CMD_START_P2P_DEVICE,
7582 .doit = nl80211_start_p2p_device,
7583 .policy = nl80211_policy,
7584 .flags = GENL_ADMIN_PERM,
7585 .internal_flags = NL80211_FLAG_NEED_WDEV |
7586 NL80211_FLAG_NEED_RTNL,
7587 },
7588 {
7589 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
7590 .doit = nl80211_stop_p2p_device,
7591 .policy = nl80211_policy,
7592 .flags = GENL_ADMIN_PERM,
7593 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7594 NL80211_FLAG_NEED_RTNL,
7595 },
Johannes Berg55682962007-09-20 13:09:35 -04007596};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007597
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007598static struct genl_multicast_group nl80211_mlme_mcgrp = {
7599 .name = "mlme",
7600};
Johannes Berg55682962007-09-20 13:09:35 -04007601
7602/* multicast groups */
7603static struct genl_multicast_group nl80211_config_mcgrp = {
7604 .name = "config",
7605};
Johannes Berg2a519312009-02-10 21:25:55 +01007606static struct genl_multicast_group nl80211_scan_mcgrp = {
7607 .name = "scan",
7608};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007609static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7610 .name = "regulatory",
7611};
Johannes Berg55682962007-09-20 13:09:35 -04007612
7613/* notification functions */
7614
7615void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7616{
7617 struct sk_buff *msg;
7618
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007620 if (!msg)
7621 return;
7622
7623 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7624 nlmsg_free(msg);
7625 return;
7626 }
7627
Johannes Berg463d0182009-07-14 00:33:35 +02007628 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7629 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007630}
7631
Johannes Berg362a4152009-05-24 16:43:15 +02007632static int nl80211_add_scan_req(struct sk_buff *msg,
7633 struct cfg80211_registered_device *rdev)
7634{
7635 struct cfg80211_scan_request *req = rdev->scan_req;
7636 struct nlattr *nest;
7637 int i;
7638
Johannes Berg667503d2009-07-07 03:56:11 +02007639 ASSERT_RDEV_LOCK(rdev);
7640
Johannes Berg362a4152009-05-24 16:43:15 +02007641 if (WARN_ON(!req))
7642 return 0;
7643
7644 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7645 if (!nest)
7646 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007647 for (i = 0; i < req->n_ssids; i++) {
7648 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7649 goto nla_put_failure;
7650 }
Johannes Berg362a4152009-05-24 16:43:15 +02007651 nla_nest_end(msg, nest);
7652
7653 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7654 if (!nest)
7655 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007656 for (i = 0; i < req->n_channels; i++) {
7657 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7658 goto nla_put_failure;
7659 }
Johannes Berg362a4152009-05-24 16:43:15 +02007660 nla_nest_end(msg, nest);
7661
David S. Miller9360ffd2012-03-29 04:41:26 -04007662 if (req->ie &&
7663 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7664 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007665
7666 return 0;
7667 nla_put_failure:
7668 return -ENOBUFS;
7669}
7670
Johannes Berga538e2d2009-06-16 19:56:42 +02007671static int nl80211_send_scan_msg(struct sk_buff *msg,
7672 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007673 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007674 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02007675 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007676{
7677 void *hdr;
7678
Eric W. Biederman15e47302012-09-07 20:12:54 +00007679 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01007680 if (!hdr)
7681 return -1;
7682
David S. Miller9360ffd2012-03-29 04:41:26 -04007683 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02007684 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
7685 wdev->netdev->ifindex)) ||
7686 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007687 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007688
Johannes Berg362a4152009-05-24 16:43:15 +02007689 /* ignore errors and send incomplete event anyway */
7690 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007691
7692 return genlmsg_end(msg, hdr);
7693
7694 nla_put_failure:
7695 genlmsg_cancel(msg, hdr);
7696 return -EMSGSIZE;
7697}
7698
Luciano Coelho807f8a82011-05-11 17:09:35 +03007699static int
7700nl80211_send_sched_scan_msg(struct sk_buff *msg,
7701 struct cfg80211_registered_device *rdev,
7702 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007703 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007704{
7705 void *hdr;
7706
Eric W. Biederman15e47302012-09-07 20:12:54 +00007707 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007708 if (!hdr)
7709 return -1;
7710
David S. Miller9360ffd2012-03-29 04:41:26 -04007711 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7712 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7713 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007714
7715 return genlmsg_end(msg, hdr);
7716
7717 nla_put_failure:
7718 genlmsg_cancel(msg, hdr);
7719 return -EMSGSIZE;
7720}
7721
Johannes Berga538e2d2009-06-16 19:56:42 +02007722void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007723 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02007724{
7725 struct sk_buff *msg;
7726
Thomas Graf58050fc2012-06-28 03:57:45 +00007727 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007728 if (!msg)
7729 return;
7730
Johannes Bergfd014282012-06-18 19:17:03 +02007731 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007732 NL80211_CMD_TRIGGER_SCAN) < 0) {
7733 nlmsg_free(msg);
7734 return;
7735 }
7736
Johannes Berg463d0182009-07-14 00:33:35 +02007737 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7738 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007739}
7740
Johannes Berg2a519312009-02-10 21:25:55 +01007741void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007742 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007743{
7744 struct sk_buff *msg;
7745
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007746 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007747 if (!msg)
7748 return;
7749
Johannes Bergfd014282012-06-18 19:17:03 +02007750 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007751 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007752 nlmsg_free(msg);
7753 return;
7754 }
7755
Johannes Berg463d0182009-07-14 00:33:35 +02007756 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7757 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007758}
7759
7760void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007761 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007762{
7763 struct sk_buff *msg;
7764
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007766 if (!msg)
7767 return;
7768
Johannes Bergfd014282012-06-18 19:17:03 +02007769 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007770 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007771 nlmsg_free(msg);
7772 return;
7773 }
7774
Johannes Berg463d0182009-07-14 00:33:35 +02007775 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7776 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007777}
7778
Luciano Coelho807f8a82011-05-11 17:09:35 +03007779void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7780 struct net_device *netdev)
7781{
7782 struct sk_buff *msg;
7783
7784 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7785 if (!msg)
7786 return;
7787
7788 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7789 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7790 nlmsg_free(msg);
7791 return;
7792 }
7793
7794 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7795 nl80211_scan_mcgrp.id, GFP_KERNEL);
7796}
7797
7798void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7799 struct net_device *netdev, u32 cmd)
7800{
7801 struct sk_buff *msg;
7802
Thomas Graf58050fc2012-06-28 03:57:45 +00007803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007804 if (!msg)
7805 return;
7806
7807 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7808 nlmsg_free(msg);
7809 return;
7810 }
7811
7812 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7813 nl80211_scan_mcgrp.id, GFP_KERNEL);
7814}
7815
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007816/*
7817 * This can happen on global regulatory changes or device specific settings
7818 * based on custom world regulatory domains.
7819 */
7820void nl80211_send_reg_change_event(struct regulatory_request *request)
7821{
7822 struct sk_buff *msg;
7823 void *hdr;
7824
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007825 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007826 if (!msg)
7827 return;
7828
7829 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7830 if (!hdr) {
7831 nlmsg_free(msg);
7832 return;
7833 }
7834
7835 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007836 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7837 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007838
David S. Miller9360ffd2012-03-29 04:41:26 -04007839 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7840 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7841 NL80211_REGDOM_TYPE_WORLD))
7842 goto nla_put_failure;
7843 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7844 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7845 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7846 goto nla_put_failure;
7847 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7848 request->intersect) {
7849 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7850 NL80211_REGDOM_TYPE_INTERSECTION))
7851 goto nla_put_failure;
7852 } else {
7853 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7854 NL80211_REGDOM_TYPE_COUNTRY) ||
7855 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7856 request->alpha2))
7857 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007858 }
7859
David S. Miller9360ffd2012-03-29 04:41:26 -04007860 if (wiphy_idx_valid(request->wiphy_idx) &&
7861 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7862 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007863
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007864 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007865
Johannes Bergbc43b282009-07-25 10:54:13 +02007866 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007867 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007868 GFP_ATOMIC);
7869 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007870
7871 return;
7872
7873nla_put_failure:
7874 genlmsg_cancel(msg, hdr);
7875 nlmsg_free(msg);
7876}
7877
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007878static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7879 struct net_device *netdev,
7880 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007881 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007882{
7883 struct sk_buff *msg;
7884 void *hdr;
7885
Johannes Berge6d6e342009-07-01 21:26:47 +02007886 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007887 if (!msg)
7888 return;
7889
7890 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7891 if (!hdr) {
7892 nlmsg_free(msg);
7893 return;
7894 }
7895
David S. Miller9360ffd2012-03-29 04:41:26 -04007896 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7897 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7898 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7899 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007900
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007901 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007902
Johannes Berg463d0182009-07-14 00:33:35 +02007903 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7904 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007905 return;
7906
7907 nla_put_failure:
7908 genlmsg_cancel(msg, hdr);
7909 nlmsg_free(msg);
7910}
7911
7912void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007913 struct net_device *netdev, const u8 *buf,
7914 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007915{
7916 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007917 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007918}
7919
7920void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7921 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007922 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007923{
Johannes Berge6d6e342009-07-01 21:26:47 +02007924 nl80211_send_mlme_event(rdev, netdev, buf, len,
7925 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007926}
7927
Jouni Malinen53b46b82009-03-27 20:53:56 +02007928void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007929 struct net_device *netdev, const u8 *buf,
7930 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007931{
7932 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007933 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007934}
7935
Jouni Malinen53b46b82009-03-27 20:53:56 +02007936void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7937 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007938 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_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007942}
7943
Jouni Malinencf4e5942010-12-16 00:52:40 +02007944void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7945 struct net_device *netdev, const u8 *buf,
7946 size_t len, gfp_t gfp)
7947{
7948 nl80211_send_mlme_event(rdev, netdev, buf, len,
7949 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7950}
7951
7952void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7953 struct net_device *netdev, const u8 *buf,
7954 size_t len, gfp_t gfp)
7955{
7956 nl80211_send_mlme_event(rdev, netdev, buf, len,
7957 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7958}
7959
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007960static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7961 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007962 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007963{
7964 struct sk_buff *msg;
7965 void *hdr;
7966
Johannes Berge6d6e342009-07-01 21:26:47 +02007967 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007968 if (!msg)
7969 return;
7970
7971 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7972 if (!hdr) {
7973 nlmsg_free(msg);
7974 return;
7975 }
7976
David S. Miller9360ffd2012-03-29 04:41:26 -04007977 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7978 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7979 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7980 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7981 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007982
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007983 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007984
Johannes Berg463d0182009-07-14 00:33:35 +02007985 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7986 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007987 return;
7988
7989 nla_put_failure:
7990 genlmsg_cancel(msg, hdr);
7991 nlmsg_free(msg);
7992}
7993
7994void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007995 struct net_device *netdev, const u8 *addr,
7996 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007997{
7998 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007999 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008000}
8001
8002void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02008003 struct net_device *netdev, const u8 *addr,
8004 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008005{
Johannes Berge6d6e342009-07-01 21:26:47 +02008006 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8007 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008008}
8009
Samuel Ortizb23aa672009-07-01 21:26:54 +02008010void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8011 struct net_device *netdev, const u8 *bssid,
8012 const u8 *req_ie, size_t req_ie_len,
8013 const u8 *resp_ie, size_t resp_ie_len,
8014 u16 status, gfp_t gfp)
8015{
8016 struct sk_buff *msg;
8017 void *hdr;
8018
Thomas Graf58050fc2012-06-28 03:57:45 +00008019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008020 if (!msg)
8021 return;
8022
8023 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8024 if (!hdr) {
8025 nlmsg_free(msg);
8026 return;
8027 }
8028
David S. Miller9360ffd2012-03-29 04:41:26 -04008029 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8030 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8031 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8032 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8033 (req_ie &&
8034 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8035 (resp_ie &&
8036 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8037 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008038
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008039 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008040
Johannes Berg463d0182009-07-14 00:33:35 +02008041 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8042 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008043 return;
8044
8045 nla_put_failure:
8046 genlmsg_cancel(msg, hdr);
8047 nlmsg_free(msg);
8048
8049}
8050
8051void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8052 struct net_device *netdev, const u8 *bssid,
8053 const u8 *req_ie, size_t req_ie_len,
8054 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8055{
8056 struct sk_buff *msg;
8057 void *hdr;
8058
Thomas Graf58050fc2012-06-28 03:57:45 +00008059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008060 if (!msg)
8061 return;
8062
8063 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8064 if (!hdr) {
8065 nlmsg_free(msg);
8066 return;
8067 }
8068
David S. Miller9360ffd2012-03-29 04:41:26 -04008069 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8070 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8071 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8072 (req_ie &&
8073 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8074 (resp_ie &&
8075 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8076 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008077
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008078 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008079
Johannes Berg463d0182009-07-14 00:33:35 +02008080 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8081 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008082 return;
8083
8084 nla_put_failure:
8085 genlmsg_cancel(msg, hdr);
8086 nlmsg_free(msg);
8087
8088}
8089
8090void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8091 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02008092 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008093{
8094 struct sk_buff *msg;
8095 void *hdr;
8096
Thomas Graf58050fc2012-06-28 03:57:45 +00008097 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008098 if (!msg)
8099 return;
8100
8101 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8102 if (!hdr) {
8103 nlmsg_free(msg);
8104 return;
8105 }
8106
David S. Miller9360ffd2012-03-29 04:41:26 -04008107 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8108 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8109 (from_ap && reason &&
8110 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8111 (from_ap &&
8112 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8113 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8114 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008115
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008116 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008117
Johannes Berg463d0182009-07-14 00:33:35 +02008118 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8119 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008120 return;
8121
8122 nla_put_failure:
8123 genlmsg_cancel(msg, hdr);
8124 nlmsg_free(msg);
8125
8126}
8127
Johannes Berg04a773a2009-04-19 21:24:32 +02008128void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8129 struct net_device *netdev, const u8 *bssid,
8130 gfp_t gfp)
8131{
8132 struct sk_buff *msg;
8133 void *hdr;
8134
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008136 if (!msg)
8137 return;
8138
8139 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
8140 if (!hdr) {
8141 nlmsg_free(msg);
8142 return;
8143 }
8144
David S. Miller9360ffd2012-03-29 04:41:26 -04008145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8146 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8147 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8148 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02008149
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008150 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02008151
Johannes Berg463d0182009-07-14 00:33:35 +02008152 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8153 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008154 return;
8155
8156 nla_put_failure:
8157 genlmsg_cancel(msg, hdr);
8158 nlmsg_free(msg);
8159}
8160
Javier Cardonac93b5e72011-04-07 15:08:34 -07008161void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
8162 struct net_device *netdev,
8163 const u8 *macaddr, const u8* ie, u8 ie_len,
8164 gfp_t gfp)
8165{
8166 struct sk_buff *msg;
8167 void *hdr;
8168
8169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8170 if (!msg)
8171 return;
8172
8173 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
8174 if (!hdr) {
8175 nlmsg_free(msg);
8176 return;
8177 }
8178
David S. Miller9360ffd2012-03-29 04:41:26 -04008179 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8180 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8181 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
8182 (ie_len && ie &&
8183 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8184 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07008185
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008186 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07008187
8188 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8189 nl80211_mlme_mcgrp.id, gfp);
8190 return;
8191
8192 nla_put_failure:
8193 genlmsg_cancel(msg, hdr);
8194 nlmsg_free(msg);
8195}
8196
Jouni Malinena3b8b052009-03-27 21:59:49 +02008197void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
8198 struct net_device *netdev, const u8 *addr,
8199 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02008200 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02008201{
8202 struct sk_buff *msg;
8203 void *hdr;
8204
Johannes Berge6d6e342009-07-01 21:26:47 +02008205 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008206 if (!msg)
8207 return;
8208
8209 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
8210 if (!hdr) {
8211 nlmsg_free(msg);
8212 return;
8213 }
8214
David S. Miller9360ffd2012-03-29 04:41:26 -04008215 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8216 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8217 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
8218 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
8219 (key_id != -1 &&
8220 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
8221 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
8222 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02008223
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008224 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008225
Johannes Berg463d0182009-07-14 00:33:35 +02008226 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8227 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008228 return;
8229
8230 nla_put_failure:
8231 genlmsg_cancel(msg, hdr);
8232 nlmsg_free(msg);
8233}
8234
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008235void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
8236 struct ieee80211_channel *channel_before,
8237 struct ieee80211_channel *channel_after)
8238{
8239 struct sk_buff *msg;
8240 void *hdr;
8241 struct nlattr *nl_freq;
8242
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008244 if (!msg)
8245 return;
8246
8247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
8248 if (!hdr) {
8249 nlmsg_free(msg);
8250 return;
8251 }
8252
8253 /*
8254 * Since we are applying the beacon hint to a wiphy we know its
8255 * wiphy_idx is valid
8256 */
David S. Miller9360ffd2012-03-29 04:41:26 -04008257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8258 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008259
8260 /* Before */
8261 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
8262 if (!nl_freq)
8263 goto nla_put_failure;
8264 if (nl80211_msg_put_channel(msg, channel_before))
8265 goto nla_put_failure;
8266 nla_nest_end(msg, nl_freq);
8267
8268 /* After */
8269 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
8270 if (!nl_freq)
8271 goto nla_put_failure;
8272 if (nl80211_msg_put_channel(msg, channel_after))
8273 goto nla_put_failure;
8274 nla_nest_end(msg, nl_freq);
8275
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008276 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008277
Johannes Berg463d0182009-07-14 00:33:35 +02008278 rcu_read_lock();
8279 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8280 GFP_ATOMIC);
8281 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008282
8283 return;
8284
8285nla_put_failure:
8286 genlmsg_cancel(msg, hdr);
8287 nlmsg_free(msg);
8288}
8289
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008290static void nl80211_send_remain_on_chan_event(
8291 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008292 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008293 struct ieee80211_channel *chan,
8294 enum nl80211_channel_type channel_type,
8295 unsigned int duration, gfp_t gfp)
8296{
8297 struct sk_buff *msg;
8298 void *hdr;
8299
8300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8301 if (!msg)
8302 return;
8303
8304 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8305 if (!hdr) {
8306 nlmsg_free(msg);
8307 return;
8308 }
8309
David S. Miller9360ffd2012-03-29 04:41:26 -04008310 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008311 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8312 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02008313 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008314 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
8315 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
8316 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8317 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008318
David S. Miller9360ffd2012-03-29 04:41:26 -04008319 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
8320 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
8321 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008322
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008323 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008324
8325 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8326 nl80211_mlme_mcgrp.id, gfp);
8327 return;
8328
8329 nla_put_failure:
8330 genlmsg_cancel(msg, hdr);
8331 nlmsg_free(msg);
8332}
8333
8334void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008335 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008336 struct ieee80211_channel *chan,
8337 enum nl80211_channel_type channel_type,
8338 unsigned int duration, gfp_t gfp)
8339{
8340 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008341 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008342 channel_type, duration, gfp);
8343}
8344
8345void nl80211_send_remain_on_channel_cancel(
Johannes Berg71bbc992012-06-15 15:30:18 +02008346 struct cfg80211_registered_device *rdev,
8347 struct wireless_dev *wdev,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008348 u64 cookie, struct ieee80211_channel *chan,
8349 enum nl80211_channel_type channel_type, gfp_t gfp)
8350{
8351 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008352 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008353 channel_type, 0, gfp);
8354}
8355
Johannes Berg98b62182009-12-23 13:15:44 +01008356void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
8357 struct net_device *dev, const u8 *mac_addr,
8358 struct station_info *sinfo, gfp_t gfp)
8359{
8360 struct sk_buff *msg;
8361
Thomas Graf58050fc2012-06-28 03:57:45 +00008362 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01008363 if (!msg)
8364 return;
8365
John W. Linville66266b32012-03-15 13:25:41 -04008366 if (nl80211_send_station(msg, 0, 0, 0,
8367 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008368 nlmsg_free(msg);
8369 return;
8370 }
8371
8372 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8373 nl80211_mlme_mcgrp.id, gfp);
8374}
8375
Jouni Malinenec15e682011-03-23 15:29:52 +02008376void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8377 struct net_device *dev, const u8 *mac_addr,
8378 gfp_t gfp)
8379{
8380 struct sk_buff *msg;
8381 void *hdr;
8382
Thomas Graf58050fc2012-06-28 03:57:45 +00008383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02008384 if (!msg)
8385 return;
8386
8387 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8388 if (!hdr) {
8389 nlmsg_free(msg);
8390 return;
8391 }
8392
David S. Miller9360ffd2012-03-29 04:41:26 -04008393 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8394 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8395 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008396
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008397 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008398
8399 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8400 nl80211_mlme_mcgrp.id, gfp);
8401 return;
8402
8403 nla_put_failure:
8404 genlmsg_cancel(msg, hdr);
8405 nlmsg_free(msg);
8406}
8407
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05308408void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
8409 struct net_device *dev, const u8 *mac_addr,
8410 enum nl80211_connect_failed_reason reason,
8411 gfp_t gfp)
8412{
8413 struct sk_buff *msg;
8414 void *hdr;
8415
8416 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8417 if (!msg)
8418 return;
8419
8420 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
8421 if (!hdr) {
8422 nlmsg_free(msg);
8423 return;
8424 }
8425
8426 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8427 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
8428 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
8429 goto nla_put_failure;
8430
8431 genlmsg_end(msg, hdr);
8432
8433 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8434 nl80211_mlme_mcgrp.id, gfp);
8435 return;
8436
8437 nla_put_failure:
8438 genlmsg_cancel(msg, hdr);
8439 nlmsg_free(msg);
8440}
8441
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008442static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8443 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008444{
8445 struct wireless_dev *wdev = dev->ieee80211_ptr;
8446 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8447 struct sk_buff *msg;
8448 void *hdr;
8449 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00008450 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01008451
Eric W. Biederman15e47302012-09-07 20:12:54 +00008452 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008453 return false;
8454
8455 msg = nlmsg_new(100, gfp);
8456 if (!msg)
8457 return true;
8458
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008459 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008460 if (!hdr) {
8461 nlmsg_free(msg);
8462 return true;
8463 }
8464
David S. Miller9360ffd2012-03-29 04:41:26 -04008465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8467 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8468 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008469
8470 err = genlmsg_end(msg, hdr);
8471 if (err < 0) {
8472 nlmsg_free(msg);
8473 return true;
8474 }
8475
Eric W. Biederman15e47302012-09-07 20:12:54 +00008476 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01008477 return true;
8478
8479 nla_put_failure:
8480 genlmsg_cancel(msg, hdr);
8481 nlmsg_free(msg);
8482 return true;
8483}
8484
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008485bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8486{
8487 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8488 addr, gfp);
8489}
8490
8491bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8492 const u8 *addr, gfp_t gfp)
8493{
8494 return __nl80211_unexpected_frame(dev,
8495 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8496 addr, gfp);
8497}
8498
Johannes Berg2e161f72010-08-12 15:38:38 +02008499int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008500 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01008501 int freq, int sig_dbm,
8502 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008503{
Johannes Berg71bbc992012-06-15 15:30:18 +02008504 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008505 struct sk_buff *msg;
8506 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008507
8508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8509 if (!msg)
8510 return -ENOMEM;
8511
Johannes Berg2e161f72010-08-12 15:38:38 +02008512 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008513 if (!hdr) {
8514 nlmsg_free(msg);
8515 return -ENOMEM;
8516 }
8517
David S. Miller9360ffd2012-03-29 04:41:26 -04008518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008519 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8520 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008521 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8522 (sig_dbm &&
8523 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8524 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8525 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008526
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008527 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008528
Eric W. Biederman15e47302012-09-07 20:12:54 +00008529 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008530
8531 nla_put_failure:
8532 genlmsg_cancel(msg, hdr);
8533 nlmsg_free(msg);
8534 return -ENOBUFS;
8535}
8536
Johannes Berg2e161f72010-08-12 15:38:38 +02008537void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008538 struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +02008539 const u8 *buf, size_t len, bool ack,
8540 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008541{
Johannes Berg71bbc992012-06-15 15:30:18 +02008542 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008543 struct sk_buff *msg;
8544 void *hdr;
8545
8546 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8547 if (!msg)
8548 return;
8549
Johannes Berg2e161f72010-08-12 15:38:38 +02008550 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008551 if (!hdr) {
8552 nlmsg_free(msg);
8553 return;
8554 }
8555
David S. Miller9360ffd2012-03-29 04:41:26 -04008556 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008557 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8558 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008559 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8560 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8561 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8562 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008563
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008564 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008565
8566 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8567 return;
8568
8569 nla_put_failure:
8570 genlmsg_cancel(msg, hdr);
8571 nlmsg_free(msg);
8572}
8573
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008574void
8575nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8576 struct net_device *netdev,
8577 enum nl80211_cqm_rssi_threshold_event rssi_event,
8578 gfp_t gfp)
8579{
8580 struct sk_buff *msg;
8581 struct nlattr *pinfoattr;
8582 void *hdr;
8583
Thomas Graf58050fc2012-06-28 03:57:45 +00008584 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008585 if (!msg)
8586 return;
8587
8588 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8589 if (!hdr) {
8590 nlmsg_free(msg);
8591 return;
8592 }
8593
David S. Miller9360ffd2012-03-29 04:41:26 -04008594 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8595 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8596 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008597
8598 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8599 if (!pinfoattr)
8600 goto nla_put_failure;
8601
David S. Miller9360ffd2012-03-29 04:41:26 -04008602 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8603 rssi_event))
8604 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008605
8606 nla_nest_end(msg, pinfoattr);
8607
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008608 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008609
8610 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8611 nl80211_mlme_mcgrp.id, gfp);
8612 return;
8613
8614 nla_put_failure:
8615 genlmsg_cancel(msg, hdr);
8616 nlmsg_free(msg);
8617}
8618
Johannes Berge5497d72011-07-05 16:35:40 +02008619void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8620 struct net_device *netdev, const u8 *bssid,
8621 const u8 *replay_ctr, gfp_t gfp)
8622{
8623 struct sk_buff *msg;
8624 struct nlattr *rekey_attr;
8625 void *hdr;
8626
Thomas Graf58050fc2012-06-28 03:57:45 +00008627 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02008628 if (!msg)
8629 return;
8630
8631 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8632 if (!hdr) {
8633 nlmsg_free(msg);
8634 return;
8635 }
8636
David S. Miller9360ffd2012-03-29 04:41:26 -04008637 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8638 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8639 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8640 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008641
8642 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8643 if (!rekey_attr)
8644 goto nla_put_failure;
8645
David S. Miller9360ffd2012-03-29 04:41:26 -04008646 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8647 NL80211_REPLAY_CTR_LEN, replay_ctr))
8648 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008649
8650 nla_nest_end(msg, rekey_attr);
8651
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008652 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008653
8654 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8655 nl80211_mlme_mcgrp.id, gfp);
8656 return;
8657
8658 nla_put_failure:
8659 genlmsg_cancel(msg, hdr);
8660 nlmsg_free(msg);
8661}
8662
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008663void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8664 struct net_device *netdev, int index,
8665 const u8 *bssid, bool preauth, gfp_t gfp)
8666{
8667 struct sk_buff *msg;
8668 struct nlattr *attr;
8669 void *hdr;
8670
Thomas Graf58050fc2012-06-28 03:57:45 +00008671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008672 if (!msg)
8673 return;
8674
8675 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8676 if (!hdr) {
8677 nlmsg_free(msg);
8678 return;
8679 }
8680
David S. Miller9360ffd2012-03-29 04:41:26 -04008681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8682 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8683 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008684
8685 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8686 if (!attr)
8687 goto nla_put_failure;
8688
David S. Miller9360ffd2012-03-29 04:41:26 -04008689 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8690 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8691 (preauth &&
8692 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8693 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008694
8695 nla_nest_end(msg, attr);
8696
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008697 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008698
8699 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8700 nl80211_mlme_mcgrp.id, gfp);
8701 return;
8702
8703 nla_put_failure:
8704 genlmsg_cancel(msg, hdr);
8705 nlmsg_free(msg);
8706}
8707
Thomas Pedersen53145262012-04-06 13:35:47 -07008708void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8709 struct net_device *netdev, int freq,
8710 enum nl80211_channel_type type, gfp_t gfp)
8711{
8712 struct sk_buff *msg;
8713 void *hdr;
8714
Thomas Graf58050fc2012-06-28 03:57:45 +00008715 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -07008716 if (!msg)
8717 return;
8718
8719 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8720 if (!hdr) {
8721 nlmsg_free(msg);
8722 return;
8723 }
8724
John W. Linville7eab0f62012-04-12 14:25:14 -04008725 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8726 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8727 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8728 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008729
8730 genlmsg_end(msg, hdr);
8731
8732 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8733 nl80211_mlme_mcgrp.id, gfp);
8734 return;
8735
8736 nla_put_failure:
8737 genlmsg_cancel(msg, hdr);
8738 nlmsg_free(msg);
8739}
8740
Johannes Bergc063dbf2010-11-24 08:10:05 +01008741void
Thomas Pedersen84f10702012-07-12 16:17:33 -07008742nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
8743 struct net_device *netdev, const u8 *peer,
8744 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
8745{
8746 struct sk_buff *msg;
8747 struct nlattr *pinfoattr;
8748 void *hdr;
8749
8750 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8751 if (!msg)
8752 return;
8753
8754 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8755 if (!hdr) {
8756 nlmsg_free(msg);
8757 return;
8758 }
8759
8760 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8761 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8762 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8763 goto nla_put_failure;
8764
8765 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8766 if (!pinfoattr)
8767 goto nla_put_failure;
8768
8769 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
8770 goto nla_put_failure;
8771
8772 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
8773 goto nla_put_failure;
8774
8775 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
8776 goto nla_put_failure;
8777
8778 nla_nest_end(msg, pinfoattr);
8779
8780 genlmsg_end(msg, hdr);
8781
8782 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8783 nl80211_mlme_mcgrp.id, gfp);
8784 return;
8785
8786 nla_put_failure:
8787 genlmsg_cancel(msg, hdr);
8788 nlmsg_free(msg);
8789}
8790
8791void
Johannes Bergc063dbf2010-11-24 08:10:05 +01008792nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8793 struct net_device *netdev, const u8 *peer,
8794 u32 num_packets, gfp_t gfp)
8795{
8796 struct sk_buff *msg;
8797 struct nlattr *pinfoattr;
8798 void *hdr;
8799
Thomas Graf58050fc2012-06-28 03:57:45 +00008800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008801 if (!msg)
8802 return;
8803
8804 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8805 if (!hdr) {
8806 nlmsg_free(msg);
8807 return;
8808 }
8809
David S. Miller9360ffd2012-03-29 04:41:26 -04008810 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8811 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8812 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8813 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008814
8815 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8816 if (!pinfoattr)
8817 goto nla_put_failure;
8818
David S. Miller9360ffd2012-03-29 04:41:26 -04008819 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8820 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008821
8822 nla_nest_end(msg, pinfoattr);
8823
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008824 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008825
8826 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8827 nl80211_mlme_mcgrp.id, gfp);
8828 return;
8829
8830 nla_put_failure:
8831 genlmsg_cancel(msg, hdr);
8832 nlmsg_free(msg);
8833}
8834
Johannes Berg7f6cf312011-11-04 11:18:15 +01008835void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8836 u64 cookie, bool acked, gfp_t gfp)
8837{
8838 struct wireless_dev *wdev = dev->ieee80211_ptr;
8839 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8840 struct sk_buff *msg;
8841 void *hdr;
8842 int err;
8843
Thomas Graf58050fc2012-06-28 03:57:45 +00008844 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008845 if (!msg)
8846 return;
8847
8848 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8849 if (!hdr) {
8850 nlmsg_free(msg);
8851 return;
8852 }
8853
David S. Miller9360ffd2012-03-29 04:41:26 -04008854 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8855 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8856 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8857 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8858 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8859 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008860
8861 err = genlmsg_end(msg, hdr);
8862 if (err < 0) {
8863 nlmsg_free(msg);
8864 return;
8865 }
8866
8867 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8868 nl80211_mlme_mcgrp.id, gfp);
8869 return;
8870
8871 nla_put_failure:
8872 genlmsg_cancel(msg, hdr);
8873 nlmsg_free(msg);
8874}
8875EXPORT_SYMBOL(cfg80211_probe_status);
8876
Johannes Berg5e760232011-11-04 11:18:17 +01008877void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8878 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008879 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e760232011-11-04 11:18:17 +01008880{
8881 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8882 struct sk_buff *msg;
8883 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00008884 u32 nlportid = ACCESS_ONCE(rdev->ap_beacons_nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +01008885
Eric W. Biederman15e47302012-09-07 20:12:54 +00008886 if (!nlportid)
Johannes Berg5e760232011-11-04 11:18:17 +01008887 return;
8888
8889 msg = nlmsg_new(len + 100, gfp);
8890 if (!msg)
8891 return;
8892
8893 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8894 if (!hdr) {
8895 nlmsg_free(msg);
8896 return;
8897 }
8898
David S. Miller9360ffd2012-03-29 04:41:26 -04008899 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8900 (freq &&
8901 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8902 (sig_dbm &&
8903 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8904 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8905 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +01008906
8907 genlmsg_end(msg, hdr);
8908
Eric W. Biederman15e47302012-09-07 20:12:54 +00008909 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +01008910 return;
8911
8912 nla_put_failure:
8913 genlmsg_cancel(msg, hdr);
8914 nlmsg_free(msg);
8915}
8916EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8917
Jouni Malinen026331c2010-02-15 12:53:10 +02008918static int nl80211_netlink_notify(struct notifier_block * nb,
8919 unsigned long state,
8920 void *_notify)
8921{
8922 struct netlink_notify *notify = _notify;
8923 struct cfg80211_registered_device *rdev;
8924 struct wireless_dev *wdev;
8925
8926 if (state != NETLINK_URELEASE)
8927 return NOTIFY_DONE;
8928
8929 rcu_read_lock();
8930
Johannes Berg5e760232011-11-04 11:18:17 +01008931 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008932 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +00008933 cfg80211_mlme_unregister_socket(wdev, notify->portid);
8934 if (rdev->ap_beacons_nlportid == notify->portid)
8935 rdev->ap_beacons_nlportid = 0;
Johannes Berg5e760232011-11-04 11:18:17 +01008936 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008937
8938 rcu_read_unlock();
8939
8940 return NOTIFY_DONE;
8941}
8942
8943static struct notifier_block nl80211_netlink_notifier = {
8944 .notifier_call = nl80211_netlink_notify,
8945};
8946
Johannes Berg55682962007-09-20 13:09:35 -04008947/* initialisation/exit functions */
8948
8949int nl80211_init(void)
8950{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008951 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008952
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008953 err = genl_register_family_with_ops(&nl80211_fam,
8954 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008955 if (err)
8956 return err;
8957
Johannes Berg55682962007-09-20 13:09:35 -04008958 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8959 if (err)
8960 goto err_out;
8961
Johannes Berg2a519312009-02-10 21:25:55 +01008962 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8963 if (err)
8964 goto err_out;
8965
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008966 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8967 if (err)
8968 goto err_out;
8969
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008970 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8971 if (err)
8972 goto err_out;
8973
Johannes Bergaff89a92009-07-01 21:26:51 +02008974#ifdef CONFIG_NL80211_TESTMODE
8975 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8976 if (err)
8977 goto err_out;
8978#endif
8979
Jouni Malinen026331c2010-02-15 12:53:10 +02008980 err = netlink_register_notifier(&nl80211_netlink_notifier);
8981 if (err)
8982 goto err_out;
8983
Johannes Berg55682962007-09-20 13:09:35 -04008984 return 0;
8985 err_out:
8986 genl_unregister_family(&nl80211_fam);
8987 return err;
8988}
8989
8990void nl80211_exit(void)
8991{
Jouni Malinen026331c2010-02-15 12:53:10 +02008992 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008993 genl_unregister_family(&nl80211_fam);
8994}