blob: 74d8123ada7701b4be8afa078f896f807abfaf0d [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 Malinen36aedc902008-08-25 11:58:58 +0300276
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800277 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700278 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700279
Johannes Berg6c739412011-11-03 09:27:01 +0100280 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200281
282 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
283 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
284 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100285 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
286 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200287
288 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_SSID_LEN },
290 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
291 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200292 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300293 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300294 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300295 [NL80211_ATTR_STA_FLAGS2] = {
296 .len = sizeof(struct nl80211_sta_flag_update),
297 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300298 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200301 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
302 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
303 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200304 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100305 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100306 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
307 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100308 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
309 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200310 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200311 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
313 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200314 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200315 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300316 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200317 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200320 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900321 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
322 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100323 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100324 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100325 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200326 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700327 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300328 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200329 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200330 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300331 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300332 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
334 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530336 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300337 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530338 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300339 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Johannes Berg55682962007-09-20 13:09:35 -0400358};
359
Johannes Berge31b8212010-10-05 19:39:30 +0200360/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000361static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200362 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200363 [NL80211_KEY_IDX] = { .type = NLA_U8 },
364 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200365 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200366 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
367 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200368 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100369 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
370};
371
372/* policy for the key default flags */
373static const struct nla_policy
374nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
375 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
376 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200377};
378
Johannes Bergff1b6e62011-05-04 15:37:28 +0200379/* policy for WoWLAN attributes */
380static const struct nla_policy
381nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
382 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
385 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200386 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
389 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200390};
391
Johannes Berge5497d72011-07-05 16:35:40 +0200392/* policy for GTK rekey offload attributes */
393static const struct nla_policy
394nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
395 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
396 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
397 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
398};
399
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300400static const struct nla_policy
401nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200402 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300403 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700404 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300405};
406
Holger Schuriga0438972009-11-11 11:30:02 +0100407/* ifidx get helper */
408static int nl80211_get_ifidx(struct netlink_callback *cb)
409{
410 int res;
411
412 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
413 nl80211_fam.attrbuf, nl80211_fam.maxattr,
414 nl80211_policy);
415 if (res)
416 return res;
417
418 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
419 return -EINVAL;
420
421 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
422 if (!res)
423 return -EINVAL;
424 return res;
425}
426
Johannes Berg67748892010-10-04 21:14:06 +0200427static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
428 struct netlink_callback *cb,
429 struct cfg80211_registered_device **rdev,
430 struct net_device **dev)
431{
432 int ifidx = cb->args[0];
433 int err;
434
435 if (!ifidx)
436 ifidx = nl80211_get_ifidx(cb);
437 if (ifidx < 0)
438 return ifidx;
439
440 cb->args[0] = ifidx;
441
442 rtnl_lock();
443
444 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
445 if (!*dev) {
446 err = -ENODEV;
447 goto out_rtnl;
448 }
449
450 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
Felix Fietkau3cc25e52010-10-31 15:31:54 +0100451 if (IS_ERR(*rdev)) {
452 err = PTR_ERR(*rdev);
Johannes Berg67748892010-10-04 21:14:06 +0200453 goto out_rtnl;
454 }
455
456 return 0;
457 out_rtnl:
458 rtnl_unlock();
459 return err;
460}
461
462static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
463{
464 cfg80211_unlock_rdev(rdev);
465 rtnl_unlock();
466}
467
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100468/* IE validation */
469static bool is_valid_ie_attr(const struct nlattr *attr)
470{
471 const u8 *pos;
472 int len;
473
474 if (!attr)
475 return true;
476
477 pos = nla_data(attr);
478 len = nla_len(attr);
479
480 while (len) {
481 u8 elemlen;
482
483 if (len < 2)
484 return false;
485 len -= 2;
486
487 elemlen = pos[1];
488 if (elemlen > len)
489 return false;
490
491 len -= elemlen;
492 pos += 2 + elemlen;
493 }
494
495 return true;
496}
497
Johannes Berg55682962007-09-20 13:09:35 -0400498/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000499static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400500 int flags, u8 cmd)
501{
502 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000503 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400504}
505
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400506static int nl80211_msg_put_channel(struct sk_buff *msg,
507 struct ieee80211_channel *chan)
508{
David S. Miller9360ffd2012-03-29 04:41:26 -0400509 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
510 chan->center_freq))
511 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400512
David S. Miller9360ffd2012-03-29 04:41:26 -0400513 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
514 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
515 goto nla_put_failure;
516 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
517 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
518 goto nla_put_failure;
519 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
520 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
521 goto nla_put_failure;
522 if ((chan->flags & IEEE80211_CHAN_RADAR) &&
523 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
524 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400525
David S. Miller9360ffd2012-03-29 04:41:26 -0400526 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
527 DBM_TO_MBM(chan->max_power)))
528 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400529
530 return 0;
531
532 nla_put_failure:
533 return -ENOBUFS;
534}
535
Johannes Berg55682962007-09-20 13:09:35 -0400536/* netlink command implementations */
537
Johannes Bergb9454e82009-07-08 13:29:08 +0200538struct key_parse {
539 struct key_params p;
540 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200541 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200542 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100543 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200544};
545
546static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
547{
548 struct nlattr *tb[NL80211_KEY_MAX + 1];
549 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
550 nl80211_key_policy);
551 if (err)
552 return err;
553
554 k->def = !!tb[NL80211_KEY_DEFAULT];
555 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
556
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100557 if (k->def) {
558 k->def_uni = true;
559 k->def_multi = true;
560 }
561 if (k->defmgmt)
562 k->def_multi = true;
563
Johannes Bergb9454e82009-07-08 13:29:08 +0200564 if (tb[NL80211_KEY_IDX])
565 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
566
567 if (tb[NL80211_KEY_DATA]) {
568 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
569 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
570 }
571
572 if (tb[NL80211_KEY_SEQ]) {
573 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
574 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
575 }
576
577 if (tb[NL80211_KEY_CIPHER])
578 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
579
Johannes Berge31b8212010-10-05 19:39:30 +0200580 if (tb[NL80211_KEY_TYPE]) {
581 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
582 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
583 return -EINVAL;
584 }
585
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100586 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
587 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100588 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
589 tb[NL80211_KEY_DEFAULT_TYPES],
590 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100591 if (err)
592 return err;
593
594 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
595 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
596 }
597
Johannes Bergb9454e82009-07-08 13:29:08 +0200598 return 0;
599}
600
601static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
602{
603 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
604 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
605 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
606 }
607
608 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
609 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
610 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
611 }
612
613 if (info->attrs[NL80211_ATTR_KEY_IDX])
614 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
615
616 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
617 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
618
619 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
620 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
621
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100622 if (k->def) {
623 k->def_uni = true;
624 k->def_multi = true;
625 }
626 if (k->defmgmt)
627 k->def_multi = true;
628
Johannes Berge31b8212010-10-05 19:39:30 +0200629 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
630 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
631 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
632 return -EINVAL;
633 }
634
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100635 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
636 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
637 int err = nla_parse_nested(
638 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
639 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
640 nl80211_key_default_policy);
641 if (err)
642 return err;
643
644 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
645 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
646 }
647
Johannes Bergb9454e82009-07-08 13:29:08 +0200648 return 0;
649}
650
651static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
652{
653 int err;
654
655 memset(k, 0, sizeof(*k));
656 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200657 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200658
659 if (info->attrs[NL80211_ATTR_KEY])
660 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
661 else
662 err = nl80211_parse_key_old(info, k);
663
664 if (err)
665 return err;
666
667 if (k->def && k->defmgmt)
668 return -EINVAL;
669
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 if (k->defmgmt) {
671 if (k->def_uni || !k->def_multi)
672 return -EINVAL;
673 }
674
Johannes Bergb9454e82009-07-08 13:29:08 +0200675 if (k->idx != -1) {
676 if (k->defmgmt) {
677 if (k->idx < 4 || k->idx > 5)
678 return -EINVAL;
679 } else if (k->def) {
680 if (k->idx < 0 || k->idx > 3)
681 return -EINVAL;
682 } else {
683 if (k->idx < 0 || k->idx > 5)
684 return -EINVAL;
685 }
686 }
687
688 return 0;
689}
690
Johannes Bergfffd0932009-07-08 14:22:54 +0200691static struct cfg80211_cached_keys *
692nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
693 struct nlattr *keys)
694{
695 struct key_parse parse;
696 struct nlattr *key;
697 struct cfg80211_cached_keys *result;
698 int rem, err, def = 0;
699
700 result = kzalloc(sizeof(*result), GFP_KERNEL);
701 if (!result)
702 return ERR_PTR(-ENOMEM);
703
704 result->def = -1;
705 result->defmgmt = -1;
706
707 nla_for_each_nested(key, keys, rem) {
708 memset(&parse, 0, sizeof(parse));
709 parse.idx = -1;
710
711 err = nl80211_parse_key_new(key, &parse);
712 if (err)
713 goto error;
714 err = -EINVAL;
715 if (!parse.p.key)
716 goto error;
717 if (parse.idx < 0 || parse.idx > 4)
718 goto error;
719 if (parse.def) {
720 if (def)
721 goto error;
722 def = 1;
723 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100724 if (!parse.def_uni || !parse.def_multi)
725 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200726 } else if (parse.defmgmt)
727 goto error;
728 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200729 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200730 if (err)
731 goto error;
732 result->params[parse.idx].cipher = parse.p.cipher;
733 result->params[parse.idx].key_len = parse.p.key_len;
734 result->params[parse.idx].key = result->data[parse.idx];
735 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
736 }
737
738 return result;
739 error:
740 kfree(result);
741 return ERR_PTR(err);
742}
743
744static int nl80211_key_allowed(struct wireless_dev *wdev)
745{
746 ASSERT_WDEV_LOCK(wdev);
747
Johannes Bergfffd0932009-07-08 14:22:54 +0200748 switch (wdev->iftype) {
749 case NL80211_IFTYPE_AP:
750 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200751 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700752 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200753 break;
754 case NL80211_IFTYPE_ADHOC:
755 if (!wdev->current_bss)
756 return -ENOLINK;
757 break;
758 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200759 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200760 if (wdev->sme_state != CFG80211_SME_CONNECTED)
761 return -ENOLINK;
762 break;
763 default:
764 return -EINVAL;
765 }
766
767 return 0;
768}
769
Johannes Berg7527a782011-05-13 10:58:57 +0200770static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
771{
772 struct nlattr *nl_modes = nla_nest_start(msg, attr);
773 int i;
774
775 if (!nl_modes)
776 goto nla_put_failure;
777
778 i = 0;
779 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400780 if ((ifmodes & 1) && nla_put_flag(msg, i))
781 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200782 ifmodes >>= 1;
783 i++;
784 }
785
786 nla_nest_end(msg, nl_modes);
787 return 0;
788
789nla_put_failure:
790 return -ENOBUFS;
791}
792
793static int nl80211_put_iface_combinations(struct wiphy *wiphy,
794 struct sk_buff *msg)
795{
796 struct nlattr *nl_combis;
797 int i, j;
798
799 nl_combis = nla_nest_start(msg,
800 NL80211_ATTR_INTERFACE_COMBINATIONS);
801 if (!nl_combis)
802 goto nla_put_failure;
803
804 for (i = 0; i < wiphy->n_iface_combinations; i++) {
805 const struct ieee80211_iface_combination *c;
806 struct nlattr *nl_combi, *nl_limits;
807
808 c = &wiphy->iface_combinations[i];
809
810 nl_combi = nla_nest_start(msg, i + 1);
811 if (!nl_combi)
812 goto nla_put_failure;
813
814 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
815 if (!nl_limits)
816 goto nla_put_failure;
817
818 for (j = 0; j < c->n_limits; j++) {
819 struct nlattr *nl_limit;
820
821 nl_limit = nla_nest_start(msg, j + 1);
822 if (!nl_limit)
823 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400824 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
825 c->limits[j].max))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
828 c->limits[j].types))
829 goto nla_put_failure;
830 nla_nest_end(msg, nl_limit);
831 }
832
833 nla_nest_end(msg, nl_limits);
834
David S. Miller9360ffd2012-03-29 04:41:26 -0400835 if (c->beacon_int_infra_match &&
836 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
837 goto nla_put_failure;
838 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
839 c->num_different_channels) ||
840 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
841 c->max_interfaces))
842 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200843
844 nla_nest_end(msg, nl_combi);
845 }
846
847 nla_nest_end(msg, nl_combis);
848
849 return 0;
850nla_put_failure:
851 return -ENOBUFS;
852}
853
Eric W. Biederman15e47302012-09-07 20:12:54 +0000854static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Berg55682962007-09-20 13:09:35 -0400855 struct cfg80211_registered_device *dev)
856{
857 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100858 struct nlattr *nl_bands, *nl_band;
859 struct nlattr *nl_freqs, *nl_freq;
860 struct nlattr *nl_rates, *nl_rate;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100861 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100862 enum ieee80211_band band;
863 struct ieee80211_channel *chan;
864 struct ieee80211_rate *rate;
865 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +0200866 const struct ieee80211_txrx_stypes *mgmt_stypes =
867 dev->wiphy.mgmt_stypes;
Johannes Berg55682962007-09-20 13:09:35 -0400868
Eric W. Biederman15e47302012-09-07 20:12:54 +0000869 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -0400870 if (!hdr)
871 return -1;
872
David S. Miller9360ffd2012-03-29 04:41:26 -0400873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
874 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) ||
875 nla_put_u32(msg, NL80211_ATTR_GENERATION,
876 cfg80211_rdev_list_generation) ||
877 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
878 dev->wiphy.retry_short) ||
879 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
880 dev->wiphy.retry_long) ||
881 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
882 dev->wiphy.frag_threshold) ||
883 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
884 dev->wiphy.rts_threshold) ||
885 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
886 dev->wiphy.coverage_class) ||
887 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
888 dev->wiphy.max_scan_ssids) ||
889 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
890 dev->wiphy.max_sched_scan_ssids) ||
891 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
892 dev->wiphy.max_scan_ie_len) ||
893 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
894 dev->wiphy.max_sched_scan_ie_len) ||
895 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
896 dev->wiphy.max_match_sets))
897 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200898
David S. Miller9360ffd2012-03-29 04:41:26 -0400899 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
900 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
901 goto nla_put_failure;
902 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
903 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
904 goto nla_put_failure;
905 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
906 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
907 goto nla_put_failure;
908 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
909 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
910 goto nla_put_failure;
911 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
912 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
913 goto nla_put_failure;
914 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
915 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
916 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +0200917
David S. Miller9360ffd2012-03-29 04:41:26 -0400918 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
919 sizeof(u32) * dev->wiphy.n_cipher_suites,
920 dev->wiphy.cipher_suites))
921 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +0100922
David S. Miller9360ffd2012-03-29 04:41:26 -0400923 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
924 dev->wiphy.max_num_pmkids))
925 goto nla_put_failure;
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530926
David S. Miller9360ffd2012-03-29 04:41:26 -0400927 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
928 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
929 goto nla_put_failure;
Johannes Berg25e47c12009-04-02 20:14:06 +0200930
David S. Miller9360ffd2012-03-29 04:41:26 -0400931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
932 dev->wiphy.available_antennas_tx) ||
933 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
934 dev->wiphy.available_antennas_rx))
935 goto nla_put_failure;
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100936
David S. Miller9360ffd2012-03-29 04:41:26 -0400937 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
938 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
939 dev->wiphy.probe_resp_offload))
940 goto nla_put_failure;
Arik Nemtsov87bbbe22011-11-10 11:28:55 +0200941
Bruno Randolf7f531e02010-12-16 11:30:22 +0900942 if ((dev->wiphy.available_antennas_tx ||
943 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900944 u32 tx_ant = 0, rx_ant = 0;
945 int res;
946 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
947 if (!res) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400948 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
949 tx_ant) ||
950 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX,
951 rx_ant))
952 goto nla_put_failure;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900953 }
954 }
955
Johannes Berg7527a782011-05-13 10:58:57 +0200956 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
957 dev->wiphy.interface_modes))
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700958 goto nla_put_failure;
959
Johannes Bergee688b002008-01-24 19:38:39 +0100960 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
961 if (!nl_bands)
962 goto nla_put_failure;
963
964 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
965 if (!dev->wiphy.bands[band])
966 continue;
967
968 nl_band = nla_nest_start(msg, band);
969 if (!nl_band)
970 goto nla_put_failure;
971
Johannes Bergd51626d2008-10-09 12:20:13 +0200972 /* add HT info */
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
974 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
975 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
976 &dev->wiphy.bands[band]->ht_cap.mcs) ||
977 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
978 dev->wiphy.bands[band]->ht_cap.cap) ||
979 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
980 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
981 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
982 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
983 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +0200984
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +0000985 /* add VHT info */
986 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
987 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
988 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
989 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
990 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
991 dev->wiphy.bands[band]->vht_cap.cap)))
992 goto nla_put_failure;
993
Johannes Bergee688b002008-01-24 19:38:39 +0100994 /* add frequencies */
995 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
996 if (!nl_freqs)
997 goto nla_put_failure;
998
999 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1000 nl_freq = nla_nest_start(msg, i);
1001 if (!nl_freq)
1002 goto nla_put_failure;
1003
1004 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +01001005
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001006 if (nl80211_msg_put_channel(msg, chan))
1007 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001008
Johannes Bergee688b002008-01-24 19:38:39 +01001009 nla_nest_end(msg, nl_freq);
1010 }
1011
1012 nla_nest_end(msg, nl_freqs);
1013
1014 /* add bitrates */
1015 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1016 if (!nl_rates)
1017 goto nla_put_failure;
1018
1019 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1020 nl_rate = nla_nest_start(msg, i);
1021 if (!nl_rate)
1022 goto nla_put_failure;
1023
1024 rate = &dev->wiphy.bands[band]->bitrates[i];
David S. Miller9360ffd2012-03-29 04:41:26 -04001025 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1026 rate->bitrate))
1027 goto nla_put_failure;
1028 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1029 nla_put_flag(msg,
1030 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1031 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001032
1033 nla_nest_end(msg, nl_rate);
1034 }
1035
1036 nla_nest_end(msg, nl_rates);
1037
1038 nla_nest_end(msg, nl_band);
1039 }
1040 nla_nest_end(msg, nl_bands);
1041
Johannes Berg8fdc6212009-03-14 09:34:01 +01001042 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1043 if (!nl_cmds)
1044 goto nla_put_failure;
1045
1046 i = 0;
1047#define CMD(op, n) \
1048 do { \
1049 if (dev->ops->op) { \
1050 i++; \
David S. Miller9360ffd2012-03-29 04:41:26 -04001051 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1052 goto nla_put_failure; \
Johannes Berg8fdc6212009-03-14 09:34:01 +01001053 } \
1054 } while (0)
1055
1056 CMD(add_virtual_intf, NEW_INTERFACE);
1057 CMD(change_virtual_intf, SET_INTERFACE);
1058 CMD(add_key, NEW_KEY);
Johannes Berg88600202012-02-13 15:17:18 +01001059 CMD(start_ap, START_AP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001060 CMD(add_station, NEW_STATION);
1061 CMD(add_mpath, NEW_MPATH);
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001062 CMD(update_mesh_config, SET_MESH_CONFIG);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001063 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001064 CMD(auth, AUTHENTICATE);
1065 CMD(assoc, ASSOCIATE);
1066 CMD(deauth, DEAUTHENTICATE);
1067 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +02001068 CMD(join_ibss, JOIN_IBSS);
Johannes Berg29cbe682010-12-03 09:20:44 +01001069 CMD(join_mesh, JOIN_MESH);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01001070 CMD(set_pmksa, SET_PMKSA);
1071 CMD(del_pmksa, DEL_PMKSA);
1072 CMD(flush_pmksa, FLUSH_PMKSA);
Johannes Berg7c4ef712011-11-18 15:33:48 +01001073 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1074 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02001075 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
Johannes Berg2e161f72010-08-12 15:38:38 +02001076 CMD(mgmt_tx, FRAME);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001077 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Johannes Berg5be83de2009-11-19 00:56:28 +01001078 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg463d0182009-07-14 00:33:35 +02001079 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001080 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1081 goto nla_put_failure;
Johannes Berg463d0182009-07-14 00:33:35 +02001082 }
Johannes Berge8c9bd52012-06-06 08:18:22 +02001083 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
Johannes Bergcc1d2802012-05-16 23:50:20 +02001084 dev->ops->join_mesh) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001085 i++;
1086 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1087 goto nla_put_failure;
1088 }
Bill Jordane8347eb2010-10-01 13:54:28 -04001089 CMD(set_wds_peer, SET_WDS_PEER);
Arik Nemtsov109086c2011-09-28 14:12:50 +03001090 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1091 CMD(tdls_mgmt, TDLS_MGMT);
1092 CMD(tdls_oper, TDLS_OPER);
1093 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03001094 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1095 CMD(sched_scan_start, START_SCHED_SCAN);
Johannes Berg7f6cf312011-11-04 11:18:15 +01001096 CMD(probe_client, PROBE_CLIENT);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01001097 CMD(set_noack_map, SET_NOACK_MAP);
Johannes Berg5e7602302011-11-04 11:18:17 +01001098 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1099 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001100 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1101 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01001102 }
Johannes Berg98104fde2012-06-16 00:19:54 +02001103 CMD(start_p2p_device, START_P2P_DEVICE);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001104
Kalle Valo4745fc02011-11-17 19:06:10 +02001105#ifdef CONFIG_NL80211_TESTMODE
1106 CMD(testmode_cmd, TESTMODE);
1107#endif
1108
Johannes Berg8fdc6212009-03-14 09:34:01 +01001109#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001110
Johannes Berg6829c872009-07-02 09:13:27 +02001111 if (dev->ops->connect || dev->ops->auth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001112 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001113 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1114 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001115 }
1116
Johannes Berg6829c872009-07-02 09:13:27 +02001117 if (dev->ops->disconnect || dev->ops->deauth) {
Samuel Ortizb23aa672009-07-01 21:26:54 +02001118 i++;
David S. Miller9360ffd2012-03-29 04:41:26 -04001119 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1120 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001121 }
1122
Johannes Berg8fdc6212009-03-14 09:34:01 +01001123 nla_nest_end(msg, nl_cmds);
1124
Johannes Berg7c4ef712011-11-18 15:33:48 +01001125 if (dev->ops->remain_on_channel &&
David S. Miller9360ffd2012-03-29 04:41:26 -04001126 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1127 nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1128 dev->wiphy.max_remain_on_channel_duration))
1129 goto nla_put_failure;
Johannes Berga2939112010-12-14 17:54:28 +01001130
David S. Miller9360ffd2012-03-29 04:41:26 -04001131 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1132 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1133 goto nla_put_failure;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001134
Johannes Berg2e161f72010-08-12 15:38:38 +02001135 if (mgmt_stypes) {
1136 u16 stypes;
1137 struct nlattr *nl_ftypes, *nl_ifs;
1138 enum nl80211_iftype ift;
1139
1140 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1141 if (!nl_ifs)
1142 goto nla_put_failure;
1143
1144 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1145 nl_ftypes = nla_nest_start(msg, ift);
1146 if (!nl_ftypes)
1147 goto nla_put_failure;
1148 i = 0;
1149 stypes = mgmt_stypes[ift].tx;
1150 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001151 if ((stypes & 1) &&
1152 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1153 (i << 4) | IEEE80211_FTYPE_MGMT))
1154 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001155 stypes >>= 1;
1156 i++;
1157 }
1158 nla_nest_end(msg, nl_ftypes);
1159 }
1160
Johannes Berg74b70a42010-08-24 12:15:53 +02001161 nla_nest_end(msg, nl_ifs);
1162
Johannes Berg2e161f72010-08-12 15:38:38 +02001163 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1164 if (!nl_ifs)
1165 goto nla_put_failure;
1166
1167 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1168 nl_ftypes = nla_nest_start(msg, ift);
1169 if (!nl_ftypes)
1170 goto nla_put_failure;
1171 i = 0;
1172 stypes = mgmt_stypes[ift].rx;
1173 while (stypes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001174 if ((stypes & 1) &&
1175 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1176 (i << 4) | IEEE80211_FTYPE_MGMT))
1177 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001178 stypes >>= 1;
1179 i++;
1180 }
1181 nla_nest_end(msg, nl_ftypes);
1182 }
1183 nla_nest_end(msg, nl_ifs);
1184 }
1185
Johannes Bergdfb89c52012-06-27 09:23:48 +02001186#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001187 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
1188 struct nlattr *nl_wowlan;
1189
1190 nl_wowlan = nla_nest_start(msg,
1191 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1192 if (!nl_wowlan)
1193 goto nla_put_failure;
1194
David S. Miller9360ffd2012-03-29 04:41:26 -04001195 if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) &&
1196 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
1197 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) &&
1198 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
1199 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) &&
1200 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
1201 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
1202 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
1203 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
1204 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
1205 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
1206 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
1207 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
1208 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
1209 ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
1210 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1211 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001212 if (dev->wiphy.wowlan.n_patterns) {
1213 struct nl80211_wowlan_pattern_support pat = {
1214 .max_patterns = dev->wiphy.wowlan.n_patterns,
1215 .min_pattern_len =
1216 dev->wiphy.wowlan.pattern_min_len,
1217 .max_pattern_len =
1218 dev->wiphy.wowlan.pattern_max_len,
1219 };
David S. Miller9360ffd2012-03-29 04:41:26 -04001220 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1221 sizeof(pat), &pat))
1222 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001223 }
1224
1225 nla_nest_end(msg, nl_wowlan);
1226 }
Johannes Bergdfb89c52012-06-27 09:23:48 +02001227#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02001228
Johannes Berg7527a782011-05-13 10:58:57 +02001229 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1230 dev->wiphy.software_iftypes))
1231 goto nla_put_failure;
1232
1233 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1234 goto nla_put_failure;
1235
David S. Miller9360ffd2012-03-29 04:41:26 -04001236 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1237 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1238 dev->wiphy.ap_sme_capa))
1239 goto nla_put_failure;
Johannes Berg562a7482011-11-07 12:39:33 +01001240
David S. Miller9360ffd2012-03-29 04:41:26 -04001241 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS,
1242 dev->wiphy.features))
1243 goto nla_put_failure;
Johannes Berg1f074bd2011-11-06 14:13:33 +01001244
David S. Miller9360ffd2012-03-29 04:41:26 -04001245 if (dev->wiphy.ht_capa_mod_mask &&
1246 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1247 sizeof(*dev->wiphy.ht_capa_mod_mask),
1248 dev->wiphy.ht_capa_mod_mask))
1249 goto nla_put_failure;
Ben Greear7e7c8922011-11-18 11:31:59 -08001250
Johannes Berg55682962007-09-20 13:09:35 -04001251 return genlmsg_end(msg, hdr);
1252
1253 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001254 genlmsg_cancel(msg, hdr);
1255 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001256}
1257
1258static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1259{
1260 int idx = 0;
1261 int start = cb->args[0];
1262 struct cfg80211_registered_device *dev;
1263
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001264 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +02001265 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001266 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1267 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001268 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001269 continue;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001270 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001271 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +02001272 dev) < 0) {
1273 idx--;
Johannes Berg55682962007-09-20 13:09:35 -04001274 break;
Julius Volzb4637272008-07-08 14:02:19 +02001275 }
Johannes Berg55682962007-09-20 13:09:35 -04001276 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001277 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001278
1279 cb->args[0] = idx;
1280
1281 return skb->len;
1282}
1283
1284static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1285{
1286 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001287 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001288
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001290 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001291 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001292
Eric W. Biederman15e47302012-09-07 20:12:54 +00001293 if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001294 nlmsg_free(msg);
1295 return -ENOBUFS;
1296 }
Johannes Berg55682962007-09-20 13:09:35 -04001297
Johannes Berg134e6372009-07-10 09:51:34 +00001298 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001299}
1300
Jouni Malinen31888482008-10-30 16:59:24 +02001301static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1302 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1303 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1304 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1305 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1306 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1307};
1308
1309static int parse_txq_params(struct nlattr *tb[],
1310 struct ieee80211_txq_params *txq_params)
1311{
Johannes Berga3304b02012-03-28 11:04:24 +02001312 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001313 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1314 !tb[NL80211_TXQ_ATTR_AIFS])
1315 return -EINVAL;
1316
Johannes Berga3304b02012-03-28 11:04:24 +02001317 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001318 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1319 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1320 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1321 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1322
Johannes Berga3304b02012-03-28 11:04:24 +02001323 if (txq_params->ac >= NL80211_NUM_ACS)
1324 return -EINVAL;
1325
Jouni Malinen31888482008-10-30 16:59:24 +02001326 return 0;
1327}
1328
Johannes Bergf444de02010-05-05 15:25:02 +02001329static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1330{
1331 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001332 * You can only set the channel explicitly for WDS interfaces,
1333 * all others have their channel managed via their respective
1334 * "establish a connection" command (connect, join, ...)
1335 *
1336 * For AP/GO and mesh mode, the channel can be set with the
1337 * channel userspace API, but is only stored and passed to the
1338 * low-level driver when the AP starts or the mesh is joined.
1339 * This is for backward compatibility, userspace can also give
1340 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001341 *
1342 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001343 * whatever else is going on, so they have their own special
1344 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001345 */
1346 return !wdev ||
1347 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001348 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001349 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1350 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001351}
1352
Johannes Bergcd6c6592012-05-10 21:27:18 +02001353static bool nl80211_valid_channel_type(struct genl_info *info,
1354 enum nl80211_channel_type *channel_type)
1355{
1356 enum nl80211_channel_type tmp;
1357
1358 if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
1359 return false;
1360
1361 tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1362 if (tmp != NL80211_CHAN_NO_HT &&
1363 tmp != NL80211_CHAN_HT20 &&
1364 tmp != NL80211_CHAN_HT40PLUS &&
1365 tmp != NL80211_CHAN_HT40MINUS)
1366 return false;
1367
1368 if (channel_type)
1369 *channel_type = tmp;
1370
1371 return true;
1372}
1373
Johannes Bergf444de02010-05-05 15:25:02 +02001374static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1375 struct wireless_dev *wdev,
1376 struct genl_info *info)
1377{
Johannes Bergaa430da2012-05-16 23:50:18 +02001378 struct ieee80211_channel *channel;
Johannes Bergf444de02010-05-05 15:25:02 +02001379 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1380 u32 freq;
1381 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001382 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1383
1384 if (wdev)
1385 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001386
1387 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1388 return -EINVAL;
1389
1390 if (!nl80211_can_set_dev_channel(wdev))
1391 return -EOPNOTSUPP;
1392
Johannes Bergcd6c6592012-05-10 21:27:18 +02001393 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
1394 !nl80211_valid_channel_type(info, &channel_type))
1395 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001396
1397 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1398
1399 mutex_lock(&rdev->devlist_mtx);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001400 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001401 case NL80211_IFTYPE_AP:
1402 case NL80211_IFTYPE_P2P_GO:
1403 if (wdev->beacon_interval) {
1404 result = -EBUSY;
1405 break;
1406 }
1407 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1408 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1409 channel,
1410 channel_type)) {
1411 result = -EINVAL;
1412 break;
1413 }
1414 wdev->preset_chan = channel;
1415 wdev->preset_chantype = channel_type;
1416 result = 0;
1417 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001418 case NL80211_IFTYPE_MESH_POINT:
1419 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1420 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001421 case NL80211_IFTYPE_MONITOR:
1422 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1423 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001424 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001425 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001426 }
1427 mutex_unlock(&rdev->devlist_mtx);
1428
1429 return result;
1430}
1431
1432static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1433{
Johannes Berg4c476992010-10-04 21:36:35 +02001434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1435 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001436
Johannes Berg4c476992010-10-04 21:36:35 +02001437 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001438}
1439
Bill Jordane8347eb2010-10-01 13:54:28 -04001440static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1441{
Johannes Berg43b19952010-10-07 13:10:30 +02001442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1443 struct net_device *dev = info->user_ptr[1];
1444 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001445 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001446
1447 if (!info->attrs[NL80211_ATTR_MAC])
1448 return -EINVAL;
1449
Johannes Berg43b19952010-10-07 13:10:30 +02001450 if (netif_running(dev))
1451 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001452
Johannes Berg43b19952010-10-07 13:10:30 +02001453 if (!rdev->ops->set_wds_peer)
1454 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001455
Johannes Berg43b19952010-10-07 13:10:30 +02001456 if (wdev->iftype != NL80211_IFTYPE_WDS)
1457 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001458
1459 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg43b19952010-10-07 13:10:30 +02001460 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001461}
1462
1463
Johannes Berg55682962007-09-20 13:09:35 -04001464static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1465{
1466 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001467 struct net_device *netdev = NULL;
1468 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001469 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001470 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001471 u32 changed;
1472 u8 retry_short = 0, retry_long = 0;
1473 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001474 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001475
Johannes Bergf444de02010-05-05 15:25:02 +02001476 /*
1477 * Try to find the wiphy and netdev. Normally this
1478 * function shouldn't need the netdev, but this is
1479 * done for backward compatibility -- previously
1480 * setting the channel was done per wiphy, but now
1481 * it is per netdev. Previous userland like hostapd
1482 * also passed a netdev to set_wiphy, so that it is
1483 * possible to let that go to the right netdev!
1484 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001485 mutex_lock(&cfg80211_mutex);
1486
Johannes Bergf444de02010-05-05 15:25:02 +02001487 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1488 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1489
1490 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1491 if (netdev && netdev->ieee80211_ptr) {
1492 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1493 mutex_lock(&rdev->mtx);
1494 } else
1495 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001496 }
1497
Johannes Bergf444de02010-05-05 15:25:02 +02001498 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001499 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1500 info->attrs);
Johannes Bergf444de02010-05-05 15:25:02 +02001501 if (IS_ERR(rdev)) {
1502 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02001503 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001504 }
1505 wdev = NULL;
1506 netdev = NULL;
1507 result = 0;
1508
1509 mutex_lock(&rdev->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001510 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
Johannes Bergf444de02010-05-05 15:25:02 +02001511 wdev = netdev->ieee80211_ptr;
1512 else
1513 wdev = NULL;
1514
1515 /*
1516 * end workaround code, by now the rdev is available
1517 * and locked, and wdev may or may not be NULL.
1518 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001519
1520 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001521 result = cfg80211_dev_rename(
1522 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001523
1524 mutex_unlock(&cfg80211_mutex);
1525
1526 if (result)
1527 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001528
Jouni Malinen31888482008-10-30 16:59:24 +02001529 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1530 struct ieee80211_txq_params txq_params;
1531 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1532
1533 if (!rdev->ops->set_txq_params) {
1534 result = -EOPNOTSUPP;
1535 goto bad_res;
1536 }
1537
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001538 if (!netdev) {
1539 result = -EINVAL;
1540 goto bad_res;
1541 }
1542
Johannes Berg133a3ff2011-11-03 14:50:13 +01001543 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1544 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1545 result = -EINVAL;
1546 goto bad_res;
1547 }
1548
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001549 if (!netif_running(netdev)) {
1550 result = -ENETDOWN;
1551 goto bad_res;
1552 }
1553
Jouni Malinen31888482008-10-30 16:59:24 +02001554 nla_for_each_nested(nl_txq_params,
1555 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1556 rem_txq_params) {
1557 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1558 nla_data(nl_txq_params),
1559 nla_len(nl_txq_params),
1560 txq_params_policy);
1561 result = parse_txq_params(tb, &txq_params);
1562 if (result)
1563 goto bad_res;
1564
1565 result = rdev->ops->set_txq_params(&rdev->wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001566 netdev,
Jouni Malinen31888482008-10-30 16:59:24 +02001567 &txq_params);
1568 if (result)
1569 goto bad_res;
1570 }
1571 }
1572
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001573 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Bergf444de02010-05-05 15:25:02 +02001574 result = __nl80211_set_channel(rdev, wdev, info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001575 if (result)
1576 goto bad_res;
1577 }
1578
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001579 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1580 enum nl80211_tx_power_setting type;
1581 int idx, mbm = 0;
1582
1583 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001584 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001585 goto bad_res;
1586 }
1587
1588 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1589 type = nla_get_u32(info->attrs[idx]);
1590
1591 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1592 (type != NL80211_TX_POWER_AUTOMATIC)) {
1593 result = -EINVAL;
1594 goto bad_res;
1595 }
1596
1597 if (type != NL80211_TX_POWER_AUTOMATIC) {
1598 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1599 mbm = nla_get_u32(info->attrs[idx]);
1600 }
1601
1602 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1603 if (result)
1604 goto bad_res;
1605 }
1606
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001607 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1608 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1609 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001610 if ((!rdev->wiphy.available_antennas_tx &&
1611 !rdev->wiphy.available_antennas_rx) ||
1612 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001613 result = -EOPNOTSUPP;
1614 goto bad_res;
1615 }
1616
1617 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1618 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1619
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001620 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001621 * available antenna masks, except for the "all" mask */
1622 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1623 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001624 result = -EINVAL;
1625 goto bad_res;
1626 }
1627
Bruno Randolf7f531e02010-12-16 11:30:22 +09001628 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1629 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001630
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001631 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1632 if (result)
1633 goto bad_res;
1634 }
1635
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001636 changed = 0;
1637
1638 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1639 retry_short = nla_get_u8(
1640 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1641 if (retry_short == 0) {
1642 result = -EINVAL;
1643 goto bad_res;
1644 }
1645 changed |= WIPHY_PARAM_RETRY_SHORT;
1646 }
1647
1648 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1649 retry_long = nla_get_u8(
1650 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1651 if (retry_long == 0) {
1652 result = -EINVAL;
1653 goto bad_res;
1654 }
1655 changed |= WIPHY_PARAM_RETRY_LONG;
1656 }
1657
1658 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1659 frag_threshold = nla_get_u32(
1660 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1661 if (frag_threshold < 256) {
1662 result = -EINVAL;
1663 goto bad_res;
1664 }
1665 if (frag_threshold != (u32) -1) {
1666 /*
1667 * Fragments (apart from the last one) are required to
1668 * have even length. Make the fragmentation code
1669 * simpler by stripping LSB should someone try to use
1670 * odd threshold value.
1671 */
1672 frag_threshold &= ~0x1;
1673 }
1674 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1675 }
1676
1677 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1678 rts_threshold = nla_get_u32(
1679 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1680 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1681 }
1682
Lukáš Turek81077e82009-12-21 22:50:47 +01001683 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1684 coverage_class = nla_get_u8(
1685 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1686 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1687 }
1688
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001689 if (changed) {
1690 u8 old_retry_short, old_retry_long;
1691 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001692 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001693
1694 if (!rdev->ops->set_wiphy_params) {
1695 result = -EOPNOTSUPP;
1696 goto bad_res;
1697 }
1698
1699 old_retry_short = rdev->wiphy.retry_short;
1700 old_retry_long = rdev->wiphy.retry_long;
1701 old_frag_threshold = rdev->wiphy.frag_threshold;
1702 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001703 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001704
1705 if (changed & WIPHY_PARAM_RETRY_SHORT)
1706 rdev->wiphy.retry_short = retry_short;
1707 if (changed & WIPHY_PARAM_RETRY_LONG)
1708 rdev->wiphy.retry_long = retry_long;
1709 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1710 rdev->wiphy.frag_threshold = frag_threshold;
1711 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1712 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001713 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1714 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001715
1716 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1717 if (result) {
1718 rdev->wiphy.retry_short = old_retry_short;
1719 rdev->wiphy.retry_long = old_retry_long;
1720 rdev->wiphy.frag_threshold = old_frag_threshold;
1721 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01001722 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001723 }
1724 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001725
Johannes Berg306d6112008-12-08 12:39:04 +01001726 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001727 mutex_unlock(&rdev->mtx);
Johannes Bergf444de02010-05-05 15:25:02 +02001728 if (netdev)
1729 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04001730 return result;
1731}
1732
Johannes Berg71bbc992012-06-15 15:30:18 +02001733static inline u64 wdev_id(struct wireless_dev *wdev)
1734{
1735 return (u64)wdev->identifier |
1736 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
1737}
Johannes Berg55682962007-09-20 13:09:35 -04001738
Eric W. Biederman15e47302012-09-07 20:12:54 +00001739static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02001740 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001741 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04001742{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001743 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04001744 void *hdr;
1745
Eric W. Biederman15e47302012-09-07 20:12:54 +00001746 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04001747 if (!hdr)
1748 return -1;
1749
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001750 if (dev &&
1751 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001752 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001753 goto nla_put_failure;
1754
1755 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1756 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02001757 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02001758 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001759 nla_put_u32(msg, NL80211_ATTR_GENERATION,
1760 rdev->devlist_generation ^
1761 (cfg80211_rdev_list_generation << 2)))
1762 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001763
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02001764 if (rdev->ops->get_channel) {
1765 struct ieee80211_channel *chan;
1766 enum nl80211_channel_type channel_type;
1767
1768 chan = rdev->ops->get_channel(&rdev->wiphy, wdev,
1769 &channel_type);
1770 if (chan &&
1771 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
1772 chan->center_freq) ||
1773 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
1774 channel_type)))
John W. Linville59ef43e2012-04-18 14:17:13 -04001775 goto nla_put_failure;
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02001776 }
1777
Johannes Berg55682962007-09-20 13:09:35 -04001778 return genlmsg_end(msg, hdr);
1779
1780 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001781 genlmsg_cancel(msg, hdr);
1782 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001783}
1784
1785static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1786{
1787 int wp_idx = 0;
1788 int if_idx = 0;
1789 int wp_start = cb->args[0];
1790 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02001791 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04001792 struct wireless_dev *wdev;
1793
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001794 mutex_lock(&cfg80211_mutex);
Johannes Bergf5ea9122009-08-07 16:17:38 +02001795 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1796 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001797 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001798 if (wp_idx < wp_start) {
1799 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001800 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001801 }
Johannes Berg55682962007-09-20 13:09:35 -04001802 if_idx = 0;
1803
Johannes Bergf5ea9122009-08-07 16:17:38 +02001804 mutex_lock(&rdev->devlist_mtx);
Johannes Berg89a54e42012-06-15 14:33:17 +02001805 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02001806 if (if_idx < if_start) {
1807 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001808 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001809 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00001810 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04001811 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001812 rdev, wdev) < 0) {
Johannes Bergf5ea9122009-08-07 16:17:38 +02001813 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001814 goto out;
1815 }
1816 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001817 }
Johannes Bergf5ea9122009-08-07 16:17:38 +02001818 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +02001819
1820 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04001821 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02001822 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001823 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -04001824
1825 cb->args[0] = wp_idx;
1826 cb->args[1] = if_idx;
1827
1828 return skb->len;
1829}
1830
1831static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1832{
1833 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001834 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001835 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04001836
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07001837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001838 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001839 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001840
Eric W. Biederman15e47302012-09-07 20:12:54 +00001841 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02001842 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001843 nlmsg_free(msg);
1844 return -ENOBUFS;
1845 }
Johannes Berg55682962007-09-20 13:09:35 -04001846
Johannes Berg134e6372009-07-10 09:51:34 +00001847 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001848}
1849
Michael Wu66f7ac52008-01-31 19:48:22 +01001850static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1851 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1852 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1853 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1854 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1855 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1856};
1857
1858static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1859{
1860 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1861 int flag;
1862
1863 *mntrflags = 0;
1864
1865 if (!nla)
1866 return -EINVAL;
1867
1868 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1869 nla, mntr_flags_policy))
1870 return -EINVAL;
1871
1872 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1873 if (flags[flag])
1874 *mntrflags |= (1<<flag);
1875
1876 return 0;
1877}
1878
Johannes Berg9bc383d2009-11-19 11:55:19 +01001879static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001880 struct net_device *netdev, u8 use_4addr,
1881 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01001882{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001883 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00001884 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001885 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01001886 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001887 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01001888
1889 switch (iftype) {
1890 case NL80211_IFTYPE_AP_VLAN:
1891 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1892 return 0;
1893 break;
1894 case NL80211_IFTYPE_STATION:
1895 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1896 return 0;
1897 break;
1898 default:
1899 break;
1900 }
1901
1902 return -EOPNOTSUPP;
1903}
1904
Johannes Berg55682962007-09-20 13:09:35 -04001905static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1906{
Johannes Berg4c476992010-10-04 21:36:35 +02001907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001908 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02001909 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02001910 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02001911 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02001912 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001913 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04001914
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001915 memset(&params, 0, sizeof(params));
1916
Johannes Berg04a773a2009-04-19 21:24:32 +02001917 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04001918
Johannes Berg723b0382008-09-16 20:22:09 +02001919 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001920 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02001921 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001922 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02001923 if (ntype > NL80211_IFTYPE_MAX)
1924 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02001925 }
1926
Johannes Berg92ffe052008-09-16 20:39:36 +02001927 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01001928 struct wireless_dev *wdev = dev->ieee80211_ptr;
1929
Johannes Berg4c476992010-10-04 21:36:35 +02001930 if (ntype != NL80211_IFTYPE_MESH_POINT)
1931 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01001932 if (netif_running(dev))
1933 return -EBUSY;
1934
1935 wdev_lock(wdev);
1936 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1937 IEEE80211_MAX_MESH_ID_LEN);
1938 wdev->mesh_id_up_len =
1939 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1940 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1941 wdev->mesh_id_up_len);
1942 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001943 }
1944
Felix Fietkau8b787642009-11-10 18:53:10 +01001945 if (info->attrs[NL80211_ATTR_4ADDR]) {
1946 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1947 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01001948 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01001949 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001950 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01001951 } else {
1952 params.use_4addr = -1;
1953 }
1954
Johannes Berg92ffe052008-09-16 20:39:36 +02001955 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02001956 if (ntype != NL80211_IFTYPE_MONITOR)
1957 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02001958 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1959 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001960 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02001961 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001962
1963 flags = &_flags;
1964 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02001965 }
Johannes Berg3b858752009-03-12 09:55:09 +01001966
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001967 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02001968 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01001969 else
1970 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02001971
Johannes Berg9bc383d2009-11-19 11:55:19 +01001972 if (!err && params.use_4addr != -1)
1973 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1974
Johannes Berg55682962007-09-20 13:09:35 -04001975 return err;
1976}
1977
1978static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1979{
Johannes Berg4c476992010-10-04 21:36:35 +02001980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001981 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02001982 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02001983 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04001984 int err;
1985 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01001986 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04001987
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001988 memset(&params, 0, sizeof(params));
1989
Johannes Berg55682962007-09-20 13:09:35 -04001990 if (!info->attrs[NL80211_ATTR_IFNAME])
1991 return -EINVAL;
1992
1993 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1994 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1995 if (type > NL80211_IFTYPE_MAX)
1996 return -EINVAL;
1997 }
1998
Johannes Berg79c97e92009-07-07 03:56:12 +02001999 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002000 !(rdev->wiphy.interface_modes & (1 << type)))
2001 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002002
Johannes Berg9bc383d2009-11-19 11:55:19 +01002003 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002004 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002005 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002006 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002007 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002008 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002009
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002010 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2011 if (!msg)
2012 return -ENOMEM;
2013
Michael Wu66f7ac52008-01-31 19:48:22 +01002014 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2015 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2016 &flags);
Johannes Berg84efbb82012-06-16 00:00:26 +02002017 wdev = rdev->ops->add_virtual_intf(&rdev->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +01002018 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002019 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002020 if (IS_ERR(wdev)) {
2021 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002022 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002023 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002024
Johannes Berg98104fde2012-06-16 00:19:54 +02002025 switch (type) {
2026 case NL80211_IFTYPE_MESH_POINT:
2027 if (!info->attrs[NL80211_ATTR_MESH_ID])
2028 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002029 wdev_lock(wdev);
2030 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2031 IEEE80211_MAX_MESH_ID_LEN);
2032 wdev->mesh_id_up_len =
2033 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2034 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2035 wdev->mesh_id_up_len);
2036 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002037 break;
2038 case NL80211_IFTYPE_P2P_DEVICE:
2039 /*
2040 * P2P Device doesn't have a netdev, so doesn't go
2041 * through the netdev notifier and must be added here
2042 */
2043 mutex_init(&wdev->mtx);
2044 INIT_LIST_HEAD(&wdev->event_list);
2045 spin_lock_init(&wdev->event_lock);
2046 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2047 spin_lock_init(&wdev->mgmt_registrations_lock);
2048
2049 mutex_lock(&rdev->devlist_mtx);
2050 wdev->identifier = ++rdev->wdev_id;
2051 list_add_rcu(&wdev->list, &rdev->wdev_list);
2052 rdev->devlist_generation++;
2053 mutex_unlock(&rdev->devlist_mtx);
2054 break;
2055 default:
2056 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002057 }
2058
Eric W. Biederman15e47302012-09-07 20:12:54 +00002059 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002060 rdev, wdev) < 0) {
2061 nlmsg_free(msg);
2062 return -ENOBUFS;
2063 }
2064
2065 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002066}
2067
2068static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2069{
Johannes Berg4c476992010-10-04 21:36:35 +02002070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002071 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002072
Johannes Berg4c476992010-10-04 21:36:35 +02002073 if (!rdev->ops->del_virtual_intf)
2074 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002075
Johannes Berg84efbb82012-06-16 00:00:26 +02002076 /*
2077 * If we remove a wireless device without a netdev then clear
2078 * user_ptr[1] so that nl80211_post_doit won't dereference it
2079 * to check if it needs to do dev_put(). Otherwise it crashes
2080 * since the wdev has been freed, unlike with a netdev where
2081 * we need the dev_put() for the netdev to really be freed.
2082 */
2083 if (!wdev->netdev)
2084 info->user_ptr[1] = NULL;
2085
2086 return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002087}
2088
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002089static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2090{
2091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2092 struct net_device *dev = info->user_ptr[1];
2093 u16 noack_map;
2094
2095 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2096 return -EINVAL;
2097
2098 if (!rdev->ops->set_noack_map)
2099 return -EOPNOTSUPP;
2100
2101 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2102
2103 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
2104}
2105
Johannes Berg41ade002007-12-19 02:03:29 +01002106struct get_key_cookie {
2107 struct sk_buff *msg;
2108 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002109 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002110};
2111
2112static void get_key_callback(void *c, struct key_params *params)
2113{
Johannes Bergb9454e82009-07-08 13:29:08 +02002114 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002115 struct get_key_cookie *cookie = c;
2116
David S. Miller9360ffd2012-03-29 04:41:26 -04002117 if ((params->key &&
2118 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2119 params->key_len, params->key)) ||
2120 (params->seq &&
2121 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2122 params->seq_len, params->seq)) ||
2123 (params->cipher &&
2124 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2125 params->cipher)))
2126 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002127
Johannes Bergb9454e82009-07-08 13:29:08 +02002128 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2129 if (!key)
2130 goto nla_put_failure;
2131
David S. Miller9360ffd2012-03-29 04:41:26 -04002132 if ((params->key &&
2133 nla_put(cookie->msg, NL80211_KEY_DATA,
2134 params->key_len, params->key)) ||
2135 (params->seq &&
2136 nla_put(cookie->msg, NL80211_KEY_SEQ,
2137 params->seq_len, params->seq)) ||
2138 (params->cipher &&
2139 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2140 params->cipher)))
2141 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002142
David S. Miller9360ffd2012-03-29 04:41:26 -04002143 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2144 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002145
2146 nla_nest_end(cookie->msg, key);
2147
Johannes Berg41ade002007-12-19 02:03:29 +01002148 return;
2149 nla_put_failure:
2150 cookie->error = 1;
2151}
2152
2153static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2154{
Johannes Berg4c476992010-10-04 21:36:35 +02002155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002156 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002157 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002158 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002159 const u8 *mac_addr = NULL;
2160 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002161 struct get_key_cookie cookie = {
2162 .error = 0,
2163 };
2164 void *hdr;
2165 struct sk_buff *msg;
2166
2167 if (info->attrs[NL80211_ATTR_KEY_IDX])
2168 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2169
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002170 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002171 return -EINVAL;
2172
2173 if (info->attrs[NL80211_ATTR_MAC])
2174 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2175
Johannes Berge31b8212010-10-05 19:39:30 +02002176 pairwise = !!mac_addr;
2177 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2178 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2179 if (kt >= NUM_NL80211_KEYTYPES)
2180 return -EINVAL;
2181 if (kt != NL80211_KEYTYPE_GROUP &&
2182 kt != NL80211_KEYTYPE_PAIRWISE)
2183 return -EINVAL;
2184 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2185 }
2186
Johannes Berg4c476992010-10-04 21:36:35 +02002187 if (!rdev->ops->get_key)
2188 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002189
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002190 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002191 if (!msg)
2192 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002193
Eric W. Biederman15e47302012-09-07 20:12:54 +00002194 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002195 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002196 if (IS_ERR(hdr))
2197 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002198
2199 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002200 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002201
David S. Miller9360ffd2012-03-29 04:41:26 -04002202 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2203 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2204 goto nla_put_failure;
2205 if (mac_addr &&
2206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2207 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002208
Johannes Berge31b8212010-10-05 19:39:30 +02002209 if (pairwise && mac_addr &&
2210 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2211 return -ENOENT;
2212
2213 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2214 mac_addr, &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002215
2216 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002217 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002218
2219 if (cookie.error)
2220 goto nla_put_failure;
2221
2222 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002223 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002224
2225 nla_put_failure:
2226 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002227 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002228 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002229 return err;
2230}
2231
2232static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2233{
Johannes Berg4c476992010-10-04 21:36:35 +02002234 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002235 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002236 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002237 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002238
Johannes Bergb9454e82009-07-08 13:29:08 +02002239 err = nl80211_parse_key(info, &key);
2240 if (err)
2241 return err;
2242
2243 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002244 return -EINVAL;
2245
Johannes Bergb9454e82009-07-08 13:29:08 +02002246 /* only support setting default key */
2247 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002248 return -EINVAL;
2249
Johannes Bergfffd0932009-07-08 14:22:54 +02002250 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002251
2252 if (key.def) {
2253 if (!rdev->ops->set_default_key) {
2254 err = -EOPNOTSUPP;
2255 goto out;
2256 }
2257
2258 err = nl80211_key_allowed(dev->ieee80211_ptr);
2259 if (err)
2260 goto out;
2261
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002262 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
2263 key.def_uni, key.def_multi);
2264
2265 if (err)
2266 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002267
Johannes Berg3d23e342009-09-29 23:27:28 +02002268#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002269 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002270#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002271 } else {
2272 if (key.def_uni || !key.def_multi) {
2273 err = -EINVAL;
2274 goto out;
2275 }
2276
2277 if (!rdev->ops->set_default_mgmt_key) {
2278 err = -EOPNOTSUPP;
2279 goto out;
2280 }
2281
2282 err = nl80211_key_allowed(dev->ieee80211_ptr);
2283 if (err)
2284 goto out;
2285
2286 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
2287 dev, key.idx);
2288 if (err)
2289 goto out;
2290
2291#ifdef CONFIG_CFG80211_WEXT
2292 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2293#endif
2294 }
2295
2296 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002297 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002298
Johannes Berg41ade002007-12-19 02:03:29 +01002299 return err;
2300}
2301
2302static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2303{
Johannes Berg4c476992010-10-04 21:36:35 +02002304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002305 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002306 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002307 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002308 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002309
Johannes Bergb9454e82009-07-08 13:29:08 +02002310 err = nl80211_parse_key(info, &key);
2311 if (err)
2312 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002313
Johannes Bergb9454e82009-07-08 13:29:08 +02002314 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002315 return -EINVAL;
2316
Johannes Berg41ade002007-12-19 02:03:29 +01002317 if (info->attrs[NL80211_ATTR_MAC])
2318 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2319
Johannes Berge31b8212010-10-05 19:39:30 +02002320 if (key.type == -1) {
2321 if (mac_addr)
2322 key.type = NL80211_KEYTYPE_PAIRWISE;
2323 else
2324 key.type = NL80211_KEYTYPE_GROUP;
2325 }
2326
2327 /* for now */
2328 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2329 key.type != NL80211_KEYTYPE_GROUP)
2330 return -EINVAL;
2331
Johannes Berg4c476992010-10-04 21:36:35 +02002332 if (!rdev->ops->add_key)
2333 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002334
Johannes Berge31b8212010-10-05 19:39:30 +02002335 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2336 key.type == NL80211_KEYTYPE_PAIRWISE,
2337 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002338 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002339
2340 wdev_lock(dev->ieee80211_ptr);
2341 err = nl80211_key_allowed(dev->ieee80211_ptr);
2342 if (!err)
2343 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
Johannes Berge31b8212010-10-05 19:39:30 +02002344 key.type == NL80211_KEYTYPE_PAIRWISE,
Johannes Bergfffd0932009-07-08 14:22:54 +02002345 mac_addr, &key.p);
2346 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002347
Johannes Berg41ade002007-12-19 02:03:29 +01002348 return err;
2349}
2350
2351static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2352{
Johannes Berg4c476992010-10-04 21:36:35 +02002353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002354 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002355 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002356 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002357 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002358
Johannes Bergb9454e82009-07-08 13:29:08 +02002359 err = nl80211_parse_key(info, &key);
2360 if (err)
2361 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002362
2363 if (info->attrs[NL80211_ATTR_MAC])
2364 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2365
Johannes Berge31b8212010-10-05 19:39:30 +02002366 if (key.type == -1) {
2367 if (mac_addr)
2368 key.type = NL80211_KEYTYPE_PAIRWISE;
2369 else
2370 key.type = NL80211_KEYTYPE_GROUP;
2371 }
2372
2373 /* for now */
2374 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2375 key.type != NL80211_KEYTYPE_GROUP)
2376 return -EINVAL;
2377
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (!rdev->ops->del_key)
2379 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002380
Johannes Bergfffd0932009-07-08 14:22:54 +02002381 wdev_lock(dev->ieee80211_ptr);
2382 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002383
2384 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2385 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2386 err = -ENOENT;
2387
Johannes Bergfffd0932009-07-08 14:22:54 +02002388 if (!err)
Johannes Berge31b8212010-10-05 19:39:30 +02002389 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2390 key.type == NL80211_KEYTYPE_PAIRWISE,
2391 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002392
Johannes Berg3d23e342009-09-29 23:27:28 +02002393#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002394 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002395 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002396 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002397 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002398 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2399 }
2400#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002401 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002402
Johannes Berg41ade002007-12-19 02:03:29 +01002403 return err;
2404}
2405
Johannes Berg88600202012-02-13 15:17:18 +01002406static int nl80211_parse_beacon(struct genl_info *info,
2407 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002408{
Johannes Berg88600202012-02-13 15:17:18 +01002409 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002410
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002411 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2412 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2413 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2414 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002415 return -EINVAL;
2416
Johannes Berg88600202012-02-13 15:17:18 +01002417 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002418
Johannes Berged1b6cc2007-12-19 02:03:32 +01002419 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002420 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2421 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2422 if (!bcn->head_len)
2423 return -EINVAL;
2424 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002425 }
2426
2427 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002428 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2429 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002430 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002431 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002432 }
2433
Johannes Berg4c476992010-10-04 21:36:35 +02002434 if (!haveinfo)
2435 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002436
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002437 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002438 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2439 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002440 }
2441
2442 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002443 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002444 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002445 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002446 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2447 }
2448
2449 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002450 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002451 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002452 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002453 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2454 }
2455
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002456 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002457 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002458 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002459 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002460 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2461 }
2462
Johannes Berg88600202012-02-13 15:17:18 +01002463 return 0;
2464}
2465
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002466static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2467 struct cfg80211_ap_settings *params)
2468{
2469 struct wireless_dev *wdev;
2470 bool ret = false;
2471
2472 mutex_lock(&rdev->devlist_mtx);
2473
Johannes Berg89a54e42012-06-15 14:33:17 +02002474 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002475 if (wdev->iftype != NL80211_IFTYPE_AP &&
2476 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2477 continue;
2478
2479 if (!wdev->preset_chan)
2480 continue;
2481
2482 params->channel = wdev->preset_chan;
2483 params->channel_type = wdev->preset_chantype;
2484 ret = true;
2485 break;
2486 }
2487
2488 mutex_unlock(&rdev->devlist_mtx);
2489
2490 return ret;
2491}
2492
Jouni Malinene39e5b52012-09-30 19:29:39 +03002493static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2494 enum nl80211_auth_type auth_type,
2495 enum nl80211_commands cmd)
2496{
2497 if (auth_type > NL80211_AUTHTYPE_MAX)
2498 return false;
2499
2500 switch (cmd) {
2501 case NL80211_CMD_AUTHENTICATE:
2502 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2503 auth_type == NL80211_AUTHTYPE_SAE)
2504 return false;
2505 return true;
2506 case NL80211_CMD_CONNECT:
2507 case NL80211_CMD_START_AP:
2508 /* SAE not supported yet */
2509 if (auth_type == NL80211_AUTHTYPE_SAE)
2510 return false;
2511 return true;
2512 default:
2513 return false;
2514 }
2515}
2516
Johannes Berg88600202012-02-13 15:17:18 +01002517static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2518{
2519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2520 struct net_device *dev = info->user_ptr[1];
2521 struct wireless_dev *wdev = dev->ieee80211_ptr;
2522 struct cfg80211_ap_settings params;
2523 int err;
2524
2525 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2526 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2527 return -EOPNOTSUPP;
2528
2529 if (!rdev->ops->start_ap)
2530 return -EOPNOTSUPP;
2531
2532 if (wdev->beacon_interval)
2533 return -EALREADY;
2534
2535 memset(&params, 0, sizeof(params));
2536
2537 /* these are required for START_AP */
2538 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2539 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2540 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2541 return -EINVAL;
2542
2543 err = nl80211_parse_beacon(info, &params.beacon);
2544 if (err)
2545 return err;
2546
2547 params.beacon_interval =
2548 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2549 params.dtim_period =
2550 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2551
2552 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
2553 if (err)
2554 return err;
2555
2556 /*
2557 * In theory, some of these attributes should be required here
2558 * but since they were not used when the command was originally
2559 * added, keep them optional for old user space programs to let
2560 * them continue to work with drivers that do not need the
2561 * additional information -- drivers must check!
2562 */
2563 if (info->attrs[NL80211_ATTR_SSID]) {
2564 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2565 params.ssid_len =
2566 nla_len(info->attrs[NL80211_ATTR_SSID]);
2567 if (params.ssid_len == 0 ||
2568 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2569 return -EINVAL;
2570 }
2571
2572 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2573 params.hidden_ssid = nla_get_u32(
2574 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2575 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
2576 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
2577 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2578 return -EINVAL;
2579 }
2580
2581 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2582
2583 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2584 params.auth_type = nla_get_u32(
2585 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03002586 if (!nl80211_valid_auth_type(rdev, params.auth_type,
2587 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01002588 return -EINVAL;
2589 } else
2590 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2591
2592 err = nl80211_crypto_settings(rdev, info, &params.crypto,
2593 NL80211_MAX_NR_CIPHER_SUITES);
2594 if (err)
2595 return err;
2596
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05302597 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
2598 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
2599 return -EOPNOTSUPP;
2600 params.inactivity_timeout = nla_get_u16(
2601 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2602 }
2603
Johannes Bergaa430da2012-05-16 23:50:18 +02002604 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2605 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2606
2607 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2608 !nl80211_valid_channel_type(info, &channel_type))
2609 return -EINVAL;
2610
2611 params.channel = rdev_freq_to_chan(rdev,
2612 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2613 channel_type);
2614 if (!params.channel)
2615 return -EINVAL;
2616 params.channel_type = channel_type;
2617 } else if (wdev->preset_chan) {
2618 params.channel = wdev->preset_chan;
2619 params.channel_type = wdev->preset_chantype;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002620 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02002621 return -EINVAL;
2622
2623 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2624 params.channel_type))
2625 return -EINVAL;
2626
Michal Kaziore4e32452012-06-29 12:47:08 +02002627 mutex_lock(&rdev->devlist_mtx);
2628 err = cfg80211_can_use_chan(rdev, wdev, params.channel,
2629 CHAN_MODE_SHARED);
2630 mutex_unlock(&rdev->devlist_mtx);
2631
2632 if (err)
2633 return err;
2634
Johannes Berg88600202012-02-13 15:17:18 +01002635 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002636 if (!err) {
2637 wdev->preset_chan = params.channel;
2638 wdev->preset_chantype = params.channel_type;
Johannes Berg88600202012-02-13 15:17:18 +01002639 wdev->beacon_interval = params.beacon_interval;
Michal Kaziorf4489eb2012-06-29 12:46:58 +02002640 wdev->channel = params.channel;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002641 }
Johannes Berg56d18932011-05-09 18:41:15 +02002642 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002643}
2644
Johannes Berg88600202012-02-13 15:17:18 +01002645static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
2646{
2647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2648 struct net_device *dev = info->user_ptr[1];
2649 struct wireless_dev *wdev = dev->ieee80211_ptr;
2650 struct cfg80211_beacon_data params;
2651 int err;
2652
2653 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2654 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2655 return -EOPNOTSUPP;
2656
2657 if (!rdev->ops->change_beacon)
2658 return -EOPNOTSUPP;
2659
2660 if (!wdev->beacon_interval)
2661 return -EINVAL;
2662
2663 err = nl80211_parse_beacon(info, &params);
2664 if (err)
2665 return err;
2666
2667 return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
2668}
2669
2670static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002671{
Johannes Berg4c476992010-10-04 21:36:35 +02002672 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2673 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01002674
Michal Kazior60771782012-06-29 12:46:56 +02002675 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01002676}
2677
Johannes Berg5727ef12007-12-19 02:03:34 +01002678static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2679 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2680 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2681 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03002682 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07002683 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01002684 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01002685};
2686
Johannes Bergeccb8e82009-05-11 21:57:56 +03002687static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002688 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03002689 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01002690{
2691 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03002692 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01002693 int flag;
2694
Johannes Bergeccb8e82009-05-11 21:57:56 +03002695 /*
2696 * Try parsing the new attribute first so userspace
2697 * can specify both for older kernels.
2698 */
2699 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2700 if (nla) {
2701 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01002702
Johannes Bergeccb8e82009-05-11 21:57:56 +03002703 sta_flags = nla_data(nla);
2704 params->sta_flags_mask = sta_flags->mask;
2705 params->sta_flags_set = sta_flags->set;
2706 if ((params->sta_flags_mask |
2707 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2708 return -EINVAL;
2709 return 0;
2710 }
2711
2712 /* if present, parse the old attribute */
2713
2714 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01002715 if (!nla)
2716 return 0;
2717
2718 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2719 nla, sta_flags_policy))
2720 return -EINVAL;
2721
Johannes Bergbdd3ae32012-01-02 13:30:03 +01002722 /*
2723 * Only allow certain flags for interface types so that
2724 * other attributes are silently ignored. Remember that
2725 * this is backward compatibility code with old userspace
2726 * and shouldn't be hit in other cases anyway.
2727 */
2728 switch (iftype) {
2729 case NL80211_IFTYPE_AP:
2730 case NL80211_IFTYPE_AP_VLAN:
2731 case NL80211_IFTYPE_P2P_GO:
2732 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2733 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2734 BIT(NL80211_STA_FLAG_WME) |
2735 BIT(NL80211_STA_FLAG_MFP);
2736 break;
2737 case NL80211_IFTYPE_P2P_CLIENT:
2738 case NL80211_IFTYPE_STATION:
2739 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2740 BIT(NL80211_STA_FLAG_TDLS_PEER);
2741 break;
2742 case NL80211_IFTYPE_MESH_POINT:
2743 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2744 BIT(NL80211_STA_FLAG_MFP) |
2745 BIT(NL80211_STA_FLAG_AUTHORIZED);
2746 default:
2747 return -EINVAL;
2748 }
Johannes Berg5727ef12007-12-19 02:03:34 +01002749
Johannes Berg3383b5a2012-05-10 20:14:43 +02002750 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
2751 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03002752 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01002753
Johannes Berg3383b5a2012-05-10 20:14:43 +02002754 /* no longer support new API additions in old API */
2755 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
2756 return -EINVAL;
2757 }
2758 }
2759
Johannes Berg5727ef12007-12-19 02:03:34 +01002760 return 0;
2761}
2762
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002763static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2764 int attr)
2765{
2766 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002767 u32 bitrate;
2768 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002769
2770 rate = nla_nest_start(msg, attr);
2771 if (!rate)
2772 goto nla_put_failure;
2773
2774 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2775 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002776 /* report 16-bit bitrate only if we can */
2777 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
David S. Miller9360ffd2012-03-29 04:41:26 -04002778 if ((bitrate > 0 &&
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03002779 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
2780 (bitrate_compat > 0 &&
2781 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002782 ((info->flags & RATE_INFO_FLAGS_MCS) &&
2783 nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
2784 ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
2785 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) ||
2786 ((info->flags & RATE_INFO_FLAGS_SHORT_GI) &&
2787 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)))
2788 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002789
2790 nla_nest_end(msg, rate);
2791 return true;
2792
2793nla_put_failure:
2794 return false;
2795}
2796
Eric W. Biederman15e47302012-09-07 20:12:54 +00002797static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04002798 int flags,
2799 struct cfg80211_registered_device *rdev,
2800 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01002801 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002802{
2803 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07002804 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002805
Eric W. Biederman15e47302012-09-07 20:12:54 +00002806 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002807 if (!hdr)
2808 return -1;
2809
David S. Miller9360ffd2012-03-29 04:41:26 -04002810 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2811 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
2812 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
2813 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002814
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002815 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2816 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002817 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04002818 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
2819 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2820 sinfo->connected_time))
2821 goto nla_put_failure;
2822 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
2823 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2824 sinfo->inactive_time))
2825 goto nla_put_failure;
2826 if ((sinfo->filled & STATION_INFO_RX_BYTES) &&
2827 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
2828 sinfo->rx_bytes))
2829 goto nla_put_failure;
2830 if ((sinfo->filled & STATION_INFO_TX_BYTES) &&
2831 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
2832 sinfo->tx_bytes))
2833 goto nla_put_failure;
2834 if ((sinfo->filled & STATION_INFO_LLID) &&
2835 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
2836 goto nla_put_failure;
2837 if ((sinfo->filled & STATION_INFO_PLID) &&
2838 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
2839 goto nla_put_failure;
2840 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
2841 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
2842 sinfo->plink_state))
2843 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002844 switch (rdev->wiphy.signal_type) {
2845 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04002846 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
2847 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
2848 sinfo->signal))
2849 goto nla_put_failure;
2850 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
2851 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2852 sinfo->signal_avg))
2853 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04002854 break;
2855 default:
2856 break;
2857 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01002858 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002859 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2860 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01002861 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01002862 }
2863 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2864 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2865 NL80211_STA_INFO_RX_BITRATE))
2866 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01002867 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002868 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
2869 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
2870 sinfo->rx_packets))
2871 goto nla_put_failure;
2872 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
2873 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
2874 sinfo->tx_packets))
2875 goto nla_put_failure;
2876 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
2877 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
2878 sinfo->tx_retries))
2879 goto nla_put_failure;
2880 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
2881 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
2882 sinfo->tx_failed))
2883 goto nla_put_failure;
2884 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
2885 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
2886 sinfo->beacon_loss_count))
2887 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002888 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2889 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2890 if (!bss_param)
2891 goto nla_put_failure;
2892
David S. Miller9360ffd2012-03-29 04:41:26 -04002893 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
2894 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
2895 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
2896 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
2897 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
2898 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
2899 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2900 sinfo->bss_param.dtim_period) ||
2901 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2902 sinfo->bss_param.beacon_interval))
2903 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07002904
2905 nla_nest_end(msg, bss_param);
2906 }
David S. Miller9360ffd2012-03-29 04:41:26 -04002907 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
2908 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
2909 sizeof(struct nl80211_sta_flag_update),
2910 &sinfo->sta_flags))
2911 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04002912 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
2913 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
2914 sinfo->t_offset))
2915 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002916 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002917
David S. Miller9360ffd2012-03-29 04:41:26 -04002918 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
2919 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2920 sinfo->assoc_req_ies))
2921 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03002922
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002923 return genlmsg_end(msg, hdr);
2924
2925 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002926 genlmsg_cancel(msg, hdr);
2927 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002928}
2929
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002930static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002931 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002932{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002933 struct station_info sinfo;
2934 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002935 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002936 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02002937 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002938 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002939
Johannes Berg67748892010-10-04 21:14:06 +02002940 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2941 if (err)
2942 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002943
2944 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02002945 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002946 goto out_err;
2947 }
2948
Johannes Bergbba95fe2008-07-29 13:22:51 +02002949 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03002950 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergbba95fe2008-07-29 13:22:51 +02002951 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2952 mac_addr, &sinfo);
2953 if (err == -ENOENT)
2954 break;
2955 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002956 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002957
2958 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00002959 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002960 cb->nlh->nlmsg_seq, NLM_F_MULTI,
John W. Linville66266b32012-03-15 13:25:41 -04002961 dev, netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02002962 &sinfo) < 0)
2963 goto out;
2964
2965 sta_idx++;
2966 }
2967
2968
2969 out:
2970 cb->args[1] = sta_idx;
2971 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002972 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02002973 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02002974
2975 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002976}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002977
Johannes Berg5727ef12007-12-19 02:03:34 +01002978static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2979{
Johannes Berg4c476992010-10-04 21:36:35 +02002980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2981 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002982 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002983 struct sk_buff *msg;
2984 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02002985 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002986
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002987 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002988
2989 if (!info->attrs[NL80211_ATTR_MAC])
2990 return -EINVAL;
2991
2992 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2993
Johannes Berg4c476992010-10-04 21:36:35 +02002994 if (!rdev->ops->get_station)
2995 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01002996
Johannes Berg79c97e92009-07-07 03:56:12 +02002997 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002998 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002999 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003000
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003001 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003002 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003003 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003004
Eric W. Biederman15e47302012-09-07 20:12:54 +00003005 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003006 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003007 nlmsg_free(msg);
3008 return -ENOBUFS;
3009 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003010
Johannes Berg4c476992010-10-04 21:36:35 +02003011 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003012}
3013
3014/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003015 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003016 */
Johannes Berg80b99892011-11-18 16:23:01 +01003017static struct net_device *get_vlan(struct genl_info *info,
3018 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003019{
Johannes Berg463d0182009-07-14 00:33:35 +02003020 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003021 struct net_device *v;
3022 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003023
Johannes Berg80b99892011-11-18 16:23:01 +01003024 if (!vlanattr)
3025 return NULL;
3026
3027 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3028 if (!v)
3029 return ERR_PTR(-ENODEV);
3030
3031 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3032 ret = -EINVAL;
3033 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003034 }
Johannes Berg80b99892011-11-18 16:23:01 +01003035
3036 if (!netif_running(v)) {
3037 ret = -ENETDOWN;
3038 goto error;
3039 }
3040
3041 return v;
3042 error:
3043 dev_put(v);
3044 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003045}
3046
3047static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3048{
Johannes Berg4c476992010-10-04 21:36:35 +02003049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003050 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003051 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003052 struct station_parameters params;
3053 u8 *mac_addr = NULL;
3054
3055 memset(&params, 0, sizeof(params));
3056
3057 params.listen_interval = -1;
Javier Cardona57cf8042011-05-13 10:45:43 -07003058 params.plink_state = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01003059
3060 if (info->attrs[NL80211_ATTR_STA_AID])
3061 return -EINVAL;
3062
3063 if (!info->attrs[NL80211_ATTR_MAC])
3064 return -EINVAL;
3065
3066 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3067
3068 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3069 params.supported_rates =
3070 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3071 params.supported_rates_len =
3072 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3073 }
3074
3075 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3076 params.listen_interval =
3077 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
3078
Jouni Malinen36aedc902008-08-25 11:58:58 +03003079 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3080 params.ht_capa =
3081 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3082
Johannes Bergbdd90d52011-12-14 12:20:27 +01003083 if (!rdev->ops->change_station)
3084 return -EOPNOTSUPP;
3085
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003086 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003087 return -EINVAL;
3088
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003089 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3090 params.plink_action =
3091 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3092
Javier Cardona9c3990a2011-05-03 16:57:11 -07003093 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
3094 params.plink_state =
3095 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3096
Johannes Berga97f4422009-06-18 17:23:43 +02003097 switch (dev->ieee80211_ptr->iftype) {
3098 case NL80211_IFTYPE_AP:
3099 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003100 case NL80211_IFTYPE_P2P_GO:
Johannes Berga97f4422009-06-18 17:23:43 +02003101 /* disallow mesh-specific things */
3102 if (params.plink_action)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003103 return -EINVAL;
3104
3105 /* TDLS can't be set, ... */
3106 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3107 return -EINVAL;
3108 /*
3109 * ... but don't bother the driver with it. This works around
3110 * a hostapd/wpa_supplicant issue -- it always includes the
3111 * TLDS_PEER flag in the mask even for AP mode.
3112 */
3113 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3114
3115 /* accept only the listed bits */
3116 if (params.sta_flags_mask &
3117 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3118 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3119 BIT(NL80211_STA_FLAG_WME) |
3120 BIT(NL80211_STA_FLAG_MFP)))
3121 return -EINVAL;
3122
3123 /* must be last in here for error handling */
3124 params.vlan = get_vlan(info, rdev);
3125 if (IS_ERR(params.vlan))
3126 return PTR_ERR(params.vlan);
Johannes Berga97f4422009-06-18 17:23:43 +02003127 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +02003128 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003129 case NL80211_IFTYPE_STATION:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003130 /*
3131 * Don't allow userspace to change the TDLS_PEER flag,
3132 * but silently ignore attempts to change it since we
3133 * don't have state here to verify that it doesn't try
3134 * to change the flag.
3135 */
3136 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartulli267335d2012-01-31 20:25:47 +01003137 /* fall through */
3138 case NL80211_IFTYPE_ADHOC:
3139 /* disallow things sta doesn't support */
3140 if (params.plink_action)
3141 return -EINVAL;
3142 if (params.ht_capa)
3143 return -EINVAL;
3144 if (params.listen_interval >= 0)
3145 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003146 /* reject any changes other than AUTHORIZED */
3147 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3148 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003149 break;
3150 case NL80211_IFTYPE_MESH_POINT:
3151 /* disallow things mesh doesn't support */
3152 if (params.vlan)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003153 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003154 if (params.ht_capa)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003155 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003156 if (params.listen_interval >= 0)
Johannes Bergbdd90d52011-12-14 12:20:27 +01003157 return -EINVAL;
3158 /*
3159 * No special handling for TDLS here -- the userspace
3160 * mesh code doesn't have this bug.
3161 */
Javier Cardonab39c48f2011-04-07 15:08:30 -07003162 if (params.sta_flags_mask &
3163 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Thomas Pedersen84298282011-05-03 16:57:13 -07003164 BIT(NL80211_STA_FLAG_MFP) |
Javier Cardonab39c48f2011-04-07 15:08:30 -07003165 BIT(NL80211_STA_FLAG_AUTHORIZED)))
Johannes Bergbdd90d52011-12-14 12:20:27 +01003166 return -EINVAL;
Johannes Berga97f4422009-06-18 17:23:43 +02003167 break;
3168 default:
Johannes Bergbdd90d52011-12-14 12:20:27 +01003169 return -EOPNOTSUPP;
Johannes Berg034d6552009-05-27 10:35:29 +02003170 }
3171
Johannes Bergbdd90d52011-12-14 12:20:27 +01003172 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003173
Johannes Berg79c97e92009-07-07 03:56:12 +02003174 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003175
Johannes Berg5727ef12007-12-19 02:03:34 +01003176 if (params.vlan)
3177 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003178
Johannes Berg5727ef12007-12-19 02:03:34 +01003179 return err;
3180}
3181
Eliad Pellerc75786c2011-08-23 14:37:46 +03003182static struct nla_policy
3183nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3184 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3185 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3186};
3187
Johannes Berg5727ef12007-12-19 02:03:34 +01003188static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3189{
Johannes Berg4c476992010-10-04 21:36:35 +02003190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003191 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003192 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003193 struct station_parameters params;
3194 u8 *mac_addr = NULL;
3195
3196 memset(&params, 0, sizeof(params));
3197
3198 if (!info->attrs[NL80211_ATTR_MAC])
3199 return -EINVAL;
3200
Johannes Berg5727ef12007-12-19 02:03:34 +01003201 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3202 return -EINVAL;
3203
3204 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3205 return -EINVAL;
3206
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003207 if (!info->attrs[NL80211_ATTR_STA_AID])
3208 return -EINVAL;
3209
Johannes Berg5727ef12007-12-19 02:03:34 +01003210 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3211 params.supported_rates =
3212 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3213 params.supported_rates_len =
3214 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3215 params.listen_interval =
3216 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003217
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003218 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3219 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3220 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003221
Jouni Malinen36aedc902008-08-25 11:58:58 +03003222 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3223 params.ht_capa =
3224 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003225
Javier Cardona96b78df2011-04-07 15:08:33 -07003226 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
3227 params.plink_action =
3228 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3229
Johannes Bergbdd90d52011-12-14 12:20:27 +01003230 if (!rdev->ops->add_station)
3231 return -EOPNOTSUPP;
3232
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003233 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003234 return -EINVAL;
3235
Johannes Bergbdd90d52011-12-14 12:20:27 +01003236 switch (dev->ieee80211_ptr->iftype) {
3237 case NL80211_IFTYPE_AP:
3238 case NL80211_IFTYPE_AP_VLAN:
3239 case NL80211_IFTYPE_P2P_GO:
3240 /* parse WME attributes if sta is WME capable */
3241 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
3242 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
3243 info->attrs[NL80211_ATTR_STA_WME]) {
3244 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3245 struct nlattr *nla;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003246
Johannes Bergbdd90d52011-12-14 12:20:27 +01003247 nla = info->attrs[NL80211_ATTR_STA_WME];
3248 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3249 nl80211_sta_wme_policy);
3250 if (err)
3251 return err;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003252
Johannes Bergbdd90d52011-12-14 12:20:27 +01003253 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3254 params.uapsd_queues =
3255 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3256 if (params.uapsd_queues &
3257 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3258 return -EINVAL;
3259
3260 if (tb[NL80211_STA_WME_MAX_SP])
3261 params.max_sp =
3262 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3263
3264 if (params.max_sp &
3265 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3266 return -EINVAL;
3267
3268 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3269 }
3270 /* TDLS peers cannot be added */
3271 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003272 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003273 /* but don't bother the driver with it */
3274 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03003275
Johannes Bergbdd90d52011-12-14 12:20:27 +01003276 /* must be last in here for error handling */
3277 params.vlan = get_vlan(info, rdev);
3278 if (IS_ERR(params.vlan))
3279 return PTR_ERR(params.vlan);
3280 break;
3281 case NL80211_IFTYPE_MESH_POINT:
3282 /* TDLS peers cannot be added */
3283 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02003284 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01003285 break;
3286 case NL80211_IFTYPE_STATION:
3287 /* Only TDLS peers can be added */
3288 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3289 return -EINVAL;
3290 /* Can only add if TDLS ... */
3291 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
3292 return -EOPNOTSUPP;
3293 /* ... with external setup is supported */
3294 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3295 return -EOPNOTSUPP;
3296 break;
3297 default:
3298 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03003299 }
3300
Johannes Bergbdd90d52011-12-14 12:20:27 +01003301 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01003302
Johannes Berg79c97e92009-07-07 03:56:12 +02003303 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003304
Johannes Berg5727ef12007-12-19 02:03:34 +01003305 if (params.vlan)
3306 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01003307 return err;
3308}
3309
3310static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
3311{
Johannes Berg4c476992010-10-04 21:36:35 +02003312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3313 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003314 u8 *mac_addr = NULL;
3315
3316 if (info->attrs[NL80211_ATTR_MAC])
3317 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3318
Johannes Berge80cf852009-05-11 14:43:13 +02003319 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02003320 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02003321 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02003322 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3323 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02003324
Johannes Berg4c476992010-10-04 21:36:35 +02003325 if (!rdev->ops->del_station)
3326 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01003327
Johannes Berg4c476992010-10-04 21:36:35 +02003328 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01003329}
3330
Eric W. Biederman15e47302012-09-07 20:12:54 +00003331static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003332 int flags, struct net_device *dev,
3333 u8 *dst, u8 *next_hop,
3334 struct mpath_info *pinfo)
3335{
3336 void *hdr;
3337 struct nlattr *pinfoattr;
3338
Eric W. Biederman15e47302012-09-07 20:12:54 +00003339 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003340 if (!hdr)
3341 return -1;
3342
David S. Miller9360ffd2012-03-29 04:41:26 -04003343 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3344 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
3345 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
3346 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
3347 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003348
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003349 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
3350 if (!pinfoattr)
3351 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003352 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
3353 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
3354 pinfo->frame_qlen))
3355 goto nla_put_failure;
3356 if (((pinfo->filled & MPATH_INFO_SN) &&
3357 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
3358 ((pinfo->filled & MPATH_INFO_METRIC) &&
3359 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
3360 pinfo->metric)) ||
3361 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
3362 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
3363 pinfo->exptime)) ||
3364 ((pinfo->filled & MPATH_INFO_FLAGS) &&
3365 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
3366 pinfo->flags)) ||
3367 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
3368 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
3369 pinfo->discovery_timeout)) ||
3370 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
3371 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
3372 pinfo->discovery_retries)))
3373 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003374
3375 nla_nest_end(msg, pinfoattr);
3376
3377 return genlmsg_end(msg, hdr);
3378
3379 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003380 genlmsg_cancel(msg, hdr);
3381 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003382}
3383
3384static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003385 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003386{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003387 struct mpath_info pinfo;
3388 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003389 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003390 u8 dst[ETH_ALEN];
3391 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02003392 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003393 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003394
Johannes Berg67748892010-10-04 21:14:06 +02003395 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3396 if (err)
3397 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003398
3399 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003400 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003401 goto out_err;
3402 }
3403
Jouni Malineneec60b02009-03-20 21:21:19 +02003404 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
3405 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02003406 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02003407 }
3408
Johannes Bergbba95fe2008-07-29 13:22:51 +02003409 while (1) {
3410 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3411 dst, next_hop, &pinfo);
3412 if (err == -ENOENT)
3413 break;
3414 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003415 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003416
Eric W. Biederman15e47302012-09-07 20:12:54 +00003417 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003418 cb->nlh->nlmsg_seq, NLM_F_MULTI,
3419 netdev, dst, next_hop,
3420 &pinfo) < 0)
3421 goto out;
3422
3423 path_idx++;
3424 }
3425
3426
3427 out:
3428 cb->args[1] = path_idx;
3429 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003430 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02003431 nl80211_finish_netdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003432 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003433}
3434
3435static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
3436{
Johannes Berg4c476992010-10-04 21:36:35 +02003437 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003438 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003439 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003440 struct mpath_info pinfo;
3441 struct sk_buff *msg;
3442 u8 *dst = NULL;
3443 u8 next_hop[ETH_ALEN];
3444
3445 memset(&pinfo, 0, sizeof(pinfo));
3446
3447 if (!info->attrs[NL80211_ATTR_MAC])
3448 return -EINVAL;
3449
3450 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3451
Johannes Berg4c476992010-10-04 21:36:35 +02003452 if (!rdev->ops->get_mpath)
3453 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003454
Johannes Berg4c476992010-10-04 21:36:35 +02003455 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3456 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003457
Johannes Berg79c97e92009-07-07 03:56:12 +02003458 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003459 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003460 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003461
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003462 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003463 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003464 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003465
Eric W. Biederman15e47302012-09-07 20:12:54 +00003466 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02003467 dev, dst, next_hop, &pinfo) < 0) {
3468 nlmsg_free(msg);
3469 return -ENOBUFS;
3470 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003471
Johannes Berg4c476992010-10-04 21:36:35 +02003472 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003473}
3474
3475static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3476{
Johannes Berg4c476992010-10-04 21:36:35 +02003477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3478 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003479 u8 *dst = NULL;
3480 u8 *next_hop = NULL;
3481
3482 if (!info->attrs[NL80211_ATTR_MAC])
3483 return -EINVAL;
3484
3485 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3486 return -EINVAL;
3487
3488 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3489 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3490
Johannes Berg4c476992010-10-04 21:36:35 +02003491 if (!rdev->ops->change_mpath)
3492 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003493
Johannes Berg4c476992010-10-04 21:36:35 +02003494 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3495 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003496
Johannes Berg4c476992010-10-04 21:36:35 +02003497 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003498}
Johannes Berg4c476992010-10-04 21:36:35 +02003499
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003500static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3501{
Johannes Berg4c476992010-10-04 21:36:35 +02003502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3503 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504 u8 *dst = NULL;
3505 u8 *next_hop = NULL;
3506
3507 if (!info->attrs[NL80211_ATTR_MAC])
3508 return -EINVAL;
3509
3510 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3511 return -EINVAL;
3512
3513 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3514 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3515
Johannes Berg4c476992010-10-04 21:36:35 +02003516 if (!rdev->ops->add_mpath)
3517 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003518
Johannes Berg4c476992010-10-04 21:36:35 +02003519 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3520 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003521
Johannes Berg4c476992010-10-04 21:36:35 +02003522 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003523}
3524
3525static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3526{
Johannes Berg4c476992010-10-04 21:36:35 +02003527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3528 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529 u8 *dst = NULL;
3530
3531 if (info->attrs[NL80211_ATTR_MAC])
3532 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3533
Johannes Berg4c476992010-10-04 21:36:35 +02003534 if (!rdev->ops->del_mpath)
3535 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003536
Johannes Berg4c476992010-10-04 21:36:35 +02003537 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003538}
3539
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003540static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3541{
Johannes Berg4c476992010-10-04 21:36:35 +02003542 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3543 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003544 struct bss_parameters params;
3545
3546 memset(&params, 0, sizeof(params));
3547 /* default to not changing parameters */
3548 params.use_cts_prot = -1;
3549 params.use_short_preamble = -1;
3550 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003551 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01003552 params.ht_opmode = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003553
3554 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3555 params.use_cts_prot =
3556 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3557 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3558 params.use_short_preamble =
3559 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3560 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3561 params.use_short_slot_time =
3562 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02003563 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3564 params.basic_rates =
3565 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3566 params.basic_rates_len =
3567 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3568 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02003569 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3570 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01003571 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3572 params.ht_opmode =
3573 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003574
Johannes Berg4c476992010-10-04 21:36:35 +02003575 if (!rdev->ops->change_bss)
3576 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003577
Johannes Berg074ac8d2010-09-16 14:58:22 +02003578 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02003579 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3580 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02003581
Johannes Berg4c476992010-10-04 21:36:35 +02003582 return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003583}
3584
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003585static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003586 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3587 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3588 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3589 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3590 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3591 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3592};
3593
3594static int parse_reg_rule(struct nlattr *tb[],
3595 struct ieee80211_reg_rule *reg_rule)
3596{
3597 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
3598 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
3599
3600 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3601 return -EINVAL;
3602 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3603 return -EINVAL;
3604 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3605 return -EINVAL;
3606 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3607 return -EINVAL;
3608 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3609 return -EINVAL;
3610
3611 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3612
3613 freq_range->start_freq_khz =
3614 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3615 freq_range->end_freq_khz =
3616 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3617 freq_range->max_bandwidth_khz =
3618 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3619
3620 power_rule->max_eirp =
3621 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3622
3623 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3624 power_rule->max_antenna_gain =
3625 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3626
3627 return 0;
3628}
3629
3630static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3631{
3632 int r;
3633 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003634 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003635
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003636 /*
3637 * You should only get this when cfg80211 hasn't yet initialized
3638 * completely when built-in to the kernel right between the time
3639 * window between nl80211_init() and regulatory_init(), if that is
3640 * even possible.
3641 */
3642 mutex_lock(&cfg80211_mutex);
3643 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003644 mutex_unlock(&cfg80211_mutex);
3645 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003646 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003647 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05003648
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003649 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3650 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003651
3652 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3653
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07003654 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
3655 user_reg_hint_type =
3656 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
3657 else
3658 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
3659
3660 switch (user_reg_hint_type) {
3661 case NL80211_USER_REG_HINT_USER:
3662 case NL80211_USER_REG_HINT_CELL_BASE:
3663 break;
3664 default:
3665 return -EINVAL;
3666 }
3667
3668 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05003669
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003670 return r;
3671}
3672
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003673static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003674 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003675{
Johannes Berg4c476992010-10-04 21:36:35 +02003676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003677 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003678 struct wireless_dev *wdev = dev->ieee80211_ptr;
3679 struct mesh_config cur_params;
3680 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003681 void *hdr;
3682 struct nlattr *pinfoattr;
3683 struct sk_buff *msg;
3684
Johannes Berg29cbe682010-12-03 09:20:44 +01003685 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3686 return -EOPNOTSUPP;
3687
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003688 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02003689 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02003690
Johannes Berg29cbe682010-12-03 09:20:44 +01003691 wdev_lock(wdev);
3692 /* If not connected, get default parameters */
3693 if (!wdev->mesh_id_len)
3694 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3695 else
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003696 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01003697 &cur_params);
3698 wdev_unlock(wdev);
3699
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003700 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003701 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003702
3703 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003705 if (!msg)
3706 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00003707 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003708 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003709 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01003710 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003711 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003712 if (!pinfoattr)
3713 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003714 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3715 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3716 cur_params.dot11MeshRetryTimeout) ||
3717 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3718 cur_params.dot11MeshConfirmTimeout) ||
3719 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3720 cur_params.dot11MeshHoldingTimeout) ||
3721 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3722 cur_params.dot11MeshMaxPeerLinks) ||
3723 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
3724 cur_params.dot11MeshMaxRetries) ||
3725 nla_put_u8(msg, NL80211_MESHCONF_TTL,
3726 cur_params.dot11MeshTTL) ||
3727 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3728 cur_params.element_ttl) ||
3729 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3730 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04003731 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3732 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003733 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3734 cur_params.dot11MeshHWMPmaxPREQretries) ||
3735 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3736 cur_params.path_refresh_time) ||
3737 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3738 cur_params.min_discovery_timeout) ||
3739 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3740 cur_params.dot11MeshHWMPactivePathTimeout) ||
3741 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3742 cur_params.dot11MeshHWMPpreqMinInterval) ||
3743 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3744 cur_params.dot11MeshHWMPperrMinInterval) ||
3745 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3746 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3747 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3748 cur_params.dot11MeshHWMPRootMode) ||
3749 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3750 cur_params.dot11MeshHWMPRannInterval) ||
3751 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3752 cur_params.dot11MeshGateAnnouncementProtocol) ||
3753 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
3754 cur_params.dot11MeshForwarding) ||
3755 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003756 cur_params.rssi_threshold) ||
3757 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003758 cur_params.ht_opmode) ||
3759 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3760 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3761 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003762 cur_params.dot11MeshHWMProotInterval) ||
3763 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3764 cur_params.dot11MeshHWMPconfirmationInterval))
David S. Miller9360ffd2012-03-29 04:41:26 -04003765 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003766 nla_nest_end(msg, pinfoattr);
3767 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003768 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003769
Johannes Berg3b858752009-03-12 09:55:09 +01003770 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003771 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01003772 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04003773 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02003774 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003775}
3776
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00003777static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003778 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3779 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3780 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3781 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3782 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3783 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01003784 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003785 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07003786 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003787 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3788 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3789 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3790 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3791 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08003792 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003793 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07003794 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07003795 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07003796 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003797 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003798 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
3799 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003800 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3801 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003802 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003803};
3804
Javier Cardonac80d5452010-12-16 17:37:49 -08003805static const struct nla_policy
3806 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07003807 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08003808 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3809 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07003810 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07003811 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003812 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07003813 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08003814};
3815
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003816static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003817 struct mesh_config *cfg,
3818 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003819{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003820 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003821 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003822
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003823#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3824do {\
3825 if (table[attr_num]) {\
3826 cfg->param = nla_fn(table[attr_num]); \
3827 mask |= (1 << (attr_num - 1)); \
3828 } \
3829} while (0);\
3830
3831
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003832 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003833 return -EINVAL;
3834 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003835 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003836 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003837 return -EINVAL;
3838
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003839 /* This makes sure that there aren't more than 32 mesh config
3840 * parameters (otherwise our bitfield scheme would not work.) */
3841 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3842
3843 /* Fill in the params struct */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003844 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003845 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3846 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003847 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003848 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3849 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003851 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3852 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003854 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
3855 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003856 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003857 mask, NL80211_MESHCONF_MAX_RETRIES,
3858 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003859 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003860 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Javier Cardona45904f22010-12-03 09:20:40 +01003861 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003862 mask, NL80211_MESHCONF_ELEMENT_TTL,
3863 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003864 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003865 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3866 nla_get_u8);
3867 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
3868 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
3869 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003871 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3872 nla_get_u8);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003874 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
3875 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003877 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3878 nla_get_u16);
3879 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
3880 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3881 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003882 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003883 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3884 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08003885 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003886 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3887 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003888 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003889 dot11MeshHWMPnetDiameterTraversalTime, mask,
3890 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3891 nla_get_u16);
3892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
3893 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
3894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
3895 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3896 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00003897 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003898 dot11MeshGateAnnouncementProtocol, mask,
3899 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3900 nla_get_u8);
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08003901 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003902 mask, NL80211_MESHCONF_FORWARDING,
3903 nla_get_u8);
Ashok Nagarajan55335132012-02-28 17:04:08 -08003904 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003905 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
3906 nla_get_u32);
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07003907 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08003908 mask, NL80211_MESHCONF_HT_OPMODE,
3909 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08003910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
3911 mask,
3912 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
3913 nla_get_u32);
3914 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
3915 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3916 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08003917 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3918 dot11MeshHWMPconfirmationInterval, mask,
3919 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3920 nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003921 if (mask_out)
3922 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08003923
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003924 return 0;
3925
3926#undef FILL_IN_MESH_PARAM_IF_SET
3927}
3928
Javier Cardonac80d5452010-12-16 17:37:49 -08003929static int nl80211_parse_mesh_setup(struct genl_info *info,
3930 struct mesh_setup *setup)
3931{
3932 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3933
3934 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3935 return -EINVAL;
3936 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3937 info->attrs[NL80211_ATTR_MESH_SETUP],
3938 nl80211_mesh_setup_params_policy))
3939 return -EINVAL;
3940
Javier Cardonad299a1f2012-03-31 11:31:33 -07003941 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
3942 setup->sync_method =
3943 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3944 IEEE80211_SYNC_METHOD_VENDOR :
3945 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
3946
Javier Cardonac80d5452010-12-16 17:37:49 -08003947 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3948 setup->path_sel_proto =
3949 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3950 IEEE80211_PATH_PROTOCOL_VENDOR :
3951 IEEE80211_PATH_PROTOCOL_HWMP;
3952
3953 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3954 setup->path_metric =
3955 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3956 IEEE80211_PATH_METRIC_VENDOR :
3957 IEEE80211_PATH_METRIC_AIRTIME;
3958
Javier Cardona581a8b02011-04-07 15:08:27 -07003959
3960 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08003961 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07003962 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08003963 if (!is_valid_ie_attr(ieattr))
3964 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07003965 setup->ie = nla_data(ieattr);
3966 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08003967 }
Javier Cardonab130e5c2011-05-03 16:57:07 -07003968 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3969 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Javier Cardonac80d5452010-12-16 17:37:49 -08003970
3971 return 0;
3972}
3973
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003974static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01003975 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003976{
3977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3978 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01003979 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003980 struct mesh_config cfg;
3981 u32 mask;
3982 int err;
3983
Johannes Berg29cbe682010-12-03 09:20:44 +01003984 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3985 return -EOPNOTSUPP;
3986
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003987 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003988 return -EOPNOTSUPP;
3989
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003990 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01003991 if (err)
3992 return err;
3993
Johannes Berg29cbe682010-12-03 09:20:44 +01003994 wdev_lock(wdev);
3995 if (!wdev->mesh_id_len)
3996 err = -ENOLINK;
3997
3998 if (!err)
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003999 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
Johannes Berg29cbe682010-12-03 09:20:44 +01004000 mask, &cfg);
4001
4002 wdev_unlock(wdev);
4003
4004 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004005}
4006
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004007static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4008{
4009 struct sk_buff *msg;
4010 void *hdr = NULL;
4011 struct nlattr *nl_reg_rules;
4012 unsigned int i;
4013 int err = -EINVAL;
4014
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004015 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004016
4017 if (!cfg80211_regdomain)
4018 goto out;
4019
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004021 if (!msg) {
4022 err = -ENOBUFS;
4023 goto out;
4024 }
4025
Eric W. Biederman15e47302012-09-07 20:12:54 +00004026 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004027 NL80211_CMD_GET_REG);
4028 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004029 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004030
David S. Miller9360ffd2012-03-29 04:41:26 -04004031 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
4032 cfg80211_regdomain->alpha2) ||
4033 (cfg80211_regdomain->dfs_region &&
4034 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
4035 cfg80211_regdomain->dfs_region)))
4036 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004037
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004038 if (reg_last_request_cell_base() &&
4039 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4040 NL80211_USER_REG_HINT_CELL_BASE))
4041 goto nla_put_failure;
4042
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004043 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4044 if (!nl_reg_rules)
4045 goto nla_put_failure;
4046
4047 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
4048 struct nlattr *nl_reg_rule;
4049 const struct ieee80211_reg_rule *reg_rule;
4050 const struct ieee80211_freq_range *freq_range;
4051 const struct ieee80211_power_rule *power_rule;
4052
4053 reg_rule = &cfg80211_regdomain->reg_rules[i];
4054 freq_range = &reg_rule->freq_range;
4055 power_rule = &reg_rule->power_rule;
4056
4057 nl_reg_rule = nla_nest_start(msg, i);
4058 if (!nl_reg_rule)
4059 goto nla_put_failure;
4060
David S. Miller9360ffd2012-03-29 04:41:26 -04004061 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4062 reg_rule->flags) ||
4063 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4064 freq_range->start_freq_khz) ||
4065 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4066 freq_range->end_freq_khz) ||
4067 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4068 freq_range->max_bandwidth_khz) ||
4069 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4070 power_rule->max_antenna_gain) ||
4071 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4072 power_rule->max_eirp))
4073 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004074
4075 nla_nest_end(msg, nl_reg_rule);
4076 }
4077
4078 nla_nest_end(msg, nl_reg_rules);
4079
4080 genlmsg_end(msg, hdr);
Johannes Berg134e6372009-07-10 09:51:34 +00004081 err = genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004082 goto out;
4083
4084nla_put_failure:
4085 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004086put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004087 nlmsg_free(msg);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004088 err = -EMSGSIZE;
4089out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004090 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004091 return err;
4092}
4093
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004094static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4095{
4096 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4097 struct nlattr *nl_reg_rule;
4098 char *alpha2 = NULL;
4099 int rem_reg_rules = 0, r = 0;
4100 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004101 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004102 struct ieee80211_regdomain *rd = NULL;
4103
4104 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4105 return -EINVAL;
4106
4107 if (!info->attrs[NL80211_ATTR_REG_RULES])
4108 return -EINVAL;
4109
4110 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4111
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004112 if (info->attrs[NL80211_ATTR_DFS_REGION])
4113 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4114
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004115 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4116 rem_reg_rules) {
4117 num_rules++;
4118 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004119 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004120 }
4121
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004122 mutex_lock(&cfg80211_mutex);
4123
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004124 if (!reg_is_valid_request(alpha2)) {
4125 r = -EINVAL;
4126 goto bad_reg;
4127 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004128
4129 size_of_regd = sizeof(struct ieee80211_regdomain) +
4130 (num_rules * sizeof(struct ieee80211_reg_rule));
4131
4132 rd = kzalloc(size_of_regd, GFP_KERNEL);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004133 if (!rd) {
4134 r = -ENOMEM;
4135 goto bad_reg;
4136 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004137
4138 rd->n_reg_rules = num_rules;
4139 rd->alpha2[0] = alpha2[0];
4140 rd->alpha2[1] = alpha2[1];
4141
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004142 /*
4143 * Disable DFS master mode if the DFS region was
4144 * not supported or known on this kernel.
4145 */
4146 if (reg_supported_dfs_region(dfs_region))
4147 rd->dfs_region = dfs_region;
4148
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004149 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4150 rem_reg_rules) {
4151 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4152 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4153 reg_rule_policy);
4154 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4155 if (r)
4156 goto bad_reg;
4157
4158 rule_idx++;
4159
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004160 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4161 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004162 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004163 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004164 }
4165
4166 BUG_ON(rule_idx != num_rules);
4167
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004168 r = set_regdom(rd);
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004169
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05004170 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004171
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004172 return r;
4173
Johannes Bergd2372b32008-10-24 20:32:20 +02004174 bad_reg:
Luis R. Rodriguez61405e92009-05-13 17:04:41 -04004175 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004176 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004177 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004178}
4179
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004180static int validate_scan_freqs(struct nlattr *freqs)
4181{
4182 struct nlattr *attr1, *attr2;
4183 int n_channels = 0, tmp1, tmp2;
4184
4185 nla_for_each_nested(attr1, freqs, tmp1) {
4186 n_channels++;
4187 /*
4188 * Some hardware has a limited channel list for
4189 * scanning, and it is pretty much nonsensical
4190 * to scan for a channel twice, so disallow that
4191 * and don't require drivers to check that the
4192 * channel list they get isn't longer than what
4193 * they can scan, as long as they can scan all
4194 * the channels they registered at once.
4195 */
4196 nla_for_each_nested(attr2, freqs, tmp2)
4197 if (attr1 != attr2 &&
4198 nla_get_u32(attr1) == nla_get_u32(attr2))
4199 return 0;
4200 }
4201
4202 return n_channels;
4203}
4204
Johannes Berg2a519312009-02-10 21:25:55 +01004205static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
4206{
Johannes Berg4c476992010-10-04 21:36:35 +02004207 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02004208 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01004209 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01004210 struct nlattr *attr;
4211 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004212 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004213 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01004214
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004215 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4216 return -EINVAL;
4217
Johannes Berg79c97e92009-07-07 03:56:12 +02004218 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004219
Johannes Berg4c476992010-10-04 21:36:35 +02004220 if (!rdev->ops->scan)
4221 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01004222
Johannes Berg4c476992010-10-04 21:36:35 +02004223 if (rdev->scan_req)
4224 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01004225
4226 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004227 n_channels = validate_scan_freqs(
4228 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Berg4c476992010-10-04 21:36:35 +02004229 if (!n_channels)
4230 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004231 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004232 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02004233 n_channels = 0;
4234
Johannes Berg2a519312009-02-10 21:25:55 +01004235 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4236 if (wiphy->bands[band])
4237 n_channels += wiphy->bands[band]->n_channels;
4238 }
4239
4240 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4241 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
4242 n_ssids++;
4243
Johannes Berg4c476992010-10-04 21:36:35 +02004244 if (n_ssids > wiphy->max_scan_ssids)
4245 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01004246
Jouni Malinen70692ad2009-02-16 19:39:13 +02004247 if (info->attrs[NL80211_ATTR_IE])
4248 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4249 else
4250 ie_len = 0;
4251
Johannes Berg4c476992010-10-04 21:36:35 +02004252 if (ie_len > wiphy->max_scan_ie_len)
4253 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02004254
Johannes Berg2a519312009-02-10 21:25:55 +01004255 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004256 + sizeof(*request->ssids) * n_ssids
4257 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02004258 + ie_len, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004259 if (!request)
4260 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01004261
Johannes Berg2a519312009-02-10 21:25:55 +01004262 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02004263 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01004264 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02004265 if (ie_len) {
4266 if (request->ssids)
4267 request->ie = (void *)(request->ssids + n_ssids);
4268 else
4269 request->ie = (void *)(request->channels + n_channels);
4270 }
Johannes Berg2a519312009-02-10 21:25:55 +01004271
Johannes Berg584991d2009-11-02 13:32:03 +01004272 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01004273 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4274 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01004275 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01004276 struct ieee80211_channel *chan;
4277
4278 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4279
4280 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01004281 err = -EINVAL;
4282 goto out_free;
4283 }
Johannes Berg584991d2009-11-02 13:32:03 +01004284
4285 /* ignore disabled channels */
4286 if (chan->flags & IEEE80211_CHAN_DISABLED)
4287 continue;
4288
4289 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004290 i++;
4291 }
4292 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02004293 enum ieee80211_band band;
4294
Johannes Berg2a519312009-02-10 21:25:55 +01004295 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01004296 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4297 int j;
4298 if (!wiphy->bands[band])
4299 continue;
4300 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01004301 struct ieee80211_channel *chan;
4302
4303 chan = &wiphy->bands[band]->channels[j];
4304
4305 if (chan->flags & IEEE80211_CHAN_DISABLED)
4306 continue;
4307
4308 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01004309 i++;
4310 }
4311 }
4312 }
4313
Johannes Berg584991d2009-11-02 13:32:03 +01004314 if (!i) {
4315 err = -EINVAL;
4316 goto out_free;
4317 }
4318
4319 request->n_channels = i;
4320
Johannes Berg2a519312009-02-10 21:25:55 +01004321 i = 0;
4322 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4323 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004324 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01004325 err = -EINVAL;
4326 goto out_free;
4327 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004328 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01004329 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01004330 i++;
4331 }
4332 }
4333
Jouni Malinen70692ad2009-02-16 19:39:13 +02004334 if (info->attrs[NL80211_ATTR_IE]) {
4335 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02004336 memcpy((void *)request->ie,
4337 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02004338 request->ie_len);
4339 }
4340
Johannes Berg34850ab2011-07-18 18:08:35 +02004341 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02004342 if (wiphy->bands[i])
4343 request->rates[i] =
4344 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02004345
4346 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
4347 nla_for_each_nested(attr,
4348 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
4349 tmp) {
4350 enum ieee80211_band band = nla_type(attr);
4351
Dan Carpenter84404622011-07-29 11:52:18 +03004352 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02004353 err = -EINVAL;
4354 goto out_free;
4355 }
4356 err = ieee80211_get_ratemask(wiphy->bands[band],
4357 nla_data(attr),
4358 nla_len(attr),
4359 &request->rates[band]);
4360 if (err)
4361 goto out_free;
4362 }
4363 }
4364
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05304365 request->no_cck =
4366 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
4367
Johannes Bergfd014282012-06-18 19:17:03 +02004368 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02004369 request->wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01004370
Johannes Berg79c97e92009-07-07 03:56:12 +02004371 rdev->scan_req = request;
Johannes Bergfd014282012-06-18 19:17:03 +02004372 err = rdev->ops->scan(&rdev->wiphy, request);
Johannes Berg2a519312009-02-10 21:25:55 +01004373
Johannes Berg463d0182009-07-14 00:33:35 +02004374 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02004375 nl80211_send_scan_start(rdev, wdev);
4376 if (wdev->netdev)
4377 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02004378 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01004379 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02004380 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01004381 kfree(request);
4382 }
Johannes Berg3b858752009-03-12 09:55:09 +01004383
Johannes Berg2a519312009-02-10 21:25:55 +01004384 return err;
4385}
4386
Luciano Coelho807f8a82011-05-11 17:09:35 +03004387static int nl80211_start_sched_scan(struct sk_buff *skb,
4388 struct genl_info *info)
4389{
4390 struct cfg80211_sched_scan_request *request;
4391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4392 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004393 struct nlattr *attr;
4394 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004395 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004396 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004397 enum ieee80211_band band;
4398 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004399 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03004400
4401 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4402 !rdev->ops->sched_scan_start)
4403 return -EOPNOTSUPP;
4404
4405 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4406 return -EINVAL;
4407
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004408 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
4409 return -EINVAL;
4410
4411 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
4412 if (interval == 0)
4413 return -EINVAL;
4414
Luciano Coelho807f8a82011-05-11 17:09:35 +03004415 wiphy = &rdev->wiphy;
4416
4417 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4418 n_channels = validate_scan_freqs(
4419 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
4420 if (!n_channels)
4421 return -EINVAL;
4422 } else {
4423 n_channels = 0;
4424
4425 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
4426 if (wiphy->bands[band])
4427 n_channels += wiphy->bands[band]->n_channels;
4428 }
4429
4430 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
4431 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4432 tmp)
4433 n_ssids++;
4434
Luciano Coelho93b6aa62011-07-13 14:57:28 +03004435 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004436 return -EINVAL;
4437
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004438 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
4439 nla_for_each_nested(attr,
4440 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4441 tmp)
4442 n_match_sets++;
4443
4444 if (n_match_sets > wiphy->max_match_sets)
4445 return -EINVAL;
4446
Luciano Coelho807f8a82011-05-11 17:09:35 +03004447 if (info->attrs[NL80211_ATTR_IE])
4448 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4449 else
4450 ie_len = 0;
4451
Luciano Coelho5a865ba2011-07-13 14:57:29 +03004452 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03004453 return -EINVAL;
4454
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004455 mutex_lock(&rdev->sched_scan_mtx);
4456
4457 if (rdev->sched_scan_req) {
4458 err = -EINPROGRESS;
4459 goto out;
4460 }
4461
Luciano Coelho807f8a82011-05-11 17:09:35 +03004462 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004463 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004464 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03004465 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03004466 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004467 if (!request) {
4468 err = -ENOMEM;
4469 goto out;
4470 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03004471
4472 if (n_ssids)
4473 request->ssids = (void *)&request->channels[n_channels];
4474 request->n_ssids = n_ssids;
4475 if (ie_len) {
4476 if (request->ssids)
4477 request->ie = (void *)(request->ssids + n_ssids);
4478 else
4479 request->ie = (void *)(request->channels + n_channels);
4480 }
4481
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004482 if (n_match_sets) {
4483 if (request->ie)
4484 request->match_sets = (void *)(request->ie + ie_len);
4485 else if (request->ssids)
4486 request->match_sets =
4487 (void *)(request->ssids + n_ssids);
4488 else
4489 request->match_sets =
4490 (void *)(request->channels + n_channels);
4491 }
4492 request->n_match_sets = n_match_sets;
4493
Luciano Coelho807f8a82011-05-11 17:09:35 +03004494 i = 0;
4495 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
4496 /* user specified, bail out if channel not found */
4497 nla_for_each_nested(attr,
4498 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
4499 tmp) {
4500 struct ieee80211_channel *chan;
4501
4502 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4503
4504 if (!chan) {
4505 err = -EINVAL;
4506 goto out_free;
4507 }
4508
4509 /* ignore disabled channels */
4510 if (chan->flags & IEEE80211_CHAN_DISABLED)
4511 continue;
4512
4513 request->channels[i] = chan;
4514 i++;
4515 }
4516 } else {
4517 /* all channels */
4518 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4519 int j;
4520 if (!wiphy->bands[band])
4521 continue;
4522 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
4523 struct ieee80211_channel *chan;
4524
4525 chan = &wiphy->bands[band]->channels[j];
4526
4527 if (chan->flags & IEEE80211_CHAN_DISABLED)
4528 continue;
4529
4530 request->channels[i] = chan;
4531 i++;
4532 }
4533 }
4534 }
4535
4536 if (!i) {
4537 err = -EINVAL;
4538 goto out_free;
4539 }
4540
4541 request->n_channels = i;
4542
4543 i = 0;
4544 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
4545 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
4546 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03004547 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03004548 err = -EINVAL;
4549 goto out_free;
4550 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03004551 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004552 memcpy(request->ssids[i].ssid, nla_data(attr),
4553 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03004554 i++;
4555 }
4556 }
4557
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004558 i = 0;
4559 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4560 nla_for_each_nested(attr,
4561 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4562 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004563 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004564
4565 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4566 nla_data(attr), nla_len(attr),
4567 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02004568 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004569 if (ssid) {
4570 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4571 err = -EINVAL;
4572 goto out_free;
4573 }
4574 memcpy(request->match_sets[i].ssid.ssid,
4575 nla_data(ssid), nla_len(ssid));
4576 request->match_sets[i].ssid.ssid_len =
4577 nla_len(ssid);
4578 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07004579 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
4580 if (rssi)
4581 request->rssi_thold = nla_get_u32(rssi);
4582 else
4583 request->rssi_thold =
4584 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03004585 i++;
4586 }
4587 }
4588
Luciano Coelho807f8a82011-05-11 17:09:35 +03004589 if (info->attrs[NL80211_ATTR_IE]) {
4590 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4591 memcpy((void *)request->ie,
4592 nla_data(info->attrs[NL80211_ATTR_IE]),
4593 request->ie_len);
4594 }
4595
4596 request->dev = dev;
4597 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03004598 request->interval = interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004599
4600 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4601 if (!err) {
4602 rdev->sched_scan_req = request;
4603 nl80211_send_sched_scan(rdev, dev,
4604 NL80211_CMD_START_SCHED_SCAN);
4605 goto out;
4606 }
4607
4608out_free:
4609 kfree(request);
4610out:
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004611 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +03004612 return err;
4613}
4614
4615static int nl80211_stop_sched_scan(struct sk_buff *skb,
4616 struct genl_info *info)
4617{
4618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004619 int err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004620
4621 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4622 !rdev->ops->sched_scan_stop)
4623 return -EOPNOTSUPP;
4624
Luciano Coelhoc10841c2011-06-30 08:32:41 +03004625 mutex_lock(&rdev->sched_scan_mtx);
4626 err = __cfg80211_stop_sched_scan(rdev, false);
4627 mutex_unlock(&rdev->sched_scan_mtx);
4628
4629 return err;
Luciano Coelho807f8a82011-05-11 17:09:35 +03004630}
4631
Johannes Berg9720bb32011-06-21 09:45:33 +02004632static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4633 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004634 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02004635 struct wireless_dev *wdev,
4636 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01004637{
Johannes Berg48ab9052009-07-10 18:42:31 +02004638 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg2a519312009-02-10 21:25:55 +01004639 void *hdr;
4640 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02004641
4642 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004643
Eric W. Biederman15e47302012-09-07 20:12:54 +00004644 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01004645 NL80211_CMD_NEW_SCAN_RESULTS);
4646 if (!hdr)
4647 return -1;
4648
Johannes Berg9720bb32011-06-21 09:45:33 +02004649 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4650
David S. Miller9360ffd2012-03-29 04:41:26 -04004651 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) ||
4652 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
4653 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004654
4655 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4656 if (!bss)
4657 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004658 if ((!is_zero_ether_addr(res->bssid) &&
4659 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) ||
4660 (res->information_elements && res->len_information_elements &&
4661 nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4662 res->len_information_elements,
4663 res->information_elements)) ||
4664 (res->beacon_ies && res->len_beacon_ies &&
4665 res->beacon_ies != res->information_elements &&
4666 nla_put(msg, NL80211_BSS_BEACON_IES,
4667 res->len_beacon_ies, res->beacon_ies)))
4668 goto nla_put_failure;
4669 if (res->tsf &&
4670 nla_put_u64(msg, NL80211_BSS_TSF, res->tsf))
4671 goto nla_put_failure;
4672 if (res->beacon_interval &&
4673 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
4674 goto nla_put_failure;
4675 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
4676 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
4677 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
4678 jiffies_to_msecs(jiffies - intbss->ts)))
4679 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004680
Johannes Berg77965c92009-02-18 18:45:06 +01004681 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01004682 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04004683 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
4684 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004685 break;
4686 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004687 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
4688 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01004689 break;
4690 default:
4691 break;
4692 }
4693
Johannes Berg48ab9052009-07-10 18:42:31 +02004694 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02004695 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02004696 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04004697 if (intbss == wdev->current_bss &&
4698 nla_put_u32(msg, NL80211_BSS_STATUS,
4699 NL80211_BSS_STATUS_ASSOCIATED))
4700 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004701 break;
4702 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04004703 if (intbss == wdev->current_bss &&
4704 nla_put_u32(msg, NL80211_BSS_STATUS,
4705 NL80211_BSS_STATUS_IBSS_JOINED))
4706 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02004707 break;
4708 default:
4709 break;
4710 }
4711
Johannes Berg2a519312009-02-10 21:25:55 +01004712 nla_nest_end(msg, bss);
4713
4714 return genlmsg_end(msg, hdr);
4715
4716 nla_put_failure:
4717 genlmsg_cancel(msg, hdr);
4718 return -EMSGSIZE;
4719}
4720
4721static int nl80211_dump_scan(struct sk_buff *skb,
4722 struct netlink_callback *cb)
4723{
Johannes Berg48ab9052009-07-10 18:42:31 +02004724 struct cfg80211_registered_device *rdev;
4725 struct net_device *dev;
Johannes Berg2a519312009-02-10 21:25:55 +01004726 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02004727 struct wireless_dev *wdev;
Johannes Berg2a519312009-02-10 21:25:55 +01004728 int start = cb->args[1], idx = 0;
4729 int err;
4730
Johannes Berg67748892010-10-04 21:14:06 +02004731 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4732 if (err)
4733 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01004734
Johannes Berg48ab9052009-07-10 18:42:31 +02004735 wdev = dev->ieee80211_ptr;
Johannes Berg2a519312009-02-10 21:25:55 +01004736
Johannes Berg48ab9052009-07-10 18:42:31 +02004737 wdev_lock(wdev);
4738 spin_lock_bh(&rdev->bss_lock);
4739 cfg80211_bss_expire(rdev);
4740
Johannes Berg9720bb32011-06-21 09:45:33 +02004741 cb->seq = rdev->bss_generation;
4742
Johannes Berg48ab9052009-07-10 18:42:31 +02004743 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01004744 if (++idx <= start)
4745 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02004746 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01004747 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02004748 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01004749 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02004750 break;
Johannes Berg2a519312009-02-10 21:25:55 +01004751 }
4752 }
4753
Johannes Berg48ab9052009-07-10 18:42:31 +02004754 spin_unlock_bh(&rdev->bss_lock);
4755 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004756
4757 cb->args[1] = idx;
Johannes Berg67748892010-10-04 21:14:06 +02004758 nl80211_finish_netdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01004759
Johannes Berg67748892010-10-04 21:14:06 +02004760 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01004761}
4762
Eric W. Biederman15e47302012-09-07 20:12:54 +00004763static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01004764 int flags, struct net_device *dev,
4765 struct survey_info *survey)
4766{
4767 void *hdr;
4768 struct nlattr *infoattr;
4769
Eric W. Biederman15e47302012-09-07 20:12:54 +00004770 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01004771 NL80211_CMD_NEW_SURVEY_RESULTS);
4772 if (!hdr)
4773 return -ENOMEM;
4774
David S. Miller9360ffd2012-03-29 04:41:26 -04004775 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
4776 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004777
4778 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4779 if (!infoattr)
4780 goto nla_put_failure;
4781
David S. Miller9360ffd2012-03-29 04:41:26 -04004782 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4783 survey->channel->center_freq))
4784 goto nla_put_failure;
4785
4786 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
4787 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
4788 goto nla_put_failure;
4789 if ((survey->filled & SURVEY_INFO_IN_USE) &&
4790 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
4791 goto nla_put_failure;
4792 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
4793 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4794 survey->channel_time))
4795 goto nla_put_failure;
4796 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
4797 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4798 survey->channel_time_busy))
4799 goto nla_put_failure;
4800 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
4801 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4802 survey->channel_time_ext_busy))
4803 goto nla_put_failure;
4804 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
4805 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4806 survey->channel_time_rx))
4807 goto nla_put_failure;
4808 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
4809 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4810 survey->channel_time_tx))
4811 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01004812
4813 nla_nest_end(msg, infoattr);
4814
4815 return genlmsg_end(msg, hdr);
4816
4817 nla_put_failure:
4818 genlmsg_cancel(msg, hdr);
4819 return -EMSGSIZE;
4820}
4821
4822static int nl80211_dump_survey(struct sk_buff *skb,
4823 struct netlink_callback *cb)
4824{
4825 struct survey_info survey;
4826 struct cfg80211_registered_device *dev;
4827 struct net_device *netdev;
Holger Schurig61fa7132009-11-11 12:25:40 +01004828 int survey_idx = cb->args[1];
4829 int res;
4830
Johannes Berg67748892010-10-04 21:14:06 +02004831 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4832 if (res)
4833 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01004834
4835 if (!dev->ops->dump_survey) {
4836 res = -EOPNOTSUPP;
4837 goto out_err;
4838 }
4839
4840 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004841 struct ieee80211_channel *chan;
4842
Holger Schurig61fa7132009-11-11 12:25:40 +01004843 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4844 &survey);
4845 if (res == -ENOENT)
4846 break;
4847 if (res)
4848 goto out_err;
4849
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07004850 /* Survey without a channel doesn't make sense */
4851 if (!survey.channel) {
4852 res = -EINVAL;
4853 goto out;
4854 }
4855
4856 chan = ieee80211_get_channel(&dev->wiphy,
4857 survey.channel->center_freq);
4858 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4859 survey_idx++;
4860 continue;
4861 }
4862
Holger Schurig61fa7132009-11-11 12:25:40 +01004863 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004864 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01004865 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4866 netdev,
4867 &survey) < 0)
4868 goto out;
4869 survey_idx++;
4870 }
4871
4872 out:
4873 cb->args[1] = survey_idx;
4874 res = skb->len;
4875 out_err:
Johannes Berg67748892010-10-04 21:14:06 +02004876 nl80211_finish_netdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01004877 return res;
4878}
4879
Samuel Ortizb23aa672009-07-01 21:26:54 +02004880static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4881{
4882 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4883 NL80211_WPA_VERSION_2));
4884}
4885
Jouni Malinen636a5d32009-03-19 13:39:22 +02004886static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4887{
Johannes Berg4c476992010-10-04 21:36:35 +02004888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4889 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02004890 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004891 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
4892 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02004893 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02004894 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004895 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004896
Johannes Bergf4a11bb2009-03-27 12:40:28 +01004897 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4898 return -EINVAL;
4899
4900 if (!info->attrs[NL80211_ATTR_MAC])
4901 return -EINVAL;
4902
Jouni Malinen17780922009-03-27 20:52:47 +02004903 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4904 return -EINVAL;
4905
Johannes Berg19957bb2009-07-02 17:20:43 +02004906 if (!info->attrs[NL80211_ATTR_SSID])
4907 return -EINVAL;
4908
4909 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4910 return -EINVAL;
4911
Johannes Bergfffd0932009-07-08 14:22:54 +02004912 err = nl80211_parse_key(info, &key);
4913 if (err)
4914 return err;
4915
4916 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02004917 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4918 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02004919 if (!key.p.key || !key.p.key_len)
4920 return -EINVAL;
4921 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4922 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4923 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4924 key.p.key_len != WLAN_KEY_LEN_WEP104))
4925 return -EINVAL;
4926 if (key.idx > 4)
4927 return -EINVAL;
4928 } else {
4929 key.p.key_len = 0;
4930 key.p.key = NULL;
4931 }
4932
Johannes Bergafea0b72010-08-10 09:46:42 +02004933 if (key.idx >= 0) {
4934 int i;
4935 bool ok = false;
4936 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4937 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4938 ok = true;
4939 break;
4940 }
4941 }
Johannes Berg4c476992010-10-04 21:36:35 +02004942 if (!ok)
4943 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02004944 }
4945
Johannes Berg4c476992010-10-04 21:36:35 +02004946 if (!rdev->ops->auth)
4947 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004948
Johannes Berg074ac8d2010-09-16 14:58:22 +02004949 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02004950 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4951 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004952
Johannes Berg19957bb2009-07-02 17:20:43 +02004953 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02004954 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02004955 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02004956 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4957 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02004958
Johannes Berg19957bb2009-07-02 17:20:43 +02004959 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4960 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4961
4962 if (info->attrs[NL80211_ATTR_IE]) {
4963 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4964 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4965 }
4966
4967 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004968 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02004969 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02004970
Jouni Malinene39e5b52012-09-30 19:29:39 +03004971 if (auth_type == NL80211_AUTHTYPE_SAE &&
4972 !info->attrs[NL80211_ATTR_SAE_DATA])
4973 return -EINVAL;
4974
4975 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
4976 if (auth_type != NL80211_AUTHTYPE_SAE)
4977 return -EINVAL;
4978 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
4979 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
4980 /* need to include at least Auth Transaction and Status Code */
4981 if (sae_data_len < 4)
4982 return -EINVAL;
4983 }
4984
Jouni Malinend5cdfac2010-04-04 09:37:19 +03004985 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4986
Johannes Berg95de8172012-01-20 13:55:25 +01004987 /*
4988 * Since we no longer track auth state, ignore
4989 * requests to only change local state.
4990 */
4991 if (local_state_change)
4992 return 0;
4993
Johannes Berg4c476992010-10-04 21:36:35 +02004994 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4995 ssid, ssid_len, ie, ie_len,
Jouni Malinene39e5b52012-09-30 19:29:39 +03004996 key.p.key, key.p.key_len, key.idx,
4997 sae_data, sae_data_len);
Jouni Malinen636a5d32009-03-19 13:39:22 +02004998}
4999
Johannes Bergc0692b82010-08-27 14:26:53 +03005000static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5001 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005002 struct cfg80211_crypto_settings *settings,
5003 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005004{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005005 memset(settings, 0, sizeof(*settings));
5006
Samuel Ortizb23aa672009-07-01 21:26:54 +02005007 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5008
Johannes Bergc0692b82010-08-27 14:26:53 +03005009 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5010 u16 proto;
5011 proto = nla_get_u16(
5012 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5013 settings->control_port_ethertype = cpu_to_be16(proto);
5014 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5015 proto != ETH_P_PAE)
5016 return -EINVAL;
5017 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5018 settings->control_port_no_encrypt = true;
5019 } else
5020 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5021
Samuel Ortizb23aa672009-07-01 21:26:54 +02005022 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5023 void *data;
5024 int len, i;
5025
5026 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5027 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5028 settings->n_ciphers_pairwise = len / sizeof(u32);
5029
5030 if (len % sizeof(u32))
5031 return -EINVAL;
5032
Johannes Berg3dc27d22009-07-02 21:36:37 +02005033 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005034 return -EINVAL;
5035
5036 memcpy(settings->ciphers_pairwise, data, len);
5037
5038 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005039 if (!cfg80211_supported_cipher_suite(
5040 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005041 settings->ciphers_pairwise[i]))
5042 return -EINVAL;
5043 }
5044
5045 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5046 settings->cipher_group =
5047 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005048 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5049 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005050 return -EINVAL;
5051 }
5052
5053 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5054 settings->wpa_versions =
5055 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5056 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5057 return -EINVAL;
5058 }
5059
5060 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5061 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005062 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005063
5064 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5065 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5066 settings->n_akm_suites = len / sizeof(u32);
5067
5068 if (len % sizeof(u32))
5069 return -EINVAL;
5070
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005071 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5072 return -EINVAL;
5073
Samuel Ortizb23aa672009-07-01 21:26:54 +02005074 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005075 }
5076
5077 return 0;
5078}
5079
Jouni Malinen636a5d32009-03-19 13:39:22 +02005080static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
5081{
Johannes Berg4c476992010-10-04 21:36:35 +02005082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5083 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005084 struct cfg80211_crypto_settings crypto;
Johannes Bergf444de02010-05-05 15:25:02 +02005085 struct ieee80211_channel *chan;
Johannes Berg3e5d7642009-07-07 14:37:26 +02005086 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005087 int err, ssid_len, ie_len = 0;
5088 bool use_mfp = false;
Ben Greear7e7c8922011-11-18 11:31:59 -08005089 u32 flags = 0;
5090 struct ieee80211_ht_cap *ht_capa = NULL;
5091 struct ieee80211_ht_cap *ht_capa_mask = NULL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005092
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005093 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5094 return -EINVAL;
5095
5096 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02005097 !info->attrs[NL80211_ATTR_SSID] ||
5098 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005099 return -EINVAL;
5100
Johannes Berg4c476992010-10-04 21:36:35 +02005101 if (!rdev->ops->assoc)
5102 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005103
Johannes Berg074ac8d2010-09-16 14:58:22 +02005104 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005105 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5106 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005107
Johannes Berg19957bb2009-07-02 17:20:43 +02005108 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005109
Johannes Berg19957bb2009-07-02 17:20:43 +02005110 chan = ieee80211_get_channel(&rdev->wiphy,
5111 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005112 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5113 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005114
Johannes Berg19957bb2009-07-02 17:20:43 +02005115 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5116 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005117
5118 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005119 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5120 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005121 }
5122
Jouni Malinendc6382c2009-05-06 22:09:37 +03005123 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005124 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03005125 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02005126 if (mfp == NL80211_MFP_REQUIRED)
Johannes Berg19957bb2009-07-02 17:20:43 +02005127 use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02005128 else if (mfp != NL80211_MFP_NO)
5129 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03005130 }
5131
Johannes Berg3e5d7642009-07-07 14:37:26 +02005132 if (info->attrs[NL80211_ATTR_PREV_BSSID])
5133 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
5134
Ben Greear7e7c8922011-11-18 11:31:59 -08005135 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5136 flags |= ASSOC_REQ_DISABLE_HT;
5137
5138 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5139 ht_capa_mask =
5140 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
5141
5142 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5143 if (!ht_capa_mask)
5144 return -EINVAL;
5145 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5146 }
5147
Johannes Bergc0692b82010-08-27 14:26:53 +03005148 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005149 if (!err)
Johannes Berg3e5d7642009-07-07 14:37:26 +02005150 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
5151 ssid, ssid_len, ie, ie_len, use_mfp,
Ben Greear7e7c8922011-11-18 11:31:59 -08005152 &crypto, flags, ht_capa,
5153 ht_capa_mask);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005154
Jouni Malinen636a5d32009-03-19 13:39:22 +02005155 return err;
5156}
5157
5158static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
5159{
Johannes Berg4c476992010-10-04 21:36:35 +02005160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5161 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005162 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005163 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005164 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005165 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005166
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005167 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5168 return -EINVAL;
5169
5170 if (!info->attrs[NL80211_ATTR_MAC])
5171 return -EINVAL;
5172
5173 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5174 return -EINVAL;
5175
Johannes Berg4c476992010-10-04 21:36:35 +02005176 if (!rdev->ops->deauth)
5177 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005178
Johannes Berg074ac8d2010-09-16 14:58:22 +02005179 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005180 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5181 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005182
Johannes Berg19957bb2009-07-02 17:20:43 +02005183 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005184
Johannes Berg19957bb2009-07-02 17:20:43 +02005185 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5186 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005187 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005188 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005189 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005190
5191 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005192 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5193 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005194 }
5195
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005196 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5197
Johannes Berg4c476992010-10-04 21:36:35 +02005198 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
5199 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005200}
5201
5202static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
5203{
Johannes Berg4c476992010-10-04 21:36:35 +02005204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5205 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005206 const u8 *ie = NULL, *bssid;
Johannes Berg4c476992010-10-04 21:36:35 +02005207 int ie_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005208 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005209 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005210
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005211 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5212 return -EINVAL;
5213
5214 if (!info->attrs[NL80211_ATTR_MAC])
5215 return -EINVAL;
5216
5217 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5218 return -EINVAL;
5219
Johannes Berg4c476992010-10-04 21:36:35 +02005220 if (!rdev->ops->disassoc)
5221 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005222
Johannes Berg074ac8d2010-09-16 14:58:22 +02005223 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005224 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5225 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005226
Johannes Berg19957bb2009-07-02 17:20:43 +02005227 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005228
Johannes Berg19957bb2009-07-02 17:20:43 +02005229 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5230 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005231 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02005232 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02005233 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02005234
5235 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02005236 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5237 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005238 }
5239
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005240 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5241
Johannes Berg4c476992010-10-04 21:36:35 +02005242 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
5243 local_state_change);
Jouni Malinen636a5d32009-03-19 13:39:22 +02005244}
5245
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005246static bool
5247nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
5248 int mcast_rate[IEEE80211_NUM_BANDS],
5249 int rateval)
5250{
5251 struct wiphy *wiphy = &rdev->wiphy;
5252 bool found = false;
5253 int band, i;
5254
5255 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5256 struct ieee80211_supported_band *sband;
5257
5258 sband = wiphy->bands[band];
5259 if (!sband)
5260 continue;
5261
5262 for (i = 0; i < sband->n_bitrates; i++) {
5263 if (sband->bitrates[i].bitrate == rateval) {
5264 mcast_rate[band] = i + 1;
5265 found = true;
5266 break;
5267 }
5268 }
5269 }
5270
5271 return found;
5272}
5273
Johannes Berg04a773a2009-04-19 21:24:32 +02005274static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
5275{
Johannes Berg4c476992010-10-04 21:36:35 +02005276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5277 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005278 struct cfg80211_ibss_params ibss;
5279 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005280 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005281 int err;
5282
Johannes Berg8e30bc52009-04-22 17:45:38 +02005283 memset(&ibss, 0, sizeof(ibss));
5284
Johannes Berg04a773a2009-04-19 21:24:32 +02005285 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5286 return -EINVAL;
5287
5288 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5289 !info->attrs[NL80211_ATTR_SSID] ||
5290 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5291 return -EINVAL;
5292
Johannes Berg8e30bc52009-04-22 17:45:38 +02005293 ibss.beacon_interval = 100;
5294
5295 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
5296 ibss.beacon_interval =
5297 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5298 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5299 return -EINVAL;
5300 }
5301
Johannes Berg4c476992010-10-04 21:36:35 +02005302 if (!rdev->ops->join_ibss)
5303 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005304
Johannes Berg4c476992010-10-04 21:36:35 +02005305 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5306 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005307
Johannes Berg79c97e92009-07-07 03:56:12 +02005308 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02005309
Johannes Berg39193492011-09-16 13:45:25 +02005310 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02005311 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02005312
5313 if (!is_valid_ether_addr(ibss.bssid))
5314 return -EINVAL;
5315 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005316 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5317 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5318
5319 if (info->attrs[NL80211_ATTR_IE]) {
5320 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5321 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5322 }
5323
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005324 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5325 enum nl80211_channel_type channel_type;
5326
Johannes Bergcd6c6592012-05-10 21:27:18 +02005327 if (!nl80211_valid_channel_type(info, &channel_type))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005328 return -EINVAL;
5329
5330 if (channel_type != NL80211_CHAN_NO_HT &&
5331 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
5332 return -EINVAL;
5333
5334 ibss.channel_type = channel_type;
5335 } else {
5336 ibss.channel_type = NL80211_CHAN_NO_HT;
5337 }
5338
5339 ibss.channel = rdev_freq_to_chan(rdev,
5340 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
5341 ibss.channel_type);
Johannes Berg04a773a2009-04-19 21:24:32 +02005342 if (!ibss.channel ||
5343 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
Johannes Berg4c476992010-10-04 21:36:35 +02005344 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
5345 return -EINVAL;
Johannes Berg04a773a2009-04-19 21:24:32 +02005346
Alexander Simon54858ee5b2011-11-30 16:56:32 +01005347 /* Both channels should be able to initiate communication */
5348 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
5349 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
5350 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
5351 ibss.channel_type))
5352 return -EINVAL;
5353
Johannes Berg04a773a2009-04-19 21:24:32 +02005354 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02005355 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02005356
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005357 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5358 u8 *rates =
5359 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5360 int n_rates =
5361 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5362 struct ieee80211_supported_band *sband =
5363 wiphy->bands[ibss.channel->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005364
Johannes Berg34850ab2011-07-18 18:08:35 +02005365 err = ieee80211_get_ratemask(sband, rates, n_rates,
5366 &ibss.basic_rates);
5367 if (err)
5368 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005369 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01005370
5371 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5372 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5373 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5374 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03005375
Johannes Berg4c476992010-10-04 21:36:35 +02005376 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5377 connkeys = nl80211_parse_connkeys(rdev,
5378 info->attrs[NL80211_ATTR_KEYS]);
5379 if (IS_ERR(connkeys))
5380 return PTR_ERR(connkeys);
5381 }
Johannes Berg04a773a2009-04-19 21:24:32 +02005382
Antonio Quartulli267335d2012-01-31 20:25:47 +01005383 ibss.control_port =
5384 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
5385
Johannes Berg4c476992010-10-04 21:36:35 +02005386 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005387 if (err)
5388 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02005389 return err;
5390}
5391
5392static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
5393{
Johannes Berg4c476992010-10-04 21:36:35 +02005394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5395 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02005396
Johannes Berg4c476992010-10-04 21:36:35 +02005397 if (!rdev->ops->leave_ibss)
5398 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005399
Johannes Berg4c476992010-10-04 21:36:35 +02005400 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
5401 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02005402
Johannes Berg4c476992010-10-04 21:36:35 +02005403 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02005404}
5405
Johannes Bergaff89a92009-07-01 21:26:51 +02005406#ifdef CONFIG_NL80211_TESTMODE
5407static struct genl_multicast_group nl80211_testmode_mcgrp = {
5408 .name = "testmode",
5409};
5410
5411static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
5412{
Johannes Berg4c476992010-10-04 21:36:35 +02005413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02005414 int err;
5415
5416 if (!info->attrs[NL80211_ATTR_TESTDATA])
5417 return -EINVAL;
5418
Johannes Bergaff89a92009-07-01 21:26:51 +02005419 err = -EOPNOTSUPP;
5420 if (rdev->ops->testmode_cmd) {
5421 rdev->testmode_info = info;
5422 err = rdev->ops->testmode_cmd(&rdev->wiphy,
5423 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
5424 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
5425 rdev->testmode_info = NULL;
5426 }
5427
Johannes Bergaff89a92009-07-01 21:26:51 +02005428 return err;
5429}
5430
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005431static int nl80211_testmode_dump(struct sk_buff *skb,
5432 struct netlink_callback *cb)
5433{
Johannes Berg00918d32011-12-13 17:22:05 +01005434 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005435 int err;
5436 long phy_idx;
5437 void *data = NULL;
5438 int data_len = 0;
5439
5440 if (cb->args[0]) {
5441 /*
5442 * 0 is a valid index, but not valid for args[0],
5443 * so we need to offset by 1.
5444 */
5445 phy_idx = cb->args[0] - 1;
5446 } else {
5447 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
5448 nl80211_fam.attrbuf, nl80211_fam.maxattr,
5449 nl80211_policy);
5450 if (err)
5451 return err;
Johannes Berg00918d32011-12-13 17:22:05 +01005452
Johannes Berg2bd7e352012-06-15 14:23:16 +02005453 mutex_lock(&cfg80211_mutex);
5454 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
5455 nl80211_fam.attrbuf);
5456 if (IS_ERR(rdev)) {
5457 mutex_unlock(&cfg80211_mutex);
5458 return PTR_ERR(rdev);
Johannes Berg00918d32011-12-13 17:22:05 +01005459 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02005460 phy_idx = rdev->wiphy_idx;
5461 rdev = NULL;
5462 mutex_unlock(&cfg80211_mutex);
5463
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005464 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
5465 cb->args[1] =
5466 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
5467 }
5468
5469 if (cb->args[1]) {
5470 data = nla_data((void *)cb->args[1]);
5471 data_len = nla_len((void *)cb->args[1]);
5472 }
5473
5474 mutex_lock(&cfg80211_mutex);
Johannes Berg00918d32011-12-13 17:22:05 +01005475 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
5476 if (!rdev) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005477 mutex_unlock(&cfg80211_mutex);
5478 return -ENOENT;
5479 }
Johannes Berg00918d32011-12-13 17:22:05 +01005480 cfg80211_lock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005481 mutex_unlock(&cfg80211_mutex);
5482
Johannes Berg00918d32011-12-13 17:22:05 +01005483 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005484 err = -EOPNOTSUPP;
5485 goto out_err;
5486 }
5487
5488 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00005489 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005490 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5491 NL80211_CMD_TESTMODE);
5492 struct nlattr *tmdata;
5493
David S. Miller9360ffd2012-03-29 04:41:26 -04005494 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005495 genlmsg_cancel(skb, hdr);
5496 break;
5497 }
5498
5499 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5500 if (!tmdata) {
5501 genlmsg_cancel(skb, hdr);
5502 break;
5503 }
Johannes Berg00918d32011-12-13 17:22:05 +01005504 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
5505 data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005506 nla_nest_end(skb, tmdata);
5507
5508 if (err == -ENOBUFS || err == -ENOENT) {
5509 genlmsg_cancel(skb, hdr);
5510 break;
5511 } else if (err) {
5512 genlmsg_cancel(skb, hdr);
5513 goto out_err;
5514 }
5515
5516 genlmsg_end(skb, hdr);
5517 }
5518
5519 err = skb->len;
5520 /* see above */
5521 cb->args[0] = phy_idx + 1;
5522 out_err:
Johannes Berg00918d32011-12-13 17:22:05 +01005523 cfg80211_unlock_rdev(rdev);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07005524 return err;
5525}
5526
Johannes Bergaff89a92009-07-01 21:26:51 +02005527static struct sk_buff *
5528__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005529 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02005530{
5531 struct sk_buff *skb;
5532 void *hdr;
5533 struct nlattr *data;
5534
5535 skb = nlmsg_new(approxlen + 100, gfp);
5536 if (!skb)
5537 return NULL;
5538
Eric W. Biederman15e47302012-09-07 20:12:54 +00005539 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02005540 if (!hdr) {
5541 kfree_skb(skb);
5542 return NULL;
5543 }
5544
David S. Miller9360ffd2012-03-29 04:41:26 -04005545 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
5546 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02005547 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
5548
5549 ((void **)skb->cb)[0] = rdev;
5550 ((void **)skb->cb)[1] = hdr;
5551 ((void **)skb->cb)[2] = data;
5552
5553 return skb;
5554
5555 nla_put_failure:
5556 kfree_skb(skb);
5557 return NULL;
5558}
5559
5560struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
5561 int approxlen)
5562{
5563 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5564
5565 if (WARN_ON(!rdev->testmode_info))
5566 return NULL;
5567
5568 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005569 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02005570 rdev->testmode_info->snd_seq,
5571 GFP_KERNEL);
5572}
5573EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
5574
5575int cfg80211_testmode_reply(struct sk_buff *skb)
5576{
5577 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
5578 void *hdr = ((void **)skb->cb)[1];
5579 struct nlattr *data = ((void **)skb->cb)[2];
5580
5581 if (WARN_ON(!rdev->testmode_info)) {
5582 kfree_skb(skb);
5583 return -EINVAL;
5584 }
5585
5586 nla_nest_end(skb, data);
5587 genlmsg_end(skb, hdr);
5588 return genlmsg_reply(skb, rdev->testmode_info);
5589}
5590EXPORT_SYMBOL(cfg80211_testmode_reply);
5591
5592struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5593 int approxlen, gfp_t gfp)
5594{
5595 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5596
5597 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5598}
5599EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5600
5601void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5602{
5603 void *hdr = ((void **)skb->cb)[1];
5604 struct nlattr *data = ((void **)skb->cb)[2];
5605
5606 nla_nest_end(skb, data);
5607 genlmsg_end(skb, hdr);
5608 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5609}
5610EXPORT_SYMBOL(cfg80211_testmode_event);
5611#endif
5612
Samuel Ortizb23aa672009-07-01 21:26:54 +02005613static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5614{
Johannes Berg4c476992010-10-04 21:36:35 +02005615 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5616 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005617 struct cfg80211_connect_params connect;
5618 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02005619 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005620 int err;
5621
5622 memset(&connect, 0, sizeof(connect));
5623
5624 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5625 return -EINVAL;
5626
5627 if (!info->attrs[NL80211_ATTR_SSID] ||
5628 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5629 return -EINVAL;
5630
5631 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5632 connect.auth_type =
5633 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005634 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
5635 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005636 return -EINVAL;
5637 } else
5638 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5639
5640 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5641
Johannes Bergc0692b82010-08-27 14:26:53 +03005642 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005643 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005644 if (err)
5645 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005646
Johannes Berg074ac8d2010-09-16 14:58:22 +02005647 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005648 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5649 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005650
Johannes Berg79c97e92009-07-07 03:56:12 +02005651 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005652
Bala Shanmugam4486ea92012-03-07 17:27:12 +05305653 connect.bg_scan_period = -1;
5654 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
5655 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
5656 connect.bg_scan_period =
5657 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
5658 }
5659
Samuel Ortizb23aa672009-07-01 21:26:54 +02005660 if (info->attrs[NL80211_ATTR_MAC])
5661 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5662 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5663 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5664
5665 if (info->attrs[NL80211_ATTR_IE]) {
5666 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5667 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5668 }
5669
5670 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5671 connect.channel =
5672 ieee80211_get_channel(wiphy,
5673 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5674 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02005675 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5676 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005677 }
5678
Johannes Bergfffd0932009-07-08 14:22:54 +02005679 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5680 connkeys = nl80211_parse_connkeys(rdev,
5681 info->attrs[NL80211_ATTR_KEYS]);
Johannes Berg4c476992010-10-04 21:36:35 +02005682 if (IS_ERR(connkeys))
5683 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005684 }
5685
Ben Greear7e7c8922011-11-18 11:31:59 -08005686 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5687 connect.flags |= ASSOC_REQ_DISABLE_HT;
5688
5689 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5690 memcpy(&connect.ht_capa_mask,
5691 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5692 sizeof(connect.ht_capa_mask));
5693
5694 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005695 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
5696 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08005697 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08005698 }
Ben Greear7e7c8922011-11-18 11:31:59 -08005699 memcpy(&connect.ht_capa,
5700 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5701 sizeof(connect.ht_capa));
5702 }
5703
Johannes Bergfffd0932009-07-08 14:22:54 +02005704 err = cfg80211_connect(rdev, dev, &connect, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02005705 if (err)
5706 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005707 return err;
5708}
5709
5710static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5711{
Johannes Berg4c476992010-10-04 21:36:35 +02005712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5713 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02005714 u16 reason;
5715
5716 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5717 reason = WLAN_REASON_DEAUTH_LEAVING;
5718 else
5719 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5720
5721 if (reason == 0)
5722 return -EINVAL;
5723
Johannes Berg074ac8d2010-09-16 14:58:22 +02005724 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005725 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5726 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005727
Johannes Berg4c476992010-10-04 21:36:35 +02005728 return cfg80211_disconnect(rdev, dev, reason, true);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005729}
5730
Johannes Berg463d0182009-07-14 00:33:35 +02005731static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5732{
Johannes Berg4c476992010-10-04 21:36:35 +02005733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02005734 struct net *net;
5735 int err;
5736 u32 pid;
5737
5738 if (!info->attrs[NL80211_ATTR_PID])
5739 return -EINVAL;
5740
5741 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5742
Johannes Berg463d0182009-07-14 00:33:35 +02005743 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02005744 if (IS_ERR(net))
5745 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005746
5747 err = 0;
5748
5749 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02005750 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5751 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02005752
Johannes Berg463d0182009-07-14 00:33:35 +02005753 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02005754 return err;
5755}
5756
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005757static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5758{
Johannes Berg4c476992010-10-04 21:36:35 +02005759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005760 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5761 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005762 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005763 struct cfg80211_pmksa pmksa;
5764
5765 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5766
5767 if (!info->attrs[NL80211_ATTR_MAC])
5768 return -EINVAL;
5769
5770 if (!info->attrs[NL80211_ATTR_PMKID])
5771 return -EINVAL;
5772
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005773 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5774 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5775
Johannes Berg074ac8d2010-09-16 14:58:22 +02005776 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005777 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5778 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005779
5780 switch (info->genlhdr->cmd) {
5781 case NL80211_CMD_SET_PMKSA:
5782 rdev_ops = rdev->ops->set_pmksa;
5783 break;
5784 case NL80211_CMD_DEL_PMKSA:
5785 rdev_ops = rdev->ops->del_pmksa;
5786 break;
5787 default:
5788 WARN_ON(1);
5789 break;
5790 }
5791
Johannes Berg4c476992010-10-04 21:36:35 +02005792 if (!rdev_ops)
5793 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005794
Johannes Berg4c476992010-10-04 21:36:35 +02005795 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005796}
5797
5798static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5799{
Johannes Berg4c476992010-10-04 21:36:35 +02005800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5801 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005802
Johannes Berg074ac8d2010-09-16 14:58:22 +02005803 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005804 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5805 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005806
Johannes Berg4c476992010-10-04 21:36:35 +02005807 if (!rdev->ops->flush_pmksa)
5808 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005809
Johannes Berg4c476992010-10-04 21:36:35 +02005810 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01005811}
5812
Arik Nemtsov109086c2011-09-28 14:12:50 +03005813static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5814{
5815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5816 struct net_device *dev = info->user_ptr[1];
5817 u8 action_code, dialog_token;
5818 u16 status_code;
5819 u8 *peer;
5820
5821 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5822 !rdev->ops->tdls_mgmt)
5823 return -EOPNOTSUPP;
5824
5825 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5826 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5827 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5828 !info->attrs[NL80211_ATTR_IE] ||
5829 !info->attrs[NL80211_ATTR_MAC])
5830 return -EINVAL;
5831
5832 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5833 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5834 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5835 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5836
5837 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5838 dialog_token, status_code,
5839 nla_data(info->attrs[NL80211_ATTR_IE]),
5840 nla_len(info->attrs[NL80211_ATTR_IE]));
5841}
5842
5843static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5844{
5845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5846 struct net_device *dev = info->user_ptr[1];
5847 enum nl80211_tdls_operation operation;
5848 u8 *peer;
5849
5850 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5851 !rdev->ops->tdls_oper)
5852 return -EOPNOTSUPP;
5853
5854 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5855 !info->attrs[NL80211_ATTR_MAC])
5856 return -EINVAL;
5857
5858 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5859 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5860
5861 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5862}
5863
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005864static int nl80211_remain_on_channel(struct sk_buff *skb,
5865 struct genl_info *info)
5866{
Johannes Berg4c476992010-10-04 21:36:35 +02005867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005868 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005869 struct ieee80211_channel *chan;
5870 struct sk_buff *msg;
5871 void *hdr;
5872 u64 cookie;
5873 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5874 u32 freq, duration;
5875 int err;
5876
5877 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5878 !info->attrs[NL80211_ATTR_DURATION])
5879 return -EINVAL;
5880
5881 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5882
Johannes Berg7c4ef712011-11-18 15:33:48 +01005883 if (!rdev->ops->remain_on_channel ||
5884 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02005885 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005886
Johannes Bergebf348f2012-06-01 12:50:54 +02005887 /*
5888 * We should be on that channel for at least a minimum amount of
5889 * time (10ms) but no longer than the driver supports.
5890 */
5891 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5892 duration > rdev->wiphy.max_remain_on_channel_duration)
5893 return -EINVAL;
5894
Johannes Bergcd6c6592012-05-10 21:27:18 +02005895 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5896 !nl80211_valid_channel_type(info, &channel_type))
5897 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005898
5899 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5900 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02005901 if (chan == NULL)
5902 return -EINVAL;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005903
5904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005905 if (!msg)
5906 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005907
Eric W. Biederman15e47302012-09-07 20:12:54 +00005908 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005909 NL80211_CMD_REMAIN_ON_CHANNEL);
5910
5911 if (IS_ERR(hdr)) {
5912 err = PTR_ERR(hdr);
5913 goto free_msg;
5914 }
5915
Johannes Berg71bbc992012-06-15 15:30:18 +02005916 err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005917 channel_type, duration, &cookie);
5918
5919 if (err)
5920 goto free_msg;
5921
David S. Miller9360ffd2012-03-29 04:41:26 -04005922 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
5923 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005924
5925 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005926
5927 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005928
5929 nla_put_failure:
5930 err = -ENOBUFS;
5931 free_msg:
5932 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005933 return err;
5934}
5935
5936static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5937 struct genl_info *info)
5938{
Johannes Berg4c476992010-10-04 21:36:35 +02005939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02005940 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005941 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005942
5943 if (!info->attrs[NL80211_ATTR_COOKIE])
5944 return -EINVAL;
5945
Johannes Berg4c476992010-10-04 21:36:35 +02005946 if (!rdev->ops->cancel_remain_on_channel)
5947 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005948
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005949 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5950
Johannes Berg71bbc992012-06-15 15:30:18 +02005951 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01005952}
5953
Jouni Malinen13ae75b2009-12-29 12:59:45 +02005954static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5955 u8 *rates, u8 rates_len)
5956{
5957 u8 i;
5958 u32 mask = 0;
5959
5960 for (i = 0; i < rates_len; i++) {
5961 int rate = (rates[i] & 0x7f) * 5;
5962 int ridx;
5963 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5964 struct ieee80211_rate *srate =
5965 &sband->bitrates[ridx];
5966 if (rate == srate->bitrate) {
5967 mask |= 1 << ridx;
5968 break;
5969 }
5970 }
5971 if (ridx == sband->n_bitrates)
5972 return 0; /* rate not found */
5973 }
5974
5975 return mask;
5976}
5977
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005978static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
5979 u8 *rates, u8 rates_len,
5980 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
5981{
5982 u8 i;
5983
5984 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5985
5986 for (i = 0; i < rates_len; i++) {
5987 int ridx, rbit;
5988
5989 ridx = rates[i] / 8;
5990 rbit = BIT(rates[i] % 8);
5991
5992 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03005993 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01005994 return false;
5995
5996 /* check availability */
5997 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
5998 mcs[ridx] |= rbit;
5999 else
6000 return false;
6001 }
6002
6003 return true;
6004}
6005
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006006static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006007 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6008 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006009 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6010 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006011};
6012
6013static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
6014 struct genl_info *info)
6015{
6016 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02006017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006018 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02006019 int rem, i;
6020 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006021 struct nlattr *tx_rates;
6022 struct ieee80211_supported_band *sband;
6023
6024 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
6025 return -EINVAL;
6026
Johannes Berg4c476992010-10-04 21:36:35 +02006027 if (!rdev->ops->set_bitrate_mask)
6028 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006029
6030 memset(&mask, 0, sizeof(mask));
6031 /* Default to all rates enabled */
6032 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
6033 sband = rdev->wiphy.bands[i];
6034 mask.control[i].legacy =
6035 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006036 if (sband)
6037 memcpy(mask.control[i].mcs,
6038 sband->ht_cap.mcs.rx_mask,
6039 sizeof(mask.control[i].mcs));
6040 else
6041 memset(mask.control[i].mcs, 0,
6042 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006043 }
6044
6045 /*
6046 * The nested attribute uses enum nl80211_band as the index. This maps
6047 * directly to the enum ieee80211_band values used in cfg80211.
6048 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006049 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006050 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
6051 {
6052 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02006053 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6054 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006055 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02006056 if (sband == NULL)
6057 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006058 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
6059 nla_len(tx_rates), nl80211_txattr_policy);
6060 if (tb[NL80211_TXRATE_LEGACY]) {
6061 mask.control[band].legacy = rateset_to_mask(
6062 sband,
6063 nla_data(tb[NL80211_TXRATE_LEGACY]),
6064 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05306065 if ((mask.control[band].legacy == 0) &&
6066 nla_len(tb[NL80211_TXRATE_LEGACY]))
6067 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006068 }
6069 if (tb[NL80211_TXRATE_MCS]) {
6070 if (!ht_rateset_to_mask(
6071 sband,
6072 nla_data(tb[NL80211_TXRATE_MCS]),
6073 nla_len(tb[NL80211_TXRATE_MCS]),
6074 mask.control[band].mcs))
6075 return -EINVAL;
6076 }
6077
6078 if (mask.control[band].legacy == 0) {
6079 /* don't allow empty legacy rates if HT
6080 * is not even supported. */
6081 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6082 return -EINVAL;
6083
6084 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
6085 if (mask.control[band].mcs[i])
6086 break;
6087
6088 /* legacy and mcs rates may not be both empty */
6089 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02006090 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006091 }
6092 }
6093
Johannes Berg4c476992010-10-04 21:36:35 +02006094 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006095}
6096
Johannes Berg2e161f72010-08-12 15:38:38 +02006097static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006098{
Johannes Berg4c476992010-10-04 21:36:35 +02006099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006100 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02006101 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02006102
6103 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
6104 return -EINVAL;
6105
Johannes Berg2e161f72010-08-12 15:38:38 +02006106 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
6107 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02006108
Johannes Berg71bbc992012-06-15 15:30:18 +02006109 switch (wdev->iftype) {
6110 case NL80211_IFTYPE_STATION:
6111 case NL80211_IFTYPE_ADHOC:
6112 case NL80211_IFTYPE_P2P_CLIENT:
6113 case NL80211_IFTYPE_AP:
6114 case NL80211_IFTYPE_AP_VLAN:
6115 case NL80211_IFTYPE_MESH_POINT:
6116 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006117 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006118 break;
6119 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006120 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006121 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006122
6123 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02006124 if (!rdev->ops->mgmt_tx)
6125 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006126
Eric W. Biederman15e47302012-09-07 20:12:54 +00006127 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02006128 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
6129 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02006130}
6131
Johannes Berg2e161f72010-08-12 15:38:38 +02006132static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02006133{
Johannes Berg4c476992010-10-04 21:36:35 +02006134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006135 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen026331c2010-02-15 12:53:10 +02006136 struct ieee80211_channel *chan;
6137 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Johannes Berg252aa632010-05-19 12:17:12 +02006138 bool channel_type_valid = false;
Jouni Malinen026331c2010-02-15 12:53:10 +02006139 u32 freq;
6140 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01006141 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006142 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01006143 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006144 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01006145 bool offchan, no_cck, dont_wait_for_ack;
6146
6147 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02006148
6149 if (!info->attrs[NL80211_ATTR_FRAME] ||
6150 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
6151 return -EINVAL;
6152
Johannes Berg4c476992010-10-04 21:36:35 +02006153 if (!rdev->ops->mgmt_tx)
6154 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02006155
Johannes Berg71bbc992012-06-15 15:30:18 +02006156 switch (wdev->iftype) {
6157 case NL80211_IFTYPE_STATION:
6158 case NL80211_IFTYPE_ADHOC:
6159 case NL80211_IFTYPE_P2P_CLIENT:
6160 case NL80211_IFTYPE_AP:
6161 case NL80211_IFTYPE_AP_VLAN:
6162 case NL80211_IFTYPE_MESH_POINT:
6163 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006164 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006165 break;
6166 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006167 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006168 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006169
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006170 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01006171 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006172 return -EINVAL;
6173 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02006174
6175 /*
6176 * We should wait on the channel for at least a minimum amount
6177 * of time (10ms) but no longer than the driver supports.
6178 */
6179 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6180 wait > rdev->wiphy.max_remain_on_channel_duration)
6181 return -EINVAL;
6182
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006183 }
6184
Jouni Malinen026331c2010-02-15 12:53:10 +02006185 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Bergcd6c6592012-05-10 21:27:18 +02006186 if (!nl80211_valid_channel_type(info, &channel_type))
Johannes Berg4c476992010-10-04 21:36:35 +02006187 return -EINVAL;
Johannes Berg252aa632010-05-19 12:17:12 +02006188 channel_type_valid = true;
Jouni Malinen026331c2010-02-15 12:53:10 +02006189 }
6190
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006191 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
6192
Johannes Berg7c4ef712011-11-18 15:33:48 +01006193 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
6194 return -EINVAL;
6195
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306196 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6197
Jouni Malinen026331c2010-02-15 12:53:10 +02006198 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6199 chan = rdev_freq_to_chan(rdev, freq, channel_type);
Johannes Berg4c476992010-10-04 21:36:35 +02006200 if (chan == NULL)
6201 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02006202
Johannes Berge247bd902011-11-04 11:18:21 +01006203 if (!dont_wait_for_ack) {
6204 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6205 if (!msg)
6206 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02006207
Eric W. Biederman15e47302012-09-07 20:12:54 +00006208 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01006209 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02006210
Johannes Berge247bd902011-11-04 11:18:21 +01006211 if (IS_ERR(hdr)) {
6212 err = PTR_ERR(hdr);
6213 goto free_msg;
6214 }
Jouni Malinen026331c2010-02-15 12:53:10 +02006215 }
Johannes Berge247bd902011-11-04 11:18:21 +01006216
Johannes Berg71bbc992012-06-15 15:30:18 +02006217 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006218 channel_type_valid, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02006219 nla_data(info->attrs[NL80211_ATTR_FRAME]),
6220 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01006221 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02006222 if (err)
6223 goto free_msg;
6224
Johannes Berge247bd902011-11-04 11:18:21 +01006225 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04006226 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6227 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02006228
Johannes Berge247bd902011-11-04 11:18:21 +01006229 genlmsg_end(msg, hdr);
6230 return genlmsg_reply(msg, info);
6231 }
6232
6233 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02006234
6235 nla_put_failure:
6236 err = -ENOBUFS;
6237 free_msg:
6238 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02006239 return err;
6240}
6241
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006242static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
6243{
6244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006245 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006246 u64 cookie;
6247
6248 if (!info->attrs[NL80211_ATTR_COOKIE])
6249 return -EINVAL;
6250
6251 if (!rdev->ops->mgmt_tx_cancel_wait)
6252 return -EOPNOTSUPP;
6253
Johannes Berg71bbc992012-06-15 15:30:18 +02006254 switch (wdev->iftype) {
6255 case NL80211_IFTYPE_STATION:
6256 case NL80211_IFTYPE_ADHOC:
6257 case NL80211_IFTYPE_P2P_CLIENT:
6258 case NL80211_IFTYPE_AP:
6259 case NL80211_IFTYPE_AP_VLAN:
6260 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02006261 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02006262 break;
6263 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006264 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02006265 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006266
6267 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6268
Johannes Berg71bbc992012-06-15 15:30:18 +02006269 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01006270}
6271
Kalle Valoffb9eb32010-02-17 17:58:10 +02006272static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
6273{
Johannes Berg4c476992010-10-04 21:36:35 +02006274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006275 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006276 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006277 u8 ps_state;
6278 bool state;
6279 int err;
6280
Johannes Berg4c476992010-10-04 21:36:35 +02006281 if (!info->attrs[NL80211_ATTR_PS_STATE])
6282 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006283
6284 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
6285
Johannes Berg4c476992010-10-04 21:36:35 +02006286 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
6287 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006288
6289 wdev = dev->ieee80211_ptr;
6290
Johannes Berg4c476992010-10-04 21:36:35 +02006291 if (!rdev->ops->set_power_mgmt)
6292 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006293
6294 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
6295
6296 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02006297 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006298
Johannes Berg4c476992010-10-04 21:36:35 +02006299 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
6300 wdev->ps_timeout);
6301 if (!err)
6302 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006303 return err;
6304}
6305
6306static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
6307{
Johannes Berg4c476992010-10-04 21:36:35 +02006308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006309 enum nl80211_ps_state ps_state;
6310 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006311 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02006312 struct sk_buff *msg;
6313 void *hdr;
6314 int err;
6315
Kalle Valoffb9eb32010-02-17 17:58:10 +02006316 wdev = dev->ieee80211_ptr;
6317
Johannes Berg4c476992010-10-04 21:36:35 +02006318 if (!rdev->ops->set_power_mgmt)
6319 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006320
6321 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006322 if (!msg)
6323 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006324
Eric W. Biederman15e47302012-09-07 20:12:54 +00006325 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02006326 NL80211_CMD_GET_POWER_SAVE);
6327 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02006328 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006329 goto free_msg;
6330 }
6331
6332 if (wdev->ps)
6333 ps_state = NL80211_PS_ENABLED;
6334 else
6335 ps_state = NL80211_PS_DISABLED;
6336
David S. Miller9360ffd2012-03-29 04:41:26 -04006337 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
6338 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02006339
6340 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006341 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006342
Johannes Berg4c476992010-10-04 21:36:35 +02006343 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006344 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02006345 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02006346 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02006347 return err;
6348}
6349
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006350static struct nla_policy
6351nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
6352 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
6353 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
6354 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07006355 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
6356 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
6357 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006358};
6359
Thomas Pedersen84f10702012-07-12 16:17:33 -07006360static int nl80211_set_cqm_txe(struct genl_info *info,
6361 u32 rate, u32 pkts, u32 intvl)
6362{
6363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6364 struct wireless_dev *wdev;
6365 struct net_device *dev = info->user_ptr[1];
6366
6367 if ((rate < 0 || rate > 100) ||
6368 (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL))
6369 return -EINVAL;
6370
6371 wdev = dev->ieee80211_ptr;
6372
6373 if (!rdev->ops->set_cqm_txe_config)
6374 return -EOPNOTSUPP;
6375
6376 if (wdev->iftype != NL80211_IFTYPE_STATION &&
6377 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6378 return -EOPNOTSUPP;
6379
6380 return rdev->ops->set_cqm_txe_config(wdev->wiphy, dev,
6381 rate, pkts, intvl);
6382}
6383
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006384static int nl80211_set_cqm_rssi(struct genl_info *info,
6385 s32 threshold, u32 hysteresis)
6386{
Johannes Berg4c476992010-10-04 21:36:35 +02006387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006388 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006389 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006390
6391 if (threshold > 0)
6392 return -EINVAL;
6393
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006394 wdev = dev->ieee80211_ptr;
6395
Johannes Berg4c476992010-10-04 21:36:35 +02006396 if (!rdev->ops->set_cqm_rssi_config)
6397 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006398
Johannes Berg074ac8d2010-09-16 14:58:22 +02006399 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006400 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
6401 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006402
Johannes Berg4c476992010-10-04 21:36:35 +02006403 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
6404 threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006405}
6406
6407static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
6408{
6409 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
6410 struct nlattr *cqm;
6411 int err;
6412
6413 cqm = info->attrs[NL80211_ATTR_CQM];
6414 if (!cqm) {
6415 err = -EINVAL;
6416 goto out;
6417 }
6418
6419 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
6420 nl80211_attr_cqm_policy);
6421 if (err)
6422 goto out;
6423
6424 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
6425 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
6426 s32 threshold;
6427 u32 hysteresis;
6428 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
6429 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6430 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07006431 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
6432 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
6433 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
6434 u32 rate, pkts, intvl;
6435 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
6436 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
6437 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6438 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02006439 } else
6440 err = -EINVAL;
6441
6442out:
6443 return err;
6444}
6445
Johannes Berg29cbe682010-12-03 09:20:44 +01006446static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6447{
6448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6449 struct net_device *dev = info->user_ptr[1];
6450 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08006451 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01006452 int err;
6453
6454 /* start with default */
6455 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08006456 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01006457
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006458 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01006459 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006460 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01006461 if (err)
6462 return err;
6463 }
6464
6465 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
6466 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
6467 return -EINVAL;
6468
Javier Cardonac80d5452010-12-16 17:37:49 -08006469 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
6470 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
6471
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08006472 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6473 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
6474 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6475 return -EINVAL;
6476
Javier Cardonac80d5452010-12-16 17:37:49 -08006477 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6478 /* parse additional setup parameters if given */
6479 err = nl80211_parse_mesh_setup(info, &setup);
6480 if (err)
6481 return err;
6482 }
6483
Johannes Bergcc1d2802012-05-16 23:50:20 +02006484 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6485 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6486
6487 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6488 !nl80211_valid_channel_type(info, &channel_type))
6489 return -EINVAL;
6490
6491 setup.channel = rdev_freq_to_chan(rdev,
6492 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6493 channel_type);
6494 if (!setup.channel)
6495 return -EINVAL;
6496 setup.channel_type = channel_type;
6497 } else {
6498 /* cfg80211_join_mesh() will sort it out */
6499 setup.channel = NULL;
6500 }
6501
Javier Cardonac80d5452010-12-16 17:37:49 -08006502 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006503}
6504
6505static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
6506{
6507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6508 struct net_device *dev = info->user_ptr[1];
6509
6510 return cfg80211_leave_mesh(rdev, dev);
6511}
6512
Johannes Bergdfb89c52012-06-27 09:23:48 +02006513#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02006514static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
6515{
6516 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6517 struct sk_buff *msg;
6518 void *hdr;
6519
6520 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6521 return -EOPNOTSUPP;
6522
6523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6524 if (!msg)
6525 return -ENOMEM;
6526
Eric W. Biederman15e47302012-09-07 20:12:54 +00006527 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02006528 NL80211_CMD_GET_WOWLAN);
6529 if (!hdr)
6530 goto nla_put_failure;
6531
6532 if (rdev->wowlan) {
6533 struct nlattr *nl_wowlan;
6534
6535 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
6536 if (!nl_wowlan)
6537 goto nla_put_failure;
6538
David S. Miller9360ffd2012-03-29 04:41:26 -04006539 if ((rdev->wowlan->any &&
6540 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
6541 (rdev->wowlan->disconnect &&
6542 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
6543 (rdev->wowlan->magic_pkt &&
6544 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
6545 (rdev->wowlan->gtk_rekey_failure &&
6546 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
6547 (rdev->wowlan->eap_identity_req &&
6548 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
6549 (rdev->wowlan->four_way_handshake &&
6550 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
6551 (rdev->wowlan->rfkill_release &&
6552 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
6553 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006554 if (rdev->wowlan->n_patterns) {
6555 struct nlattr *nl_pats, *nl_pat;
6556 int i, pat_len;
6557
6558 nl_pats = nla_nest_start(msg,
6559 NL80211_WOWLAN_TRIG_PKT_PATTERN);
6560 if (!nl_pats)
6561 goto nla_put_failure;
6562
6563 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
6564 nl_pat = nla_nest_start(msg, i + 1);
6565 if (!nl_pat)
6566 goto nla_put_failure;
6567 pat_len = rdev->wowlan->patterns[i].pattern_len;
David S. Miller9360ffd2012-03-29 04:41:26 -04006568 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
6569 DIV_ROUND_UP(pat_len, 8),
6570 rdev->wowlan->patterns[i].mask) ||
6571 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
6572 pat_len,
6573 rdev->wowlan->patterns[i].pattern))
6574 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006575 nla_nest_end(msg, nl_pat);
6576 }
6577 nla_nest_end(msg, nl_pats);
6578 }
6579
6580 nla_nest_end(msg, nl_wowlan);
6581 }
6582
6583 genlmsg_end(msg, hdr);
6584 return genlmsg_reply(msg, info);
6585
6586nla_put_failure:
6587 nlmsg_free(msg);
6588 return -ENOBUFS;
6589}
6590
6591static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
6592{
6593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6594 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02006595 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02006596 struct cfg80211_wowlan *ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006597 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
6598 int err, i;
Johannes Berg6d525632012-04-04 15:05:25 +02006599 bool prev_enabled = rdev->wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006600
6601 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
6602 return -EOPNOTSUPP;
6603
Johannes Bergae33bd82012-07-12 16:25:02 +02006604 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
6605 cfg80211_rdev_free_wowlan(rdev);
6606 rdev->wowlan = NULL;
6607 goto set_wakeup;
6608 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02006609
6610 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
6611 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6612 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
6613 nl80211_wowlan_policy);
6614 if (err)
6615 return err;
6616
6617 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
6618 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
6619 return -EINVAL;
6620 new_triggers.any = true;
6621 }
6622
6623 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
6624 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
6625 return -EINVAL;
6626 new_triggers.disconnect = true;
6627 }
6628
6629 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
6630 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
6631 return -EINVAL;
6632 new_triggers.magic_pkt = true;
6633 }
6634
Johannes Berg77dbbb12011-07-13 10:48:55 +02006635 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
6636 return -EINVAL;
6637
6638 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
6639 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
6640 return -EINVAL;
6641 new_triggers.gtk_rekey_failure = true;
6642 }
6643
6644 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
6645 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
6646 return -EINVAL;
6647 new_triggers.eap_identity_req = true;
6648 }
6649
6650 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
6651 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
6652 return -EINVAL;
6653 new_triggers.four_way_handshake = true;
6654 }
6655
6656 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
6657 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
6658 return -EINVAL;
6659 new_triggers.rfkill_release = true;
6660 }
6661
Johannes Bergff1b6e62011-05-04 15:37:28 +02006662 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
6663 struct nlattr *pat;
6664 int n_patterns = 0;
6665 int rem, pat_len, mask_len;
6666 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
6667
6668 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6669 rem)
6670 n_patterns++;
6671 if (n_patterns > wowlan->n_patterns)
6672 return -EINVAL;
6673
6674 new_triggers.patterns = kcalloc(n_patterns,
6675 sizeof(new_triggers.patterns[0]),
6676 GFP_KERNEL);
6677 if (!new_triggers.patterns)
6678 return -ENOMEM;
6679
6680 new_triggers.n_patterns = n_patterns;
6681 i = 0;
6682
6683 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
6684 rem) {
6685 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
6686 nla_data(pat), nla_len(pat), NULL);
6687 err = -EINVAL;
6688 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
6689 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
6690 goto error;
6691 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6692 mask_len = DIV_ROUND_UP(pat_len, 8);
6693 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
6694 mask_len)
6695 goto error;
6696 if (pat_len > wowlan->pattern_max_len ||
6697 pat_len < wowlan->pattern_min_len)
6698 goto error;
6699
6700 new_triggers.patterns[i].mask =
6701 kmalloc(mask_len + pat_len, GFP_KERNEL);
6702 if (!new_triggers.patterns[i].mask) {
6703 err = -ENOMEM;
6704 goto error;
6705 }
6706 new_triggers.patterns[i].pattern =
6707 new_triggers.patterns[i].mask + mask_len;
6708 memcpy(new_triggers.patterns[i].mask,
6709 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6710 mask_len);
6711 new_triggers.patterns[i].pattern_len = pat_len;
6712 memcpy(new_triggers.patterns[i].pattern,
6713 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6714 pat_len);
6715 i++;
6716 }
6717 }
6718
Johannes Bergae33bd82012-07-12 16:25:02 +02006719 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
6720 if (!ntrig) {
6721 err = -ENOMEM;
6722 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006723 }
Johannes Bergae33bd82012-07-12 16:25:02 +02006724 cfg80211_rdev_free_wowlan(rdev);
6725 rdev->wowlan = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02006726
Johannes Bergae33bd82012-07-12 16:25:02 +02006727 set_wakeup:
Johannes Berg6d525632012-04-04 15:05:25 +02006728 if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
6729 rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
6730
Johannes Bergff1b6e62011-05-04 15:37:28 +02006731 return 0;
6732 error:
6733 for (i = 0; i < new_triggers.n_patterns; i++)
6734 kfree(new_triggers.patterns[i].mask);
6735 kfree(new_triggers.patterns);
6736 return err;
6737}
Johannes Bergdfb89c52012-06-27 09:23:48 +02006738#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02006739
Johannes Berge5497d72011-07-05 16:35:40 +02006740static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6741{
6742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6743 struct net_device *dev = info->user_ptr[1];
6744 struct wireless_dev *wdev = dev->ieee80211_ptr;
6745 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6746 struct cfg80211_gtk_rekey_data rekey_data;
6747 int err;
6748
6749 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6750 return -EINVAL;
6751
6752 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6753 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6754 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6755 nl80211_rekey_policy);
6756 if (err)
6757 return err;
6758
6759 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6760 return -ERANGE;
6761 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6762 return -ERANGE;
6763 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6764 return -ERANGE;
6765
6766 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6767 NL80211_KEK_LEN);
6768 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6769 NL80211_KCK_LEN);
6770 memcpy(rekey_data.replay_ctr,
6771 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6772 NL80211_REPLAY_CTR_LEN);
6773
6774 wdev_lock(wdev);
6775 if (!wdev->current_bss) {
6776 err = -ENOTCONN;
6777 goto out;
6778 }
6779
6780 if (!rdev->ops->set_rekey_data) {
6781 err = -EOPNOTSUPP;
6782 goto out;
6783 }
6784
6785 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6786 out:
6787 wdev_unlock(wdev);
6788 return err;
6789}
6790
Johannes Berg28946da2011-11-04 11:18:12 +01006791static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6792 struct genl_info *info)
6793{
6794 struct net_device *dev = info->user_ptr[1];
6795 struct wireless_dev *wdev = dev->ieee80211_ptr;
6796
6797 if (wdev->iftype != NL80211_IFTYPE_AP &&
6798 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6799 return -EINVAL;
6800
Eric W. Biederman15e47302012-09-07 20:12:54 +00006801 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01006802 return -EBUSY;
6803
Eric W. Biederman15e47302012-09-07 20:12:54 +00006804 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01006805 return 0;
6806}
6807
Johannes Berg7f6cf312011-11-04 11:18:15 +01006808static int nl80211_probe_client(struct sk_buff *skb,
6809 struct genl_info *info)
6810{
6811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6812 struct net_device *dev = info->user_ptr[1];
6813 struct wireless_dev *wdev = dev->ieee80211_ptr;
6814 struct sk_buff *msg;
6815 void *hdr;
6816 const u8 *addr;
6817 u64 cookie;
6818 int err;
6819
6820 if (wdev->iftype != NL80211_IFTYPE_AP &&
6821 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6822 return -EOPNOTSUPP;
6823
6824 if (!info->attrs[NL80211_ATTR_MAC])
6825 return -EINVAL;
6826
6827 if (!rdev->ops->probe_client)
6828 return -EOPNOTSUPP;
6829
6830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6831 if (!msg)
6832 return -ENOMEM;
6833
Eric W. Biederman15e47302012-09-07 20:12:54 +00006834 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01006835 NL80211_CMD_PROBE_CLIENT);
6836
6837 if (IS_ERR(hdr)) {
6838 err = PTR_ERR(hdr);
6839 goto free_msg;
6840 }
6841
6842 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6843
6844 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6845 if (err)
6846 goto free_msg;
6847
David S. Miller9360ffd2012-03-29 04:41:26 -04006848 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6849 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01006850
6851 genlmsg_end(msg, hdr);
6852
6853 return genlmsg_reply(msg, info);
6854
6855 nla_put_failure:
6856 err = -ENOBUFS;
6857 free_msg:
6858 nlmsg_free(msg);
6859 return err;
6860}
6861
Johannes Berg5e7602302011-11-04 11:18:17 +01006862static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6863{
6864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6865
6866 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6867 return -EOPNOTSUPP;
6868
Eric W. Biederman15e47302012-09-07 20:12:54 +00006869 if (rdev->ap_beacons_nlportid)
Johannes Berg5e7602302011-11-04 11:18:17 +01006870 return -EBUSY;
6871
Eric W. Biederman15e47302012-09-07 20:12:54 +00006872 rdev->ap_beacons_nlportid = info->snd_portid;
Johannes Berg5e7602302011-11-04 11:18:17 +01006873
6874 return 0;
6875}
6876
Johannes Berg98104fde2012-06-16 00:19:54 +02006877static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
6878{
6879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6880 struct wireless_dev *wdev = info->user_ptr[1];
6881 int err;
6882
6883 if (!rdev->ops->start_p2p_device)
6884 return -EOPNOTSUPP;
6885
6886 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6887 return -EOPNOTSUPP;
6888
6889 if (wdev->p2p_started)
6890 return 0;
6891
6892 mutex_lock(&rdev->devlist_mtx);
6893 err = cfg80211_can_add_interface(rdev, wdev->iftype);
6894 mutex_unlock(&rdev->devlist_mtx);
6895 if (err)
6896 return err;
6897
6898 err = rdev->ops->start_p2p_device(&rdev->wiphy, wdev);
6899 if (err)
6900 return err;
6901
6902 wdev->p2p_started = true;
6903 mutex_lock(&rdev->devlist_mtx);
6904 rdev->opencount++;
6905 mutex_unlock(&rdev->devlist_mtx);
6906
6907 return 0;
6908}
6909
6910static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
6911{
6912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6913 struct wireless_dev *wdev = info->user_ptr[1];
6914
6915 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
6916 return -EOPNOTSUPP;
6917
6918 if (!rdev->ops->stop_p2p_device)
6919 return -EOPNOTSUPP;
6920
6921 if (!wdev->p2p_started)
6922 return 0;
6923
6924 rdev->ops->stop_p2p_device(&rdev->wiphy, wdev);
6925 wdev->p2p_started = false;
6926
6927 mutex_lock(&rdev->devlist_mtx);
6928 rdev->opencount--;
6929 mutex_unlock(&rdev->devlist_mtx);
6930
6931 if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
6932 rdev->scan_req->aborted = true;
6933 ___cfg80211_scan_done(rdev, true);
6934 }
6935
6936 return 0;
6937}
6938
Johannes Berg4c476992010-10-04 21:36:35 +02006939#define NL80211_FLAG_NEED_WIPHY 0x01
6940#define NL80211_FLAG_NEED_NETDEV 0x02
6941#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02006942#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6943#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6944 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02006945#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02006946/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02006947#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6948 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02006949
6950static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6951 struct genl_info *info)
6952{
6953 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02006954 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02006955 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02006956 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6957
6958 if (rtnl)
6959 rtnl_lock();
6960
6961 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02006962 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02006963 if (IS_ERR(rdev)) {
6964 if (rtnl)
6965 rtnl_unlock();
6966 return PTR_ERR(rdev);
6967 }
6968 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02006969 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
6970 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg89a54e42012-06-15 14:33:17 +02006971 mutex_lock(&cfg80211_mutex);
6972 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
6973 info->attrs);
6974 if (IS_ERR(wdev)) {
6975 mutex_unlock(&cfg80211_mutex);
Johannes Berg4c476992010-10-04 21:36:35 +02006976 if (rtnl)
6977 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02006978 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006979 }
Johannes Berg89a54e42012-06-15 14:33:17 +02006980
Johannes Berg89a54e42012-06-15 14:33:17 +02006981 dev = wdev->netdev;
6982 rdev = wiphy_to_dev(wdev->wiphy);
6983
Johannes Berg1bf614e2012-06-15 15:23:36 +02006984 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
6985 if (!dev) {
6986 mutex_unlock(&cfg80211_mutex);
6987 if (rtnl)
6988 rtnl_unlock();
6989 return -EINVAL;
6990 }
6991
6992 info->user_ptr[1] = dev;
6993 } else {
6994 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02006995 }
Johannes Berg89a54e42012-06-15 14:33:17 +02006996
Johannes Berg1bf614e2012-06-15 15:23:36 +02006997 if (dev) {
6998 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6999 !netif_running(dev)) {
7000 mutex_unlock(&cfg80211_mutex);
7001 if (rtnl)
7002 rtnl_unlock();
7003 return -ENETDOWN;
7004 }
7005
7006 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02007007 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
7008 if (!wdev->p2p_started) {
7009 mutex_unlock(&cfg80211_mutex);
7010 if (rtnl)
7011 rtnl_unlock();
7012 return -ENETDOWN;
7013 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02007014 }
7015
Johannes Berg89a54e42012-06-15 14:33:17 +02007016 cfg80211_lock_rdev(rdev);
7017
7018 mutex_unlock(&cfg80211_mutex);
7019
Johannes Berg4c476992010-10-04 21:36:35 +02007020 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007021 }
7022
7023 return 0;
7024}
7025
7026static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
7027 struct genl_info *info)
7028{
7029 if (info->user_ptr[0])
7030 cfg80211_unlock_rdev(info->user_ptr[0]);
Johannes Berg1bf614e2012-06-15 15:23:36 +02007031 if (info->user_ptr[1]) {
7032 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
7033 struct wireless_dev *wdev = info->user_ptr[1];
7034
7035 if (wdev->netdev)
7036 dev_put(wdev->netdev);
7037 } else {
7038 dev_put(info->user_ptr[1]);
7039 }
7040 }
Johannes Berg4c476992010-10-04 21:36:35 +02007041 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
7042 rtnl_unlock();
7043}
7044
Johannes Berg55682962007-09-20 13:09:35 -04007045static struct genl_ops nl80211_ops[] = {
7046 {
7047 .cmd = NL80211_CMD_GET_WIPHY,
7048 .doit = nl80211_get_wiphy,
7049 .dumpit = nl80211_dump_wiphy,
7050 .policy = nl80211_policy,
7051 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007052 .internal_flags = NL80211_FLAG_NEED_WIPHY,
Johannes Berg55682962007-09-20 13:09:35 -04007053 },
7054 {
7055 .cmd = NL80211_CMD_SET_WIPHY,
7056 .doit = nl80211_set_wiphy,
7057 .policy = nl80211_policy,
7058 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007059 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007060 },
7061 {
7062 .cmd = NL80211_CMD_GET_INTERFACE,
7063 .doit = nl80211_get_interface,
7064 .dumpit = nl80211_dump_interface,
7065 .policy = nl80211_policy,
7066 /* can be retrieved by unprivileged users */
Johannes Berg72fb2ab2012-06-15 17:52:47 +02007067 .internal_flags = NL80211_FLAG_NEED_WDEV,
Johannes Berg55682962007-09-20 13:09:35 -04007068 },
7069 {
7070 .cmd = NL80211_CMD_SET_INTERFACE,
7071 .doit = nl80211_set_interface,
7072 .policy = nl80211_policy,
7073 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007074 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7075 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007076 },
7077 {
7078 .cmd = NL80211_CMD_NEW_INTERFACE,
7079 .doit = nl80211_new_interface,
7080 .policy = nl80211_policy,
7081 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007082 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7083 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007084 },
7085 {
7086 .cmd = NL80211_CMD_DEL_INTERFACE,
7087 .doit = nl80211_del_interface,
7088 .policy = nl80211_policy,
7089 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02007090 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007091 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04007092 },
Johannes Berg41ade002007-12-19 02:03:29 +01007093 {
7094 .cmd = NL80211_CMD_GET_KEY,
7095 .doit = nl80211_get_key,
7096 .policy = nl80211_policy,
7097 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007098 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007099 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007100 },
7101 {
7102 .cmd = NL80211_CMD_SET_KEY,
7103 .doit = nl80211_set_key,
7104 .policy = nl80211_policy,
7105 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007106 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007107 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007108 },
7109 {
7110 .cmd = NL80211_CMD_NEW_KEY,
7111 .doit = nl80211_new_key,
7112 .policy = nl80211_policy,
7113 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007114 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007115 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007116 },
7117 {
7118 .cmd = NL80211_CMD_DEL_KEY,
7119 .doit = nl80211_del_key,
7120 .policy = nl80211_policy,
7121 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007122 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007123 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01007124 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01007125 {
7126 .cmd = NL80211_CMD_SET_BEACON,
7127 .policy = nl80211_policy,
7128 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007129 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007130 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007131 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007132 },
7133 {
Johannes Berg88600202012-02-13 15:17:18 +01007134 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007135 .policy = nl80211_policy,
7136 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007137 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007138 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007139 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007140 },
7141 {
Johannes Berg88600202012-02-13 15:17:18 +01007142 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007143 .policy = nl80211_policy,
7144 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01007145 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007146 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007147 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01007148 },
Johannes Berg5727ef12007-12-19 02:03:34 +01007149 {
7150 .cmd = NL80211_CMD_GET_STATION,
7151 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007152 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01007153 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02007154 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7155 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007156 },
7157 {
7158 .cmd = NL80211_CMD_SET_STATION,
7159 .doit = nl80211_set_station,
7160 .policy = nl80211_policy,
7161 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007163 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007164 },
7165 {
7166 .cmd = NL80211_CMD_NEW_STATION,
7167 .doit = nl80211_new_station,
7168 .policy = nl80211_policy,
7169 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007171 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007172 },
7173 {
7174 .cmd = NL80211_CMD_DEL_STATION,
7175 .doit = nl80211_del_station,
7176 .policy = nl80211_policy,
7177 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007179 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01007180 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007181 {
7182 .cmd = NL80211_CMD_GET_MPATH,
7183 .doit = nl80211_get_mpath,
7184 .dumpit = nl80211_dump_mpath,
7185 .policy = nl80211_policy,
7186 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007187 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007188 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007189 },
7190 {
7191 .cmd = NL80211_CMD_SET_MPATH,
7192 .doit = nl80211_set_mpath,
7193 .policy = nl80211_policy,
7194 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007195 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007196 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007197 },
7198 {
7199 .cmd = NL80211_CMD_NEW_MPATH,
7200 .doit = nl80211_new_mpath,
7201 .policy = nl80211_policy,
7202 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007204 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007205 },
7206 {
7207 .cmd = NL80211_CMD_DEL_MPATH,
7208 .doit = nl80211_del_mpath,
7209 .policy = nl80211_policy,
7210 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007211 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007212 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01007213 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007214 {
7215 .cmd = NL80211_CMD_SET_BSS,
7216 .doit = nl80211_set_bss,
7217 .policy = nl80211_policy,
7218 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007220 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007221 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007222 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007223 .cmd = NL80211_CMD_GET_REG,
7224 .doit = nl80211_get_reg,
7225 .policy = nl80211_policy,
7226 /* can be retrieved by unprivileged users */
7227 },
7228 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007229 .cmd = NL80211_CMD_SET_REG,
7230 .doit = nl80211_set_reg,
7231 .policy = nl80211_policy,
7232 .flags = GENL_ADMIN_PERM,
7233 },
7234 {
7235 .cmd = NL80211_CMD_REQ_SET_REG,
7236 .doit = nl80211_req_set_reg,
7237 .policy = nl80211_policy,
7238 .flags = GENL_ADMIN_PERM,
7239 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007240 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007241 .cmd = NL80211_CMD_GET_MESH_CONFIG,
7242 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007243 .policy = nl80211_policy,
7244 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007246 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007247 },
7248 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007249 .cmd = NL80211_CMD_SET_MESH_CONFIG,
7250 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007251 .policy = nl80211_policy,
7252 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01007253 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007254 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007255 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02007256 {
Johannes Berg2a519312009-02-10 21:25:55 +01007257 .cmd = NL80211_CMD_TRIGGER_SCAN,
7258 .doit = nl80211_trigger_scan,
7259 .policy = nl80211_policy,
7260 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02007261 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007262 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01007263 },
7264 {
7265 .cmd = NL80211_CMD_GET_SCAN,
7266 .policy = nl80211_policy,
7267 .dumpit = nl80211_dump_scan,
7268 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02007269 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007270 .cmd = NL80211_CMD_START_SCHED_SCAN,
7271 .doit = nl80211_start_sched_scan,
7272 .policy = nl80211_policy,
7273 .flags = GENL_ADMIN_PERM,
7274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7275 NL80211_FLAG_NEED_RTNL,
7276 },
7277 {
7278 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
7279 .doit = nl80211_stop_sched_scan,
7280 .policy = nl80211_policy,
7281 .flags = GENL_ADMIN_PERM,
7282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7283 NL80211_FLAG_NEED_RTNL,
7284 },
7285 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02007286 .cmd = NL80211_CMD_AUTHENTICATE,
7287 .doit = nl80211_authenticate,
7288 .policy = nl80211_policy,
7289 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007290 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007291 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007292 },
7293 {
7294 .cmd = NL80211_CMD_ASSOCIATE,
7295 .doit = nl80211_associate,
7296 .policy = nl80211_policy,
7297 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007299 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007300 },
7301 {
7302 .cmd = NL80211_CMD_DEAUTHENTICATE,
7303 .doit = nl80211_deauthenticate,
7304 .policy = nl80211_policy,
7305 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007307 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007308 },
7309 {
7310 .cmd = NL80211_CMD_DISASSOCIATE,
7311 .doit = nl80211_disassociate,
7312 .policy = nl80211_policy,
7313 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007315 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02007316 },
Johannes Berg04a773a2009-04-19 21:24:32 +02007317 {
7318 .cmd = NL80211_CMD_JOIN_IBSS,
7319 .doit = nl80211_join_ibss,
7320 .policy = nl80211_policy,
7321 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007322 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007323 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007324 },
7325 {
7326 .cmd = NL80211_CMD_LEAVE_IBSS,
7327 .doit = nl80211_leave_ibss,
7328 .policy = nl80211_policy,
7329 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007331 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02007332 },
Johannes Bergaff89a92009-07-01 21:26:51 +02007333#ifdef CONFIG_NL80211_TESTMODE
7334 {
7335 .cmd = NL80211_CMD_TESTMODE,
7336 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007337 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02007338 .policy = nl80211_policy,
7339 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007340 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7341 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02007342 },
7343#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02007344 {
7345 .cmd = NL80211_CMD_CONNECT,
7346 .doit = nl80211_connect,
7347 .policy = nl80211_policy,
7348 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007349 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007350 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007351 },
7352 {
7353 .cmd = NL80211_CMD_DISCONNECT,
7354 .doit = nl80211_disconnect,
7355 .policy = nl80211_policy,
7356 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02007357 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007358 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007359 },
Johannes Berg463d0182009-07-14 00:33:35 +02007360 {
7361 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
7362 .doit = nl80211_wiphy_netns,
7363 .policy = nl80211_policy,
7364 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007365 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7366 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02007367 },
Holger Schurig61fa7132009-11-11 12:25:40 +01007368 {
7369 .cmd = NL80211_CMD_GET_SURVEY,
7370 .policy = nl80211_policy,
7371 .dumpit = nl80211_dump_survey,
7372 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007373 {
7374 .cmd = NL80211_CMD_SET_PMKSA,
7375 .doit = nl80211_setdel_pmksa,
7376 .policy = nl80211_policy,
7377 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007379 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007380 },
7381 {
7382 .cmd = NL80211_CMD_DEL_PMKSA,
7383 .doit = nl80211_setdel_pmksa,
7384 .policy = nl80211_policy,
7385 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007387 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007388 },
7389 {
7390 .cmd = NL80211_CMD_FLUSH_PMKSA,
7391 .doit = nl80211_flush_pmksa,
7392 .policy = nl80211_policy,
7393 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007395 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007396 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007397 {
7398 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
7399 .doit = nl80211_remain_on_channel,
7400 .policy = nl80211_policy,
7401 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007402 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007403 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007404 },
7405 {
7406 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7407 .doit = nl80211_cancel_remain_on_channel,
7408 .policy = nl80211_policy,
7409 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007410 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007411 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007412 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007413 {
7414 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
7415 .doit = nl80211_set_tx_bitrate_mask,
7416 .policy = nl80211_policy,
7417 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007418 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7419 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007420 },
Jouni Malinen026331c2010-02-15 12:53:10 +02007421 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007422 .cmd = NL80211_CMD_REGISTER_FRAME,
7423 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007424 .policy = nl80211_policy,
7425 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007426 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02007427 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007428 },
7429 {
Johannes Berg2e161f72010-08-12 15:38:38 +02007430 .cmd = NL80211_CMD_FRAME,
7431 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02007432 .policy = nl80211_policy,
7433 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007434 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02007435 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02007436 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02007437 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007438 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
7439 .doit = nl80211_tx_mgmt_cancel_wait,
7440 .policy = nl80211_policy,
7441 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02007442 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007443 NL80211_FLAG_NEED_RTNL,
7444 },
7445 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02007446 .cmd = NL80211_CMD_SET_POWER_SAVE,
7447 .doit = nl80211_set_power_save,
7448 .policy = nl80211_policy,
7449 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007450 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7451 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007452 },
7453 {
7454 .cmd = NL80211_CMD_GET_POWER_SAVE,
7455 .doit = nl80211_get_power_save,
7456 .policy = nl80211_policy,
7457 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02007458 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7459 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007460 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007461 {
7462 .cmd = NL80211_CMD_SET_CQM,
7463 .doit = nl80211_set_cqm,
7464 .policy = nl80211_policy,
7465 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007466 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7467 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007468 },
Johannes Bergf444de02010-05-05 15:25:02 +02007469 {
7470 .cmd = NL80211_CMD_SET_CHANNEL,
7471 .doit = nl80211_set_channel,
7472 .policy = nl80211_policy,
7473 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02007474 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7475 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02007476 },
Bill Jordane8347eb2010-10-01 13:54:28 -04007477 {
7478 .cmd = NL80211_CMD_SET_WDS_PEER,
7479 .doit = nl80211_set_wds_peer,
7480 .policy = nl80211_policy,
7481 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02007482 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7483 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04007484 },
Johannes Berg29cbe682010-12-03 09:20:44 +01007485 {
7486 .cmd = NL80211_CMD_JOIN_MESH,
7487 .doit = nl80211_join_mesh,
7488 .policy = nl80211_policy,
7489 .flags = GENL_ADMIN_PERM,
7490 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7491 NL80211_FLAG_NEED_RTNL,
7492 },
7493 {
7494 .cmd = NL80211_CMD_LEAVE_MESH,
7495 .doit = nl80211_leave_mesh,
7496 .policy = nl80211_policy,
7497 .flags = GENL_ADMIN_PERM,
7498 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7499 NL80211_FLAG_NEED_RTNL,
7500 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007501#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02007502 {
7503 .cmd = NL80211_CMD_GET_WOWLAN,
7504 .doit = nl80211_get_wowlan,
7505 .policy = nl80211_policy,
7506 /* can be retrieved by unprivileged users */
7507 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7508 NL80211_FLAG_NEED_RTNL,
7509 },
7510 {
7511 .cmd = NL80211_CMD_SET_WOWLAN,
7512 .doit = nl80211_set_wowlan,
7513 .policy = nl80211_policy,
7514 .flags = GENL_ADMIN_PERM,
7515 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7516 NL80211_FLAG_NEED_RTNL,
7517 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02007518#endif
Johannes Berge5497d72011-07-05 16:35:40 +02007519 {
7520 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
7521 .doit = nl80211_set_rekey_data,
7522 .policy = nl80211_policy,
7523 .flags = GENL_ADMIN_PERM,
7524 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7525 NL80211_FLAG_NEED_RTNL,
7526 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03007527 {
7528 .cmd = NL80211_CMD_TDLS_MGMT,
7529 .doit = nl80211_tdls_mgmt,
7530 .policy = nl80211_policy,
7531 .flags = GENL_ADMIN_PERM,
7532 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7533 NL80211_FLAG_NEED_RTNL,
7534 },
7535 {
7536 .cmd = NL80211_CMD_TDLS_OPER,
7537 .doit = nl80211_tdls_oper,
7538 .policy = nl80211_policy,
7539 .flags = GENL_ADMIN_PERM,
7540 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
7541 NL80211_FLAG_NEED_RTNL,
7542 },
Johannes Berg28946da2011-11-04 11:18:12 +01007543 {
7544 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
7545 .doit = nl80211_register_unexpected_frame,
7546 .policy = nl80211_policy,
7547 .flags = GENL_ADMIN_PERM,
7548 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7549 NL80211_FLAG_NEED_RTNL,
7550 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01007551 {
7552 .cmd = NL80211_CMD_PROBE_CLIENT,
7553 .doit = nl80211_probe_client,
7554 .policy = nl80211_policy,
7555 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02007556 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01007557 NL80211_FLAG_NEED_RTNL,
7558 },
Johannes Berg5e7602302011-11-04 11:18:17 +01007559 {
7560 .cmd = NL80211_CMD_REGISTER_BEACONS,
7561 .doit = nl80211_register_beacons,
7562 .policy = nl80211_policy,
7563 .flags = GENL_ADMIN_PERM,
7564 .internal_flags = NL80211_FLAG_NEED_WIPHY |
7565 NL80211_FLAG_NEED_RTNL,
7566 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01007567 {
7568 .cmd = NL80211_CMD_SET_NOACK_MAP,
7569 .doit = nl80211_set_noack_map,
7570 .policy = nl80211_policy,
7571 .flags = GENL_ADMIN_PERM,
7572 .internal_flags = NL80211_FLAG_NEED_NETDEV |
7573 NL80211_FLAG_NEED_RTNL,
7574 },
Johannes Berg98104fde2012-06-16 00:19:54 +02007575 {
7576 .cmd = NL80211_CMD_START_P2P_DEVICE,
7577 .doit = nl80211_start_p2p_device,
7578 .policy = nl80211_policy,
7579 .flags = GENL_ADMIN_PERM,
7580 .internal_flags = NL80211_FLAG_NEED_WDEV |
7581 NL80211_FLAG_NEED_RTNL,
7582 },
7583 {
7584 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
7585 .doit = nl80211_stop_p2p_device,
7586 .policy = nl80211_policy,
7587 .flags = GENL_ADMIN_PERM,
7588 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
7589 NL80211_FLAG_NEED_RTNL,
7590 },
Johannes Berg55682962007-09-20 13:09:35 -04007591};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007592
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007593static struct genl_multicast_group nl80211_mlme_mcgrp = {
7594 .name = "mlme",
7595};
Johannes Berg55682962007-09-20 13:09:35 -04007596
7597/* multicast groups */
7598static struct genl_multicast_group nl80211_config_mcgrp = {
7599 .name = "config",
7600};
Johannes Berg2a519312009-02-10 21:25:55 +01007601static struct genl_multicast_group nl80211_scan_mcgrp = {
7602 .name = "scan",
7603};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007604static struct genl_multicast_group nl80211_regulatory_mcgrp = {
7605 .name = "regulatory",
7606};
Johannes Berg55682962007-09-20 13:09:35 -04007607
7608/* notification functions */
7609
7610void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
7611{
7612 struct sk_buff *msg;
7613
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007614 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007615 if (!msg)
7616 return;
7617
7618 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7619 nlmsg_free(msg);
7620 return;
7621 }
7622
Johannes Berg463d0182009-07-14 00:33:35 +02007623 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7624 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04007625}
7626
Johannes Berg362a4152009-05-24 16:43:15 +02007627static int nl80211_add_scan_req(struct sk_buff *msg,
7628 struct cfg80211_registered_device *rdev)
7629{
7630 struct cfg80211_scan_request *req = rdev->scan_req;
7631 struct nlattr *nest;
7632 int i;
7633
Johannes Berg667503dd2009-07-07 03:56:11 +02007634 ASSERT_RDEV_LOCK(rdev);
7635
Johannes Berg362a4152009-05-24 16:43:15 +02007636 if (WARN_ON(!req))
7637 return 0;
7638
7639 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
7640 if (!nest)
7641 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007642 for (i = 0; i < req->n_ssids; i++) {
7643 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
7644 goto nla_put_failure;
7645 }
Johannes Berg362a4152009-05-24 16:43:15 +02007646 nla_nest_end(msg, nest);
7647
7648 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
7649 if (!nest)
7650 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007651 for (i = 0; i < req->n_channels; i++) {
7652 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
7653 goto nla_put_failure;
7654 }
Johannes Berg362a4152009-05-24 16:43:15 +02007655 nla_nest_end(msg, nest);
7656
David S. Miller9360ffd2012-03-29 04:41:26 -04007657 if (req->ie &&
7658 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
7659 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02007660
7661 return 0;
7662 nla_put_failure:
7663 return -ENOBUFS;
7664}
7665
Johannes Berga538e2d2009-06-16 19:56:42 +02007666static int nl80211_send_scan_msg(struct sk_buff *msg,
7667 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007668 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007669 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02007670 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01007671{
7672 void *hdr;
7673
Eric W. Biederman15e47302012-09-07 20:12:54 +00007674 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01007675 if (!hdr)
7676 return -1;
7677
David S. Miller9360ffd2012-03-29 04:41:26 -04007678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02007679 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
7680 wdev->netdev->ifindex)) ||
7681 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007682 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007683
Johannes Berg362a4152009-05-24 16:43:15 +02007684 /* ignore errors and send incomplete event anyway */
7685 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007686
7687 return genlmsg_end(msg, hdr);
7688
7689 nla_put_failure:
7690 genlmsg_cancel(msg, hdr);
7691 return -EMSGSIZE;
7692}
7693
Luciano Coelho807f8a82011-05-11 17:09:35 +03007694static int
7695nl80211_send_sched_scan_msg(struct sk_buff *msg,
7696 struct cfg80211_registered_device *rdev,
7697 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007698 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007699{
7700 void *hdr;
7701
Eric W. Biederman15e47302012-09-07 20:12:54 +00007702 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007703 if (!hdr)
7704 return -1;
7705
David S. Miller9360ffd2012-03-29 04:41:26 -04007706 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7707 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
7708 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007709
7710 return genlmsg_end(msg, hdr);
7711
7712 nla_put_failure:
7713 genlmsg_cancel(msg, hdr);
7714 return -EMSGSIZE;
7715}
7716
Johannes Berga538e2d2009-06-16 19:56:42 +02007717void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007718 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02007719{
7720 struct sk_buff *msg;
7721
Thomas Graf58050fc2012-06-28 03:57:45 +00007722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007723 if (!msg)
7724 return;
7725
Johannes Bergfd014282012-06-18 19:17:03 +02007726 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007727 NL80211_CMD_TRIGGER_SCAN) < 0) {
7728 nlmsg_free(msg);
7729 return;
7730 }
7731
Johannes Berg463d0182009-07-14 00:33:35 +02007732 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7733 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02007734}
7735
Johannes Berg2a519312009-02-10 21:25:55 +01007736void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007737 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007738{
7739 struct sk_buff *msg;
7740
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007741 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007742 if (!msg)
7743 return;
7744
Johannes Bergfd014282012-06-18 19:17:03 +02007745 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007746 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007747 nlmsg_free(msg);
7748 return;
7749 }
7750
Johannes Berg463d0182009-07-14 00:33:35 +02007751 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7752 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007753}
7754
7755void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02007756 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01007757{
7758 struct sk_buff *msg;
7759
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007760 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007761 if (!msg)
7762 return;
7763
Johannes Bergfd014282012-06-18 19:17:03 +02007764 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02007765 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007766 nlmsg_free(msg);
7767 return;
7768 }
7769
Johannes Berg463d0182009-07-14 00:33:35 +02007770 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7771 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01007772}
7773
Luciano Coelho807f8a82011-05-11 17:09:35 +03007774void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
7775 struct net_device *netdev)
7776{
7777 struct sk_buff *msg;
7778
7779 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7780 if (!msg)
7781 return;
7782
7783 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7784 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
7785 nlmsg_free(msg);
7786 return;
7787 }
7788
7789 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7790 nl80211_scan_mcgrp.id, GFP_KERNEL);
7791}
7792
7793void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
7794 struct net_device *netdev, u32 cmd)
7795{
7796 struct sk_buff *msg;
7797
Thomas Graf58050fc2012-06-28 03:57:45 +00007798 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007799 if (!msg)
7800 return;
7801
7802 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7803 nlmsg_free(msg);
7804 return;
7805 }
7806
7807 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7808 nl80211_scan_mcgrp.id, GFP_KERNEL);
7809}
7810
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007811/*
7812 * This can happen on global regulatory changes or device specific settings
7813 * based on custom world regulatory domains.
7814 */
7815void nl80211_send_reg_change_event(struct regulatory_request *request)
7816{
7817 struct sk_buff *msg;
7818 void *hdr;
7819
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007821 if (!msg)
7822 return;
7823
7824 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
7825 if (!hdr) {
7826 nlmsg_free(msg);
7827 return;
7828 }
7829
7830 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04007831 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
7832 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007833
David S. Miller9360ffd2012-03-29 04:41:26 -04007834 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
7835 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7836 NL80211_REGDOM_TYPE_WORLD))
7837 goto nla_put_failure;
7838 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
7839 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7840 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
7841 goto nla_put_failure;
7842 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
7843 request->intersect) {
7844 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7845 NL80211_REGDOM_TYPE_INTERSECTION))
7846 goto nla_put_failure;
7847 } else {
7848 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
7849 NL80211_REGDOM_TYPE_COUNTRY) ||
7850 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
7851 request->alpha2))
7852 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007853 }
7854
David S. Miller9360ffd2012-03-29 04:41:26 -04007855 if (wiphy_idx_valid(request->wiphy_idx) &&
7856 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
7857 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007858
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007859 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007860
Johannes Bergbc43b282009-07-25 10:54:13 +02007861 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02007862 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02007863 GFP_ATOMIC);
7864 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04007865
7866 return;
7867
7868nla_put_failure:
7869 genlmsg_cancel(msg, hdr);
7870 nlmsg_free(msg);
7871}
7872
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007873static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7874 struct net_device *netdev,
7875 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007876 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007877{
7878 struct sk_buff *msg;
7879 void *hdr;
7880
Johannes Berge6d6e342009-07-01 21:26:47 +02007881 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007882 if (!msg)
7883 return;
7884
7885 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7886 if (!hdr) {
7887 nlmsg_free(msg);
7888 return;
7889 }
7890
David S. Miller9360ffd2012-03-29 04:41:26 -04007891 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7892 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7893 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
7894 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007895
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007896 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007897
Johannes Berg463d0182009-07-14 00:33:35 +02007898 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7899 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007900 return;
7901
7902 nla_put_failure:
7903 genlmsg_cancel(msg, hdr);
7904 nlmsg_free(msg);
7905}
7906
7907void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007908 struct net_device *netdev, const u8 *buf,
7909 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007910{
7911 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007912 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007913}
7914
7915void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7916 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007917 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007918{
Johannes Berge6d6e342009-07-01 21:26:47 +02007919 nl80211_send_mlme_event(rdev, netdev, buf, len,
7920 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007921}
7922
Jouni Malinen53b46b82009-03-27 20:53:56 +02007923void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007924 struct net_device *netdev, const u8 *buf,
7925 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007926{
7927 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007928 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007929}
7930
Jouni Malinen53b46b82009-03-27 20:53:56 +02007931void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7932 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02007933 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007934{
7935 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02007936 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02007937}
7938
Jouni Malinencf4e5942010-12-16 00:52:40 +02007939void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7940 struct net_device *netdev, const u8 *buf,
7941 size_t len, gfp_t gfp)
7942{
7943 nl80211_send_mlme_event(rdev, netdev, buf, len,
7944 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7945}
7946
7947void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7948 struct net_device *netdev, const u8 *buf,
7949 size_t len, gfp_t gfp)
7950{
7951 nl80211_send_mlme_event(rdev, netdev, buf, len,
7952 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7953}
7954
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04007955static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7956 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02007957 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007958{
7959 struct sk_buff *msg;
7960 void *hdr;
7961
Johannes Berge6d6e342009-07-01 21:26:47 +02007962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007963 if (!msg)
7964 return;
7965
7966 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7967 if (!hdr) {
7968 nlmsg_free(msg);
7969 return;
7970 }
7971
David S. Miller9360ffd2012-03-29 04:41:26 -04007972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
7973 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
7974 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
7975 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
7976 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03007977
Johannes Berg3b7b72e2011-10-22 19:05:51 +02007978 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03007979
Johannes Berg463d0182009-07-14 00:33:35 +02007980 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7981 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007982 return;
7983
7984 nla_put_failure:
7985 genlmsg_cancel(msg, hdr);
7986 nlmsg_free(msg);
7987}
7988
7989void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007990 struct net_device *netdev, const u8 *addr,
7991 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03007992{
7993 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02007994 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03007995}
7996
7997void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02007998 struct net_device *netdev, const u8 *addr,
7999 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03008000{
Johannes Berge6d6e342009-07-01 21:26:47 +02008001 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
8002 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03008003}
8004
Samuel Ortizb23aa672009-07-01 21:26:54 +02008005void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
8006 struct net_device *netdev, const u8 *bssid,
8007 const u8 *req_ie, size_t req_ie_len,
8008 const u8 *resp_ie, size_t resp_ie_len,
8009 u16 status, gfp_t gfp)
8010{
8011 struct sk_buff *msg;
8012 void *hdr;
8013
Thomas Graf58050fc2012-06-28 03:57:45 +00008014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008015 if (!msg)
8016 return;
8017
8018 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
8019 if (!hdr) {
8020 nlmsg_free(msg);
8021 return;
8022 }
8023
David S. Miller9360ffd2012-03-29 04:41:26 -04008024 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8025 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8026 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
8027 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
8028 (req_ie &&
8029 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8030 (resp_ie &&
8031 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8032 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008033
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008034 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008035
Johannes Berg463d0182009-07-14 00:33:35 +02008036 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8037 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008038 return;
8039
8040 nla_put_failure:
8041 genlmsg_cancel(msg, hdr);
8042 nlmsg_free(msg);
8043
8044}
8045
8046void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
8047 struct net_device *netdev, const u8 *bssid,
8048 const u8 *req_ie, size_t req_ie_len,
8049 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
8050{
8051 struct sk_buff *msg;
8052 void *hdr;
8053
Thomas Graf58050fc2012-06-28 03:57:45 +00008054 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008055 if (!msg)
8056 return;
8057
8058 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
8059 if (!hdr) {
8060 nlmsg_free(msg);
8061 return;
8062 }
8063
David S. Miller9360ffd2012-03-29 04:41:26 -04008064 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8065 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8066 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
8067 (req_ie &&
8068 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
8069 (resp_ie &&
8070 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
8071 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008072
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008073 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008074
Johannes Berg463d0182009-07-14 00:33:35 +02008075 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8076 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008077 return;
8078
8079 nla_put_failure:
8080 genlmsg_cancel(msg, hdr);
8081 nlmsg_free(msg);
8082
8083}
8084
8085void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
8086 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02008087 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02008088{
8089 struct sk_buff *msg;
8090 void *hdr;
8091
Thomas Graf58050fc2012-06-28 03:57:45 +00008092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008093 if (!msg)
8094 return;
8095
8096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
8097 if (!hdr) {
8098 nlmsg_free(msg);
8099 return;
8100 }
8101
David S. Miller9360ffd2012-03-29 04:41:26 -04008102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8103 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8104 (from_ap && reason &&
8105 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
8106 (from_ap &&
8107 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
8108 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8109 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008110
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008111 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008112
Johannes Berg463d0182009-07-14 00:33:35 +02008113 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8114 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008115 return;
8116
8117 nla_put_failure:
8118 genlmsg_cancel(msg, hdr);
8119 nlmsg_free(msg);
8120
8121}
8122
Johannes Berg04a773a2009-04-19 21:24:32 +02008123void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
8124 struct net_device *netdev, const u8 *bssid,
8125 gfp_t gfp)
8126{
8127 struct sk_buff *msg;
8128 void *hdr;
8129
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008130 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008131 if (!msg)
8132 return;
8133
8134 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
8135 if (!hdr) {
8136 nlmsg_free(msg);
8137 return;
8138 }
8139
David S. Miller9360ffd2012-03-29 04:41:26 -04008140 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8141 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8142 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8143 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02008144
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008145 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02008146
Johannes Berg463d0182009-07-14 00:33:35 +02008147 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8148 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02008149 return;
8150
8151 nla_put_failure:
8152 genlmsg_cancel(msg, hdr);
8153 nlmsg_free(msg);
8154}
8155
Javier Cardonac93b5e72011-04-07 15:08:34 -07008156void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
8157 struct net_device *netdev,
8158 const u8 *macaddr, const u8* ie, u8 ie_len,
8159 gfp_t gfp)
8160{
8161 struct sk_buff *msg;
8162 void *hdr;
8163
8164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8165 if (!msg)
8166 return;
8167
8168 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
8169 if (!hdr) {
8170 nlmsg_free(msg);
8171 return;
8172 }
8173
David S. Miller9360ffd2012-03-29 04:41:26 -04008174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8176 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) ||
8177 (ie_len && ie &&
8178 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8179 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07008180
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008181 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07008182
8183 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8184 nl80211_mlme_mcgrp.id, gfp);
8185 return;
8186
8187 nla_put_failure:
8188 genlmsg_cancel(msg, hdr);
8189 nlmsg_free(msg);
8190}
8191
Jouni Malinena3b8b052009-03-27 21:59:49 +02008192void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
8193 struct net_device *netdev, const u8 *addr,
8194 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02008195 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02008196{
8197 struct sk_buff *msg;
8198 void *hdr;
8199
Johannes Berge6d6e342009-07-01 21:26:47 +02008200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008201 if (!msg)
8202 return;
8203
8204 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
8205 if (!hdr) {
8206 nlmsg_free(msg);
8207 return;
8208 }
8209
David S. Miller9360ffd2012-03-29 04:41:26 -04008210 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8211 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8212 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
8213 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
8214 (key_id != -1 &&
8215 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
8216 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
8217 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02008218
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008219 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008220
Johannes Berg463d0182009-07-14 00:33:35 +02008221 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8222 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02008223 return;
8224
8225 nla_put_failure:
8226 genlmsg_cancel(msg, hdr);
8227 nlmsg_free(msg);
8228}
8229
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008230void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
8231 struct ieee80211_channel *channel_before,
8232 struct ieee80211_channel *channel_after)
8233{
8234 struct sk_buff *msg;
8235 void *hdr;
8236 struct nlattr *nl_freq;
8237
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008238 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008239 if (!msg)
8240 return;
8241
8242 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
8243 if (!hdr) {
8244 nlmsg_free(msg);
8245 return;
8246 }
8247
8248 /*
8249 * Since we are applying the beacon hint to a wiphy we know its
8250 * wiphy_idx is valid
8251 */
David S. Miller9360ffd2012-03-29 04:41:26 -04008252 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
8253 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008254
8255 /* Before */
8256 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
8257 if (!nl_freq)
8258 goto nla_put_failure;
8259 if (nl80211_msg_put_channel(msg, channel_before))
8260 goto nla_put_failure;
8261 nla_nest_end(msg, nl_freq);
8262
8263 /* After */
8264 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
8265 if (!nl_freq)
8266 goto nla_put_failure;
8267 if (nl80211_msg_put_channel(msg, channel_after))
8268 goto nla_put_failure;
8269 nla_nest_end(msg, nl_freq);
8270
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008271 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008272
Johannes Berg463d0182009-07-14 00:33:35 +02008273 rcu_read_lock();
8274 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
8275 GFP_ATOMIC);
8276 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04008277
8278 return;
8279
8280nla_put_failure:
8281 genlmsg_cancel(msg, hdr);
8282 nlmsg_free(msg);
8283}
8284
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008285static void nl80211_send_remain_on_chan_event(
8286 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008287 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008288 struct ieee80211_channel *chan,
8289 enum nl80211_channel_type channel_type,
8290 unsigned int duration, gfp_t gfp)
8291{
8292 struct sk_buff *msg;
8293 void *hdr;
8294
8295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8296 if (!msg)
8297 return;
8298
8299 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8300 if (!hdr) {
8301 nlmsg_free(msg);
8302 return;
8303 }
8304
David S. Miller9360ffd2012-03-29 04:41:26 -04008305 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008306 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8307 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02008308 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008309 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
8310 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
8311 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8312 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008313
David S. Miller9360ffd2012-03-29 04:41:26 -04008314 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
8315 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
8316 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008317
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008318 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008319
8320 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8321 nl80211_mlme_mcgrp.id, gfp);
8322 return;
8323
8324 nla_put_failure:
8325 genlmsg_cancel(msg, hdr);
8326 nlmsg_free(msg);
8327}
8328
8329void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008330 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008331 struct ieee80211_channel *chan,
8332 enum nl80211_channel_type channel_type,
8333 unsigned int duration, gfp_t gfp)
8334{
8335 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008336 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008337 channel_type, duration, gfp);
8338}
8339
8340void nl80211_send_remain_on_channel_cancel(
Johannes Berg71bbc992012-06-15 15:30:18 +02008341 struct cfg80211_registered_device *rdev,
8342 struct wireless_dev *wdev,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008343 u64 cookie, struct ieee80211_channel *chan,
8344 enum nl80211_channel_type channel_type, gfp_t gfp)
8345{
8346 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02008347 rdev, wdev, cookie, chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008348 channel_type, 0, gfp);
8349}
8350
Johannes Berg98b62182009-12-23 13:15:44 +01008351void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
8352 struct net_device *dev, const u8 *mac_addr,
8353 struct station_info *sinfo, gfp_t gfp)
8354{
8355 struct sk_buff *msg;
8356
Thomas Graf58050fc2012-06-28 03:57:45 +00008357 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01008358 if (!msg)
8359 return;
8360
John W. Linville66266b32012-03-15 13:25:41 -04008361 if (nl80211_send_station(msg, 0, 0, 0,
8362 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01008363 nlmsg_free(msg);
8364 return;
8365 }
8366
8367 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8368 nl80211_mlme_mcgrp.id, gfp);
8369}
8370
Jouni Malinenec15e682011-03-23 15:29:52 +02008371void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
8372 struct net_device *dev, const u8 *mac_addr,
8373 gfp_t gfp)
8374{
8375 struct sk_buff *msg;
8376 void *hdr;
8377
Thomas Graf58050fc2012-06-28 03:57:45 +00008378 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02008379 if (!msg)
8380 return;
8381
8382 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
8383 if (!hdr) {
8384 nlmsg_free(msg);
8385 return;
8386 }
8387
David S. Miller9360ffd2012-03-29 04:41:26 -04008388 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8389 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
8390 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02008391
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008392 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02008393
8394 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8395 nl80211_mlme_mcgrp.id, gfp);
8396 return;
8397
8398 nla_put_failure:
8399 genlmsg_cancel(msg, hdr);
8400 nlmsg_free(msg);
8401}
8402
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05308403void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
8404 struct net_device *dev, const u8 *mac_addr,
8405 enum nl80211_connect_failed_reason reason,
8406 gfp_t gfp)
8407{
8408 struct sk_buff *msg;
8409 void *hdr;
8410
8411 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8412 if (!msg)
8413 return;
8414
8415 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
8416 if (!hdr) {
8417 nlmsg_free(msg);
8418 return;
8419 }
8420
8421 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8422 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
8423 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
8424 goto nla_put_failure;
8425
8426 genlmsg_end(msg, hdr);
8427
8428 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8429 nl80211_mlme_mcgrp.id, gfp);
8430 return;
8431
8432 nla_put_failure:
8433 genlmsg_cancel(msg, hdr);
8434 nlmsg_free(msg);
8435}
8436
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008437static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
8438 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01008439{
8440 struct wireless_dev *wdev = dev->ieee80211_ptr;
8441 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8442 struct sk_buff *msg;
8443 void *hdr;
8444 int err;
Eric W. Biederman15e47302012-09-07 20:12:54 +00008445 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01008446
Eric W. Biederman15e47302012-09-07 20:12:54 +00008447 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008448 return false;
8449
8450 msg = nlmsg_new(100, gfp);
8451 if (!msg)
8452 return true;
8453
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008454 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01008455 if (!hdr) {
8456 nlmsg_free(msg);
8457 return true;
8458 }
8459
David S. Miller9360ffd2012-03-29 04:41:26 -04008460 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8461 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8462 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
8463 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01008464
8465 err = genlmsg_end(msg, hdr);
8466 if (err < 0) {
8467 nlmsg_free(msg);
8468 return true;
8469 }
8470
Eric W. Biederman15e47302012-09-07 20:12:54 +00008471 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01008472 return true;
8473
8474 nla_put_failure:
8475 genlmsg_cancel(msg, hdr);
8476 nlmsg_free(msg);
8477 return true;
8478}
8479
Johannes Bergb92ab5d2011-11-04 11:18:19 +01008480bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
8481{
8482 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
8483 addr, gfp);
8484}
8485
8486bool nl80211_unexpected_4addr_frame(struct net_device *dev,
8487 const u8 *addr, gfp_t gfp)
8488{
8489 return __nl80211_unexpected_frame(dev,
8490 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
8491 addr, gfp);
8492}
8493
Johannes Berg2e161f72010-08-12 15:38:38 +02008494int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00008495 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01008496 int freq, int sig_dbm,
8497 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008498{
Johannes Berg71bbc992012-06-15 15:30:18 +02008499 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008500 struct sk_buff *msg;
8501 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02008502
8503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8504 if (!msg)
8505 return -ENOMEM;
8506
Johannes Berg2e161f72010-08-12 15:38:38 +02008507 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02008508 if (!hdr) {
8509 nlmsg_free(msg);
8510 return -ENOMEM;
8511 }
8512
David S. Miller9360ffd2012-03-29 04:41:26 -04008513 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008514 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8515 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008516 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8517 (sig_dbm &&
8518 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8519 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
8520 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008521
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008522 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008523
Eric W. Biederman15e47302012-09-07 20:12:54 +00008524 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02008525
8526 nla_put_failure:
8527 genlmsg_cancel(msg, hdr);
8528 nlmsg_free(msg);
8529 return -ENOBUFS;
8530}
8531
Johannes Berg2e161f72010-08-12 15:38:38 +02008532void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02008533 struct wireless_dev *wdev, u64 cookie,
Johannes Berg2e161f72010-08-12 15:38:38 +02008534 const u8 *buf, size_t len, bool ack,
8535 gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02008536{
Johannes Berg71bbc992012-06-15 15:30:18 +02008537 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02008538 struct sk_buff *msg;
8539 void *hdr;
8540
8541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
8542 if (!msg)
8543 return;
8544
Johannes Berg2e161f72010-08-12 15:38:38 +02008545 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02008546 if (!hdr) {
8547 nlmsg_free(msg);
8548 return;
8549 }
8550
David S. Miller9360ffd2012-03-29 04:41:26 -04008551 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02008552 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8553 netdev->ifindex)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008554 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
8555 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8556 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
8557 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008558
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008559 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02008560
8561 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
8562 return;
8563
8564 nla_put_failure:
8565 genlmsg_cancel(msg, hdr);
8566 nlmsg_free(msg);
8567}
8568
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008569void
8570nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
8571 struct net_device *netdev,
8572 enum nl80211_cqm_rssi_threshold_event rssi_event,
8573 gfp_t gfp)
8574{
8575 struct sk_buff *msg;
8576 struct nlattr *pinfoattr;
8577 void *hdr;
8578
Thomas Graf58050fc2012-06-28 03:57:45 +00008579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008580 if (!msg)
8581 return;
8582
8583 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8584 if (!hdr) {
8585 nlmsg_free(msg);
8586 return;
8587 }
8588
David S. Miller9360ffd2012-03-29 04:41:26 -04008589 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8590 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8591 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008592
8593 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8594 if (!pinfoattr)
8595 goto nla_put_failure;
8596
David S. Miller9360ffd2012-03-29 04:41:26 -04008597 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
8598 rssi_event))
8599 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008600
8601 nla_nest_end(msg, pinfoattr);
8602
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008603 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008604
8605 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8606 nl80211_mlme_mcgrp.id, gfp);
8607 return;
8608
8609 nla_put_failure:
8610 genlmsg_cancel(msg, hdr);
8611 nlmsg_free(msg);
8612}
8613
Johannes Berge5497d72011-07-05 16:35:40 +02008614void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
8615 struct net_device *netdev, const u8 *bssid,
8616 const u8 *replay_ctr, gfp_t gfp)
8617{
8618 struct sk_buff *msg;
8619 struct nlattr *rekey_attr;
8620 void *hdr;
8621
Thomas Graf58050fc2012-06-28 03:57:45 +00008622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +02008623 if (!msg)
8624 return;
8625
8626 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
8627 if (!hdr) {
8628 nlmsg_free(msg);
8629 return;
8630 }
8631
David S. Miller9360ffd2012-03-29 04:41:26 -04008632 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8633 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8634 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
8635 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008636
8637 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
8638 if (!rekey_attr)
8639 goto nla_put_failure;
8640
David S. Miller9360ffd2012-03-29 04:41:26 -04008641 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8642 NL80211_REPLAY_CTR_LEN, replay_ctr))
8643 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +02008644
8645 nla_nest_end(msg, rekey_attr);
8646
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008647 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +02008648
8649 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8650 nl80211_mlme_mcgrp.id, gfp);
8651 return;
8652
8653 nla_put_failure:
8654 genlmsg_cancel(msg, hdr);
8655 nlmsg_free(msg);
8656}
8657
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008658void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
8659 struct net_device *netdev, int index,
8660 const u8 *bssid, bool preauth, gfp_t gfp)
8661{
8662 struct sk_buff *msg;
8663 struct nlattr *attr;
8664 void *hdr;
8665
Thomas Graf58050fc2012-06-28 03:57:45 +00008666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008667 if (!msg)
8668 return;
8669
8670 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
8671 if (!hdr) {
8672 nlmsg_free(msg);
8673 return;
8674 }
8675
David S. Miller9360ffd2012-03-29 04:41:26 -04008676 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8677 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
8678 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008679
8680 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
8681 if (!attr)
8682 goto nla_put_failure;
8683
David S. Miller9360ffd2012-03-29 04:41:26 -04008684 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
8685 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
8686 (preauth &&
8687 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
8688 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008689
8690 nla_nest_end(msg, attr);
8691
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008692 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +03008693
8694 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8695 nl80211_mlme_mcgrp.id, gfp);
8696 return;
8697
8698 nla_put_failure:
8699 genlmsg_cancel(msg, hdr);
8700 nlmsg_free(msg);
8701}
8702
Thomas Pedersen53145262012-04-06 13:35:47 -07008703void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
8704 struct net_device *netdev, int freq,
8705 enum nl80211_channel_type type, gfp_t gfp)
8706{
8707 struct sk_buff *msg;
8708 void *hdr;
8709
Thomas Graf58050fc2012-06-28 03:57:45 +00008710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -07008711 if (!msg)
8712 return;
8713
8714 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
8715 if (!hdr) {
8716 nlmsg_free(msg);
8717 return;
8718 }
8719
John W. Linville7eab0f62012-04-12 14:25:14 -04008720 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8721 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
8722 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type))
8723 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -07008724
8725 genlmsg_end(msg, hdr);
8726
8727 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8728 nl80211_mlme_mcgrp.id, gfp);
8729 return;
8730
8731 nla_put_failure:
8732 genlmsg_cancel(msg, hdr);
8733 nlmsg_free(msg);
8734}
8735
Johannes Bergc063dbf2010-11-24 08:10:05 +01008736void
Thomas Pedersen84f10702012-07-12 16:17:33 -07008737nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
8738 struct net_device *netdev, const u8 *peer,
8739 u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
8740{
8741 struct sk_buff *msg;
8742 struct nlattr *pinfoattr;
8743 void *hdr;
8744
8745 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
8746 if (!msg)
8747 return;
8748
8749 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8750 if (!hdr) {
8751 nlmsg_free(msg);
8752 return;
8753 }
8754
8755 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8756 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8757 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8758 goto nla_put_failure;
8759
8760 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8761 if (!pinfoattr)
8762 goto nla_put_failure;
8763
8764 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
8765 goto nla_put_failure;
8766
8767 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
8768 goto nla_put_failure;
8769
8770 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
8771 goto nla_put_failure;
8772
8773 nla_nest_end(msg, pinfoattr);
8774
8775 genlmsg_end(msg, hdr);
8776
8777 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8778 nl80211_mlme_mcgrp.id, gfp);
8779 return;
8780
8781 nla_put_failure:
8782 genlmsg_cancel(msg, hdr);
8783 nlmsg_free(msg);
8784}
8785
8786void
Johannes Bergc063dbf2010-11-24 08:10:05 +01008787nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
8788 struct net_device *netdev, const u8 *peer,
8789 u32 num_packets, gfp_t gfp)
8790{
8791 struct sk_buff *msg;
8792 struct nlattr *pinfoattr;
8793 void *hdr;
8794
Thomas Graf58050fc2012-06-28 03:57:45 +00008795 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008796 if (!msg)
8797 return;
8798
8799 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
8800 if (!hdr) {
8801 nlmsg_free(msg);
8802 return;
8803 }
8804
David S. Miller9360ffd2012-03-29 04:41:26 -04008805 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8806 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
8807 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
8808 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008809
8810 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
8811 if (!pinfoattr)
8812 goto nla_put_failure;
8813
David S. Miller9360ffd2012-03-29 04:41:26 -04008814 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
8815 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +01008816
8817 nla_nest_end(msg, pinfoattr);
8818
Johannes Berg3b7b72e2011-10-22 19:05:51 +02008819 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +01008820
8821 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8822 nl80211_mlme_mcgrp.id, gfp);
8823 return;
8824
8825 nla_put_failure:
8826 genlmsg_cancel(msg, hdr);
8827 nlmsg_free(msg);
8828}
8829
Johannes Berg7f6cf312011-11-04 11:18:15 +01008830void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
8831 u64 cookie, bool acked, gfp_t gfp)
8832{
8833 struct wireless_dev *wdev = dev->ieee80211_ptr;
8834 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
8835 struct sk_buff *msg;
8836 void *hdr;
8837 int err;
8838
Thomas Graf58050fc2012-06-28 03:57:45 +00008839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008840 if (!msg)
8841 return;
8842
8843 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
8844 if (!hdr) {
8845 nlmsg_free(msg);
8846 return;
8847 }
8848
David S. Miller9360ffd2012-03-29 04:41:26 -04008849 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8850 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
8851 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8852 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
8853 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
8854 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008855
8856 err = genlmsg_end(msg, hdr);
8857 if (err < 0) {
8858 nlmsg_free(msg);
8859 return;
8860 }
8861
8862 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8863 nl80211_mlme_mcgrp.id, gfp);
8864 return;
8865
8866 nla_put_failure:
8867 genlmsg_cancel(msg, hdr);
8868 nlmsg_free(msg);
8869}
8870EXPORT_SYMBOL(cfg80211_probe_status);
8871
Johannes Berg5e7602302011-11-04 11:18:17 +01008872void cfg80211_report_obss_beacon(struct wiphy *wiphy,
8873 const u8 *frame, size_t len,
Johannes Berg804483e2012-03-05 22:18:41 +01008874 int freq, int sig_dbm, gfp_t gfp)
Johannes Berg5e7602302011-11-04 11:18:17 +01008875{
8876 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
8877 struct sk_buff *msg;
8878 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00008879 u32 nlportid = ACCESS_ONCE(rdev->ap_beacons_nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008880
Eric W. Biederman15e47302012-09-07 20:12:54 +00008881 if (!nlportid)
Johannes Berg5e7602302011-11-04 11:18:17 +01008882 return;
8883
8884 msg = nlmsg_new(len + 100, gfp);
8885 if (!msg)
8886 return;
8887
8888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
8889 if (!hdr) {
8890 nlmsg_free(msg);
8891 return;
8892 }
8893
David S. Miller9360ffd2012-03-29 04:41:26 -04008894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
8895 (freq &&
8896 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
8897 (sig_dbm &&
8898 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
8899 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
8900 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +01008901
8902 genlmsg_end(msg, hdr);
8903
Eric W. Biederman15e47302012-09-07 20:12:54 +00008904 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +01008905 return;
8906
8907 nla_put_failure:
8908 genlmsg_cancel(msg, hdr);
8909 nlmsg_free(msg);
8910}
8911EXPORT_SYMBOL(cfg80211_report_obss_beacon);
8912
Jouni Malinen026331c2010-02-15 12:53:10 +02008913static int nl80211_netlink_notify(struct notifier_block * nb,
8914 unsigned long state,
8915 void *_notify)
8916{
8917 struct netlink_notify *notify = _notify;
8918 struct cfg80211_registered_device *rdev;
8919 struct wireless_dev *wdev;
8920
8921 if (state != NETLINK_URELEASE)
8922 return NOTIFY_DONE;
8923
8924 rcu_read_lock();
8925
Johannes Berg5e7602302011-11-04 11:18:17 +01008926 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +02008927 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +00008928 cfg80211_mlme_unregister_socket(wdev, notify->portid);
8929 if (rdev->ap_beacons_nlportid == notify->portid)
8930 rdev->ap_beacons_nlportid = 0;
Johannes Berg5e7602302011-11-04 11:18:17 +01008931 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008932
8933 rcu_read_unlock();
8934
8935 return NOTIFY_DONE;
8936}
8937
8938static struct notifier_block nl80211_netlink_notifier = {
8939 .notifier_call = nl80211_netlink_notify,
8940};
8941
Johannes Berg55682962007-09-20 13:09:35 -04008942/* initialisation/exit functions */
8943
8944int nl80211_init(void)
8945{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008946 int err;
Johannes Berg55682962007-09-20 13:09:35 -04008947
Michał Mirosław0d63cbb2009-05-21 10:34:06 +00008948 err = genl_register_family_with_ops(&nl80211_fam,
8949 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -04008950 if (err)
8951 return err;
8952
Johannes Berg55682962007-09-20 13:09:35 -04008953 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
8954 if (err)
8955 goto err_out;
8956
Johannes Berg2a519312009-02-10 21:25:55 +01008957 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
8958 if (err)
8959 goto err_out;
8960
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008961 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
8962 if (err)
8963 goto err_out;
8964
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008965 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
8966 if (err)
8967 goto err_out;
8968
Johannes Bergaff89a92009-07-01 21:26:51 +02008969#ifdef CONFIG_NL80211_TESTMODE
8970 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
8971 if (err)
8972 goto err_out;
8973#endif
8974
Jouni Malinen026331c2010-02-15 12:53:10 +02008975 err = netlink_register_notifier(&nl80211_netlink_notifier);
8976 if (err)
8977 goto err_out;
8978
Johannes Berg55682962007-09-20 13:09:35 -04008979 return 0;
8980 err_out:
8981 genl_unregister_family(&nl80211_fam);
8982 return err;
8983}
8984
8985void nl80211_exit(void)
8986{
Jouni Malinen026331c2010-02-15 12:53:10 +02008987 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -04008988 genl_unregister_family(&nl80211_fam);
8989}